Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module _CF =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Jack Jansen | 620a766 | 2001-12-18 15:39:38 +0000 | [diff] [blame^] | 8 | #ifdef _WIN32 |
| 9 | #include "pywintoolbox.h" |
| 10 | #else |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 11 | #include "macglue.h" |
| 12 | #include "pymactoolbox.h" |
Jack Jansen | 620a766 | 2001-12-18 15:39:38 +0000 | [diff] [blame^] | 13 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 14 | |
| 15 | /* Macro to test whether a weak-loaded CFM function exists */ |
| 16 | #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ |
| 17 | PyErr_SetString(PyExc_NotImplementedError, \ |
| 18 | "Not available in this shared library/OS version"); \ |
| 19 | return NULL; \ |
| 20 | }} while(0) |
| 21 | |
| 22 | |
| 23 | #ifdef WITHOUT_FRAMEWORKS |
| 24 | #include <CFBase.h> |
| 25 | #include <CFArray.h> |
| 26 | #include <CFData.h> |
| 27 | #include <CFDictionary.h> |
| 28 | #include <CFString.h> |
| 29 | #include <CFURL.h> |
| 30 | #else |
| 31 | #include <CoreServices/CoreServices.h> |
| 32 | #endif |
| 33 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 34 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 35 | extern PyObject *_CFTypeRefObj_New(CFTypeRef); |
| 36 | extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *); |
| 37 | #define CFTypeRefObj_New _CFTypeRefObj_New |
| 38 | #define CFTypeRefObj_Convert _CFTypeRefObj_Convert |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 39 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 40 | extern PyObject *_CFStringRefObj_New(CFStringRef); |
| 41 | extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *); |
| 42 | #define CFStringRefObj_New _CFStringRefObj_New |
| 43 | #define CFStringRefObj_Convert _CFStringRefObj_Convert |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 44 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 45 | extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef); |
| 46 | extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *); |
| 47 | #define CFMutableStringRefObj_New _CFMutableStringRefObj_New |
| 48 | #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 49 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 50 | extern PyObject *_CFArrayRefObj_New(CFArrayRef); |
| 51 | extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *); |
| 52 | #define CFArrayRefObj_New _CFArrayRefObj_New |
| 53 | #define CFArrayRefObj_Convert _CFArrayRefObj_Convert |
| 54 | |
| 55 | extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef); |
| 56 | extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *); |
| 57 | #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New |
| 58 | #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert |
| 59 | |
| 60 | extern PyObject *_CFDataRefObj_New(CFDataRef); |
| 61 | extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *); |
| 62 | #define CFDataRefObj_New _CFDataRefObj_New |
| 63 | #define CFDataRefObj_Convert _CFDataRefObj_Convert |
| 64 | |
| 65 | extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef); |
| 66 | extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *); |
| 67 | #define CFMutableDataRefObj_New _CFMutableDataRefObj_New |
| 68 | #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert |
| 69 | |
| 70 | extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef); |
| 71 | extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *); |
| 72 | #define CFDictionaryRefObj_New _CFDictionaryRefObj_New |
| 73 | #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert |
| 74 | |
| 75 | extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef); |
| 76 | extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *); |
| 77 | #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New |
| 78 | #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert |
| 79 | |
| 80 | extern PyObject *_CFURLRefObj_New(CFURLRef); |
| 81 | extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *); |
| 82 | extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *); |
| 83 | #define CFURLRefObj_New _CFURLRefObj_New |
| 84 | #define CFURLRefObj_Convert _CFURLRefObj_Convert |
| 85 | #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | /* |
| 89 | ** Parse/generate CFRange records |
| 90 | */ |
| 91 | PyObject *CFRange_New(CFRange *itself) |
| 92 | { |
| 93 | |
| 94 | return Py_BuildValue("ll", (long)itself->location, (long)itself->length); |
| 95 | } |
| 96 | |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 97 | int |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 98 | CFRange_Convert(PyObject *v, CFRange *p_itself) |
| 99 | { |
| 100 | long location, length; |
| 101 | |
| 102 | if( !PyArg_ParseTuple(v, "ll", &location, &length) ) |
| 103 | return 0; |
| 104 | p_itself->location = (CFIndex)location; |
| 105 | p_itself->length = (CFIndex)length; |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | /* Optional CFURL argument or None (passed as NULL) */ |
| 110 | int |
| 111 | OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself) |
| 112 | { |
| 113 | if ( v == Py_None ) { |
| 114 | p_itself = NULL; |
| 115 | return 1; |
| 116 | } |
| 117 | return CFURLRefObj_Convert(v, p_itself); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | static PyObject *CF_Error; |
| 122 | |
| 123 | /* --------------------- Object type CFTypeRef ---------------------- */ |
| 124 | |
| 125 | PyTypeObject CFTypeRef_Type; |
| 126 | |
| 127 | #define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type) |
| 128 | |
| 129 | typedef struct CFTypeRefObject { |
| 130 | PyObject_HEAD |
| 131 | CFTypeRef ob_itself; |
| 132 | void (*ob_freeit)(CFTypeRef ptr); |
| 133 | } CFTypeRefObject; |
| 134 | |
| 135 | PyObject *CFTypeRefObj_New(CFTypeRef itself) |
| 136 | { |
| 137 | CFTypeRefObject *it; |
| 138 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 139 | it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type); |
| 140 | if (it == NULL) return NULL; |
| 141 | it->ob_itself = itself; |
| 142 | it->ob_freeit = CFRelease; |
| 143 | return (PyObject *)it; |
| 144 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 145 | int CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 146 | { |
| 147 | |
| 148 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 149 | /* Check for other CF objects here */ |
| 150 | |
| 151 | if (!CFTypeRefObj_Check(v)) |
| 152 | { |
| 153 | PyErr_SetString(PyExc_TypeError, "CFTypeRef required"); |
| 154 | return 0; |
| 155 | } |
| 156 | *p_itself = ((CFTypeRefObject *)v)->ob_itself; |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | static void CFTypeRefObj_dealloc(CFTypeRefObject *self) |
| 161 | { |
| 162 | if (self->ob_freeit && self->ob_itself) |
| 163 | { |
| 164 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 165 | } |
| 166 | PyMem_DEL(self); |
| 167 | } |
| 168 | |
| 169 | static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args) |
| 170 | { |
| 171 | PyObject *_res = NULL; |
| 172 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 173 | #ifndef CFGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 174 | PyMac_PRECHECK(CFGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 175 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 176 | if (!PyArg_ParseTuple(_args, "")) |
| 177 | return NULL; |
| 178 | _rv = CFGetTypeID(_self->ob_itself); |
| 179 | _res = Py_BuildValue("l", |
| 180 | _rv); |
| 181 | return _res; |
| 182 | } |
| 183 | |
| 184 | static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args) |
| 185 | { |
| 186 | PyObject *_res = NULL; |
| 187 | CFTypeRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 188 | #ifndef CFRetain |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 189 | PyMac_PRECHECK(CFRetain); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 190 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 191 | if (!PyArg_ParseTuple(_args, "")) |
| 192 | return NULL; |
| 193 | _rv = CFRetain(_self->ob_itself); |
| 194 | _res = Py_BuildValue("O&", |
| 195 | CFTypeRefObj_New, _rv); |
| 196 | return _res; |
| 197 | } |
| 198 | |
| 199 | static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args) |
| 200 | { |
| 201 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 202 | #ifndef CFRelease |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 203 | PyMac_PRECHECK(CFRelease); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 204 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 205 | if (!PyArg_ParseTuple(_args, "")) |
| 206 | return NULL; |
| 207 | CFRelease(_self->ob_itself); |
| 208 | Py_INCREF(Py_None); |
| 209 | _res = Py_None; |
| 210 | return _res; |
| 211 | } |
| 212 | |
| 213 | static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args) |
| 214 | { |
| 215 | PyObject *_res = NULL; |
| 216 | CFIndex _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 217 | #ifndef CFGetRetainCount |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 218 | PyMac_PRECHECK(CFGetRetainCount); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 219 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 220 | if (!PyArg_ParseTuple(_args, "")) |
| 221 | return NULL; |
| 222 | _rv = CFGetRetainCount(_self->ob_itself); |
| 223 | _res = Py_BuildValue("l", |
| 224 | _rv); |
| 225 | return _res; |
| 226 | } |
| 227 | |
| 228 | static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args) |
| 229 | { |
| 230 | PyObject *_res = NULL; |
| 231 | Boolean _rv; |
| 232 | CFTypeRef cf2; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 233 | #ifndef CFEqual |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 234 | PyMac_PRECHECK(CFEqual); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 235 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 236 | if (!PyArg_ParseTuple(_args, "O&", |
| 237 | CFTypeRefObj_Convert, &cf2)) |
| 238 | return NULL; |
| 239 | _rv = CFEqual(_self->ob_itself, |
| 240 | cf2); |
| 241 | _res = Py_BuildValue("l", |
| 242 | _rv); |
| 243 | return _res; |
| 244 | } |
| 245 | |
| 246 | static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args) |
| 247 | { |
| 248 | PyObject *_res = NULL; |
| 249 | CFHashCode _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 250 | #ifndef CFHash |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 251 | PyMac_PRECHECK(CFHash); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 252 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 253 | if (!PyArg_ParseTuple(_args, "")) |
| 254 | return NULL; |
| 255 | _rv = CFHash(_self->ob_itself); |
| 256 | _res = Py_BuildValue("l", |
| 257 | _rv); |
| 258 | return _res; |
| 259 | } |
| 260 | |
| 261 | static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args) |
| 262 | { |
| 263 | PyObject *_res = NULL; |
| 264 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 265 | #ifndef CFCopyDescription |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 266 | PyMac_PRECHECK(CFCopyDescription); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 267 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 268 | if (!PyArg_ParseTuple(_args, "")) |
| 269 | return NULL; |
| 270 | _rv = CFCopyDescription(_self->ob_itself); |
| 271 | _res = Py_BuildValue("O&", |
| 272 | CFStringRefObj_New, _rv); |
| 273 | return _res; |
| 274 | } |
| 275 | |
| 276 | static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args) |
| 277 | { |
| 278 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 279 | #ifndef CFShow |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 280 | PyMac_PRECHECK(CFShow); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 281 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 282 | if (!PyArg_ParseTuple(_args, "")) |
| 283 | return NULL; |
| 284 | CFShow(_self->ob_itself); |
| 285 | Py_INCREF(Py_None); |
| 286 | _res = Py_None; |
| 287 | return _res; |
| 288 | } |
| 289 | |
| 290 | static PyMethodDef CFTypeRefObj_methods[] = { |
| 291 | {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1, |
| 292 | "() -> (CFTypeID _rv)"}, |
| 293 | {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1, |
| 294 | "() -> (CFTypeRef _rv)"}, |
| 295 | {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1, |
| 296 | "() -> None"}, |
| 297 | {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1, |
| 298 | "() -> (CFIndex _rv)"}, |
| 299 | {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1, |
| 300 | "(CFTypeRef cf2) -> (Boolean _rv)"}, |
| 301 | {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1, |
| 302 | "() -> (CFHashCode _rv)"}, |
| 303 | {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1, |
| 304 | "() -> (CFStringRef _rv)"}, |
| 305 | {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1, |
| 306 | "() -> None"}, |
| 307 | {NULL, NULL, 0} |
| 308 | }; |
| 309 | |
| 310 | PyMethodChain CFTypeRefObj_chain = { CFTypeRefObj_methods, NULL }; |
| 311 | |
| 312 | static PyObject *CFTypeRefObj_getattr(CFTypeRefObject *self, char *name) |
| 313 | { |
| 314 | return Py_FindMethodInChain(&CFTypeRefObj_chain, (PyObject *)self, name); |
| 315 | } |
| 316 | |
| 317 | #define CFTypeRefObj_setattr NULL |
| 318 | |
| 319 | static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other) |
| 320 | { |
| 321 | /* XXXX Or should we use CFEqual?? */ |
| 322 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 323 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self) |
| 328 | { |
| 329 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 330 | sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 331 | return PyString_FromString(buf); |
| 332 | } |
| 333 | |
| 334 | static int CFTypeRefObj_hash(CFTypeRefObject *self) |
| 335 | { |
| 336 | /* XXXX Or should we use CFHash?? */ |
| 337 | return (int)self->ob_itself; |
| 338 | } |
| 339 | |
| 340 | PyTypeObject CFTypeRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 341 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 342 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 343 | "_CF.CFTypeRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 344 | sizeof(CFTypeRefObject), /*tp_basicsize*/ |
| 345 | 0, /*tp_itemsize*/ |
| 346 | /* methods */ |
| 347 | (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/ |
| 348 | 0, /*tp_print*/ |
| 349 | (getattrfunc) CFTypeRefObj_getattr, /*tp_getattr*/ |
| 350 | (setattrfunc) CFTypeRefObj_setattr, /*tp_setattr*/ |
| 351 | (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/ |
| 352 | (reprfunc) CFTypeRefObj_repr, /*tp_repr*/ |
| 353 | (PyNumberMethods *)0, /* tp_as_number */ |
| 354 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 355 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 356 | (hashfunc) CFTypeRefObj_hash, /*tp_hash*/ |
| 357 | }; |
| 358 | |
| 359 | /* ------------------- End object type CFTypeRef -------------------- */ |
| 360 | |
| 361 | |
| 362 | /* --------------------- Object type CFArrayRef --------------------- */ |
| 363 | |
| 364 | PyTypeObject CFArrayRef_Type; |
| 365 | |
| 366 | #define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type) |
| 367 | |
| 368 | typedef struct CFArrayRefObject { |
| 369 | PyObject_HEAD |
| 370 | CFArrayRef ob_itself; |
| 371 | void (*ob_freeit)(CFTypeRef ptr); |
| 372 | } CFArrayRefObject; |
| 373 | |
| 374 | PyObject *CFArrayRefObj_New(CFArrayRef itself) |
| 375 | { |
| 376 | CFArrayRefObject *it; |
| 377 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 378 | it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type); |
| 379 | if (it == NULL) return NULL; |
| 380 | it->ob_itself = itself; |
| 381 | it->ob_freeit = CFRelease; |
| 382 | return (PyObject *)it; |
| 383 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 384 | int CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 385 | { |
| 386 | |
| 387 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 388 | /* Check for other CF objects here */ |
| 389 | |
| 390 | if (!CFArrayRefObj_Check(v)) |
| 391 | { |
| 392 | PyErr_SetString(PyExc_TypeError, "CFArrayRef required"); |
| 393 | return 0; |
| 394 | } |
| 395 | *p_itself = ((CFArrayRefObject *)v)->ob_itself; |
| 396 | return 1; |
| 397 | } |
| 398 | |
| 399 | static void CFArrayRefObj_dealloc(CFArrayRefObject *self) |
| 400 | { |
| 401 | if (self->ob_freeit && self->ob_itself) |
| 402 | { |
| 403 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 404 | } |
| 405 | PyMem_DEL(self); |
| 406 | } |
| 407 | |
| 408 | static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args) |
| 409 | { |
| 410 | PyObject *_res = NULL; |
| 411 | CFArrayRef _rv; |
| 412 | if (!PyArg_ParseTuple(_args, "")) |
| 413 | return NULL; |
| 414 | _rv = CFArrayCreateCopy((CFAllocatorRef)NULL, |
| 415 | _self->ob_itself); |
| 416 | _res = Py_BuildValue("O&", |
| 417 | CFArrayRefObj_New, _rv); |
| 418 | return _res; |
| 419 | } |
| 420 | |
| 421 | static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args) |
| 422 | { |
| 423 | PyObject *_res = NULL; |
| 424 | CFIndex _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 425 | #ifndef CFArrayGetCount |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 426 | PyMac_PRECHECK(CFArrayGetCount); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 427 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 428 | if (!PyArg_ParseTuple(_args, "")) |
| 429 | return NULL; |
| 430 | _rv = CFArrayGetCount(_self->ob_itself); |
| 431 | _res = Py_BuildValue("l", |
| 432 | _rv); |
| 433 | return _res; |
| 434 | } |
| 435 | |
| 436 | static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args) |
| 437 | { |
| 438 | PyObject *_res = NULL; |
| 439 | CFStringRef _rv; |
| 440 | CFStringRef separatorString; |
| 441 | if (!PyArg_ParseTuple(_args, "O&", |
| 442 | CFStringRefObj_Convert, &separatorString)) |
| 443 | return NULL; |
| 444 | _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL, |
| 445 | _self->ob_itself, |
| 446 | separatorString); |
| 447 | _res = Py_BuildValue("O&", |
| 448 | CFStringRefObj_New, _rv); |
| 449 | return _res; |
| 450 | } |
| 451 | |
| 452 | static PyMethodDef CFArrayRefObj_methods[] = { |
| 453 | {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1, |
| 454 | "() -> (CFArrayRef _rv)"}, |
| 455 | {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1, |
| 456 | "() -> (CFIndex _rv)"}, |
| 457 | {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1, |
| 458 | "(CFStringRef separatorString) -> (CFStringRef _rv)"}, |
| 459 | {NULL, NULL, 0} |
| 460 | }; |
| 461 | |
| 462 | PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, &CFTypeRefObj_chain }; |
| 463 | |
| 464 | static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name) |
| 465 | { |
| 466 | return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name); |
| 467 | } |
| 468 | |
| 469 | #define CFArrayRefObj_setattr NULL |
| 470 | |
| 471 | static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other) |
| 472 | { |
| 473 | /* XXXX Or should we use CFEqual?? */ |
| 474 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 475 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self) |
| 480 | { |
| 481 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 482 | sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 483 | return PyString_FromString(buf); |
| 484 | } |
| 485 | |
| 486 | static int CFArrayRefObj_hash(CFArrayRefObject *self) |
| 487 | { |
| 488 | /* XXXX Or should we use CFHash?? */ |
| 489 | return (int)self->ob_itself; |
| 490 | } |
| 491 | |
| 492 | PyTypeObject CFArrayRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 493 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 494 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 495 | "_CF.CFArrayRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 496 | sizeof(CFArrayRefObject), /*tp_basicsize*/ |
| 497 | 0, /*tp_itemsize*/ |
| 498 | /* methods */ |
| 499 | (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/ |
| 500 | 0, /*tp_print*/ |
| 501 | (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/ |
| 502 | (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/ |
| 503 | (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/ |
| 504 | (reprfunc) CFArrayRefObj_repr, /*tp_repr*/ |
| 505 | (PyNumberMethods *)0, /* tp_as_number */ |
| 506 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 507 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 508 | (hashfunc) CFArrayRefObj_hash, /*tp_hash*/ |
| 509 | }; |
| 510 | |
| 511 | /* ------------------- End object type CFArrayRef ------------------- */ |
| 512 | |
| 513 | |
| 514 | /* ----------------- Object type CFMutableArrayRef ------------------ */ |
| 515 | |
| 516 | PyTypeObject CFMutableArrayRef_Type; |
| 517 | |
| 518 | #define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type) |
| 519 | |
| 520 | typedef struct CFMutableArrayRefObject { |
| 521 | PyObject_HEAD |
| 522 | CFMutableArrayRef ob_itself; |
| 523 | void (*ob_freeit)(CFTypeRef ptr); |
| 524 | } CFMutableArrayRefObject; |
| 525 | |
| 526 | PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself) |
| 527 | { |
| 528 | CFMutableArrayRefObject *it; |
| 529 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 530 | it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type); |
| 531 | if (it == NULL) return NULL; |
| 532 | it->ob_itself = itself; |
| 533 | it->ob_freeit = CFRelease; |
| 534 | return (PyObject *)it; |
| 535 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 536 | int CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 537 | { |
| 538 | |
| 539 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 540 | /* Check for other CF objects here */ |
| 541 | |
| 542 | if (!CFMutableArrayRefObj_Check(v)) |
| 543 | { |
| 544 | PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required"); |
| 545 | return 0; |
| 546 | } |
| 547 | *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself; |
| 548 | return 1; |
| 549 | } |
| 550 | |
| 551 | static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self) |
| 552 | { |
| 553 | if (self->ob_freeit && self->ob_itself) |
| 554 | { |
| 555 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 556 | } |
| 557 | PyMem_DEL(self); |
| 558 | } |
| 559 | |
| 560 | static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args) |
| 561 | { |
| 562 | PyObject *_res = NULL; |
| 563 | CFIndex idx; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 564 | #ifndef CFArrayRemoveValueAtIndex |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 565 | PyMac_PRECHECK(CFArrayRemoveValueAtIndex); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 566 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 567 | if (!PyArg_ParseTuple(_args, "l", |
| 568 | &idx)) |
| 569 | return NULL; |
| 570 | CFArrayRemoveValueAtIndex(_self->ob_itself, |
| 571 | idx); |
| 572 | Py_INCREF(Py_None); |
| 573 | _res = Py_None; |
| 574 | return _res; |
| 575 | } |
| 576 | |
| 577 | static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args) |
| 578 | { |
| 579 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 580 | #ifndef CFArrayRemoveAllValues |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 581 | PyMac_PRECHECK(CFArrayRemoveAllValues); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 582 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 583 | if (!PyArg_ParseTuple(_args, "")) |
| 584 | return NULL; |
| 585 | CFArrayRemoveAllValues(_self->ob_itself); |
| 586 | Py_INCREF(Py_None); |
| 587 | _res = Py_None; |
| 588 | return _res; |
| 589 | } |
| 590 | |
| 591 | static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args) |
| 592 | { |
| 593 | PyObject *_res = NULL; |
| 594 | CFIndex idx1; |
| 595 | CFIndex idx2; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 596 | #ifndef CFArrayExchangeValuesAtIndices |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 597 | PyMac_PRECHECK(CFArrayExchangeValuesAtIndices); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 598 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 599 | if (!PyArg_ParseTuple(_args, "ll", |
| 600 | &idx1, |
| 601 | &idx2)) |
| 602 | return NULL; |
| 603 | CFArrayExchangeValuesAtIndices(_self->ob_itself, |
| 604 | idx1, |
| 605 | idx2); |
| 606 | Py_INCREF(Py_None); |
| 607 | _res = Py_None; |
| 608 | return _res; |
| 609 | } |
| 610 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 611 | static PyObject *CFMutableArrayRefObj_CFArrayAppendArray(CFMutableArrayRefObject *_self, PyObject *_args) |
| 612 | { |
| 613 | PyObject *_res = NULL; |
| 614 | CFArrayRef otherArray; |
| 615 | CFRange otherRange; |
| 616 | #ifndef CFArrayAppendArray |
| 617 | PyMac_PRECHECK(CFArrayAppendArray); |
| 618 | #endif |
| 619 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 620 | CFArrayRefObj_Convert, &otherArray, |
| 621 | CFRange_Convert, &otherRange)) |
| 622 | return NULL; |
| 623 | CFArrayAppendArray(_self->ob_itself, |
| 624 | otherArray, |
| 625 | otherRange); |
| 626 | Py_INCREF(Py_None); |
| 627 | _res = Py_None; |
| 628 | return _res; |
| 629 | } |
| 630 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 631 | static PyMethodDef CFMutableArrayRefObj_methods[] = { |
| 632 | {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1, |
| 633 | "(CFIndex idx) -> None"}, |
| 634 | {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1, |
| 635 | "() -> None"}, |
| 636 | {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1, |
| 637 | "(CFIndex idx1, CFIndex idx2) -> None"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 638 | {"CFArrayAppendArray", (PyCFunction)CFMutableArrayRefObj_CFArrayAppendArray, 1, |
| 639 | "(CFArrayRef otherArray, CFRange otherRange) -> None"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 640 | {NULL, NULL, 0} |
| 641 | }; |
| 642 | |
| 643 | PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, &CFArrayRefObj_chain }; |
| 644 | |
| 645 | static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name) |
| 646 | { |
| 647 | return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name); |
| 648 | } |
| 649 | |
| 650 | #define CFMutableArrayRefObj_setattr NULL |
| 651 | |
| 652 | static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other) |
| 653 | { |
| 654 | /* XXXX Or should we use CFEqual?? */ |
| 655 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 656 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self) |
| 661 | { |
| 662 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 663 | sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 664 | return PyString_FromString(buf); |
| 665 | } |
| 666 | |
| 667 | static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self) |
| 668 | { |
| 669 | /* XXXX Or should we use CFHash?? */ |
| 670 | return (int)self->ob_itself; |
| 671 | } |
| 672 | |
| 673 | PyTypeObject CFMutableArrayRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 674 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 675 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 676 | "_CF.CFMutableArrayRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 677 | sizeof(CFMutableArrayRefObject), /*tp_basicsize*/ |
| 678 | 0, /*tp_itemsize*/ |
| 679 | /* methods */ |
| 680 | (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/ |
| 681 | 0, /*tp_print*/ |
| 682 | (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/ |
| 683 | (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/ |
| 684 | (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/ |
| 685 | (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/ |
| 686 | (PyNumberMethods *)0, /* tp_as_number */ |
| 687 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 688 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 689 | (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/ |
| 690 | }; |
| 691 | |
| 692 | /* --------------- End object type CFMutableArrayRef ---------------- */ |
| 693 | |
| 694 | |
| 695 | /* ------------------ Object type CFDictionaryRef ------------------- */ |
| 696 | |
| 697 | PyTypeObject CFDictionaryRef_Type; |
| 698 | |
| 699 | #define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type) |
| 700 | |
| 701 | typedef struct CFDictionaryRefObject { |
| 702 | PyObject_HEAD |
| 703 | CFDictionaryRef ob_itself; |
| 704 | void (*ob_freeit)(CFTypeRef ptr); |
| 705 | } CFDictionaryRefObject; |
| 706 | |
| 707 | PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself) |
| 708 | { |
| 709 | CFDictionaryRefObject *it; |
| 710 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 711 | it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type); |
| 712 | if (it == NULL) return NULL; |
| 713 | it->ob_itself = itself; |
| 714 | it->ob_freeit = CFRelease; |
| 715 | return (PyObject *)it; |
| 716 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 717 | int CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 718 | { |
| 719 | |
| 720 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 721 | /* Check for other CF objects here */ |
| 722 | |
| 723 | if (!CFDictionaryRefObj_Check(v)) |
| 724 | { |
| 725 | PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required"); |
| 726 | return 0; |
| 727 | } |
| 728 | *p_itself = ((CFDictionaryRefObject *)v)->ob_itself; |
| 729 | return 1; |
| 730 | } |
| 731 | |
| 732 | static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self) |
| 733 | { |
| 734 | if (self->ob_freeit && self->ob_itself) |
| 735 | { |
| 736 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 737 | } |
| 738 | PyMem_DEL(self); |
| 739 | } |
| 740 | |
| 741 | static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args) |
| 742 | { |
| 743 | PyObject *_res = NULL; |
| 744 | CFDictionaryRef _rv; |
| 745 | if (!PyArg_ParseTuple(_args, "")) |
| 746 | return NULL; |
| 747 | _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL, |
| 748 | _self->ob_itself); |
| 749 | _res = Py_BuildValue("O&", |
| 750 | CFDictionaryRefObj_New, _rv); |
| 751 | return _res; |
| 752 | } |
| 753 | |
| 754 | static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args) |
| 755 | { |
| 756 | PyObject *_res = NULL; |
| 757 | CFIndex _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 758 | #ifndef CFDictionaryGetCount |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 759 | PyMac_PRECHECK(CFDictionaryGetCount); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 760 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 761 | if (!PyArg_ParseTuple(_args, "")) |
| 762 | return NULL; |
| 763 | _rv = CFDictionaryGetCount(_self->ob_itself); |
| 764 | _res = Py_BuildValue("l", |
| 765 | _rv); |
| 766 | return _res; |
| 767 | } |
| 768 | |
| 769 | static PyMethodDef CFDictionaryRefObj_methods[] = { |
| 770 | {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1, |
| 771 | "() -> (CFDictionaryRef _rv)"}, |
| 772 | {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1, |
| 773 | "() -> (CFIndex _rv)"}, |
| 774 | {NULL, NULL, 0} |
| 775 | }; |
| 776 | |
| 777 | PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, &CFTypeRefObj_chain }; |
| 778 | |
| 779 | static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name) |
| 780 | { |
| 781 | return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name); |
| 782 | } |
| 783 | |
| 784 | #define CFDictionaryRefObj_setattr NULL |
| 785 | |
| 786 | static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other) |
| 787 | { |
| 788 | /* XXXX Or should we use CFEqual?? */ |
| 789 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 790 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self) |
| 795 | { |
| 796 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 797 | sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 798 | return PyString_FromString(buf); |
| 799 | } |
| 800 | |
| 801 | static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self) |
| 802 | { |
| 803 | /* XXXX Or should we use CFHash?? */ |
| 804 | return (int)self->ob_itself; |
| 805 | } |
| 806 | |
| 807 | PyTypeObject CFDictionaryRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 808 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 809 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 810 | "_CF.CFDictionaryRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 811 | sizeof(CFDictionaryRefObject), /*tp_basicsize*/ |
| 812 | 0, /*tp_itemsize*/ |
| 813 | /* methods */ |
| 814 | (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/ |
| 815 | 0, /*tp_print*/ |
| 816 | (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/ |
| 817 | (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/ |
| 818 | (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/ |
| 819 | (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/ |
| 820 | (PyNumberMethods *)0, /* tp_as_number */ |
| 821 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 822 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 823 | (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/ |
| 824 | }; |
| 825 | |
| 826 | /* ---------------- End object type CFDictionaryRef ----------------- */ |
| 827 | |
| 828 | |
| 829 | /* --------------- Object type CFMutableDictionaryRef --------------- */ |
| 830 | |
| 831 | PyTypeObject CFMutableDictionaryRef_Type; |
| 832 | |
| 833 | #define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type) |
| 834 | |
| 835 | typedef struct CFMutableDictionaryRefObject { |
| 836 | PyObject_HEAD |
| 837 | CFMutableDictionaryRef ob_itself; |
| 838 | void (*ob_freeit)(CFTypeRef ptr); |
| 839 | } CFMutableDictionaryRefObject; |
| 840 | |
| 841 | PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself) |
| 842 | { |
| 843 | CFMutableDictionaryRefObject *it; |
| 844 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 845 | it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type); |
| 846 | if (it == NULL) return NULL; |
| 847 | it->ob_itself = itself; |
| 848 | it->ob_freeit = CFRelease; |
| 849 | return (PyObject *)it; |
| 850 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 851 | int CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 852 | { |
| 853 | |
| 854 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 855 | /* Check for other CF objects here */ |
| 856 | |
| 857 | if (!CFMutableDictionaryRefObj_Check(v)) |
| 858 | { |
| 859 | PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required"); |
| 860 | return 0; |
| 861 | } |
| 862 | *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself; |
| 863 | return 1; |
| 864 | } |
| 865 | |
| 866 | static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self) |
| 867 | { |
| 868 | if (self->ob_freeit && self->ob_itself) |
| 869 | { |
| 870 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 871 | } |
| 872 | PyMem_DEL(self); |
| 873 | } |
| 874 | |
| 875 | static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args) |
| 876 | { |
| 877 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 878 | #ifndef CFDictionaryRemoveAllValues |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 879 | PyMac_PRECHECK(CFDictionaryRemoveAllValues); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 880 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 881 | if (!PyArg_ParseTuple(_args, "")) |
| 882 | return NULL; |
| 883 | CFDictionaryRemoveAllValues(_self->ob_itself); |
| 884 | Py_INCREF(Py_None); |
| 885 | _res = Py_None; |
| 886 | return _res; |
| 887 | } |
| 888 | |
| 889 | static PyMethodDef CFMutableDictionaryRefObj_methods[] = { |
| 890 | {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1, |
| 891 | "() -> None"}, |
| 892 | {NULL, NULL, 0} |
| 893 | }; |
| 894 | |
| 895 | PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, &CFDictionaryRefObj_chain }; |
| 896 | |
| 897 | static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name) |
| 898 | { |
| 899 | return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name); |
| 900 | } |
| 901 | |
| 902 | #define CFMutableDictionaryRefObj_setattr NULL |
| 903 | |
| 904 | static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other) |
| 905 | { |
| 906 | /* XXXX Or should we use CFEqual?? */ |
| 907 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 908 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self) |
| 913 | { |
| 914 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 915 | sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 916 | return PyString_FromString(buf); |
| 917 | } |
| 918 | |
| 919 | static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self) |
| 920 | { |
| 921 | /* XXXX Or should we use CFHash?? */ |
| 922 | return (int)self->ob_itself; |
| 923 | } |
| 924 | |
| 925 | PyTypeObject CFMutableDictionaryRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 926 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 927 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 928 | "_CF.CFMutableDictionaryRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 929 | sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/ |
| 930 | 0, /*tp_itemsize*/ |
| 931 | /* methods */ |
| 932 | (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/ |
| 933 | 0, /*tp_print*/ |
| 934 | (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/ |
| 935 | (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/ |
| 936 | (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/ |
| 937 | (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/ |
| 938 | (PyNumberMethods *)0, /* tp_as_number */ |
| 939 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 940 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 941 | (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/ |
| 942 | }; |
| 943 | |
| 944 | /* ------------- End object type CFMutableDictionaryRef ------------- */ |
| 945 | |
| 946 | |
| 947 | /* --------------------- Object type CFDataRef ---------------------- */ |
| 948 | |
| 949 | PyTypeObject CFDataRef_Type; |
| 950 | |
| 951 | #define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type) |
| 952 | |
| 953 | typedef struct CFDataRefObject { |
| 954 | PyObject_HEAD |
| 955 | CFDataRef ob_itself; |
| 956 | void (*ob_freeit)(CFTypeRef ptr); |
| 957 | } CFDataRefObject; |
| 958 | |
| 959 | PyObject *CFDataRefObj_New(CFDataRef itself) |
| 960 | { |
| 961 | CFDataRefObject *it; |
| 962 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 963 | it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type); |
| 964 | if (it == NULL) return NULL; |
| 965 | it->ob_itself = itself; |
| 966 | it->ob_freeit = CFRelease; |
| 967 | return (PyObject *)it; |
| 968 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 969 | int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 970 | { |
| 971 | |
| 972 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 973 | /* Check for other CF objects here */ |
| 974 | |
| 975 | if (!CFDataRefObj_Check(v)) |
| 976 | { |
| 977 | PyErr_SetString(PyExc_TypeError, "CFDataRef required"); |
| 978 | return 0; |
| 979 | } |
| 980 | *p_itself = ((CFDataRefObject *)v)->ob_itself; |
| 981 | return 1; |
| 982 | } |
| 983 | |
| 984 | static void CFDataRefObj_dealloc(CFDataRefObject *self) |
| 985 | { |
| 986 | if (self->ob_freeit && self->ob_itself) |
| 987 | { |
| 988 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 989 | } |
| 990 | PyMem_DEL(self); |
| 991 | } |
| 992 | |
| 993 | static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args) |
| 994 | { |
| 995 | PyObject *_res = NULL; |
| 996 | CFDataRef _rv; |
| 997 | if (!PyArg_ParseTuple(_args, "")) |
| 998 | return NULL; |
| 999 | _rv = CFDataCreateCopy((CFAllocatorRef)NULL, |
| 1000 | _self->ob_itself); |
| 1001 | _res = Py_BuildValue("O&", |
| 1002 | CFDataRefObj_New, _rv); |
| 1003 | return _res; |
| 1004 | } |
| 1005 | |
| 1006 | static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args) |
| 1007 | { |
| 1008 | PyObject *_res = NULL; |
| 1009 | CFIndex _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1010 | #ifndef CFDataGetLength |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1011 | PyMac_PRECHECK(CFDataGetLength); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1012 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1013 | if (!PyArg_ParseTuple(_args, "")) |
| 1014 | return NULL; |
| 1015 | _rv = CFDataGetLength(_self->ob_itself); |
| 1016 | _res = Py_BuildValue("l", |
| 1017 | _rv); |
| 1018 | return _res; |
| 1019 | } |
| 1020 | |
| 1021 | static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args) |
| 1022 | { |
| 1023 | PyObject *_res = NULL; |
| 1024 | CFStringRef _rv; |
| 1025 | CFStringEncoding encoding; |
| 1026 | if (!PyArg_ParseTuple(_args, "l", |
| 1027 | &encoding)) |
| 1028 | return NULL; |
| 1029 | _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL, |
| 1030 | _self->ob_itself, |
| 1031 | encoding); |
| 1032 | _res = Py_BuildValue("O&", |
| 1033 | CFStringRefObj_New, _rv); |
| 1034 | return _res; |
| 1035 | } |
| 1036 | |
| 1037 | static PyMethodDef CFDataRefObj_methods[] = { |
| 1038 | {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1, |
| 1039 | "() -> (CFDataRef _rv)"}, |
| 1040 | {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1, |
| 1041 | "() -> (CFIndex _rv)"}, |
| 1042 | {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1, |
| 1043 | "(CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
| 1044 | {NULL, NULL, 0} |
| 1045 | }; |
| 1046 | |
| 1047 | PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, &CFTypeRefObj_chain }; |
| 1048 | |
| 1049 | static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name) |
| 1050 | { |
| 1051 | return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name); |
| 1052 | } |
| 1053 | |
| 1054 | #define CFDataRefObj_setattr NULL |
| 1055 | |
| 1056 | static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other) |
| 1057 | { |
| 1058 | /* XXXX Or should we use CFEqual?? */ |
| 1059 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 1060 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | static PyObject * CFDataRefObj_repr(CFDataRefObject *self) |
| 1065 | { |
| 1066 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 1067 | sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1068 | return PyString_FromString(buf); |
| 1069 | } |
| 1070 | |
| 1071 | static int CFDataRefObj_hash(CFDataRefObject *self) |
| 1072 | { |
| 1073 | /* XXXX Or should we use CFHash?? */ |
| 1074 | return (int)self->ob_itself; |
| 1075 | } |
| 1076 | |
| 1077 | PyTypeObject CFDataRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1078 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1079 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 1080 | "_CF.CFDataRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1081 | sizeof(CFDataRefObject), /*tp_basicsize*/ |
| 1082 | 0, /*tp_itemsize*/ |
| 1083 | /* methods */ |
| 1084 | (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/ |
| 1085 | 0, /*tp_print*/ |
| 1086 | (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/ |
| 1087 | (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/ |
| 1088 | (cmpfunc) CFDataRefObj_compare, /*tp_compare*/ |
| 1089 | (reprfunc) CFDataRefObj_repr, /*tp_repr*/ |
| 1090 | (PyNumberMethods *)0, /* tp_as_number */ |
| 1091 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 1092 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 1093 | (hashfunc) CFDataRefObj_hash, /*tp_hash*/ |
| 1094 | }; |
| 1095 | |
| 1096 | /* ------------------- End object type CFDataRef -------------------- */ |
| 1097 | |
| 1098 | |
| 1099 | /* ------------------ Object type CFMutableDataRef ------------------ */ |
| 1100 | |
| 1101 | PyTypeObject CFMutableDataRef_Type; |
| 1102 | |
| 1103 | #define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type) |
| 1104 | |
| 1105 | typedef struct CFMutableDataRefObject { |
| 1106 | PyObject_HEAD |
| 1107 | CFMutableDataRef ob_itself; |
| 1108 | void (*ob_freeit)(CFTypeRef ptr); |
| 1109 | } CFMutableDataRefObject; |
| 1110 | |
| 1111 | PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself) |
| 1112 | { |
| 1113 | CFMutableDataRefObject *it; |
| 1114 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 1115 | it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type); |
| 1116 | if (it == NULL) return NULL; |
| 1117 | it->ob_itself = itself; |
| 1118 | it->ob_freeit = CFRelease; |
| 1119 | return (PyObject *)it; |
| 1120 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 1121 | int CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1122 | { |
| 1123 | |
| 1124 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 1125 | /* Check for other CF objects here */ |
| 1126 | |
| 1127 | if (!CFMutableDataRefObj_Check(v)) |
| 1128 | { |
| 1129 | PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required"); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | *p_itself = ((CFMutableDataRefObject *)v)->ob_itself; |
| 1133 | return 1; |
| 1134 | } |
| 1135 | |
| 1136 | static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self) |
| 1137 | { |
| 1138 | if (self->ob_freeit && self->ob_itself) |
| 1139 | { |
| 1140 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 1141 | } |
| 1142 | PyMem_DEL(self); |
| 1143 | } |
| 1144 | |
| 1145 | static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args) |
| 1146 | { |
| 1147 | PyObject *_res = NULL; |
| 1148 | CFIndex length; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1149 | #ifndef CFDataSetLength |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1150 | PyMac_PRECHECK(CFDataSetLength); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1151 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1152 | if (!PyArg_ParseTuple(_args, "l", |
| 1153 | &length)) |
| 1154 | return NULL; |
| 1155 | CFDataSetLength(_self->ob_itself, |
| 1156 | length); |
| 1157 | Py_INCREF(Py_None); |
| 1158 | _res = Py_None; |
| 1159 | return _res; |
| 1160 | } |
| 1161 | |
| 1162 | static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args) |
| 1163 | { |
| 1164 | PyObject *_res = NULL; |
| 1165 | CFIndex extraLength; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1166 | #ifndef CFDataIncreaseLength |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1167 | PyMac_PRECHECK(CFDataIncreaseLength); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1168 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1169 | if (!PyArg_ParseTuple(_args, "l", |
| 1170 | &extraLength)) |
| 1171 | return NULL; |
| 1172 | CFDataIncreaseLength(_self->ob_itself, |
| 1173 | extraLength); |
| 1174 | Py_INCREF(Py_None); |
| 1175 | _res = Py_None; |
| 1176 | return _res; |
| 1177 | } |
| 1178 | |
| 1179 | static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args) |
| 1180 | { |
| 1181 | PyObject *_res = NULL; |
| 1182 | unsigned char *bytes__in__; |
| 1183 | long bytes__len__; |
| 1184 | int bytes__in_len__; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1185 | #ifndef CFDataAppendBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1186 | PyMac_PRECHECK(CFDataAppendBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1187 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1188 | if (!PyArg_ParseTuple(_args, "s#", |
| 1189 | &bytes__in__, &bytes__in_len__)) |
| 1190 | return NULL; |
| 1191 | bytes__len__ = bytes__in_len__; |
| 1192 | CFDataAppendBytes(_self->ob_itself, |
| 1193 | bytes__in__, bytes__len__); |
| 1194 | Py_INCREF(Py_None); |
| 1195 | _res = Py_None; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1196 | return _res; |
| 1197 | } |
| 1198 | |
| 1199 | static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args) |
| 1200 | { |
| 1201 | PyObject *_res = NULL; |
| 1202 | CFRange range; |
| 1203 | unsigned char *newBytes__in__; |
| 1204 | long newBytes__len__; |
| 1205 | int newBytes__in_len__; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1206 | #ifndef CFDataReplaceBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1207 | PyMac_PRECHECK(CFDataReplaceBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1208 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1209 | if (!PyArg_ParseTuple(_args, "O&s#", |
| 1210 | CFRange_Convert, &range, |
| 1211 | &newBytes__in__, &newBytes__in_len__)) |
| 1212 | return NULL; |
| 1213 | newBytes__len__ = newBytes__in_len__; |
| 1214 | CFDataReplaceBytes(_self->ob_itself, |
| 1215 | range, |
| 1216 | newBytes__in__, newBytes__len__); |
| 1217 | Py_INCREF(Py_None); |
| 1218 | _res = Py_None; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1219 | return _res; |
| 1220 | } |
| 1221 | |
| 1222 | static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args) |
| 1223 | { |
| 1224 | PyObject *_res = NULL; |
| 1225 | CFRange range; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1226 | #ifndef CFDataDeleteBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1227 | PyMac_PRECHECK(CFDataDeleteBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1228 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1229 | if (!PyArg_ParseTuple(_args, "O&", |
| 1230 | CFRange_Convert, &range)) |
| 1231 | return NULL; |
| 1232 | CFDataDeleteBytes(_self->ob_itself, |
| 1233 | range); |
| 1234 | Py_INCREF(Py_None); |
| 1235 | _res = Py_None; |
| 1236 | return _res; |
| 1237 | } |
| 1238 | |
| 1239 | static PyMethodDef CFMutableDataRefObj_methods[] = { |
| 1240 | {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1, |
| 1241 | "(CFIndex length) -> None"}, |
| 1242 | {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1, |
| 1243 | "(CFIndex extraLength) -> None"}, |
| 1244 | {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1, |
| 1245 | "(Buffer bytes) -> None"}, |
| 1246 | {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1, |
| 1247 | "(CFRange range, Buffer newBytes) -> None"}, |
| 1248 | {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1, |
| 1249 | "(CFRange range) -> None"}, |
| 1250 | {NULL, NULL, 0} |
| 1251 | }; |
| 1252 | |
| 1253 | PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, &CFDataRefObj_chain }; |
| 1254 | |
| 1255 | static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name) |
| 1256 | { |
| 1257 | return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name); |
| 1258 | } |
| 1259 | |
| 1260 | #define CFMutableDataRefObj_setattr NULL |
| 1261 | |
| 1262 | static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other) |
| 1263 | { |
| 1264 | /* XXXX Or should we use CFEqual?? */ |
| 1265 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 1266 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self) |
| 1271 | { |
| 1272 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 1273 | sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1274 | return PyString_FromString(buf); |
| 1275 | } |
| 1276 | |
| 1277 | static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self) |
| 1278 | { |
| 1279 | /* XXXX Or should we use CFHash?? */ |
| 1280 | return (int)self->ob_itself; |
| 1281 | } |
| 1282 | |
| 1283 | PyTypeObject CFMutableDataRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1284 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1285 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 1286 | "_CF.CFMutableDataRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1287 | sizeof(CFMutableDataRefObject), /*tp_basicsize*/ |
| 1288 | 0, /*tp_itemsize*/ |
| 1289 | /* methods */ |
| 1290 | (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/ |
| 1291 | 0, /*tp_print*/ |
| 1292 | (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/ |
| 1293 | (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/ |
| 1294 | (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/ |
| 1295 | (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/ |
| 1296 | (PyNumberMethods *)0, /* tp_as_number */ |
| 1297 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 1298 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 1299 | (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/ |
| 1300 | }; |
| 1301 | |
| 1302 | /* ---------------- End object type CFMutableDataRef ---------------- */ |
| 1303 | |
| 1304 | |
| 1305 | /* -------------------- Object type CFStringRef --------------------- */ |
| 1306 | |
| 1307 | PyTypeObject CFStringRef_Type; |
| 1308 | |
| 1309 | #define CFStringRefObj_Check(x) ((x)->ob_type == &CFStringRef_Type) |
| 1310 | |
| 1311 | typedef struct CFStringRefObject { |
| 1312 | PyObject_HEAD |
| 1313 | CFStringRef ob_itself; |
| 1314 | void (*ob_freeit)(CFTypeRef ptr); |
| 1315 | } CFStringRefObject; |
| 1316 | |
| 1317 | PyObject *CFStringRefObj_New(CFStringRef itself) |
| 1318 | { |
| 1319 | CFStringRefObject *it; |
| 1320 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 1321 | it = PyObject_NEW(CFStringRefObject, &CFStringRef_Type); |
| 1322 | if (it == NULL) return NULL; |
| 1323 | it->ob_itself = itself; |
| 1324 | it->ob_freeit = CFRelease; |
| 1325 | return (PyObject *)it; |
| 1326 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 1327 | int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1328 | { |
| 1329 | |
| 1330 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 1331 | if (PyString_Check(v)) { |
| 1332 | char *cStr = PyString_AsString(v); |
| 1333 | *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0); |
| 1334 | return 1; |
| 1335 | } |
| 1336 | if (PyUnicode_Check(v)) { |
| 1337 | /* We use the CF types here, if Python was configured differently that will give an error */ |
| 1338 | CFIndex size = PyUnicode_GetSize(v); |
| 1339 | UniChar *unichars = PyUnicode_AsUnicode(v); |
| 1340 | if (!unichars) return 0; |
| 1341 | *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size); |
| 1342 | return 1; |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | if (!CFStringRefObj_Check(v)) |
| 1347 | { |
| 1348 | PyErr_SetString(PyExc_TypeError, "CFStringRef required"); |
| 1349 | return 0; |
| 1350 | } |
| 1351 | *p_itself = ((CFStringRefObject *)v)->ob_itself; |
| 1352 | return 1; |
| 1353 | } |
| 1354 | |
| 1355 | static void CFStringRefObj_dealloc(CFStringRefObject *self) |
| 1356 | { |
| 1357 | if (self->ob_freeit && self->ob_itself) |
| 1358 | { |
| 1359 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 1360 | } |
| 1361 | PyMem_DEL(self); |
| 1362 | } |
| 1363 | |
| 1364 | static PyObject *CFStringRefObj_CFStringCreateWithSubstring(CFStringRefObject *_self, PyObject *_args) |
| 1365 | { |
| 1366 | PyObject *_res = NULL; |
| 1367 | CFStringRef _rv; |
| 1368 | CFRange range; |
| 1369 | if (!PyArg_ParseTuple(_args, "O&", |
| 1370 | CFRange_Convert, &range)) |
| 1371 | return NULL; |
| 1372 | _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL, |
| 1373 | _self->ob_itself, |
| 1374 | range); |
| 1375 | _res = Py_BuildValue("O&", |
| 1376 | CFStringRefObj_New, _rv); |
| 1377 | return _res; |
| 1378 | } |
| 1379 | |
| 1380 | static PyObject *CFStringRefObj_CFStringCreateCopy(CFStringRefObject *_self, PyObject *_args) |
| 1381 | { |
| 1382 | PyObject *_res = NULL; |
| 1383 | CFStringRef _rv; |
| 1384 | if (!PyArg_ParseTuple(_args, "")) |
| 1385 | return NULL; |
| 1386 | _rv = CFStringCreateCopy((CFAllocatorRef)NULL, |
| 1387 | _self->ob_itself); |
| 1388 | _res = Py_BuildValue("O&", |
| 1389 | CFStringRefObj_New, _rv); |
| 1390 | return _res; |
| 1391 | } |
| 1392 | |
| 1393 | static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args) |
| 1394 | { |
| 1395 | PyObject *_res = NULL; |
| 1396 | CFIndex _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1397 | #ifndef CFStringGetLength |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1398 | PyMac_PRECHECK(CFStringGetLength); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1399 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1400 | if (!PyArg_ParseTuple(_args, "")) |
| 1401 | return NULL; |
| 1402 | _rv = CFStringGetLength(_self->ob_itself); |
| 1403 | _res = Py_BuildValue("l", |
| 1404 | _rv); |
| 1405 | return _res; |
| 1406 | } |
| 1407 | |
| 1408 | static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args) |
| 1409 | { |
| 1410 | PyObject *_res = NULL; |
| 1411 | CFIndex _rv; |
| 1412 | CFRange range; |
| 1413 | CFStringEncoding encoding; |
| 1414 | UInt8 lossByte; |
| 1415 | Boolean isExternalRepresentation; |
| 1416 | UInt8 buffer; |
| 1417 | CFIndex maxBufLen; |
| 1418 | CFIndex usedBufLen; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1419 | #ifndef CFStringGetBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1420 | PyMac_PRECHECK(CFStringGetBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1421 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1422 | if (!PyArg_ParseTuple(_args, "O&lbll", |
| 1423 | CFRange_Convert, &range, |
| 1424 | &encoding, |
| 1425 | &lossByte, |
| 1426 | &isExternalRepresentation, |
| 1427 | &maxBufLen)) |
| 1428 | return NULL; |
| 1429 | _rv = CFStringGetBytes(_self->ob_itself, |
| 1430 | range, |
| 1431 | encoding, |
| 1432 | lossByte, |
| 1433 | isExternalRepresentation, |
| 1434 | &buffer, |
| 1435 | maxBufLen, |
| 1436 | &usedBufLen); |
| 1437 | _res = Py_BuildValue("lbl", |
| 1438 | _rv, |
| 1439 | buffer, |
| 1440 | usedBufLen); |
| 1441 | return _res; |
| 1442 | } |
| 1443 | |
| 1444 | static PyObject *CFStringRefObj_CFStringCreateExternalRepresentation(CFStringRefObject *_self, PyObject *_args) |
| 1445 | { |
| 1446 | PyObject *_res = NULL; |
| 1447 | CFDataRef _rv; |
| 1448 | CFStringEncoding encoding; |
| 1449 | UInt8 lossByte; |
| 1450 | if (!PyArg_ParseTuple(_args, "lb", |
| 1451 | &encoding, |
| 1452 | &lossByte)) |
| 1453 | return NULL; |
| 1454 | _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL, |
| 1455 | _self->ob_itself, |
| 1456 | encoding, |
| 1457 | lossByte); |
| 1458 | _res = Py_BuildValue("O&", |
| 1459 | CFDataRefObj_New, _rv); |
| 1460 | return _res; |
| 1461 | } |
| 1462 | |
| 1463 | static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args) |
| 1464 | { |
| 1465 | PyObject *_res = NULL; |
| 1466 | CFStringEncoding _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1467 | #ifndef CFStringGetSmallestEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1468 | PyMac_PRECHECK(CFStringGetSmallestEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1469 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1470 | if (!PyArg_ParseTuple(_args, "")) |
| 1471 | return NULL; |
| 1472 | _rv = CFStringGetSmallestEncoding(_self->ob_itself); |
| 1473 | _res = Py_BuildValue("l", |
| 1474 | _rv); |
| 1475 | return _res; |
| 1476 | } |
| 1477 | |
| 1478 | static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args) |
| 1479 | { |
| 1480 | PyObject *_res = NULL; |
| 1481 | CFStringEncoding _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1482 | #ifndef CFStringGetFastestEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1483 | PyMac_PRECHECK(CFStringGetFastestEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1484 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1485 | if (!PyArg_ParseTuple(_args, "")) |
| 1486 | return NULL; |
| 1487 | _rv = CFStringGetFastestEncoding(_self->ob_itself); |
| 1488 | _res = Py_BuildValue("l", |
| 1489 | _rv); |
| 1490 | return _res; |
| 1491 | } |
| 1492 | |
| 1493 | static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args) |
| 1494 | { |
| 1495 | PyObject *_res = NULL; |
| 1496 | CFComparisonResult _rv; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1497 | CFStringRef theString2; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1498 | CFRange rangeToCompare; |
| 1499 | CFOptionFlags compareOptions; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1500 | #ifndef CFStringCompareWithOptions |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1501 | PyMac_PRECHECK(CFStringCompareWithOptions); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1502 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1503 | if (!PyArg_ParseTuple(_args, "O&O&l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1504 | CFStringRefObj_Convert, &theString2, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1505 | CFRange_Convert, &rangeToCompare, |
| 1506 | &compareOptions)) |
| 1507 | return NULL; |
| 1508 | _rv = CFStringCompareWithOptions(_self->ob_itself, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1509 | theString2, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1510 | rangeToCompare, |
| 1511 | compareOptions); |
| 1512 | _res = Py_BuildValue("l", |
| 1513 | _rv); |
| 1514 | return _res; |
| 1515 | } |
| 1516 | |
| 1517 | static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args) |
| 1518 | { |
| 1519 | PyObject *_res = NULL; |
| 1520 | CFComparisonResult _rv; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1521 | CFStringRef theString2; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1522 | CFOptionFlags compareOptions; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1523 | #ifndef CFStringCompare |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1524 | PyMac_PRECHECK(CFStringCompare); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1525 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1526 | if (!PyArg_ParseTuple(_args, "O&l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1527 | CFStringRefObj_Convert, &theString2, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1528 | &compareOptions)) |
| 1529 | return NULL; |
| 1530 | _rv = CFStringCompare(_self->ob_itself, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1531 | theString2, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1532 | compareOptions); |
| 1533 | _res = Py_BuildValue("l", |
| 1534 | _rv); |
| 1535 | return _res; |
| 1536 | } |
| 1537 | |
| 1538 | static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args) |
| 1539 | { |
| 1540 | PyObject *_res = NULL; |
| 1541 | Boolean _rv; |
| 1542 | CFStringRef stringToFind; |
| 1543 | CFRange rangeToSearch; |
| 1544 | CFOptionFlags searchOptions; |
| 1545 | CFRange result; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1546 | #ifndef CFStringFindWithOptions |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1547 | PyMac_PRECHECK(CFStringFindWithOptions); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1548 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1549 | if (!PyArg_ParseTuple(_args, "O&O&l", |
| 1550 | CFStringRefObj_Convert, &stringToFind, |
| 1551 | CFRange_Convert, &rangeToSearch, |
| 1552 | &searchOptions)) |
| 1553 | return NULL; |
| 1554 | _rv = CFStringFindWithOptions(_self->ob_itself, |
| 1555 | stringToFind, |
| 1556 | rangeToSearch, |
| 1557 | searchOptions, |
| 1558 | &result); |
| 1559 | _res = Py_BuildValue("lO&", |
| 1560 | _rv, |
| 1561 | CFRange_New, result); |
| 1562 | return _res; |
| 1563 | } |
| 1564 | |
| 1565 | static PyObject *CFStringRefObj_CFStringCreateArrayWithFindResults(CFStringRefObject *_self, PyObject *_args) |
| 1566 | { |
| 1567 | PyObject *_res = NULL; |
| 1568 | CFArrayRef _rv; |
| 1569 | CFStringRef stringToFind; |
| 1570 | CFRange rangeToSearch; |
| 1571 | CFOptionFlags compareOptions; |
| 1572 | if (!PyArg_ParseTuple(_args, "O&O&l", |
| 1573 | CFStringRefObj_Convert, &stringToFind, |
| 1574 | CFRange_Convert, &rangeToSearch, |
| 1575 | &compareOptions)) |
| 1576 | return NULL; |
| 1577 | _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL, |
| 1578 | _self->ob_itself, |
| 1579 | stringToFind, |
| 1580 | rangeToSearch, |
| 1581 | compareOptions); |
| 1582 | _res = Py_BuildValue("O&", |
| 1583 | CFArrayRefObj_New, _rv); |
| 1584 | return _res; |
| 1585 | } |
| 1586 | |
| 1587 | static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args) |
| 1588 | { |
| 1589 | PyObject *_res = NULL; |
| 1590 | CFRange _rv; |
| 1591 | CFStringRef stringToFind; |
| 1592 | CFOptionFlags compareOptions; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1593 | #ifndef CFStringFind |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1594 | PyMac_PRECHECK(CFStringFind); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1595 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1596 | if (!PyArg_ParseTuple(_args, "O&l", |
| 1597 | CFStringRefObj_Convert, &stringToFind, |
| 1598 | &compareOptions)) |
| 1599 | return NULL; |
| 1600 | _rv = CFStringFind(_self->ob_itself, |
| 1601 | stringToFind, |
| 1602 | compareOptions); |
| 1603 | _res = Py_BuildValue("O&", |
| 1604 | CFRange_New, _rv); |
| 1605 | return _res; |
| 1606 | } |
| 1607 | |
| 1608 | static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args) |
| 1609 | { |
| 1610 | PyObject *_res = NULL; |
| 1611 | Boolean _rv; |
| 1612 | CFStringRef prefix; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1613 | #ifndef CFStringHasPrefix |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1614 | PyMac_PRECHECK(CFStringHasPrefix); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1615 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1616 | if (!PyArg_ParseTuple(_args, "O&", |
| 1617 | CFStringRefObj_Convert, &prefix)) |
| 1618 | return NULL; |
| 1619 | _rv = CFStringHasPrefix(_self->ob_itself, |
| 1620 | prefix); |
| 1621 | _res = Py_BuildValue("l", |
| 1622 | _rv); |
| 1623 | return _res; |
| 1624 | } |
| 1625 | |
| 1626 | static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args) |
| 1627 | { |
| 1628 | PyObject *_res = NULL; |
| 1629 | Boolean _rv; |
| 1630 | CFStringRef suffix; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1631 | #ifndef CFStringHasSuffix |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1632 | PyMac_PRECHECK(CFStringHasSuffix); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1633 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1634 | if (!PyArg_ParseTuple(_args, "O&", |
| 1635 | CFStringRefObj_Convert, &suffix)) |
| 1636 | return NULL; |
| 1637 | _rv = CFStringHasSuffix(_self->ob_itself, |
| 1638 | suffix); |
| 1639 | _res = Py_BuildValue("l", |
| 1640 | _rv); |
| 1641 | return _res; |
| 1642 | } |
| 1643 | |
| 1644 | static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args) |
| 1645 | { |
| 1646 | PyObject *_res = NULL; |
| 1647 | CFRange range; |
| 1648 | CFIndex lineBeginIndex; |
| 1649 | CFIndex lineEndIndex; |
| 1650 | CFIndex contentsEndIndex; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1651 | #ifndef CFStringGetLineBounds |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1652 | PyMac_PRECHECK(CFStringGetLineBounds); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1653 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1654 | if (!PyArg_ParseTuple(_args, "O&", |
| 1655 | CFRange_Convert, &range)) |
| 1656 | return NULL; |
| 1657 | CFStringGetLineBounds(_self->ob_itself, |
| 1658 | range, |
| 1659 | &lineBeginIndex, |
| 1660 | &lineEndIndex, |
| 1661 | &contentsEndIndex); |
| 1662 | _res = Py_BuildValue("lll", |
| 1663 | lineBeginIndex, |
| 1664 | lineEndIndex, |
| 1665 | contentsEndIndex); |
| 1666 | return _res; |
| 1667 | } |
| 1668 | |
| 1669 | static PyObject *CFStringRefObj_CFStringCreateArrayBySeparatingStrings(CFStringRefObject *_self, PyObject *_args) |
| 1670 | { |
| 1671 | PyObject *_res = NULL; |
| 1672 | CFArrayRef _rv; |
| 1673 | CFStringRef separatorString; |
| 1674 | if (!PyArg_ParseTuple(_args, "O&", |
| 1675 | CFStringRefObj_Convert, &separatorString)) |
| 1676 | return NULL; |
| 1677 | _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL, |
| 1678 | _self->ob_itself, |
| 1679 | separatorString); |
| 1680 | _res = Py_BuildValue("O&", |
| 1681 | CFArrayRefObj_New, _rv); |
| 1682 | return _res; |
| 1683 | } |
| 1684 | |
| 1685 | static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args) |
| 1686 | { |
| 1687 | PyObject *_res = NULL; |
| 1688 | SInt32 _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1689 | #ifndef CFStringGetIntValue |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1690 | PyMac_PRECHECK(CFStringGetIntValue); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1691 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1692 | if (!PyArg_ParseTuple(_args, "")) |
| 1693 | return NULL; |
| 1694 | _rv = CFStringGetIntValue(_self->ob_itself); |
| 1695 | _res = Py_BuildValue("l", |
| 1696 | _rv); |
| 1697 | return _res; |
| 1698 | } |
| 1699 | |
| 1700 | static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args) |
| 1701 | { |
| 1702 | PyObject *_res = NULL; |
| 1703 | double _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1704 | #ifndef CFStringGetDoubleValue |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1705 | PyMac_PRECHECK(CFStringGetDoubleValue); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1706 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1707 | if (!PyArg_ParseTuple(_args, "")) |
| 1708 | return NULL; |
| 1709 | _rv = CFStringGetDoubleValue(_self->ob_itself); |
| 1710 | _res = Py_BuildValue("d", |
| 1711 | _rv); |
| 1712 | return _res; |
| 1713 | } |
| 1714 | |
| 1715 | static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args) |
| 1716 | { |
| 1717 | PyObject *_res = NULL; |
| 1718 | CFStringEncoding _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1719 | #ifndef CFStringConvertIANACharSetNameToEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1720 | PyMac_PRECHECK(CFStringConvertIANACharSetNameToEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1721 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1722 | if (!PyArg_ParseTuple(_args, "")) |
| 1723 | return NULL; |
| 1724 | _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself); |
| 1725 | _res = Py_BuildValue("l", |
| 1726 | _rv); |
| 1727 | return _res; |
| 1728 | } |
| 1729 | |
| 1730 | static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args) |
| 1731 | { |
| 1732 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1733 | #ifndef CFShowStr |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1734 | PyMac_PRECHECK(CFShowStr); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1735 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1736 | if (!PyArg_ParseTuple(_args, "")) |
| 1737 | return NULL; |
| 1738 | CFShowStr(_self->ob_itself); |
| 1739 | Py_INCREF(Py_None); |
| 1740 | _res = Py_None; |
| 1741 | return _res; |
| 1742 | } |
| 1743 | |
| 1744 | static PyObject *CFStringRefObj_CFURLCreateWithString(CFStringRefObject *_self, PyObject *_args) |
| 1745 | { |
| 1746 | PyObject *_res = NULL; |
| 1747 | CFURLRef _rv; |
| 1748 | CFURLRef baseURL; |
| 1749 | if (!PyArg_ParseTuple(_args, "O&", |
| 1750 | OptionalCFURLRefObj_Convert, &baseURL)) |
| 1751 | return NULL; |
| 1752 | _rv = CFURLCreateWithString((CFAllocatorRef)NULL, |
| 1753 | _self->ob_itself, |
| 1754 | baseURL); |
| 1755 | _res = Py_BuildValue("O&", |
| 1756 | CFURLRefObj_New, _rv); |
| 1757 | return _res; |
| 1758 | } |
| 1759 | |
| 1760 | static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPath(CFStringRefObject *_self, PyObject *_args) |
| 1761 | { |
| 1762 | PyObject *_res = NULL; |
| 1763 | CFURLRef _rv; |
| 1764 | CFURLPathStyle pathStyle; |
| 1765 | Boolean isDirectory; |
| 1766 | if (!PyArg_ParseTuple(_args, "ll", |
| 1767 | &pathStyle, |
| 1768 | &isDirectory)) |
| 1769 | return NULL; |
| 1770 | _rv = CFURLCreateWithFileSystemPath((CFAllocatorRef)NULL, |
| 1771 | _self->ob_itself, |
| 1772 | pathStyle, |
| 1773 | isDirectory); |
| 1774 | _res = Py_BuildValue("O&", |
| 1775 | CFURLRefObj_New, _rv); |
| 1776 | return _res; |
| 1777 | } |
| 1778 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1779 | static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase(CFStringRefObject *_self, PyObject *_args) |
| 1780 | { |
| 1781 | PyObject *_res = NULL; |
| 1782 | CFURLRef _rv; |
| 1783 | CFURLPathStyle pathStyle; |
| 1784 | Boolean isDirectory; |
| 1785 | CFURLRef baseURL; |
| 1786 | if (!PyArg_ParseTuple(_args, "llO&", |
| 1787 | &pathStyle, |
| 1788 | &isDirectory, |
| 1789 | OptionalCFURLRefObj_Convert, &baseURL)) |
| 1790 | return NULL; |
| 1791 | _rv = CFURLCreateWithFileSystemPathRelativeToBase((CFAllocatorRef)NULL, |
| 1792 | _self->ob_itself, |
| 1793 | pathStyle, |
| 1794 | isDirectory, |
| 1795 | baseURL); |
| 1796 | _res = Py_BuildValue("O&", |
| 1797 | CFURLRefObj_New, _rv); |
| 1798 | return _res; |
| 1799 | } |
| 1800 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1801 | static PyObject *CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes(CFStringRefObject *_self, PyObject *_args) |
| 1802 | { |
| 1803 | PyObject *_res = NULL; |
| 1804 | CFStringRef _rv; |
| 1805 | CFStringRef charactersToLeaveEscaped; |
| 1806 | if (!PyArg_ParseTuple(_args, "O&", |
| 1807 | CFStringRefObj_Convert, &charactersToLeaveEscaped)) |
| 1808 | return NULL; |
| 1809 | _rv = CFURLCreateStringByReplacingPercentEscapes((CFAllocatorRef)NULL, |
| 1810 | _self->ob_itself, |
| 1811 | charactersToLeaveEscaped); |
| 1812 | _res = Py_BuildValue("O&", |
| 1813 | CFStringRefObj_New, _rv); |
| 1814 | return _res; |
| 1815 | } |
| 1816 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1817 | static PyObject *CFStringRefObj_CFURLCreateStringByAddingPercentEscapes(CFStringRefObject *_self, PyObject *_args) |
| 1818 | { |
| 1819 | PyObject *_res = NULL; |
| 1820 | CFStringRef _rv; |
| 1821 | CFStringRef charactersToLeaveUnescaped; |
| 1822 | CFStringRef legalURLCharactersToBeEscaped; |
| 1823 | CFStringEncoding encoding; |
| 1824 | if (!PyArg_ParseTuple(_args, "O&O&l", |
| 1825 | CFStringRefObj_Convert, &charactersToLeaveUnescaped, |
| 1826 | CFStringRefObj_Convert, &legalURLCharactersToBeEscaped, |
| 1827 | &encoding)) |
| 1828 | return NULL; |
| 1829 | _rv = CFURLCreateStringByAddingPercentEscapes((CFAllocatorRef)NULL, |
| 1830 | _self->ob_itself, |
| 1831 | charactersToLeaveUnescaped, |
| 1832 | legalURLCharactersToBeEscaped, |
| 1833 | encoding); |
| 1834 | _res = Py_BuildValue("O&", |
| 1835 | CFStringRefObj_New, _rv); |
| 1836 | return _res; |
| 1837 | } |
| 1838 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1839 | static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyObject *_args) |
| 1840 | { |
| 1841 | PyObject *_res = NULL; |
| 1842 | |
| 1843 | int size = CFStringGetLength(_self->ob_itself)+1; |
| 1844 | char *data = malloc(size); |
| 1845 | |
| 1846 | if( data == NULL ) return PyErr_NoMemory(); |
| 1847 | if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) { |
| 1848 | _res = (PyObject *)PyString_FromString(data); |
| 1849 | } else { |
| 1850 | PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string"); |
| 1851 | _res = NULL; |
| 1852 | } |
| 1853 | free(data); |
| 1854 | return _res; |
| 1855 | |
| 1856 | } |
| 1857 | |
| 1858 | static PyObject *CFStringRefObj_CFStringGetUnicode(CFStringRefObject *_self, PyObject *_args) |
| 1859 | { |
| 1860 | PyObject *_res = NULL; |
| 1861 | |
| 1862 | int size = CFStringGetLength(_self->ob_itself)+1; |
| 1863 | Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE)); |
| 1864 | CFRange range; |
| 1865 | |
| 1866 | range.location = 0; |
| 1867 | range.length = size; |
| 1868 | if( data == NULL ) return PyErr_NoMemory(); |
| 1869 | CFStringGetCharacters(_self->ob_itself, range, data); |
| 1870 | _res = (PyObject *)PyUnicode_FromUnicode(data, size); |
| 1871 | free(data); |
| 1872 | return _res; |
| 1873 | |
| 1874 | } |
| 1875 | |
| 1876 | static PyMethodDef CFStringRefObj_methods[] = { |
| 1877 | {"CFStringCreateWithSubstring", (PyCFunction)CFStringRefObj_CFStringCreateWithSubstring, 1, |
| 1878 | "(CFRange range) -> (CFStringRef _rv)"}, |
| 1879 | {"CFStringCreateCopy", (PyCFunction)CFStringRefObj_CFStringCreateCopy, 1, |
| 1880 | "() -> (CFStringRef _rv)"}, |
| 1881 | {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1, |
| 1882 | "() -> (CFIndex _rv)"}, |
| 1883 | {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1, |
| 1884 | "(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)"}, |
| 1885 | {"CFStringCreateExternalRepresentation", (PyCFunction)CFStringRefObj_CFStringCreateExternalRepresentation, 1, |
| 1886 | "(CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)"}, |
| 1887 | {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1, |
| 1888 | "() -> (CFStringEncoding _rv)"}, |
| 1889 | {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1, |
| 1890 | "() -> (CFStringEncoding _rv)"}, |
| 1891 | {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1892 | "(CFStringRef theString2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1893 | {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1894 | "(CFStringRef theString2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1895 | {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1, |
| 1896 | "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)"}, |
| 1897 | {"CFStringCreateArrayWithFindResults", (PyCFunction)CFStringRefObj_CFStringCreateArrayWithFindResults, 1, |
| 1898 | "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)"}, |
| 1899 | {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1, |
| 1900 | "(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)"}, |
| 1901 | {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1, |
| 1902 | "(CFStringRef prefix) -> (Boolean _rv)"}, |
| 1903 | {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1, |
| 1904 | "(CFStringRef suffix) -> (Boolean _rv)"}, |
| 1905 | {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1, |
| 1906 | "(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)"}, |
| 1907 | {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CFStringRefObj_CFStringCreateArrayBySeparatingStrings, 1, |
| 1908 | "(CFStringRef separatorString) -> (CFArrayRef _rv)"}, |
| 1909 | {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1, |
| 1910 | "() -> (SInt32 _rv)"}, |
| 1911 | {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1, |
| 1912 | "() -> (double _rv)"}, |
| 1913 | {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1, |
| 1914 | "() -> (CFStringEncoding _rv)"}, |
| 1915 | {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1, |
| 1916 | "() -> None"}, |
| 1917 | {"CFURLCreateWithString", (PyCFunction)CFStringRefObj_CFURLCreateWithString, 1, |
| 1918 | "(CFURLRef baseURL) -> (CFURLRef _rv)"}, |
| 1919 | {"CFURLCreateWithFileSystemPath", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPath, 1, |
| 1920 | "(CFURLPathStyle pathStyle, Boolean isDirectory) -> (CFURLRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1921 | {"CFURLCreateWithFileSystemPathRelativeToBase", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase, 1, |
| 1922 | "(CFURLPathStyle pathStyle, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1923 | {"CFURLCreateStringByReplacingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes, 1, |
| 1924 | "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 1925 | {"CFURLCreateStringByAddingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByAddingPercentEscapes, 1, |
| 1926 | "(CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1927 | {"CFStringGetString", (PyCFunction)CFStringRefObj_CFStringGetString, 1, |
| 1928 | "() -> (string _rv)"}, |
| 1929 | {"CFStringGetUnicode", (PyCFunction)CFStringRefObj_CFStringGetUnicode, 1, |
| 1930 | "() -> (unicode _rv)"}, |
| 1931 | {NULL, NULL, 0} |
| 1932 | }; |
| 1933 | |
| 1934 | PyMethodChain CFStringRefObj_chain = { CFStringRefObj_methods, &CFTypeRefObj_chain }; |
| 1935 | |
| 1936 | static PyObject *CFStringRefObj_getattr(CFStringRefObject *self, char *name) |
| 1937 | { |
| 1938 | return Py_FindMethodInChain(&CFStringRefObj_chain, (PyObject *)self, name); |
| 1939 | } |
| 1940 | |
| 1941 | #define CFStringRefObj_setattr NULL |
| 1942 | |
| 1943 | static int CFStringRefObj_compare(CFStringRefObject *self, CFStringRefObject *other) |
| 1944 | { |
| 1945 | /* XXXX Or should we use CFEqual?? */ |
| 1946 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 1947 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | static PyObject * CFStringRefObj_repr(CFStringRefObject *self) |
| 1952 | { |
| 1953 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 1954 | sprintf(buf, "<CFStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1955 | return PyString_FromString(buf); |
| 1956 | } |
| 1957 | |
| 1958 | static int CFStringRefObj_hash(CFStringRefObject *self) |
| 1959 | { |
| 1960 | /* XXXX Or should we use CFHash?? */ |
| 1961 | return (int)self->ob_itself; |
| 1962 | } |
| 1963 | |
| 1964 | PyTypeObject CFStringRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 1965 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1966 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 1967 | "_CF.CFStringRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 1968 | sizeof(CFStringRefObject), /*tp_basicsize*/ |
| 1969 | 0, /*tp_itemsize*/ |
| 1970 | /* methods */ |
| 1971 | (destructor) CFStringRefObj_dealloc, /*tp_dealloc*/ |
| 1972 | 0, /*tp_print*/ |
| 1973 | (getattrfunc) CFStringRefObj_getattr, /*tp_getattr*/ |
| 1974 | (setattrfunc) CFStringRefObj_setattr, /*tp_setattr*/ |
| 1975 | (cmpfunc) CFStringRefObj_compare, /*tp_compare*/ |
| 1976 | (reprfunc) CFStringRefObj_repr, /*tp_repr*/ |
| 1977 | (PyNumberMethods *)0, /* tp_as_number */ |
| 1978 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 1979 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 1980 | (hashfunc) CFStringRefObj_hash, /*tp_hash*/ |
| 1981 | }; |
| 1982 | |
| 1983 | /* ------------------ End object type CFStringRef ------------------- */ |
| 1984 | |
| 1985 | |
| 1986 | /* ----------------- Object type CFMutableStringRef ----------------- */ |
| 1987 | |
| 1988 | PyTypeObject CFMutableStringRef_Type; |
| 1989 | |
| 1990 | #define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type) |
| 1991 | |
| 1992 | typedef struct CFMutableStringRefObject { |
| 1993 | PyObject_HEAD |
| 1994 | CFMutableStringRef ob_itself; |
| 1995 | void (*ob_freeit)(CFTypeRef ptr); |
| 1996 | } CFMutableStringRefObject; |
| 1997 | |
| 1998 | PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself) |
| 1999 | { |
| 2000 | CFMutableStringRefObject *it; |
| 2001 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 2002 | it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type); |
| 2003 | if (it == NULL) return NULL; |
| 2004 | it->ob_itself = itself; |
| 2005 | it->ob_freeit = CFRelease; |
| 2006 | return (PyObject *)it; |
| 2007 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 2008 | int CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2009 | { |
| 2010 | |
| 2011 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 2012 | /* Check for other CF objects here */ |
| 2013 | |
| 2014 | if (!CFMutableStringRefObj_Check(v)) |
| 2015 | { |
| 2016 | PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required"); |
| 2017 | return 0; |
| 2018 | } |
| 2019 | *p_itself = ((CFMutableStringRefObject *)v)->ob_itself; |
| 2020 | return 1; |
| 2021 | } |
| 2022 | |
| 2023 | static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self) |
| 2024 | { |
| 2025 | if (self->ob_freeit && self->ob_itself) |
| 2026 | { |
| 2027 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 2028 | } |
| 2029 | PyMem_DEL(self); |
| 2030 | } |
| 2031 | |
| 2032 | static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args) |
| 2033 | { |
| 2034 | PyObject *_res = NULL; |
| 2035 | CFStringRef appendedString; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2036 | #ifndef CFStringAppend |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2037 | PyMac_PRECHECK(CFStringAppend); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2038 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2039 | if (!PyArg_ParseTuple(_args, "O&", |
| 2040 | CFStringRefObj_Convert, &appendedString)) |
| 2041 | return NULL; |
| 2042 | CFStringAppend(_self->ob_itself, |
| 2043 | appendedString); |
| 2044 | Py_INCREF(Py_None); |
| 2045 | _res = Py_None; |
| 2046 | return _res; |
| 2047 | } |
| 2048 | |
| 2049 | static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args) |
| 2050 | { |
| 2051 | PyObject *_res = NULL; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2052 | Str255 pStr; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2053 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2054 | #ifndef CFStringAppendPascalString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2055 | PyMac_PRECHECK(CFStringAppendPascalString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2056 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2057 | if (!PyArg_ParseTuple(_args, "O&l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2058 | PyMac_GetStr255, pStr, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2059 | &encoding)) |
| 2060 | return NULL; |
| 2061 | CFStringAppendPascalString(_self->ob_itself, |
| 2062 | pStr, |
| 2063 | encoding); |
| 2064 | Py_INCREF(Py_None); |
| 2065 | _res = Py_None; |
| 2066 | return _res; |
| 2067 | } |
| 2068 | |
| 2069 | static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args) |
| 2070 | { |
| 2071 | PyObject *_res = NULL; |
| 2072 | char* cStr; |
| 2073 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2074 | #ifndef CFStringAppendCString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2075 | PyMac_PRECHECK(CFStringAppendCString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2076 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2077 | if (!PyArg_ParseTuple(_args, "sl", |
| 2078 | &cStr, |
| 2079 | &encoding)) |
| 2080 | return NULL; |
| 2081 | CFStringAppendCString(_self->ob_itself, |
| 2082 | cStr, |
| 2083 | encoding); |
| 2084 | Py_INCREF(Py_None); |
| 2085 | _res = Py_None; |
| 2086 | return _res; |
| 2087 | } |
| 2088 | |
| 2089 | static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args) |
| 2090 | { |
| 2091 | PyObject *_res = NULL; |
| 2092 | CFIndex idx; |
| 2093 | CFStringRef insertedStr; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2094 | #ifndef CFStringInsert |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2095 | PyMac_PRECHECK(CFStringInsert); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2096 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2097 | if (!PyArg_ParseTuple(_args, "lO&", |
| 2098 | &idx, |
| 2099 | CFStringRefObj_Convert, &insertedStr)) |
| 2100 | return NULL; |
| 2101 | CFStringInsert(_self->ob_itself, |
| 2102 | idx, |
| 2103 | insertedStr); |
| 2104 | Py_INCREF(Py_None); |
| 2105 | _res = Py_None; |
| 2106 | return _res; |
| 2107 | } |
| 2108 | |
| 2109 | static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args) |
| 2110 | { |
| 2111 | PyObject *_res = NULL; |
| 2112 | CFRange range; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2113 | #ifndef CFStringDelete |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2114 | PyMac_PRECHECK(CFStringDelete); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2115 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2116 | if (!PyArg_ParseTuple(_args, "O&", |
| 2117 | CFRange_Convert, &range)) |
| 2118 | return NULL; |
| 2119 | CFStringDelete(_self->ob_itself, |
| 2120 | range); |
| 2121 | Py_INCREF(Py_None); |
| 2122 | _res = Py_None; |
| 2123 | return _res; |
| 2124 | } |
| 2125 | |
| 2126 | static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args) |
| 2127 | { |
| 2128 | PyObject *_res = NULL; |
| 2129 | CFRange range; |
| 2130 | CFStringRef replacement; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2131 | #ifndef CFStringReplace |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2132 | PyMac_PRECHECK(CFStringReplace); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2133 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2134 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 2135 | CFRange_Convert, &range, |
| 2136 | CFStringRefObj_Convert, &replacement)) |
| 2137 | return NULL; |
| 2138 | CFStringReplace(_self->ob_itself, |
| 2139 | range, |
| 2140 | replacement); |
| 2141 | Py_INCREF(Py_None); |
| 2142 | _res = Py_None; |
| 2143 | return _res; |
| 2144 | } |
| 2145 | |
| 2146 | static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args) |
| 2147 | { |
| 2148 | PyObject *_res = NULL; |
| 2149 | CFStringRef replacement; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2150 | #ifndef CFStringReplaceAll |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2151 | PyMac_PRECHECK(CFStringReplaceAll); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2152 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2153 | if (!PyArg_ParseTuple(_args, "O&", |
| 2154 | CFStringRefObj_Convert, &replacement)) |
| 2155 | return NULL; |
| 2156 | CFStringReplaceAll(_self->ob_itself, |
| 2157 | replacement); |
| 2158 | Py_INCREF(Py_None); |
| 2159 | _res = Py_None; |
| 2160 | return _res; |
| 2161 | } |
| 2162 | |
| 2163 | static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args) |
| 2164 | { |
| 2165 | PyObject *_res = NULL; |
| 2166 | CFStringRef padString; |
| 2167 | CFIndex length; |
| 2168 | CFIndex indexIntoPad; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2169 | #ifndef CFStringPad |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2170 | PyMac_PRECHECK(CFStringPad); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2171 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2172 | if (!PyArg_ParseTuple(_args, "O&ll", |
| 2173 | CFStringRefObj_Convert, &padString, |
| 2174 | &length, |
| 2175 | &indexIntoPad)) |
| 2176 | return NULL; |
| 2177 | CFStringPad(_self->ob_itself, |
| 2178 | padString, |
| 2179 | length, |
| 2180 | indexIntoPad); |
| 2181 | Py_INCREF(Py_None); |
| 2182 | _res = Py_None; |
| 2183 | return _res; |
| 2184 | } |
| 2185 | |
| 2186 | static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args) |
| 2187 | { |
| 2188 | PyObject *_res = NULL; |
| 2189 | CFStringRef trimString; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2190 | #ifndef CFStringTrim |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2191 | PyMac_PRECHECK(CFStringTrim); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2192 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2193 | if (!PyArg_ParseTuple(_args, "O&", |
| 2194 | CFStringRefObj_Convert, &trimString)) |
| 2195 | return NULL; |
| 2196 | CFStringTrim(_self->ob_itself, |
| 2197 | trimString); |
| 2198 | Py_INCREF(Py_None); |
| 2199 | _res = Py_None; |
| 2200 | return _res; |
| 2201 | } |
| 2202 | |
| 2203 | static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args) |
| 2204 | { |
| 2205 | PyObject *_res = NULL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2206 | #ifndef CFStringTrimWhitespace |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2207 | PyMac_PRECHECK(CFStringTrimWhitespace); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2208 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2209 | if (!PyArg_ParseTuple(_args, "")) |
| 2210 | return NULL; |
| 2211 | CFStringTrimWhitespace(_self->ob_itself); |
| 2212 | Py_INCREF(Py_None); |
| 2213 | _res = Py_None; |
| 2214 | return _res; |
| 2215 | } |
| 2216 | |
| 2217 | static PyMethodDef CFMutableStringRefObj_methods[] = { |
| 2218 | {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1, |
| 2219 | "(CFStringRef appendedString) -> None"}, |
| 2220 | {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2221 | "(Str255 pStr, CFStringEncoding encoding) -> None"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2222 | {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1, |
| 2223 | "(char* cStr, CFStringEncoding encoding) -> None"}, |
| 2224 | {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1, |
| 2225 | "(CFIndex idx, CFStringRef insertedStr) -> None"}, |
| 2226 | {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1, |
| 2227 | "(CFRange range) -> None"}, |
| 2228 | {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1, |
| 2229 | "(CFRange range, CFStringRef replacement) -> None"}, |
| 2230 | {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1, |
| 2231 | "(CFStringRef replacement) -> None"}, |
| 2232 | {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1, |
| 2233 | "(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None"}, |
| 2234 | {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1, |
| 2235 | "(CFStringRef trimString) -> None"}, |
| 2236 | {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1, |
| 2237 | "() -> None"}, |
| 2238 | {NULL, NULL, 0} |
| 2239 | }; |
| 2240 | |
| 2241 | PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, &CFStringRefObj_chain }; |
| 2242 | |
| 2243 | static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name) |
| 2244 | { |
| 2245 | return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name); |
| 2246 | } |
| 2247 | |
| 2248 | #define CFMutableStringRefObj_setattr NULL |
| 2249 | |
| 2250 | static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other) |
| 2251 | { |
| 2252 | /* XXXX Or should we use CFEqual?? */ |
| 2253 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 2254 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self) |
| 2259 | { |
| 2260 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 2261 | sprintf(buf, "<CFMutableStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2262 | return PyString_FromString(buf); |
| 2263 | } |
| 2264 | |
| 2265 | static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self) |
| 2266 | { |
| 2267 | /* XXXX Or should we use CFHash?? */ |
| 2268 | return (int)self->ob_itself; |
| 2269 | } |
| 2270 | |
| 2271 | PyTypeObject CFMutableStringRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2272 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2273 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 2274 | "_CF.CFMutableStringRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2275 | sizeof(CFMutableStringRefObject), /*tp_basicsize*/ |
| 2276 | 0, /*tp_itemsize*/ |
| 2277 | /* methods */ |
| 2278 | (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/ |
| 2279 | 0, /*tp_print*/ |
| 2280 | (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/ |
| 2281 | (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/ |
| 2282 | (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/ |
| 2283 | (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/ |
| 2284 | (PyNumberMethods *)0, /* tp_as_number */ |
| 2285 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 2286 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 2287 | (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/ |
| 2288 | }; |
| 2289 | |
| 2290 | /* --------------- End object type CFMutableStringRef --------------- */ |
| 2291 | |
| 2292 | |
| 2293 | /* ---------------------- Object type CFURLRef ---------------------- */ |
| 2294 | |
| 2295 | PyTypeObject CFURLRef_Type; |
| 2296 | |
| 2297 | #define CFURLRefObj_Check(x) ((x)->ob_type == &CFURLRef_Type) |
| 2298 | |
| 2299 | typedef struct CFURLRefObject { |
| 2300 | PyObject_HEAD |
| 2301 | CFURLRef ob_itself; |
| 2302 | void (*ob_freeit)(CFTypeRef ptr); |
| 2303 | } CFURLRefObject; |
| 2304 | |
| 2305 | PyObject *CFURLRefObj_New(CFURLRef itself) |
| 2306 | { |
| 2307 | CFURLRefObject *it; |
| 2308 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 2309 | it = PyObject_NEW(CFURLRefObject, &CFURLRef_Type); |
| 2310 | if (it == NULL) return NULL; |
| 2311 | it->ob_itself = itself; |
| 2312 | it->ob_freeit = CFRelease; |
| 2313 | return (PyObject *)it; |
| 2314 | } |
Jack Jansen | 06d2e1a | 2001-09-04 22:19:18 +0000 | [diff] [blame] | 2315 | int CFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2316 | { |
| 2317 | |
| 2318 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 2319 | /* Check for other CF objects here */ |
| 2320 | |
| 2321 | if (!CFURLRefObj_Check(v)) |
| 2322 | { |
| 2323 | PyErr_SetString(PyExc_TypeError, "CFURLRef required"); |
| 2324 | return 0; |
| 2325 | } |
| 2326 | *p_itself = ((CFURLRefObject *)v)->ob_itself; |
| 2327 | return 1; |
| 2328 | } |
| 2329 | |
| 2330 | static void CFURLRefObj_dealloc(CFURLRefObject *self) |
| 2331 | { |
| 2332 | if (self->ob_freeit && self->ob_itself) |
| 2333 | { |
| 2334 | self->ob_freeit((CFTypeRef)self->ob_itself); |
| 2335 | } |
| 2336 | PyMem_DEL(self); |
| 2337 | } |
| 2338 | |
| 2339 | static PyObject *CFURLRefObj_CFURLCreateData(CFURLRefObject *_self, PyObject *_args) |
| 2340 | { |
| 2341 | PyObject *_res = NULL; |
| 2342 | CFDataRef _rv; |
| 2343 | CFStringEncoding encoding; |
| 2344 | Boolean escapeWhitespace; |
| 2345 | if (!PyArg_ParseTuple(_args, "ll", |
| 2346 | &encoding, |
| 2347 | &escapeWhitespace)) |
| 2348 | return NULL; |
| 2349 | _rv = CFURLCreateData((CFAllocatorRef)NULL, |
| 2350 | _self->ob_itself, |
| 2351 | encoding, |
| 2352 | escapeWhitespace); |
| 2353 | _res = Py_BuildValue("O&", |
| 2354 | CFDataRefObj_New, _rv); |
| 2355 | return _res; |
| 2356 | } |
| 2357 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2358 | static PyObject *CFURLRefObj_CFURLGetFileSystemRepresentation(CFURLRefObject *_self, PyObject *_args) |
| 2359 | { |
| 2360 | PyObject *_res = NULL; |
| 2361 | Boolean _rv; |
| 2362 | Boolean resolveAgainstBase; |
| 2363 | UInt8 buffer; |
| 2364 | CFIndex maxBufLen; |
| 2365 | #ifndef CFURLGetFileSystemRepresentation |
| 2366 | PyMac_PRECHECK(CFURLGetFileSystemRepresentation); |
| 2367 | #endif |
| 2368 | if (!PyArg_ParseTuple(_args, "ll", |
| 2369 | &resolveAgainstBase, |
| 2370 | &maxBufLen)) |
| 2371 | return NULL; |
| 2372 | _rv = CFURLGetFileSystemRepresentation(_self->ob_itself, |
| 2373 | resolveAgainstBase, |
| 2374 | &buffer, |
| 2375 | maxBufLen); |
| 2376 | _res = Py_BuildValue("lb", |
| 2377 | _rv, |
| 2378 | buffer); |
| 2379 | return _res; |
| 2380 | } |
| 2381 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2382 | static PyObject *CFURLRefObj_CFURLCopyAbsoluteURL(CFURLRefObject *_self, PyObject *_args) |
| 2383 | { |
| 2384 | PyObject *_res = NULL; |
| 2385 | CFURLRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2386 | #ifndef CFURLCopyAbsoluteURL |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2387 | PyMac_PRECHECK(CFURLCopyAbsoluteURL); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2388 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2389 | if (!PyArg_ParseTuple(_args, "")) |
| 2390 | return NULL; |
| 2391 | _rv = CFURLCopyAbsoluteURL(_self->ob_itself); |
| 2392 | _res = Py_BuildValue("O&", |
| 2393 | CFURLRefObj_New, _rv); |
| 2394 | return _res; |
| 2395 | } |
| 2396 | |
| 2397 | static PyObject *CFURLRefObj_CFURLGetString(CFURLRefObject *_self, PyObject *_args) |
| 2398 | { |
| 2399 | PyObject *_res = NULL; |
| 2400 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2401 | #ifndef CFURLGetString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2402 | PyMac_PRECHECK(CFURLGetString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2403 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2404 | if (!PyArg_ParseTuple(_args, "")) |
| 2405 | return NULL; |
| 2406 | _rv = CFURLGetString(_self->ob_itself); |
| 2407 | _res = Py_BuildValue("O&", |
| 2408 | CFStringRefObj_New, _rv); |
| 2409 | return _res; |
| 2410 | } |
| 2411 | |
| 2412 | static PyObject *CFURLRefObj_CFURLGetBaseURL(CFURLRefObject *_self, PyObject *_args) |
| 2413 | { |
| 2414 | PyObject *_res = NULL; |
| 2415 | CFURLRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2416 | #ifndef CFURLGetBaseURL |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2417 | PyMac_PRECHECK(CFURLGetBaseURL); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2418 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2419 | if (!PyArg_ParseTuple(_args, "")) |
| 2420 | return NULL; |
| 2421 | _rv = CFURLGetBaseURL(_self->ob_itself); |
| 2422 | _res = Py_BuildValue("O&", |
| 2423 | CFURLRefObj_New, _rv); |
| 2424 | return _res; |
| 2425 | } |
| 2426 | |
| 2427 | static PyObject *CFURLRefObj_CFURLCanBeDecomposed(CFURLRefObject *_self, PyObject *_args) |
| 2428 | { |
| 2429 | PyObject *_res = NULL; |
| 2430 | Boolean _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2431 | #ifndef CFURLCanBeDecomposed |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2432 | PyMac_PRECHECK(CFURLCanBeDecomposed); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2433 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2434 | if (!PyArg_ParseTuple(_args, "")) |
| 2435 | return NULL; |
| 2436 | _rv = CFURLCanBeDecomposed(_self->ob_itself); |
| 2437 | _res = Py_BuildValue("l", |
| 2438 | _rv); |
| 2439 | return _res; |
| 2440 | } |
| 2441 | |
| 2442 | static PyObject *CFURLRefObj_CFURLCopyScheme(CFURLRefObject *_self, PyObject *_args) |
| 2443 | { |
| 2444 | PyObject *_res = NULL; |
| 2445 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2446 | #ifndef CFURLCopyScheme |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2447 | PyMac_PRECHECK(CFURLCopyScheme); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2448 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2449 | if (!PyArg_ParseTuple(_args, "")) |
| 2450 | return NULL; |
| 2451 | _rv = CFURLCopyScheme(_self->ob_itself); |
| 2452 | _res = Py_BuildValue("O&", |
| 2453 | CFStringRefObj_New, _rv); |
| 2454 | return _res; |
| 2455 | } |
| 2456 | |
| 2457 | static PyObject *CFURLRefObj_CFURLCopyNetLocation(CFURLRefObject *_self, PyObject *_args) |
| 2458 | { |
| 2459 | PyObject *_res = NULL; |
| 2460 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2461 | #ifndef CFURLCopyNetLocation |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2462 | PyMac_PRECHECK(CFURLCopyNetLocation); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2463 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2464 | if (!PyArg_ParseTuple(_args, "")) |
| 2465 | return NULL; |
| 2466 | _rv = CFURLCopyNetLocation(_self->ob_itself); |
| 2467 | _res = Py_BuildValue("O&", |
| 2468 | CFStringRefObj_New, _rv); |
| 2469 | return _res; |
| 2470 | } |
| 2471 | |
| 2472 | static PyObject *CFURLRefObj_CFURLCopyPath(CFURLRefObject *_self, PyObject *_args) |
| 2473 | { |
| 2474 | PyObject *_res = NULL; |
| 2475 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2476 | #ifndef CFURLCopyPath |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2477 | PyMac_PRECHECK(CFURLCopyPath); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2478 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2479 | if (!PyArg_ParseTuple(_args, "")) |
| 2480 | return NULL; |
| 2481 | _rv = CFURLCopyPath(_self->ob_itself); |
| 2482 | _res = Py_BuildValue("O&", |
| 2483 | CFStringRefObj_New, _rv); |
| 2484 | return _res; |
| 2485 | } |
| 2486 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2487 | static PyObject *CFURLRefObj_CFURLCopyStrictPath(CFURLRefObject *_self, PyObject *_args) |
| 2488 | { |
| 2489 | PyObject *_res = NULL; |
| 2490 | CFStringRef _rv; |
| 2491 | Boolean isAbsolute; |
| 2492 | #ifndef CFURLCopyStrictPath |
| 2493 | PyMac_PRECHECK(CFURLCopyStrictPath); |
| 2494 | #endif |
| 2495 | if (!PyArg_ParseTuple(_args, "")) |
| 2496 | return NULL; |
| 2497 | _rv = CFURLCopyStrictPath(_self->ob_itself, |
| 2498 | &isAbsolute); |
| 2499 | _res = Py_BuildValue("O&l", |
| 2500 | CFStringRefObj_New, _rv, |
| 2501 | isAbsolute); |
| 2502 | return _res; |
| 2503 | } |
| 2504 | |
| 2505 | static PyObject *CFURLRefObj_CFURLCopyFileSystemPath(CFURLRefObject *_self, PyObject *_args) |
| 2506 | { |
| 2507 | PyObject *_res = NULL; |
| 2508 | CFStringRef _rv; |
| 2509 | CFURLPathStyle pathStyle; |
| 2510 | #ifndef CFURLCopyFileSystemPath |
| 2511 | PyMac_PRECHECK(CFURLCopyFileSystemPath); |
| 2512 | #endif |
| 2513 | if (!PyArg_ParseTuple(_args, "l", |
| 2514 | &pathStyle)) |
| 2515 | return NULL; |
| 2516 | _rv = CFURLCopyFileSystemPath(_self->ob_itself, |
| 2517 | pathStyle); |
| 2518 | _res = Py_BuildValue("O&", |
| 2519 | CFStringRefObj_New, _rv); |
| 2520 | return _res; |
| 2521 | } |
| 2522 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2523 | static PyObject *CFURLRefObj_CFURLHasDirectoryPath(CFURLRefObject *_self, PyObject *_args) |
| 2524 | { |
| 2525 | PyObject *_res = NULL; |
| 2526 | Boolean _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2527 | #ifndef CFURLHasDirectoryPath |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2528 | PyMac_PRECHECK(CFURLHasDirectoryPath); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2529 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2530 | if (!PyArg_ParseTuple(_args, "")) |
| 2531 | return NULL; |
| 2532 | _rv = CFURLHasDirectoryPath(_self->ob_itself); |
| 2533 | _res = Py_BuildValue("l", |
| 2534 | _rv); |
| 2535 | return _res; |
| 2536 | } |
| 2537 | |
| 2538 | static PyObject *CFURLRefObj_CFURLCopyResourceSpecifier(CFURLRefObject *_self, PyObject *_args) |
| 2539 | { |
| 2540 | PyObject *_res = NULL; |
| 2541 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2542 | #ifndef CFURLCopyResourceSpecifier |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2543 | PyMac_PRECHECK(CFURLCopyResourceSpecifier); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2544 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2545 | if (!PyArg_ParseTuple(_args, "")) |
| 2546 | return NULL; |
| 2547 | _rv = CFURLCopyResourceSpecifier(_self->ob_itself); |
| 2548 | _res = Py_BuildValue("O&", |
| 2549 | CFStringRefObj_New, _rv); |
| 2550 | return _res; |
| 2551 | } |
| 2552 | |
| 2553 | static PyObject *CFURLRefObj_CFURLCopyHostName(CFURLRefObject *_self, PyObject *_args) |
| 2554 | { |
| 2555 | PyObject *_res = NULL; |
| 2556 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2557 | #ifndef CFURLCopyHostName |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2558 | PyMac_PRECHECK(CFURLCopyHostName); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2559 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2560 | if (!PyArg_ParseTuple(_args, "")) |
| 2561 | return NULL; |
| 2562 | _rv = CFURLCopyHostName(_self->ob_itself); |
| 2563 | _res = Py_BuildValue("O&", |
| 2564 | CFStringRefObj_New, _rv); |
| 2565 | return _res; |
| 2566 | } |
| 2567 | |
| 2568 | static PyObject *CFURLRefObj_CFURLGetPortNumber(CFURLRefObject *_self, PyObject *_args) |
| 2569 | { |
| 2570 | PyObject *_res = NULL; |
| 2571 | SInt32 _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2572 | #ifndef CFURLGetPortNumber |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2573 | PyMac_PRECHECK(CFURLGetPortNumber); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2574 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2575 | if (!PyArg_ParseTuple(_args, "")) |
| 2576 | return NULL; |
| 2577 | _rv = CFURLGetPortNumber(_self->ob_itself); |
| 2578 | _res = Py_BuildValue("l", |
| 2579 | _rv); |
| 2580 | return _res; |
| 2581 | } |
| 2582 | |
| 2583 | static PyObject *CFURLRefObj_CFURLCopyUserName(CFURLRefObject *_self, PyObject *_args) |
| 2584 | { |
| 2585 | PyObject *_res = NULL; |
| 2586 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2587 | #ifndef CFURLCopyUserName |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2588 | PyMac_PRECHECK(CFURLCopyUserName); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2589 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2590 | if (!PyArg_ParseTuple(_args, "")) |
| 2591 | return NULL; |
| 2592 | _rv = CFURLCopyUserName(_self->ob_itself); |
| 2593 | _res = Py_BuildValue("O&", |
| 2594 | CFStringRefObj_New, _rv); |
| 2595 | return _res; |
| 2596 | } |
| 2597 | |
| 2598 | static PyObject *CFURLRefObj_CFURLCopyPassword(CFURLRefObject *_self, PyObject *_args) |
| 2599 | { |
| 2600 | PyObject *_res = NULL; |
| 2601 | CFStringRef _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2602 | #ifndef CFURLCopyPassword |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2603 | PyMac_PRECHECK(CFURLCopyPassword); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2604 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2605 | if (!PyArg_ParseTuple(_args, "")) |
| 2606 | return NULL; |
| 2607 | _rv = CFURLCopyPassword(_self->ob_itself); |
| 2608 | _res = Py_BuildValue("O&", |
| 2609 | CFStringRefObj_New, _rv); |
| 2610 | return _res; |
| 2611 | } |
| 2612 | |
| 2613 | static PyObject *CFURLRefObj_CFURLCopyParameterString(CFURLRefObject *_self, PyObject *_args) |
| 2614 | { |
| 2615 | PyObject *_res = NULL; |
| 2616 | CFStringRef _rv; |
| 2617 | CFStringRef charactersToLeaveEscaped; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2618 | #ifndef CFURLCopyParameterString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2619 | PyMac_PRECHECK(CFURLCopyParameterString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2620 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2621 | if (!PyArg_ParseTuple(_args, "O&", |
| 2622 | CFStringRefObj_Convert, &charactersToLeaveEscaped)) |
| 2623 | return NULL; |
| 2624 | _rv = CFURLCopyParameterString(_self->ob_itself, |
| 2625 | charactersToLeaveEscaped); |
| 2626 | _res = Py_BuildValue("O&", |
| 2627 | CFStringRefObj_New, _rv); |
| 2628 | return _res; |
| 2629 | } |
| 2630 | |
| 2631 | static PyObject *CFURLRefObj_CFURLCopyQueryString(CFURLRefObject *_self, PyObject *_args) |
| 2632 | { |
| 2633 | PyObject *_res = NULL; |
| 2634 | CFStringRef _rv; |
| 2635 | CFStringRef charactersToLeaveEscaped; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2636 | #ifndef CFURLCopyQueryString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2637 | PyMac_PRECHECK(CFURLCopyQueryString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2638 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2639 | if (!PyArg_ParseTuple(_args, "O&", |
| 2640 | CFStringRefObj_Convert, &charactersToLeaveEscaped)) |
| 2641 | return NULL; |
| 2642 | _rv = CFURLCopyQueryString(_self->ob_itself, |
| 2643 | charactersToLeaveEscaped); |
| 2644 | _res = Py_BuildValue("O&", |
| 2645 | CFStringRefObj_New, _rv); |
| 2646 | return _res; |
| 2647 | } |
| 2648 | |
| 2649 | static PyObject *CFURLRefObj_CFURLCopyFragment(CFURLRefObject *_self, PyObject *_args) |
| 2650 | { |
| 2651 | PyObject *_res = NULL; |
| 2652 | CFStringRef _rv; |
| 2653 | CFStringRef charactersToLeaveEscaped; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2654 | #ifndef CFURLCopyFragment |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2655 | PyMac_PRECHECK(CFURLCopyFragment); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2656 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2657 | if (!PyArg_ParseTuple(_args, "O&", |
| 2658 | CFStringRefObj_Convert, &charactersToLeaveEscaped)) |
| 2659 | return NULL; |
| 2660 | _rv = CFURLCopyFragment(_self->ob_itself, |
| 2661 | charactersToLeaveEscaped); |
| 2662 | _res = Py_BuildValue("O&", |
| 2663 | CFStringRefObj_New, _rv); |
| 2664 | return _res; |
| 2665 | } |
| 2666 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2667 | static PyObject *CFURLRefObj_CFURLCopyLastPathComponent(CFURLRefObject *_self, PyObject *_args) |
| 2668 | { |
| 2669 | PyObject *_res = NULL; |
| 2670 | CFStringRef _rv; |
| 2671 | #ifndef CFURLCopyLastPathComponent |
| 2672 | PyMac_PRECHECK(CFURLCopyLastPathComponent); |
| 2673 | #endif |
| 2674 | if (!PyArg_ParseTuple(_args, "")) |
| 2675 | return NULL; |
| 2676 | _rv = CFURLCopyLastPathComponent(_self->ob_itself); |
| 2677 | _res = Py_BuildValue("O&", |
| 2678 | CFStringRefObj_New, _rv); |
| 2679 | return _res; |
| 2680 | } |
| 2681 | |
| 2682 | static PyObject *CFURLRefObj_CFURLCopyPathExtension(CFURLRefObject *_self, PyObject *_args) |
| 2683 | { |
| 2684 | PyObject *_res = NULL; |
| 2685 | CFStringRef _rv; |
| 2686 | #ifndef CFURLCopyPathExtension |
| 2687 | PyMac_PRECHECK(CFURLCopyPathExtension); |
| 2688 | #endif |
| 2689 | if (!PyArg_ParseTuple(_args, "")) |
| 2690 | return NULL; |
| 2691 | _rv = CFURLCopyPathExtension(_self->ob_itself); |
| 2692 | _res = Py_BuildValue("O&", |
| 2693 | CFStringRefObj_New, _rv); |
| 2694 | return _res; |
| 2695 | } |
| 2696 | |
| 2697 | static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathComponent(CFURLRefObject *_self, PyObject *_args) |
| 2698 | { |
| 2699 | PyObject *_res = NULL; |
| 2700 | CFURLRef _rv; |
| 2701 | CFStringRef pathComponent; |
| 2702 | Boolean isDirectory; |
| 2703 | if (!PyArg_ParseTuple(_args, "O&l", |
| 2704 | CFStringRefObj_Convert, &pathComponent, |
| 2705 | &isDirectory)) |
| 2706 | return NULL; |
| 2707 | _rv = CFURLCreateCopyAppendingPathComponent((CFAllocatorRef)NULL, |
| 2708 | _self->ob_itself, |
| 2709 | pathComponent, |
| 2710 | isDirectory); |
| 2711 | _res = Py_BuildValue("O&", |
| 2712 | CFURLRefObj_New, _rv); |
| 2713 | return _res; |
| 2714 | } |
| 2715 | |
| 2716 | static PyObject *CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent(CFURLRefObject *_self, PyObject *_args) |
| 2717 | { |
| 2718 | PyObject *_res = NULL; |
| 2719 | CFURLRef _rv; |
| 2720 | if (!PyArg_ParseTuple(_args, "")) |
| 2721 | return NULL; |
| 2722 | _rv = CFURLCreateCopyDeletingLastPathComponent((CFAllocatorRef)NULL, |
| 2723 | _self->ob_itself); |
| 2724 | _res = Py_BuildValue("O&", |
| 2725 | CFURLRefObj_New, _rv); |
| 2726 | return _res; |
| 2727 | } |
| 2728 | |
| 2729 | static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathExtension(CFURLRefObject *_self, PyObject *_args) |
| 2730 | { |
| 2731 | PyObject *_res = NULL; |
| 2732 | CFURLRef _rv; |
| 2733 | CFStringRef extension; |
| 2734 | if (!PyArg_ParseTuple(_args, "O&", |
| 2735 | CFStringRefObj_Convert, &extension)) |
| 2736 | return NULL; |
| 2737 | _rv = CFURLCreateCopyAppendingPathExtension((CFAllocatorRef)NULL, |
| 2738 | _self->ob_itself, |
| 2739 | extension); |
| 2740 | _res = Py_BuildValue("O&", |
| 2741 | CFURLRefObj_New, _rv); |
| 2742 | return _res; |
| 2743 | } |
| 2744 | |
| 2745 | static PyObject *CFURLRefObj_CFURLCreateCopyDeletingPathExtension(CFURLRefObject *_self, PyObject *_args) |
| 2746 | { |
| 2747 | PyObject *_res = NULL; |
| 2748 | CFURLRef _rv; |
| 2749 | if (!PyArg_ParseTuple(_args, "")) |
| 2750 | return NULL; |
| 2751 | _rv = CFURLCreateCopyDeletingPathExtension((CFAllocatorRef)NULL, |
| 2752 | _self->ob_itself); |
| 2753 | _res = Py_BuildValue("O&", |
| 2754 | CFURLRefObj_New, _rv); |
| 2755 | return _res; |
| 2756 | } |
| 2757 | |
| 2758 | static PyObject *CFURLRefObj_CFURLGetFSRef(CFURLRefObject *_self, PyObject *_args) |
| 2759 | { |
| 2760 | PyObject *_res = NULL; |
| 2761 | Boolean _rv; |
| 2762 | FSRef fsRef; |
| 2763 | #ifndef CFURLGetFSRef |
| 2764 | PyMac_PRECHECK(CFURLGetFSRef); |
| 2765 | #endif |
| 2766 | if (!PyArg_ParseTuple(_args, "")) |
| 2767 | return NULL; |
| 2768 | _rv = CFURLGetFSRef(_self->ob_itself, |
| 2769 | &fsRef); |
| 2770 | _res = Py_BuildValue("lO&", |
| 2771 | _rv, |
| 2772 | PyMac_BuildFSRef, fsRef); |
| 2773 | return _res; |
| 2774 | } |
| 2775 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2776 | static PyMethodDef CFURLRefObj_methods[] = { |
| 2777 | {"CFURLCreateData", (PyCFunction)CFURLRefObj_CFURLCreateData, 1, |
| 2778 | "(CFStringEncoding encoding, Boolean escapeWhitespace) -> (CFDataRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2779 | {"CFURLGetFileSystemRepresentation", (PyCFunction)CFURLRefObj_CFURLGetFileSystemRepresentation, 1, |
| 2780 | "(Boolean resolveAgainstBase, CFIndex maxBufLen) -> (Boolean _rv, UInt8 buffer)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2781 | {"CFURLCopyAbsoluteURL", (PyCFunction)CFURLRefObj_CFURLCopyAbsoluteURL, 1, |
| 2782 | "() -> (CFURLRef _rv)"}, |
| 2783 | {"CFURLGetString", (PyCFunction)CFURLRefObj_CFURLGetString, 1, |
| 2784 | "() -> (CFStringRef _rv)"}, |
| 2785 | {"CFURLGetBaseURL", (PyCFunction)CFURLRefObj_CFURLGetBaseURL, 1, |
| 2786 | "() -> (CFURLRef _rv)"}, |
| 2787 | {"CFURLCanBeDecomposed", (PyCFunction)CFURLRefObj_CFURLCanBeDecomposed, 1, |
| 2788 | "() -> (Boolean _rv)"}, |
| 2789 | {"CFURLCopyScheme", (PyCFunction)CFURLRefObj_CFURLCopyScheme, 1, |
| 2790 | "() -> (CFStringRef _rv)"}, |
| 2791 | {"CFURLCopyNetLocation", (PyCFunction)CFURLRefObj_CFURLCopyNetLocation, 1, |
| 2792 | "() -> (CFStringRef _rv)"}, |
| 2793 | {"CFURLCopyPath", (PyCFunction)CFURLRefObj_CFURLCopyPath, 1, |
| 2794 | "() -> (CFStringRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2795 | {"CFURLCopyStrictPath", (PyCFunction)CFURLRefObj_CFURLCopyStrictPath, 1, |
| 2796 | "() -> (CFStringRef _rv, Boolean isAbsolute)"}, |
| 2797 | {"CFURLCopyFileSystemPath", (PyCFunction)CFURLRefObj_CFURLCopyFileSystemPath, 1, |
| 2798 | "(CFURLPathStyle pathStyle) -> (CFStringRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2799 | {"CFURLHasDirectoryPath", (PyCFunction)CFURLRefObj_CFURLHasDirectoryPath, 1, |
| 2800 | "() -> (Boolean _rv)"}, |
| 2801 | {"CFURLCopyResourceSpecifier", (PyCFunction)CFURLRefObj_CFURLCopyResourceSpecifier, 1, |
| 2802 | "() -> (CFStringRef _rv)"}, |
| 2803 | {"CFURLCopyHostName", (PyCFunction)CFURLRefObj_CFURLCopyHostName, 1, |
| 2804 | "() -> (CFStringRef _rv)"}, |
| 2805 | {"CFURLGetPortNumber", (PyCFunction)CFURLRefObj_CFURLGetPortNumber, 1, |
| 2806 | "() -> (SInt32 _rv)"}, |
| 2807 | {"CFURLCopyUserName", (PyCFunction)CFURLRefObj_CFURLCopyUserName, 1, |
| 2808 | "() -> (CFStringRef _rv)"}, |
| 2809 | {"CFURLCopyPassword", (PyCFunction)CFURLRefObj_CFURLCopyPassword, 1, |
| 2810 | "() -> (CFStringRef _rv)"}, |
| 2811 | {"CFURLCopyParameterString", (PyCFunction)CFURLRefObj_CFURLCopyParameterString, 1, |
| 2812 | "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"}, |
| 2813 | {"CFURLCopyQueryString", (PyCFunction)CFURLRefObj_CFURLCopyQueryString, 1, |
| 2814 | "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"}, |
| 2815 | {"CFURLCopyFragment", (PyCFunction)CFURLRefObj_CFURLCopyFragment, 1, |
| 2816 | "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2817 | {"CFURLCopyLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCopyLastPathComponent, 1, |
| 2818 | "() -> (CFStringRef _rv)"}, |
| 2819 | {"CFURLCopyPathExtension", (PyCFunction)CFURLRefObj_CFURLCopyPathExtension, 1, |
| 2820 | "() -> (CFStringRef _rv)"}, |
| 2821 | {"CFURLCreateCopyAppendingPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathComponent, 1, |
| 2822 | "(CFStringRef pathComponent, Boolean isDirectory) -> (CFURLRef _rv)"}, |
| 2823 | {"CFURLCreateCopyDeletingLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent, 1, |
| 2824 | "() -> (CFURLRef _rv)"}, |
| 2825 | {"CFURLCreateCopyAppendingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathExtension, 1, |
| 2826 | "(CFStringRef extension) -> (CFURLRef _rv)"}, |
| 2827 | {"CFURLCreateCopyDeletingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingPathExtension, 1, |
| 2828 | "() -> (CFURLRef _rv)"}, |
| 2829 | {"CFURLGetFSRef", (PyCFunction)CFURLRefObj_CFURLGetFSRef, 1, |
| 2830 | "() -> (Boolean _rv, FSRef fsRef)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2831 | {NULL, NULL, 0} |
| 2832 | }; |
| 2833 | |
| 2834 | PyMethodChain CFURLRefObj_chain = { CFURLRefObj_methods, &CFTypeRefObj_chain }; |
| 2835 | |
| 2836 | static PyObject *CFURLRefObj_getattr(CFURLRefObject *self, char *name) |
| 2837 | { |
| 2838 | return Py_FindMethodInChain(&CFURLRefObj_chain, (PyObject *)self, name); |
| 2839 | } |
| 2840 | |
| 2841 | #define CFURLRefObj_setattr NULL |
| 2842 | |
| 2843 | static int CFURLRefObj_compare(CFURLRefObject *self, CFURLRefObject *other) |
| 2844 | { |
| 2845 | /* XXXX Or should we use CFEqual?? */ |
| 2846 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 2847 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | static PyObject * CFURLRefObj_repr(CFURLRefObject *self) |
| 2852 | { |
| 2853 | char buf[100]; |
Jack Jansen | fd06486 | 2001-09-05 10:31:52 +0000 | [diff] [blame] | 2854 | sprintf(buf, "<CFURL object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2855 | return PyString_FromString(buf); |
| 2856 | } |
| 2857 | |
| 2858 | static int CFURLRefObj_hash(CFURLRefObject *self) |
| 2859 | { |
| 2860 | /* XXXX Or should we use CFHash?? */ |
| 2861 | return (int)self->ob_itself; |
| 2862 | } |
| 2863 | |
| 2864 | PyTypeObject CFURLRef_Type = { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2865 | PyObject_HEAD_INIT(NULL) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2866 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 2867 | "_CF.CFURLRef", /*tp_name*/ |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2868 | sizeof(CFURLRefObject), /*tp_basicsize*/ |
| 2869 | 0, /*tp_itemsize*/ |
| 2870 | /* methods */ |
| 2871 | (destructor) CFURLRefObj_dealloc, /*tp_dealloc*/ |
| 2872 | 0, /*tp_print*/ |
| 2873 | (getattrfunc) CFURLRefObj_getattr, /*tp_getattr*/ |
| 2874 | (setattrfunc) CFURLRefObj_setattr, /*tp_setattr*/ |
| 2875 | (cmpfunc) CFURLRefObj_compare, /*tp_compare*/ |
| 2876 | (reprfunc) CFURLRefObj_repr, /*tp_repr*/ |
| 2877 | (PyNumberMethods *)0, /* tp_as_number */ |
| 2878 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 2879 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 2880 | (hashfunc) CFURLRefObj_hash, /*tp_hash*/ |
| 2881 | }; |
| 2882 | |
| 2883 | /* -------------------- End object type CFURLRef -------------------- */ |
| 2884 | |
| 2885 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2886 | static PyObject *CF___CFRangeMake(PyObject *_self, PyObject *_args) |
| 2887 | { |
| 2888 | PyObject *_res = NULL; |
| 2889 | CFRange _rv; |
| 2890 | CFIndex loc; |
| 2891 | CFIndex len; |
| 2892 | #ifndef __CFRangeMake |
| 2893 | PyMac_PRECHECK(__CFRangeMake); |
| 2894 | #endif |
| 2895 | if (!PyArg_ParseTuple(_args, "ll", |
| 2896 | &loc, |
| 2897 | &len)) |
| 2898 | return NULL; |
| 2899 | _rv = __CFRangeMake(loc, |
| 2900 | len); |
| 2901 | _res = Py_BuildValue("O&", |
| 2902 | CFRange_New, _rv); |
| 2903 | return _res; |
| 2904 | } |
| 2905 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2906 | static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args) |
| 2907 | { |
| 2908 | PyObject *_res = NULL; |
| 2909 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2910 | #ifndef CFAllocatorGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2911 | PyMac_PRECHECK(CFAllocatorGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2912 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2913 | if (!PyArg_ParseTuple(_args, "")) |
| 2914 | return NULL; |
| 2915 | _rv = CFAllocatorGetTypeID(); |
| 2916 | _res = Py_BuildValue("l", |
| 2917 | _rv); |
| 2918 | return _res; |
| 2919 | } |
| 2920 | |
| 2921 | static PyObject *CF_CFAllocatorGetPreferredSizeForSize(PyObject *_self, PyObject *_args) |
| 2922 | { |
| 2923 | PyObject *_res = NULL; |
| 2924 | CFIndex _rv; |
| 2925 | CFIndex size; |
| 2926 | CFOptionFlags hint; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2927 | #ifndef CFAllocatorGetPreferredSizeForSize |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2928 | PyMac_PRECHECK(CFAllocatorGetPreferredSizeForSize); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2929 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2930 | if (!PyArg_ParseTuple(_args, "ll", |
| 2931 | &size, |
| 2932 | &hint)) |
| 2933 | return NULL; |
| 2934 | _rv = CFAllocatorGetPreferredSizeForSize((CFAllocatorRef)NULL, |
| 2935 | size, |
| 2936 | hint); |
| 2937 | _res = Py_BuildValue("l", |
| 2938 | _rv); |
| 2939 | return _res; |
| 2940 | } |
| 2941 | |
| 2942 | static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args) |
| 2943 | { |
| 2944 | PyObject *_res = NULL; |
| 2945 | CFStringRef _rv; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2946 | CFTypeID type_id; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2947 | #ifndef CFCopyTypeIDDescription |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2948 | PyMac_PRECHECK(CFCopyTypeIDDescription); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2949 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2950 | if (!PyArg_ParseTuple(_args, "l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2951 | &type_id)) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2952 | return NULL; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2953 | _rv = CFCopyTypeIDDescription(type_id); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2954 | _res = Py_BuildValue("O&", |
| 2955 | CFStringRefObj_New, _rv); |
| 2956 | return _res; |
| 2957 | } |
| 2958 | |
| 2959 | static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args) |
| 2960 | { |
| 2961 | PyObject *_res = NULL; |
| 2962 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2963 | #ifndef CFArrayGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2964 | PyMac_PRECHECK(CFArrayGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2965 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2966 | if (!PyArg_ParseTuple(_args, "")) |
| 2967 | return NULL; |
| 2968 | _rv = CFArrayGetTypeID(); |
| 2969 | _res = Py_BuildValue("l", |
| 2970 | _rv); |
| 2971 | return _res; |
| 2972 | } |
| 2973 | |
| 2974 | static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args) |
| 2975 | { |
| 2976 | PyObject *_res = NULL; |
| 2977 | CFMutableArrayRef _rv; |
| 2978 | CFIndex capacity; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2979 | #ifndef CFArrayCreateMutable |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2980 | PyMac_PRECHECK(CFArrayCreateMutable); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2981 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 2982 | if (!PyArg_ParseTuple(_args, "l", |
| 2983 | &capacity)) |
| 2984 | return NULL; |
| 2985 | _rv = CFArrayCreateMutable((CFAllocatorRef)NULL, |
| 2986 | capacity, |
| 2987 | &kCFTypeArrayCallBacks); |
| 2988 | _res = Py_BuildValue("O&", |
| 2989 | CFMutableArrayRefObj_New, _rv); |
| 2990 | return _res; |
| 2991 | } |
| 2992 | |
| 2993 | static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args) |
| 2994 | { |
| 2995 | PyObject *_res = NULL; |
| 2996 | CFMutableArrayRef _rv; |
| 2997 | CFIndex capacity; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 2998 | CFArrayRef theArray; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 2999 | #ifndef CFArrayCreateMutableCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3000 | PyMac_PRECHECK(CFArrayCreateMutableCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3001 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3002 | if (!PyArg_ParseTuple(_args, "lO&", |
| 3003 | &capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3004 | CFArrayRefObj_Convert, &theArray)) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3005 | return NULL; |
| 3006 | _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL, |
| 3007 | capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3008 | theArray); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3009 | _res = Py_BuildValue("O&", |
| 3010 | CFMutableArrayRefObj_New, _rv); |
| 3011 | return _res; |
| 3012 | } |
| 3013 | |
| 3014 | static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args) |
| 3015 | { |
| 3016 | PyObject *_res = NULL; |
| 3017 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3018 | #ifndef CFDataGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3019 | PyMac_PRECHECK(CFDataGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3020 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3021 | if (!PyArg_ParseTuple(_args, "")) |
| 3022 | return NULL; |
| 3023 | _rv = CFDataGetTypeID(); |
| 3024 | _res = Py_BuildValue("l", |
| 3025 | _rv); |
| 3026 | return _res; |
| 3027 | } |
| 3028 | |
| 3029 | static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args) |
| 3030 | { |
| 3031 | PyObject *_res = NULL; |
| 3032 | CFDataRef _rv; |
| 3033 | unsigned char *bytes__in__; |
| 3034 | long bytes__len__; |
| 3035 | int bytes__in_len__; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3036 | #ifndef CFDataCreate |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3037 | PyMac_PRECHECK(CFDataCreate); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3038 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3039 | if (!PyArg_ParseTuple(_args, "s#", |
| 3040 | &bytes__in__, &bytes__in_len__)) |
| 3041 | return NULL; |
| 3042 | bytes__len__ = bytes__in_len__; |
| 3043 | _rv = CFDataCreate((CFAllocatorRef)NULL, |
| 3044 | bytes__in__, bytes__len__); |
| 3045 | _res = Py_BuildValue("O&", |
| 3046 | CFDataRefObj_New, _rv); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3047 | return _res; |
| 3048 | } |
| 3049 | |
| 3050 | static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args) |
| 3051 | { |
| 3052 | PyObject *_res = NULL; |
| 3053 | CFDataRef _rv; |
| 3054 | unsigned char *bytes__in__; |
| 3055 | long bytes__len__; |
| 3056 | int bytes__in_len__; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3057 | #ifndef CFDataCreateWithBytesNoCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3058 | PyMac_PRECHECK(CFDataCreateWithBytesNoCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3059 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3060 | if (!PyArg_ParseTuple(_args, "s#", |
| 3061 | &bytes__in__, &bytes__in_len__)) |
| 3062 | return NULL; |
| 3063 | bytes__len__ = bytes__in_len__; |
| 3064 | _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL, |
| 3065 | bytes__in__, bytes__len__, |
| 3066 | (CFAllocatorRef)NULL); |
| 3067 | _res = Py_BuildValue("O&", |
| 3068 | CFDataRefObj_New, _rv); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3069 | return _res; |
| 3070 | } |
| 3071 | |
| 3072 | static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args) |
| 3073 | { |
| 3074 | PyObject *_res = NULL; |
| 3075 | CFMutableDataRef _rv; |
| 3076 | CFIndex capacity; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3077 | #ifndef CFDataCreateMutable |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3078 | PyMac_PRECHECK(CFDataCreateMutable); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3079 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3080 | if (!PyArg_ParseTuple(_args, "l", |
| 3081 | &capacity)) |
| 3082 | return NULL; |
| 3083 | _rv = CFDataCreateMutable((CFAllocatorRef)NULL, |
| 3084 | capacity); |
| 3085 | _res = Py_BuildValue("O&", |
| 3086 | CFMutableDataRefObj_New, _rv); |
| 3087 | return _res; |
| 3088 | } |
| 3089 | |
| 3090 | static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args) |
| 3091 | { |
| 3092 | PyObject *_res = NULL; |
| 3093 | CFMutableDataRef _rv; |
| 3094 | CFIndex capacity; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3095 | CFDataRef theData; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3096 | #ifndef CFDataCreateMutableCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3097 | PyMac_PRECHECK(CFDataCreateMutableCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3098 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3099 | if (!PyArg_ParseTuple(_args, "lO&", |
| 3100 | &capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3101 | CFDataRefObj_Convert, &theData)) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3102 | return NULL; |
| 3103 | _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL, |
| 3104 | capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3105 | theData); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3106 | _res = Py_BuildValue("O&", |
| 3107 | CFMutableDataRefObj_New, _rv); |
| 3108 | return _res; |
| 3109 | } |
| 3110 | |
| 3111 | static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args) |
| 3112 | { |
| 3113 | PyObject *_res = NULL; |
| 3114 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3115 | #ifndef CFDictionaryGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3116 | PyMac_PRECHECK(CFDictionaryGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3117 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3118 | if (!PyArg_ParseTuple(_args, "")) |
| 3119 | return NULL; |
| 3120 | _rv = CFDictionaryGetTypeID(); |
| 3121 | _res = Py_BuildValue("l", |
| 3122 | _rv); |
| 3123 | return _res; |
| 3124 | } |
| 3125 | |
| 3126 | static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args) |
| 3127 | { |
| 3128 | PyObject *_res = NULL; |
| 3129 | CFMutableDictionaryRef _rv; |
| 3130 | CFIndex capacity; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3131 | #ifndef CFDictionaryCreateMutable |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3132 | PyMac_PRECHECK(CFDictionaryCreateMutable); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3133 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3134 | if (!PyArg_ParseTuple(_args, "l", |
| 3135 | &capacity)) |
| 3136 | return NULL; |
| 3137 | _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL, |
| 3138 | capacity, |
| 3139 | &kCFTypeDictionaryKeyCallBacks, |
| 3140 | &kCFTypeDictionaryValueCallBacks); |
| 3141 | _res = Py_BuildValue("O&", |
| 3142 | CFMutableDictionaryRefObj_New, _rv); |
| 3143 | return _res; |
| 3144 | } |
| 3145 | |
| 3146 | static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args) |
| 3147 | { |
| 3148 | PyObject *_res = NULL; |
| 3149 | CFMutableDictionaryRef _rv; |
| 3150 | CFIndex capacity; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3151 | CFDictionaryRef theDict; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3152 | #ifndef CFDictionaryCreateMutableCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3153 | PyMac_PRECHECK(CFDictionaryCreateMutableCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3154 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3155 | if (!PyArg_ParseTuple(_args, "lO&", |
| 3156 | &capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3157 | CFDictionaryRefObj_Convert, &theDict)) |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3158 | return NULL; |
| 3159 | _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL, |
| 3160 | capacity, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3161 | theDict); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3162 | _res = Py_BuildValue("O&", |
| 3163 | CFMutableDictionaryRefObj_New, _rv); |
| 3164 | return _res; |
| 3165 | } |
| 3166 | |
| 3167 | static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args) |
| 3168 | { |
| 3169 | PyObject *_res = NULL; |
| 3170 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3171 | #ifndef CFStringGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3172 | PyMac_PRECHECK(CFStringGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3173 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3174 | if (!PyArg_ParseTuple(_args, "")) |
| 3175 | return NULL; |
| 3176 | _rv = CFStringGetTypeID(); |
| 3177 | _res = Py_BuildValue("l", |
| 3178 | _rv); |
| 3179 | return _res; |
| 3180 | } |
| 3181 | |
| 3182 | static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args) |
| 3183 | { |
| 3184 | PyObject *_res = NULL; |
| 3185 | CFStringRef _rv; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3186 | Str255 pStr; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3187 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3188 | #ifndef CFStringCreateWithPascalString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3189 | PyMac_PRECHECK(CFStringCreateWithPascalString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3190 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3191 | if (!PyArg_ParseTuple(_args, "O&l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3192 | PyMac_GetStr255, pStr, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3193 | &encoding)) |
| 3194 | return NULL; |
| 3195 | _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL, |
| 3196 | pStr, |
| 3197 | encoding); |
| 3198 | _res = Py_BuildValue("O&", |
| 3199 | CFStringRefObj_New, _rv); |
| 3200 | return _res; |
| 3201 | } |
| 3202 | |
| 3203 | static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args) |
| 3204 | { |
| 3205 | PyObject *_res = NULL; |
| 3206 | CFStringRef _rv; |
| 3207 | char* cStr; |
| 3208 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3209 | #ifndef CFStringCreateWithCString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3210 | PyMac_PRECHECK(CFStringCreateWithCString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3211 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3212 | if (!PyArg_ParseTuple(_args, "sl", |
| 3213 | &cStr, |
| 3214 | &encoding)) |
| 3215 | return NULL; |
| 3216 | _rv = CFStringCreateWithCString((CFAllocatorRef)NULL, |
| 3217 | cStr, |
| 3218 | encoding); |
| 3219 | _res = Py_BuildValue("O&", |
| 3220 | CFStringRefObj_New, _rv); |
| 3221 | return _res; |
| 3222 | } |
| 3223 | |
| 3224 | static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args) |
| 3225 | { |
| 3226 | PyObject *_res = NULL; |
| 3227 | CFStringRef _rv; |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3228 | Str255 pStr; |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3229 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3230 | #ifndef CFStringCreateWithPascalStringNoCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3231 | PyMac_PRECHECK(CFStringCreateWithPascalStringNoCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3232 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3233 | if (!PyArg_ParseTuple(_args, "O&l", |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3234 | PyMac_GetStr255, pStr, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3235 | &encoding)) |
| 3236 | return NULL; |
| 3237 | _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL, |
| 3238 | pStr, |
| 3239 | encoding, |
| 3240 | (CFAllocatorRef)NULL); |
| 3241 | _res = Py_BuildValue("O&", |
| 3242 | CFStringRefObj_New, _rv); |
| 3243 | return _res; |
| 3244 | } |
| 3245 | |
| 3246 | static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args) |
| 3247 | { |
| 3248 | PyObject *_res = NULL; |
| 3249 | CFStringRef _rv; |
| 3250 | char* cStr; |
| 3251 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3252 | #ifndef CFStringCreateWithCStringNoCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3253 | PyMac_PRECHECK(CFStringCreateWithCStringNoCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3254 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3255 | if (!PyArg_ParseTuple(_args, "sl", |
| 3256 | &cStr, |
| 3257 | &encoding)) |
| 3258 | return NULL; |
| 3259 | _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL, |
| 3260 | cStr, |
| 3261 | encoding, |
| 3262 | (CFAllocatorRef)NULL); |
| 3263 | _res = Py_BuildValue("O&", |
| 3264 | CFStringRefObj_New, _rv); |
| 3265 | return _res; |
| 3266 | } |
| 3267 | |
| 3268 | static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args) |
| 3269 | { |
| 3270 | PyObject *_res = NULL; |
| 3271 | CFMutableStringRef _rv; |
| 3272 | CFIndex maxLength; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3273 | #ifndef CFStringCreateMutable |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3274 | PyMac_PRECHECK(CFStringCreateMutable); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3275 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3276 | if (!PyArg_ParseTuple(_args, "l", |
| 3277 | &maxLength)) |
| 3278 | return NULL; |
| 3279 | _rv = CFStringCreateMutable((CFAllocatorRef)NULL, |
| 3280 | maxLength); |
| 3281 | _res = Py_BuildValue("O&", |
| 3282 | CFMutableStringRefObj_New, _rv); |
| 3283 | return _res; |
| 3284 | } |
| 3285 | |
| 3286 | static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args) |
| 3287 | { |
| 3288 | PyObject *_res = NULL; |
| 3289 | CFMutableStringRef _rv; |
| 3290 | CFIndex maxLength; |
| 3291 | CFStringRef theString; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3292 | #ifndef CFStringCreateMutableCopy |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3293 | PyMac_PRECHECK(CFStringCreateMutableCopy); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3294 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3295 | if (!PyArg_ParseTuple(_args, "lO&", |
| 3296 | &maxLength, |
| 3297 | CFStringRefObj_Convert, &theString)) |
| 3298 | return NULL; |
| 3299 | _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL, |
| 3300 | maxLength, |
| 3301 | theString); |
| 3302 | _res = Py_BuildValue("O&", |
| 3303 | CFMutableStringRefObj_New, _rv); |
| 3304 | return _res; |
| 3305 | } |
| 3306 | |
| 3307 | static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args) |
| 3308 | { |
| 3309 | PyObject *_res = NULL; |
| 3310 | CFStringRef _rv; |
| 3311 | unsigned char *bytes__in__; |
| 3312 | long bytes__len__; |
| 3313 | int bytes__in_len__; |
| 3314 | CFStringEncoding encoding; |
| 3315 | Boolean isExternalRepresentation; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3316 | #ifndef CFStringCreateWithBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3317 | PyMac_PRECHECK(CFStringCreateWithBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3318 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3319 | if (!PyArg_ParseTuple(_args, "s#ll", |
| 3320 | &bytes__in__, &bytes__in_len__, |
| 3321 | &encoding, |
| 3322 | &isExternalRepresentation)) |
| 3323 | return NULL; |
| 3324 | bytes__len__ = bytes__in_len__; |
| 3325 | _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL, |
| 3326 | bytes__in__, bytes__len__, |
| 3327 | encoding, |
| 3328 | isExternalRepresentation); |
| 3329 | _res = Py_BuildValue("O&", |
| 3330 | CFStringRefObj_New, _rv); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3331 | return _res; |
| 3332 | } |
| 3333 | |
| 3334 | static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args) |
| 3335 | { |
| 3336 | PyObject *_res = NULL; |
| 3337 | CFStringEncoding _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3338 | #ifndef CFStringGetSystemEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3339 | PyMac_PRECHECK(CFStringGetSystemEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3340 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3341 | if (!PyArg_ParseTuple(_args, "")) |
| 3342 | return NULL; |
| 3343 | _rv = CFStringGetSystemEncoding(); |
| 3344 | _res = Py_BuildValue("l", |
| 3345 | _rv); |
| 3346 | return _res; |
| 3347 | } |
| 3348 | |
| 3349 | static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args) |
| 3350 | { |
| 3351 | PyObject *_res = NULL; |
| 3352 | CFIndex _rv; |
| 3353 | CFIndex length; |
| 3354 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3355 | #ifndef CFStringGetMaximumSizeForEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3356 | PyMac_PRECHECK(CFStringGetMaximumSizeForEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3357 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3358 | if (!PyArg_ParseTuple(_args, "ll", |
| 3359 | &length, |
| 3360 | &encoding)) |
| 3361 | return NULL; |
| 3362 | _rv = CFStringGetMaximumSizeForEncoding(length, |
| 3363 | encoding); |
| 3364 | _res = Py_BuildValue("l", |
| 3365 | _rv); |
| 3366 | return _res; |
| 3367 | } |
| 3368 | |
| 3369 | static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args) |
| 3370 | { |
| 3371 | PyObject *_res = NULL; |
| 3372 | Boolean _rv; |
| 3373 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3374 | #ifndef CFStringIsEncodingAvailable |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3375 | PyMac_PRECHECK(CFStringIsEncodingAvailable); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3376 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3377 | if (!PyArg_ParseTuple(_args, "l", |
| 3378 | &encoding)) |
| 3379 | return NULL; |
| 3380 | _rv = CFStringIsEncodingAvailable(encoding); |
| 3381 | _res = Py_BuildValue("l", |
| 3382 | _rv); |
| 3383 | return _res; |
| 3384 | } |
| 3385 | |
| 3386 | static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args) |
| 3387 | { |
| 3388 | PyObject *_res = NULL; |
| 3389 | CFStringRef _rv; |
| 3390 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3391 | #ifndef CFStringGetNameOfEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3392 | PyMac_PRECHECK(CFStringGetNameOfEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3393 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3394 | if (!PyArg_ParseTuple(_args, "l", |
| 3395 | &encoding)) |
| 3396 | return NULL; |
| 3397 | _rv = CFStringGetNameOfEncoding(encoding); |
| 3398 | _res = Py_BuildValue("O&", |
| 3399 | CFStringRefObj_New, _rv); |
| 3400 | return _res; |
| 3401 | } |
| 3402 | |
| 3403 | static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args) |
| 3404 | { |
| 3405 | PyObject *_res = NULL; |
| 3406 | UInt32 _rv; |
| 3407 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3408 | #ifndef CFStringConvertEncodingToNSStringEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3409 | PyMac_PRECHECK(CFStringConvertEncodingToNSStringEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3410 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3411 | if (!PyArg_ParseTuple(_args, "l", |
| 3412 | &encoding)) |
| 3413 | return NULL; |
| 3414 | _rv = CFStringConvertEncodingToNSStringEncoding(encoding); |
| 3415 | _res = Py_BuildValue("l", |
| 3416 | _rv); |
| 3417 | return _res; |
| 3418 | } |
| 3419 | |
| 3420 | static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args) |
| 3421 | { |
| 3422 | PyObject *_res = NULL; |
| 3423 | CFStringEncoding _rv; |
| 3424 | UInt32 encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3425 | #ifndef CFStringConvertNSStringEncodingToEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3426 | PyMac_PRECHECK(CFStringConvertNSStringEncodingToEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3427 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3428 | if (!PyArg_ParseTuple(_args, "l", |
| 3429 | &encoding)) |
| 3430 | return NULL; |
| 3431 | _rv = CFStringConvertNSStringEncodingToEncoding(encoding); |
| 3432 | _res = Py_BuildValue("l", |
| 3433 | _rv); |
| 3434 | return _res; |
| 3435 | } |
| 3436 | |
| 3437 | static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args) |
| 3438 | { |
| 3439 | PyObject *_res = NULL; |
| 3440 | UInt32 _rv; |
| 3441 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3442 | #ifndef CFStringConvertEncodingToWindowsCodepage |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3443 | PyMac_PRECHECK(CFStringConvertEncodingToWindowsCodepage); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3444 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3445 | if (!PyArg_ParseTuple(_args, "l", |
| 3446 | &encoding)) |
| 3447 | return NULL; |
| 3448 | _rv = CFStringConvertEncodingToWindowsCodepage(encoding); |
| 3449 | _res = Py_BuildValue("l", |
| 3450 | _rv); |
| 3451 | return _res; |
| 3452 | } |
| 3453 | |
| 3454 | static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args) |
| 3455 | { |
| 3456 | PyObject *_res = NULL; |
| 3457 | CFStringEncoding _rv; |
| 3458 | UInt32 codepage; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3459 | #ifndef CFStringConvertWindowsCodepageToEncoding |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3460 | PyMac_PRECHECK(CFStringConvertWindowsCodepageToEncoding); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3461 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3462 | if (!PyArg_ParseTuple(_args, "l", |
| 3463 | &codepage)) |
| 3464 | return NULL; |
| 3465 | _rv = CFStringConvertWindowsCodepageToEncoding(codepage); |
| 3466 | _res = Py_BuildValue("l", |
| 3467 | _rv); |
| 3468 | return _res; |
| 3469 | } |
| 3470 | |
| 3471 | static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args) |
| 3472 | { |
| 3473 | PyObject *_res = NULL; |
| 3474 | CFStringRef _rv; |
| 3475 | CFStringEncoding encoding; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3476 | #ifndef CFStringConvertEncodingToIANACharSetName |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3477 | PyMac_PRECHECK(CFStringConvertEncodingToIANACharSetName); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3478 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3479 | if (!PyArg_ParseTuple(_args, "l", |
| 3480 | &encoding)) |
| 3481 | return NULL; |
| 3482 | _rv = CFStringConvertEncodingToIANACharSetName(encoding); |
| 3483 | _res = Py_BuildValue("O&", |
| 3484 | CFStringRefObj_New, _rv); |
| 3485 | return _res; |
| 3486 | } |
| 3487 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3488 | static PyObject *CF_CFStringGetMostCompatibleMacStringEncoding(PyObject *_self, PyObject *_args) |
| 3489 | { |
| 3490 | PyObject *_res = NULL; |
| 3491 | CFStringEncoding _rv; |
| 3492 | CFStringEncoding encoding; |
| 3493 | #ifndef CFStringGetMostCompatibleMacStringEncoding |
| 3494 | PyMac_PRECHECK(CFStringGetMostCompatibleMacStringEncoding); |
| 3495 | #endif |
| 3496 | if (!PyArg_ParseTuple(_args, "l", |
| 3497 | &encoding)) |
| 3498 | return NULL; |
| 3499 | _rv = CFStringGetMostCompatibleMacStringEncoding(encoding); |
| 3500 | _res = Py_BuildValue("l", |
| 3501 | _rv); |
| 3502 | return _res; |
| 3503 | } |
| 3504 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3505 | static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args) |
| 3506 | { |
| 3507 | PyObject *_res = NULL; |
| 3508 | CFStringRef _rv; |
| 3509 | char* cStr; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3510 | #ifndef __CFStringMakeConstantString |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3511 | PyMac_PRECHECK(__CFStringMakeConstantString); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3512 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3513 | if (!PyArg_ParseTuple(_args, "s", |
| 3514 | &cStr)) |
| 3515 | return NULL; |
| 3516 | _rv = __CFStringMakeConstantString(cStr); |
| 3517 | _res = Py_BuildValue("O&", |
| 3518 | CFStringRefObj_New, _rv); |
| 3519 | return _res; |
| 3520 | } |
| 3521 | |
| 3522 | static PyObject *CF_CFURLGetTypeID(PyObject *_self, PyObject *_args) |
| 3523 | { |
| 3524 | PyObject *_res = NULL; |
| 3525 | CFTypeID _rv; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3526 | #ifndef CFURLGetTypeID |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3527 | PyMac_PRECHECK(CFURLGetTypeID); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3528 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3529 | if (!PyArg_ParseTuple(_args, "")) |
| 3530 | return NULL; |
| 3531 | _rv = CFURLGetTypeID(); |
| 3532 | _res = Py_BuildValue("l", |
| 3533 | _rv); |
| 3534 | return _res; |
| 3535 | } |
| 3536 | |
| 3537 | static PyObject *CF_CFURLCreateWithBytes(PyObject *_self, PyObject *_args) |
| 3538 | { |
| 3539 | PyObject *_res = NULL; |
| 3540 | CFURLRef _rv; |
| 3541 | unsigned char *URLBytes__in__; |
| 3542 | long URLBytes__len__; |
| 3543 | int URLBytes__in_len__; |
| 3544 | CFStringEncoding encoding; |
| 3545 | CFURLRef baseURL; |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3546 | #ifndef CFURLCreateWithBytes |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3547 | PyMac_PRECHECK(CFURLCreateWithBytes); |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 3548 | #endif |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3549 | if (!PyArg_ParseTuple(_args, "s#lO&", |
| 3550 | &URLBytes__in__, &URLBytes__in_len__, |
| 3551 | &encoding, |
| 3552 | OptionalCFURLRefObj_Convert, &baseURL)) |
| 3553 | return NULL; |
| 3554 | URLBytes__len__ = URLBytes__in_len__; |
| 3555 | _rv = CFURLCreateWithBytes((CFAllocatorRef)NULL, |
| 3556 | URLBytes__in__, URLBytes__len__, |
| 3557 | encoding, |
| 3558 | baseURL); |
| 3559 | _res = Py_BuildValue("O&", |
| 3560 | CFURLRefObj_New, _rv); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3561 | return _res; |
| 3562 | } |
| 3563 | |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3564 | static PyObject *CF_CFURLCreateFromFileSystemRepresentation(PyObject *_self, PyObject *_args) |
| 3565 | { |
| 3566 | PyObject *_res = NULL; |
| 3567 | CFURLRef _rv; |
| 3568 | unsigned char *buffer__in__; |
| 3569 | long buffer__len__; |
| 3570 | int buffer__in_len__; |
| 3571 | Boolean isDirectory; |
| 3572 | #ifndef CFURLCreateFromFileSystemRepresentation |
| 3573 | PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentation); |
| 3574 | #endif |
| 3575 | if (!PyArg_ParseTuple(_args, "s#l", |
| 3576 | &buffer__in__, &buffer__in_len__, |
| 3577 | &isDirectory)) |
| 3578 | return NULL; |
| 3579 | buffer__len__ = buffer__in_len__; |
| 3580 | _rv = CFURLCreateFromFileSystemRepresentation((CFAllocatorRef)NULL, |
| 3581 | buffer__in__, buffer__len__, |
| 3582 | isDirectory); |
| 3583 | _res = Py_BuildValue("O&", |
| 3584 | CFURLRefObj_New, _rv); |
| 3585 | return _res; |
| 3586 | } |
| 3587 | |
| 3588 | static PyObject *CF_CFURLCreateFromFileSystemRepresentationRelativeToBase(PyObject *_self, PyObject *_args) |
| 3589 | { |
| 3590 | PyObject *_res = NULL; |
| 3591 | CFURLRef _rv; |
| 3592 | unsigned char *buffer__in__; |
| 3593 | long buffer__len__; |
| 3594 | int buffer__in_len__; |
| 3595 | Boolean isDirectory; |
| 3596 | CFURLRef baseURL; |
| 3597 | #ifndef CFURLCreateFromFileSystemRepresentationRelativeToBase |
| 3598 | PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentationRelativeToBase); |
| 3599 | #endif |
| 3600 | if (!PyArg_ParseTuple(_args, "s#lO&", |
| 3601 | &buffer__in__, &buffer__in_len__, |
| 3602 | &isDirectory, |
| 3603 | OptionalCFURLRefObj_Convert, &baseURL)) |
| 3604 | return NULL; |
| 3605 | buffer__len__ = buffer__in_len__; |
| 3606 | _rv = CFURLCreateFromFileSystemRepresentationRelativeToBase((CFAllocatorRef)NULL, |
| 3607 | buffer__in__, buffer__len__, |
| 3608 | isDirectory, |
| 3609 | baseURL); |
| 3610 | _res = Py_BuildValue("O&", |
| 3611 | CFURLRefObj_New, _rv); |
| 3612 | return _res; |
| 3613 | } |
| 3614 | |
| 3615 | static PyObject *CF_CFURLCreateFromFSRef(PyObject *_self, PyObject *_args) |
| 3616 | { |
| 3617 | PyObject *_res = NULL; |
| 3618 | CFURLRef _rv; |
| 3619 | FSRef fsRef; |
| 3620 | #ifndef CFURLCreateFromFSRef |
| 3621 | PyMac_PRECHECK(CFURLCreateFromFSRef); |
| 3622 | #endif |
| 3623 | if (!PyArg_ParseTuple(_args, "O&", |
| 3624 | PyMac_GetFSRef, &fsRef)) |
| 3625 | return NULL; |
| 3626 | _rv = CFURLCreateFromFSRef((CFAllocatorRef)NULL, |
| 3627 | &fsRef); |
| 3628 | _res = Py_BuildValue("O&", |
| 3629 | CFURLRefObj_New, _rv); |
| 3630 | return _res; |
| 3631 | } |
| 3632 | |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3633 | static PyMethodDef CF_methods[] = { |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3634 | {"__CFRangeMake", (PyCFunction)CF___CFRangeMake, 1, |
| 3635 | "(CFIndex loc, CFIndex len) -> (CFRange _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3636 | {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1, |
| 3637 | "() -> (CFTypeID _rv)"}, |
| 3638 | {"CFAllocatorGetPreferredSizeForSize", (PyCFunction)CF_CFAllocatorGetPreferredSizeForSize, 1, |
| 3639 | "(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)"}, |
| 3640 | {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3641 | "(CFTypeID type_id) -> (CFStringRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3642 | {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1, |
| 3643 | "() -> (CFTypeID _rv)"}, |
| 3644 | {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1, |
| 3645 | "(CFIndex capacity) -> (CFMutableArrayRef _rv)"}, |
| 3646 | {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3647 | "(CFIndex capacity, CFArrayRef theArray) -> (CFMutableArrayRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3648 | {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1, |
| 3649 | "() -> (CFTypeID _rv)"}, |
| 3650 | {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1, |
| 3651 | "(Buffer bytes) -> (CFDataRef _rv)"}, |
| 3652 | {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1, |
| 3653 | "(Buffer bytes) -> (CFDataRef _rv)"}, |
| 3654 | {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1, |
| 3655 | "(CFIndex capacity) -> (CFMutableDataRef _rv)"}, |
| 3656 | {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3657 | "(CFIndex capacity, CFDataRef theData) -> (CFMutableDataRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3658 | {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1, |
| 3659 | "() -> (CFTypeID _rv)"}, |
| 3660 | {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1, |
| 3661 | "(CFIndex capacity) -> (CFMutableDictionaryRef _rv)"}, |
| 3662 | {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3663 | "(CFIndex capacity, CFDictionaryRef theDict) -> (CFMutableDictionaryRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3664 | {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1, |
| 3665 | "() -> (CFTypeID _rv)"}, |
| 3666 | {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3667 | "(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3668 | {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1, |
| 3669 | "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
| 3670 | {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3671 | "(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3672 | {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1, |
| 3673 | "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
| 3674 | {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1, |
| 3675 | "(CFIndex maxLength) -> (CFMutableStringRef _rv)"}, |
| 3676 | {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1, |
| 3677 | "(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)"}, |
| 3678 | {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1, |
| 3679 | "(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)"}, |
| 3680 | {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1, |
| 3681 | "() -> (CFStringEncoding _rv)"}, |
| 3682 | {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1, |
| 3683 | "(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)"}, |
| 3684 | {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1, |
| 3685 | "(CFStringEncoding encoding) -> (Boolean _rv)"}, |
| 3686 | {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1, |
| 3687 | "(CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
| 3688 | {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1, |
| 3689 | "(CFStringEncoding encoding) -> (UInt32 _rv)"}, |
| 3690 | {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1, |
| 3691 | "(UInt32 encoding) -> (CFStringEncoding _rv)"}, |
| 3692 | {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1, |
| 3693 | "(CFStringEncoding encoding) -> (UInt32 _rv)"}, |
| 3694 | {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1, |
| 3695 | "(UInt32 codepage) -> (CFStringEncoding _rv)"}, |
| 3696 | {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1, |
| 3697 | "(CFStringEncoding encoding) -> (CFStringRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3698 | {"CFStringGetMostCompatibleMacStringEncoding", (PyCFunction)CF_CFStringGetMostCompatibleMacStringEncoding, 1, |
| 3699 | "(CFStringEncoding encoding) -> (CFStringEncoding _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3700 | {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1, |
| 3701 | "(char* cStr) -> (CFStringRef _rv)"}, |
| 3702 | {"CFURLGetTypeID", (PyCFunction)CF_CFURLGetTypeID, 1, |
| 3703 | "() -> (CFTypeID _rv)"}, |
| 3704 | {"CFURLCreateWithBytes", (PyCFunction)CF_CFURLCreateWithBytes, 1, |
| 3705 | "(Buffer URLBytes, CFStringEncoding encoding, CFURLRef baseURL) -> (CFURLRef _rv)"}, |
Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 3706 | {"CFURLCreateFromFileSystemRepresentation", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentation, 1, |
| 3707 | "(Buffer buffer, Boolean isDirectory) -> (CFURLRef _rv)"}, |
| 3708 | {"CFURLCreateFromFileSystemRepresentationRelativeToBase", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentationRelativeToBase, 1, |
| 3709 | "(Buffer buffer, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)"}, |
| 3710 | {"CFURLCreateFromFSRef", (PyCFunction)CF_CFURLCreateFromFSRef, 1, |
| 3711 | "(FSRef fsRef) -> (CFURLRef _rv)"}, |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3712 | {NULL, NULL, 0} |
| 3713 | }; |
| 3714 | |
| 3715 | |
| 3716 | |
| 3717 | |
| 3718 | void init_CF(void) |
| 3719 | { |
| 3720 | PyObject *m; |
| 3721 | PyObject *d; |
| 3722 | |
| 3723 | |
| 3724 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 3725 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New); |
| 3726 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert); |
| 3727 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New); |
| 3728 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert); |
| 3729 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New); |
| 3730 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert); |
| 3731 | |
| 3732 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New); |
| 3733 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert); |
| 3734 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New); |
| 3735 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert); |
| 3736 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New); |
| 3737 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert); |
| 3738 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New); |
| 3739 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert); |
| 3740 | PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New); |
| 3741 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert); |
| 3742 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert); |
Jack Jansen | 50ecb0a | 2001-08-23 14:02:09 +0000 | [diff] [blame] | 3743 | |
| 3744 | |
| 3745 | m = Py_InitModule("_CF", CF_methods); |
| 3746 | d = PyModule_GetDict(m); |
| 3747 | CF_Error = PyMac_GetOSErrException(); |
| 3748 | if (CF_Error == NULL || |
| 3749 | PyDict_SetItemString(d, "Error", CF_Error) != 0) |
| 3750 | return; |
| 3751 | CFTypeRef_Type.ob_type = &PyType_Type; |
| 3752 | Py_INCREF(&CFTypeRef_Type); |
| 3753 | if (PyDict_SetItemString(d, "CFTypeRefType", (PyObject *)&CFTypeRef_Type) != 0) |
| 3754 | Py_FatalError("can't initialize CFTypeRefType"); |
| 3755 | CFArrayRef_Type.ob_type = &PyType_Type; |
| 3756 | Py_INCREF(&CFArrayRef_Type); |
| 3757 | if (PyDict_SetItemString(d, "CFArrayRefType", (PyObject *)&CFArrayRef_Type) != 0) |
| 3758 | Py_FatalError("can't initialize CFArrayRefType"); |
| 3759 | CFMutableArrayRef_Type.ob_type = &PyType_Type; |
| 3760 | Py_INCREF(&CFMutableArrayRef_Type); |
| 3761 | if (PyDict_SetItemString(d, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type) != 0) |
| 3762 | Py_FatalError("can't initialize CFMutableArrayRefType"); |
| 3763 | CFDictionaryRef_Type.ob_type = &PyType_Type; |
| 3764 | Py_INCREF(&CFDictionaryRef_Type); |
| 3765 | if (PyDict_SetItemString(d, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type) != 0) |
| 3766 | Py_FatalError("can't initialize CFDictionaryRefType"); |
| 3767 | CFMutableDictionaryRef_Type.ob_type = &PyType_Type; |
| 3768 | Py_INCREF(&CFMutableDictionaryRef_Type); |
| 3769 | if (PyDict_SetItemString(d, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type) != 0) |
| 3770 | Py_FatalError("can't initialize CFMutableDictionaryRefType"); |
| 3771 | CFDataRef_Type.ob_type = &PyType_Type; |
| 3772 | Py_INCREF(&CFDataRef_Type); |
| 3773 | if (PyDict_SetItemString(d, "CFDataRefType", (PyObject *)&CFDataRef_Type) != 0) |
| 3774 | Py_FatalError("can't initialize CFDataRefType"); |
| 3775 | CFMutableDataRef_Type.ob_type = &PyType_Type; |
| 3776 | Py_INCREF(&CFMutableDataRef_Type); |
| 3777 | if (PyDict_SetItemString(d, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type) != 0) |
| 3778 | Py_FatalError("can't initialize CFMutableDataRefType"); |
| 3779 | CFStringRef_Type.ob_type = &PyType_Type; |
| 3780 | Py_INCREF(&CFStringRef_Type); |
| 3781 | if (PyDict_SetItemString(d, "CFStringRefType", (PyObject *)&CFStringRef_Type) != 0) |
| 3782 | Py_FatalError("can't initialize CFStringRefType"); |
| 3783 | CFMutableStringRef_Type.ob_type = &PyType_Type; |
| 3784 | Py_INCREF(&CFMutableStringRef_Type); |
| 3785 | if (PyDict_SetItemString(d, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type) != 0) |
| 3786 | Py_FatalError("can't initialize CFMutableStringRefType"); |
| 3787 | CFURLRef_Type.ob_type = &PyType_Type; |
| 3788 | Py_INCREF(&CFURLRef_Type); |
| 3789 | if (PyDict_SetItemString(d, "CFURLRefType", (PyObject *)&CFURLRef_Type) != 0) |
| 3790 | Py_FatalError("can't initialize CFURLRefType"); |
| 3791 | } |
| 3792 | |
| 3793 | /* ========================= End module _CF ========================= */ |
| 3794 | |