_make_boundary(): Fix for SF bug #745478, broken boundary calculation
[python/dscho.git] / Mac / Modules / cf / _CFmodule.c
blobb6e434af77ab908ff61dee6c9876597962c39629
2 /* =========================== Module _CF =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <CFBase.h>
25 #include <CFArray.h>
26 #include <CFData.h>
27 #include <CFDictionary.h>
28 #include <CFString.h>
29 #include <CFURL.h>
30 #include <CFPropertyList.h>
31 #include <CFPreferences.h>
32 #else
33 #include <CoreServices/CoreServices.h>
34 #endif
36 #include "pycfbridge.h"
38 #ifdef USE_TOOLBOX_OBJECT_GLUE
39 extern PyObject *_CFObj_New(CFTypeRef);
40 extern int _CFObj_Convert(PyObject *, CFTypeRef *);
41 #define CFObj_New _CFObj_New
42 #define CFObj_Convert _CFObj_Convert
44 extern PyObject *_CFTypeRefObj_New(CFTypeRef);
45 extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
46 #define CFTypeRefObj_New _CFTypeRefObj_New
47 #define CFTypeRefObj_Convert _CFTypeRefObj_Convert
49 extern PyObject *_CFStringRefObj_New(CFStringRef);
50 extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
51 #define CFStringRefObj_New _CFStringRefObj_New
52 #define CFStringRefObj_Convert _CFStringRefObj_Convert
54 extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
55 extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
56 #define CFMutableStringRefObj_New _CFMutableStringRefObj_New
57 #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
59 extern PyObject *_CFArrayRefObj_New(CFArrayRef);
60 extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
61 #define CFArrayRefObj_New _CFArrayRefObj_New
62 #define CFArrayRefObj_Convert _CFArrayRefObj_Convert
64 extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
65 extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
66 #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
67 #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
69 extern PyObject *_CFDataRefObj_New(CFDataRef);
70 extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
71 #define CFDataRefObj_New _CFDataRefObj_New
72 #define CFDataRefObj_Convert _CFDataRefObj_Convert
74 extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
75 extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
76 #define CFMutableDataRefObj_New _CFMutableDataRefObj_New
77 #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
79 extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
80 extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
81 #define CFDictionaryRefObj_New _CFDictionaryRefObj_New
82 #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
84 extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
85 extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
86 #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
87 #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
89 extern PyObject *_CFURLRefObj_New(CFURLRef);
90 extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
91 extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
92 #define CFURLRefObj_New _CFURLRefObj_New
93 #define CFURLRefObj_Convert _CFURLRefObj_Convert
94 #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
95 #endif
98 ** Parse/generate CFRange records
100 PyObject *CFRange_New(CFRange *itself)
103 return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
107 CFRange_Convert(PyObject *v, CFRange *p_itself)
109 long location, length;
111 if( !PyArg_ParseTuple(v, "ll", &location, &length) )
112 return 0;
113 p_itself->location = (CFIndex)location;
114 p_itself->length = (CFIndex)length;
115 return 1;
118 /* Optional CFURL argument or None (passed as NULL) */
120 OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
122 if ( v == Py_None ) {
123 p_itself = NULL;
124 return 1;
126 return CFURLRefObj_Convert(v, p_itself);
129 static PyObject *CF_Error;
131 /* --------------------- Object type CFTypeRef ---------------------- */
133 PyTypeObject CFTypeRef_Type;
135 #define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
137 typedef struct CFTypeRefObject {
138 PyObject_HEAD
139 CFTypeRef ob_itself;
140 void (*ob_freeit)(CFTypeRef ptr);
141 } CFTypeRefObject;
143 PyObject *CFTypeRefObj_New(CFTypeRef itself)
145 CFTypeRefObject *it;
146 if (itself == NULL)
148 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
149 return NULL;
151 it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
152 if (it == NULL) return NULL;
153 it->ob_itself = itself;
154 it->ob_freeit = CFRelease;
155 return (PyObject *)it;
157 int CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself)
160 if (v == Py_None) { *p_itself = NULL; return 1; }
161 /* Check for other CF objects here */
163 if (!CFTypeRefObj_Check(v))
165 PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
166 return 0;
168 *p_itself = ((CFTypeRefObject *)v)->ob_itself;
169 return 1;
172 static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
174 if (self->ob_freeit && self->ob_itself)
176 self->ob_freeit((CFTypeRef)self->ob_itself);
178 PyObject_Free((PyObject *)self);
181 static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
183 PyObject *_res = NULL;
184 CFTypeID _rv;
185 #ifndef CFGetTypeID
186 PyMac_PRECHECK(CFGetTypeID);
187 #endif
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 _rv = CFGetTypeID(_self->ob_itself);
191 _res = Py_BuildValue("l",
192 _rv);
193 return _res;
196 static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
198 PyObject *_res = NULL;
199 CFTypeRef _rv;
200 #ifndef CFRetain
201 PyMac_PRECHECK(CFRetain);
202 #endif
203 if (!PyArg_ParseTuple(_args, ""))
204 return NULL;
205 _rv = CFRetain(_self->ob_itself);
206 _res = Py_BuildValue("O&",
207 CFTypeRefObj_New, _rv);
208 return _res;
211 static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
213 PyObject *_res = NULL;
214 #ifndef CFRelease
215 PyMac_PRECHECK(CFRelease);
216 #endif
217 if (!PyArg_ParseTuple(_args, ""))
218 return NULL;
219 CFRelease(_self->ob_itself);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
225 static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
227 PyObject *_res = NULL;
228 CFIndex _rv;
229 #ifndef CFGetRetainCount
230 PyMac_PRECHECK(CFGetRetainCount);
231 #endif
232 if (!PyArg_ParseTuple(_args, ""))
233 return NULL;
234 _rv = CFGetRetainCount(_self->ob_itself);
235 _res = Py_BuildValue("l",
236 _rv);
237 return _res;
240 static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
242 PyObject *_res = NULL;
243 Boolean _rv;
244 CFTypeRef cf2;
245 #ifndef CFEqual
246 PyMac_PRECHECK(CFEqual);
247 #endif
248 if (!PyArg_ParseTuple(_args, "O&",
249 CFTypeRefObj_Convert, &cf2))
250 return NULL;
251 _rv = CFEqual(_self->ob_itself,
252 cf2);
253 _res = Py_BuildValue("l",
254 _rv);
255 return _res;
258 static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
260 PyObject *_res = NULL;
261 CFHashCode _rv;
262 #ifndef CFHash
263 PyMac_PRECHECK(CFHash);
264 #endif
265 if (!PyArg_ParseTuple(_args, ""))
266 return NULL;
267 _rv = CFHash(_self->ob_itself);
268 _res = Py_BuildValue("l",
269 _rv);
270 return _res;
273 static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
275 PyObject *_res = NULL;
276 CFStringRef _rv;
277 #ifndef CFCopyDescription
278 PyMac_PRECHECK(CFCopyDescription);
279 #endif
280 if (!PyArg_ParseTuple(_args, ""))
281 return NULL;
282 _rv = CFCopyDescription(_self->ob_itself);
283 _res = Py_BuildValue("O&",
284 CFStringRefObj_New, _rv);
285 return _res;
288 static PyObject *CFTypeRefObj_CFPropertyListCreateXMLData(CFTypeRefObject *_self, PyObject *_args)
290 PyObject *_res = NULL;
291 CFDataRef _rv;
292 if (!PyArg_ParseTuple(_args, ""))
293 return NULL;
294 _rv = CFPropertyListCreateXMLData((CFAllocatorRef)NULL,
295 _self->ob_itself);
296 _res = Py_BuildValue("O&",
297 CFDataRefObj_New, _rv);
298 return _res;
301 static PyObject *CFTypeRefObj_CFPropertyListCreateDeepCopy(CFTypeRefObject *_self, PyObject *_args)
303 PyObject *_res = NULL;
304 CFTypeRef _rv;
305 CFOptionFlags mutabilityOption;
306 if (!PyArg_ParseTuple(_args, "l",
307 &mutabilityOption))
308 return NULL;
309 _rv = CFPropertyListCreateDeepCopy((CFAllocatorRef)NULL,
310 _self->ob_itself,
311 mutabilityOption);
312 _res = Py_BuildValue("O&",
313 CFTypeRefObj_New, _rv);
314 return _res;
317 static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
319 PyObject *_res = NULL;
320 #ifndef CFShow
321 PyMac_PRECHECK(CFShow);
322 #endif
323 if (!PyArg_ParseTuple(_args, ""))
324 return NULL;
325 CFShow(_self->ob_itself);
326 Py_INCREF(Py_None);
327 _res = Py_None;
328 return _res;
331 static PyObject *CFTypeRefObj_CFPropertyListCreateFromXMLData(CFTypeRefObject *_self, PyObject *_args)
333 PyObject *_res = NULL;
335 CFTypeRef _rv;
336 CFOptionFlags mutabilityOption;
337 CFStringRef errorString;
338 if (!PyArg_ParseTuple(_args, "l",
339 &mutabilityOption))
340 return NULL;
341 _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
342 _self->ob_itself,
343 mutabilityOption,
344 &errorString);
345 if (errorString)
346 CFRelease(errorString);
347 if (_rv == NULL) {
348 PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
349 return NULL;
351 _res = Py_BuildValue("O&",
352 CFTypeRefObj_New, _rv);
353 return _res;
357 static PyObject *CFTypeRefObj_toPython(CFTypeRefObject *_self, PyObject *_args)
359 PyObject *_res = NULL;
361 _res = PyCF_CF2Python(_self->ob_itself);
362 return _res;
366 static PyMethodDef CFTypeRefObj_methods[] = {
367 {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
368 PyDoc_STR("() -> (CFTypeID _rv)")},
369 {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
370 PyDoc_STR("() -> (CFTypeRef _rv)")},
371 {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
372 PyDoc_STR("() -> None")},
373 {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
374 PyDoc_STR("() -> (CFIndex _rv)")},
375 {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
376 PyDoc_STR("(CFTypeRef cf2) -> (Boolean _rv)")},
377 {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
378 PyDoc_STR("() -> (CFHashCode _rv)")},
379 {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
380 PyDoc_STR("() -> (CFStringRef _rv)")},
381 {"CFPropertyListCreateXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateXMLData, 1,
382 PyDoc_STR("() -> (CFDataRef _rv)")},
383 {"CFPropertyListCreateDeepCopy", (PyCFunction)CFTypeRefObj_CFPropertyListCreateDeepCopy, 1,
384 PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRef _rv)")},
385 {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
386 PyDoc_STR("() -> None")},
387 {"CFPropertyListCreateFromXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateFromXMLData, 1,
388 PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)")},
389 {"toPython", (PyCFunction)CFTypeRefObj_toPython, 1,
390 PyDoc_STR("() -> (python_object)")},
391 {NULL, NULL, 0}
394 PyMethodChain CFTypeRefObj_chain = { CFTypeRefObj_methods, NULL };
396 static PyObject *CFTypeRefObj_getattr(CFTypeRefObject *self, char *name)
398 return Py_FindMethodInChain(&CFTypeRefObj_chain, (PyObject *)self, name);
401 #define CFTypeRefObj_setattr NULL
403 static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other)
405 /* XXXX Or should we use CFEqual?? */
406 if ( self->ob_itself > other->ob_itself ) return 1;
407 if ( self->ob_itself < other->ob_itself ) return -1;
408 return 0;
411 static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
413 char buf[100];
414 sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);
415 return PyString_FromString(buf);
418 static int CFTypeRefObj_hash(CFTypeRefObject *self)
420 /* XXXX Or should we use CFHash?? */
421 return (int)self->ob_itself;
424 PyTypeObject CFTypeRef_Type = {
425 PyObject_HEAD_INIT(NULL)
426 0, /*ob_size*/
427 "_CF.CFTypeRef", /*tp_name*/
428 sizeof(CFTypeRefObject), /*tp_basicsize*/
429 0, /*tp_itemsize*/
430 /* methods */
431 (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
432 0, /*tp_print*/
433 (getattrfunc) CFTypeRefObj_getattr, /*tp_getattr*/
434 (setattrfunc) CFTypeRefObj_setattr, /*tp_setattr*/
435 (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
436 (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
437 (PyNumberMethods *)0, /* tp_as_number */
438 (PySequenceMethods *)0, /* tp_as_sequence */
439 (PyMappingMethods *)0, /* tp_as_mapping */
440 (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
443 /* ------------------- End object type CFTypeRef -------------------- */
446 /* --------------------- Object type CFArrayRef --------------------- */
448 PyTypeObject CFArrayRef_Type;
450 #define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type || PyObject_TypeCheck((x), &CFArrayRef_Type))
452 typedef struct CFArrayRefObject {
453 PyObject_HEAD
454 CFArrayRef ob_itself;
455 void (*ob_freeit)(CFTypeRef ptr);
456 } CFArrayRefObject;
458 PyObject *CFArrayRefObj_New(CFArrayRef itself)
460 CFArrayRefObject *it;
461 if (itself == NULL)
463 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
464 return NULL;
466 it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
467 if (it == NULL) return NULL;
468 it->ob_itself = itself;
469 it->ob_freeit = CFRelease;
470 return (PyObject *)it;
472 int CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself)
475 if (v == Py_None) { *p_itself = NULL; return 1; }
476 /* Check for other CF objects here */
478 if (!CFArrayRefObj_Check(v))
480 PyErr_SetString(PyExc_TypeError, "CFArrayRef required");
481 return 0;
483 *p_itself = ((CFArrayRefObject *)v)->ob_itself;
484 return 1;
487 static void CFArrayRefObj_dealloc(CFArrayRefObject *self)
489 if (self->ob_freeit && self->ob_itself)
491 self->ob_freeit((CFTypeRef)self->ob_itself);
493 PyObject_Free((PyObject *)self);
496 static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
498 PyObject *_res = NULL;
499 CFArrayRef _rv;
500 if (!PyArg_ParseTuple(_args, ""))
501 return NULL;
502 _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
503 _self->ob_itself);
504 _res = Py_BuildValue("O&",
505 CFArrayRefObj_New, _rv);
506 return _res;
509 static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
511 PyObject *_res = NULL;
512 CFIndex _rv;
513 #ifndef CFArrayGetCount
514 PyMac_PRECHECK(CFArrayGetCount);
515 #endif
516 if (!PyArg_ParseTuple(_args, ""))
517 return NULL;
518 _rv = CFArrayGetCount(_self->ob_itself);
519 _res = Py_BuildValue("l",
520 _rv);
521 return _res;
524 static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
526 PyObject *_res = NULL;
527 CFStringRef _rv;
528 CFStringRef separatorString;
529 if (!PyArg_ParseTuple(_args, "O&",
530 CFStringRefObj_Convert, &separatorString))
531 return NULL;
532 _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
533 _self->ob_itself,
534 separatorString);
535 _res = Py_BuildValue("O&",
536 CFStringRefObj_New, _rv);
537 return _res;
540 static PyMethodDef CFArrayRefObj_methods[] = {
541 {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
542 PyDoc_STR("() -> (CFArrayRef _rv)")},
543 {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
544 PyDoc_STR("() -> (CFIndex _rv)")},
545 {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
546 PyDoc_STR("(CFStringRef separatorString) -> (CFStringRef _rv)")},
547 {NULL, NULL, 0}
550 PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, &CFTypeRefObj_chain };
552 static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name)
554 return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name);
557 #define CFArrayRefObj_setattr NULL
559 static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other)
561 /* XXXX Or should we use CFEqual?? */
562 if ( self->ob_itself > other->ob_itself ) return 1;
563 if ( self->ob_itself < other->ob_itself ) return -1;
564 return 0;
567 static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
569 char buf[100];
570 sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
571 return PyString_FromString(buf);
574 static int CFArrayRefObj_hash(CFArrayRefObject *self)
576 /* XXXX Or should we use CFHash?? */
577 return (int)self->ob_itself;
580 PyTypeObject CFArrayRef_Type = {
581 PyObject_HEAD_INIT(NULL)
582 0, /*ob_size*/
583 "_CF.CFArrayRef", /*tp_name*/
584 sizeof(CFArrayRefObject), /*tp_basicsize*/
585 0, /*tp_itemsize*/
586 /* methods */
587 (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
588 0, /*tp_print*/
589 (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/
590 (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/
591 (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/
592 (reprfunc) CFArrayRefObj_repr, /*tp_repr*/
593 (PyNumberMethods *)0, /* tp_as_number */
594 (PySequenceMethods *)0, /* tp_as_sequence */
595 (PyMappingMethods *)0, /* tp_as_mapping */
596 (hashfunc) CFArrayRefObj_hash, /*tp_hash*/
599 /* ------------------- End object type CFArrayRef ------------------- */
602 /* ----------------- Object type CFMutableArrayRef ------------------ */
604 PyTypeObject CFMutableArrayRef_Type;
606 #define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &CFMutableArrayRef_Type))
608 typedef struct CFMutableArrayRefObject {
609 PyObject_HEAD
610 CFMutableArrayRef ob_itself;
611 void (*ob_freeit)(CFTypeRef ptr);
612 } CFMutableArrayRefObject;
614 PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself)
616 CFMutableArrayRefObject *it;
617 if (itself == NULL)
619 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
620 return NULL;
622 it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
623 if (it == NULL) return NULL;
624 it->ob_itself = itself;
625 it->ob_freeit = CFRelease;
626 return (PyObject *)it;
628 int CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself)
631 if (v == Py_None) { *p_itself = NULL; return 1; }
632 /* Check for other CF objects here */
634 if (!CFMutableArrayRefObj_Check(v))
636 PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required");
637 return 0;
639 *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself;
640 return 1;
643 static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self)
645 if (self->ob_freeit && self->ob_itself)
647 self->ob_freeit((CFTypeRef)self->ob_itself);
649 PyObject_Free((PyObject *)self);
652 static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
654 PyObject *_res = NULL;
655 CFIndex idx;
656 #ifndef CFArrayRemoveValueAtIndex
657 PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
658 #endif
659 if (!PyArg_ParseTuple(_args, "l",
660 &idx))
661 return NULL;
662 CFArrayRemoveValueAtIndex(_self->ob_itself,
663 idx);
664 Py_INCREF(Py_None);
665 _res = Py_None;
666 return _res;
669 static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args)
671 PyObject *_res = NULL;
672 #ifndef CFArrayRemoveAllValues
673 PyMac_PRECHECK(CFArrayRemoveAllValues);
674 #endif
675 if (!PyArg_ParseTuple(_args, ""))
676 return NULL;
677 CFArrayRemoveAllValues(_self->ob_itself);
678 Py_INCREF(Py_None);
679 _res = Py_None;
680 return _res;
683 static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args)
685 PyObject *_res = NULL;
686 CFIndex idx1;
687 CFIndex idx2;
688 #ifndef CFArrayExchangeValuesAtIndices
689 PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
690 #endif
691 if (!PyArg_ParseTuple(_args, "ll",
692 &idx1,
693 &idx2))
694 return NULL;
695 CFArrayExchangeValuesAtIndices(_self->ob_itself,
696 idx1,
697 idx2);
698 Py_INCREF(Py_None);
699 _res = Py_None;
700 return _res;
703 static PyObject *CFMutableArrayRefObj_CFArrayAppendArray(CFMutableArrayRefObject *_self, PyObject *_args)
705 PyObject *_res = NULL;
706 CFArrayRef otherArray;
707 CFRange otherRange;
708 #ifndef CFArrayAppendArray
709 PyMac_PRECHECK(CFArrayAppendArray);
710 #endif
711 if (!PyArg_ParseTuple(_args, "O&O&",
712 CFArrayRefObj_Convert, &otherArray,
713 CFRange_Convert, &otherRange))
714 return NULL;
715 CFArrayAppendArray(_self->ob_itself,
716 otherArray,
717 otherRange);
718 Py_INCREF(Py_None);
719 _res = Py_None;
720 return _res;
723 static PyMethodDef CFMutableArrayRefObj_methods[] = {
724 {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
725 PyDoc_STR("(CFIndex idx) -> None")},
726 {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
727 PyDoc_STR("() -> None")},
728 {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
729 PyDoc_STR("(CFIndex idx1, CFIndex idx2) -> None")},
730 {"CFArrayAppendArray", (PyCFunction)CFMutableArrayRefObj_CFArrayAppendArray, 1,
731 PyDoc_STR("(CFArrayRef otherArray, CFRange otherRange) -> None")},
732 {NULL, NULL, 0}
735 PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, &CFArrayRefObj_chain };
737 static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name)
739 return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name);
742 #define CFMutableArrayRefObj_setattr NULL
744 static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other)
746 /* XXXX Or should we use CFEqual?? */
747 if ( self->ob_itself > other->ob_itself ) return 1;
748 if ( self->ob_itself < other->ob_itself ) return -1;
749 return 0;
752 static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
754 char buf[100];
755 sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
756 return PyString_FromString(buf);
759 static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
761 /* XXXX Or should we use CFHash?? */
762 return (int)self->ob_itself;
765 PyTypeObject CFMutableArrayRef_Type = {
766 PyObject_HEAD_INIT(NULL)
767 0, /*ob_size*/
768 "_CF.CFMutableArrayRef", /*tp_name*/
769 sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
770 0, /*tp_itemsize*/
771 /* methods */
772 (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
773 0, /*tp_print*/
774 (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/
775 (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/
776 (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/
777 (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/
778 (PyNumberMethods *)0, /* tp_as_number */
779 (PySequenceMethods *)0, /* tp_as_sequence */
780 (PyMappingMethods *)0, /* tp_as_mapping */
781 (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/
784 /* --------------- End object type CFMutableArrayRef ---------------- */
787 /* ------------------ Object type CFDictionaryRef ------------------- */
789 PyTypeObject CFDictionaryRef_Type;
791 #define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &CFDictionaryRef_Type))
793 typedef struct CFDictionaryRefObject {
794 PyObject_HEAD
795 CFDictionaryRef ob_itself;
796 void (*ob_freeit)(CFTypeRef ptr);
797 } CFDictionaryRefObject;
799 PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself)
801 CFDictionaryRefObject *it;
802 if (itself == NULL)
804 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
805 return NULL;
807 it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
808 if (it == NULL) return NULL;
809 it->ob_itself = itself;
810 it->ob_freeit = CFRelease;
811 return (PyObject *)it;
813 int CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself)
816 if (v == Py_None) { *p_itself = NULL; return 1; }
817 /* Check for other CF objects here */
819 if (!CFDictionaryRefObj_Check(v))
821 PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required");
822 return 0;
824 *p_itself = ((CFDictionaryRefObject *)v)->ob_itself;
825 return 1;
828 static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self)
830 if (self->ob_freeit && self->ob_itself)
832 self->ob_freeit((CFTypeRef)self->ob_itself);
834 PyObject_Free((PyObject *)self);
837 static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
839 PyObject *_res = NULL;
840 CFDictionaryRef _rv;
841 if (!PyArg_ParseTuple(_args, ""))
842 return NULL;
843 _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
844 _self->ob_itself);
845 _res = Py_BuildValue("O&",
846 CFDictionaryRefObj_New, _rv);
847 return _res;
850 static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
852 PyObject *_res = NULL;
853 CFIndex _rv;
854 #ifndef CFDictionaryGetCount
855 PyMac_PRECHECK(CFDictionaryGetCount);
856 #endif
857 if (!PyArg_ParseTuple(_args, ""))
858 return NULL;
859 _rv = CFDictionaryGetCount(_self->ob_itself);
860 _res = Py_BuildValue("l",
861 _rv);
862 return _res;
865 static PyMethodDef CFDictionaryRefObj_methods[] = {
866 {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
867 PyDoc_STR("() -> (CFDictionaryRef _rv)")},
868 {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
869 PyDoc_STR("() -> (CFIndex _rv)")},
870 {NULL, NULL, 0}
873 PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, &CFTypeRefObj_chain };
875 static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name)
877 return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name);
880 #define CFDictionaryRefObj_setattr NULL
882 static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other)
884 /* XXXX Or should we use CFEqual?? */
885 if ( self->ob_itself > other->ob_itself ) return 1;
886 if ( self->ob_itself < other->ob_itself ) return -1;
887 return 0;
890 static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
892 char buf[100];
893 sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
894 return PyString_FromString(buf);
897 static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
899 /* XXXX Or should we use CFHash?? */
900 return (int)self->ob_itself;
903 PyTypeObject CFDictionaryRef_Type = {
904 PyObject_HEAD_INIT(NULL)
905 0, /*ob_size*/
906 "_CF.CFDictionaryRef", /*tp_name*/
907 sizeof(CFDictionaryRefObject), /*tp_basicsize*/
908 0, /*tp_itemsize*/
909 /* methods */
910 (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
911 0, /*tp_print*/
912 (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/
913 (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/
914 (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/
915 (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/
916 (PyNumberMethods *)0, /* tp_as_number */
917 (PySequenceMethods *)0, /* tp_as_sequence */
918 (PyMappingMethods *)0, /* tp_as_mapping */
919 (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/
922 /* ---------------- End object type CFDictionaryRef ----------------- */
925 /* --------------- Object type CFMutableDictionaryRef --------------- */
927 PyTypeObject CFMutableDictionaryRef_Type;
929 #define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &CFMutableDictionaryRef_Type))
931 typedef struct CFMutableDictionaryRefObject {
932 PyObject_HEAD
933 CFMutableDictionaryRef ob_itself;
934 void (*ob_freeit)(CFTypeRef ptr);
935 } CFMutableDictionaryRefObject;
937 PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself)
939 CFMutableDictionaryRefObject *it;
940 if (itself == NULL)
942 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
943 return NULL;
945 it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
946 if (it == NULL) return NULL;
947 it->ob_itself = itself;
948 it->ob_freeit = CFRelease;
949 return (PyObject *)it;
951 int CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself)
954 if (v == Py_None) { *p_itself = NULL; return 1; }
955 /* Check for other CF objects here */
957 if (!CFMutableDictionaryRefObj_Check(v))
959 PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required");
960 return 0;
962 *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself;
963 return 1;
966 static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self)
968 if (self->ob_freeit && self->ob_itself)
970 self->ob_freeit((CFTypeRef)self->ob_itself);
972 PyObject_Free((PyObject *)self);
975 static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
977 PyObject *_res = NULL;
978 #ifndef CFDictionaryRemoveAllValues
979 PyMac_PRECHECK(CFDictionaryRemoveAllValues);
980 #endif
981 if (!PyArg_ParseTuple(_args, ""))
982 return NULL;
983 CFDictionaryRemoveAllValues(_self->ob_itself);
984 Py_INCREF(Py_None);
985 _res = Py_None;
986 return _res;
989 static PyMethodDef CFMutableDictionaryRefObj_methods[] = {
990 {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1,
991 PyDoc_STR("() -> None")},
992 {NULL, NULL, 0}
995 PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, &CFDictionaryRefObj_chain };
997 static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name)
999 return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name);
1002 #define CFMutableDictionaryRefObj_setattr NULL
1004 static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other)
1006 /* XXXX Or should we use CFEqual?? */
1007 if ( self->ob_itself > other->ob_itself ) return 1;
1008 if ( self->ob_itself < other->ob_itself ) return -1;
1009 return 0;
1012 static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self)
1014 char buf[100];
1015 sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
1016 return PyString_FromString(buf);
1019 static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
1021 /* XXXX Or should we use CFHash?? */
1022 return (int)self->ob_itself;
1025 PyTypeObject CFMutableDictionaryRef_Type = {
1026 PyObject_HEAD_INIT(NULL)
1027 0, /*ob_size*/
1028 "_CF.CFMutableDictionaryRef", /*tp_name*/
1029 sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
1030 0, /*tp_itemsize*/
1031 /* methods */
1032 (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
1033 0, /*tp_print*/
1034 (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/
1035 (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/
1036 (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/
1037 (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/
1038 (PyNumberMethods *)0, /* tp_as_number */
1039 (PySequenceMethods *)0, /* tp_as_sequence */
1040 (PyMappingMethods *)0, /* tp_as_mapping */
1041 (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/
1044 /* ------------- End object type CFMutableDictionaryRef ------------- */
1047 /* --------------------- Object type CFDataRef ---------------------- */
1049 PyTypeObject CFDataRef_Type;
1051 #define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type || PyObject_TypeCheck((x), &CFDataRef_Type))
1053 typedef struct CFDataRefObject {
1054 PyObject_HEAD
1055 CFDataRef ob_itself;
1056 void (*ob_freeit)(CFTypeRef ptr);
1057 } CFDataRefObject;
1059 PyObject *CFDataRefObj_New(CFDataRef itself)
1061 CFDataRefObject *it;
1062 if (itself == NULL)
1064 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1065 return NULL;
1067 it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
1068 if (it == NULL) return NULL;
1069 it->ob_itself = itself;
1070 it->ob_freeit = CFRelease;
1071 return (PyObject *)it;
1073 int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
1076 if (v == Py_None) { *p_itself = NULL; return 1; }
1077 if (PyString_Check(v)) {
1078 char *cStr;
1079 int cLen;
1080 if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
1081 *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
1082 return 1;
1085 if (!CFDataRefObj_Check(v))
1087 PyErr_SetString(PyExc_TypeError, "CFDataRef required");
1088 return 0;
1090 *p_itself = ((CFDataRefObject *)v)->ob_itself;
1091 return 1;
1094 static void CFDataRefObj_dealloc(CFDataRefObject *self)
1096 if (self->ob_freeit && self->ob_itself)
1098 self->ob_freeit((CFTypeRef)self->ob_itself);
1100 PyObject_Free((PyObject *)self);
1103 static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
1105 PyObject *_res = NULL;
1106 CFDataRef _rv;
1107 if (!PyArg_ParseTuple(_args, ""))
1108 return NULL;
1109 _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
1110 _self->ob_itself);
1111 _res = Py_BuildValue("O&",
1112 CFDataRefObj_New, _rv);
1113 return _res;
1116 static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
1118 PyObject *_res = NULL;
1119 CFIndex _rv;
1120 #ifndef CFDataGetLength
1121 PyMac_PRECHECK(CFDataGetLength);
1122 #endif
1123 if (!PyArg_ParseTuple(_args, ""))
1124 return NULL;
1125 _rv = CFDataGetLength(_self->ob_itself);
1126 _res = Py_BuildValue("l",
1127 _rv);
1128 return _res;
1131 static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
1133 PyObject *_res = NULL;
1134 CFStringRef _rv;
1135 CFStringEncoding encoding;
1136 if (!PyArg_ParseTuple(_args, "l",
1137 &encoding))
1138 return NULL;
1139 _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
1140 _self->ob_itself,
1141 encoding);
1142 _res = Py_BuildValue("O&",
1143 CFStringRefObj_New, _rv);
1144 return _res;
1147 static PyObject *CFDataRefObj_CFDataGetData(CFDataRefObject *_self, PyObject *_args)
1149 PyObject *_res = NULL;
1151 int size = CFDataGetLength(_self->ob_itself);
1152 char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
1154 _res = (PyObject *)PyString_FromStringAndSize(data, size);
1155 return _res;
1159 static PyMethodDef CFDataRefObj_methods[] = {
1160 {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
1161 PyDoc_STR("() -> (CFDataRef _rv)")},
1162 {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
1163 PyDoc_STR("() -> (CFIndex _rv)")},
1164 {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
1165 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
1166 {"CFDataGetData", (PyCFunction)CFDataRefObj_CFDataGetData, 1,
1167 PyDoc_STR("() -> (string _rv)")},
1168 {NULL, NULL, 0}
1171 PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, &CFTypeRefObj_chain };
1173 static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name)
1175 return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name);
1178 #define CFDataRefObj_setattr NULL
1180 static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other)
1182 /* XXXX Or should we use CFEqual?? */
1183 if ( self->ob_itself > other->ob_itself ) return 1;
1184 if ( self->ob_itself < other->ob_itself ) return -1;
1185 return 0;
1188 static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
1190 char buf[100];
1191 sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
1192 return PyString_FromString(buf);
1195 static int CFDataRefObj_hash(CFDataRefObject *self)
1197 /* XXXX Or should we use CFHash?? */
1198 return (int)self->ob_itself;
1201 PyTypeObject CFDataRef_Type = {
1202 PyObject_HEAD_INIT(NULL)
1203 0, /*ob_size*/
1204 "_CF.CFDataRef", /*tp_name*/
1205 sizeof(CFDataRefObject), /*tp_basicsize*/
1206 0, /*tp_itemsize*/
1207 /* methods */
1208 (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
1209 0, /*tp_print*/
1210 (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/
1211 (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/
1212 (cmpfunc) CFDataRefObj_compare, /*tp_compare*/
1213 (reprfunc) CFDataRefObj_repr, /*tp_repr*/
1214 (PyNumberMethods *)0, /* tp_as_number */
1215 (PySequenceMethods *)0, /* tp_as_sequence */
1216 (PyMappingMethods *)0, /* tp_as_mapping */
1217 (hashfunc) CFDataRefObj_hash, /*tp_hash*/
1220 /* ------------------- End object type CFDataRef -------------------- */
1223 /* ------------------ Object type CFMutableDataRef ------------------ */
1225 PyTypeObject CFMutableDataRef_Type;
1227 #define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &CFMutableDataRef_Type))
1229 typedef struct CFMutableDataRefObject {
1230 PyObject_HEAD
1231 CFMutableDataRef ob_itself;
1232 void (*ob_freeit)(CFTypeRef ptr);
1233 } CFMutableDataRefObject;
1235 PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself)
1237 CFMutableDataRefObject *it;
1238 if (itself == NULL)
1240 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1241 return NULL;
1243 it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
1244 if (it == NULL) return NULL;
1245 it->ob_itself = itself;
1246 it->ob_freeit = CFRelease;
1247 return (PyObject *)it;
1249 int CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself)
1252 if (v == Py_None) { *p_itself = NULL; return 1; }
1253 /* Check for other CF objects here */
1255 if (!CFMutableDataRefObj_Check(v))
1257 PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required");
1258 return 0;
1260 *p_itself = ((CFMutableDataRefObject *)v)->ob_itself;
1261 return 1;
1264 static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self)
1266 if (self->ob_freeit && self->ob_itself)
1268 self->ob_freeit((CFTypeRef)self->ob_itself);
1270 PyObject_Free((PyObject *)self);
1273 static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
1275 PyObject *_res = NULL;
1276 CFIndex length;
1277 #ifndef CFDataSetLength
1278 PyMac_PRECHECK(CFDataSetLength);
1279 #endif
1280 if (!PyArg_ParseTuple(_args, "l",
1281 &length))
1282 return NULL;
1283 CFDataSetLength(_self->ob_itself,
1284 length);
1285 Py_INCREF(Py_None);
1286 _res = Py_None;
1287 return _res;
1290 static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args)
1292 PyObject *_res = NULL;
1293 CFIndex extraLength;
1294 #ifndef CFDataIncreaseLength
1295 PyMac_PRECHECK(CFDataIncreaseLength);
1296 #endif
1297 if (!PyArg_ParseTuple(_args, "l",
1298 &extraLength))
1299 return NULL;
1300 CFDataIncreaseLength(_self->ob_itself,
1301 extraLength);
1302 Py_INCREF(Py_None);
1303 _res = Py_None;
1304 return _res;
1307 static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args)
1309 PyObject *_res = NULL;
1310 unsigned char *bytes__in__;
1311 long bytes__len__;
1312 int bytes__in_len__;
1313 #ifndef CFDataAppendBytes
1314 PyMac_PRECHECK(CFDataAppendBytes);
1315 #endif
1316 if (!PyArg_ParseTuple(_args, "s#",
1317 &bytes__in__, &bytes__in_len__))
1318 return NULL;
1319 bytes__len__ = bytes__in_len__;
1320 CFDataAppendBytes(_self->ob_itself,
1321 bytes__in__, bytes__len__);
1322 Py_INCREF(Py_None);
1323 _res = Py_None;
1324 return _res;
1327 static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args)
1329 PyObject *_res = NULL;
1330 CFRange range;
1331 unsigned char *newBytes__in__;
1332 long newBytes__len__;
1333 int newBytes__in_len__;
1334 #ifndef CFDataReplaceBytes
1335 PyMac_PRECHECK(CFDataReplaceBytes);
1336 #endif
1337 if (!PyArg_ParseTuple(_args, "O&s#",
1338 CFRange_Convert, &range,
1339 &newBytes__in__, &newBytes__in_len__))
1340 return NULL;
1341 newBytes__len__ = newBytes__in_len__;
1342 CFDataReplaceBytes(_self->ob_itself,
1343 range,
1344 newBytes__in__, newBytes__len__);
1345 Py_INCREF(Py_None);
1346 _res = Py_None;
1347 return _res;
1350 static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
1352 PyObject *_res = NULL;
1353 CFRange range;
1354 #ifndef CFDataDeleteBytes
1355 PyMac_PRECHECK(CFDataDeleteBytes);
1356 #endif
1357 if (!PyArg_ParseTuple(_args, "O&",
1358 CFRange_Convert, &range))
1359 return NULL;
1360 CFDataDeleteBytes(_self->ob_itself,
1361 range);
1362 Py_INCREF(Py_None);
1363 _res = Py_None;
1364 return _res;
1367 static PyMethodDef CFMutableDataRefObj_methods[] = {
1368 {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1,
1369 PyDoc_STR("(CFIndex length) -> None")},
1370 {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
1371 PyDoc_STR("(CFIndex extraLength) -> None")},
1372 {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
1373 PyDoc_STR("(Buffer bytes) -> None")},
1374 {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
1375 PyDoc_STR("(CFRange range, Buffer newBytes) -> None")},
1376 {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
1377 PyDoc_STR("(CFRange range) -> None")},
1378 {NULL, NULL, 0}
1381 PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, &CFDataRefObj_chain };
1383 static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name)
1385 return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name);
1388 #define CFMutableDataRefObj_setattr NULL
1390 static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other)
1392 /* XXXX Or should we use CFEqual?? */
1393 if ( self->ob_itself > other->ob_itself ) return 1;
1394 if ( self->ob_itself < other->ob_itself ) return -1;
1395 return 0;
1398 static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
1400 char buf[100];
1401 sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
1402 return PyString_FromString(buf);
1405 static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
1407 /* XXXX Or should we use CFHash?? */
1408 return (int)self->ob_itself;
1411 PyTypeObject CFMutableDataRef_Type = {
1412 PyObject_HEAD_INIT(NULL)
1413 0, /*ob_size*/
1414 "_CF.CFMutableDataRef", /*tp_name*/
1415 sizeof(CFMutableDataRefObject), /*tp_basicsize*/
1416 0, /*tp_itemsize*/
1417 /* methods */
1418 (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/
1419 0, /*tp_print*/
1420 (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/
1421 (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/
1422 (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/
1423 (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/
1424 (PyNumberMethods *)0, /* tp_as_number */
1425 (PySequenceMethods *)0, /* tp_as_sequence */
1426 (PyMappingMethods *)0, /* tp_as_mapping */
1427 (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/
1430 /* ---------------- End object type CFMutableDataRef ---------------- */
1433 /* -------------------- Object type CFStringRef --------------------- */
1435 PyTypeObject CFStringRef_Type;
1437 #define CFStringRefObj_Check(x) ((x)->ob_type == &CFStringRef_Type || PyObject_TypeCheck((x), &CFStringRef_Type))
1439 typedef struct CFStringRefObject {
1440 PyObject_HEAD
1441 CFStringRef ob_itself;
1442 void (*ob_freeit)(CFTypeRef ptr);
1443 } CFStringRefObject;
1445 PyObject *CFStringRefObj_New(CFStringRef itself)
1447 CFStringRefObject *it;
1448 if (itself == NULL)
1450 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1451 return NULL;
1453 it = PyObject_NEW(CFStringRefObject, &CFStringRef_Type);
1454 if (it == NULL) return NULL;
1455 it->ob_itself = itself;
1456 it->ob_freeit = CFRelease;
1457 return (PyObject *)it;
1459 int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
1462 if (v == Py_None) { *p_itself = NULL; return 1; }
1463 if (PyString_Check(v)) {
1464 char *cStr;
1465 if (!PyArg_Parse(v, "es", "ascii", &cStr))
1466 return NULL;
1467 *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
1468 return 1;
1470 if (PyUnicode_Check(v)) {
1471 /* We use the CF types here, if Python was configured differently that will give an error */
1472 CFIndex size = PyUnicode_GetSize(v);
1473 UniChar *unichars = PyUnicode_AsUnicode(v);
1474 if (!unichars) return 0;
1475 *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
1476 return 1;
1480 if (!CFStringRefObj_Check(v))
1482 PyErr_SetString(PyExc_TypeError, "CFStringRef required");
1483 return 0;
1485 *p_itself = ((CFStringRefObject *)v)->ob_itself;
1486 return 1;
1489 static void CFStringRefObj_dealloc(CFStringRefObject *self)
1491 if (self->ob_freeit && self->ob_itself)
1493 self->ob_freeit((CFTypeRef)self->ob_itself);
1495 PyObject_Free((PyObject *)self);
1498 static PyObject *CFStringRefObj_CFStringCreateWithSubstring(CFStringRefObject *_self, PyObject *_args)
1500 PyObject *_res = NULL;
1501 CFStringRef _rv;
1502 CFRange range;
1503 if (!PyArg_ParseTuple(_args, "O&",
1504 CFRange_Convert, &range))
1505 return NULL;
1506 _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL,
1507 _self->ob_itself,
1508 range);
1509 _res = Py_BuildValue("O&",
1510 CFStringRefObj_New, _rv);
1511 return _res;
1514 static PyObject *CFStringRefObj_CFStringCreateCopy(CFStringRefObject *_self, PyObject *_args)
1516 PyObject *_res = NULL;
1517 CFStringRef _rv;
1518 if (!PyArg_ParseTuple(_args, ""))
1519 return NULL;
1520 _rv = CFStringCreateCopy((CFAllocatorRef)NULL,
1521 _self->ob_itself);
1522 _res = Py_BuildValue("O&",
1523 CFStringRefObj_New, _rv);
1524 return _res;
1527 static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args)
1529 PyObject *_res = NULL;
1530 CFIndex _rv;
1531 #ifndef CFStringGetLength
1532 PyMac_PRECHECK(CFStringGetLength);
1533 #endif
1534 if (!PyArg_ParseTuple(_args, ""))
1535 return NULL;
1536 _rv = CFStringGetLength(_self->ob_itself);
1537 _res = Py_BuildValue("l",
1538 _rv);
1539 return _res;
1542 static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args)
1544 PyObject *_res = NULL;
1545 CFIndex _rv;
1546 CFRange range;
1547 CFStringEncoding encoding;
1548 UInt8 lossByte;
1549 Boolean isExternalRepresentation;
1550 UInt8 buffer;
1551 CFIndex maxBufLen;
1552 CFIndex usedBufLen;
1553 #ifndef CFStringGetBytes
1554 PyMac_PRECHECK(CFStringGetBytes);
1555 #endif
1556 if (!PyArg_ParseTuple(_args, "O&lbll",
1557 CFRange_Convert, &range,
1558 &encoding,
1559 &lossByte,
1560 &isExternalRepresentation,
1561 &maxBufLen))
1562 return NULL;
1563 _rv = CFStringGetBytes(_self->ob_itself,
1564 range,
1565 encoding,
1566 lossByte,
1567 isExternalRepresentation,
1568 &buffer,
1569 maxBufLen,
1570 &usedBufLen);
1571 _res = Py_BuildValue("lbl",
1572 _rv,
1573 buffer,
1574 usedBufLen);
1575 return _res;
1578 static PyObject *CFStringRefObj_CFStringCreateExternalRepresentation(CFStringRefObject *_self, PyObject *_args)
1580 PyObject *_res = NULL;
1581 CFDataRef _rv;
1582 CFStringEncoding encoding;
1583 UInt8 lossByte;
1584 if (!PyArg_ParseTuple(_args, "lb",
1585 &encoding,
1586 &lossByte))
1587 return NULL;
1588 _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL,
1589 _self->ob_itself,
1590 encoding,
1591 lossByte);
1592 _res = Py_BuildValue("O&",
1593 CFDataRefObj_New, _rv);
1594 return _res;
1597 static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args)
1599 PyObject *_res = NULL;
1600 CFStringEncoding _rv;
1601 #ifndef CFStringGetSmallestEncoding
1602 PyMac_PRECHECK(CFStringGetSmallestEncoding);
1603 #endif
1604 if (!PyArg_ParseTuple(_args, ""))
1605 return NULL;
1606 _rv = CFStringGetSmallestEncoding(_self->ob_itself);
1607 _res = Py_BuildValue("l",
1608 _rv);
1609 return _res;
1612 static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args)
1614 PyObject *_res = NULL;
1615 CFStringEncoding _rv;
1616 #ifndef CFStringGetFastestEncoding
1617 PyMac_PRECHECK(CFStringGetFastestEncoding);
1618 #endif
1619 if (!PyArg_ParseTuple(_args, ""))
1620 return NULL;
1621 _rv = CFStringGetFastestEncoding(_self->ob_itself);
1622 _res = Py_BuildValue("l",
1623 _rv);
1624 return _res;
1627 static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args)
1629 PyObject *_res = NULL;
1630 CFComparisonResult _rv;
1631 CFStringRef theString2;
1632 CFRange rangeToCompare;
1633 CFOptionFlags compareOptions;
1634 #ifndef CFStringCompareWithOptions
1635 PyMac_PRECHECK(CFStringCompareWithOptions);
1636 #endif
1637 if (!PyArg_ParseTuple(_args, "O&O&l",
1638 CFStringRefObj_Convert, &theString2,
1639 CFRange_Convert, &rangeToCompare,
1640 &compareOptions))
1641 return NULL;
1642 _rv = CFStringCompareWithOptions(_self->ob_itself,
1643 theString2,
1644 rangeToCompare,
1645 compareOptions);
1646 _res = Py_BuildValue("l",
1647 _rv);
1648 return _res;
1651 static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args)
1653 PyObject *_res = NULL;
1654 CFComparisonResult _rv;
1655 CFStringRef theString2;
1656 CFOptionFlags compareOptions;
1657 #ifndef CFStringCompare
1658 PyMac_PRECHECK(CFStringCompare);
1659 #endif
1660 if (!PyArg_ParseTuple(_args, "O&l",
1661 CFStringRefObj_Convert, &theString2,
1662 &compareOptions))
1663 return NULL;
1664 _rv = CFStringCompare(_self->ob_itself,
1665 theString2,
1666 compareOptions);
1667 _res = Py_BuildValue("l",
1668 _rv);
1669 return _res;
1672 static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args)
1674 PyObject *_res = NULL;
1675 Boolean _rv;
1676 CFStringRef stringToFind;
1677 CFRange rangeToSearch;
1678 CFOptionFlags searchOptions;
1679 CFRange result;
1680 #ifndef CFStringFindWithOptions
1681 PyMac_PRECHECK(CFStringFindWithOptions);
1682 #endif
1683 if (!PyArg_ParseTuple(_args, "O&O&l",
1684 CFStringRefObj_Convert, &stringToFind,
1685 CFRange_Convert, &rangeToSearch,
1686 &searchOptions))
1687 return NULL;
1688 _rv = CFStringFindWithOptions(_self->ob_itself,
1689 stringToFind,
1690 rangeToSearch,
1691 searchOptions,
1692 &result);
1693 _res = Py_BuildValue("lO&",
1694 _rv,
1695 CFRange_New, result);
1696 return _res;
1699 static PyObject *CFStringRefObj_CFStringCreateArrayWithFindResults(CFStringRefObject *_self, PyObject *_args)
1701 PyObject *_res = NULL;
1702 CFArrayRef _rv;
1703 CFStringRef stringToFind;
1704 CFRange rangeToSearch;
1705 CFOptionFlags compareOptions;
1706 if (!PyArg_ParseTuple(_args, "O&O&l",
1707 CFStringRefObj_Convert, &stringToFind,
1708 CFRange_Convert, &rangeToSearch,
1709 &compareOptions))
1710 return NULL;
1711 _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL,
1712 _self->ob_itself,
1713 stringToFind,
1714 rangeToSearch,
1715 compareOptions);
1716 _res = Py_BuildValue("O&",
1717 CFArrayRefObj_New, _rv);
1718 return _res;
1721 static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args)
1723 PyObject *_res = NULL;
1724 CFRange _rv;
1725 CFStringRef stringToFind;
1726 CFOptionFlags compareOptions;
1727 #ifndef CFStringFind
1728 PyMac_PRECHECK(CFStringFind);
1729 #endif
1730 if (!PyArg_ParseTuple(_args, "O&l",
1731 CFStringRefObj_Convert, &stringToFind,
1732 &compareOptions))
1733 return NULL;
1734 _rv = CFStringFind(_self->ob_itself,
1735 stringToFind,
1736 compareOptions);
1737 _res = Py_BuildValue("O&",
1738 CFRange_New, _rv);
1739 return _res;
1742 static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args)
1744 PyObject *_res = NULL;
1745 Boolean _rv;
1746 CFStringRef prefix;
1747 #ifndef CFStringHasPrefix
1748 PyMac_PRECHECK(CFStringHasPrefix);
1749 #endif
1750 if (!PyArg_ParseTuple(_args, "O&",
1751 CFStringRefObj_Convert, &prefix))
1752 return NULL;
1753 _rv = CFStringHasPrefix(_self->ob_itself,
1754 prefix);
1755 _res = Py_BuildValue("l",
1756 _rv);
1757 return _res;
1760 static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args)
1762 PyObject *_res = NULL;
1763 Boolean _rv;
1764 CFStringRef suffix;
1765 #ifndef CFStringHasSuffix
1766 PyMac_PRECHECK(CFStringHasSuffix);
1767 #endif
1768 if (!PyArg_ParseTuple(_args, "O&",
1769 CFStringRefObj_Convert, &suffix))
1770 return NULL;
1771 _rv = CFStringHasSuffix(_self->ob_itself,
1772 suffix);
1773 _res = Py_BuildValue("l",
1774 _rv);
1775 return _res;
1778 static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args)
1780 PyObject *_res = NULL;
1781 CFRange range;
1782 CFIndex lineBeginIndex;
1783 CFIndex lineEndIndex;
1784 CFIndex contentsEndIndex;
1785 #ifndef CFStringGetLineBounds
1786 PyMac_PRECHECK(CFStringGetLineBounds);
1787 #endif
1788 if (!PyArg_ParseTuple(_args, "O&",
1789 CFRange_Convert, &range))
1790 return NULL;
1791 CFStringGetLineBounds(_self->ob_itself,
1792 range,
1793 &lineBeginIndex,
1794 &lineEndIndex,
1795 &contentsEndIndex);
1796 _res = Py_BuildValue("lll",
1797 lineBeginIndex,
1798 lineEndIndex,
1799 contentsEndIndex);
1800 return _res;
1803 static PyObject *CFStringRefObj_CFStringCreateArrayBySeparatingStrings(CFStringRefObject *_self, PyObject *_args)
1805 PyObject *_res = NULL;
1806 CFArrayRef _rv;
1807 CFStringRef separatorString;
1808 if (!PyArg_ParseTuple(_args, "O&",
1809 CFStringRefObj_Convert, &separatorString))
1810 return NULL;
1811 _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL,
1812 _self->ob_itself,
1813 separatorString);
1814 _res = Py_BuildValue("O&",
1815 CFArrayRefObj_New, _rv);
1816 return _res;
1819 static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args)
1821 PyObject *_res = NULL;
1822 SInt32 _rv;
1823 #ifndef CFStringGetIntValue
1824 PyMac_PRECHECK(CFStringGetIntValue);
1825 #endif
1826 if (!PyArg_ParseTuple(_args, ""))
1827 return NULL;
1828 _rv = CFStringGetIntValue(_self->ob_itself);
1829 _res = Py_BuildValue("l",
1830 _rv);
1831 return _res;
1834 static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args)
1836 PyObject *_res = NULL;
1837 double _rv;
1838 #ifndef CFStringGetDoubleValue
1839 PyMac_PRECHECK(CFStringGetDoubleValue);
1840 #endif
1841 if (!PyArg_ParseTuple(_args, ""))
1842 return NULL;
1843 _rv = CFStringGetDoubleValue(_self->ob_itself);
1844 _res = Py_BuildValue("d",
1845 _rv);
1846 return _res;
1849 static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args)
1851 PyObject *_res = NULL;
1852 CFStringEncoding _rv;
1853 #ifndef CFStringConvertIANACharSetNameToEncoding
1854 PyMac_PRECHECK(CFStringConvertIANACharSetNameToEncoding);
1855 #endif
1856 if (!PyArg_ParseTuple(_args, ""))
1857 return NULL;
1858 _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself);
1859 _res = Py_BuildValue("l",
1860 _rv);
1861 return _res;
1864 static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args)
1866 PyObject *_res = NULL;
1867 #ifndef CFShowStr
1868 PyMac_PRECHECK(CFShowStr);
1869 #endif
1870 if (!PyArg_ParseTuple(_args, ""))
1871 return NULL;
1872 CFShowStr(_self->ob_itself);
1873 Py_INCREF(Py_None);
1874 _res = Py_None;
1875 return _res;
1878 static PyObject *CFStringRefObj_CFURLCreateWithString(CFStringRefObject *_self, PyObject *_args)
1880 PyObject *_res = NULL;
1881 CFURLRef _rv;
1882 CFURLRef baseURL;
1883 if (!PyArg_ParseTuple(_args, "O&",
1884 OptionalCFURLRefObj_Convert, &baseURL))
1885 return NULL;
1886 _rv = CFURLCreateWithString((CFAllocatorRef)NULL,
1887 _self->ob_itself,
1888 baseURL);
1889 _res = Py_BuildValue("O&",
1890 CFURLRefObj_New, _rv);
1891 return _res;
1894 static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPath(CFStringRefObject *_self, PyObject *_args)
1896 PyObject *_res = NULL;
1897 CFURLRef _rv;
1898 CFURLPathStyle pathStyle;
1899 Boolean isDirectory;
1900 if (!PyArg_ParseTuple(_args, "ll",
1901 &pathStyle,
1902 &isDirectory))
1903 return NULL;
1904 _rv = CFURLCreateWithFileSystemPath((CFAllocatorRef)NULL,
1905 _self->ob_itself,
1906 pathStyle,
1907 isDirectory);
1908 _res = Py_BuildValue("O&",
1909 CFURLRefObj_New, _rv);
1910 return _res;
1913 static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase(CFStringRefObject *_self, PyObject *_args)
1915 PyObject *_res = NULL;
1916 CFURLRef _rv;
1917 CFURLPathStyle pathStyle;
1918 Boolean isDirectory;
1919 CFURLRef baseURL;
1920 if (!PyArg_ParseTuple(_args, "llO&",
1921 &pathStyle,
1922 &isDirectory,
1923 OptionalCFURLRefObj_Convert, &baseURL))
1924 return NULL;
1925 _rv = CFURLCreateWithFileSystemPathRelativeToBase((CFAllocatorRef)NULL,
1926 _self->ob_itself,
1927 pathStyle,
1928 isDirectory,
1929 baseURL);
1930 _res = Py_BuildValue("O&",
1931 CFURLRefObj_New, _rv);
1932 return _res;
1935 static PyObject *CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
1937 PyObject *_res = NULL;
1938 CFStringRef _rv;
1939 CFStringRef charactersToLeaveEscaped;
1940 if (!PyArg_ParseTuple(_args, "O&",
1941 CFStringRefObj_Convert, &charactersToLeaveEscaped))
1942 return NULL;
1943 _rv = CFURLCreateStringByReplacingPercentEscapes((CFAllocatorRef)NULL,
1944 _self->ob_itself,
1945 charactersToLeaveEscaped);
1946 _res = Py_BuildValue("O&",
1947 CFStringRefObj_New, _rv);
1948 return _res;
1951 static PyObject *CFStringRefObj_CFURLCreateStringByAddingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
1953 PyObject *_res = NULL;
1954 CFStringRef _rv;
1955 CFStringRef charactersToLeaveUnescaped;
1956 CFStringRef legalURLCharactersToBeEscaped;
1957 CFStringEncoding encoding;
1958 if (!PyArg_ParseTuple(_args, "O&O&l",
1959 CFStringRefObj_Convert, &charactersToLeaveUnescaped,
1960 CFStringRefObj_Convert, &legalURLCharactersToBeEscaped,
1961 &encoding))
1962 return NULL;
1963 _rv = CFURLCreateStringByAddingPercentEscapes((CFAllocatorRef)NULL,
1964 _self->ob_itself,
1965 charactersToLeaveUnescaped,
1966 legalURLCharactersToBeEscaped,
1967 encoding);
1968 _res = Py_BuildValue("O&",
1969 CFStringRefObj_New, _rv);
1970 return _res;
1973 static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyObject *_args)
1975 PyObject *_res = NULL;
1977 int size = CFStringGetLength(_self->ob_itself)+1;
1978 char *data = malloc(size);
1980 if( data == NULL ) return PyErr_NoMemory();
1981 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
1982 _res = (PyObject *)PyString_FromString(data);
1983 } else {
1984 PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
1985 _res = NULL;
1987 free(data);
1988 return _res;
1992 static PyObject *CFStringRefObj_CFStringGetUnicode(CFStringRefObject *_self, PyObject *_args)
1994 PyObject *_res = NULL;
1996 int size = CFStringGetLength(_self->ob_itself)+1;
1997 Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
1998 CFRange range;
2000 range.location = 0;
2001 range.length = size;
2002 if( data == NULL ) return PyErr_NoMemory();
2003 CFStringGetCharacters(_self->ob_itself, range, data);
2004 _res = (PyObject *)PyUnicode_FromUnicode(data, size);
2005 free(data);
2006 return _res;
2010 static PyMethodDef CFStringRefObj_methods[] = {
2011 {"CFStringCreateWithSubstring", (PyCFunction)CFStringRefObj_CFStringCreateWithSubstring, 1,
2012 PyDoc_STR("(CFRange range) -> (CFStringRef _rv)")},
2013 {"CFStringCreateCopy", (PyCFunction)CFStringRefObj_CFStringCreateCopy, 1,
2014 PyDoc_STR("() -> (CFStringRef _rv)")},
2015 {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1,
2016 PyDoc_STR("() -> (CFIndex _rv)")},
2017 {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1,
2018 PyDoc_STR("(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)")},
2019 {"CFStringCreateExternalRepresentation", (PyCFunction)CFStringRefObj_CFStringCreateExternalRepresentation, 1,
2020 PyDoc_STR("(CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)")},
2021 {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1,
2022 PyDoc_STR("() -> (CFStringEncoding _rv)")},
2023 {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1,
2024 PyDoc_STR("() -> (CFStringEncoding _rv)")},
2025 {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1,
2026 PyDoc_STR("(CFStringRef theString2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)")},
2027 {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1,
2028 PyDoc_STR("(CFStringRef theString2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)")},
2029 {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1,
2030 PyDoc_STR("(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)")},
2031 {"CFStringCreateArrayWithFindResults", (PyCFunction)CFStringRefObj_CFStringCreateArrayWithFindResults, 1,
2032 PyDoc_STR("(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)")},
2033 {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1,
2034 PyDoc_STR("(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)")},
2035 {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1,
2036 PyDoc_STR("(CFStringRef prefix) -> (Boolean _rv)")},
2037 {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1,
2038 PyDoc_STR("(CFStringRef suffix) -> (Boolean _rv)")},
2039 {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1,
2040 PyDoc_STR("(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)")},
2041 {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CFStringRefObj_CFStringCreateArrayBySeparatingStrings, 1,
2042 PyDoc_STR("(CFStringRef separatorString) -> (CFArrayRef _rv)")},
2043 {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1,
2044 PyDoc_STR("() -> (SInt32 _rv)")},
2045 {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1,
2046 PyDoc_STR("() -> (double _rv)")},
2047 {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1,
2048 PyDoc_STR("() -> (CFStringEncoding _rv)")},
2049 {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1,
2050 PyDoc_STR("() -> None")},
2051 {"CFURLCreateWithString", (PyCFunction)CFStringRefObj_CFURLCreateWithString, 1,
2052 PyDoc_STR("(CFURLRef baseURL) -> (CFURLRef _rv)")},
2053 {"CFURLCreateWithFileSystemPath", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPath, 1,
2054 PyDoc_STR("(CFURLPathStyle pathStyle, Boolean isDirectory) -> (CFURLRef _rv)")},
2055 {"CFURLCreateWithFileSystemPathRelativeToBase", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase, 1,
2056 PyDoc_STR("(CFURLPathStyle pathStyle, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)")},
2057 {"CFURLCreateStringByReplacingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes, 1,
2058 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
2059 {"CFURLCreateStringByAddingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByAddingPercentEscapes, 1,
2060 PyDoc_STR("(CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding) -> (CFStringRef _rv)")},
2061 {"CFStringGetString", (PyCFunction)CFStringRefObj_CFStringGetString, 1,
2062 PyDoc_STR("() -> (string _rv)")},
2063 {"CFStringGetUnicode", (PyCFunction)CFStringRefObj_CFStringGetUnicode, 1,
2064 PyDoc_STR("() -> (unicode _rv)")},
2065 {NULL, NULL, 0}
2068 PyMethodChain CFStringRefObj_chain = { CFStringRefObj_methods, &CFTypeRefObj_chain };
2070 static PyObject *CFStringRefObj_getattr(CFStringRefObject *self, char *name)
2072 return Py_FindMethodInChain(&CFStringRefObj_chain, (PyObject *)self, name);
2075 #define CFStringRefObj_setattr NULL
2077 static int CFStringRefObj_compare(CFStringRefObject *self, CFStringRefObject *other)
2079 /* XXXX Or should we use CFEqual?? */
2080 if ( self->ob_itself > other->ob_itself ) return 1;
2081 if ( self->ob_itself < other->ob_itself ) return -1;
2082 return 0;
2085 static PyObject * CFStringRefObj_repr(CFStringRefObject *self)
2087 char buf[100];
2088 sprintf(buf, "<CFStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
2089 return PyString_FromString(buf);
2092 static int CFStringRefObj_hash(CFStringRefObject *self)
2094 /* XXXX Or should we use CFHash?? */
2095 return (int)self->ob_itself;
2098 PyTypeObject CFStringRef_Type = {
2099 PyObject_HEAD_INIT(NULL)
2100 0, /*ob_size*/
2101 "_CF.CFStringRef", /*tp_name*/
2102 sizeof(CFStringRefObject), /*tp_basicsize*/
2103 0, /*tp_itemsize*/
2104 /* methods */
2105 (destructor) CFStringRefObj_dealloc, /*tp_dealloc*/
2106 0, /*tp_print*/
2107 (getattrfunc) CFStringRefObj_getattr, /*tp_getattr*/
2108 (setattrfunc) CFStringRefObj_setattr, /*tp_setattr*/
2109 (cmpfunc) CFStringRefObj_compare, /*tp_compare*/
2110 (reprfunc) CFStringRefObj_repr, /*tp_repr*/
2111 (PyNumberMethods *)0, /* tp_as_number */
2112 (PySequenceMethods *)0, /* tp_as_sequence */
2113 (PyMappingMethods *)0, /* tp_as_mapping */
2114 (hashfunc) CFStringRefObj_hash, /*tp_hash*/
2117 /* ------------------ End object type CFStringRef ------------------- */
2120 /* ----------------- Object type CFMutableStringRef ----------------- */
2122 PyTypeObject CFMutableStringRef_Type;
2124 #define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type || PyObject_TypeCheck((x), &CFMutableStringRef_Type))
2126 typedef struct CFMutableStringRefObject {
2127 PyObject_HEAD
2128 CFMutableStringRef ob_itself;
2129 void (*ob_freeit)(CFTypeRef ptr);
2130 } CFMutableStringRefObject;
2132 PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself)
2134 CFMutableStringRefObject *it;
2135 if (itself == NULL)
2137 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
2138 return NULL;
2140 it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type);
2141 if (it == NULL) return NULL;
2142 it->ob_itself = itself;
2143 it->ob_freeit = CFRelease;
2144 return (PyObject *)it;
2146 int CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself)
2149 if (v == Py_None) { *p_itself = NULL; return 1; }
2150 /* Check for other CF objects here */
2152 if (!CFMutableStringRefObj_Check(v))
2154 PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required");
2155 return 0;
2157 *p_itself = ((CFMutableStringRefObject *)v)->ob_itself;
2158 return 1;
2161 static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self)
2163 if (self->ob_freeit && self->ob_itself)
2165 self->ob_freeit((CFTypeRef)self->ob_itself);
2167 PyObject_Free((PyObject *)self);
2170 static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args)
2172 PyObject *_res = NULL;
2173 CFStringRef appendedString;
2174 #ifndef CFStringAppend
2175 PyMac_PRECHECK(CFStringAppend);
2176 #endif
2177 if (!PyArg_ParseTuple(_args, "O&",
2178 CFStringRefObj_Convert, &appendedString))
2179 return NULL;
2180 CFStringAppend(_self->ob_itself,
2181 appendedString);
2182 Py_INCREF(Py_None);
2183 _res = Py_None;
2184 return _res;
2187 static PyObject *CFMutableStringRefObj_CFStringAppendCharacters(CFMutableStringRefObject *_self, PyObject *_args)
2189 PyObject *_res = NULL;
2190 UniChar *chars__in__;
2191 UniCharCount chars__len__;
2192 int chars__in_len__;
2193 #ifndef CFStringAppendCharacters
2194 PyMac_PRECHECK(CFStringAppendCharacters);
2195 #endif
2196 if (!PyArg_ParseTuple(_args, "u#",
2197 &chars__in__, &chars__in_len__))
2198 return NULL;
2199 chars__len__ = chars__in_len__;
2200 CFStringAppendCharacters(_self->ob_itself,
2201 chars__in__, chars__len__);
2202 Py_INCREF(Py_None);
2203 _res = Py_None;
2204 return _res;
2207 static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args)
2209 PyObject *_res = NULL;
2210 Str255 pStr;
2211 CFStringEncoding encoding;
2212 #ifndef CFStringAppendPascalString
2213 PyMac_PRECHECK(CFStringAppendPascalString);
2214 #endif
2215 if (!PyArg_ParseTuple(_args, "O&l",
2216 PyMac_GetStr255, pStr,
2217 &encoding))
2218 return NULL;
2219 CFStringAppendPascalString(_self->ob_itself,
2220 pStr,
2221 encoding);
2222 Py_INCREF(Py_None);
2223 _res = Py_None;
2224 return _res;
2227 static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args)
2229 PyObject *_res = NULL;
2230 char* cStr;
2231 CFStringEncoding encoding;
2232 #ifndef CFStringAppendCString
2233 PyMac_PRECHECK(CFStringAppendCString);
2234 #endif
2235 if (!PyArg_ParseTuple(_args, "sl",
2236 &cStr,
2237 &encoding))
2238 return NULL;
2239 CFStringAppendCString(_self->ob_itself,
2240 cStr,
2241 encoding);
2242 Py_INCREF(Py_None);
2243 _res = Py_None;
2244 return _res;
2247 static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args)
2249 PyObject *_res = NULL;
2250 CFIndex idx;
2251 CFStringRef insertedStr;
2252 #ifndef CFStringInsert
2253 PyMac_PRECHECK(CFStringInsert);
2254 #endif
2255 if (!PyArg_ParseTuple(_args, "lO&",
2256 &idx,
2257 CFStringRefObj_Convert, &insertedStr))
2258 return NULL;
2259 CFStringInsert(_self->ob_itself,
2260 idx,
2261 insertedStr);
2262 Py_INCREF(Py_None);
2263 _res = Py_None;
2264 return _res;
2267 static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args)
2269 PyObject *_res = NULL;
2270 CFRange range;
2271 #ifndef CFStringDelete
2272 PyMac_PRECHECK(CFStringDelete);
2273 #endif
2274 if (!PyArg_ParseTuple(_args, "O&",
2275 CFRange_Convert, &range))
2276 return NULL;
2277 CFStringDelete(_self->ob_itself,
2278 range);
2279 Py_INCREF(Py_None);
2280 _res = Py_None;
2281 return _res;
2284 static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args)
2286 PyObject *_res = NULL;
2287 CFRange range;
2288 CFStringRef replacement;
2289 #ifndef CFStringReplace
2290 PyMac_PRECHECK(CFStringReplace);
2291 #endif
2292 if (!PyArg_ParseTuple(_args, "O&O&",
2293 CFRange_Convert, &range,
2294 CFStringRefObj_Convert, &replacement))
2295 return NULL;
2296 CFStringReplace(_self->ob_itself,
2297 range,
2298 replacement);
2299 Py_INCREF(Py_None);
2300 _res = Py_None;
2301 return _res;
2304 static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args)
2306 PyObject *_res = NULL;
2307 CFStringRef replacement;
2308 #ifndef CFStringReplaceAll
2309 PyMac_PRECHECK(CFStringReplaceAll);
2310 #endif
2311 if (!PyArg_ParseTuple(_args, "O&",
2312 CFStringRefObj_Convert, &replacement))
2313 return NULL;
2314 CFStringReplaceAll(_self->ob_itself,
2315 replacement);
2316 Py_INCREF(Py_None);
2317 _res = Py_None;
2318 return _res;
2321 static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args)
2323 PyObject *_res = NULL;
2324 CFStringRef padString;
2325 CFIndex length;
2326 CFIndex indexIntoPad;
2327 #ifndef CFStringPad
2328 PyMac_PRECHECK(CFStringPad);
2329 #endif
2330 if (!PyArg_ParseTuple(_args, "O&ll",
2331 CFStringRefObj_Convert, &padString,
2332 &length,
2333 &indexIntoPad))
2334 return NULL;
2335 CFStringPad(_self->ob_itself,
2336 padString,
2337 length,
2338 indexIntoPad);
2339 Py_INCREF(Py_None);
2340 _res = Py_None;
2341 return _res;
2344 static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args)
2346 PyObject *_res = NULL;
2347 CFStringRef trimString;
2348 #ifndef CFStringTrim
2349 PyMac_PRECHECK(CFStringTrim);
2350 #endif
2351 if (!PyArg_ParseTuple(_args, "O&",
2352 CFStringRefObj_Convert, &trimString))
2353 return NULL;
2354 CFStringTrim(_self->ob_itself,
2355 trimString);
2356 Py_INCREF(Py_None);
2357 _res = Py_None;
2358 return _res;
2361 static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args)
2363 PyObject *_res = NULL;
2364 #ifndef CFStringTrimWhitespace
2365 PyMac_PRECHECK(CFStringTrimWhitespace);
2366 #endif
2367 if (!PyArg_ParseTuple(_args, ""))
2368 return NULL;
2369 CFStringTrimWhitespace(_self->ob_itself);
2370 Py_INCREF(Py_None);
2371 _res = Py_None;
2372 return _res;
2375 static PyMethodDef CFMutableStringRefObj_methods[] = {
2376 {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1,
2377 PyDoc_STR("(CFStringRef appendedString) -> None")},
2378 {"CFStringAppendCharacters", (PyCFunction)CFMutableStringRefObj_CFStringAppendCharacters, 1,
2379 PyDoc_STR("(Buffer chars) -> None")},
2380 {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1,
2381 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> None")},
2382 {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1,
2383 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> None")},
2384 {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1,
2385 PyDoc_STR("(CFIndex idx, CFStringRef insertedStr) -> None")},
2386 {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1,
2387 PyDoc_STR("(CFRange range) -> None")},
2388 {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1,
2389 PyDoc_STR("(CFRange range, CFStringRef replacement) -> None")},
2390 {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1,
2391 PyDoc_STR("(CFStringRef replacement) -> None")},
2392 {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1,
2393 PyDoc_STR("(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None")},
2394 {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1,
2395 PyDoc_STR("(CFStringRef trimString) -> None")},
2396 {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1,
2397 PyDoc_STR("() -> None")},
2398 {NULL, NULL, 0}
2401 PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, &CFStringRefObj_chain };
2403 static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name)
2405 return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name);
2408 #define CFMutableStringRefObj_setattr NULL
2410 static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other)
2412 /* XXXX Or should we use CFEqual?? */
2413 if ( self->ob_itself > other->ob_itself ) return 1;
2414 if ( self->ob_itself < other->ob_itself ) return -1;
2415 return 0;
2418 static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self)
2420 char buf[100];
2421 sprintf(buf, "<CFMutableStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
2422 return PyString_FromString(buf);
2425 static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self)
2427 /* XXXX Or should we use CFHash?? */
2428 return (int)self->ob_itself;
2431 PyTypeObject CFMutableStringRef_Type = {
2432 PyObject_HEAD_INIT(NULL)
2433 0, /*ob_size*/
2434 "_CF.CFMutableStringRef", /*tp_name*/
2435 sizeof(CFMutableStringRefObject), /*tp_basicsize*/
2436 0, /*tp_itemsize*/
2437 /* methods */
2438 (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/
2439 0, /*tp_print*/
2440 (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/
2441 (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/
2442 (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/
2443 (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/
2444 (PyNumberMethods *)0, /* tp_as_number */
2445 (PySequenceMethods *)0, /* tp_as_sequence */
2446 (PyMappingMethods *)0, /* tp_as_mapping */
2447 (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/
2450 /* --------------- End object type CFMutableStringRef --------------- */
2453 /* ---------------------- Object type CFURLRef ---------------------- */
2455 PyTypeObject CFURLRef_Type;
2457 #define CFURLRefObj_Check(x) ((x)->ob_type == &CFURLRef_Type || PyObject_TypeCheck((x), &CFURLRef_Type))
2459 typedef struct CFURLRefObject {
2460 PyObject_HEAD
2461 CFURLRef ob_itself;
2462 void (*ob_freeit)(CFTypeRef ptr);
2463 } CFURLRefObject;
2465 PyObject *CFURLRefObj_New(CFURLRef itself)
2467 CFURLRefObject *it;
2468 if (itself == NULL)
2470 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
2471 return NULL;
2473 it = PyObject_NEW(CFURLRefObject, &CFURLRef_Type);
2474 if (it == NULL) return NULL;
2475 it->ob_itself = itself;
2476 it->ob_freeit = CFRelease;
2477 return (PyObject *)it;
2479 int CFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
2482 if (v == Py_None) { *p_itself = NULL; return 1; }
2483 /* Check for other CF objects here */
2485 if (!CFURLRefObj_Check(v))
2487 PyErr_SetString(PyExc_TypeError, "CFURLRef required");
2488 return 0;
2490 *p_itself = ((CFURLRefObject *)v)->ob_itself;
2491 return 1;
2494 static void CFURLRefObj_dealloc(CFURLRefObject *self)
2496 if (self->ob_freeit && self->ob_itself)
2498 self->ob_freeit((CFTypeRef)self->ob_itself);
2500 PyObject_Free((PyObject *)self);
2503 static PyObject *CFURLRefObj_CFURLCreateData(CFURLRefObject *_self, PyObject *_args)
2505 PyObject *_res = NULL;
2506 CFDataRef _rv;
2507 CFStringEncoding encoding;
2508 Boolean escapeWhitespace;
2509 if (!PyArg_ParseTuple(_args, "ll",
2510 &encoding,
2511 &escapeWhitespace))
2512 return NULL;
2513 _rv = CFURLCreateData((CFAllocatorRef)NULL,
2514 _self->ob_itself,
2515 encoding,
2516 escapeWhitespace);
2517 _res = Py_BuildValue("O&",
2518 CFDataRefObj_New, _rv);
2519 return _res;
2522 static PyObject *CFURLRefObj_CFURLGetFileSystemRepresentation(CFURLRefObject *_self, PyObject *_args)
2524 PyObject *_res = NULL;
2525 Boolean _rv;
2526 Boolean resolveAgainstBase;
2527 UInt8 buffer;
2528 CFIndex maxBufLen;
2529 #ifndef CFURLGetFileSystemRepresentation
2530 PyMac_PRECHECK(CFURLGetFileSystemRepresentation);
2531 #endif
2532 if (!PyArg_ParseTuple(_args, "ll",
2533 &resolveAgainstBase,
2534 &maxBufLen))
2535 return NULL;
2536 _rv = CFURLGetFileSystemRepresentation(_self->ob_itself,
2537 resolveAgainstBase,
2538 &buffer,
2539 maxBufLen);
2540 _res = Py_BuildValue("lb",
2541 _rv,
2542 buffer);
2543 return _res;
2546 static PyObject *CFURLRefObj_CFURLCopyAbsoluteURL(CFURLRefObject *_self, PyObject *_args)
2548 PyObject *_res = NULL;
2549 CFURLRef _rv;
2550 #ifndef CFURLCopyAbsoluteURL
2551 PyMac_PRECHECK(CFURLCopyAbsoluteURL);
2552 #endif
2553 if (!PyArg_ParseTuple(_args, ""))
2554 return NULL;
2555 _rv = CFURLCopyAbsoluteURL(_self->ob_itself);
2556 _res = Py_BuildValue("O&",
2557 CFURLRefObj_New, _rv);
2558 return _res;
2561 static PyObject *CFURLRefObj_CFURLGetString(CFURLRefObject *_self, PyObject *_args)
2563 PyObject *_res = NULL;
2564 CFStringRef _rv;
2565 #ifndef CFURLGetString
2566 PyMac_PRECHECK(CFURLGetString);
2567 #endif
2568 if (!PyArg_ParseTuple(_args, ""))
2569 return NULL;
2570 _rv = CFURLGetString(_self->ob_itself);
2571 _res = Py_BuildValue("O&",
2572 CFStringRefObj_New, _rv);
2573 return _res;
2576 static PyObject *CFURLRefObj_CFURLGetBaseURL(CFURLRefObject *_self, PyObject *_args)
2578 PyObject *_res = NULL;
2579 CFURLRef _rv;
2580 #ifndef CFURLGetBaseURL
2581 PyMac_PRECHECK(CFURLGetBaseURL);
2582 #endif
2583 if (!PyArg_ParseTuple(_args, ""))
2584 return NULL;
2585 _rv = CFURLGetBaseURL(_self->ob_itself);
2586 _res = Py_BuildValue("O&",
2587 CFURLRefObj_New, _rv);
2588 return _res;
2591 static PyObject *CFURLRefObj_CFURLCanBeDecomposed(CFURLRefObject *_self, PyObject *_args)
2593 PyObject *_res = NULL;
2594 Boolean _rv;
2595 #ifndef CFURLCanBeDecomposed
2596 PyMac_PRECHECK(CFURLCanBeDecomposed);
2597 #endif
2598 if (!PyArg_ParseTuple(_args, ""))
2599 return NULL;
2600 _rv = CFURLCanBeDecomposed(_self->ob_itself);
2601 _res = Py_BuildValue("l",
2602 _rv);
2603 return _res;
2606 static PyObject *CFURLRefObj_CFURLCopyScheme(CFURLRefObject *_self, PyObject *_args)
2608 PyObject *_res = NULL;
2609 CFStringRef _rv;
2610 #ifndef CFURLCopyScheme
2611 PyMac_PRECHECK(CFURLCopyScheme);
2612 #endif
2613 if (!PyArg_ParseTuple(_args, ""))
2614 return NULL;
2615 _rv = CFURLCopyScheme(_self->ob_itself);
2616 _res = Py_BuildValue("O&",
2617 CFStringRefObj_New, _rv);
2618 return _res;
2621 static PyObject *CFURLRefObj_CFURLCopyNetLocation(CFURLRefObject *_self, PyObject *_args)
2623 PyObject *_res = NULL;
2624 CFStringRef _rv;
2625 #ifndef CFURLCopyNetLocation
2626 PyMac_PRECHECK(CFURLCopyNetLocation);
2627 #endif
2628 if (!PyArg_ParseTuple(_args, ""))
2629 return NULL;
2630 _rv = CFURLCopyNetLocation(_self->ob_itself);
2631 _res = Py_BuildValue("O&",
2632 CFStringRefObj_New, _rv);
2633 return _res;
2636 static PyObject *CFURLRefObj_CFURLCopyPath(CFURLRefObject *_self, PyObject *_args)
2638 PyObject *_res = NULL;
2639 CFStringRef _rv;
2640 #ifndef CFURLCopyPath
2641 PyMac_PRECHECK(CFURLCopyPath);
2642 #endif
2643 if (!PyArg_ParseTuple(_args, ""))
2644 return NULL;
2645 _rv = CFURLCopyPath(_self->ob_itself);
2646 _res = Py_BuildValue("O&",
2647 CFStringRefObj_New, _rv);
2648 return _res;
2651 static PyObject *CFURLRefObj_CFURLCopyStrictPath(CFURLRefObject *_self, PyObject *_args)
2653 PyObject *_res = NULL;
2654 CFStringRef _rv;
2655 Boolean isAbsolute;
2656 #ifndef CFURLCopyStrictPath
2657 PyMac_PRECHECK(CFURLCopyStrictPath);
2658 #endif
2659 if (!PyArg_ParseTuple(_args, ""))
2660 return NULL;
2661 _rv = CFURLCopyStrictPath(_self->ob_itself,
2662 &isAbsolute);
2663 _res = Py_BuildValue("O&l",
2664 CFStringRefObj_New, _rv,
2665 isAbsolute);
2666 return _res;
2669 static PyObject *CFURLRefObj_CFURLCopyFileSystemPath(CFURLRefObject *_self, PyObject *_args)
2671 PyObject *_res = NULL;
2672 CFStringRef _rv;
2673 CFURLPathStyle pathStyle;
2674 #ifndef CFURLCopyFileSystemPath
2675 PyMac_PRECHECK(CFURLCopyFileSystemPath);
2676 #endif
2677 if (!PyArg_ParseTuple(_args, "l",
2678 &pathStyle))
2679 return NULL;
2680 _rv = CFURLCopyFileSystemPath(_self->ob_itself,
2681 pathStyle);
2682 _res = Py_BuildValue("O&",
2683 CFStringRefObj_New, _rv);
2684 return _res;
2687 static PyObject *CFURLRefObj_CFURLHasDirectoryPath(CFURLRefObject *_self, PyObject *_args)
2689 PyObject *_res = NULL;
2690 Boolean _rv;
2691 #ifndef CFURLHasDirectoryPath
2692 PyMac_PRECHECK(CFURLHasDirectoryPath);
2693 #endif
2694 if (!PyArg_ParseTuple(_args, ""))
2695 return NULL;
2696 _rv = CFURLHasDirectoryPath(_self->ob_itself);
2697 _res = Py_BuildValue("l",
2698 _rv);
2699 return _res;
2702 static PyObject *CFURLRefObj_CFURLCopyResourceSpecifier(CFURLRefObject *_self, PyObject *_args)
2704 PyObject *_res = NULL;
2705 CFStringRef _rv;
2706 #ifndef CFURLCopyResourceSpecifier
2707 PyMac_PRECHECK(CFURLCopyResourceSpecifier);
2708 #endif
2709 if (!PyArg_ParseTuple(_args, ""))
2710 return NULL;
2711 _rv = CFURLCopyResourceSpecifier(_self->ob_itself);
2712 _res = Py_BuildValue("O&",
2713 CFStringRefObj_New, _rv);
2714 return _res;
2717 static PyObject *CFURLRefObj_CFURLCopyHostName(CFURLRefObject *_self, PyObject *_args)
2719 PyObject *_res = NULL;
2720 CFStringRef _rv;
2721 #ifndef CFURLCopyHostName
2722 PyMac_PRECHECK(CFURLCopyHostName);
2723 #endif
2724 if (!PyArg_ParseTuple(_args, ""))
2725 return NULL;
2726 _rv = CFURLCopyHostName(_self->ob_itself);
2727 _res = Py_BuildValue("O&",
2728 CFStringRefObj_New, _rv);
2729 return _res;
2732 static PyObject *CFURLRefObj_CFURLGetPortNumber(CFURLRefObject *_self, PyObject *_args)
2734 PyObject *_res = NULL;
2735 SInt32 _rv;
2736 #ifndef CFURLGetPortNumber
2737 PyMac_PRECHECK(CFURLGetPortNumber);
2738 #endif
2739 if (!PyArg_ParseTuple(_args, ""))
2740 return NULL;
2741 _rv = CFURLGetPortNumber(_self->ob_itself);
2742 _res = Py_BuildValue("l",
2743 _rv);
2744 return _res;
2747 static PyObject *CFURLRefObj_CFURLCopyUserName(CFURLRefObject *_self, PyObject *_args)
2749 PyObject *_res = NULL;
2750 CFStringRef _rv;
2751 #ifndef CFURLCopyUserName
2752 PyMac_PRECHECK(CFURLCopyUserName);
2753 #endif
2754 if (!PyArg_ParseTuple(_args, ""))
2755 return NULL;
2756 _rv = CFURLCopyUserName(_self->ob_itself);
2757 _res = Py_BuildValue("O&",
2758 CFStringRefObj_New, _rv);
2759 return _res;
2762 static PyObject *CFURLRefObj_CFURLCopyPassword(CFURLRefObject *_self, PyObject *_args)
2764 PyObject *_res = NULL;
2765 CFStringRef _rv;
2766 #ifndef CFURLCopyPassword
2767 PyMac_PRECHECK(CFURLCopyPassword);
2768 #endif
2769 if (!PyArg_ParseTuple(_args, ""))
2770 return NULL;
2771 _rv = CFURLCopyPassword(_self->ob_itself);
2772 _res = Py_BuildValue("O&",
2773 CFStringRefObj_New, _rv);
2774 return _res;
2777 static PyObject *CFURLRefObj_CFURLCopyParameterString(CFURLRefObject *_self, PyObject *_args)
2779 PyObject *_res = NULL;
2780 CFStringRef _rv;
2781 CFStringRef charactersToLeaveEscaped;
2782 #ifndef CFURLCopyParameterString
2783 PyMac_PRECHECK(CFURLCopyParameterString);
2784 #endif
2785 if (!PyArg_ParseTuple(_args, "O&",
2786 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2787 return NULL;
2788 _rv = CFURLCopyParameterString(_self->ob_itself,
2789 charactersToLeaveEscaped);
2790 _res = Py_BuildValue("O&",
2791 CFStringRefObj_New, _rv);
2792 return _res;
2795 static PyObject *CFURLRefObj_CFURLCopyQueryString(CFURLRefObject *_self, PyObject *_args)
2797 PyObject *_res = NULL;
2798 CFStringRef _rv;
2799 CFStringRef charactersToLeaveEscaped;
2800 #ifndef CFURLCopyQueryString
2801 PyMac_PRECHECK(CFURLCopyQueryString);
2802 #endif
2803 if (!PyArg_ParseTuple(_args, "O&",
2804 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2805 return NULL;
2806 _rv = CFURLCopyQueryString(_self->ob_itself,
2807 charactersToLeaveEscaped);
2808 _res = Py_BuildValue("O&",
2809 CFStringRefObj_New, _rv);
2810 return _res;
2813 static PyObject *CFURLRefObj_CFURLCopyFragment(CFURLRefObject *_self, PyObject *_args)
2815 PyObject *_res = NULL;
2816 CFStringRef _rv;
2817 CFStringRef charactersToLeaveEscaped;
2818 #ifndef CFURLCopyFragment
2819 PyMac_PRECHECK(CFURLCopyFragment);
2820 #endif
2821 if (!PyArg_ParseTuple(_args, "O&",
2822 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2823 return NULL;
2824 _rv = CFURLCopyFragment(_self->ob_itself,
2825 charactersToLeaveEscaped);
2826 _res = Py_BuildValue("O&",
2827 CFStringRefObj_New, _rv);
2828 return _res;
2831 static PyObject *CFURLRefObj_CFURLCopyLastPathComponent(CFURLRefObject *_self, PyObject *_args)
2833 PyObject *_res = NULL;
2834 CFStringRef _rv;
2835 #ifndef CFURLCopyLastPathComponent
2836 PyMac_PRECHECK(CFURLCopyLastPathComponent);
2837 #endif
2838 if (!PyArg_ParseTuple(_args, ""))
2839 return NULL;
2840 _rv = CFURLCopyLastPathComponent(_self->ob_itself);
2841 _res = Py_BuildValue("O&",
2842 CFStringRefObj_New, _rv);
2843 return _res;
2846 static PyObject *CFURLRefObj_CFURLCopyPathExtension(CFURLRefObject *_self, PyObject *_args)
2848 PyObject *_res = NULL;
2849 CFStringRef _rv;
2850 #ifndef CFURLCopyPathExtension
2851 PyMac_PRECHECK(CFURLCopyPathExtension);
2852 #endif
2853 if (!PyArg_ParseTuple(_args, ""))
2854 return NULL;
2855 _rv = CFURLCopyPathExtension(_self->ob_itself);
2856 _res = Py_BuildValue("O&",
2857 CFStringRefObj_New, _rv);
2858 return _res;
2861 static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathComponent(CFURLRefObject *_self, PyObject *_args)
2863 PyObject *_res = NULL;
2864 CFURLRef _rv;
2865 CFStringRef pathComponent;
2866 Boolean isDirectory;
2867 if (!PyArg_ParseTuple(_args, "O&l",
2868 CFStringRefObj_Convert, &pathComponent,
2869 &isDirectory))
2870 return NULL;
2871 _rv = CFURLCreateCopyAppendingPathComponent((CFAllocatorRef)NULL,
2872 _self->ob_itself,
2873 pathComponent,
2874 isDirectory);
2875 _res = Py_BuildValue("O&",
2876 CFURLRefObj_New, _rv);
2877 return _res;
2880 static PyObject *CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent(CFURLRefObject *_self, PyObject *_args)
2882 PyObject *_res = NULL;
2883 CFURLRef _rv;
2884 if (!PyArg_ParseTuple(_args, ""))
2885 return NULL;
2886 _rv = CFURLCreateCopyDeletingLastPathComponent((CFAllocatorRef)NULL,
2887 _self->ob_itself);
2888 _res = Py_BuildValue("O&",
2889 CFURLRefObj_New, _rv);
2890 return _res;
2893 static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathExtension(CFURLRefObject *_self, PyObject *_args)
2895 PyObject *_res = NULL;
2896 CFURLRef _rv;
2897 CFStringRef extension;
2898 if (!PyArg_ParseTuple(_args, "O&",
2899 CFStringRefObj_Convert, &extension))
2900 return NULL;
2901 _rv = CFURLCreateCopyAppendingPathExtension((CFAllocatorRef)NULL,
2902 _self->ob_itself,
2903 extension);
2904 _res = Py_BuildValue("O&",
2905 CFURLRefObj_New, _rv);
2906 return _res;
2909 static PyObject *CFURLRefObj_CFURLCreateCopyDeletingPathExtension(CFURLRefObject *_self, PyObject *_args)
2911 PyObject *_res = NULL;
2912 CFURLRef _rv;
2913 if (!PyArg_ParseTuple(_args, ""))
2914 return NULL;
2915 _rv = CFURLCreateCopyDeletingPathExtension((CFAllocatorRef)NULL,
2916 _self->ob_itself);
2917 _res = Py_BuildValue("O&",
2918 CFURLRefObj_New, _rv);
2919 return _res;
2922 static PyObject *CFURLRefObj_CFURLGetFSRef(CFURLRefObject *_self, PyObject *_args)
2924 PyObject *_res = NULL;
2925 Boolean _rv;
2926 FSRef fsRef;
2927 #ifndef CFURLGetFSRef
2928 PyMac_PRECHECK(CFURLGetFSRef);
2929 #endif
2930 if (!PyArg_ParseTuple(_args, ""))
2931 return NULL;
2932 _rv = CFURLGetFSRef(_self->ob_itself,
2933 &fsRef);
2934 _res = Py_BuildValue("lO&",
2935 _rv,
2936 PyMac_BuildFSRef, &fsRef);
2937 return _res;
2940 static PyMethodDef CFURLRefObj_methods[] = {
2941 {"CFURLCreateData", (PyCFunction)CFURLRefObj_CFURLCreateData, 1,
2942 PyDoc_STR("(CFStringEncoding encoding, Boolean escapeWhitespace) -> (CFDataRef _rv)")},
2943 {"CFURLGetFileSystemRepresentation", (PyCFunction)CFURLRefObj_CFURLGetFileSystemRepresentation, 1,
2944 PyDoc_STR("(Boolean resolveAgainstBase, CFIndex maxBufLen) -> (Boolean _rv, UInt8 buffer)")},
2945 {"CFURLCopyAbsoluteURL", (PyCFunction)CFURLRefObj_CFURLCopyAbsoluteURL, 1,
2946 PyDoc_STR("() -> (CFURLRef _rv)")},
2947 {"CFURLGetString", (PyCFunction)CFURLRefObj_CFURLGetString, 1,
2948 PyDoc_STR("() -> (CFStringRef _rv)")},
2949 {"CFURLGetBaseURL", (PyCFunction)CFURLRefObj_CFURLGetBaseURL, 1,
2950 PyDoc_STR("() -> (CFURLRef _rv)")},
2951 {"CFURLCanBeDecomposed", (PyCFunction)CFURLRefObj_CFURLCanBeDecomposed, 1,
2952 PyDoc_STR("() -> (Boolean _rv)")},
2953 {"CFURLCopyScheme", (PyCFunction)CFURLRefObj_CFURLCopyScheme, 1,
2954 PyDoc_STR("() -> (CFStringRef _rv)")},
2955 {"CFURLCopyNetLocation", (PyCFunction)CFURLRefObj_CFURLCopyNetLocation, 1,
2956 PyDoc_STR("() -> (CFStringRef _rv)")},
2957 {"CFURLCopyPath", (PyCFunction)CFURLRefObj_CFURLCopyPath, 1,
2958 PyDoc_STR("() -> (CFStringRef _rv)")},
2959 {"CFURLCopyStrictPath", (PyCFunction)CFURLRefObj_CFURLCopyStrictPath, 1,
2960 PyDoc_STR("() -> (CFStringRef _rv, Boolean isAbsolute)")},
2961 {"CFURLCopyFileSystemPath", (PyCFunction)CFURLRefObj_CFURLCopyFileSystemPath, 1,
2962 PyDoc_STR("(CFURLPathStyle pathStyle) -> (CFStringRef _rv)")},
2963 {"CFURLHasDirectoryPath", (PyCFunction)CFURLRefObj_CFURLHasDirectoryPath, 1,
2964 PyDoc_STR("() -> (Boolean _rv)")},
2965 {"CFURLCopyResourceSpecifier", (PyCFunction)CFURLRefObj_CFURLCopyResourceSpecifier, 1,
2966 PyDoc_STR("() -> (CFStringRef _rv)")},
2967 {"CFURLCopyHostName", (PyCFunction)CFURLRefObj_CFURLCopyHostName, 1,
2968 PyDoc_STR("() -> (CFStringRef _rv)")},
2969 {"CFURLGetPortNumber", (PyCFunction)CFURLRefObj_CFURLGetPortNumber, 1,
2970 PyDoc_STR("() -> (SInt32 _rv)")},
2971 {"CFURLCopyUserName", (PyCFunction)CFURLRefObj_CFURLCopyUserName, 1,
2972 PyDoc_STR("() -> (CFStringRef _rv)")},
2973 {"CFURLCopyPassword", (PyCFunction)CFURLRefObj_CFURLCopyPassword, 1,
2974 PyDoc_STR("() -> (CFStringRef _rv)")},
2975 {"CFURLCopyParameterString", (PyCFunction)CFURLRefObj_CFURLCopyParameterString, 1,
2976 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
2977 {"CFURLCopyQueryString", (PyCFunction)CFURLRefObj_CFURLCopyQueryString, 1,
2978 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
2979 {"CFURLCopyFragment", (PyCFunction)CFURLRefObj_CFURLCopyFragment, 1,
2980 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
2981 {"CFURLCopyLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCopyLastPathComponent, 1,
2982 PyDoc_STR("() -> (CFStringRef _rv)")},
2983 {"CFURLCopyPathExtension", (PyCFunction)CFURLRefObj_CFURLCopyPathExtension, 1,
2984 PyDoc_STR("() -> (CFStringRef _rv)")},
2985 {"CFURLCreateCopyAppendingPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathComponent, 1,
2986 PyDoc_STR("(CFStringRef pathComponent, Boolean isDirectory) -> (CFURLRef _rv)")},
2987 {"CFURLCreateCopyDeletingLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent, 1,
2988 PyDoc_STR("() -> (CFURLRef _rv)")},
2989 {"CFURLCreateCopyAppendingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathExtension, 1,
2990 PyDoc_STR("(CFStringRef extension) -> (CFURLRef _rv)")},
2991 {"CFURLCreateCopyDeletingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingPathExtension, 1,
2992 PyDoc_STR("() -> (CFURLRef _rv)")},
2993 {"CFURLGetFSRef", (PyCFunction)CFURLRefObj_CFURLGetFSRef, 1,
2994 PyDoc_STR("() -> (Boolean _rv, FSRef fsRef)")},
2995 {NULL, NULL, 0}
2998 PyMethodChain CFURLRefObj_chain = { CFURLRefObj_methods, &CFTypeRefObj_chain };
3000 static PyObject *CFURLRefObj_getattr(CFURLRefObject *self, char *name)
3002 return Py_FindMethodInChain(&CFURLRefObj_chain, (PyObject *)self, name);
3005 #define CFURLRefObj_setattr NULL
3007 static int CFURLRefObj_compare(CFURLRefObject *self, CFURLRefObject *other)
3009 /* XXXX Or should we use CFEqual?? */
3010 if ( self->ob_itself > other->ob_itself ) return 1;
3011 if ( self->ob_itself < other->ob_itself ) return -1;
3012 return 0;
3015 static PyObject * CFURLRefObj_repr(CFURLRefObject *self)
3017 char buf[100];
3018 sprintf(buf, "<CFURL object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
3019 return PyString_FromString(buf);
3022 static int CFURLRefObj_hash(CFURLRefObject *self)
3024 /* XXXX Or should we use CFHash?? */
3025 return (int)self->ob_itself;
3028 PyTypeObject CFURLRef_Type = {
3029 PyObject_HEAD_INIT(NULL)
3030 0, /*ob_size*/
3031 "_CF.CFURLRef", /*tp_name*/
3032 sizeof(CFURLRefObject), /*tp_basicsize*/
3033 0, /*tp_itemsize*/
3034 /* methods */
3035 (destructor) CFURLRefObj_dealloc, /*tp_dealloc*/
3036 0, /*tp_print*/
3037 (getattrfunc) CFURLRefObj_getattr, /*tp_getattr*/
3038 (setattrfunc) CFURLRefObj_setattr, /*tp_setattr*/
3039 (cmpfunc) CFURLRefObj_compare, /*tp_compare*/
3040 (reprfunc) CFURLRefObj_repr, /*tp_repr*/
3041 (PyNumberMethods *)0, /* tp_as_number */
3042 (PySequenceMethods *)0, /* tp_as_sequence */
3043 (PyMappingMethods *)0, /* tp_as_mapping */
3044 (hashfunc) CFURLRefObj_hash, /*tp_hash*/
3047 /* -------------------- End object type CFURLRef -------------------- */
3050 static PyObject *CF___CFRangeMake(PyObject *_self, PyObject *_args)
3052 PyObject *_res = NULL;
3053 CFRange _rv;
3054 CFIndex loc;
3055 CFIndex len;
3056 #ifndef __CFRangeMake
3057 PyMac_PRECHECK(__CFRangeMake);
3058 #endif
3059 if (!PyArg_ParseTuple(_args, "ll",
3060 &loc,
3061 &len))
3062 return NULL;
3063 _rv = __CFRangeMake(loc,
3064 len);
3065 _res = Py_BuildValue("O&",
3066 CFRange_New, _rv);
3067 return _res;
3070 static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args)
3072 PyObject *_res = NULL;
3073 CFTypeID _rv;
3074 #ifndef CFAllocatorGetTypeID
3075 PyMac_PRECHECK(CFAllocatorGetTypeID);
3076 #endif
3077 if (!PyArg_ParseTuple(_args, ""))
3078 return NULL;
3079 _rv = CFAllocatorGetTypeID();
3080 _res = Py_BuildValue("l",
3081 _rv);
3082 return _res;
3085 static PyObject *CF_CFAllocatorGetPreferredSizeForSize(PyObject *_self, PyObject *_args)
3087 PyObject *_res = NULL;
3088 CFIndex _rv;
3089 CFIndex size;
3090 CFOptionFlags hint;
3091 #ifndef CFAllocatorGetPreferredSizeForSize
3092 PyMac_PRECHECK(CFAllocatorGetPreferredSizeForSize);
3093 #endif
3094 if (!PyArg_ParseTuple(_args, "ll",
3095 &size,
3096 &hint))
3097 return NULL;
3098 _rv = CFAllocatorGetPreferredSizeForSize((CFAllocatorRef)NULL,
3099 size,
3100 hint);
3101 _res = Py_BuildValue("l",
3102 _rv);
3103 return _res;
3106 static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args)
3108 PyObject *_res = NULL;
3109 CFStringRef _rv;
3110 CFTypeID type_id;
3111 #ifndef CFCopyTypeIDDescription
3112 PyMac_PRECHECK(CFCopyTypeIDDescription);
3113 #endif
3114 if (!PyArg_ParseTuple(_args, "l",
3115 &type_id))
3116 return NULL;
3117 _rv = CFCopyTypeIDDescription(type_id);
3118 _res = Py_BuildValue("O&",
3119 CFStringRefObj_New, _rv);
3120 return _res;
3123 static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args)
3125 PyObject *_res = NULL;
3126 CFTypeID _rv;
3127 #ifndef CFArrayGetTypeID
3128 PyMac_PRECHECK(CFArrayGetTypeID);
3129 #endif
3130 if (!PyArg_ParseTuple(_args, ""))
3131 return NULL;
3132 _rv = CFArrayGetTypeID();
3133 _res = Py_BuildValue("l",
3134 _rv);
3135 return _res;
3138 static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args)
3140 PyObject *_res = NULL;
3141 CFMutableArrayRef _rv;
3142 CFIndex capacity;
3143 #ifndef CFArrayCreateMutable
3144 PyMac_PRECHECK(CFArrayCreateMutable);
3145 #endif
3146 if (!PyArg_ParseTuple(_args, "l",
3147 &capacity))
3148 return NULL;
3149 _rv = CFArrayCreateMutable((CFAllocatorRef)NULL,
3150 capacity,
3151 &kCFTypeArrayCallBacks);
3152 _res = Py_BuildValue("O&",
3153 CFMutableArrayRefObj_New, _rv);
3154 return _res;
3157 static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args)
3159 PyObject *_res = NULL;
3160 CFMutableArrayRef _rv;
3161 CFIndex capacity;
3162 CFArrayRef theArray;
3163 #ifndef CFArrayCreateMutableCopy
3164 PyMac_PRECHECK(CFArrayCreateMutableCopy);
3165 #endif
3166 if (!PyArg_ParseTuple(_args, "lO&",
3167 &capacity,
3168 CFArrayRefObj_Convert, &theArray))
3169 return NULL;
3170 _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL,
3171 capacity,
3172 theArray);
3173 _res = Py_BuildValue("O&",
3174 CFMutableArrayRefObj_New, _rv);
3175 return _res;
3178 static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args)
3180 PyObject *_res = NULL;
3181 CFTypeID _rv;
3182 #ifndef CFDataGetTypeID
3183 PyMac_PRECHECK(CFDataGetTypeID);
3184 #endif
3185 if (!PyArg_ParseTuple(_args, ""))
3186 return NULL;
3187 _rv = CFDataGetTypeID();
3188 _res = Py_BuildValue("l",
3189 _rv);
3190 return _res;
3193 static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args)
3195 PyObject *_res = NULL;
3196 CFDataRef _rv;
3197 unsigned char *bytes__in__;
3198 long bytes__len__;
3199 int bytes__in_len__;
3200 #ifndef CFDataCreate
3201 PyMac_PRECHECK(CFDataCreate);
3202 #endif
3203 if (!PyArg_ParseTuple(_args, "s#",
3204 &bytes__in__, &bytes__in_len__))
3205 return NULL;
3206 bytes__len__ = bytes__in_len__;
3207 _rv = CFDataCreate((CFAllocatorRef)NULL,
3208 bytes__in__, bytes__len__);
3209 _res = Py_BuildValue("O&",
3210 CFDataRefObj_New, _rv);
3211 return _res;
3214 static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args)
3216 PyObject *_res = NULL;
3217 CFDataRef _rv;
3218 unsigned char *bytes__in__;
3219 long bytes__len__;
3220 int bytes__in_len__;
3221 #ifndef CFDataCreateWithBytesNoCopy
3222 PyMac_PRECHECK(CFDataCreateWithBytesNoCopy);
3223 #endif
3224 if (!PyArg_ParseTuple(_args, "s#",
3225 &bytes__in__, &bytes__in_len__))
3226 return NULL;
3227 bytes__len__ = bytes__in_len__;
3228 _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL,
3229 bytes__in__, bytes__len__,
3230 (CFAllocatorRef)NULL);
3231 _res = Py_BuildValue("O&",
3232 CFDataRefObj_New, _rv);
3233 return _res;
3236 static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args)
3238 PyObject *_res = NULL;
3239 CFMutableDataRef _rv;
3240 CFIndex capacity;
3241 #ifndef CFDataCreateMutable
3242 PyMac_PRECHECK(CFDataCreateMutable);
3243 #endif
3244 if (!PyArg_ParseTuple(_args, "l",
3245 &capacity))
3246 return NULL;
3247 _rv = CFDataCreateMutable((CFAllocatorRef)NULL,
3248 capacity);
3249 _res = Py_BuildValue("O&",
3250 CFMutableDataRefObj_New, _rv);
3251 return _res;
3254 static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args)
3256 PyObject *_res = NULL;
3257 CFMutableDataRef _rv;
3258 CFIndex capacity;
3259 CFDataRef theData;
3260 #ifndef CFDataCreateMutableCopy
3261 PyMac_PRECHECK(CFDataCreateMutableCopy);
3262 #endif
3263 if (!PyArg_ParseTuple(_args, "lO&",
3264 &capacity,
3265 CFDataRefObj_Convert, &theData))
3266 return NULL;
3267 _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL,
3268 capacity,
3269 theData);
3270 _res = Py_BuildValue("O&",
3271 CFMutableDataRefObj_New, _rv);
3272 return _res;
3275 static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args)
3277 PyObject *_res = NULL;
3278 CFTypeID _rv;
3279 #ifndef CFDictionaryGetTypeID
3280 PyMac_PRECHECK(CFDictionaryGetTypeID);
3281 #endif
3282 if (!PyArg_ParseTuple(_args, ""))
3283 return NULL;
3284 _rv = CFDictionaryGetTypeID();
3285 _res = Py_BuildValue("l",
3286 _rv);
3287 return _res;
3290 static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args)
3292 PyObject *_res = NULL;
3293 CFMutableDictionaryRef _rv;
3294 CFIndex capacity;
3295 #ifndef CFDictionaryCreateMutable
3296 PyMac_PRECHECK(CFDictionaryCreateMutable);
3297 #endif
3298 if (!PyArg_ParseTuple(_args, "l",
3299 &capacity))
3300 return NULL;
3301 _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL,
3302 capacity,
3303 &kCFTypeDictionaryKeyCallBacks,
3304 &kCFTypeDictionaryValueCallBacks);
3305 _res = Py_BuildValue("O&",
3306 CFMutableDictionaryRefObj_New, _rv);
3307 return _res;
3310 static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args)
3312 PyObject *_res = NULL;
3313 CFMutableDictionaryRef _rv;
3314 CFIndex capacity;
3315 CFDictionaryRef theDict;
3316 #ifndef CFDictionaryCreateMutableCopy
3317 PyMac_PRECHECK(CFDictionaryCreateMutableCopy);
3318 #endif
3319 if (!PyArg_ParseTuple(_args, "lO&",
3320 &capacity,
3321 CFDictionaryRefObj_Convert, &theDict))
3322 return NULL;
3323 _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL,
3324 capacity,
3325 theDict);
3326 _res = Py_BuildValue("O&",
3327 CFMutableDictionaryRefObj_New, _rv);
3328 return _res;
3331 static PyObject *CF_CFPreferencesCopyAppValue(PyObject *_self, PyObject *_args)
3333 PyObject *_res = NULL;
3334 CFTypeRef _rv;
3335 CFStringRef key;
3336 CFStringRef applicationID;
3337 #ifndef CFPreferencesCopyAppValue
3338 PyMac_PRECHECK(CFPreferencesCopyAppValue);
3339 #endif
3340 if (!PyArg_ParseTuple(_args, "O&O&",
3341 CFStringRefObj_Convert, &key,
3342 CFStringRefObj_Convert, &applicationID))
3343 return NULL;
3344 _rv = CFPreferencesCopyAppValue(key,
3345 applicationID);
3346 _res = Py_BuildValue("O&",
3347 CFTypeRefObj_New, _rv);
3348 return _res;
3351 static PyObject *CF_CFPreferencesGetAppBooleanValue(PyObject *_self, PyObject *_args)
3353 PyObject *_res = NULL;
3354 Boolean _rv;
3355 CFStringRef key;
3356 CFStringRef applicationID;
3357 Boolean keyExistsAndHasValidFormat;
3358 #ifndef CFPreferencesGetAppBooleanValue
3359 PyMac_PRECHECK(CFPreferencesGetAppBooleanValue);
3360 #endif
3361 if (!PyArg_ParseTuple(_args, "O&O&",
3362 CFStringRefObj_Convert, &key,
3363 CFStringRefObj_Convert, &applicationID))
3364 return NULL;
3365 _rv = CFPreferencesGetAppBooleanValue(key,
3366 applicationID,
3367 &keyExistsAndHasValidFormat);
3368 _res = Py_BuildValue("ll",
3369 _rv,
3370 keyExistsAndHasValidFormat);
3371 return _res;
3374 static PyObject *CF_CFPreferencesGetAppIntegerValue(PyObject *_self, PyObject *_args)
3376 PyObject *_res = NULL;
3377 CFIndex _rv;
3378 CFStringRef key;
3379 CFStringRef applicationID;
3380 Boolean keyExistsAndHasValidFormat;
3381 #ifndef CFPreferencesGetAppIntegerValue
3382 PyMac_PRECHECK(CFPreferencesGetAppIntegerValue);
3383 #endif
3384 if (!PyArg_ParseTuple(_args, "O&O&",
3385 CFStringRefObj_Convert, &key,
3386 CFStringRefObj_Convert, &applicationID))
3387 return NULL;
3388 _rv = CFPreferencesGetAppIntegerValue(key,
3389 applicationID,
3390 &keyExistsAndHasValidFormat);
3391 _res = Py_BuildValue("ll",
3392 _rv,
3393 keyExistsAndHasValidFormat);
3394 return _res;
3397 static PyObject *CF_CFPreferencesSetAppValue(PyObject *_self, PyObject *_args)
3399 PyObject *_res = NULL;
3400 CFStringRef key;
3401 CFTypeRef value;
3402 CFStringRef applicationID;
3403 #ifndef CFPreferencesSetAppValue
3404 PyMac_PRECHECK(CFPreferencesSetAppValue);
3405 #endif
3406 if (!PyArg_ParseTuple(_args, "O&O&O&",
3407 CFStringRefObj_Convert, &key,
3408 CFTypeRefObj_Convert, &value,
3409 CFStringRefObj_Convert, &applicationID))
3410 return NULL;
3411 CFPreferencesSetAppValue(key,
3412 value,
3413 applicationID);
3414 Py_INCREF(Py_None);
3415 _res = Py_None;
3416 return _res;
3419 static PyObject *CF_CFPreferencesAddSuitePreferencesToApp(PyObject *_self, PyObject *_args)
3421 PyObject *_res = NULL;
3422 CFStringRef applicationID;
3423 CFStringRef suiteID;
3424 #ifndef CFPreferencesAddSuitePreferencesToApp
3425 PyMac_PRECHECK(CFPreferencesAddSuitePreferencesToApp);
3426 #endif
3427 if (!PyArg_ParseTuple(_args, "O&O&",
3428 CFStringRefObj_Convert, &applicationID,
3429 CFStringRefObj_Convert, &suiteID))
3430 return NULL;
3431 CFPreferencesAddSuitePreferencesToApp(applicationID,
3432 suiteID);
3433 Py_INCREF(Py_None);
3434 _res = Py_None;
3435 return _res;
3438 static PyObject *CF_CFPreferencesRemoveSuitePreferencesFromApp(PyObject *_self, PyObject *_args)
3440 PyObject *_res = NULL;
3441 CFStringRef applicationID;
3442 CFStringRef suiteID;
3443 #ifndef CFPreferencesRemoveSuitePreferencesFromApp
3444 PyMac_PRECHECK(CFPreferencesRemoveSuitePreferencesFromApp);
3445 #endif
3446 if (!PyArg_ParseTuple(_args, "O&O&",
3447 CFStringRefObj_Convert, &applicationID,
3448 CFStringRefObj_Convert, &suiteID))
3449 return NULL;
3450 CFPreferencesRemoveSuitePreferencesFromApp(applicationID,
3451 suiteID);
3452 Py_INCREF(Py_None);
3453 _res = Py_None;
3454 return _res;
3457 static PyObject *CF_CFPreferencesAppSynchronize(PyObject *_self, PyObject *_args)
3459 PyObject *_res = NULL;
3460 Boolean _rv;
3461 CFStringRef applicationID;
3462 #ifndef CFPreferencesAppSynchronize
3463 PyMac_PRECHECK(CFPreferencesAppSynchronize);
3464 #endif
3465 if (!PyArg_ParseTuple(_args, "O&",
3466 CFStringRefObj_Convert, &applicationID))
3467 return NULL;
3468 _rv = CFPreferencesAppSynchronize(applicationID);
3469 _res = Py_BuildValue("l",
3470 _rv);
3471 return _res;
3474 static PyObject *CF_CFPreferencesCopyValue(PyObject *_self, PyObject *_args)
3476 PyObject *_res = NULL;
3477 CFTypeRef _rv;
3478 CFStringRef key;
3479 CFStringRef applicationID;
3480 CFStringRef userName;
3481 CFStringRef hostName;
3482 #ifndef CFPreferencesCopyValue
3483 PyMac_PRECHECK(CFPreferencesCopyValue);
3484 #endif
3485 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
3486 CFStringRefObj_Convert, &key,
3487 CFStringRefObj_Convert, &applicationID,
3488 CFStringRefObj_Convert, &userName,
3489 CFStringRefObj_Convert, &hostName))
3490 return NULL;
3491 _rv = CFPreferencesCopyValue(key,
3492 applicationID,
3493 userName,
3494 hostName);
3495 _res = Py_BuildValue("O&",
3496 CFTypeRefObj_New, _rv);
3497 return _res;
3500 static PyObject *CF_CFPreferencesCopyMultiple(PyObject *_self, PyObject *_args)
3502 PyObject *_res = NULL;
3503 CFDictionaryRef _rv;
3504 CFArrayRef keysToFetch;
3505 CFStringRef applicationID;
3506 CFStringRef userName;
3507 CFStringRef hostName;
3508 #ifndef CFPreferencesCopyMultiple
3509 PyMac_PRECHECK(CFPreferencesCopyMultiple);
3510 #endif
3511 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
3512 CFArrayRefObj_Convert, &keysToFetch,
3513 CFStringRefObj_Convert, &applicationID,
3514 CFStringRefObj_Convert, &userName,
3515 CFStringRefObj_Convert, &hostName))
3516 return NULL;
3517 _rv = CFPreferencesCopyMultiple(keysToFetch,
3518 applicationID,
3519 userName,
3520 hostName);
3521 _res = Py_BuildValue("O&",
3522 CFDictionaryRefObj_New, _rv);
3523 return _res;
3526 static PyObject *CF_CFPreferencesSetValue(PyObject *_self, PyObject *_args)
3528 PyObject *_res = NULL;
3529 CFStringRef key;
3530 CFTypeRef value;
3531 CFStringRef applicationID;
3532 CFStringRef userName;
3533 CFStringRef hostName;
3534 #ifndef CFPreferencesSetValue
3535 PyMac_PRECHECK(CFPreferencesSetValue);
3536 #endif
3537 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
3538 CFStringRefObj_Convert, &key,
3539 CFTypeRefObj_Convert, &value,
3540 CFStringRefObj_Convert, &applicationID,
3541 CFStringRefObj_Convert, &userName,
3542 CFStringRefObj_Convert, &hostName))
3543 return NULL;
3544 CFPreferencesSetValue(key,
3545 value,
3546 applicationID,
3547 userName,
3548 hostName);
3549 Py_INCREF(Py_None);
3550 _res = Py_None;
3551 return _res;
3554 static PyObject *CF_CFPreferencesSetMultiple(PyObject *_self, PyObject *_args)
3556 PyObject *_res = NULL;
3557 CFDictionaryRef keysToSet;
3558 CFArrayRef keysToRemove;
3559 CFStringRef applicationID;
3560 CFStringRef userName;
3561 CFStringRef hostName;
3562 #ifndef CFPreferencesSetMultiple
3563 PyMac_PRECHECK(CFPreferencesSetMultiple);
3564 #endif
3565 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
3566 CFDictionaryRefObj_Convert, &keysToSet,
3567 CFArrayRefObj_Convert, &keysToRemove,
3568 CFStringRefObj_Convert, &applicationID,
3569 CFStringRefObj_Convert, &userName,
3570 CFStringRefObj_Convert, &hostName))
3571 return NULL;
3572 CFPreferencesSetMultiple(keysToSet,
3573 keysToRemove,
3574 applicationID,
3575 userName,
3576 hostName);
3577 Py_INCREF(Py_None);
3578 _res = Py_None;
3579 return _res;
3582 static PyObject *CF_CFPreferencesSynchronize(PyObject *_self, PyObject *_args)
3584 PyObject *_res = NULL;
3585 Boolean _rv;
3586 CFStringRef applicationID;
3587 CFStringRef userName;
3588 CFStringRef hostName;
3589 #ifndef CFPreferencesSynchronize
3590 PyMac_PRECHECK(CFPreferencesSynchronize);
3591 #endif
3592 if (!PyArg_ParseTuple(_args, "O&O&O&",
3593 CFStringRefObj_Convert, &applicationID,
3594 CFStringRefObj_Convert, &userName,
3595 CFStringRefObj_Convert, &hostName))
3596 return NULL;
3597 _rv = CFPreferencesSynchronize(applicationID,
3598 userName,
3599 hostName);
3600 _res = Py_BuildValue("l",
3601 _rv);
3602 return _res;
3605 static PyObject *CF_CFPreferencesCopyApplicationList(PyObject *_self, PyObject *_args)
3607 PyObject *_res = NULL;
3608 CFArrayRef _rv;
3609 CFStringRef userName;
3610 CFStringRef hostName;
3611 #ifndef CFPreferencesCopyApplicationList
3612 PyMac_PRECHECK(CFPreferencesCopyApplicationList);
3613 #endif
3614 if (!PyArg_ParseTuple(_args, "O&O&",
3615 CFStringRefObj_Convert, &userName,
3616 CFStringRefObj_Convert, &hostName))
3617 return NULL;
3618 _rv = CFPreferencesCopyApplicationList(userName,
3619 hostName);
3620 _res = Py_BuildValue("O&",
3621 CFArrayRefObj_New, _rv);
3622 return _res;
3625 static PyObject *CF_CFPreferencesCopyKeyList(PyObject *_self, PyObject *_args)
3627 PyObject *_res = NULL;
3628 CFArrayRef _rv;
3629 CFStringRef applicationID;
3630 CFStringRef userName;
3631 CFStringRef hostName;
3632 #ifndef CFPreferencesCopyKeyList
3633 PyMac_PRECHECK(CFPreferencesCopyKeyList);
3634 #endif
3635 if (!PyArg_ParseTuple(_args, "O&O&O&",
3636 CFStringRefObj_Convert, &applicationID,
3637 CFStringRefObj_Convert, &userName,
3638 CFStringRefObj_Convert, &hostName))
3639 return NULL;
3640 _rv = CFPreferencesCopyKeyList(applicationID,
3641 userName,
3642 hostName);
3643 _res = Py_BuildValue("O&",
3644 CFArrayRefObj_New, _rv);
3645 return _res;
3648 static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args)
3650 PyObject *_res = NULL;
3651 CFTypeID _rv;
3652 #ifndef CFStringGetTypeID
3653 PyMac_PRECHECK(CFStringGetTypeID);
3654 #endif
3655 if (!PyArg_ParseTuple(_args, ""))
3656 return NULL;
3657 _rv = CFStringGetTypeID();
3658 _res = Py_BuildValue("l",
3659 _rv);
3660 return _res;
3663 static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args)
3665 PyObject *_res = NULL;
3666 CFStringRef _rv;
3667 Str255 pStr;
3668 CFStringEncoding encoding;
3669 #ifndef CFStringCreateWithPascalString
3670 PyMac_PRECHECK(CFStringCreateWithPascalString);
3671 #endif
3672 if (!PyArg_ParseTuple(_args, "O&l",
3673 PyMac_GetStr255, pStr,
3674 &encoding))
3675 return NULL;
3676 _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL,
3677 pStr,
3678 encoding);
3679 _res = Py_BuildValue("O&",
3680 CFStringRefObj_New, _rv);
3681 return _res;
3684 static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args)
3686 PyObject *_res = NULL;
3687 CFStringRef _rv;
3688 char* cStr;
3689 CFStringEncoding encoding;
3690 #ifndef CFStringCreateWithCString
3691 PyMac_PRECHECK(CFStringCreateWithCString);
3692 #endif
3693 if (!PyArg_ParseTuple(_args, "sl",
3694 &cStr,
3695 &encoding))
3696 return NULL;
3697 _rv = CFStringCreateWithCString((CFAllocatorRef)NULL,
3698 cStr,
3699 encoding);
3700 _res = Py_BuildValue("O&",
3701 CFStringRefObj_New, _rv);
3702 return _res;
3705 static PyObject *CF_CFStringCreateWithCharacters(PyObject *_self, PyObject *_args)
3707 PyObject *_res = NULL;
3708 CFStringRef _rv;
3709 UniChar *chars__in__;
3710 UniCharCount chars__len__;
3711 int chars__in_len__;
3712 #ifndef CFStringCreateWithCharacters
3713 PyMac_PRECHECK(CFStringCreateWithCharacters);
3714 #endif
3715 if (!PyArg_ParseTuple(_args, "u#",
3716 &chars__in__, &chars__in_len__))
3717 return NULL;
3718 chars__len__ = chars__in_len__;
3719 _rv = CFStringCreateWithCharacters((CFAllocatorRef)NULL,
3720 chars__in__, chars__len__);
3721 _res = Py_BuildValue("O&",
3722 CFStringRefObj_New, _rv);
3723 return _res;
3726 static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args)
3728 PyObject *_res = NULL;
3729 CFStringRef _rv;
3730 Str255 pStr;
3731 CFStringEncoding encoding;
3732 #ifndef CFStringCreateWithPascalStringNoCopy
3733 PyMac_PRECHECK(CFStringCreateWithPascalStringNoCopy);
3734 #endif
3735 if (!PyArg_ParseTuple(_args, "O&l",
3736 PyMac_GetStr255, pStr,
3737 &encoding))
3738 return NULL;
3739 _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL,
3740 pStr,
3741 encoding,
3742 (CFAllocatorRef)NULL);
3743 _res = Py_BuildValue("O&",
3744 CFStringRefObj_New, _rv);
3745 return _res;
3748 static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args)
3750 PyObject *_res = NULL;
3751 CFStringRef _rv;
3752 char* cStr;
3753 CFStringEncoding encoding;
3754 #ifndef CFStringCreateWithCStringNoCopy
3755 PyMac_PRECHECK(CFStringCreateWithCStringNoCopy);
3756 #endif
3757 if (!PyArg_ParseTuple(_args, "sl",
3758 &cStr,
3759 &encoding))
3760 return NULL;
3761 _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL,
3762 cStr,
3763 encoding,
3764 (CFAllocatorRef)NULL);
3765 _res = Py_BuildValue("O&",
3766 CFStringRefObj_New, _rv);
3767 return _res;
3770 static PyObject *CF_CFStringCreateWithCharactersNoCopy(PyObject *_self, PyObject *_args)
3772 PyObject *_res = NULL;
3773 CFStringRef _rv;
3774 UniChar *chars__in__;
3775 UniCharCount chars__len__;
3776 int chars__in_len__;
3777 #ifndef CFStringCreateWithCharactersNoCopy
3778 PyMac_PRECHECK(CFStringCreateWithCharactersNoCopy);
3779 #endif
3780 if (!PyArg_ParseTuple(_args, "u#",
3781 &chars__in__, &chars__in_len__))
3782 return NULL;
3783 chars__len__ = chars__in_len__;
3784 _rv = CFStringCreateWithCharactersNoCopy((CFAllocatorRef)NULL,
3785 chars__in__, chars__len__,
3786 (CFAllocatorRef)NULL);
3787 _res = Py_BuildValue("O&",
3788 CFStringRefObj_New, _rv);
3789 return _res;
3792 static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args)
3794 PyObject *_res = NULL;
3795 CFMutableStringRef _rv;
3796 CFIndex maxLength;
3797 #ifndef CFStringCreateMutable
3798 PyMac_PRECHECK(CFStringCreateMutable);
3799 #endif
3800 if (!PyArg_ParseTuple(_args, "l",
3801 &maxLength))
3802 return NULL;
3803 _rv = CFStringCreateMutable((CFAllocatorRef)NULL,
3804 maxLength);
3805 _res = Py_BuildValue("O&",
3806 CFMutableStringRefObj_New, _rv);
3807 return _res;
3810 static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args)
3812 PyObject *_res = NULL;
3813 CFMutableStringRef _rv;
3814 CFIndex maxLength;
3815 CFStringRef theString;
3816 #ifndef CFStringCreateMutableCopy
3817 PyMac_PRECHECK(CFStringCreateMutableCopy);
3818 #endif
3819 if (!PyArg_ParseTuple(_args, "lO&",
3820 &maxLength,
3821 CFStringRefObj_Convert, &theString))
3822 return NULL;
3823 _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL,
3824 maxLength,
3825 theString);
3826 _res = Py_BuildValue("O&",
3827 CFMutableStringRefObj_New, _rv);
3828 return _res;
3831 static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args)
3833 PyObject *_res = NULL;
3834 CFStringRef _rv;
3835 unsigned char *bytes__in__;
3836 long bytes__len__;
3837 int bytes__in_len__;
3838 CFStringEncoding encoding;
3839 Boolean isExternalRepresentation;
3840 #ifndef CFStringCreateWithBytes
3841 PyMac_PRECHECK(CFStringCreateWithBytes);
3842 #endif
3843 if (!PyArg_ParseTuple(_args, "s#ll",
3844 &bytes__in__, &bytes__in_len__,
3845 &encoding,
3846 &isExternalRepresentation))
3847 return NULL;
3848 bytes__len__ = bytes__in_len__;
3849 _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL,
3850 bytes__in__, bytes__len__,
3851 encoding,
3852 isExternalRepresentation);
3853 _res = Py_BuildValue("O&",
3854 CFStringRefObj_New, _rv);
3855 return _res;
3858 static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args)
3860 PyObject *_res = NULL;
3861 CFStringEncoding _rv;
3862 #ifndef CFStringGetSystemEncoding
3863 PyMac_PRECHECK(CFStringGetSystemEncoding);
3864 #endif
3865 if (!PyArg_ParseTuple(_args, ""))
3866 return NULL;
3867 _rv = CFStringGetSystemEncoding();
3868 _res = Py_BuildValue("l",
3869 _rv);
3870 return _res;
3873 static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args)
3875 PyObject *_res = NULL;
3876 CFIndex _rv;
3877 CFIndex length;
3878 CFStringEncoding encoding;
3879 #ifndef CFStringGetMaximumSizeForEncoding
3880 PyMac_PRECHECK(CFStringGetMaximumSizeForEncoding);
3881 #endif
3882 if (!PyArg_ParseTuple(_args, "ll",
3883 &length,
3884 &encoding))
3885 return NULL;
3886 _rv = CFStringGetMaximumSizeForEncoding(length,
3887 encoding);
3888 _res = Py_BuildValue("l",
3889 _rv);
3890 return _res;
3893 static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args)
3895 PyObject *_res = NULL;
3896 Boolean _rv;
3897 CFStringEncoding encoding;
3898 #ifndef CFStringIsEncodingAvailable
3899 PyMac_PRECHECK(CFStringIsEncodingAvailable);
3900 #endif
3901 if (!PyArg_ParseTuple(_args, "l",
3902 &encoding))
3903 return NULL;
3904 _rv = CFStringIsEncodingAvailable(encoding);
3905 _res = Py_BuildValue("l",
3906 _rv);
3907 return _res;
3910 static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args)
3912 PyObject *_res = NULL;
3913 CFStringRef _rv;
3914 CFStringEncoding encoding;
3915 #ifndef CFStringGetNameOfEncoding
3916 PyMac_PRECHECK(CFStringGetNameOfEncoding);
3917 #endif
3918 if (!PyArg_ParseTuple(_args, "l",
3919 &encoding))
3920 return NULL;
3921 _rv = CFStringGetNameOfEncoding(encoding);
3922 _res = Py_BuildValue("O&",
3923 CFStringRefObj_New, _rv);
3924 return _res;
3927 static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args)
3929 PyObject *_res = NULL;
3930 UInt32 _rv;
3931 CFStringEncoding encoding;
3932 #ifndef CFStringConvertEncodingToNSStringEncoding
3933 PyMac_PRECHECK(CFStringConvertEncodingToNSStringEncoding);
3934 #endif
3935 if (!PyArg_ParseTuple(_args, "l",
3936 &encoding))
3937 return NULL;
3938 _rv = CFStringConvertEncodingToNSStringEncoding(encoding);
3939 _res = Py_BuildValue("l",
3940 _rv);
3941 return _res;
3944 static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args)
3946 PyObject *_res = NULL;
3947 CFStringEncoding _rv;
3948 UInt32 encoding;
3949 #ifndef CFStringConvertNSStringEncodingToEncoding
3950 PyMac_PRECHECK(CFStringConvertNSStringEncodingToEncoding);
3951 #endif
3952 if (!PyArg_ParseTuple(_args, "l",
3953 &encoding))
3954 return NULL;
3955 _rv = CFStringConvertNSStringEncodingToEncoding(encoding);
3956 _res = Py_BuildValue("l",
3957 _rv);
3958 return _res;
3961 static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args)
3963 PyObject *_res = NULL;
3964 UInt32 _rv;
3965 CFStringEncoding encoding;
3966 #ifndef CFStringConvertEncodingToWindowsCodepage
3967 PyMac_PRECHECK(CFStringConvertEncodingToWindowsCodepage);
3968 #endif
3969 if (!PyArg_ParseTuple(_args, "l",
3970 &encoding))
3971 return NULL;
3972 _rv = CFStringConvertEncodingToWindowsCodepage(encoding);
3973 _res = Py_BuildValue("l",
3974 _rv);
3975 return _res;
3978 static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args)
3980 PyObject *_res = NULL;
3981 CFStringEncoding _rv;
3982 UInt32 codepage;
3983 #ifndef CFStringConvertWindowsCodepageToEncoding
3984 PyMac_PRECHECK(CFStringConvertWindowsCodepageToEncoding);
3985 #endif
3986 if (!PyArg_ParseTuple(_args, "l",
3987 &codepage))
3988 return NULL;
3989 _rv = CFStringConvertWindowsCodepageToEncoding(codepage);
3990 _res = Py_BuildValue("l",
3991 _rv);
3992 return _res;
3995 static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args)
3997 PyObject *_res = NULL;
3998 CFStringRef _rv;
3999 CFStringEncoding encoding;
4000 #ifndef CFStringConvertEncodingToIANACharSetName
4001 PyMac_PRECHECK(CFStringConvertEncodingToIANACharSetName);
4002 #endif
4003 if (!PyArg_ParseTuple(_args, "l",
4004 &encoding))
4005 return NULL;
4006 _rv = CFStringConvertEncodingToIANACharSetName(encoding);
4007 _res = Py_BuildValue("O&",
4008 CFStringRefObj_New, _rv);
4009 return _res;
4012 static PyObject *CF_CFStringGetMostCompatibleMacStringEncoding(PyObject *_self, PyObject *_args)
4014 PyObject *_res = NULL;
4015 CFStringEncoding _rv;
4016 CFStringEncoding encoding;
4017 #ifndef CFStringGetMostCompatibleMacStringEncoding
4018 PyMac_PRECHECK(CFStringGetMostCompatibleMacStringEncoding);
4019 #endif
4020 if (!PyArg_ParseTuple(_args, "l",
4021 &encoding))
4022 return NULL;
4023 _rv = CFStringGetMostCompatibleMacStringEncoding(encoding);
4024 _res = Py_BuildValue("l",
4025 _rv);
4026 return _res;
4029 static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args)
4031 PyObject *_res = NULL;
4032 CFStringRef _rv;
4033 char* cStr;
4034 #ifndef __CFStringMakeConstantString
4035 PyMac_PRECHECK(__CFStringMakeConstantString);
4036 #endif
4037 if (!PyArg_ParseTuple(_args, "s",
4038 &cStr))
4039 return NULL;
4040 _rv = __CFStringMakeConstantString(cStr);
4041 _res = Py_BuildValue("O&",
4042 CFStringRefObj_New, _rv);
4043 return _res;
4046 static PyObject *CF_CFURLGetTypeID(PyObject *_self, PyObject *_args)
4048 PyObject *_res = NULL;
4049 CFTypeID _rv;
4050 #ifndef CFURLGetTypeID
4051 PyMac_PRECHECK(CFURLGetTypeID);
4052 #endif
4053 if (!PyArg_ParseTuple(_args, ""))
4054 return NULL;
4055 _rv = CFURLGetTypeID();
4056 _res = Py_BuildValue("l",
4057 _rv);
4058 return _res;
4061 static PyObject *CF_CFURLCreateWithBytes(PyObject *_self, PyObject *_args)
4063 PyObject *_res = NULL;
4064 CFURLRef _rv;
4065 unsigned char *URLBytes__in__;
4066 long URLBytes__len__;
4067 int URLBytes__in_len__;
4068 CFStringEncoding encoding;
4069 CFURLRef baseURL;
4070 #ifndef CFURLCreateWithBytes
4071 PyMac_PRECHECK(CFURLCreateWithBytes);
4072 #endif
4073 if (!PyArg_ParseTuple(_args, "s#lO&",
4074 &URLBytes__in__, &URLBytes__in_len__,
4075 &encoding,
4076 OptionalCFURLRefObj_Convert, &baseURL))
4077 return NULL;
4078 URLBytes__len__ = URLBytes__in_len__;
4079 _rv = CFURLCreateWithBytes((CFAllocatorRef)NULL,
4080 URLBytes__in__, URLBytes__len__,
4081 encoding,
4082 baseURL);
4083 _res = Py_BuildValue("O&",
4084 CFURLRefObj_New, _rv);
4085 return _res;
4088 static PyObject *CF_CFURLCreateFromFileSystemRepresentation(PyObject *_self, PyObject *_args)
4090 PyObject *_res = NULL;
4091 CFURLRef _rv;
4092 unsigned char *buffer__in__;
4093 long buffer__len__;
4094 int buffer__in_len__;
4095 Boolean isDirectory;
4096 #ifndef CFURLCreateFromFileSystemRepresentation
4097 PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentation);
4098 #endif
4099 if (!PyArg_ParseTuple(_args, "s#l",
4100 &buffer__in__, &buffer__in_len__,
4101 &isDirectory))
4102 return NULL;
4103 buffer__len__ = buffer__in_len__;
4104 _rv = CFURLCreateFromFileSystemRepresentation((CFAllocatorRef)NULL,
4105 buffer__in__, buffer__len__,
4106 isDirectory);
4107 _res = Py_BuildValue("O&",
4108 CFURLRefObj_New, _rv);
4109 return _res;
4112 static PyObject *CF_CFURLCreateFromFileSystemRepresentationRelativeToBase(PyObject *_self, PyObject *_args)
4114 PyObject *_res = NULL;
4115 CFURLRef _rv;
4116 unsigned char *buffer__in__;
4117 long buffer__len__;
4118 int buffer__in_len__;
4119 Boolean isDirectory;
4120 CFURLRef baseURL;
4121 #ifndef CFURLCreateFromFileSystemRepresentationRelativeToBase
4122 PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentationRelativeToBase);
4123 #endif
4124 if (!PyArg_ParseTuple(_args, "s#lO&",
4125 &buffer__in__, &buffer__in_len__,
4126 &isDirectory,
4127 OptionalCFURLRefObj_Convert, &baseURL))
4128 return NULL;
4129 buffer__len__ = buffer__in_len__;
4130 _rv = CFURLCreateFromFileSystemRepresentationRelativeToBase((CFAllocatorRef)NULL,
4131 buffer__in__, buffer__len__,
4132 isDirectory,
4133 baseURL);
4134 _res = Py_BuildValue("O&",
4135 CFURLRefObj_New, _rv);
4136 return _res;
4139 static PyObject *CF_CFURLCreateFromFSRef(PyObject *_self, PyObject *_args)
4141 PyObject *_res = NULL;
4142 CFURLRef _rv;
4143 FSRef fsRef;
4144 #ifndef CFURLCreateFromFSRef
4145 PyMac_PRECHECK(CFURLCreateFromFSRef);
4146 #endif
4147 if (!PyArg_ParseTuple(_args, "O&",
4148 PyMac_GetFSRef, &fsRef))
4149 return NULL;
4150 _rv = CFURLCreateFromFSRef((CFAllocatorRef)NULL,
4151 &fsRef);
4152 _res = Py_BuildValue("O&",
4153 CFURLRefObj_New, _rv);
4154 return _res;
4157 static PyObject *CF_toCF(PyObject *_self, PyObject *_args)
4159 PyObject *_res = NULL;
4161 CFTypeRef rv;
4162 CFTypeID typeid;
4164 if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
4165 return NULL;
4166 typeid = CFGetTypeID(rv);
4168 if (typeid == CFStringGetTypeID())
4169 return Py_BuildValue("O&", CFStringRefObj_New, rv);
4170 if (typeid == CFArrayGetTypeID())
4171 return Py_BuildValue("O&", CFArrayRefObj_New, rv);
4172 if (typeid == CFDictionaryGetTypeID())
4173 return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
4174 if (typeid == CFURLGetTypeID())
4175 return Py_BuildValue("O&", CFURLRefObj_New, rv);
4177 _res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
4178 return _res;
4182 static PyMethodDef CF_methods[] = {
4183 {"__CFRangeMake", (PyCFunction)CF___CFRangeMake, 1,
4184 PyDoc_STR("(CFIndex loc, CFIndex len) -> (CFRange _rv)")},
4185 {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1,
4186 PyDoc_STR("() -> (CFTypeID _rv)")},
4187 {"CFAllocatorGetPreferredSizeForSize", (PyCFunction)CF_CFAllocatorGetPreferredSizeForSize, 1,
4188 PyDoc_STR("(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)")},
4189 {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1,
4190 PyDoc_STR("(CFTypeID type_id) -> (CFStringRef _rv)")},
4191 {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1,
4192 PyDoc_STR("() -> (CFTypeID _rv)")},
4193 {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1,
4194 PyDoc_STR("(CFIndex capacity) -> (CFMutableArrayRef _rv)")},
4195 {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1,
4196 PyDoc_STR("(CFIndex capacity, CFArrayRef theArray) -> (CFMutableArrayRef _rv)")},
4197 {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1,
4198 PyDoc_STR("() -> (CFTypeID _rv)")},
4199 {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1,
4200 PyDoc_STR("(Buffer bytes) -> (CFDataRef _rv)")},
4201 {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1,
4202 PyDoc_STR("(Buffer bytes) -> (CFDataRef _rv)")},
4203 {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1,
4204 PyDoc_STR("(CFIndex capacity) -> (CFMutableDataRef _rv)")},
4205 {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1,
4206 PyDoc_STR("(CFIndex capacity, CFDataRef theData) -> (CFMutableDataRef _rv)")},
4207 {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1,
4208 PyDoc_STR("() -> (CFTypeID _rv)")},
4209 {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1,
4210 PyDoc_STR("(CFIndex capacity) -> (CFMutableDictionaryRef _rv)")},
4211 {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1,
4212 PyDoc_STR("(CFIndex capacity, CFDictionaryRef theDict) -> (CFMutableDictionaryRef _rv)")},
4213 {"CFPreferencesCopyAppValue", (PyCFunction)CF_CFPreferencesCopyAppValue, 1,
4214 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (CFTypeRef _rv)")},
4215 {"CFPreferencesGetAppBooleanValue", (PyCFunction)CF_CFPreferencesGetAppBooleanValue, 1,
4216 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (Boolean _rv, Boolean keyExistsAndHasValidFormat)")},
4217 {"CFPreferencesGetAppIntegerValue", (PyCFunction)CF_CFPreferencesGetAppIntegerValue, 1,
4218 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (CFIndex _rv, Boolean keyExistsAndHasValidFormat)")},
4219 {"CFPreferencesSetAppValue", (PyCFunction)CF_CFPreferencesSetAppValue, 1,
4220 PyDoc_STR("(CFStringRef key, CFTypeRef value, CFStringRef applicationID) -> None")},
4221 {"CFPreferencesAddSuitePreferencesToApp", (PyCFunction)CF_CFPreferencesAddSuitePreferencesToApp, 1,
4222 PyDoc_STR("(CFStringRef applicationID, CFStringRef suiteID) -> None")},
4223 {"CFPreferencesRemoveSuitePreferencesFromApp", (PyCFunction)CF_CFPreferencesRemoveSuitePreferencesFromApp, 1,
4224 PyDoc_STR("(CFStringRef applicationID, CFStringRef suiteID) -> None")},
4225 {"CFPreferencesAppSynchronize", (PyCFunction)CF_CFPreferencesAppSynchronize, 1,
4226 PyDoc_STR("(CFStringRef applicationID) -> (Boolean _rv)")},
4227 {"CFPreferencesCopyValue", (PyCFunction)CF_CFPreferencesCopyValue, 1,
4228 PyDoc_STR("(CFStringRef key, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFTypeRef _rv)")},
4229 {"CFPreferencesCopyMultiple", (PyCFunction)CF_CFPreferencesCopyMultiple, 1,
4230 PyDoc_STR("(CFArrayRef keysToFetch, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFDictionaryRef _rv)")},
4231 {"CFPreferencesSetValue", (PyCFunction)CF_CFPreferencesSetValue, 1,
4232 PyDoc_STR("(CFStringRef key, CFTypeRef value, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> None")},
4233 {"CFPreferencesSetMultiple", (PyCFunction)CF_CFPreferencesSetMultiple, 1,
4234 PyDoc_STR("(CFDictionaryRef keysToSet, CFArrayRef keysToRemove, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> None")},
4235 {"CFPreferencesSynchronize", (PyCFunction)CF_CFPreferencesSynchronize, 1,
4236 PyDoc_STR("(CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (Boolean _rv)")},
4237 {"CFPreferencesCopyApplicationList", (PyCFunction)CF_CFPreferencesCopyApplicationList, 1,
4238 PyDoc_STR("(CFStringRef userName, CFStringRef hostName) -> (CFArrayRef _rv)")},
4239 {"CFPreferencesCopyKeyList", (PyCFunction)CF_CFPreferencesCopyKeyList, 1,
4240 PyDoc_STR("(CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFArrayRef _rv)")},
4241 {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1,
4242 PyDoc_STR("() -> (CFTypeID _rv)")},
4243 {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1,
4244 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
4245 {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1,
4246 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
4247 {"CFStringCreateWithCharacters", (PyCFunction)CF_CFStringCreateWithCharacters, 1,
4248 PyDoc_STR("(Buffer chars) -> (CFStringRef _rv)")},
4249 {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1,
4250 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
4251 {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1,
4252 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
4253 {"CFStringCreateWithCharactersNoCopy", (PyCFunction)CF_CFStringCreateWithCharactersNoCopy, 1,
4254 PyDoc_STR("(Buffer chars) -> (CFStringRef _rv)")},
4255 {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1,
4256 PyDoc_STR("(CFIndex maxLength) -> (CFMutableStringRef _rv)")},
4257 {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1,
4258 PyDoc_STR("(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)")},
4259 {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1,
4260 PyDoc_STR("(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)")},
4261 {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1,
4262 PyDoc_STR("() -> (CFStringEncoding _rv)")},
4263 {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1,
4264 PyDoc_STR("(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)")},
4265 {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1,
4266 PyDoc_STR("(CFStringEncoding encoding) -> (Boolean _rv)")},
4267 {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1,
4268 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
4269 {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1,
4270 PyDoc_STR("(CFStringEncoding encoding) -> (UInt32 _rv)")},
4271 {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1,
4272 PyDoc_STR("(UInt32 encoding) -> (CFStringEncoding _rv)")},
4273 {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1,
4274 PyDoc_STR("(CFStringEncoding encoding) -> (UInt32 _rv)")},
4275 {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1,
4276 PyDoc_STR("(UInt32 codepage) -> (CFStringEncoding _rv)")},
4277 {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1,
4278 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
4279 {"CFStringGetMostCompatibleMacStringEncoding", (PyCFunction)CF_CFStringGetMostCompatibleMacStringEncoding, 1,
4280 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringEncoding _rv)")},
4281 {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1,
4282 PyDoc_STR("(char* cStr) -> (CFStringRef _rv)")},
4283 {"CFURLGetTypeID", (PyCFunction)CF_CFURLGetTypeID, 1,
4284 PyDoc_STR("() -> (CFTypeID _rv)")},
4285 {"CFURLCreateWithBytes", (PyCFunction)CF_CFURLCreateWithBytes, 1,
4286 PyDoc_STR("(Buffer URLBytes, CFStringEncoding encoding, CFURLRef baseURL) -> (CFURLRef _rv)")},
4287 {"CFURLCreateFromFileSystemRepresentation", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentation, 1,
4288 PyDoc_STR("(Buffer buffer, Boolean isDirectory) -> (CFURLRef _rv)")},
4289 {"CFURLCreateFromFileSystemRepresentationRelativeToBase", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentationRelativeToBase, 1,
4290 PyDoc_STR("(Buffer buffer, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)")},
4291 {"CFURLCreateFromFSRef", (PyCFunction)CF_CFURLCreateFromFSRef, 1,
4292 PyDoc_STR("(FSRef fsRef) -> (CFURLRef _rv)")},
4293 {"toCF", (PyCFunction)CF_toCF, 1,
4294 PyDoc_STR("(python_object) -> (CF_object)")},
4295 {NULL, NULL, 0}
4301 /* Routines to convert any CF type to/from the corresponding CFxxxObj */
4302 PyObject *CFObj_New(CFTypeRef itself)
4304 if (itself == NULL)
4306 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
4307 return NULL;
4309 if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself);
4310 if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself);
4311 if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself);
4312 if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself);
4313 if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself);
4314 /* XXXX Or should we use PyCF_CF2Python here?? */
4315 return CFTypeRefObj_New(itself);
4317 int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
4320 if (v == Py_None) { *p_itself = NULL; return 1; }
4321 /* Check for other CF objects here */
4323 if (!CFTypeRefObj_Check(v) &&
4324 !CFArrayRefObj_Check(v) &&
4325 !CFMutableArrayRefObj_Check(v) &&
4326 !CFDictionaryRefObj_Check(v) &&
4327 !CFMutableDictionaryRefObj_Check(v) &&
4328 !CFDataRefObj_Check(v) &&
4329 !CFMutableDataRefObj_Check(v) &&
4330 !CFStringRefObj_Check(v) &&
4331 !CFMutableStringRefObj_Check(v) &&
4332 !CFURLRefObj_Check(v) )
4334 /* XXXX Or should we use PyCF_Python2CF here?? */
4335 PyErr_SetString(PyExc_TypeError, "CF object required");
4336 return 0;
4338 *p_itself = ((CFTypeRefObject *)v)->ob_itself;
4339 return 1;
4343 void init_CF(void)
4345 PyObject *m;
4346 PyObject *d;
4350 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
4351 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
4352 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
4353 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
4354 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
4355 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
4357 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
4358 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
4359 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
4360 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
4361 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
4362 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
4363 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
4364 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
4365 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
4366 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
4367 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
4370 m = Py_InitModule("_CF", CF_methods);
4371 d = PyModule_GetDict(m);
4372 CF_Error = PyMac_GetOSErrException();
4373 if (CF_Error == NULL ||
4374 PyDict_SetItemString(d, "Error", CF_Error) != 0)
4375 return;
4376 CFTypeRef_Type.ob_type = &PyType_Type;
4377 if (PyType_Ready(&CFTypeRef_Type) < 0) return;
4378 Py_INCREF(&CFTypeRef_Type);
4379 PyModule_AddObject(m, "CFTypeRef", (PyObject *)&CFTypeRef_Type);
4380 /* Backward-compatible name */
4381 Py_INCREF(&CFTypeRef_Type);
4382 PyModule_AddObject(m, "CFTypeRefType", (PyObject *)&CFTypeRef_Type);
4383 CFArrayRef_Type.ob_type = &PyType_Type;
4384 if (PyType_Ready(&CFArrayRef_Type) < 0) return;
4385 Py_INCREF(&CFArrayRef_Type);
4386 PyModule_AddObject(m, "CFArrayRef", (PyObject *)&CFArrayRef_Type);
4387 /* Backward-compatible name */
4388 Py_INCREF(&CFArrayRef_Type);
4389 PyModule_AddObject(m, "CFArrayRefType", (PyObject *)&CFArrayRef_Type);
4390 CFMutableArrayRef_Type.ob_type = &PyType_Type;
4391 if (PyType_Ready(&CFMutableArrayRef_Type) < 0) return;
4392 Py_INCREF(&CFMutableArrayRef_Type);
4393 PyModule_AddObject(m, "CFMutableArrayRef", (PyObject *)&CFMutableArrayRef_Type);
4394 /* Backward-compatible name */
4395 Py_INCREF(&CFMutableArrayRef_Type);
4396 PyModule_AddObject(m, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type);
4397 CFDictionaryRef_Type.ob_type = &PyType_Type;
4398 if (PyType_Ready(&CFDictionaryRef_Type) < 0) return;
4399 Py_INCREF(&CFDictionaryRef_Type);
4400 PyModule_AddObject(m, "CFDictionaryRef", (PyObject *)&CFDictionaryRef_Type);
4401 /* Backward-compatible name */
4402 Py_INCREF(&CFDictionaryRef_Type);
4403 PyModule_AddObject(m, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type);
4404 CFMutableDictionaryRef_Type.ob_type = &PyType_Type;
4405 if (PyType_Ready(&CFMutableDictionaryRef_Type) < 0) return;
4406 Py_INCREF(&CFMutableDictionaryRef_Type);
4407 PyModule_AddObject(m, "CFMutableDictionaryRef", (PyObject *)&CFMutableDictionaryRef_Type);
4408 /* Backward-compatible name */
4409 Py_INCREF(&CFMutableDictionaryRef_Type);
4410 PyModule_AddObject(m, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type);
4411 CFDataRef_Type.ob_type = &PyType_Type;
4412 if (PyType_Ready(&CFDataRef_Type) < 0) return;
4413 Py_INCREF(&CFDataRef_Type);
4414 PyModule_AddObject(m, "CFDataRef", (PyObject *)&CFDataRef_Type);
4415 /* Backward-compatible name */
4416 Py_INCREF(&CFDataRef_Type);
4417 PyModule_AddObject(m, "CFDataRefType", (PyObject *)&CFDataRef_Type);
4418 CFMutableDataRef_Type.ob_type = &PyType_Type;
4419 if (PyType_Ready(&CFMutableDataRef_Type) < 0) return;
4420 Py_INCREF(&CFMutableDataRef_Type);
4421 PyModule_AddObject(m, "CFMutableDataRef", (PyObject *)&CFMutableDataRef_Type);
4422 /* Backward-compatible name */
4423 Py_INCREF(&CFMutableDataRef_Type);
4424 PyModule_AddObject(m, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type);
4425 CFStringRef_Type.ob_type = &PyType_Type;
4426 if (PyType_Ready(&CFStringRef_Type) < 0) return;
4427 Py_INCREF(&CFStringRef_Type);
4428 PyModule_AddObject(m, "CFStringRef", (PyObject *)&CFStringRef_Type);
4429 /* Backward-compatible name */
4430 Py_INCREF(&CFStringRef_Type);
4431 PyModule_AddObject(m, "CFStringRefType", (PyObject *)&CFStringRef_Type);
4432 CFMutableStringRef_Type.ob_type = &PyType_Type;
4433 if (PyType_Ready(&CFMutableStringRef_Type) < 0) return;
4434 Py_INCREF(&CFMutableStringRef_Type);
4435 PyModule_AddObject(m, "CFMutableStringRef", (PyObject *)&CFMutableStringRef_Type);
4436 /* Backward-compatible name */
4437 Py_INCREF(&CFMutableStringRef_Type);
4438 PyModule_AddObject(m, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type);
4439 CFURLRef_Type.ob_type = &PyType_Type;
4440 if (PyType_Ready(&CFURLRef_Type) < 0) return;
4441 Py_INCREF(&CFURLRef_Type);
4442 PyModule_AddObject(m, "CFURLRef", (PyObject *)&CFURLRef_Type);
4443 /* Backward-compatible name */
4444 Py_INCREF(&CFURLRef_Type);
4445 PyModule_AddObject(m, "CFURLRefType", (PyObject *)&CFURLRef_Type);
4447 #define _STRINGCONST(name) PyModule_AddObject(m, #name, CFStringRefObj_New(name))
4448 _STRINGCONST(kCFPreferencesAnyApplication);
4449 _STRINGCONST(kCFPreferencesCurrentApplication);
4450 _STRINGCONST(kCFPreferencesAnyHost);
4451 _STRINGCONST(kCFPreferencesCurrentHost);
4452 _STRINGCONST(kCFPreferencesAnyUser);
4453 _STRINGCONST(kCFPreferencesCurrentUser);
4459 /* ========================= End module _CF ========================= */