| 1 | n/a | # This script generates a Python interface for an Apple Macintosh Manager. |
|---|
| 2 | n/a | # It uses the "bgen" package to generate C code. |
|---|
| 3 | n/a | # The function specifications are generated by scanning the mamager's header file, |
|---|
| 4 | n/a | # using the "scantools" package (customized for this particular manager). |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | #error missing SetActionFilter |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | import string |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | # Declarations that change for each manager |
|---|
| 11 | n/a | MODNAME = '_CF' # The name of the module |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 14 | n/a | MODPREFIX = 'CF' # The prefix for module-wide routines |
|---|
| 15 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 16 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | from macsupport import * |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | # Special case generator for the functions that have an AllocatorRef first argument, |
|---|
| 21 | n/a | # which we skip anyway, and the object as the second arg. |
|---|
| 22 | n/a | class MethodSkipArg1(MethodGenerator): |
|---|
| 23 | n/a | """Similar to MethodGenerator, but has self as last argument""" |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | def parseArgumentList(self, args): |
|---|
| 26 | n/a | if len(args) < 2: |
|---|
| 27 | n/a | raise ValueError, "MethodSkipArg1 expects at least 2 args" |
|---|
| 28 | n/a | a0, a1, args = args[0], args[1], args[2:] |
|---|
| 29 | n/a | t0, n0, m0 = a0 |
|---|
| 30 | n/a | if t0 != "CFAllocatorRef" and m0 != InMode: |
|---|
| 31 | n/a | raise ValueError, "MethodSkipArg1 should have dummy AllocatorRef first arg" |
|---|
| 32 | n/a | t1, n1, m1 = a1 |
|---|
| 33 | n/a | if m1 != InMode: |
|---|
| 34 | n/a | raise ValueError, "method's 'self' must be 'InMode'" |
|---|
| 35 | n/a | dummy = Variable(t0, n0, m0) |
|---|
| 36 | n/a | self.argumentList.append(dummy) |
|---|
| 37 | n/a | self.itself = Variable(t1, "_self->ob_itself", SelfMode) |
|---|
| 38 | n/a | self.argumentList.append(self.itself) |
|---|
| 39 | n/a | FunctionGenerator.parseArgumentList(self, args) |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | # Create the type objects |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | includestuff = includestuff + """ |
|---|
| 45 | n/a | #include <CoreServices/CoreServices.h> |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | #include "pycfbridge.h" |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 50 | n/a | extern PyObject *_CFObj_New(CFTypeRef); |
|---|
| 51 | n/a | extern int _CFObj_Convert(PyObject *, CFTypeRef *); |
|---|
| 52 | n/a | #define CFObj_New _CFObj_New |
|---|
| 53 | n/a | #define CFObj_Convert _CFObj_Convert |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | extern PyObject *_CFTypeRefObj_New(CFTypeRef); |
|---|
| 56 | n/a | extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *); |
|---|
| 57 | n/a | #define CFTypeRefObj_New _CFTypeRefObj_New |
|---|
| 58 | n/a | #define CFTypeRefObj_Convert _CFTypeRefObj_Convert |
|---|
| 59 | n/a | |
|---|
| 60 | n/a | extern PyObject *_CFStringRefObj_New(CFStringRef); |
|---|
| 61 | n/a | extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *); |
|---|
| 62 | n/a | #define CFStringRefObj_New _CFStringRefObj_New |
|---|
| 63 | n/a | #define CFStringRefObj_Convert _CFStringRefObj_Convert |
|---|
| 64 | n/a | |
|---|
| 65 | n/a | extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef); |
|---|
| 66 | n/a | extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *); |
|---|
| 67 | n/a | #define CFMutableStringRefObj_New _CFMutableStringRefObj_New |
|---|
| 68 | n/a | #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | extern PyObject *_CFArrayRefObj_New(CFArrayRef); |
|---|
| 71 | n/a | extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *); |
|---|
| 72 | n/a | #define CFArrayRefObj_New _CFArrayRefObj_New |
|---|
| 73 | n/a | #define CFArrayRefObj_Convert _CFArrayRefObj_Convert |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef); |
|---|
| 76 | n/a | extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *); |
|---|
| 77 | n/a | #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New |
|---|
| 78 | n/a | #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | extern PyObject *_CFDataRefObj_New(CFDataRef); |
|---|
| 81 | n/a | extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *); |
|---|
| 82 | n/a | #define CFDataRefObj_New _CFDataRefObj_New |
|---|
| 83 | n/a | #define CFDataRefObj_Convert _CFDataRefObj_Convert |
|---|
| 84 | n/a | |
|---|
| 85 | n/a | extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef); |
|---|
| 86 | n/a | extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *); |
|---|
| 87 | n/a | #define CFMutableDataRefObj_New _CFMutableDataRefObj_New |
|---|
| 88 | n/a | #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef); |
|---|
| 91 | n/a | extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *); |
|---|
| 92 | n/a | #define CFDictionaryRefObj_New _CFDictionaryRefObj_New |
|---|
| 93 | n/a | #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef); |
|---|
| 96 | n/a | extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *); |
|---|
| 97 | n/a | #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New |
|---|
| 98 | n/a | #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert |
|---|
| 99 | n/a | |
|---|
| 100 | n/a | extern PyObject *_CFURLRefObj_New(CFURLRef); |
|---|
| 101 | n/a | extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *); |
|---|
| 102 | n/a | extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *); |
|---|
| 103 | n/a | #define CFURLRefObj_New _CFURLRefObj_New |
|---|
| 104 | n/a | #define CFURLRefObj_Convert _CFURLRefObj_Convert |
|---|
| 105 | n/a | #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert |
|---|
| 106 | n/a | #endif |
|---|
| 107 | n/a | |
|---|
| 108 | n/a | /* |
|---|
| 109 | n/a | ** Parse/generate CFRange records |
|---|
| 110 | n/a | */ |
|---|
| 111 | n/a | PyObject *CFRange_New(CFRange *itself) |
|---|
| 112 | n/a | { |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | return Py_BuildValue("ll", (long)itself->location, (long)itself->length); |
|---|
| 115 | n/a | } |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | int |
|---|
| 118 | n/a | CFRange_Convert(PyObject *v, CFRange *p_itself) |
|---|
| 119 | n/a | { |
|---|
| 120 | n/a | long location, length; |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | if( !PyArg_ParseTuple(v, "ll", &location, &length) ) |
|---|
| 123 | n/a | return 0; |
|---|
| 124 | n/a | p_itself->location = (CFIndex)location; |
|---|
| 125 | n/a | p_itself->length = (CFIndex)length; |
|---|
| 126 | n/a | return 1; |
|---|
| 127 | n/a | } |
|---|
| 128 | n/a | |
|---|
| 129 | n/a | /* Optional CFURL argument or None (passed as NULL) */ |
|---|
| 130 | n/a | int |
|---|
| 131 | n/a | OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself) |
|---|
| 132 | n/a | { |
|---|
| 133 | n/a | if ( v == Py_None ) { |
|---|
| 134 | n/a | p_itself = NULL; |
|---|
| 135 | n/a | return 1; |
|---|
| 136 | n/a | } |
|---|
| 137 | n/a | return CFURLRefObj_Convert(v, p_itself); |
|---|
| 138 | n/a | } |
|---|
| 139 | n/a | """ |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | finalstuff = finalstuff + """ |
|---|
| 142 | n/a | |
|---|
| 143 | n/a | /* Routines to convert any CF type to/from the corresponding CFxxxObj */ |
|---|
| 144 | n/a | PyObject *CFObj_New(CFTypeRef itself) |
|---|
| 145 | n/a | { |
|---|
| 146 | n/a | if (itself == NULL) |
|---|
| 147 | n/a | { |
|---|
| 148 | n/a | PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL"); |
|---|
| 149 | n/a | return NULL; |
|---|
| 150 | n/a | } |
|---|
| 151 | n/a | if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself); |
|---|
| 152 | n/a | if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself); |
|---|
| 153 | n/a | if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself); |
|---|
| 154 | n/a | if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself); |
|---|
| 155 | n/a | if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself); |
|---|
| 156 | n/a | /* XXXX Or should we use PyCF_CF2Python here?? */ |
|---|
| 157 | n/a | return CFTypeRefObj_New(itself); |
|---|
| 158 | n/a | } |
|---|
| 159 | n/a | int CFObj_Convert(PyObject *v, CFTypeRef *p_itself) |
|---|
| 160 | n/a | { |
|---|
| 161 | n/a | |
|---|
| 162 | n/a | if (v == Py_None) { *p_itself = NULL; return 1; } |
|---|
| 163 | n/a | /* Check for other CF objects here */ |
|---|
| 164 | n/a | |
|---|
| 165 | n/a | if (!CFTypeRefObj_Check(v) && |
|---|
| 166 | n/a | !CFArrayRefObj_Check(v) && |
|---|
| 167 | n/a | !CFMutableArrayRefObj_Check(v) && |
|---|
| 168 | n/a | !CFDictionaryRefObj_Check(v) && |
|---|
| 169 | n/a | !CFMutableDictionaryRefObj_Check(v) && |
|---|
| 170 | n/a | !CFDataRefObj_Check(v) && |
|---|
| 171 | n/a | !CFMutableDataRefObj_Check(v) && |
|---|
| 172 | n/a | !CFStringRefObj_Check(v) && |
|---|
| 173 | n/a | !CFMutableStringRefObj_Check(v) && |
|---|
| 174 | n/a | !CFURLRefObj_Check(v) ) |
|---|
| 175 | n/a | { |
|---|
| 176 | n/a | /* XXXX Or should we use PyCF_Python2CF here?? */ |
|---|
| 177 | n/a | PyErr_SetString(PyExc_TypeError, "CF object required"); |
|---|
| 178 | n/a | return 0; |
|---|
| 179 | n/a | } |
|---|
| 180 | n/a | *p_itself = ((CFTypeRefObject *)v)->ob_itself; |
|---|
| 181 | n/a | return 1; |
|---|
| 182 | n/a | } |
|---|
| 183 | n/a | """ |
|---|
| 184 | n/a | |
|---|
| 185 | n/a | initstuff = initstuff + """ |
|---|
| 186 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFObj_New); |
|---|
| 187 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFObj_Convert); |
|---|
| 188 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New); |
|---|
| 189 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert); |
|---|
| 190 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New); |
|---|
| 191 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert); |
|---|
| 192 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New); |
|---|
| 193 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert); |
|---|
| 194 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New); |
|---|
| 195 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert); |
|---|
| 196 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New); |
|---|
| 197 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert); |
|---|
| 198 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New); |
|---|
| 199 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert); |
|---|
| 200 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New); |
|---|
| 201 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert); |
|---|
| 202 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New); |
|---|
| 203 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert); |
|---|
| 204 | n/a | """ |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | variablestuff=""" |
|---|
| 207 | n/a | #define _STRINGCONST(name) PyModule_AddObject(m, #name, CFStringRefObj_New(name)) |
|---|
| 208 | n/a | _STRINGCONST(kCFPreferencesAnyApplication); |
|---|
| 209 | n/a | _STRINGCONST(kCFPreferencesCurrentApplication); |
|---|
| 210 | n/a | _STRINGCONST(kCFPreferencesAnyHost); |
|---|
| 211 | n/a | _STRINGCONST(kCFPreferencesCurrentHost); |
|---|
| 212 | n/a | _STRINGCONST(kCFPreferencesAnyUser); |
|---|
| 213 | n/a | _STRINGCONST(kCFPreferencesCurrentUser); |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | """ |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | Boolean = Type("Boolean", "l") |
|---|
| 218 | n/a | CFTypeID = Type("CFTypeID", "l") # XXXX a guess, seems better than OSTypeType. |
|---|
| 219 | n/a | CFHashCode = Type("CFHashCode", "l") |
|---|
| 220 | n/a | CFIndex = Type("CFIndex", "l") |
|---|
| 221 | n/a | CFRange = OpaqueByValueType('CFRange', 'CFRange') |
|---|
| 222 | n/a | CFOptionFlags = Type("CFOptionFlags", "l") |
|---|
| 223 | n/a | CFStringEncoding = Type("CFStringEncoding", "l") |
|---|
| 224 | n/a | CFComparisonResult = Type("CFComparisonResult", "l") # a bit dangerous, it's an enum |
|---|
| 225 | n/a | CFURLPathStyle = Type("CFURLPathStyle", "l") # a bit dangerous, it's an enum |
|---|
| 226 | n/a | |
|---|
| 227 | n/a | char_ptr = stringptr |
|---|
| 228 | n/a | return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!! |
|---|
| 229 | n/a | |
|---|
| 230 | n/a | CFAllocatorRef = FakeType("(CFAllocatorRef)NULL") |
|---|
| 231 | n/a | CFArrayCallBacks_ptr = FakeType("&kCFTypeArrayCallBacks") |
|---|
| 232 | n/a | CFDictionaryKeyCallBacks_ptr = FakeType("&kCFTypeDictionaryKeyCallBacks") |
|---|
| 233 | n/a | CFDictionaryValueCallBacks_ptr = FakeType("&kCFTypeDictionaryValueCallBacks") |
|---|
| 234 | n/a | # The real objects |
|---|
| 235 | n/a | CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj") |
|---|
| 236 | n/a | CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj") |
|---|
| 237 | n/a | CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj") |
|---|
| 238 | n/a | CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj") |
|---|
| 239 | n/a | CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj") |
|---|
| 240 | n/a | CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj") |
|---|
| 241 | n/a | CFMutableDataRef = OpaqueByValueType("CFMutableDataRef", "CFMutableDataRefObj") |
|---|
| 242 | n/a | CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj") |
|---|
| 243 | n/a | CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj") |
|---|
| 244 | n/a | CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj") |
|---|
| 245 | n/a | CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj") |
|---|
| 246 | n/a | CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj") |
|---|
| 247 | n/a | OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj") |
|---|
| 248 | n/a | ##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj") |
|---|
| 249 | n/a | # ADD object type here |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | # Our (opaque) objects |
|---|
| 252 | n/a | |
|---|
| 253 | n/a | class MyGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|---|
| 254 | n/a | def outputCheckNewArg(self): |
|---|
| 255 | n/a | Output('if (itself == NULL)') |
|---|
| 256 | n/a | OutLbrace() |
|---|
| 257 | n/a | Output('PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");') |
|---|
| 258 | n/a | Output('return NULL;') |
|---|
| 259 | n/a | OutRbrace() |
|---|
| 260 | n/a | def outputStructMembers(self): |
|---|
| 261 | n/a | GlobalObjectDefinition.outputStructMembers(self) |
|---|
| 262 | n/a | Output("void (*ob_freeit)(CFTypeRef ptr);") |
|---|
| 263 | n/a | def outputInitStructMembers(self): |
|---|
| 264 | n/a | GlobalObjectDefinition.outputInitStructMembers(self) |
|---|
| 265 | n/a | ## Output("it->ob_freeit = NULL;") |
|---|
| 266 | n/a | Output("it->ob_freeit = CFRelease;") |
|---|
| 267 | n/a | def outputCheckConvertArg(self): |
|---|
| 268 | n/a | Out(""" |
|---|
| 269 | n/a | if (v == Py_None) { *p_itself = NULL; return 1; } |
|---|
| 270 | n/a | /* Check for other CF objects here */ |
|---|
| 271 | n/a | """) |
|---|
| 272 | n/a | def outputCleanupStructMembers(self): |
|---|
| 273 | n/a | Output("if (self->ob_freeit && self->ob_itself)") |
|---|
| 274 | n/a | OutLbrace() |
|---|
| 275 | n/a | Output("self->ob_freeit((CFTypeRef)self->ob_itself);") |
|---|
| 276 | n/a | Output("self->ob_itself = NULL;") |
|---|
| 277 | n/a | OutRbrace() |
|---|
| 278 | n/a | |
|---|
| 279 | n/a | def outputCompare(self): |
|---|
| 280 | n/a | Output() |
|---|
| 281 | n/a | Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype) |
|---|
| 282 | n/a | OutLbrace() |
|---|
| 283 | n/a | Output("/* XXXX Or should we use CFEqual?? */") |
|---|
| 284 | n/a | Output("if ( self->ob_itself > other->ob_itself ) return 1;") |
|---|
| 285 | n/a | Output("if ( self->ob_itself < other->ob_itself ) return -1;") |
|---|
| 286 | n/a | Output("return 0;") |
|---|
| 287 | n/a | OutRbrace() |
|---|
| 288 | n/a | |
|---|
| 289 | n/a | def outputHash(self): |
|---|
| 290 | n/a | Output() |
|---|
| 291 | n/a | Output("static int %s_hash(%s *self)", self.prefix, self.objecttype) |
|---|
| 292 | n/a | OutLbrace() |
|---|
| 293 | n/a | Output("/* XXXX Or should we use CFHash?? */") |
|---|
| 294 | n/a | Output("return (int)self->ob_itself;") |
|---|
| 295 | n/a | OutRbrace() |
|---|
| 296 | n/a | |
|---|
| 297 | n/a | def outputRepr(self): |
|---|
| 298 | n/a | Output() |
|---|
| 299 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 300 | n/a | OutLbrace() |
|---|
| 301 | n/a | Output("char buf[100];") |
|---|
| 302 | n/a | Output("""sprintf(buf, "<CFTypeRef type-%%d object at 0x%%8.8x for 0x%%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 303 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 304 | n/a | OutRbrace() |
|---|
| 305 | n/a | |
|---|
| 306 | n/a | def output_tp_newBody(self): |
|---|
| 307 | n/a | Output("PyObject *self;") |
|---|
| 308 | n/a | Output |
|---|
| 309 | n/a | Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;") |
|---|
| 310 | n/a | Output("((%s *)self)->ob_itself = NULL;", self.objecttype) |
|---|
| 311 | n/a | Output("((%s *)self)->ob_freeit = CFRelease;", self.objecttype) |
|---|
| 312 | n/a | Output("return self;") |
|---|
| 313 | n/a | |
|---|
| 314 | n/a | def output_tp_initBody(self): |
|---|
| 315 | n/a | Output("%s itself;", self.itselftype) |
|---|
| 316 | n/a | Output("char *kw[] = {\"itself\", 0};") |
|---|
| 317 | n/a | Output() |
|---|
| 318 | n/a | Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, %s_Convert, &itself))", |
|---|
| 319 | n/a | self.prefix) |
|---|
| 320 | n/a | OutLbrace() |
|---|
| 321 | n/a | Output("((%s *)_self)->ob_itself = itself;", self.objecttype) |
|---|
| 322 | n/a | Output("return 0;") |
|---|
| 323 | n/a | OutRbrace() |
|---|
| 324 | n/a | if self.prefix != 'CFTypeRefObj': |
|---|
| 325 | n/a | Output() |
|---|
| 326 | n/a | Output("/* Any CFTypeRef descendent is allowed as initializer too */") |
|---|
| 327 | n/a | Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, CFTypeRefObj_Convert, &itself))") |
|---|
| 328 | n/a | OutLbrace() |
|---|
| 329 | n/a | Output("((%s *)_self)->ob_itself = itself;", self.objecttype) |
|---|
| 330 | n/a | Output("return 0;") |
|---|
| 331 | n/a | OutRbrace() |
|---|
| 332 | n/a | Output("return -1;") |
|---|
| 333 | n/a | |
|---|
| 334 | n/a | class CFTypeRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 335 | n/a | pass |
|---|
| 336 | n/a | |
|---|
| 337 | n/a | class CFArrayRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 338 | n/a | basetype = "CFTypeRef_Type" |
|---|
| 339 | n/a | |
|---|
| 340 | n/a | def outputRepr(self): |
|---|
| 341 | n/a | Output() |
|---|
| 342 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 343 | n/a | OutLbrace() |
|---|
| 344 | n/a | Output("char buf[100];") |
|---|
| 345 | n/a | Output("""sprintf(buf, "<CFArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 346 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 347 | n/a | OutRbrace() |
|---|
| 348 | n/a | |
|---|
| 349 | n/a | class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 350 | n/a | basetype = "CFArrayRef_Type" |
|---|
| 351 | n/a | |
|---|
| 352 | n/a | def outputRepr(self): |
|---|
| 353 | n/a | Output() |
|---|
| 354 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 355 | n/a | OutLbrace() |
|---|
| 356 | n/a | Output("char buf[100];") |
|---|
| 357 | n/a | Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 358 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 359 | n/a | OutRbrace() |
|---|
| 360 | n/a | |
|---|
| 361 | n/a | class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 362 | n/a | basetype = "CFTypeRef_Type" |
|---|
| 363 | n/a | |
|---|
| 364 | n/a | def outputRepr(self): |
|---|
| 365 | n/a | Output() |
|---|
| 366 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 367 | n/a | OutLbrace() |
|---|
| 368 | n/a | Output("char buf[100];") |
|---|
| 369 | n/a | Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 370 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 371 | n/a | OutRbrace() |
|---|
| 372 | n/a | |
|---|
| 373 | n/a | class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 374 | n/a | basetype = "CFDictionaryRef_Type" |
|---|
| 375 | n/a | |
|---|
| 376 | n/a | def outputRepr(self): |
|---|
| 377 | n/a | Output() |
|---|
| 378 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 379 | n/a | OutLbrace() |
|---|
| 380 | n/a | Output("char buf[100];") |
|---|
| 381 | n/a | Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 382 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 383 | n/a | OutRbrace() |
|---|
| 384 | n/a | |
|---|
| 385 | n/a | class CFDataRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 386 | n/a | basetype = "CFTypeRef_Type" |
|---|
| 387 | n/a | |
|---|
| 388 | n/a | def outputCheckConvertArg(self): |
|---|
| 389 | n/a | Out(""" |
|---|
| 390 | n/a | if (v == Py_None) { *p_itself = NULL; return 1; } |
|---|
| 391 | n/a | if (PyString_Check(v)) { |
|---|
| 392 | n/a | char *cStr; |
|---|
| 393 | n/a | int cLen; |
|---|
| 394 | n/a | if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0; |
|---|
| 395 | n/a | *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen); |
|---|
| 396 | n/a | return 1; |
|---|
| 397 | n/a | } |
|---|
| 398 | n/a | """) |
|---|
| 399 | n/a | |
|---|
| 400 | n/a | def outputRepr(self): |
|---|
| 401 | n/a | Output() |
|---|
| 402 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 403 | n/a | OutLbrace() |
|---|
| 404 | n/a | Output("char buf[100];") |
|---|
| 405 | n/a | Output("""sprintf(buf, "<CFDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 406 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 407 | n/a | OutRbrace() |
|---|
| 408 | n/a | |
|---|
| 409 | n/a | class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 410 | n/a | basetype = "CFDataRef_Type" |
|---|
| 411 | n/a | |
|---|
| 412 | n/a | def outputRepr(self): |
|---|
| 413 | n/a | Output() |
|---|
| 414 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 415 | n/a | OutLbrace() |
|---|
| 416 | n/a | Output("char buf[100];") |
|---|
| 417 | n/a | Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 418 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 419 | n/a | OutRbrace() |
|---|
| 420 | n/a | |
|---|
| 421 | n/a | class CFStringRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 422 | n/a | basetype = "CFTypeRef_Type" |
|---|
| 423 | n/a | |
|---|
| 424 | n/a | def outputCheckConvertArg(self): |
|---|
| 425 | n/a | Out(""" |
|---|
| 426 | n/a | if (v == Py_None) { *p_itself = NULL; return 1; } |
|---|
| 427 | n/a | if (PyString_Check(v)) { |
|---|
| 428 | n/a | char *cStr; |
|---|
| 429 | n/a | if (!PyArg_Parse(v, "es", "ascii", &cStr)) |
|---|
| 430 | n/a | return NULL; |
|---|
| 431 | n/a | *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII); |
|---|
| 432 | n/a | PyMem_Free(cStr); |
|---|
| 433 | n/a | return 1; |
|---|
| 434 | n/a | } |
|---|
| 435 | n/a | if (PyUnicode_Check(v)) { |
|---|
| 436 | n/a | /* We use the CF types here, if Python was configured differently that will give an error */ |
|---|
| 437 | n/a | CFIndex size = PyUnicode_GetSize(v); |
|---|
| 438 | n/a | UniChar *unichars = PyUnicode_AsUnicode(v); |
|---|
| 439 | n/a | if (!unichars) return 0; |
|---|
| 440 | n/a | *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size); |
|---|
| 441 | n/a | return 1; |
|---|
| 442 | n/a | } |
|---|
| 443 | n/a | |
|---|
| 444 | n/a | """) |
|---|
| 445 | n/a | |
|---|
| 446 | n/a | def outputRepr(self): |
|---|
| 447 | n/a | Output() |
|---|
| 448 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 449 | n/a | OutLbrace() |
|---|
| 450 | n/a | Output("char buf[100];") |
|---|
| 451 | n/a | Output("""sprintf(buf, "<CFStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 452 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 453 | n/a | OutRbrace() |
|---|
| 454 | n/a | |
|---|
| 455 | n/a | class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition): |
|---|
| 456 | n/a | basetype = "CFStringRef_Type" |
|---|
| 457 | n/a | |
|---|
| 458 | n/a | def outputCheckConvertArg(self): |
|---|
| 459 | n/a | # Mutable, don't allow Python strings |
|---|
| 460 | n/a | return MyGlobalObjectDefinition.outputCheckConvertArg(self) |
|---|
| 461 | n/a | |
|---|
| 462 | n/a | def outputRepr(self): |
|---|
| 463 | n/a | Output() |
|---|
| 464 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 465 | n/a | OutLbrace() |
|---|
| 466 | n/a | Output("char buf[100];") |
|---|
| 467 | n/a | Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 468 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 469 | n/a | OutRbrace() |
|---|
| 470 | n/a | |
|---|
| 471 | n/a | class CFURLRefObjectDefinition(MyGlobalObjectDefinition): |
|---|
| 472 | n/a | basetype = "CFTypeRef_Type" |
|---|
| 473 | n/a | |
|---|
| 474 | n/a | def outputRepr(self): |
|---|
| 475 | n/a | Output() |
|---|
| 476 | n/a | Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype) |
|---|
| 477 | n/a | OutLbrace() |
|---|
| 478 | n/a | Output("char buf[100];") |
|---|
| 479 | n/a | Output("""sprintf(buf, "<CFURL object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""") |
|---|
| 480 | n/a | Output("return PyString_FromString(buf);") |
|---|
| 481 | n/a | OutRbrace() |
|---|
| 482 | n/a | |
|---|
| 483 | n/a | |
|---|
| 484 | n/a | # ADD object class here |
|---|
| 485 | n/a | |
|---|
| 486 | n/a | # From here on it's basically all boiler plate... |
|---|
| 487 | n/a | |
|---|
| 488 | n/a | # Create the generator groups and link them |
|---|
| 489 | n/a | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff) |
|---|
| 490 | n/a | CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef') |
|---|
| 491 | n/a | CFArrayRef_object = CFArrayRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef') |
|---|
| 492 | n/a | CFMutableArrayRef_object = CFMutableArrayRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef') |
|---|
| 493 | n/a | CFDictionaryRef_object = CFDictionaryRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef') |
|---|
| 494 | n/a | CFMutableDictionaryRef_object = CFMutableDictionaryRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef') |
|---|
| 495 | n/a | CFDataRef_object = CFDataRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef') |
|---|
| 496 | n/a | CFMutableDataRef_object = CFMutableDataRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef') |
|---|
| 497 | n/a | CFStringRef_object = CFStringRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef') |
|---|
| 498 | n/a | CFMutableStringRef_object = CFMutableStringRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef') |
|---|
| 499 | n/a | CFURLRef_object = CFURLRefObjectDefinition('CFURLRef', 'CFURLRefObj', 'CFURLRef') |
|---|
| 500 | n/a | |
|---|
| 501 | n/a | # ADD object here |
|---|
| 502 | n/a | |
|---|
| 503 | n/a | module.addobject(CFTypeRef_object) |
|---|
| 504 | n/a | module.addobject(CFArrayRef_object) |
|---|
| 505 | n/a | module.addobject(CFMutableArrayRef_object) |
|---|
| 506 | n/a | module.addobject(CFDictionaryRef_object) |
|---|
| 507 | n/a | module.addobject(CFMutableDictionaryRef_object) |
|---|
| 508 | n/a | module.addobject(CFDataRef_object) |
|---|
| 509 | n/a | module.addobject(CFMutableDataRef_object) |
|---|
| 510 | n/a | module.addobject(CFStringRef_object) |
|---|
| 511 | n/a | module.addobject(CFMutableStringRef_object) |
|---|
| 512 | n/a | module.addobject(CFURLRef_object) |
|---|
| 513 | n/a | # ADD addobject call here |
|---|
| 514 | n/a | |
|---|
| 515 | n/a | # Create the generator classes used to populate the lists |
|---|
| 516 | n/a | Function = OSErrWeakLinkFunctionGenerator |
|---|
| 517 | n/a | Method = OSErrWeakLinkMethodGenerator |
|---|
| 518 | n/a | |
|---|
| 519 | n/a | # Create and populate the lists |
|---|
| 520 | n/a | functions = [] |
|---|
| 521 | n/a | CFTypeRef_methods = [] |
|---|
| 522 | n/a | CFArrayRef_methods = [] |
|---|
| 523 | n/a | CFMutableArrayRef_methods = [] |
|---|
| 524 | n/a | CFDictionaryRef_methods = [] |
|---|
| 525 | n/a | CFMutableDictionaryRef_methods = [] |
|---|
| 526 | n/a | CFDataRef_methods = [] |
|---|
| 527 | n/a | CFMutableDataRef_methods = [] |
|---|
| 528 | n/a | CFStringRef_methods = [] |
|---|
| 529 | n/a | CFMutableStringRef_methods = [] |
|---|
| 530 | n/a | CFURLRef_methods = [] |
|---|
| 531 | n/a | |
|---|
| 532 | n/a | # ADD _methods initializer here |
|---|
| 533 | n/a | execfile(INPUTFILE) |
|---|
| 534 | n/a | |
|---|
| 535 | n/a | |
|---|
| 536 | n/a | # add the populated lists to the generator groups |
|---|
| 537 | n/a | # (in a different wordl the scan program would generate this) |
|---|
| 538 | n/a | for f in functions: module.add(f) |
|---|
| 539 | n/a | for f in CFTypeRef_methods: CFTypeRef_object.add(f) |
|---|
| 540 | n/a | for f in CFArrayRef_methods: CFArrayRef_object.add(f) |
|---|
| 541 | n/a | for f in CFMutableArrayRef_methods: CFMutableArrayRef_object.add(f) |
|---|
| 542 | n/a | for f in CFDictionaryRef_methods: CFDictionaryRef_object.add(f) |
|---|
| 543 | n/a | for f in CFMutableDictionaryRef_methods: CFMutableDictionaryRef_object.add(f) |
|---|
| 544 | n/a | for f in CFDataRef_methods: CFDataRef_object.add(f) |
|---|
| 545 | n/a | for f in CFMutableDataRef_methods: CFMutableDataRef_object.add(f) |
|---|
| 546 | n/a | for f in CFStringRef_methods: CFStringRef_object.add(f) |
|---|
| 547 | n/a | for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f) |
|---|
| 548 | n/a | for f in CFURLRef_methods: CFURLRef_object.add(f) |
|---|
| 549 | n/a | |
|---|
| 550 | n/a | # Manual generators for getting data out of strings |
|---|
| 551 | n/a | |
|---|
| 552 | n/a | getasstring_body = """ |
|---|
| 553 | n/a | int size = CFStringGetLength(_self->ob_itself)+1; |
|---|
| 554 | n/a | char *data = malloc(size); |
|---|
| 555 | n/a | |
|---|
| 556 | n/a | if( data == NULL ) return PyErr_NoMemory(); |
|---|
| 557 | n/a | if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) { |
|---|
| 558 | n/a | _res = (PyObject *)PyString_FromString(data); |
|---|
| 559 | n/a | } else { |
|---|
| 560 | n/a | PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string"); |
|---|
| 561 | n/a | _res = NULL; |
|---|
| 562 | n/a | } |
|---|
| 563 | n/a | free(data); |
|---|
| 564 | n/a | return _res; |
|---|
| 565 | n/a | """ |
|---|
| 566 | n/a | |
|---|
| 567 | n/a | f = ManualGenerator("CFStringGetString", getasstring_body); |
|---|
| 568 | n/a | f.docstring = lambda: "() -> (string _rv)" |
|---|
| 569 | n/a | CFStringRef_object.add(f) |
|---|
| 570 | n/a | |
|---|
| 571 | n/a | getasunicode_body = """ |
|---|
| 572 | n/a | int size = CFStringGetLength(_self->ob_itself)+1; |
|---|
| 573 | n/a | Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE)); |
|---|
| 574 | n/a | CFRange range; |
|---|
| 575 | n/a | |
|---|
| 576 | n/a | range.location = 0; |
|---|
| 577 | n/a | range.length = size; |
|---|
| 578 | n/a | if( data == NULL ) return PyErr_NoMemory(); |
|---|
| 579 | n/a | CFStringGetCharacters(_self->ob_itself, range, data); |
|---|
| 580 | n/a | _res = (PyObject *)PyUnicode_FromUnicode(data, size-1); |
|---|
| 581 | n/a | free(data); |
|---|
| 582 | n/a | return _res; |
|---|
| 583 | n/a | """ |
|---|
| 584 | n/a | |
|---|
| 585 | n/a | f = ManualGenerator("CFStringGetUnicode", getasunicode_body); |
|---|
| 586 | n/a | f.docstring = lambda: "() -> (unicode _rv)" |
|---|
| 587 | n/a | CFStringRef_object.add(f) |
|---|
| 588 | n/a | |
|---|
| 589 | n/a | # Get data from CFDataRef |
|---|
| 590 | n/a | getasdata_body = """ |
|---|
| 591 | n/a | int size = CFDataGetLength(_self->ob_itself); |
|---|
| 592 | n/a | char *data = (char *)CFDataGetBytePtr(_self->ob_itself); |
|---|
| 593 | n/a | |
|---|
| 594 | n/a | _res = (PyObject *)PyString_FromStringAndSize(data, size); |
|---|
| 595 | n/a | return _res; |
|---|
| 596 | n/a | """ |
|---|
| 597 | n/a | |
|---|
| 598 | n/a | f = ManualGenerator("CFDataGetData", getasdata_body); |
|---|
| 599 | n/a | f.docstring = lambda: "() -> (string _rv)" |
|---|
| 600 | n/a | CFDataRef_object.add(f) |
|---|
| 601 | n/a | |
|---|
| 602 | n/a | # Manual generator for CFPropertyListCreateFromXMLData because of funny error return |
|---|
| 603 | n/a | fromxml_body = """ |
|---|
| 604 | n/a | CFTypeRef _rv; |
|---|
| 605 | n/a | CFOptionFlags mutabilityOption; |
|---|
| 606 | n/a | CFStringRef errorString; |
|---|
| 607 | n/a | if (!PyArg_ParseTuple(_args, "l", |
|---|
| 608 | n/a | &mutabilityOption)) |
|---|
| 609 | n/a | return NULL; |
|---|
| 610 | n/a | _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL, |
|---|
| 611 | n/a | _self->ob_itself, |
|---|
| 612 | n/a | mutabilityOption, |
|---|
| 613 | n/a | &errorString); |
|---|
| 614 | n/a | if (errorString) |
|---|
| 615 | n/a | CFRelease(errorString); |
|---|
| 616 | n/a | if (_rv == NULL) { |
|---|
| 617 | n/a | PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data"); |
|---|
| 618 | n/a | return NULL; |
|---|
| 619 | n/a | } |
|---|
| 620 | n/a | _res = Py_BuildValue("O&", |
|---|
| 621 | n/a | CFTypeRefObj_New, _rv); |
|---|
| 622 | n/a | return _res; |
|---|
| 623 | n/a | """ |
|---|
| 624 | n/a | f = ManualGenerator("CFPropertyListCreateFromXMLData", fromxml_body) |
|---|
| 625 | n/a | f.docstring = lambda: "(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)" |
|---|
| 626 | n/a | CFTypeRef_object.add(f) |
|---|
| 627 | n/a | |
|---|
| 628 | n/a | # Convert CF objects to Python objects |
|---|
| 629 | n/a | toPython_body = """ |
|---|
| 630 | n/a | _res = PyCF_CF2Python(_self->ob_itself); |
|---|
| 631 | n/a | return _res; |
|---|
| 632 | n/a | """ |
|---|
| 633 | n/a | |
|---|
| 634 | n/a | f = ManualGenerator("toPython", toPython_body); |
|---|
| 635 | n/a | f.docstring = lambda: "() -> (python_object)" |
|---|
| 636 | n/a | CFTypeRef_object.add(f) |
|---|
| 637 | n/a | |
|---|
| 638 | n/a | toCF_body = """ |
|---|
| 639 | n/a | CFTypeRef rv; |
|---|
| 640 | n/a | CFTypeID typeid; |
|---|
| 641 | n/a | |
|---|
| 642 | n/a | if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv)) |
|---|
| 643 | n/a | return NULL; |
|---|
| 644 | n/a | typeid = CFGetTypeID(rv); |
|---|
| 645 | n/a | |
|---|
| 646 | n/a | if (typeid == CFStringGetTypeID()) |
|---|
| 647 | n/a | return Py_BuildValue("O&", CFStringRefObj_New, rv); |
|---|
| 648 | n/a | if (typeid == CFArrayGetTypeID()) |
|---|
| 649 | n/a | return Py_BuildValue("O&", CFArrayRefObj_New, rv); |
|---|
| 650 | n/a | if (typeid == CFDictionaryGetTypeID()) |
|---|
| 651 | n/a | return Py_BuildValue("O&", CFDictionaryRefObj_New, rv); |
|---|
| 652 | n/a | if (typeid == CFURLGetTypeID()) |
|---|
| 653 | n/a | return Py_BuildValue("O&", CFURLRefObj_New, rv); |
|---|
| 654 | n/a | |
|---|
| 655 | n/a | _res = Py_BuildValue("O&", CFTypeRefObj_New, rv); |
|---|
| 656 | n/a | return _res; |
|---|
| 657 | n/a | """ |
|---|
| 658 | n/a | f = ManualGenerator("toCF", toCF_body); |
|---|
| 659 | n/a | f.docstring = lambda: "(python_object) -> (CF_object)" |
|---|
| 660 | n/a | module.add(f) |
|---|
| 661 | n/a | |
|---|
| 662 | n/a | # ADD add forloop here |
|---|
| 663 | n/a | |
|---|
| 664 | n/a | # generate output (open the output file as late as possible) |
|---|
| 665 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 666 | n/a | module.generate() |
|---|