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