New \grammartoken markup, similar to \token but allowed everywhere.
[python/dscho.git] / Mac / Modules / cf / CFmodule.c
blob51b85fcecce5958582970de9df1381a1bf12561e
2 /* =========================== Module CF ============================ */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 /* Macro to test whether a weak-loaded CFM function exists */
12 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
13 PyErr_SetString(PyExc_NotImplementedError, \
14 "Not available in this shared library/OS version"); \
15 return NULL; \
16 }} while(0)
19 #ifdef WITHOUT_FRAMEWORKS
20 #include <CFBase.h>
21 #include <CFArray.h>
22 #include <CFData.h>
23 #include <CFDictionary.h>
24 #include <CFString.h>
25 #include <CFURL.h>
26 #else
27 #include <CoreServices/CoreServices.h>
28 #endif
30 /* For now we declare them forward here. They'll go to mactoolbox later */
31 staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
32 staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
33 staticforward PyObject *CFStringRefObj_New(CFStringRef);
34 staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
35 staticforward PyObject *CFURLRefObj_New(CFURLRef);
36 staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
38 staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
40 // ADD declarations
41 #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
42 //extern PyObject *_CFTypeRefObj_New(CFTypeRef);
43 //extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
45 //#define CFTypeRefObj_New _CFTypeRefObj_New
46 //#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
47 #endif
50 ** Parse/generate CFRange records
52 PyObject *CFRange_New(CFRange *itself)
55 return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
58 CFRange_Convert(PyObject *v, CFRange *p_itself)
60 long location, length;
62 if( !PyArg_ParseTuple(v, "ll", &location, &length) )
63 return 0;
64 p_itself->location = (CFIndex)location;
65 p_itself->length = (CFIndex)length;
66 return 1;
69 /* Optional CFURL argument or None (passed as NULL) */
70 int
71 OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
73 if ( v == Py_None ) {
74 p_itself = NULL;
75 return 1;
77 return CFURLRefObj_Convert(v, p_itself);
81 static PyObject *CF_Error;
83 /* --------------------- Object type CFTypeRef ---------------------- */
85 PyTypeObject CFTypeRef_Type;
87 #define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type)
89 typedef struct CFTypeRefObject {
90 PyObject_HEAD
91 CFTypeRef ob_itself;
92 void (*ob_freeit)(CFTypeRef ptr);
93 } CFTypeRefObject;
95 PyObject *CFTypeRefObj_New(CFTypeRef itself)
97 CFTypeRefObject *it;
98 if (itself == NULL) return PyMac_Error(resNotFound);
99 it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
100 if (it == NULL) return NULL;
101 it->ob_itself = itself;
102 it->ob_freeit = CFRelease;
103 return (PyObject *)it;
105 CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself)
108 if (v == Py_None) { *p_itself = NULL; return 1; }
109 /* Check for other CF objects here */
111 if (!CFTypeRefObj_Check(v))
113 PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
114 return 0;
116 *p_itself = ((CFTypeRefObject *)v)->ob_itself;
117 return 1;
120 static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
122 if (self->ob_freeit && self->ob_itself)
124 self->ob_freeit((CFTypeRef)self->ob_itself);
126 PyMem_DEL(self);
129 static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
131 PyObject *_res = NULL;
132 CFTypeID _rv;
133 PyMac_PRECHECK(CFGetTypeID);
134 if (!PyArg_ParseTuple(_args, ""))
135 return NULL;
136 _rv = CFGetTypeID(_self->ob_itself);
137 _res = Py_BuildValue("l",
138 _rv);
139 return _res;
142 static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
144 PyObject *_res = NULL;
145 CFTypeRef _rv;
146 PyMac_PRECHECK(CFRetain);
147 if (!PyArg_ParseTuple(_args, ""))
148 return NULL;
149 _rv = CFRetain(_self->ob_itself);
150 _res = Py_BuildValue("O&",
151 CFTypeRefObj_New, _rv);
152 return _res;
155 static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
157 PyObject *_res = NULL;
158 PyMac_PRECHECK(CFRelease);
159 if (!PyArg_ParseTuple(_args, ""))
160 return NULL;
161 CFRelease(_self->ob_itself);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
167 static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
169 PyObject *_res = NULL;
170 CFIndex _rv;
171 PyMac_PRECHECK(CFGetRetainCount);
172 if (!PyArg_ParseTuple(_args, ""))
173 return NULL;
174 _rv = CFGetRetainCount(_self->ob_itself);
175 _res = Py_BuildValue("l",
176 _rv);
177 return _res;
180 static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
182 PyObject *_res = NULL;
183 Boolean _rv;
184 CFTypeRef cf2;
185 PyMac_PRECHECK(CFEqual);
186 if (!PyArg_ParseTuple(_args, "O&",
187 CFTypeRefObj_Convert, &cf2))
188 return NULL;
189 _rv = CFEqual(_self->ob_itself,
190 cf2);
191 _res = Py_BuildValue("l",
192 _rv);
193 return _res;
196 static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
198 PyObject *_res = NULL;
199 CFHashCode _rv;
200 PyMac_PRECHECK(CFHash);
201 if (!PyArg_ParseTuple(_args, ""))
202 return NULL;
203 _rv = CFHash(_self->ob_itself);
204 _res = Py_BuildValue("l",
205 _rv);
206 return _res;
209 static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
211 PyObject *_res = NULL;
212 CFStringRef _rv;
213 PyMac_PRECHECK(CFCopyDescription);
214 if (!PyArg_ParseTuple(_args, ""))
215 return NULL;
216 _rv = CFCopyDescription(_self->ob_itself);
217 _res = Py_BuildValue("O&",
218 CFStringRefObj_New, _rv);
219 return _res;
222 static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
224 PyObject *_res = NULL;
225 PyMac_PRECHECK(CFShow);
226 if (!PyArg_ParseTuple(_args, ""))
227 return NULL;
228 CFShow(_self->ob_itself);
229 Py_INCREF(Py_None);
230 _res = Py_None;
231 return _res;
234 static PyMethodDef CFTypeRefObj_methods[] = {
235 {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
236 "() -> (CFTypeID _rv)"},
237 {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
238 "() -> (CFTypeRef _rv)"},
239 {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
240 "() -> None"},
241 {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
242 "() -> (CFIndex _rv)"},
243 {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
244 "(CFTypeRef cf2) -> (Boolean _rv)"},
245 {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
246 "() -> (CFHashCode _rv)"},
247 {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
248 "() -> (CFStringRef _rv)"},
249 {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
250 "() -> None"},
251 {NULL, NULL, 0}
254 PyMethodChain CFTypeRefObj_chain = { CFTypeRefObj_methods, NULL };
256 static PyObject *CFTypeRefObj_getattr(CFTypeRefObject *self, char *name)
258 return Py_FindMethodInChain(&CFTypeRefObj_chain, (PyObject *)self, name);
261 #define CFTypeRefObj_setattr NULL
263 static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other)
265 /* XXXX Or should we use CFEqual?? */
266 if ( self->ob_itself > other->ob_itself ) return 1;
267 if ( self->ob_itself < other->ob_itself ) return -1;
268 return 0;
271 static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
273 char buf[100];
274 sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);
275 return PyString_FromString(buf);
278 static int CFTypeRefObj_hash(CFTypeRefObject *self)
280 /* XXXX Or should we use CFHash?? */
281 return (int)self->ob_itself;
284 PyTypeObject CFTypeRef_Type = {
285 PyObject_HEAD_INIT(&PyType_Type)
286 0, /*ob_size*/
287 "CFTypeRef", /*tp_name*/
288 sizeof(CFTypeRefObject), /*tp_basicsize*/
289 0, /*tp_itemsize*/
290 /* methods */
291 (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
292 0, /*tp_print*/
293 (getattrfunc) CFTypeRefObj_getattr, /*tp_getattr*/
294 (setattrfunc) CFTypeRefObj_setattr, /*tp_setattr*/
295 (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
296 (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
297 (PyNumberMethods *)0, /* tp_as_number */
298 (PySequenceMethods *)0, /* tp_as_sequence */
299 (PyMappingMethods *)0, /* tp_as_mapping */
300 (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
303 /* ------------------- End object type CFTypeRef -------------------- */
306 /* --------------------- Object type CFArrayRef --------------------- */
308 PyTypeObject CFArrayRef_Type;
310 #define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type)
312 typedef struct CFArrayRefObject {
313 PyObject_HEAD
314 CFArrayRef ob_itself;
315 void (*ob_freeit)(CFTypeRef ptr);
316 } CFArrayRefObject;
318 PyObject *CFArrayRefObj_New(CFArrayRef itself)
320 CFArrayRefObject *it;
321 if (itself == NULL) return PyMac_Error(resNotFound);
322 it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
323 if (it == NULL) return NULL;
324 it->ob_itself = itself;
325 it->ob_freeit = CFRelease;
326 return (PyObject *)it;
328 CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself)
331 if (v == Py_None) { *p_itself = NULL; return 1; }
332 /* Check for other CF objects here */
334 if (!CFArrayRefObj_Check(v))
336 PyErr_SetString(PyExc_TypeError, "CFArrayRef required");
337 return 0;
339 *p_itself = ((CFArrayRefObject *)v)->ob_itself;
340 return 1;
343 static void CFArrayRefObj_dealloc(CFArrayRefObject *self)
345 if (self->ob_freeit && self->ob_itself)
347 self->ob_freeit((CFTypeRef)self->ob_itself);
349 PyMem_DEL(self);
352 static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
354 PyObject *_res = NULL;
355 CFArrayRef _rv;
356 if (!PyArg_ParseTuple(_args, ""))
357 return NULL;
358 _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
359 _self->ob_itself);
360 _res = Py_BuildValue("O&",
361 CFArrayRefObj_New, _rv);
362 return _res;
365 static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
367 PyObject *_res = NULL;
368 CFIndex _rv;
369 PyMac_PRECHECK(CFArrayGetCount);
370 if (!PyArg_ParseTuple(_args, ""))
371 return NULL;
372 _rv = CFArrayGetCount(_self->ob_itself);
373 _res = Py_BuildValue("l",
374 _rv);
375 return _res;
378 static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
380 PyObject *_res = NULL;
381 CFStringRef _rv;
382 CFStringRef separatorString;
383 if (!PyArg_ParseTuple(_args, "O&",
384 CFStringRefObj_Convert, &separatorString))
385 return NULL;
386 _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
387 _self->ob_itself,
388 separatorString);
389 _res = Py_BuildValue("O&",
390 CFStringRefObj_New, _rv);
391 return _res;
394 static PyMethodDef CFArrayRefObj_methods[] = {
395 {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
396 "() -> (CFArrayRef _rv)"},
397 {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
398 "() -> (CFIndex _rv)"},
399 {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
400 "(CFStringRef separatorString) -> (CFStringRef _rv)"},
401 {NULL, NULL, 0}
404 PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, &CFTypeRefObj_chain };
406 static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name)
408 return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name);
411 #define CFArrayRefObj_setattr NULL
413 static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other)
415 /* XXXX Or should we use CFEqual?? */
416 if ( self->ob_itself > other->ob_itself ) return 1;
417 if ( self->ob_itself < other->ob_itself ) return -1;
418 return 0;
421 static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
423 char buf[100];
424 sprintf(buf, "<CFArrayRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
425 return PyString_FromString(buf);
428 static int CFArrayRefObj_hash(CFArrayRefObject *self)
430 /* XXXX Or should we use CFHash?? */
431 return (int)self->ob_itself;
434 PyTypeObject CFArrayRef_Type = {
435 PyObject_HEAD_INIT(&PyType_Type)
436 0, /*ob_size*/
437 "CFArrayRef", /*tp_name*/
438 sizeof(CFArrayRefObject), /*tp_basicsize*/
439 0, /*tp_itemsize*/
440 /* methods */
441 (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
442 0, /*tp_print*/
443 (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/
444 (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/
445 (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/
446 (reprfunc) CFArrayRefObj_repr, /*tp_repr*/
447 (PyNumberMethods *)0, /* tp_as_number */
448 (PySequenceMethods *)0, /* tp_as_sequence */
449 (PyMappingMethods *)0, /* tp_as_mapping */
450 (hashfunc) CFArrayRefObj_hash, /*tp_hash*/
453 /* ------------------- End object type CFArrayRef ------------------- */
456 /* ----------------- Object type CFMutableArrayRef ------------------ */
458 PyTypeObject CFMutableArrayRef_Type;
460 #define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type)
462 typedef struct CFMutableArrayRefObject {
463 PyObject_HEAD
464 CFMutableArrayRef ob_itself;
465 void (*ob_freeit)(CFTypeRef ptr);
466 } CFMutableArrayRefObject;
468 PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself)
470 CFMutableArrayRefObject *it;
471 if (itself == NULL) return PyMac_Error(resNotFound);
472 it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
473 if (it == NULL) return NULL;
474 it->ob_itself = itself;
475 it->ob_freeit = CFRelease;
476 return (PyObject *)it;
478 CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself)
481 if (v == Py_None) { *p_itself = NULL; return 1; }
482 /* Check for other CF objects here */
484 if (!CFMutableArrayRefObj_Check(v))
486 PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required");
487 return 0;
489 *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself;
490 return 1;
493 static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self)
495 if (self->ob_freeit && self->ob_itself)
497 self->ob_freeit((CFTypeRef)self->ob_itself);
499 PyMem_DEL(self);
502 static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
504 PyObject *_res = NULL;
505 CFIndex idx;
506 PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
507 if (!PyArg_ParseTuple(_args, "l",
508 &idx))
509 return NULL;
510 CFArrayRemoveValueAtIndex(_self->ob_itself,
511 idx);
512 Py_INCREF(Py_None);
513 _res = Py_None;
514 return _res;
517 static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args)
519 PyObject *_res = NULL;
520 PyMac_PRECHECK(CFArrayRemoveAllValues);
521 if (!PyArg_ParseTuple(_args, ""))
522 return NULL;
523 CFArrayRemoveAllValues(_self->ob_itself);
524 Py_INCREF(Py_None);
525 _res = Py_None;
526 return _res;
529 static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args)
531 PyObject *_res = NULL;
532 CFIndex idx1;
533 CFIndex idx2;
534 PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
535 if (!PyArg_ParseTuple(_args, "ll",
536 &idx1,
537 &idx2))
538 return NULL;
539 CFArrayExchangeValuesAtIndices(_self->ob_itself,
540 idx1,
541 idx2);
542 Py_INCREF(Py_None);
543 _res = Py_None;
544 return _res;
547 static PyMethodDef CFMutableArrayRefObj_methods[] = {
548 {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
549 "(CFIndex idx) -> None"},
550 {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
551 "() -> None"},
552 {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
553 "(CFIndex idx1, CFIndex idx2) -> None"},
554 {NULL, NULL, 0}
557 PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, &CFArrayRefObj_chain };
559 static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name)
561 return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name);
564 #define CFMutableArrayRefObj_setattr NULL
566 static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other)
568 /* XXXX Or should we use CFEqual?? */
569 if ( self->ob_itself > other->ob_itself ) return 1;
570 if ( self->ob_itself < other->ob_itself ) return -1;
571 return 0;
574 static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
576 char buf[100];
577 sprintf(buf, "<CFMutableArrayRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
578 return PyString_FromString(buf);
581 static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
583 /* XXXX Or should we use CFHash?? */
584 return (int)self->ob_itself;
587 PyTypeObject CFMutableArrayRef_Type = {
588 PyObject_HEAD_INIT(&PyType_Type)
589 0, /*ob_size*/
590 "CFMutableArrayRef", /*tp_name*/
591 sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
592 0, /*tp_itemsize*/
593 /* methods */
594 (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
595 0, /*tp_print*/
596 (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/
597 (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/
598 (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/
599 (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/
600 (PyNumberMethods *)0, /* tp_as_number */
601 (PySequenceMethods *)0, /* tp_as_sequence */
602 (PyMappingMethods *)0, /* tp_as_mapping */
603 (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/
606 /* --------------- End object type CFMutableArrayRef ---------------- */
609 /* ------------------ Object type CFDictionaryRef ------------------- */
611 PyTypeObject CFDictionaryRef_Type;
613 #define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type)
615 typedef struct CFDictionaryRefObject {
616 PyObject_HEAD
617 CFDictionaryRef ob_itself;
618 void (*ob_freeit)(CFTypeRef ptr);
619 } CFDictionaryRefObject;
621 PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself)
623 CFDictionaryRefObject *it;
624 if (itself == NULL) return PyMac_Error(resNotFound);
625 it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
626 if (it == NULL) return NULL;
627 it->ob_itself = itself;
628 it->ob_freeit = CFRelease;
629 return (PyObject *)it;
631 CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself)
634 if (v == Py_None) { *p_itself = NULL; return 1; }
635 /* Check for other CF objects here */
637 if (!CFDictionaryRefObj_Check(v))
639 PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required");
640 return 0;
642 *p_itself = ((CFDictionaryRefObject *)v)->ob_itself;
643 return 1;
646 static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self)
648 if (self->ob_freeit && self->ob_itself)
650 self->ob_freeit((CFTypeRef)self->ob_itself);
652 PyMem_DEL(self);
655 static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
657 PyObject *_res = NULL;
658 CFDictionaryRef _rv;
659 if (!PyArg_ParseTuple(_args, ""))
660 return NULL;
661 _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
662 _self->ob_itself);
663 _res = Py_BuildValue("O&",
664 CFDictionaryRefObj_New, _rv);
665 return _res;
668 static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
670 PyObject *_res = NULL;
671 CFIndex _rv;
672 PyMac_PRECHECK(CFDictionaryGetCount);
673 if (!PyArg_ParseTuple(_args, ""))
674 return NULL;
675 _rv = CFDictionaryGetCount(_self->ob_itself);
676 _res = Py_BuildValue("l",
677 _rv);
678 return _res;
681 static PyMethodDef CFDictionaryRefObj_methods[] = {
682 {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
683 "() -> (CFDictionaryRef _rv)"},
684 {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
685 "() -> (CFIndex _rv)"},
686 {NULL, NULL, 0}
689 PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, &CFTypeRefObj_chain };
691 static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name)
693 return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name);
696 #define CFDictionaryRefObj_setattr NULL
698 static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other)
700 /* XXXX Or should we use CFEqual?? */
701 if ( self->ob_itself > other->ob_itself ) return 1;
702 if ( self->ob_itself < other->ob_itself ) return -1;
703 return 0;
706 static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
708 char buf[100];
709 sprintf(buf, "<CFDictionaryRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
710 return PyString_FromString(buf);
713 static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
715 /* XXXX Or should we use CFHash?? */
716 return (int)self->ob_itself;
719 PyTypeObject CFDictionaryRef_Type = {
720 PyObject_HEAD_INIT(&PyType_Type)
721 0, /*ob_size*/
722 "CFDictionaryRef", /*tp_name*/
723 sizeof(CFDictionaryRefObject), /*tp_basicsize*/
724 0, /*tp_itemsize*/
725 /* methods */
726 (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
727 0, /*tp_print*/
728 (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/
729 (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/
730 (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/
731 (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/
732 (PyNumberMethods *)0, /* tp_as_number */
733 (PySequenceMethods *)0, /* tp_as_sequence */
734 (PyMappingMethods *)0, /* tp_as_mapping */
735 (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/
738 /* ---------------- End object type CFDictionaryRef ----------------- */
741 /* --------------- Object type CFMutableDictionaryRef --------------- */
743 PyTypeObject CFMutableDictionaryRef_Type;
745 #define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type)
747 typedef struct CFMutableDictionaryRefObject {
748 PyObject_HEAD
749 CFMutableDictionaryRef ob_itself;
750 void (*ob_freeit)(CFTypeRef ptr);
751 } CFMutableDictionaryRefObject;
753 PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself)
755 CFMutableDictionaryRefObject *it;
756 if (itself == NULL) return PyMac_Error(resNotFound);
757 it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
758 if (it == NULL) return NULL;
759 it->ob_itself = itself;
760 it->ob_freeit = CFRelease;
761 return (PyObject *)it;
763 CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself)
766 if (v == Py_None) { *p_itself = NULL; return 1; }
767 /* Check for other CF objects here */
769 if (!CFMutableDictionaryRefObj_Check(v))
771 PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required");
772 return 0;
774 *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself;
775 return 1;
778 static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self)
780 if (self->ob_freeit && self->ob_itself)
782 self->ob_freeit((CFTypeRef)self->ob_itself);
784 PyMem_DEL(self);
787 static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
789 PyObject *_res = NULL;
790 PyMac_PRECHECK(CFDictionaryRemoveAllValues);
791 if (!PyArg_ParseTuple(_args, ""))
792 return NULL;
793 CFDictionaryRemoveAllValues(_self->ob_itself);
794 Py_INCREF(Py_None);
795 _res = Py_None;
796 return _res;
799 static PyMethodDef CFMutableDictionaryRefObj_methods[] = {
800 {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1,
801 "() -> None"},
802 {NULL, NULL, 0}
805 PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, &CFDictionaryRefObj_chain };
807 static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name)
809 return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name);
812 #define CFMutableDictionaryRefObj_setattr NULL
814 static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other)
816 /* XXXX Or should we use CFEqual?? */
817 if ( self->ob_itself > other->ob_itself ) return 1;
818 if ( self->ob_itself < other->ob_itself ) return -1;
819 return 0;
822 static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self)
824 char buf[100];
825 sprintf(buf, "<CFMutableDictionaryRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
826 return PyString_FromString(buf);
829 static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
831 /* XXXX Or should we use CFHash?? */
832 return (int)self->ob_itself;
835 PyTypeObject CFMutableDictionaryRef_Type = {
836 PyObject_HEAD_INIT(&PyType_Type)
837 0, /*ob_size*/
838 "CFMutableDictionaryRef", /*tp_name*/
839 sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
840 0, /*tp_itemsize*/
841 /* methods */
842 (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
843 0, /*tp_print*/
844 (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/
845 (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/
846 (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/
847 (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/
848 (PyNumberMethods *)0, /* tp_as_number */
849 (PySequenceMethods *)0, /* tp_as_sequence */
850 (PyMappingMethods *)0, /* tp_as_mapping */
851 (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/
854 /* ------------- End object type CFMutableDictionaryRef ------------- */
857 /* --------------------- Object type CFDataRef ---------------------- */
859 PyTypeObject CFDataRef_Type;
861 #define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type)
863 typedef struct CFDataRefObject {
864 PyObject_HEAD
865 CFDataRef ob_itself;
866 void (*ob_freeit)(CFTypeRef ptr);
867 } CFDataRefObject;
869 PyObject *CFDataRefObj_New(CFDataRef itself)
871 CFDataRefObject *it;
872 if (itself == NULL) return PyMac_Error(resNotFound);
873 it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
874 if (it == NULL) return NULL;
875 it->ob_itself = itself;
876 it->ob_freeit = CFRelease;
877 return (PyObject *)it;
879 CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
882 if (v == Py_None) { *p_itself = NULL; return 1; }
883 /* Check for other CF objects here */
885 if (!CFDataRefObj_Check(v))
887 PyErr_SetString(PyExc_TypeError, "CFDataRef required");
888 return 0;
890 *p_itself = ((CFDataRefObject *)v)->ob_itself;
891 return 1;
894 static void CFDataRefObj_dealloc(CFDataRefObject *self)
896 if (self->ob_freeit && self->ob_itself)
898 self->ob_freeit((CFTypeRef)self->ob_itself);
900 PyMem_DEL(self);
903 static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
905 PyObject *_res = NULL;
906 CFDataRef _rv;
907 if (!PyArg_ParseTuple(_args, ""))
908 return NULL;
909 _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
910 _self->ob_itself);
911 _res = Py_BuildValue("O&",
912 CFDataRefObj_New, _rv);
913 return _res;
916 static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
918 PyObject *_res = NULL;
919 CFIndex _rv;
920 PyMac_PRECHECK(CFDataGetLength);
921 if (!PyArg_ParseTuple(_args, ""))
922 return NULL;
923 _rv = CFDataGetLength(_self->ob_itself);
924 _res = Py_BuildValue("l",
925 _rv);
926 return _res;
929 static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
931 PyObject *_res = NULL;
932 CFStringRef _rv;
933 CFStringEncoding encoding;
934 if (!PyArg_ParseTuple(_args, "l",
935 &encoding))
936 return NULL;
937 _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
938 _self->ob_itself,
939 encoding);
940 _res = Py_BuildValue("O&",
941 CFStringRefObj_New, _rv);
942 return _res;
945 static PyMethodDef CFDataRefObj_methods[] = {
946 {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
947 "() -> (CFDataRef _rv)"},
948 {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
949 "() -> (CFIndex _rv)"},
950 {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
951 "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
952 {NULL, NULL, 0}
955 PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, &CFTypeRefObj_chain };
957 static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name)
959 return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name);
962 #define CFDataRefObj_setattr NULL
964 static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other)
966 /* XXXX Or should we use CFEqual?? */
967 if ( self->ob_itself > other->ob_itself ) return 1;
968 if ( self->ob_itself < other->ob_itself ) return -1;
969 return 0;
972 static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
974 char buf[100];
975 sprintf(buf, "<CFDataRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
976 return PyString_FromString(buf);
979 static int CFDataRefObj_hash(CFDataRefObject *self)
981 /* XXXX Or should we use CFHash?? */
982 return (int)self->ob_itself;
985 PyTypeObject CFDataRef_Type = {
986 PyObject_HEAD_INIT(&PyType_Type)
987 0, /*ob_size*/
988 "CFDataRef", /*tp_name*/
989 sizeof(CFDataRefObject), /*tp_basicsize*/
990 0, /*tp_itemsize*/
991 /* methods */
992 (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
993 0, /*tp_print*/
994 (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/
995 (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/
996 (cmpfunc) CFDataRefObj_compare, /*tp_compare*/
997 (reprfunc) CFDataRefObj_repr, /*tp_repr*/
998 (PyNumberMethods *)0, /* tp_as_number */
999 (PySequenceMethods *)0, /* tp_as_sequence */
1000 (PyMappingMethods *)0, /* tp_as_mapping */
1001 (hashfunc) CFDataRefObj_hash, /*tp_hash*/
1004 /* ------------------- End object type CFDataRef -------------------- */
1007 /* ------------------ Object type CFMutableDataRef ------------------ */
1009 PyTypeObject CFMutableDataRef_Type;
1011 #define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type)
1013 typedef struct CFMutableDataRefObject {
1014 PyObject_HEAD
1015 CFMutableDataRef ob_itself;
1016 void (*ob_freeit)(CFTypeRef ptr);
1017 } CFMutableDataRefObject;
1019 PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself)
1021 CFMutableDataRefObject *it;
1022 if (itself == NULL) return PyMac_Error(resNotFound);
1023 it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
1024 if (it == NULL) return NULL;
1025 it->ob_itself = itself;
1026 it->ob_freeit = CFRelease;
1027 return (PyObject *)it;
1029 CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself)
1032 if (v == Py_None) { *p_itself = NULL; return 1; }
1033 /* Check for other CF objects here */
1035 if (!CFMutableDataRefObj_Check(v))
1037 PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required");
1038 return 0;
1040 *p_itself = ((CFMutableDataRefObject *)v)->ob_itself;
1041 return 1;
1044 static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self)
1046 if (self->ob_freeit && self->ob_itself)
1048 self->ob_freeit((CFTypeRef)self->ob_itself);
1050 PyMem_DEL(self);
1053 static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
1055 PyObject *_res = NULL;
1056 CFIndex length;
1057 PyMac_PRECHECK(CFDataSetLength);
1058 if (!PyArg_ParseTuple(_args, "l",
1059 &length))
1060 return NULL;
1061 CFDataSetLength(_self->ob_itself,
1062 length);
1063 Py_INCREF(Py_None);
1064 _res = Py_None;
1065 return _res;
1068 static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args)
1070 PyObject *_res = NULL;
1071 CFIndex extraLength;
1072 PyMac_PRECHECK(CFDataIncreaseLength);
1073 if (!PyArg_ParseTuple(_args, "l",
1074 &extraLength))
1075 return NULL;
1076 CFDataIncreaseLength(_self->ob_itself,
1077 extraLength);
1078 Py_INCREF(Py_None);
1079 _res = Py_None;
1080 return _res;
1083 static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args)
1085 PyObject *_res = NULL;
1086 unsigned char *bytes__in__;
1087 long bytes__len__;
1088 int bytes__in_len__;
1089 PyMac_PRECHECK(CFDataAppendBytes);
1090 if (!PyArg_ParseTuple(_args, "s#",
1091 &bytes__in__, &bytes__in_len__))
1092 return NULL;
1093 bytes__len__ = bytes__in_len__;
1094 CFDataAppendBytes(_self->ob_itself,
1095 bytes__in__, bytes__len__);
1096 Py_INCREF(Py_None);
1097 _res = Py_None;
1098 bytes__error__: ;
1099 return _res;
1102 static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args)
1104 PyObject *_res = NULL;
1105 CFRange range;
1106 unsigned char *newBytes__in__;
1107 long newBytes__len__;
1108 int newBytes__in_len__;
1109 PyMac_PRECHECK(CFDataReplaceBytes);
1110 if (!PyArg_ParseTuple(_args, "O&s#",
1111 CFRange_Convert, &range,
1112 &newBytes__in__, &newBytes__in_len__))
1113 return NULL;
1114 newBytes__len__ = newBytes__in_len__;
1115 CFDataReplaceBytes(_self->ob_itself,
1116 range,
1117 newBytes__in__, newBytes__len__);
1118 Py_INCREF(Py_None);
1119 _res = Py_None;
1120 newBytes__error__: ;
1121 return _res;
1124 static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
1126 PyObject *_res = NULL;
1127 CFRange range;
1128 PyMac_PRECHECK(CFDataDeleteBytes);
1129 if (!PyArg_ParseTuple(_args, "O&",
1130 CFRange_Convert, &range))
1131 return NULL;
1132 CFDataDeleteBytes(_self->ob_itself,
1133 range);
1134 Py_INCREF(Py_None);
1135 _res = Py_None;
1136 return _res;
1139 static PyMethodDef CFMutableDataRefObj_methods[] = {
1140 {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1,
1141 "(CFIndex length) -> None"},
1142 {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
1143 "(CFIndex extraLength) -> None"},
1144 {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
1145 "(Buffer bytes) -> None"},
1146 {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
1147 "(CFRange range, Buffer newBytes) -> None"},
1148 {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
1149 "(CFRange range) -> None"},
1150 {NULL, NULL, 0}
1153 PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, &CFDataRefObj_chain };
1155 static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name)
1157 return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name);
1160 #define CFMutableDataRefObj_setattr NULL
1162 static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other)
1164 /* XXXX Or should we use CFEqual?? */
1165 if ( self->ob_itself > other->ob_itself ) return 1;
1166 if ( self->ob_itself < other->ob_itself ) return -1;
1167 return 0;
1170 static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
1172 char buf[100];
1173 sprintf(buf, "<CFMutableDataRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
1174 return PyString_FromString(buf);
1177 static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
1179 /* XXXX Or should we use CFHash?? */
1180 return (int)self->ob_itself;
1183 PyTypeObject CFMutableDataRef_Type = {
1184 PyObject_HEAD_INIT(&PyType_Type)
1185 0, /*ob_size*/
1186 "CFMutableDataRef", /*tp_name*/
1187 sizeof(CFMutableDataRefObject), /*tp_basicsize*/
1188 0, /*tp_itemsize*/
1189 /* methods */
1190 (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/
1191 0, /*tp_print*/
1192 (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/
1193 (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/
1194 (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/
1195 (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/
1196 (PyNumberMethods *)0, /* tp_as_number */
1197 (PySequenceMethods *)0, /* tp_as_sequence */
1198 (PyMappingMethods *)0, /* tp_as_mapping */
1199 (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/
1202 /* ---------------- End object type CFMutableDataRef ---------------- */
1205 /* -------------------- Object type CFStringRef --------------------- */
1207 PyTypeObject CFStringRef_Type;
1209 #define CFStringRefObj_Check(x) ((x)->ob_type == &CFStringRef_Type)
1211 typedef struct CFStringRefObject {
1212 PyObject_HEAD
1213 CFStringRef ob_itself;
1214 void (*ob_freeit)(CFTypeRef ptr);
1215 } CFStringRefObject;
1217 PyObject *CFStringRefObj_New(CFStringRef itself)
1219 CFStringRefObject *it;
1220 if (itself == NULL) return PyMac_Error(resNotFound);
1221 it = PyObject_NEW(CFStringRefObject, &CFStringRef_Type);
1222 if (it == NULL) return NULL;
1223 it->ob_itself = itself;
1224 it->ob_freeit = CFRelease;
1225 return (PyObject *)it;
1227 CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
1230 if (v == Py_None) { *p_itself = NULL; return 1; }
1231 if (PyString_Check(v)) {
1232 char *cStr = PyString_AsString(v);
1233 *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
1234 return 1;
1236 if (PyUnicode_Check(v)) {
1237 /* We use the CF types here, if Python was configured differently that will give an error */
1238 CFIndex size = PyUnicode_GetSize(v);
1239 UniChar *unichars = PyUnicode_AsUnicode(v);
1240 if (!unichars) return 0;
1241 *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
1242 return 1;
1246 if (!CFStringRefObj_Check(v))
1248 PyErr_SetString(PyExc_TypeError, "CFStringRef required");
1249 return 0;
1251 *p_itself = ((CFStringRefObject *)v)->ob_itself;
1252 return 1;
1255 static void CFStringRefObj_dealloc(CFStringRefObject *self)
1257 if (self->ob_freeit && self->ob_itself)
1259 self->ob_freeit((CFTypeRef)self->ob_itself);
1261 PyMem_DEL(self);
1264 static PyObject *CFStringRefObj_CFStringCreateWithSubstring(CFStringRefObject *_self, PyObject *_args)
1266 PyObject *_res = NULL;
1267 CFStringRef _rv;
1268 CFRange range;
1269 if (!PyArg_ParseTuple(_args, "O&",
1270 CFRange_Convert, &range))
1271 return NULL;
1272 _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL,
1273 _self->ob_itself,
1274 range);
1275 _res = Py_BuildValue("O&",
1276 CFStringRefObj_New, _rv);
1277 return _res;
1280 static PyObject *CFStringRefObj_CFStringCreateCopy(CFStringRefObject *_self, PyObject *_args)
1282 PyObject *_res = NULL;
1283 CFStringRef _rv;
1284 if (!PyArg_ParseTuple(_args, ""))
1285 return NULL;
1286 _rv = CFStringCreateCopy((CFAllocatorRef)NULL,
1287 _self->ob_itself);
1288 _res = Py_BuildValue("O&",
1289 CFStringRefObj_New, _rv);
1290 return _res;
1293 static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args)
1295 PyObject *_res = NULL;
1296 CFIndex _rv;
1297 PyMac_PRECHECK(CFStringGetLength);
1298 if (!PyArg_ParseTuple(_args, ""))
1299 return NULL;
1300 _rv = CFStringGetLength(_self->ob_itself);
1301 _res = Py_BuildValue("l",
1302 _rv);
1303 return _res;
1306 static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args)
1308 PyObject *_res = NULL;
1309 CFIndex _rv;
1310 CFRange range;
1311 CFStringEncoding encoding;
1312 UInt8 lossByte;
1313 Boolean isExternalRepresentation;
1314 UInt8 buffer;
1315 CFIndex maxBufLen;
1316 CFIndex usedBufLen;
1317 PyMac_PRECHECK(CFStringGetBytes);
1318 if (!PyArg_ParseTuple(_args, "O&lbll",
1319 CFRange_Convert, &range,
1320 &encoding,
1321 &lossByte,
1322 &isExternalRepresentation,
1323 &maxBufLen))
1324 return NULL;
1325 _rv = CFStringGetBytes(_self->ob_itself,
1326 range,
1327 encoding,
1328 lossByte,
1329 isExternalRepresentation,
1330 &buffer,
1331 maxBufLen,
1332 &usedBufLen);
1333 _res = Py_BuildValue("lbl",
1334 _rv,
1335 buffer,
1336 usedBufLen);
1337 return _res;
1340 static PyObject *CFStringRefObj_CFStringCreateExternalRepresentation(CFStringRefObject *_self, PyObject *_args)
1342 PyObject *_res = NULL;
1343 CFDataRef _rv;
1344 CFStringEncoding encoding;
1345 UInt8 lossByte;
1346 if (!PyArg_ParseTuple(_args, "lb",
1347 &encoding,
1348 &lossByte))
1349 return NULL;
1350 _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL,
1351 _self->ob_itself,
1352 encoding,
1353 lossByte);
1354 _res = Py_BuildValue("O&",
1355 CFDataRefObj_New, _rv);
1356 return _res;
1359 static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args)
1361 PyObject *_res = NULL;
1362 CFStringEncoding _rv;
1363 PyMac_PRECHECK(CFStringGetSmallestEncoding);
1364 if (!PyArg_ParseTuple(_args, ""))
1365 return NULL;
1366 _rv = CFStringGetSmallestEncoding(_self->ob_itself);
1367 _res = Py_BuildValue("l",
1368 _rv);
1369 return _res;
1372 static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args)
1374 PyObject *_res = NULL;
1375 CFStringEncoding _rv;
1376 PyMac_PRECHECK(CFStringGetFastestEncoding);
1377 if (!PyArg_ParseTuple(_args, ""))
1378 return NULL;
1379 _rv = CFStringGetFastestEncoding(_self->ob_itself);
1380 _res = Py_BuildValue("l",
1381 _rv);
1382 return _res;
1385 static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args)
1387 PyObject *_res = NULL;
1388 CFComparisonResult _rv;
1389 CFStringRef string2;
1390 CFRange rangeToCompare;
1391 CFOptionFlags compareOptions;
1392 PyMac_PRECHECK(CFStringCompareWithOptions);
1393 if (!PyArg_ParseTuple(_args, "O&O&l",
1394 CFStringRefObj_Convert, &string2,
1395 CFRange_Convert, &rangeToCompare,
1396 &compareOptions))
1397 return NULL;
1398 _rv = CFStringCompareWithOptions(_self->ob_itself,
1399 string2,
1400 rangeToCompare,
1401 compareOptions);
1402 _res = Py_BuildValue("l",
1403 _rv);
1404 return _res;
1407 static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args)
1409 PyObject *_res = NULL;
1410 CFComparisonResult _rv;
1411 CFStringRef string2;
1412 CFOptionFlags compareOptions;
1413 PyMac_PRECHECK(CFStringCompare);
1414 if (!PyArg_ParseTuple(_args, "O&l",
1415 CFStringRefObj_Convert, &string2,
1416 &compareOptions))
1417 return NULL;
1418 _rv = CFStringCompare(_self->ob_itself,
1419 string2,
1420 compareOptions);
1421 _res = Py_BuildValue("l",
1422 _rv);
1423 return _res;
1426 static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args)
1428 PyObject *_res = NULL;
1429 Boolean _rv;
1430 CFStringRef stringToFind;
1431 CFRange rangeToSearch;
1432 CFOptionFlags searchOptions;
1433 CFRange result;
1434 PyMac_PRECHECK(CFStringFindWithOptions);
1435 if (!PyArg_ParseTuple(_args, "O&O&l",
1436 CFStringRefObj_Convert, &stringToFind,
1437 CFRange_Convert, &rangeToSearch,
1438 &searchOptions))
1439 return NULL;
1440 _rv = CFStringFindWithOptions(_self->ob_itself,
1441 stringToFind,
1442 rangeToSearch,
1443 searchOptions,
1444 &result);
1445 _res = Py_BuildValue("lO&",
1446 _rv,
1447 CFRange_New, result);
1448 return _res;
1451 static PyObject *CFStringRefObj_CFStringCreateArrayWithFindResults(CFStringRefObject *_self, PyObject *_args)
1453 PyObject *_res = NULL;
1454 CFArrayRef _rv;
1455 CFStringRef stringToFind;
1456 CFRange rangeToSearch;
1457 CFOptionFlags compareOptions;
1458 if (!PyArg_ParseTuple(_args, "O&O&l",
1459 CFStringRefObj_Convert, &stringToFind,
1460 CFRange_Convert, &rangeToSearch,
1461 &compareOptions))
1462 return NULL;
1463 _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL,
1464 _self->ob_itself,
1465 stringToFind,
1466 rangeToSearch,
1467 compareOptions);
1468 _res = Py_BuildValue("O&",
1469 CFArrayRefObj_New, _rv);
1470 return _res;
1473 static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args)
1475 PyObject *_res = NULL;
1476 CFRange _rv;
1477 CFStringRef stringToFind;
1478 CFOptionFlags compareOptions;
1479 PyMac_PRECHECK(CFStringFind);
1480 if (!PyArg_ParseTuple(_args, "O&l",
1481 CFStringRefObj_Convert, &stringToFind,
1482 &compareOptions))
1483 return NULL;
1484 _rv = CFStringFind(_self->ob_itself,
1485 stringToFind,
1486 compareOptions);
1487 _res = Py_BuildValue("O&",
1488 CFRange_New, _rv);
1489 return _res;
1492 static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args)
1494 PyObject *_res = NULL;
1495 Boolean _rv;
1496 CFStringRef prefix;
1497 PyMac_PRECHECK(CFStringHasPrefix);
1498 if (!PyArg_ParseTuple(_args, "O&",
1499 CFStringRefObj_Convert, &prefix))
1500 return NULL;
1501 _rv = CFStringHasPrefix(_self->ob_itself,
1502 prefix);
1503 _res = Py_BuildValue("l",
1504 _rv);
1505 return _res;
1508 static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args)
1510 PyObject *_res = NULL;
1511 Boolean _rv;
1512 CFStringRef suffix;
1513 PyMac_PRECHECK(CFStringHasSuffix);
1514 if (!PyArg_ParseTuple(_args, "O&",
1515 CFStringRefObj_Convert, &suffix))
1516 return NULL;
1517 _rv = CFStringHasSuffix(_self->ob_itself,
1518 suffix);
1519 _res = Py_BuildValue("l",
1520 _rv);
1521 return _res;
1524 static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args)
1526 PyObject *_res = NULL;
1527 CFRange range;
1528 CFIndex lineBeginIndex;
1529 CFIndex lineEndIndex;
1530 CFIndex contentsEndIndex;
1531 PyMac_PRECHECK(CFStringGetLineBounds);
1532 if (!PyArg_ParseTuple(_args, "O&",
1533 CFRange_Convert, &range))
1534 return NULL;
1535 CFStringGetLineBounds(_self->ob_itself,
1536 range,
1537 &lineBeginIndex,
1538 &lineEndIndex,
1539 &contentsEndIndex);
1540 _res = Py_BuildValue("lll",
1541 lineBeginIndex,
1542 lineEndIndex,
1543 contentsEndIndex);
1544 return _res;
1547 static PyObject *CFStringRefObj_CFStringCreateArrayBySeparatingStrings(CFStringRefObject *_self, PyObject *_args)
1549 PyObject *_res = NULL;
1550 CFArrayRef _rv;
1551 CFStringRef separatorString;
1552 if (!PyArg_ParseTuple(_args, "O&",
1553 CFStringRefObj_Convert, &separatorString))
1554 return NULL;
1555 _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL,
1556 _self->ob_itself,
1557 separatorString);
1558 _res = Py_BuildValue("O&",
1559 CFArrayRefObj_New, _rv);
1560 return _res;
1563 static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args)
1565 PyObject *_res = NULL;
1566 SInt32 _rv;
1567 PyMac_PRECHECK(CFStringGetIntValue);
1568 if (!PyArg_ParseTuple(_args, ""))
1569 return NULL;
1570 _rv = CFStringGetIntValue(_self->ob_itself);
1571 _res = Py_BuildValue("l",
1572 _rv);
1573 return _res;
1576 static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args)
1578 PyObject *_res = NULL;
1579 double _rv;
1580 PyMac_PRECHECK(CFStringGetDoubleValue);
1581 if (!PyArg_ParseTuple(_args, ""))
1582 return NULL;
1583 _rv = CFStringGetDoubleValue(_self->ob_itself);
1584 _res = Py_BuildValue("d",
1585 _rv);
1586 return _res;
1589 static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args)
1591 PyObject *_res = NULL;
1592 CFStringEncoding _rv;
1593 PyMac_PRECHECK(CFStringConvertIANACharSetNameToEncoding);
1594 if (!PyArg_ParseTuple(_args, ""))
1595 return NULL;
1596 _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself);
1597 _res = Py_BuildValue("l",
1598 _rv);
1599 return _res;
1602 static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args)
1604 PyObject *_res = NULL;
1605 PyMac_PRECHECK(CFShowStr);
1606 if (!PyArg_ParseTuple(_args, ""))
1607 return NULL;
1608 CFShowStr(_self->ob_itself);
1609 Py_INCREF(Py_None);
1610 _res = Py_None;
1611 return _res;
1614 static PyObject *CFStringRefObj_CFURLCreateWithString(CFStringRefObject *_self, PyObject *_args)
1616 PyObject *_res = NULL;
1617 CFURLRef _rv;
1618 CFURLRef baseURL;
1619 if (!PyArg_ParseTuple(_args, "O&",
1620 OptionalCFURLRefObj_Convert, &baseURL))
1621 return NULL;
1622 _rv = CFURLCreateWithString((CFAllocatorRef)NULL,
1623 _self->ob_itself,
1624 baseURL);
1625 _res = Py_BuildValue("O&",
1626 CFURLRefObj_New, _rv);
1627 return _res;
1630 static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPath(CFStringRefObject *_self, PyObject *_args)
1632 PyObject *_res = NULL;
1633 CFURLRef _rv;
1634 CFURLPathStyle pathStyle;
1635 Boolean isDirectory;
1636 if (!PyArg_ParseTuple(_args, "ll",
1637 &pathStyle,
1638 &isDirectory))
1639 return NULL;
1640 _rv = CFURLCreateWithFileSystemPath((CFAllocatorRef)NULL,
1641 _self->ob_itself,
1642 pathStyle,
1643 isDirectory);
1644 _res = Py_BuildValue("O&",
1645 CFURLRefObj_New, _rv);
1646 return _res;
1649 static PyObject *CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
1651 PyObject *_res = NULL;
1652 CFStringRef _rv;
1653 CFStringRef charactersToLeaveEscaped;
1654 if (!PyArg_ParseTuple(_args, "O&",
1655 CFStringRefObj_Convert, &charactersToLeaveEscaped))
1656 return NULL;
1657 _rv = CFURLCreateStringByReplacingPercentEscapes((CFAllocatorRef)NULL,
1658 _self->ob_itself,
1659 charactersToLeaveEscaped);
1660 _res = Py_BuildValue("O&",
1661 CFStringRefObj_New, _rv);
1662 return _res;
1665 static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyObject *_args)
1667 PyObject *_res = NULL;
1669 int size = CFStringGetLength(_self->ob_itself)+1;
1670 char *data = malloc(size);
1672 if( data == NULL ) return PyErr_NoMemory();
1673 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
1674 _res = (PyObject *)PyString_FromString(data);
1675 } else {
1676 PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
1677 _res = NULL;
1679 free(data);
1680 return _res;
1684 static PyObject *CFStringRefObj_CFStringGetUnicode(CFStringRefObject *_self, PyObject *_args)
1686 PyObject *_res = NULL;
1688 int size = CFStringGetLength(_self->ob_itself)+1;
1689 Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
1690 CFRange range;
1692 range.location = 0;
1693 range.length = size;
1694 if( data == NULL ) return PyErr_NoMemory();
1695 CFStringGetCharacters(_self->ob_itself, range, data);
1696 _res = (PyObject *)PyUnicode_FromUnicode(data, size);
1697 free(data);
1698 return _res;
1702 static PyMethodDef CFStringRefObj_methods[] = {
1703 {"CFStringCreateWithSubstring", (PyCFunction)CFStringRefObj_CFStringCreateWithSubstring, 1,
1704 "(CFRange range) -> (CFStringRef _rv)"},
1705 {"CFStringCreateCopy", (PyCFunction)CFStringRefObj_CFStringCreateCopy, 1,
1706 "() -> (CFStringRef _rv)"},
1707 {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1,
1708 "() -> (CFIndex _rv)"},
1709 {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1,
1710 "(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)"},
1711 {"CFStringCreateExternalRepresentation", (PyCFunction)CFStringRefObj_CFStringCreateExternalRepresentation, 1,
1712 "(CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)"},
1713 {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1,
1714 "() -> (CFStringEncoding _rv)"},
1715 {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1,
1716 "() -> (CFStringEncoding _rv)"},
1717 {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1,
1718 "(CFStringRef string2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"},
1719 {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1,
1720 "(CFStringRef string2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"},
1721 {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1,
1722 "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)"},
1723 {"CFStringCreateArrayWithFindResults", (PyCFunction)CFStringRefObj_CFStringCreateArrayWithFindResults, 1,
1724 "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)"},
1725 {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1,
1726 "(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)"},
1727 {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1,
1728 "(CFStringRef prefix) -> (Boolean _rv)"},
1729 {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1,
1730 "(CFStringRef suffix) -> (Boolean _rv)"},
1731 {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1,
1732 "(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)"},
1733 {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CFStringRefObj_CFStringCreateArrayBySeparatingStrings, 1,
1734 "(CFStringRef separatorString) -> (CFArrayRef _rv)"},
1735 {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1,
1736 "() -> (SInt32 _rv)"},
1737 {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1,
1738 "() -> (double _rv)"},
1739 {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1,
1740 "() -> (CFStringEncoding _rv)"},
1741 {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1,
1742 "() -> None"},
1743 {"CFURLCreateWithString", (PyCFunction)CFStringRefObj_CFURLCreateWithString, 1,
1744 "(CFURLRef baseURL) -> (CFURLRef _rv)"},
1745 {"CFURLCreateWithFileSystemPath", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPath, 1,
1746 "(CFURLPathStyle pathStyle, Boolean isDirectory) -> (CFURLRef _rv)"},
1747 {"CFURLCreateStringByReplacingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes, 1,
1748 "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
1749 {"CFStringGetString", (PyCFunction)CFStringRefObj_CFStringGetString, 1,
1750 "() -> (string _rv)"},
1751 {"CFStringGetUnicode", (PyCFunction)CFStringRefObj_CFStringGetUnicode, 1,
1752 "() -> (unicode _rv)"},
1753 {NULL, NULL, 0}
1756 PyMethodChain CFStringRefObj_chain = { CFStringRefObj_methods, &CFTypeRefObj_chain };
1758 static PyObject *CFStringRefObj_getattr(CFStringRefObject *self, char *name)
1760 return Py_FindMethodInChain(&CFStringRefObj_chain, (PyObject *)self, name);
1763 #define CFStringRefObj_setattr NULL
1765 static int CFStringRefObj_compare(CFStringRefObject *self, CFStringRefObject *other)
1767 /* XXXX Or should we use CFEqual?? */
1768 if ( self->ob_itself > other->ob_itself ) return 1;
1769 if ( self->ob_itself < other->ob_itself ) return -1;
1770 return 0;
1773 static PyObject * CFStringRefObj_repr(CFStringRefObject *self)
1775 char buf[100];
1776 sprintf(buf, "<CFStringRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
1777 return PyString_FromString(buf);
1780 static int CFStringRefObj_hash(CFStringRefObject *self)
1782 /* XXXX Or should we use CFHash?? */
1783 return (int)self->ob_itself;
1786 PyTypeObject CFStringRef_Type = {
1787 PyObject_HEAD_INIT(&PyType_Type)
1788 0, /*ob_size*/
1789 "CFStringRef", /*tp_name*/
1790 sizeof(CFStringRefObject), /*tp_basicsize*/
1791 0, /*tp_itemsize*/
1792 /* methods */
1793 (destructor) CFStringRefObj_dealloc, /*tp_dealloc*/
1794 0, /*tp_print*/
1795 (getattrfunc) CFStringRefObj_getattr, /*tp_getattr*/
1796 (setattrfunc) CFStringRefObj_setattr, /*tp_setattr*/
1797 (cmpfunc) CFStringRefObj_compare, /*tp_compare*/
1798 (reprfunc) CFStringRefObj_repr, /*tp_repr*/
1799 (PyNumberMethods *)0, /* tp_as_number */
1800 (PySequenceMethods *)0, /* tp_as_sequence */
1801 (PyMappingMethods *)0, /* tp_as_mapping */
1802 (hashfunc) CFStringRefObj_hash, /*tp_hash*/
1805 /* ------------------ End object type CFStringRef ------------------- */
1808 /* ----------------- Object type CFMutableStringRef ----------------- */
1810 PyTypeObject CFMutableStringRef_Type;
1812 #define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type)
1814 typedef struct CFMutableStringRefObject {
1815 PyObject_HEAD
1816 CFMutableStringRef ob_itself;
1817 void (*ob_freeit)(CFTypeRef ptr);
1818 } CFMutableStringRefObject;
1820 PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself)
1822 CFMutableStringRefObject *it;
1823 if (itself == NULL) return PyMac_Error(resNotFound);
1824 it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type);
1825 if (it == NULL) return NULL;
1826 it->ob_itself = itself;
1827 it->ob_freeit = CFRelease;
1828 return (PyObject *)it;
1830 CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself)
1833 if (v == Py_None) { *p_itself = NULL; return 1; }
1834 /* Check for other CF objects here */
1836 if (!CFMutableStringRefObj_Check(v))
1838 PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required");
1839 return 0;
1841 *p_itself = ((CFMutableStringRefObject *)v)->ob_itself;
1842 return 1;
1845 static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self)
1847 if (self->ob_freeit && self->ob_itself)
1849 self->ob_freeit((CFTypeRef)self->ob_itself);
1851 PyMem_DEL(self);
1854 static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args)
1856 PyObject *_res = NULL;
1857 CFStringRef appendedString;
1858 PyMac_PRECHECK(CFStringAppend);
1859 if (!PyArg_ParseTuple(_args, "O&",
1860 CFStringRefObj_Convert, &appendedString))
1861 return NULL;
1862 CFStringAppend(_self->ob_itself,
1863 appendedString);
1864 Py_INCREF(Py_None);
1865 _res = Py_None;
1866 return _res;
1869 static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args)
1871 PyObject *_res = NULL;
1872 StringPtr pStr;
1873 CFStringEncoding encoding;
1874 PyMac_PRECHECK(CFStringAppendPascalString);
1875 if (!PyArg_ParseTuple(_args, "O&l",
1876 PyMac_GetStr255, &pStr,
1877 &encoding))
1878 return NULL;
1879 CFStringAppendPascalString(_self->ob_itself,
1880 pStr,
1881 encoding);
1882 Py_INCREF(Py_None);
1883 _res = Py_None;
1884 return _res;
1887 static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args)
1889 PyObject *_res = NULL;
1890 char* cStr;
1891 CFStringEncoding encoding;
1892 PyMac_PRECHECK(CFStringAppendCString);
1893 if (!PyArg_ParseTuple(_args, "sl",
1894 &cStr,
1895 &encoding))
1896 return NULL;
1897 CFStringAppendCString(_self->ob_itself,
1898 cStr,
1899 encoding);
1900 Py_INCREF(Py_None);
1901 _res = Py_None;
1902 return _res;
1905 static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args)
1907 PyObject *_res = NULL;
1908 CFIndex idx;
1909 CFStringRef insertedStr;
1910 PyMac_PRECHECK(CFStringInsert);
1911 if (!PyArg_ParseTuple(_args, "lO&",
1912 &idx,
1913 CFStringRefObj_Convert, &insertedStr))
1914 return NULL;
1915 CFStringInsert(_self->ob_itself,
1916 idx,
1917 insertedStr);
1918 Py_INCREF(Py_None);
1919 _res = Py_None;
1920 return _res;
1923 static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args)
1925 PyObject *_res = NULL;
1926 CFRange range;
1927 PyMac_PRECHECK(CFStringDelete);
1928 if (!PyArg_ParseTuple(_args, "O&",
1929 CFRange_Convert, &range))
1930 return NULL;
1931 CFStringDelete(_self->ob_itself,
1932 range);
1933 Py_INCREF(Py_None);
1934 _res = Py_None;
1935 return _res;
1938 static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args)
1940 PyObject *_res = NULL;
1941 CFRange range;
1942 CFStringRef replacement;
1943 PyMac_PRECHECK(CFStringReplace);
1944 if (!PyArg_ParseTuple(_args, "O&O&",
1945 CFRange_Convert, &range,
1946 CFStringRefObj_Convert, &replacement))
1947 return NULL;
1948 CFStringReplace(_self->ob_itself,
1949 range,
1950 replacement);
1951 Py_INCREF(Py_None);
1952 _res = Py_None;
1953 return _res;
1956 static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args)
1958 PyObject *_res = NULL;
1959 CFStringRef replacement;
1960 PyMac_PRECHECK(CFStringReplaceAll);
1961 if (!PyArg_ParseTuple(_args, "O&",
1962 CFStringRefObj_Convert, &replacement))
1963 return NULL;
1964 CFStringReplaceAll(_self->ob_itself,
1965 replacement);
1966 Py_INCREF(Py_None);
1967 _res = Py_None;
1968 return _res;
1971 static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args)
1973 PyObject *_res = NULL;
1974 CFStringRef padString;
1975 CFIndex length;
1976 CFIndex indexIntoPad;
1977 PyMac_PRECHECK(CFStringPad);
1978 if (!PyArg_ParseTuple(_args, "O&ll",
1979 CFStringRefObj_Convert, &padString,
1980 &length,
1981 &indexIntoPad))
1982 return NULL;
1983 CFStringPad(_self->ob_itself,
1984 padString,
1985 length,
1986 indexIntoPad);
1987 Py_INCREF(Py_None);
1988 _res = Py_None;
1989 return _res;
1992 static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args)
1994 PyObject *_res = NULL;
1995 CFStringRef trimString;
1996 PyMac_PRECHECK(CFStringTrim);
1997 if (!PyArg_ParseTuple(_args, "O&",
1998 CFStringRefObj_Convert, &trimString))
1999 return NULL;
2000 CFStringTrim(_self->ob_itself,
2001 trimString);
2002 Py_INCREF(Py_None);
2003 _res = Py_None;
2004 return _res;
2007 static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args)
2009 PyObject *_res = NULL;
2010 PyMac_PRECHECK(CFStringTrimWhitespace);
2011 if (!PyArg_ParseTuple(_args, ""))
2012 return NULL;
2013 CFStringTrimWhitespace(_self->ob_itself);
2014 Py_INCREF(Py_None);
2015 _res = Py_None;
2016 return _res;
2019 static PyMethodDef CFMutableStringRefObj_methods[] = {
2020 {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1,
2021 "(CFStringRef appendedString) -> None"},
2022 {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1,
2023 "(StringPtr pStr, CFStringEncoding encoding) -> None"},
2024 {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1,
2025 "(char* cStr, CFStringEncoding encoding) -> None"},
2026 {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1,
2027 "(CFIndex idx, CFStringRef insertedStr) -> None"},
2028 {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1,
2029 "(CFRange range) -> None"},
2030 {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1,
2031 "(CFRange range, CFStringRef replacement) -> None"},
2032 {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1,
2033 "(CFStringRef replacement) -> None"},
2034 {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1,
2035 "(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None"},
2036 {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1,
2037 "(CFStringRef trimString) -> None"},
2038 {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1,
2039 "() -> None"},
2040 {NULL, NULL, 0}
2043 PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, &CFStringRefObj_chain };
2045 static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name)
2047 return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name);
2050 #define CFMutableStringRefObj_setattr NULL
2052 static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other)
2054 /* XXXX Or should we use CFEqual?? */
2055 if ( self->ob_itself > other->ob_itself ) return 1;
2056 if ( self->ob_itself < other->ob_itself ) return -1;
2057 return 0;
2060 static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self)
2062 char buf[100];
2063 sprintf(buf, "<CFMutableStringRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
2064 return PyString_FromString(buf);
2067 static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self)
2069 /* XXXX Or should we use CFHash?? */
2070 return (int)self->ob_itself;
2073 PyTypeObject CFMutableStringRef_Type = {
2074 PyObject_HEAD_INIT(&PyType_Type)
2075 0, /*ob_size*/
2076 "CFMutableStringRef", /*tp_name*/
2077 sizeof(CFMutableStringRefObject), /*tp_basicsize*/
2078 0, /*tp_itemsize*/
2079 /* methods */
2080 (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/
2081 0, /*tp_print*/
2082 (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/
2083 (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/
2084 (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/
2085 (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/
2086 (PyNumberMethods *)0, /* tp_as_number */
2087 (PySequenceMethods *)0, /* tp_as_sequence */
2088 (PyMappingMethods *)0, /* tp_as_mapping */
2089 (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/
2092 /* --------------- End object type CFMutableStringRef --------------- */
2095 /* ---------------------- Object type CFURLRef ---------------------- */
2097 PyTypeObject CFURLRef_Type;
2099 #define CFURLRefObj_Check(x) ((x)->ob_type == &CFURLRef_Type)
2101 typedef struct CFURLRefObject {
2102 PyObject_HEAD
2103 CFURLRef ob_itself;
2104 void (*ob_freeit)(CFTypeRef ptr);
2105 } CFURLRefObject;
2107 PyObject *CFURLRefObj_New(CFURLRef itself)
2109 CFURLRefObject *it;
2110 if (itself == NULL) return PyMac_Error(resNotFound);
2111 it = PyObject_NEW(CFURLRefObject, &CFURLRef_Type);
2112 if (it == NULL) return NULL;
2113 it->ob_itself = itself;
2114 it->ob_freeit = CFRelease;
2115 return (PyObject *)it;
2117 CFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
2120 if (v == Py_None) { *p_itself = NULL; return 1; }
2121 /* Check for other CF objects here */
2123 if (!CFURLRefObj_Check(v))
2125 PyErr_SetString(PyExc_TypeError, "CFURLRef required");
2126 return 0;
2128 *p_itself = ((CFURLRefObject *)v)->ob_itself;
2129 return 1;
2132 static void CFURLRefObj_dealloc(CFURLRefObject *self)
2134 if (self->ob_freeit && self->ob_itself)
2136 self->ob_freeit((CFTypeRef)self->ob_itself);
2138 PyMem_DEL(self);
2141 static PyObject *CFURLRefObj_CFURLCreateData(CFURLRefObject *_self, PyObject *_args)
2143 PyObject *_res = NULL;
2144 CFDataRef _rv;
2145 CFStringEncoding encoding;
2146 Boolean escapeWhitespace;
2147 if (!PyArg_ParseTuple(_args, "ll",
2148 &encoding,
2149 &escapeWhitespace))
2150 return NULL;
2151 _rv = CFURLCreateData((CFAllocatorRef)NULL,
2152 _self->ob_itself,
2153 encoding,
2154 escapeWhitespace);
2155 _res = Py_BuildValue("O&",
2156 CFDataRefObj_New, _rv);
2157 return _res;
2160 static PyObject *CFURLRefObj_CFURLCopyAbsoluteURL(CFURLRefObject *_self, PyObject *_args)
2162 PyObject *_res = NULL;
2163 CFURLRef _rv;
2164 PyMac_PRECHECK(CFURLCopyAbsoluteURL);
2165 if (!PyArg_ParseTuple(_args, ""))
2166 return NULL;
2167 _rv = CFURLCopyAbsoluteURL(_self->ob_itself);
2168 _res = Py_BuildValue("O&",
2169 CFURLRefObj_New, _rv);
2170 return _res;
2173 static PyObject *CFURLRefObj_CFURLGetString(CFURLRefObject *_self, PyObject *_args)
2175 PyObject *_res = NULL;
2176 CFStringRef _rv;
2177 PyMac_PRECHECK(CFURLGetString);
2178 if (!PyArg_ParseTuple(_args, ""))
2179 return NULL;
2180 _rv = CFURLGetString(_self->ob_itself);
2181 _res = Py_BuildValue("O&",
2182 CFStringRefObj_New, _rv);
2183 return _res;
2186 static PyObject *CFURLRefObj_CFURLGetBaseURL(CFURLRefObject *_self, PyObject *_args)
2188 PyObject *_res = NULL;
2189 CFURLRef _rv;
2190 PyMac_PRECHECK(CFURLGetBaseURL);
2191 if (!PyArg_ParseTuple(_args, ""))
2192 return NULL;
2193 _rv = CFURLGetBaseURL(_self->ob_itself);
2194 _res = Py_BuildValue("O&",
2195 CFURLRefObj_New, _rv);
2196 return _res;
2199 static PyObject *CFURLRefObj_CFURLCanBeDecomposed(CFURLRefObject *_self, PyObject *_args)
2201 PyObject *_res = NULL;
2202 Boolean _rv;
2203 PyMac_PRECHECK(CFURLCanBeDecomposed);
2204 if (!PyArg_ParseTuple(_args, ""))
2205 return NULL;
2206 _rv = CFURLCanBeDecomposed(_self->ob_itself);
2207 _res = Py_BuildValue("l",
2208 _rv);
2209 return _res;
2212 static PyObject *CFURLRefObj_CFURLCopyScheme(CFURLRefObject *_self, PyObject *_args)
2214 PyObject *_res = NULL;
2215 CFStringRef _rv;
2216 PyMac_PRECHECK(CFURLCopyScheme);
2217 if (!PyArg_ParseTuple(_args, ""))
2218 return NULL;
2219 _rv = CFURLCopyScheme(_self->ob_itself);
2220 _res = Py_BuildValue("O&",
2221 CFStringRefObj_New, _rv);
2222 return _res;
2225 static PyObject *CFURLRefObj_CFURLCopyNetLocation(CFURLRefObject *_self, PyObject *_args)
2227 PyObject *_res = NULL;
2228 CFStringRef _rv;
2229 PyMac_PRECHECK(CFURLCopyNetLocation);
2230 if (!PyArg_ParseTuple(_args, ""))
2231 return NULL;
2232 _rv = CFURLCopyNetLocation(_self->ob_itself);
2233 _res = Py_BuildValue("O&",
2234 CFStringRefObj_New, _rv);
2235 return _res;
2238 static PyObject *CFURLRefObj_CFURLCopyPath(CFURLRefObject *_self, PyObject *_args)
2240 PyObject *_res = NULL;
2241 CFStringRef _rv;
2242 PyMac_PRECHECK(CFURLCopyPath);
2243 if (!PyArg_ParseTuple(_args, ""))
2244 return NULL;
2245 _rv = CFURLCopyPath(_self->ob_itself);
2246 _res = Py_BuildValue("O&",
2247 CFStringRefObj_New, _rv);
2248 return _res;
2251 static PyObject *CFURLRefObj_CFURLHasDirectoryPath(CFURLRefObject *_self, PyObject *_args)
2253 PyObject *_res = NULL;
2254 Boolean _rv;
2255 PyMac_PRECHECK(CFURLHasDirectoryPath);
2256 if (!PyArg_ParseTuple(_args, ""))
2257 return NULL;
2258 _rv = CFURLHasDirectoryPath(_self->ob_itself);
2259 _res = Py_BuildValue("l",
2260 _rv);
2261 return _res;
2264 static PyObject *CFURLRefObj_CFURLCopyResourceSpecifier(CFURLRefObject *_self, PyObject *_args)
2266 PyObject *_res = NULL;
2267 CFStringRef _rv;
2268 PyMac_PRECHECK(CFURLCopyResourceSpecifier);
2269 if (!PyArg_ParseTuple(_args, ""))
2270 return NULL;
2271 _rv = CFURLCopyResourceSpecifier(_self->ob_itself);
2272 _res = Py_BuildValue("O&",
2273 CFStringRefObj_New, _rv);
2274 return _res;
2277 static PyObject *CFURLRefObj_CFURLCopyHostName(CFURLRefObject *_self, PyObject *_args)
2279 PyObject *_res = NULL;
2280 CFStringRef _rv;
2281 PyMac_PRECHECK(CFURLCopyHostName);
2282 if (!PyArg_ParseTuple(_args, ""))
2283 return NULL;
2284 _rv = CFURLCopyHostName(_self->ob_itself);
2285 _res = Py_BuildValue("O&",
2286 CFStringRefObj_New, _rv);
2287 return _res;
2290 static PyObject *CFURLRefObj_CFURLGetPortNumber(CFURLRefObject *_self, PyObject *_args)
2292 PyObject *_res = NULL;
2293 SInt32 _rv;
2294 PyMac_PRECHECK(CFURLGetPortNumber);
2295 if (!PyArg_ParseTuple(_args, ""))
2296 return NULL;
2297 _rv = CFURLGetPortNumber(_self->ob_itself);
2298 _res = Py_BuildValue("l",
2299 _rv);
2300 return _res;
2303 static PyObject *CFURLRefObj_CFURLCopyUserName(CFURLRefObject *_self, PyObject *_args)
2305 PyObject *_res = NULL;
2306 CFStringRef _rv;
2307 PyMac_PRECHECK(CFURLCopyUserName);
2308 if (!PyArg_ParseTuple(_args, ""))
2309 return NULL;
2310 _rv = CFURLCopyUserName(_self->ob_itself);
2311 _res = Py_BuildValue("O&",
2312 CFStringRefObj_New, _rv);
2313 return _res;
2316 static PyObject *CFURLRefObj_CFURLCopyPassword(CFURLRefObject *_self, PyObject *_args)
2318 PyObject *_res = NULL;
2319 CFStringRef _rv;
2320 PyMac_PRECHECK(CFURLCopyPassword);
2321 if (!PyArg_ParseTuple(_args, ""))
2322 return NULL;
2323 _rv = CFURLCopyPassword(_self->ob_itself);
2324 _res = Py_BuildValue("O&",
2325 CFStringRefObj_New, _rv);
2326 return _res;
2329 static PyObject *CFURLRefObj_CFURLCopyParameterString(CFURLRefObject *_self, PyObject *_args)
2331 PyObject *_res = NULL;
2332 CFStringRef _rv;
2333 CFStringRef charactersToLeaveEscaped;
2334 PyMac_PRECHECK(CFURLCopyParameterString);
2335 if (!PyArg_ParseTuple(_args, "O&",
2336 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2337 return NULL;
2338 _rv = CFURLCopyParameterString(_self->ob_itself,
2339 charactersToLeaveEscaped);
2340 _res = Py_BuildValue("O&",
2341 CFStringRefObj_New, _rv);
2342 return _res;
2345 static PyObject *CFURLRefObj_CFURLCopyQueryString(CFURLRefObject *_self, PyObject *_args)
2347 PyObject *_res = NULL;
2348 CFStringRef _rv;
2349 CFStringRef charactersToLeaveEscaped;
2350 PyMac_PRECHECK(CFURLCopyQueryString);
2351 if (!PyArg_ParseTuple(_args, "O&",
2352 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2353 return NULL;
2354 _rv = CFURLCopyQueryString(_self->ob_itself,
2355 charactersToLeaveEscaped);
2356 _res = Py_BuildValue("O&",
2357 CFStringRefObj_New, _rv);
2358 return _res;
2361 static PyObject *CFURLRefObj_CFURLCopyFragment(CFURLRefObject *_self, PyObject *_args)
2363 PyObject *_res = NULL;
2364 CFStringRef _rv;
2365 CFStringRef charactersToLeaveEscaped;
2366 PyMac_PRECHECK(CFURLCopyFragment);
2367 if (!PyArg_ParseTuple(_args, "O&",
2368 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2369 return NULL;
2370 _rv = CFURLCopyFragment(_self->ob_itself,
2371 charactersToLeaveEscaped);
2372 _res = Py_BuildValue("O&",
2373 CFStringRefObj_New, _rv);
2374 return _res;
2377 static PyMethodDef CFURLRefObj_methods[] = {
2378 {"CFURLCreateData", (PyCFunction)CFURLRefObj_CFURLCreateData, 1,
2379 "(CFStringEncoding encoding, Boolean escapeWhitespace) -> (CFDataRef _rv)"},
2380 {"CFURLCopyAbsoluteURL", (PyCFunction)CFURLRefObj_CFURLCopyAbsoluteURL, 1,
2381 "() -> (CFURLRef _rv)"},
2382 {"CFURLGetString", (PyCFunction)CFURLRefObj_CFURLGetString, 1,
2383 "() -> (CFStringRef _rv)"},
2384 {"CFURLGetBaseURL", (PyCFunction)CFURLRefObj_CFURLGetBaseURL, 1,
2385 "() -> (CFURLRef _rv)"},
2386 {"CFURLCanBeDecomposed", (PyCFunction)CFURLRefObj_CFURLCanBeDecomposed, 1,
2387 "() -> (Boolean _rv)"},
2388 {"CFURLCopyScheme", (PyCFunction)CFURLRefObj_CFURLCopyScheme, 1,
2389 "() -> (CFStringRef _rv)"},
2390 {"CFURLCopyNetLocation", (PyCFunction)CFURLRefObj_CFURLCopyNetLocation, 1,
2391 "() -> (CFStringRef _rv)"},
2392 {"CFURLCopyPath", (PyCFunction)CFURLRefObj_CFURLCopyPath, 1,
2393 "() -> (CFStringRef _rv)"},
2394 {"CFURLHasDirectoryPath", (PyCFunction)CFURLRefObj_CFURLHasDirectoryPath, 1,
2395 "() -> (Boolean _rv)"},
2396 {"CFURLCopyResourceSpecifier", (PyCFunction)CFURLRefObj_CFURLCopyResourceSpecifier, 1,
2397 "() -> (CFStringRef _rv)"},
2398 {"CFURLCopyHostName", (PyCFunction)CFURLRefObj_CFURLCopyHostName, 1,
2399 "() -> (CFStringRef _rv)"},
2400 {"CFURLGetPortNumber", (PyCFunction)CFURLRefObj_CFURLGetPortNumber, 1,
2401 "() -> (SInt32 _rv)"},
2402 {"CFURLCopyUserName", (PyCFunction)CFURLRefObj_CFURLCopyUserName, 1,
2403 "() -> (CFStringRef _rv)"},
2404 {"CFURLCopyPassword", (PyCFunction)CFURLRefObj_CFURLCopyPassword, 1,
2405 "() -> (CFStringRef _rv)"},
2406 {"CFURLCopyParameterString", (PyCFunction)CFURLRefObj_CFURLCopyParameterString, 1,
2407 "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
2408 {"CFURLCopyQueryString", (PyCFunction)CFURLRefObj_CFURLCopyQueryString, 1,
2409 "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
2410 {"CFURLCopyFragment", (PyCFunction)CFURLRefObj_CFURLCopyFragment, 1,
2411 "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
2412 {NULL, NULL, 0}
2415 PyMethodChain CFURLRefObj_chain = { CFURLRefObj_methods, &CFTypeRefObj_chain };
2417 static PyObject *CFURLRefObj_getattr(CFURLRefObject *self, char *name)
2419 return Py_FindMethodInChain(&CFURLRefObj_chain, (PyObject *)self, name);
2422 #define CFURLRefObj_setattr NULL
2424 static int CFURLRefObj_compare(CFURLRefObject *self, CFURLRefObject *other)
2426 /* XXXX Or should we use CFEqual?? */
2427 if ( self->ob_itself > other->ob_itself ) return 1;
2428 if ( self->ob_itself < other->ob_itself ) return -1;
2429 return 0;
2432 static PyObject * CFURLRefObj_repr(CFURLRefObject *self)
2434 char buf[100];
2435 sprintf(buf, "<CFURL object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
2436 return PyString_FromString(buf);
2439 static int CFURLRefObj_hash(CFURLRefObject *self)
2441 /* XXXX Or should we use CFHash?? */
2442 return (int)self->ob_itself;
2445 PyTypeObject CFURLRef_Type = {
2446 PyObject_HEAD_INIT(&PyType_Type)
2447 0, /*ob_size*/
2448 "CFURLRef", /*tp_name*/
2449 sizeof(CFURLRefObject), /*tp_basicsize*/
2450 0, /*tp_itemsize*/
2451 /* methods */
2452 (destructor) CFURLRefObj_dealloc, /*tp_dealloc*/
2453 0, /*tp_print*/
2454 (getattrfunc) CFURLRefObj_getattr, /*tp_getattr*/
2455 (setattrfunc) CFURLRefObj_setattr, /*tp_setattr*/
2456 (cmpfunc) CFURLRefObj_compare, /*tp_compare*/
2457 (reprfunc) CFURLRefObj_repr, /*tp_repr*/
2458 (PyNumberMethods *)0, /* tp_as_number */
2459 (PySequenceMethods *)0, /* tp_as_sequence */
2460 (PyMappingMethods *)0, /* tp_as_mapping */
2461 (hashfunc) CFURLRefObj_hash, /*tp_hash*/
2464 /* -------------------- End object type CFURLRef -------------------- */
2467 static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args)
2469 PyObject *_res = NULL;
2470 CFTypeID _rv;
2471 PyMac_PRECHECK(CFAllocatorGetTypeID);
2472 if (!PyArg_ParseTuple(_args, ""))
2473 return NULL;
2474 _rv = CFAllocatorGetTypeID();
2475 _res = Py_BuildValue("l",
2476 _rv);
2477 return _res;
2480 static PyObject *CF_CFAllocatorGetPreferredSizeForSize(PyObject *_self, PyObject *_args)
2482 PyObject *_res = NULL;
2483 CFIndex _rv;
2484 CFIndex size;
2485 CFOptionFlags hint;
2486 PyMac_PRECHECK(CFAllocatorGetPreferredSizeForSize);
2487 if (!PyArg_ParseTuple(_args, "ll",
2488 &size,
2489 &hint))
2490 return NULL;
2491 _rv = CFAllocatorGetPreferredSizeForSize((CFAllocatorRef)NULL,
2492 size,
2493 hint);
2494 _res = Py_BuildValue("l",
2495 _rv);
2496 return _res;
2499 static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args)
2501 PyObject *_res = NULL;
2502 CFStringRef _rv;
2503 CFTypeID theType;
2504 PyMac_PRECHECK(CFCopyTypeIDDescription);
2505 if (!PyArg_ParseTuple(_args, "l",
2506 &theType))
2507 return NULL;
2508 _rv = CFCopyTypeIDDescription(theType);
2509 _res = Py_BuildValue("O&",
2510 CFStringRefObj_New, _rv);
2511 return _res;
2514 static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args)
2516 PyObject *_res = NULL;
2517 CFTypeID _rv;
2518 PyMac_PRECHECK(CFArrayGetTypeID);
2519 if (!PyArg_ParseTuple(_args, ""))
2520 return NULL;
2521 _rv = CFArrayGetTypeID();
2522 _res = Py_BuildValue("l",
2523 _rv);
2524 return _res;
2527 static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args)
2529 PyObject *_res = NULL;
2530 CFMutableArrayRef _rv;
2531 CFIndex capacity;
2532 PyMac_PRECHECK(CFArrayCreateMutable);
2533 if (!PyArg_ParseTuple(_args, "l",
2534 &capacity))
2535 return NULL;
2536 _rv = CFArrayCreateMutable((CFAllocatorRef)NULL,
2537 capacity,
2538 &kCFTypeArrayCallBacks);
2539 _res = Py_BuildValue("O&",
2540 CFMutableArrayRefObj_New, _rv);
2541 return _res;
2544 static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args)
2546 PyObject *_res = NULL;
2547 CFMutableArrayRef _rv;
2548 CFIndex capacity;
2549 CFArrayRef srcArray;
2550 PyMac_PRECHECK(CFArrayCreateMutableCopy);
2551 if (!PyArg_ParseTuple(_args, "lO&",
2552 &capacity,
2553 CFArrayRefObj_Convert, &srcArray))
2554 return NULL;
2555 _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL,
2556 capacity,
2557 srcArray);
2558 _res = Py_BuildValue("O&",
2559 CFMutableArrayRefObj_New, _rv);
2560 return _res;
2563 static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args)
2565 PyObject *_res = NULL;
2566 CFTypeID _rv;
2567 PyMac_PRECHECK(CFDataGetTypeID);
2568 if (!PyArg_ParseTuple(_args, ""))
2569 return NULL;
2570 _rv = CFDataGetTypeID();
2571 _res = Py_BuildValue("l",
2572 _rv);
2573 return _res;
2576 static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args)
2578 PyObject *_res = NULL;
2579 CFDataRef _rv;
2580 unsigned char *bytes__in__;
2581 long bytes__len__;
2582 int bytes__in_len__;
2583 PyMac_PRECHECK(CFDataCreate);
2584 if (!PyArg_ParseTuple(_args, "s#",
2585 &bytes__in__, &bytes__in_len__))
2586 return NULL;
2587 bytes__len__ = bytes__in_len__;
2588 _rv = CFDataCreate((CFAllocatorRef)NULL,
2589 bytes__in__, bytes__len__);
2590 _res = Py_BuildValue("O&",
2591 CFDataRefObj_New, _rv);
2592 bytes__error__: ;
2593 return _res;
2596 static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args)
2598 PyObject *_res = NULL;
2599 CFDataRef _rv;
2600 unsigned char *bytes__in__;
2601 long bytes__len__;
2602 int bytes__in_len__;
2603 PyMac_PRECHECK(CFDataCreateWithBytesNoCopy);
2604 if (!PyArg_ParseTuple(_args, "s#",
2605 &bytes__in__, &bytes__in_len__))
2606 return NULL;
2607 bytes__len__ = bytes__in_len__;
2608 _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL,
2609 bytes__in__, bytes__len__,
2610 (CFAllocatorRef)NULL);
2611 _res = Py_BuildValue("O&",
2612 CFDataRefObj_New, _rv);
2613 bytes__error__: ;
2614 return _res;
2617 static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args)
2619 PyObject *_res = NULL;
2620 CFMutableDataRef _rv;
2621 CFIndex capacity;
2622 PyMac_PRECHECK(CFDataCreateMutable);
2623 if (!PyArg_ParseTuple(_args, "l",
2624 &capacity))
2625 return NULL;
2626 _rv = CFDataCreateMutable((CFAllocatorRef)NULL,
2627 capacity);
2628 _res = Py_BuildValue("O&",
2629 CFMutableDataRefObj_New, _rv);
2630 return _res;
2633 static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args)
2635 PyObject *_res = NULL;
2636 CFMutableDataRef _rv;
2637 CFIndex capacity;
2638 CFDataRef data;
2639 PyMac_PRECHECK(CFDataCreateMutableCopy);
2640 if (!PyArg_ParseTuple(_args, "lO&",
2641 &capacity,
2642 CFDataRefObj_Convert, &data))
2643 return NULL;
2644 _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL,
2645 capacity,
2646 data);
2647 _res = Py_BuildValue("O&",
2648 CFMutableDataRefObj_New, _rv);
2649 return _res;
2652 static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args)
2654 PyObject *_res = NULL;
2655 CFTypeID _rv;
2656 PyMac_PRECHECK(CFDictionaryGetTypeID);
2657 if (!PyArg_ParseTuple(_args, ""))
2658 return NULL;
2659 _rv = CFDictionaryGetTypeID();
2660 _res = Py_BuildValue("l",
2661 _rv);
2662 return _res;
2665 static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args)
2667 PyObject *_res = NULL;
2668 CFMutableDictionaryRef _rv;
2669 CFIndex capacity;
2670 PyMac_PRECHECK(CFDictionaryCreateMutable);
2671 if (!PyArg_ParseTuple(_args, "l",
2672 &capacity))
2673 return NULL;
2674 _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL,
2675 capacity,
2676 &kCFTypeDictionaryKeyCallBacks,
2677 &kCFTypeDictionaryValueCallBacks);
2678 _res = Py_BuildValue("O&",
2679 CFMutableDictionaryRefObj_New, _rv);
2680 return _res;
2683 static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args)
2685 PyObject *_res = NULL;
2686 CFMutableDictionaryRef _rv;
2687 CFIndex capacity;
2688 CFDictionaryRef dict;
2689 PyMac_PRECHECK(CFDictionaryCreateMutableCopy);
2690 if (!PyArg_ParseTuple(_args, "lO&",
2691 &capacity,
2692 CFDictionaryRefObj_Convert, &dict))
2693 return NULL;
2694 _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL,
2695 capacity,
2696 dict);
2697 _res = Py_BuildValue("O&",
2698 CFMutableDictionaryRefObj_New, _rv);
2699 return _res;
2702 static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args)
2704 PyObject *_res = NULL;
2705 CFTypeID _rv;
2706 PyMac_PRECHECK(CFStringGetTypeID);
2707 if (!PyArg_ParseTuple(_args, ""))
2708 return NULL;
2709 _rv = CFStringGetTypeID();
2710 _res = Py_BuildValue("l",
2711 _rv);
2712 return _res;
2715 static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args)
2717 PyObject *_res = NULL;
2718 CFStringRef _rv;
2719 StringPtr pStr;
2720 CFStringEncoding encoding;
2721 PyMac_PRECHECK(CFStringCreateWithPascalString);
2722 if (!PyArg_ParseTuple(_args, "O&l",
2723 PyMac_GetStr255, &pStr,
2724 &encoding))
2725 return NULL;
2726 _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL,
2727 pStr,
2728 encoding);
2729 _res = Py_BuildValue("O&",
2730 CFStringRefObj_New, _rv);
2731 return _res;
2734 static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args)
2736 PyObject *_res = NULL;
2737 CFStringRef _rv;
2738 char* cStr;
2739 CFStringEncoding encoding;
2740 PyMac_PRECHECK(CFStringCreateWithCString);
2741 if (!PyArg_ParseTuple(_args, "sl",
2742 &cStr,
2743 &encoding))
2744 return NULL;
2745 _rv = CFStringCreateWithCString((CFAllocatorRef)NULL,
2746 cStr,
2747 encoding);
2748 _res = Py_BuildValue("O&",
2749 CFStringRefObj_New, _rv);
2750 return _res;
2753 static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args)
2755 PyObject *_res = NULL;
2756 CFStringRef _rv;
2757 StringPtr pStr;
2758 CFStringEncoding encoding;
2759 PyMac_PRECHECK(CFStringCreateWithPascalStringNoCopy);
2760 if (!PyArg_ParseTuple(_args, "O&l",
2761 PyMac_GetStr255, &pStr,
2762 &encoding))
2763 return NULL;
2764 _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL,
2765 pStr,
2766 encoding,
2767 (CFAllocatorRef)NULL);
2768 _res = Py_BuildValue("O&",
2769 CFStringRefObj_New, _rv);
2770 return _res;
2773 static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args)
2775 PyObject *_res = NULL;
2776 CFStringRef _rv;
2777 char* cStr;
2778 CFStringEncoding encoding;
2779 PyMac_PRECHECK(CFStringCreateWithCStringNoCopy);
2780 if (!PyArg_ParseTuple(_args, "sl",
2781 &cStr,
2782 &encoding))
2783 return NULL;
2784 _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL,
2785 cStr,
2786 encoding,
2787 (CFAllocatorRef)NULL);
2788 _res = Py_BuildValue("O&",
2789 CFStringRefObj_New, _rv);
2790 return _res;
2793 static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args)
2795 PyObject *_res = NULL;
2796 CFMutableStringRef _rv;
2797 CFIndex maxLength;
2798 PyMac_PRECHECK(CFStringCreateMutable);
2799 if (!PyArg_ParseTuple(_args, "l",
2800 &maxLength))
2801 return NULL;
2802 _rv = CFStringCreateMutable((CFAllocatorRef)NULL,
2803 maxLength);
2804 _res = Py_BuildValue("O&",
2805 CFMutableStringRefObj_New, _rv);
2806 return _res;
2809 static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args)
2811 PyObject *_res = NULL;
2812 CFMutableStringRef _rv;
2813 CFIndex maxLength;
2814 CFStringRef theString;
2815 PyMac_PRECHECK(CFStringCreateMutableCopy);
2816 if (!PyArg_ParseTuple(_args, "lO&",
2817 &maxLength,
2818 CFStringRefObj_Convert, &theString))
2819 return NULL;
2820 _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL,
2821 maxLength,
2822 theString);
2823 _res = Py_BuildValue("O&",
2824 CFMutableStringRefObj_New, _rv);
2825 return _res;
2828 static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args)
2830 PyObject *_res = NULL;
2831 CFStringRef _rv;
2832 unsigned char *bytes__in__;
2833 long bytes__len__;
2834 int bytes__in_len__;
2835 CFStringEncoding encoding;
2836 Boolean isExternalRepresentation;
2837 PyMac_PRECHECK(CFStringCreateWithBytes);
2838 if (!PyArg_ParseTuple(_args, "s#ll",
2839 &bytes__in__, &bytes__in_len__,
2840 &encoding,
2841 &isExternalRepresentation))
2842 return NULL;
2843 bytes__len__ = bytes__in_len__;
2844 _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL,
2845 bytes__in__, bytes__len__,
2846 encoding,
2847 isExternalRepresentation);
2848 _res = Py_BuildValue("O&",
2849 CFStringRefObj_New, _rv);
2850 bytes__error__: ;
2851 return _res;
2854 static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args)
2856 PyObject *_res = NULL;
2857 CFStringEncoding _rv;
2858 PyMac_PRECHECK(CFStringGetSystemEncoding);
2859 if (!PyArg_ParseTuple(_args, ""))
2860 return NULL;
2861 _rv = CFStringGetSystemEncoding();
2862 _res = Py_BuildValue("l",
2863 _rv);
2864 return _res;
2867 static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args)
2869 PyObject *_res = NULL;
2870 CFIndex _rv;
2871 CFIndex length;
2872 CFStringEncoding encoding;
2873 PyMac_PRECHECK(CFStringGetMaximumSizeForEncoding);
2874 if (!PyArg_ParseTuple(_args, "ll",
2875 &length,
2876 &encoding))
2877 return NULL;
2878 _rv = CFStringGetMaximumSizeForEncoding(length,
2879 encoding);
2880 _res = Py_BuildValue("l",
2881 _rv);
2882 return _res;
2885 static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args)
2887 PyObject *_res = NULL;
2888 Boolean _rv;
2889 CFStringEncoding encoding;
2890 PyMac_PRECHECK(CFStringIsEncodingAvailable);
2891 if (!PyArg_ParseTuple(_args, "l",
2892 &encoding))
2893 return NULL;
2894 _rv = CFStringIsEncodingAvailable(encoding);
2895 _res = Py_BuildValue("l",
2896 _rv);
2897 return _res;
2900 static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args)
2902 PyObject *_res = NULL;
2903 CFStringRef _rv;
2904 CFStringEncoding encoding;
2905 PyMac_PRECHECK(CFStringGetNameOfEncoding);
2906 if (!PyArg_ParseTuple(_args, "l",
2907 &encoding))
2908 return NULL;
2909 _rv = CFStringGetNameOfEncoding(encoding);
2910 _res = Py_BuildValue("O&",
2911 CFStringRefObj_New, _rv);
2912 return _res;
2915 static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args)
2917 PyObject *_res = NULL;
2918 UInt32 _rv;
2919 CFStringEncoding encoding;
2920 PyMac_PRECHECK(CFStringConvertEncodingToNSStringEncoding);
2921 if (!PyArg_ParseTuple(_args, "l",
2922 &encoding))
2923 return NULL;
2924 _rv = CFStringConvertEncodingToNSStringEncoding(encoding);
2925 _res = Py_BuildValue("l",
2926 _rv);
2927 return _res;
2930 static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args)
2932 PyObject *_res = NULL;
2933 CFStringEncoding _rv;
2934 UInt32 encoding;
2935 PyMac_PRECHECK(CFStringConvertNSStringEncodingToEncoding);
2936 if (!PyArg_ParseTuple(_args, "l",
2937 &encoding))
2938 return NULL;
2939 _rv = CFStringConvertNSStringEncodingToEncoding(encoding);
2940 _res = Py_BuildValue("l",
2941 _rv);
2942 return _res;
2945 static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args)
2947 PyObject *_res = NULL;
2948 UInt32 _rv;
2949 CFStringEncoding encoding;
2950 PyMac_PRECHECK(CFStringConvertEncodingToWindowsCodepage);
2951 if (!PyArg_ParseTuple(_args, "l",
2952 &encoding))
2953 return NULL;
2954 _rv = CFStringConvertEncodingToWindowsCodepage(encoding);
2955 _res = Py_BuildValue("l",
2956 _rv);
2957 return _res;
2960 static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args)
2962 PyObject *_res = NULL;
2963 CFStringEncoding _rv;
2964 UInt32 codepage;
2965 PyMac_PRECHECK(CFStringConvertWindowsCodepageToEncoding);
2966 if (!PyArg_ParseTuple(_args, "l",
2967 &codepage))
2968 return NULL;
2969 _rv = CFStringConvertWindowsCodepageToEncoding(codepage);
2970 _res = Py_BuildValue("l",
2971 _rv);
2972 return _res;
2975 static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args)
2977 PyObject *_res = NULL;
2978 CFStringRef _rv;
2979 CFStringEncoding encoding;
2980 PyMac_PRECHECK(CFStringConvertEncodingToIANACharSetName);
2981 if (!PyArg_ParseTuple(_args, "l",
2982 &encoding))
2983 return NULL;
2984 _rv = CFStringConvertEncodingToIANACharSetName(encoding);
2985 _res = Py_BuildValue("O&",
2986 CFStringRefObj_New, _rv);
2987 return _res;
2990 static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args)
2992 PyObject *_res = NULL;
2993 CFStringRef _rv;
2994 char* cStr;
2995 PyMac_PRECHECK(__CFStringMakeConstantString);
2996 if (!PyArg_ParseTuple(_args, "s",
2997 &cStr))
2998 return NULL;
2999 _rv = __CFStringMakeConstantString(cStr);
3000 _res = Py_BuildValue("O&",
3001 CFStringRefObj_New, _rv);
3002 return _res;
3005 static PyObject *CF_CFURLGetTypeID(PyObject *_self, PyObject *_args)
3007 PyObject *_res = NULL;
3008 CFTypeID _rv;
3009 PyMac_PRECHECK(CFURLGetTypeID);
3010 if (!PyArg_ParseTuple(_args, ""))
3011 return NULL;
3012 _rv = CFURLGetTypeID();
3013 _res = Py_BuildValue("l",
3014 _rv);
3015 return _res;
3018 static PyObject *CF_CFURLCreateWithBytes(PyObject *_self, PyObject *_args)
3020 PyObject *_res = NULL;
3021 CFURLRef _rv;
3022 unsigned char *URLBytes__in__;
3023 long URLBytes__len__;
3024 int URLBytes__in_len__;
3025 CFStringEncoding encoding;
3026 CFURLRef baseURL;
3027 PyMac_PRECHECK(CFURLCreateWithBytes);
3028 if (!PyArg_ParseTuple(_args, "s#lO&",
3029 &URLBytes__in__, &URLBytes__in_len__,
3030 &encoding,
3031 OptionalCFURLRefObj_Convert, &baseURL))
3032 return NULL;
3033 URLBytes__len__ = URLBytes__in_len__;
3034 _rv = CFURLCreateWithBytes((CFAllocatorRef)NULL,
3035 URLBytes__in__, URLBytes__len__,
3036 encoding,
3037 baseURL);
3038 _res = Py_BuildValue("O&",
3039 CFURLRefObj_New, _rv);
3040 URLBytes__error__: ;
3041 return _res;
3044 static PyMethodDef CF_methods[] = {
3045 {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1,
3046 "() -> (CFTypeID _rv)"},
3047 {"CFAllocatorGetPreferredSizeForSize", (PyCFunction)CF_CFAllocatorGetPreferredSizeForSize, 1,
3048 "(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)"},
3049 {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1,
3050 "(CFTypeID theType) -> (CFStringRef _rv)"},
3051 {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1,
3052 "() -> (CFTypeID _rv)"},
3053 {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1,
3054 "(CFIndex capacity) -> (CFMutableArrayRef _rv)"},
3055 {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1,
3056 "(CFIndex capacity, CFArrayRef srcArray) -> (CFMutableArrayRef _rv)"},
3057 {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1,
3058 "() -> (CFTypeID _rv)"},
3059 {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1,
3060 "(Buffer bytes) -> (CFDataRef _rv)"},
3061 {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1,
3062 "(Buffer bytes) -> (CFDataRef _rv)"},
3063 {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1,
3064 "(CFIndex capacity) -> (CFMutableDataRef _rv)"},
3065 {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1,
3066 "(CFIndex capacity, CFDataRef data) -> (CFMutableDataRef _rv)"},
3067 {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1,
3068 "() -> (CFTypeID _rv)"},
3069 {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1,
3070 "(CFIndex capacity) -> (CFMutableDictionaryRef _rv)"},
3071 {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1,
3072 "(CFIndex capacity, CFDictionaryRef dict) -> (CFMutableDictionaryRef _rv)"},
3073 {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1,
3074 "() -> (CFTypeID _rv)"},
3075 {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1,
3076 "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
3077 {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1,
3078 "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
3079 {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1,
3080 "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
3081 {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1,
3082 "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
3083 {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1,
3084 "(CFIndex maxLength) -> (CFMutableStringRef _rv)"},
3085 {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1,
3086 "(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)"},
3087 {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1,
3088 "(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)"},
3089 {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1,
3090 "() -> (CFStringEncoding _rv)"},
3091 {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1,
3092 "(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)"},
3093 {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1,
3094 "(CFStringEncoding encoding) -> (Boolean _rv)"},
3095 {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1,
3096 "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
3097 {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1,
3098 "(CFStringEncoding encoding) -> (UInt32 _rv)"},
3099 {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1,
3100 "(UInt32 encoding) -> (CFStringEncoding _rv)"},
3101 {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1,
3102 "(CFStringEncoding encoding) -> (UInt32 _rv)"},
3103 {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1,
3104 "(UInt32 codepage) -> (CFStringEncoding _rv)"},
3105 {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1,
3106 "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
3107 {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1,
3108 "(char* cStr) -> (CFStringRef _rv)"},
3109 {"CFURLGetTypeID", (PyCFunction)CF_CFURLGetTypeID, 1,
3110 "() -> (CFTypeID _rv)"},
3111 {"CFURLCreateWithBytes", (PyCFunction)CF_CFURLCreateWithBytes, 1,
3112 "(Buffer URLBytes, CFStringEncoding encoding, CFURLRef baseURL) -> (CFURLRef _rv)"},
3113 {NULL, NULL, 0}
3119 void initCF(void)
3121 PyObject *m;
3122 PyObject *d;
3126 // PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
3127 // PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
3130 m = Py_InitModule("CF", CF_methods);
3131 d = PyModule_GetDict(m);
3132 CF_Error = PyMac_GetOSErrException();
3133 if (CF_Error == NULL ||
3134 PyDict_SetItemString(d, "Error", CF_Error) != 0)
3135 return;
3136 CFTypeRef_Type.ob_type = &PyType_Type;
3137 Py_INCREF(&CFTypeRef_Type);
3138 if (PyDict_SetItemString(d, "CFTypeRefType", (PyObject *)&CFTypeRef_Type) != 0)
3139 Py_FatalError("can't initialize CFTypeRefType");
3140 CFArrayRef_Type.ob_type = &PyType_Type;
3141 Py_INCREF(&CFArrayRef_Type);
3142 if (PyDict_SetItemString(d, "CFArrayRefType", (PyObject *)&CFArrayRef_Type) != 0)
3143 Py_FatalError("can't initialize CFArrayRefType");
3144 CFMutableArrayRef_Type.ob_type = &PyType_Type;
3145 Py_INCREF(&CFMutableArrayRef_Type);
3146 if (PyDict_SetItemString(d, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type) != 0)
3147 Py_FatalError("can't initialize CFMutableArrayRefType");
3148 CFDictionaryRef_Type.ob_type = &PyType_Type;
3149 Py_INCREF(&CFDictionaryRef_Type);
3150 if (PyDict_SetItemString(d, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type) != 0)
3151 Py_FatalError("can't initialize CFDictionaryRefType");
3152 CFMutableDictionaryRef_Type.ob_type = &PyType_Type;
3153 Py_INCREF(&CFMutableDictionaryRef_Type);
3154 if (PyDict_SetItemString(d, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type) != 0)
3155 Py_FatalError("can't initialize CFMutableDictionaryRefType");
3156 CFDataRef_Type.ob_type = &PyType_Type;
3157 Py_INCREF(&CFDataRef_Type);
3158 if (PyDict_SetItemString(d, "CFDataRefType", (PyObject *)&CFDataRef_Type) != 0)
3159 Py_FatalError("can't initialize CFDataRefType");
3160 CFMutableDataRef_Type.ob_type = &PyType_Type;
3161 Py_INCREF(&CFMutableDataRef_Type);
3162 if (PyDict_SetItemString(d, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type) != 0)
3163 Py_FatalError("can't initialize CFMutableDataRefType");
3164 CFStringRef_Type.ob_type = &PyType_Type;
3165 Py_INCREF(&CFStringRef_Type);
3166 if (PyDict_SetItemString(d, "CFStringRefType", (PyObject *)&CFStringRef_Type) != 0)
3167 Py_FatalError("can't initialize CFStringRefType");
3168 CFMutableStringRef_Type.ob_type = &PyType_Type;
3169 Py_INCREF(&CFMutableStringRef_Type);
3170 if (PyDict_SetItemString(d, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type) != 0)
3171 Py_FatalError("can't initialize CFMutableStringRefType");
3172 CFURLRef_Type.ob_type = &PyType_Type;
3173 Py_INCREF(&CFURLRef_Type);
3174 if (PyDict_SetItemString(d, "CFURLRefType", (PyObject *)&CFURLRef_Type) != 0)
3175 Py_FatalError("can't initialize CFURLRefType");
3178 /* ========================= End module CF ========================== */