blob: 4f5d935b2696d1ae8ec13146f7f3c1068adbc013 [file] [log] [blame]
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001
2/* =========================== Module _CF =========================== */
3
4#include "Python.h"
5
6
7
Jack Jansen620a7662001-12-18 15:39:38 +00008#ifdef _WIN32
9#include "pywintoolbox.h"
10#else
Jack Jansen50ecb0a2001-08-23 14:02:09 +000011#include "macglue.h"
12#include "pymactoolbox.h"
Jack Jansen620a7662001-12-18 15:39:38 +000013#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +000014
15/* Macro to test whether a weak-loaded CFM function exists */
16#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
21
22
23#ifdef WITHOUT_FRAMEWORKS
24#include <CFBase.h>
25#include <CFArray.h>
26#include <CFData.h>
27#include <CFDictionary.h>
28#include <CFString.h>
29#include <CFURL.h>
Jack Jansen79066342002-05-12 22:04:14 +000030#include <CFPropertyList.h>
Jack Jansen23be1ce2002-05-13 21:21:49 +000031#include <CFPreferences.h>
Jack Jansen50ecb0a2001-08-23 14:02:09 +000032#else
33#include <CoreServices/CoreServices.h>
34#endif
35
Jack Jansen5ad6f7a2002-05-07 23:00:03 +000036#include "pycfbridge.h"
37
Jack Jansen537a69f2001-11-05 14:39:22 +000038#ifdef USE_TOOLBOX_OBJECT_GLUE
39extern PyObject *_CFTypeRefObj_New(CFTypeRef);
40extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
41#define CFTypeRefObj_New _CFTypeRefObj_New
42#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
Jack Jansen50ecb0a2001-08-23 14:02:09 +000043
Jack Jansen537a69f2001-11-05 14:39:22 +000044extern PyObject *_CFStringRefObj_New(CFStringRef);
45extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
46#define CFStringRefObj_New _CFStringRefObj_New
47#define CFStringRefObj_Convert _CFStringRefObj_Convert
Jack Jansen50ecb0a2001-08-23 14:02:09 +000048
Jack Jansen537a69f2001-11-05 14:39:22 +000049extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
50extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
51#define CFMutableStringRefObj_New _CFMutableStringRefObj_New
52#define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
Jack Jansen50ecb0a2001-08-23 14:02:09 +000053
Jack Jansen537a69f2001-11-05 14:39:22 +000054extern PyObject *_CFArrayRefObj_New(CFArrayRef);
55extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
56#define CFArrayRefObj_New _CFArrayRefObj_New
57#define CFArrayRefObj_Convert _CFArrayRefObj_Convert
58
59extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
60extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
61#define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
62#define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
63
64extern PyObject *_CFDataRefObj_New(CFDataRef);
65extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
66#define CFDataRefObj_New _CFDataRefObj_New
67#define CFDataRefObj_Convert _CFDataRefObj_Convert
68
69extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
70extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
71#define CFMutableDataRefObj_New _CFMutableDataRefObj_New
72#define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
73
74extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
75extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
76#define CFDictionaryRefObj_New _CFDictionaryRefObj_New
77#define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
78
79extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
80extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
81#define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
82#define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
83
84extern PyObject *_CFURLRefObj_New(CFURLRef);
85extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
86extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
87#define CFURLRefObj_New _CFURLRefObj_New
88#define CFURLRefObj_Convert _CFURLRefObj_Convert
89#define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
Jack Jansen50ecb0a2001-08-23 14:02:09 +000090#endif
91
92/*
93** Parse/generate CFRange records
94*/
95PyObject *CFRange_New(CFRange *itself)
96{
97
98 return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
99}
100
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000101int
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000102CFRange_Convert(PyObject *v, CFRange *p_itself)
103{
104 long location, length;
105
106 if( !PyArg_ParseTuple(v, "ll", &location, &length) )
107 return 0;
108 p_itself->location = (CFIndex)location;
109 p_itself->length = (CFIndex)length;
110 return 1;
111}
112
113/* Optional CFURL argument or None (passed as NULL) */
114int
115OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
116{
117 if ( v == Py_None ) {
118 p_itself = NULL;
119 return 1;
120 }
121 return CFURLRefObj_Convert(v, p_itself);
122}
123
124
125static PyObject *CF_Error;
126
127/* --------------------- Object type CFTypeRef ---------------------- */
128
129PyTypeObject CFTypeRef_Type;
130
Jack Jansenf9557842002-12-19 21:24:35 +0000131#define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type || PyObject_TypeCheck((x), &CFTypeRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000132
133typedef struct CFTypeRefObject {
134 PyObject_HEAD
135 CFTypeRef ob_itself;
136 void (*ob_freeit)(CFTypeRef ptr);
137} CFTypeRefObject;
138
139PyObject *CFTypeRefObj_New(CFTypeRef itself)
140{
141 CFTypeRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +0000142 if (itself == NULL)
143 {
144 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
145 return NULL;
146 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000147 it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
148 if (it == NULL) return NULL;
149 it->ob_itself = itself;
150 it->ob_freeit = CFRelease;
151 return (PyObject *)it;
152}
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000153int CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000154{
155
156 if (v == Py_None) { *p_itself = NULL; return 1; }
157 /* Check for other CF objects here */
158
159 if (!CFTypeRefObj_Check(v))
160 {
161 PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
162 return 0;
163 }
164 *p_itself = ((CFTypeRefObject *)v)->ob_itself;
165 return 1;
166}
167
168static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
169{
170 if (self->ob_freeit && self->ob_itself)
171 {
172 self->ob_freeit((CFTypeRef)self->ob_itself);
173 }
Jack Jansen234d0742002-12-23 22:35:38 +0000174 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000175}
176
177static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
178{
179 PyObject *_res = NULL;
180 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000181#ifndef CFGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000182 PyMac_PRECHECK(CFGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +0000183#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000184 if (!PyArg_ParseTuple(_args, ""))
185 return NULL;
186 _rv = CFGetTypeID(_self->ob_itself);
187 _res = Py_BuildValue("l",
188 _rv);
189 return _res;
190}
191
192static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
193{
194 PyObject *_res = NULL;
195 CFTypeRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000196#ifndef CFRetain
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000197 PyMac_PRECHECK(CFRetain);
Jack Jansenb3be2162001-11-30 14:16:36 +0000198#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000199 if (!PyArg_ParseTuple(_args, ""))
200 return NULL;
201 _rv = CFRetain(_self->ob_itself);
202 _res = Py_BuildValue("O&",
203 CFTypeRefObj_New, _rv);
204 return _res;
205}
206
207static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
208{
209 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +0000210#ifndef CFRelease
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000211 PyMac_PRECHECK(CFRelease);
Jack Jansenb3be2162001-11-30 14:16:36 +0000212#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000213 if (!PyArg_ParseTuple(_args, ""))
214 return NULL;
215 CFRelease(_self->ob_itself);
216 Py_INCREF(Py_None);
217 _res = Py_None;
218 return _res;
219}
220
221static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
222{
223 PyObject *_res = NULL;
224 CFIndex _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000225#ifndef CFGetRetainCount
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000226 PyMac_PRECHECK(CFGetRetainCount);
Jack Jansenb3be2162001-11-30 14:16:36 +0000227#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000228 if (!PyArg_ParseTuple(_args, ""))
229 return NULL;
230 _rv = CFGetRetainCount(_self->ob_itself);
231 _res = Py_BuildValue("l",
232 _rv);
233 return _res;
234}
235
236static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
237{
238 PyObject *_res = NULL;
239 Boolean _rv;
240 CFTypeRef cf2;
Jack Jansenb3be2162001-11-30 14:16:36 +0000241#ifndef CFEqual
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000242 PyMac_PRECHECK(CFEqual);
Jack Jansenb3be2162001-11-30 14:16:36 +0000243#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000244 if (!PyArg_ParseTuple(_args, "O&",
245 CFTypeRefObj_Convert, &cf2))
246 return NULL;
247 _rv = CFEqual(_self->ob_itself,
248 cf2);
249 _res = Py_BuildValue("l",
250 _rv);
251 return _res;
252}
253
254static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
255{
256 PyObject *_res = NULL;
257 CFHashCode _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000258#ifndef CFHash
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000259 PyMac_PRECHECK(CFHash);
Jack Jansenb3be2162001-11-30 14:16:36 +0000260#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
263 _rv = CFHash(_self->ob_itself);
264 _res = Py_BuildValue("l",
265 _rv);
266 return _res;
267}
268
269static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
270{
271 PyObject *_res = NULL;
272 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000273#ifndef CFCopyDescription
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000274 PyMac_PRECHECK(CFCopyDescription);
Jack Jansenb3be2162001-11-30 14:16:36 +0000275#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000276 if (!PyArg_ParseTuple(_args, ""))
277 return NULL;
278 _rv = CFCopyDescription(_self->ob_itself);
279 _res = Py_BuildValue("O&",
280 CFStringRefObj_New, _rv);
281 return _res;
282}
283
Jack Jansen79066342002-05-12 22:04:14 +0000284static PyObject *CFTypeRefObj_CFPropertyListCreateXMLData(CFTypeRefObject *_self, PyObject *_args)
285{
286 PyObject *_res = NULL;
287 CFDataRef _rv;
288 if (!PyArg_ParseTuple(_args, ""))
289 return NULL;
290 _rv = CFPropertyListCreateXMLData((CFAllocatorRef)NULL,
291 _self->ob_itself);
292 _res = Py_BuildValue("O&",
293 CFDataRefObj_New, _rv);
294 return _res;
295}
296
297static PyObject *CFTypeRefObj_CFPropertyListCreateDeepCopy(CFTypeRefObject *_self, PyObject *_args)
298{
299 PyObject *_res = NULL;
300 CFTypeRef _rv;
301 CFOptionFlags mutabilityOption;
302 if (!PyArg_ParseTuple(_args, "l",
303 &mutabilityOption))
304 return NULL;
305 _rv = CFPropertyListCreateDeepCopy((CFAllocatorRef)NULL,
306 _self->ob_itself,
307 mutabilityOption);
308 _res = Py_BuildValue("O&",
309 CFTypeRefObj_New, _rv);
310 return _res;
311}
312
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000313static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
314{
315 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +0000316#ifndef CFShow
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000317 PyMac_PRECHECK(CFShow);
Jack Jansenb3be2162001-11-30 14:16:36 +0000318#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000319 if (!PyArg_ParseTuple(_args, ""))
320 return NULL;
321 CFShow(_self->ob_itself);
322 Py_INCREF(Py_None);
323 _res = Py_None;
324 return _res;
325}
326
Jack Jansen79066342002-05-12 22:04:14 +0000327static PyObject *CFTypeRefObj_CFPropertyListCreateFromXMLData(CFTypeRefObject *_self, PyObject *_args)
328{
329 PyObject *_res = NULL;
330
331 CFTypeRef _rv;
332 CFOptionFlags mutabilityOption;
333 CFStringRef errorString;
334 if (!PyArg_ParseTuple(_args, "l",
335 &mutabilityOption))
336 return NULL;
337 _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
338 _self->ob_itself,
339 mutabilityOption,
340 &errorString);
341 if (errorString)
342 CFRelease(errorString);
343 if (_rv == NULL) {
344 PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
345 return NULL;
346 }
347 _res = Py_BuildValue("O&",
348 CFTypeRefObj_New, _rv);
349 return _res;
350
351}
352
Jack Jansen5ad6f7a2002-05-07 23:00:03 +0000353static PyObject *CFTypeRefObj_toPython(CFTypeRefObject *_self, PyObject *_args)
354{
355 PyObject *_res = NULL;
356
Jack Jansen234d0742002-12-23 22:35:38 +0000357 _res = PyCF_CF2Python(_self->ob_itself);
358 return _res;
Jack Jansen5ad6f7a2002-05-07 23:00:03 +0000359
360}
361
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000362static PyMethodDef CFTypeRefObj_methods[] = {
363 {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000364 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000365 {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000366 PyDoc_STR("() -> (CFTypeRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000367 {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000368 PyDoc_STR("() -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000369 {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000370 PyDoc_STR("() -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000371 {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000372 PyDoc_STR("(CFTypeRef cf2) -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000373 {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000374 PyDoc_STR("() -> (CFHashCode _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000375 {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000376 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen79066342002-05-12 22:04:14 +0000377 {"CFPropertyListCreateXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateXMLData, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000378 PyDoc_STR("() -> (CFDataRef _rv)")},
Jack Jansen79066342002-05-12 22:04:14 +0000379 {"CFPropertyListCreateDeepCopy", (PyCFunction)CFTypeRefObj_CFPropertyListCreateDeepCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000380 PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000381 {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000382 PyDoc_STR("() -> None")},
Jack Jansen79066342002-05-12 22:04:14 +0000383 {"CFPropertyListCreateFromXMLData", (PyCFunction)CFTypeRefObj_CFPropertyListCreateFromXMLData, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000384 PyDoc_STR("(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)")},
Jack Jansen5ad6f7a2002-05-07 23:00:03 +0000385 {"toPython", (PyCFunction)CFTypeRefObj_toPython, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000386 PyDoc_STR("() -> (python_object)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000387 {NULL, NULL, 0}
388};
389
390PyMethodChain CFTypeRefObj_chain = { CFTypeRefObj_methods, NULL };
391
392static PyObject *CFTypeRefObj_getattr(CFTypeRefObject *self, char *name)
393{
394 return Py_FindMethodInChain(&CFTypeRefObj_chain, (PyObject *)self, name);
395}
396
397#define CFTypeRefObj_setattr NULL
398
399static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other)
400{
401 /* XXXX Or should we use CFEqual?? */
402 if ( self->ob_itself > other->ob_itself ) return 1;
403 if ( self->ob_itself < other->ob_itself ) return -1;
404 return 0;
405}
406
407static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
408{
409 char buf[100];
Jack Jansen234d0742002-12-23 22:35:38 +0000410 sprintf(buf, "<CFTypeRef type-%d object at 0x%8.8x for 0x%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000411 return PyString_FromString(buf);
412}
413
414static int CFTypeRefObj_hash(CFTypeRefObject *self)
415{
416 /* XXXX Or should we use CFHash?? */
417 return (int)self->ob_itself;
418}
419
420PyTypeObject CFTypeRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +0000421 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000422 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000423 "_CF.CFTypeRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000424 sizeof(CFTypeRefObject), /*tp_basicsize*/
425 0, /*tp_itemsize*/
426 /* methods */
427 (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
428 0, /*tp_print*/
429 (getattrfunc) CFTypeRefObj_getattr, /*tp_getattr*/
430 (setattrfunc) CFTypeRefObj_setattr, /*tp_setattr*/
431 (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
432 (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
433 (PyNumberMethods *)0, /* tp_as_number */
434 (PySequenceMethods *)0, /* tp_as_sequence */
435 (PyMappingMethods *)0, /* tp_as_mapping */
436 (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
437};
438
439/* ------------------- End object type CFTypeRef -------------------- */
440
441
442/* --------------------- Object type CFArrayRef --------------------- */
443
444PyTypeObject CFArrayRef_Type;
445
Jack Jansenf9557842002-12-19 21:24:35 +0000446#define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type || PyObject_TypeCheck((x), &CFArrayRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000447
448typedef struct CFArrayRefObject {
449 PyObject_HEAD
450 CFArrayRef ob_itself;
451 void (*ob_freeit)(CFTypeRef ptr);
452} CFArrayRefObject;
453
454PyObject *CFArrayRefObj_New(CFArrayRef itself)
455{
456 CFArrayRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +0000457 if (itself == NULL)
458 {
459 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
460 return NULL;
461 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000462 it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
463 if (it == NULL) return NULL;
464 it->ob_itself = itself;
465 it->ob_freeit = CFRelease;
466 return (PyObject *)it;
467}
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000468int CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000469{
470
471 if (v == Py_None) { *p_itself = NULL; return 1; }
472 /* Check for other CF objects here */
473
474 if (!CFArrayRefObj_Check(v))
475 {
476 PyErr_SetString(PyExc_TypeError, "CFArrayRef required");
477 return 0;
478 }
479 *p_itself = ((CFArrayRefObject *)v)->ob_itself;
480 return 1;
481}
482
483static void CFArrayRefObj_dealloc(CFArrayRefObject *self)
484{
485 if (self->ob_freeit && self->ob_itself)
486 {
487 self->ob_freeit((CFTypeRef)self->ob_itself);
488 }
Jack Jansen234d0742002-12-23 22:35:38 +0000489 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000490}
491
492static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
493{
494 PyObject *_res = NULL;
495 CFArrayRef _rv;
496 if (!PyArg_ParseTuple(_args, ""))
497 return NULL;
498 _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
499 _self->ob_itself);
500 _res = Py_BuildValue("O&",
501 CFArrayRefObj_New, _rv);
502 return _res;
503}
504
505static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
506{
507 PyObject *_res = NULL;
508 CFIndex _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000509#ifndef CFArrayGetCount
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000510 PyMac_PRECHECK(CFArrayGetCount);
Jack Jansenb3be2162001-11-30 14:16:36 +0000511#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000512 if (!PyArg_ParseTuple(_args, ""))
513 return NULL;
514 _rv = CFArrayGetCount(_self->ob_itself);
515 _res = Py_BuildValue("l",
516 _rv);
517 return _res;
518}
519
520static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
521{
522 PyObject *_res = NULL;
523 CFStringRef _rv;
524 CFStringRef separatorString;
525 if (!PyArg_ParseTuple(_args, "O&",
526 CFStringRefObj_Convert, &separatorString))
527 return NULL;
528 _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
529 _self->ob_itself,
530 separatorString);
531 _res = Py_BuildValue("O&",
532 CFStringRefObj_New, _rv);
533 return _res;
534}
535
536static PyMethodDef CFArrayRefObj_methods[] = {
537 {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000538 PyDoc_STR("() -> (CFArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000539 {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000540 PyDoc_STR("() -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000541 {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000542 PyDoc_STR("(CFStringRef separatorString) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000543 {NULL, NULL, 0}
544};
545
546PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, &CFTypeRefObj_chain };
547
548static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name)
549{
550 return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name);
551}
552
553#define CFArrayRefObj_setattr NULL
554
555static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other)
556{
557 /* XXXX Or should we use CFEqual?? */
558 if ( self->ob_itself > other->ob_itself ) return 1;
559 if ( self->ob_itself < other->ob_itself ) return -1;
560 return 0;
561}
562
563static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
564{
565 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +0000566 sprintf(buf, "<CFArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000567 return PyString_FromString(buf);
568}
569
570static int CFArrayRefObj_hash(CFArrayRefObject *self)
571{
572 /* XXXX Or should we use CFHash?? */
573 return (int)self->ob_itself;
574}
575
576PyTypeObject CFArrayRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +0000577 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000578 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000579 "_CF.CFArrayRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000580 sizeof(CFArrayRefObject), /*tp_basicsize*/
581 0, /*tp_itemsize*/
582 /* methods */
583 (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
584 0, /*tp_print*/
585 (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/
586 (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/
587 (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/
588 (reprfunc) CFArrayRefObj_repr, /*tp_repr*/
589 (PyNumberMethods *)0, /* tp_as_number */
590 (PySequenceMethods *)0, /* tp_as_sequence */
591 (PyMappingMethods *)0, /* tp_as_mapping */
592 (hashfunc) CFArrayRefObj_hash, /*tp_hash*/
593};
594
595/* ------------------- End object type CFArrayRef ------------------- */
596
597
598/* ----------------- Object type CFMutableArrayRef ------------------ */
599
600PyTypeObject CFMutableArrayRef_Type;
601
Jack Jansenf9557842002-12-19 21:24:35 +0000602#define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type || PyObject_TypeCheck((x), &CFMutableArrayRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000603
604typedef struct CFMutableArrayRefObject {
605 PyObject_HEAD
606 CFMutableArrayRef ob_itself;
607 void (*ob_freeit)(CFTypeRef ptr);
608} CFMutableArrayRefObject;
609
610PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself)
611{
612 CFMutableArrayRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +0000613 if (itself == NULL)
614 {
615 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
616 return NULL;
617 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000618 it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
619 if (it == NULL) return NULL;
620 it->ob_itself = itself;
621 it->ob_freeit = CFRelease;
622 return (PyObject *)it;
623}
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000624int CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000625{
626
627 if (v == Py_None) { *p_itself = NULL; return 1; }
628 /* Check for other CF objects here */
629
630 if (!CFMutableArrayRefObj_Check(v))
631 {
632 PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required");
633 return 0;
634 }
635 *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself;
636 return 1;
637}
638
639static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self)
640{
641 if (self->ob_freeit && self->ob_itself)
642 {
643 self->ob_freeit((CFTypeRef)self->ob_itself);
644 }
Jack Jansen234d0742002-12-23 22:35:38 +0000645 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000646}
647
648static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
649{
650 PyObject *_res = NULL;
651 CFIndex idx;
Jack Jansenb3be2162001-11-30 14:16:36 +0000652#ifndef CFArrayRemoveValueAtIndex
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000653 PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
Jack Jansenb3be2162001-11-30 14:16:36 +0000654#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000655 if (!PyArg_ParseTuple(_args, "l",
656 &idx))
657 return NULL;
658 CFArrayRemoveValueAtIndex(_self->ob_itself,
659 idx);
660 Py_INCREF(Py_None);
661 _res = Py_None;
662 return _res;
663}
664
665static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args)
666{
667 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +0000668#ifndef CFArrayRemoveAllValues
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000669 PyMac_PRECHECK(CFArrayRemoveAllValues);
Jack Jansenb3be2162001-11-30 14:16:36 +0000670#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000671 if (!PyArg_ParseTuple(_args, ""))
672 return NULL;
673 CFArrayRemoveAllValues(_self->ob_itself);
674 Py_INCREF(Py_None);
675 _res = Py_None;
676 return _res;
677}
678
679static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args)
680{
681 PyObject *_res = NULL;
682 CFIndex idx1;
683 CFIndex idx2;
Jack Jansenb3be2162001-11-30 14:16:36 +0000684#ifndef CFArrayExchangeValuesAtIndices
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000685 PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
Jack Jansenb3be2162001-11-30 14:16:36 +0000686#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000687 if (!PyArg_ParseTuple(_args, "ll",
688 &idx1,
689 &idx2))
690 return NULL;
691 CFArrayExchangeValuesAtIndices(_self->ob_itself,
692 idx1,
693 idx2);
694 Py_INCREF(Py_None);
695 _res = Py_None;
696 return _res;
697}
698
Jack Jansen2168e9d2001-12-16 20:18:40 +0000699static PyObject *CFMutableArrayRefObj_CFArrayAppendArray(CFMutableArrayRefObject *_self, PyObject *_args)
700{
701 PyObject *_res = NULL;
702 CFArrayRef otherArray;
703 CFRange otherRange;
704#ifndef CFArrayAppendArray
705 PyMac_PRECHECK(CFArrayAppendArray);
706#endif
707 if (!PyArg_ParseTuple(_args, "O&O&",
708 CFArrayRefObj_Convert, &otherArray,
709 CFRange_Convert, &otherRange))
710 return NULL;
711 CFArrayAppendArray(_self->ob_itself,
712 otherArray,
713 otherRange);
714 Py_INCREF(Py_None);
715 _res = Py_None;
716 return _res;
717}
718
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000719static PyMethodDef CFMutableArrayRefObj_methods[] = {
720 {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000721 PyDoc_STR("(CFIndex idx) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000722 {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000723 PyDoc_STR("() -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000724 {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000725 PyDoc_STR("(CFIndex idx1, CFIndex idx2) -> None")},
Jack Jansen2168e9d2001-12-16 20:18:40 +0000726 {"CFArrayAppendArray", (PyCFunction)CFMutableArrayRefObj_CFArrayAppendArray, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000727 PyDoc_STR("(CFArrayRef otherArray, CFRange otherRange) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000728 {NULL, NULL, 0}
729};
730
731PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, &CFArrayRefObj_chain };
732
733static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name)
734{
735 return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name);
736}
737
738#define CFMutableArrayRefObj_setattr NULL
739
740static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other)
741{
742 /* XXXX Or should we use CFEqual?? */
743 if ( self->ob_itself > other->ob_itself ) return 1;
744 if ( self->ob_itself < other->ob_itself ) return -1;
745 return 0;
746}
747
748static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
749{
750 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +0000751 sprintf(buf, "<CFMutableArrayRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000752 return PyString_FromString(buf);
753}
754
755static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
756{
757 /* XXXX Or should we use CFHash?? */
758 return (int)self->ob_itself;
759}
760
761PyTypeObject CFMutableArrayRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +0000762 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000763 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000764 "_CF.CFMutableArrayRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000765 sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
766 0, /*tp_itemsize*/
767 /* methods */
768 (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
769 0, /*tp_print*/
770 (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/
771 (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/
772 (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/
773 (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/
774 (PyNumberMethods *)0, /* tp_as_number */
775 (PySequenceMethods *)0, /* tp_as_sequence */
776 (PyMappingMethods *)0, /* tp_as_mapping */
777 (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/
778};
779
780/* --------------- End object type CFMutableArrayRef ---------------- */
781
782
783/* ------------------ Object type CFDictionaryRef ------------------- */
784
785PyTypeObject CFDictionaryRef_Type;
786
Jack Jansenf9557842002-12-19 21:24:35 +0000787#define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type || PyObject_TypeCheck((x), &CFDictionaryRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000788
789typedef struct CFDictionaryRefObject {
790 PyObject_HEAD
791 CFDictionaryRef ob_itself;
792 void (*ob_freeit)(CFTypeRef ptr);
793} CFDictionaryRefObject;
794
795PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself)
796{
797 CFDictionaryRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +0000798 if (itself == NULL)
799 {
800 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
801 return NULL;
802 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000803 it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
804 if (it == NULL) return NULL;
805 it->ob_itself = itself;
806 it->ob_freeit = CFRelease;
807 return (PyObject *)it;
808}
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000809int CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000810{
811
812 if (v == Py_None) { *p_itself = NULL; return 1; }
813 /* Check for other CF objects here */
814
815 if (!CFDictionaryRefObj_Check(v))
816 {
817 PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required");
818 return 0;
819 }
820 *p_itself = ((CFDictionaryRefObject *)v)->ob_itself;
821 return 1;
822}
823
824static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self)
825{
826 if (self->ob_freeit && self->ob_itself)
827 {
828 self->ob_freeit((CFTypeRef)self->ob_itself);
829 }
Jack Jansen234d0742002-12-23 22:35:38 +0000830 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000831}
832
833static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
834{
835 PyObject *_res = NULL;
836 CFDictionaryRef _rv;
837 if (!PyArg_ParseTuple(_args, ""))
838 return NULL;
839 _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
840 _self->ob_itself);
841 _res = Py_BuildValue("O&",
842 CFDictionaryRefObj_New, _rv);
843 return _res;
844}
845
846static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
847{
848 PyObject *_res = NULL;
849 CFIndex _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +0000850#ifndef CFDictionaryGetCount
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000851 PyMac_PRECHECK(CFDictionaryGetCount);
Jack Jansenb3be2162001-11-30 14:16:36 +0000852#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000853 if (!PyArg_ParseTuple(_args, ""))
854 return NULL;
855 _rv = CFDictionaryGetCount(_self->ob_itself);
856 _res = Py_BuildValue("l",
857 _rv);
858 return _res;
859}
860
861static PyMethodDef CFDictionaryRefObj_methods[] = {
862 {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000863 PyDoc_STR("() -> (CFDictionaryRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000864 {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000865 PyDoc_STR("() -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000866 {NULL, NULL, 0}
867};
868
869PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, &CFTypeRefObj_chain };
870
871static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name)
872{
873 return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name);
874}
875
876#define CFDictionaryRefObj_setattr NULL
877
878static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other)
879{
880 /* XXXX Or should we use CFEqual?? */
881 if ( self->ob_itself > other->ob_itself ) return 1;
882 if ( self->ob_itself < other->ob_itself ) return -1;
883 return 0;
884}
885
886static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
887{
888 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +0000889 sprintf(buf, "<CFDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000890 return PyString_FromString(buf);
891}
892
893static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
894{
895 /* XXXX Or should we use CFHash?? */
896 return (int)self->ob_itself;
897}
898
899PyTypeObject CFDictionaryRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +0000900 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000901 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000902 "_CF.CFDictionaryRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000903 sizeof(CFDictionaryRefObject), /*tp_basicsize*/
904 0, /*tp_itemsize*/
905 /* methods */
906 (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
907 0, /*tp_print*/
908 (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/
909 (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/
910 (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/
911 (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/
912 (PyNumberMethods *)0, /* tp_as_number */
913 (PySequenceMethods *)0, /* tp_as_sequence */
914 (PyMappingMethods *)0, /* tp_as_mapping */
915 (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/
916};
917
918/* ---------------- End object type CFDictionaryRef ----------------- */
919
920
921/* --------------- Object type CFMutableDictionaryRef --------------- */
922
923PyTypeObject CFMutableDictionaryRef_Type;
924
Jack Jansenf9557842002-12-19 21:24:35 +0000925#define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type || PyObject_TypeCheck((x), &CFMutableDictionaryRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000926
927typedef struct CFMutableDictionaryRefObject {
928 PyObject_HEAD
929 CFMutableDictionaryRef ob_itself;
930 void (*ob_freeit)(CFTypeRef ptr);
931} CFMutableDictionaryRefObject;
932
933PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself)
934{
935 CFMutableDictionaryRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +0000936 if (itself == NULL)
937 {
938 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
939 return NULL;
940 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000941 it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
942 if (it == NULL) return NULL;
943 it->ob_itself = itself;
944 it->ob_freeit = CFRelease;
945 return (PyObject *)it;
946}
Jack Jansen06d2e1a2001-09-04 22:19:18 +0000947int CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000948{
949
950 if (v == Py_None) { *p_itself = NULL; return 1; }
951 /* Check for other CF objects here */
952
953 if (!CFMutableDictionaryRefObj_Check(v))
954 {
955 PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required");
956 return 0;
957 }
958 *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself;
959 return 1;
960}
961
962static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self)
963{
964 if (self->ob_freeit && self->ob_itself)
965 {
966 self->ob_freeit((CFTypeRef)self->ob_itself);
967 }
Jack Jansen234d0742002-12-23 22:35:38 +0000968 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000969}
970
971static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
972{
973 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +0000974#ifndef CFDictionaryRemoveAllValues
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000975 PyMac_PRECHECK(CFDictionaryRemoveAllValues);
Jack Jansenb3be2162001-11-30 14:16:36 +0000976#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000977 if (!PyArg_ParseTuple(_args, ""))
978 return NULL;
979 CFDictionaryRemoveAllValues(_self->ob_itself);
980 Py_INCREF(Py_None);
981 _res = Py_None;
982 return _res;
983}
984
985static PyMethodDef CFMutableDictionaryRefObj_methods[] = {
986 {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1,
Jack Jansen49931882002-08-16 09:09:31 +0000987 PyDoc_STR("() -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +0000988 {NULL, NULL, 0}
989};
990
991PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, &CFDictionaryRefObj_chain };
992
993static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name)
994{
995 return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name);
996}
997
998#define CFMutableDictionaryRefObj_setattr NULL
999
1000static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other)
1001{
1002 /* XXXX Or should we use CFEqual?? */
1003 if ( self->ob_itself > other->ob_itself ) return 1;
1004 if ( self->ob_itself < other->ob_itself ) return -1;
1005 return 0;
1006}
1007
1008static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self)
1009{
1010 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00001011 sprintf(buf, "<CFMutableDictionaryRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001012 return PyString_FromString(buf);
1013}
1014
1015static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
1016{
1017 /* XXXX Or should we use CFHash?? */
1018 return (int)self->ob_itself;
1019}
1020
1021PyTypeObject CFMutableDictionaryRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00001022 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001023 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001024 "_CF.CFMutableDictionaryRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001025 sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
1026 0, /*tp_itemsize*/
1027 /* methods */
1028 (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
1029 0, /*tp_print*/
1030 (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/
1031 (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/
1032 (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/
1033 (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/
1034 (PyNumberMethods *)0, /* tp_as_number */
1035 (PySequenceMethods *)0, /* tp_as_sequence */
1036 (PyMappingMethods *)0, /* tp_as_mapping */
1037 (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/
1038};
1039
1040/* ------------- End object type CFMutableDictionaryRef ------------- */
1041
1042
1043/* --------------------- Object type CFDataRef ---------------------- */
1044
1045PyTypeObject CFDataRef_Type;
1046
Jack Jansenf9557842002-12-19 21:24:35 +00001047#define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type || PyObject_TypeCheck((x), &CFDataRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001048
1049typedef struct CFDataRefObject {
1050 PyObject_HEAD
1051 CFDataRef ob_itself;
1052 void (*ob_freeit)(CFTypeRef ptr);
1053} CFDataRefObject;
1054
1055PyObject *CFDataRefObj_New(CFDataRef itself)
1056{
1057 CFDataRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +00001058 if (itself == NULL)
1059 {
1060 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1061 return NULL;
1062 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001063 it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
1064 if (it == NULL) return NULL;
1065 it->ob_itself = itself;
1066 it->ob_freeit = CFRelease;
1067 return (PyObject *)it;
1068}
Jack Jansen06d2e1a2001-09-04 22:19:18 +00001069int CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001070{
1071
1072 if (v == Py_None) { *p_itself = NULL; return 1; }
Jack Jansen79066342002-05-12 22:04:14 +00001073 if (PyString_Check(v)) {
1074 char *cStr;
1075 int cLen;
1076 if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
1077 *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
1078 return 1;
1079 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001080
1081 if (!CFDataRefObj_Check(v))
1082 {
1083 PyErr_SetString(PyExc_TypeError, "CFDataRef required");
1084 return 0;
1085 }
1086 *p_itself = ((CFDataRefObject *)v)->ob_itself;
1087 return 1;
1088}
1089
1090static void CFDataRefObj_dealloc(CFDataRefObject *self)
1091{
1092 if (self->ob_freeit && self->ob_itself)
1093 {
1094 self->ob_freeit((CFTypeRef)self->ob_itself);
1095 }
Jack Jansen234d0742002-12-23 22:35:38 +00001096 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001097}
1098
1099static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
1100{
1101 PyObject *_res = NULL;
1102 CFDataRef _rv;
1103 if (!PyArg_ParseTuple(_args, ""))
1104 return NULL;
1105 _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
1106 _self->ob_itself);
1107 _res = Py_BuildValue("O&",
1108 CFDataRefObj_New, _rv);
1109 return _res;
1110}
1111
1112static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
1113{
1114 PyObject *_res = NULL;
1115 CFIndex _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001116#ifndef CFDataGetLength
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001117 PyMac_PRECHECK(CFDataGetLength);
Jack Jansenb3be2162001-11-30 14:16:36 +00001118#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001119 if (!PyArg_ParseTuple(_args, ""))
1120 return NULL;
1121 _rv = CFDataGetLength(_self->ob_itself);
1122 _res = Py_BuildValue("l",
1123 _rv);
1124 return _res;
1125}
1126
1127static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
1128{
1129 PyObject *_res = NULL;
1130 CFStringRef _rv;
1131 CFStringEncoding encoding;
1132 if (!PyArg_ParseTuple(_args, "l",
1133 &encoding))
1134 return NULL;
1135 _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
1136 _self->ob_itself,
1137 encoding);
1138 _res = Py_BuildValue("O&",
1139 CFStringRefObj_New, _rv);
1140 return _res;
1141}
1142
Jack Jansen79066342002-05-12 22:04:14 +00001143static PyObject *CFDataRefObj_CFDataGetData(CFDataRefObject *_self, PyObject *_args)
1144{
1145 PyObject *_res = NULL;
1146
1147 int size = CFDataGetLength(_self->ob_itself);
1148 char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
1149
1150 _res = (PyObject *)PyString_FromStringAndSize(data, size);
1151 return _res;
1152
1153}
1154
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001155static PyMethodDef CFDataRefObj_methods[] = {
1156 {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001157 PyDoc_STR("() -> (CFDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001158 {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001159 PyDoc_STR("() -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001160 {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001161 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen79066342002-05-12 22:04:14 +00001162 {"CFDataGetData", (PyCFunction)CFDataRefObj_CFDataGetData, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001163 PyDoc_STR("() -> (string _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001164 {NULL, NULL, 0}
1165};
1166
1167PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, &CFTypeRefObj_chain };
1168
1169static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name)
1170{
1171 return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name);
1172}
1173
1174#define CFDataRefObj_setattr NULL
1175
1176static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other)
1177{
1178 /* XXXX Or should we use CFEqual?? */
1179 if ( self->ob_itself > other->ob_itself ) return 1;
1180 if ( self->ob_itself < other->ob_itself ) return -1;
1181 return 0;
1182}
1183
1184static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
1185{
1186 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00001187 sprintf(buf, "<CFDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001188 return PyString_FromString(buf);
1189}
1190
1191static int CFDataRefObj_hash(CFDataRefObject *self)
1192{
1193 /* XXXX Or should we use CFHash?? */
1194 return (int)self->ob_itself;
1195}
1196
1197PyTypeObject CFDataRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00001198 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001199 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001200 "_CF.CFDataRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001201 sizeof(CFDataRefObject), /*tp_basicsize*/
1202 0, /*tp_itemsize*/
1203 /* methods */
1204 (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
1205 0, /*tp_print*/
1206 (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/
1207 (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/
1208 (cmpfunc) CFDataRefObj_compare, /*tp_compare*/
1209 (reprfunc) CFDataRefObj_repr, /*tp_repr*/
1210 (PyNumberMethods *)0, /* tp_as_number */
1211 (PySequenceMethods *)0, /* tp_as_sequence */
1212 (PyMappingMethods *)0, /* tp_as_mapping */
1213 (hashfunc) CFDataRefObj_hash, /*tp_hash*/
1214};
1215
1216/* ------------------- End object type CFDataRef -------------------- */
1217
1218
1219/* ------------------ Object type CFMutableDataRef ------------------ */
1220
1221PyTypeObject CFMutableDataRef_Type;
1222
Jack Jansenf9557842002-12-19 21:24:35 +00001223#define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type || PyObject_TypeCheck((x), &CFMutableDataRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001224
1225typedef struct CFMutableDataRefObject {
1226 PyObject_HEAD
1227 CFMutableDataRef ob_itself;
1228 void (*ob_freeit)(CFTypeRef ptr);
1229} CFMutableDataRefObject;
1230
1231PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself)
1232{
1233 CFMutableDataRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +00001234 if (itself == NULL)
1235 {
1236 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1237 return NULL;
1238 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001239 it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
1240 if (it == NULL) return NULL;
1241 it->ob_itself = itself;
1242 it->ob_freeit = CFRelease;
1243 return (PyObject *)it;
1244}
Jack Jansen06d2e1a2001-09-04 22:19:18 +00001245int CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001246{
1247
1248 if (v == Py_None) { *p_itself = NULL; return 1; }
1249 /* Check for other CF objects here */
1250
1251 if (!CFMutableDataRefObj_Check(v))
1252 {
1253 PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required");
1254 return 0;
1255 }
1256 *p_itself = ((CFMutableDataRefObject *)v)->ob_itself;
1257 return 1;
1258}
1259
1260static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self)
1261{
1262 if (self->ob_freeit && self->ob_itself)
1263 {
1264 self->ob_freeit((CFTypeRef)self->ob_itself);
1265 }
Jack Jansen234d0742002-12-23 22:35:38 +00001266 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001267}
1268
1269static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
1270{
1271 PyObject *_res = NULL;
1272 CFIndex length;
Jack Jansenb3be2162001-11-30 14:16:36 +00001273#ifndef CFDataSetLength
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001274 PyMac_PRECHECK(CFDataSetLength);
Jack Jansenb3be2162001-11-30 14:16:36 +00001275#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001276 if (!PyArg_ParseTuple(_args, "l",
1277 &length))
1278 return NULL;
1279 CFDataSetLength(_self->ob_itself,
1280 length);
1281 Py_INCREF(Py_None);
1282 _res = Py_None;
1283 return _res;
1284}
1285
1286static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args)
1287{
1288 PyObject *_res = NULL;
1289 CFIndex extraLength;
Jack Jansenb3be2162001-11-30 14:16:36 +00001290#ifndef CFDataIncreaseLength
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001291 PyMac_PRECHECK(CFDataIncreaseLength);
Jack Jansenb3be2162001-11-30 14:16:36 +00001292#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001293 if (!PyArg_ParseTuple(_args, "l",
1294 &extraLength))
1295 return NULL;
1296 CFDataIncreaseLength(_self->ob_itself,
1297 extraLength);
1298 Py_INCREF(Py_None);
1299 _res = Py_None;
1300 return _res;
1301}
1302
1303static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args)
1304{
1305 PyObject *_res = NULL;
1306 unsigned char *bytes__in__;
1307 long bytes__len__;
1308 int bytes__in_len__;
Jack Jansenb3be2162001-11-30 14:16:36 +00001309#ifndef CFDataAppendBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001310 PyMac_PRECHECK(CFDataAppendBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00001311#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001312 if (!PyArg_ParseTuple(_args, "s#",
1313 &bytes__in__, &bytes__in_len__))
1314 return NULL;
1315 bytes__len__ = bytes__in_len__;
1316 CFDataAppendBytes(_self->ob_itself,
1317 bytes__in__, bytes__len__);
1318 Py_INCREF(Py_None);
1319 _res = Py_None;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001320 return _res;
1321}
1322
1323static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args)
1324{
1325 PyObject *_res = NULL;
1326 CFRange range;
1327 unsigned char *newBytes__in__;
1328 long newBytes__len__;
1329 int newBytes__in_len__;
Jack Jansenb3be2162001-11-30 14:16:36 +00001330#ifndef CFDataReplaceBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001331 PyMac_PRECHECK(CFDataReplaceBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00001332#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001333 if (!PyArg_ParseTuple(_args, "O&s#",
1334 CFRange_Convert, &range,
1335 &newBytes__in__, &newBytes__in_len__))
1336 return NULL;
1337 newBytes__len__ = newBytes__in_len__;
1338 CFDataReplaceBytes(_self->ob_itself,
1339 range,
1340 newBytes__in__, newBytes__len__);
1341 Py_INCREF(Py_None);
1342 _res = Py_None;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001343 return _res;
1344}
1345
1346static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
1347{
1348 PyObject *_res = NULL;
1349 CFRange range;
Jack Jansenb3be2162001-11-30 14:16:36 +00001350#ifndef CFDataDeleteBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001351 PyMac_PRECHECK(CFDataDeleteBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00001352#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001353 if (!PyArg_ParseTuple(_args, "O&",
1354 CFRange_Convert, &range))
1355 return NULL;
1356 CFDataDeleteBytes(_self->ob_itself,
1357 range);
1358 Py_INCREF(Py_None);
1359 _res = Py_None;
1360 return _res;
1361}
1362
1363static PyMethodDef CFMutableDataRefObj_methods[] = {
1364 {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001365 PyDoc_STR("(CFIndex length) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001366 {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001367 PyDoc_STR("(CFIndex extraLength) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001368 {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001369 PyDoc_STR("(Buffer bytes) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001370 {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001371 PyDoc_STR("(CFRange range, Buffer newBytes) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001372 {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00001373 PyDoc_STR("(CFRange range) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001374 {NULL, NULL, 0}
1375};
1376
1377PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, &CFDataRefObj_chain };
1378
1379static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name)
1380{
1381 return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name);
1382}
1383
1384#define CFMutableDataRefObj_setattr NULL
1385
1386static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other)
1387{
1388 /* XXXX Or should we use CFEqual?? */
1389 if ( self->ob_itself > other->ob_itself ) return 1;
1390 if ( self->ob_itself < other->ob_itself ) return -1;
1391 return 0;
1392}
1393
1394static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
1395{
1396 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00001397 sprintf(buf, "<CFMutableDataRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001398 return PyString_FromString(buf);
1399}
1400
1401static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
1402{
1403 /* XXXX Or should we use CFHash?? */
1404 return (int)self->ob_itself;
1405}
1406
1407PyTypeObject CFMutableDataRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00001408 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001409 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001410 "_CF.CFMutableDataRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001411 sizeof(CFMutableDataRefObject), /*tp_basicsize*/
1412 0, /*tp_itemsize*/
1413 /* methods */
1414 (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/
1415 0, /*tp_print*/
1416 (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/
1417 (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/
1418 (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/
1419 (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/
1420 (PyNumberMethods *)0, /* tp_as_number */
1421 (PySequenceMethods *)0, /* tp_as_sequence */
1422 (PyMappingMethods *)0, /* tp_as_mapping */
1423 (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/
1424};
1425
1426/* ---------------- End object type CFMutableDataRef ---------------- */
1427
1428
1429/* -------------------- Object type CFStringRef --------------------- */
1430
1431PyTypeObject CFStringRef_Type;
1432
Jack Jansenf9557842002-12-19 21:24:35 +00001433#define CFStringRefObj_Check(x) ((x)->ob_type == &CFStringRef_Type || PyObject_TypeCheck((x), &CFStringRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001434
1435typedef struct CFStringRefObject {
1436 PyObject_HEAD
1437 CFStringRef ob_itself;
1438 void (*ob_freeit)(CFTypeRef ptr);
1439} CFStringRefObject;
1440
1441PyObject *CFStringRefObj_New(CFStringRef itself)
1442{
1443 CFStringRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +00001444 if (itself == NULL)
1445 {
1446 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
1447 return NULL;
1448 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001449 it = PyObject_NEW(CFStringRefObject, &CFStringRef_Type);
1450 if (it == NULL) return NULL;
1451 it->ob_itself = itself;
1452 it->ob_freeit = CFRelease;
1453 return (PyObject *)it;
1454}
Jack Jansen06d2e1a2001-09-04 22:19:18 +00001455int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001456{
1457
1458 if (v == Py_None) { *p_itself = NULL; return 1; }
1459 if (PyString_Check(v)) {
1460 char *cStr = PyString_AsString(v);
1461 *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
1462 return 1;
1463 }
1464 if (PyUnicode_Check(v)) {
1465 /* We use the CF types here, if Python was configured differently that will give an error */
1466 CFIndex size = PyUnicode_GetSize(v);
1467 UniChar *unichars = PyUnicode_AsUnicode(v);
1468 if (!unichars) return 0;
1469 *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
1470 return 1;
1471 }
1472
1473
1474 if (!CFStringRefObj_Check(v))
1475 {
1476 PyErr_SetString(PyExc_TypeError, "CFStringRef required");
1477 return 0;
1478 }
1479 *p_itself = ((CFStringRefObject *)v)->ob_itself;
1480 return 1;
1481}
1482
1483static void CFStringRefObj_dealloc(CFStringRefObject *self)
1484{
1485 if (self->ob_freeit && self->ob_itself)
1486 {
1487 self->ob_freeit((CFTypeRef)self->ob_itself);
1488 }
Jack Jansen234d0742002-12-23 22:35:38 +00001489 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001490}
1491
1492static PyObject *CFStringRefObj_CFStringCreateWithSubstring(CFStringRefObject *_self, PyObject *_args)
1493{
1494 PyObject *_res = NULL;
1495 CFStringRef _rv;
1496 CFRange range;
1497 if (!PyArg_ParseTuple(_args, "O&",
1498 CFRange_Convert, &range))
1499 return NULL;
1500 _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL,
1501 _self->ob_itself,
1502 range);
1503 _res = Py_BuildValue("O&",
1504 CFStringRefObj_New, _rv);
1505 return _res;
1506}
1507
1508static PyObject *CFStringRefObj_CFStringCreateCopy(CFStringRefObject *_self, PyObject *_args)
1509{
1510 PyObject *_res = NULL;
1511 CFStringRef _rv;
1512 if (!PyArg_ParseTuple(_args, ""))
1513 return NULL;
1514 _rv = CFStringCreateCopy((CFAllocatorRef)NULL,
1515 _self->ob_itself);
1516 _res = Py_BuildValue("O&",
1517 CFStringRefObj_New, _rv);
1518 return _res;
1519}
1520
1521static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args)
1522{
1523 PyObject *_res = NULL;
1524 CFIndex _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001525#ifndef CFStringGetLength
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001526 PyMac_PRECHECK(CFStringGetLength);
Jack Jansenb3be2162001-11-30 14:16:36 +00001527#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001528 if (!PyArg_ParseTuple(_args, ""))
1529 return NULL;
1530 _rv = CFStringGetLength(_self->ob_itself);
1531 _res = Py_BuildValue("l",
1532 _rv);
1533 return _res;
1534}
1535
1536static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args)
1537{
1538 PyObject *_res = NULL;
1539 CFIndex _rv;
1540 CFRange range;
1541 CFStringEncoding encoding;
1542 UInt8 lossByte;
1543 Boolean isExternalRepresentation;
1544 UInt8 buffer;
1545 CFIndex maxBufLen;
1546 CFIndex usedBufLen;
Jack Jansenb3be2162001-11-30 14:16:36 +00001547#ifndef CFStringGetBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001548 PyMac_PRECHECK(CFStringGetBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00001549#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001550 if (!PyArg_ParseTuple(_args, "O&lbll",
1551 CFRange_Convert, &range,
1552 &encoding,
1553 &lossByte,
1554 &isExternalRepresentation,
1555 &maxBufLen))
1556 return NULL;
1557 _rv = CFStringGetBytes(_self->ob_itself,
1558 range,
1559 encoding,
1560 lossByte,
1561 isExternalRepresentation,
1562 &buffer,
1563 maxBufLen,
1564 &usedBufLen);
1565 _res = Py_BuildValue("lbl",
1566 _rv,
1567 buffer,
1568 usedBufLen);
1569 return _res;
1570}
1571
1572static PyObject *CFStringRefObj_CFStringCreateExternalRepresentation(CFStringRefObject *_self, PyObject *_args)
1573{
1574 PyObject *_res = NULL;
1575 CFDataRef _rv;
1576 CFStringEncoding encoding;
1577 UInt8 lossByte;
1578 if (!PyArg_ParseTuple(_args, "lb",
1579 &encoding,
1580 &lossByte))
1581 return NULL;
1582 _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL,
1583 _self->ob_itself,
1584 encoding,
1585 lossByte);
1586 _res = Py_BuildValue("O&",
1587 CFDataRefObj_New, _rv);
1588 return _res;
1589}
1590
1591static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args)
1592{
1593 PyObject *_res = NULL;
1594 CFStringEncoding _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001595#ifndef CFStringGetSmallestEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001596 PyMac_PRECHECK(CFStringGetSmallestEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00001597#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001598 if (!PyArg_ParseTuple(_args, ""))
1599 return NULL;
1600 _rv = CFStringGetSmallestEncoding(_self->ob_itself);
1601 _res = Py_BuildValue("l",
1602 _rv);
1603 return _res;
1604}
1605
1606static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args)
1607{
1608 PyObject *_res = NULL;
1609 CFStringEncoding _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001610#ifndef CFStringGetFastestEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001611 PyMac_PRECHECK(CFStringGetFastestEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00001612#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001613 if (!PyArg_ParseTuple(_args, ""))
1614 return NULL;
1615 _rv = CFStringGetFastestEncoding(_self->ob_itself);
1616 _res = Py_BuildValue("l",
1617 _rv);
1618 return _res;
1619}
1620
1621static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args)
1622{
1623 PyObject *_res = NULL;
1624 CFComparisonResult _rv;
Jack Jansen2168e9d2001-12-16 20:18:40 +00001625 CFStringRef theString2;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001626 CFRange rangeToCompare;
1627 CFOptionFlags compareOptions;
Jack Jansenb3be2162001-11-30 14:16:36 +00001628#ifndef CFStringCompareWithOptions
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001629 PyMac_PRECHECK(CFStringCompareWithOptions);
Jack Jansenb3be2162001-11-30 14:16:36 +00001630#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001631 if (!PyArg_ParseTuple(_args, "O&O&l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00001632 CFStringRefObj_Convert, &theString2,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001633 CFRange_Convert, &rangeToCompare,
1634 &compareOptions))
1635 return NULL;
1636 _rv = CFStringCompareWithOptions(_self->ob_itself,
Jack Jansen2168e9d2001-12-16 20:18:40 +00001637 theString2,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001638 rangeToCompare,
1639 compareOptions);
1640 _res = Py_BuildValue("l",
1641 _rv);
1642 return _res;
1643}
1644
1645static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args)
1646{
1647 PyObject *_res = NULL;
1648 CFComparisonResult _rv;
Jack Jansen2168e9d2001-12-16 20:18:40 +00001649 CFStringRef theString2;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001650 CFOptionFlags compareOptions;
Jack Jansenb3be2162001-11-30 14:16:36 +00001651#ifndef CFStringCompare
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001652 PyMac_PRECHECK(CFStringCompare);
Jack Jansenb3be2162001-11-30 14:16:36 +00001653#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001654 if (!PyArg_ParseTuple(_args, "O&l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00001655 CFStringRefObj_Convert, &theString2,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001656 &compareOptions))
1657 return NULL;
1658 _rv = CFStringCompare(_self->ob_itself,
Jack Jansen2168e9d2001-12-16 20:18:40 +00001659 theString2,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001660 compareOptions);
1661 _res = Py_BuildValue("l",
1662 _rv);
1663 return _res;
1664}
1665
1666static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args)
1667{
1668 PyObject *_res = NULL;
1669 Boolean _rv;
1670 CFStringRef stringToFind;
1671 CFRange rangeToSearch;
1672 CFOptionFlags searchOptions;
1673 CFRange result;
Jack Jansenb3be2162001-11-30 14:16:36 +00001674#ifndef CFStringFindWithOptions
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001675 PyMac_PRECHECK(CFStringFindWithOptions);
Jack Jansenb3be2162001-11-30 14:16:36 +00001676#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001677 if (!PyArg_ParseTuple(_args, "O&O&l",
1678 CFStringRefObj_Convert, &stringToFind,
1679 CFRange_Convert, &rangeToSearch,
1680 &searchOptions))
1681 return NULL;
1682 _rv = CFStringFindWithOptions(_self->ob_itself,
1683 stringToFind,
1684 rangeToSearch,
1685 searchOptions,
1686 &result);
1687 _res = Py_BuildValue("lO&",
1688 _rv,
1689 CFRange_New, result);
1690 return _res;
1691}
1692
1693static PyObject *CFStringRefObj_CFStringCreateArrayWithFindResults(CFStringRefObject *_self, PyObject *_args)
1694{
1695 PyObject *_res = NULL;
1696 CFArrayRef _rv;
1697 CFStringRef stringToFind;
1698 CFRange rangeToSearch;
1699 CFOptionFlags compareOptions;
1700 if (!PyArg_ParseTuple(_args, "O&O&l",
1701 CFStringRefObj_Convert, &stringToFind,
1702 CFRange_Convert, &rangeToSearch,
1703 &compareOptions))
1704 return NULL;
1705 _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL,
1706 _self->ob_itself,
1707 stringToFind,
1708 rangeToSearch,
1709 compareOptions);
1710 _res = Py_BuildValue("O&",
1711 CFArrayRefObj_New, _rv);
1712 return _res;
1713}
1714
1715static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args)
1716{
1717 PyObject *_res = NULL;
1718 CFRange _rv;
1719 CFStringRef stringToFind;
1720 CFOptionFlags compareOptions;
Jack Jansenb3be2162001-11-30 14:16:36 +00001721#ifndef CFStringFind
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001722 PyMac_PRECHECK(CFStringFind);
Jack Jansenb3be2162001-11-30 14:16:36 +00001723#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001724 if (!PyArg_ParseTuple(_args, "O&l",
1725 CFStringRefObj_Convert, &stringToFind,
1726 &compareOptions))
1727 return NULL;
1728 _rv = CFStringFind(_self->ob_itself,
1729 stringToFind,
1730 compareOptions);
1731 _res = Py_BuildValue("O&",
1732 CFRange_New, _rv);
1733 return _res;
1734}
1735
1736static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args)
1737{
1738 PyObject *_res = NULL;
1739 Boolean _rv;
1740 CFStringRef prefix;
Jack Jansenb3be2162001-11-30 14:16:36 +00001741#ifndef CFStringHasPrefix
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001742 PyMac_PRECHECK(CFStringHasPrefix);
Jack Jansenb3be2162001-11-30 14:16:36 +00001743#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001744 if (!PyArg_ParseTuple(_args, "O&",
1745 CFStringRefObj_Convert, &prefix))
1746 return NULL;
1747 _rv = CFStringHasPrefix(_self->ob_itself,
1748 prefix);
1749 _res = Py_BuildValue("l",
1750 _rv);
1751 return _res;
1752}
1753
1754static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args)
1755{
1756 PyObject *_res = NULL;
1757 Boolean _rv;
1758 CFStringRef suffix;
Jack Jansenb3be2162001-11-30 14:16:36 +00001759#ifndef CFStringHasSuffix
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001760 PyMac_PRECHECK(CFStringHasSuffix);
Jack Jansenb3be2162001-11-30 14:16:36 +00001761#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001762 if (!PyArg_ParseTuple(_args, "O&",
1763 CFStringRefObj_Convert, &suffix))
1764 return NULL;
1765 _rv = CFStringHasSuffix(_self->ob_itself,
1766 suffix);
1767 _res = Py_BuildValue("l",
1768 _rv);
1769 return _res;
1770}
1771
1772static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args)
1773{
1774 PyObject *_res = NULL;
1775 CFRange range;
1776 CFIndex lineBeginIndex;
1777 CFIndex lineEndIndex;
1778 CFIndex contentsEndIndex;
Jack Jansenb3be2162001-11-30 14:16:36 +00001779#ifndef CFStringGetLineBounds
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001780 PyMac_PRECHECK(CFStringGetLineBounds);
Jack Jansenb3be2162001-11-30 14:16:36 +00001781#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001782 if (!PyArg_ParseTuple(_args, "O&",
1783 CFRange_Convert, &range))
1784 return NULL;
1785 CFStringGetLineBounds(_self->ob_itself,
1786 range,
1787 &lineBeginIndex,
1788 &lineEndIndex,
1789 &contentsEndIndex);
1790 _res = Py_BuildValue("lll",
1791 lineBeginIndex,
1792 lineEndIndex,
1793 contentsEndIndex);
1794 return _res;
1795}
1796
1797static PyObject *CFStringRefObj_CFStringCreateArrayBySeparatingStrings(CFStringRefObject *_self, PyObject *_args)
1798{
1799 PyObject *_res = NULL;
1800 CFArrayRef _rv;
1801 CFStringRef separatorString;
1802 if (!PyArg_ParseTuple(_args, "O&",
1803 CFStringRefObj_Convert, &separatorString))
1804 return NULL;
1805 _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL,
1806 _self->ob_itself,
1807 separatorString);
1808 _res = Py_BuildValue("O&",
1809 CFArrayRefObj_New, _rv);
1810 return _res;
1811}
1812
1813static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args)
1814{
1815 PyObject *_res = NULL;
1816 SInt32 _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001817#ifndef CFStringGetIntValue
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001818 PyMac_PRECHECK(CFStringGetIntValue);
Jack Jansenb3be2162001-11-30 14:16:36 +00001819#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001820 if (!PyArg_ParseTuple(_args, ""))
1821 return NULL;
1822 _rv = CFStringGetIntValue(_self->ob_itself);
1823 _res = Py_BuildValue("l",
1824 _rv);
1825 return _res;
1826}
1827
1828static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args)
1829{
1830 PyObject *_res = NULL;
1831 double _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001832#ifndef CFStringGetDoubleValue
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001833 PyMac_PRECHECK(CFStringGetDoubleValue);
Jack Jansenb3be2162001-11-30 14:16:36 +00001834#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001835 if (!PyArg_ParseTuple(_args, ""))
1836 return NULL;
1837 _rv = CFStringGetDoubleValue(_self->ob_itself);
1838 _res = Py_BuildValue("d",
1839 _rv);
1840 return _res;
1841}
1842
1843static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args)
1844{
1845 PyObject *_res = NULL;
1846 CFStringEncoding _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00001847#ifndef CFStringConvertIANACharSetNameToEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001848 PyMac_PRECHECK(CFStringConvertIANACharSetNameToEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00001849#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001850 if (!PyArg_ParseTuple(_args, ""))
1851 return NULL;
1852 _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself);
1853 _res = Py_BuildValue("l",
1854 _rv);
1855 return _res;
1856}
1857
1858static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args)
1859{
1860 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +00001861#ifndef CFShowStr
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001862 PyMac_PRECHECK(CFShowStr);
Jack Jansenb3be2162001-11-30 14:16:36 +00001863#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001864 if (!PyArg_ParseTuple(_args, ""))
1865 return NULL;
1866 CFShowStr(_self->ob_itself);
1867 Py_INCREF(Py_None);
1868 _res = Py_None;
1869 return _res;
1870}
1871
1872static PyObject *CFStringRefObj_CFURLCreateWithString(CFStringRefObject *_self, PyObject *_args)
1873{
1874 PyObject *_res = NULL;
1875 CFURLRef _rv;
1876 CFURLRef baseURL;
1877 if (!PyArg_ParseTuple(_args, "O&",
1878 OptionalCFURLRefObj_Convert, &baseURL))
1879 return NULL;
1880 _rv = CFURLCreateWithString((CFAllocatorRef)NULL,
1881 _self->ob_itself,
1882 baseURL);
1883 _res = Py_BuildValue("O&",
1884 CFURLRefObj_New, _rv);
1885 return _res;
1886}
1887
1888static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPath(CFStringRefObject *_self, PyObject *_args)
1889{
1890 PyObject *_res = NULL;
1891 CFURLRef _rv;
1892 CFURLPathStyle pathStyle;
1893 Boolean isDirectory;
1894 if (!PyArg_ParseTuple(_args, "ll",
1895 &pathStyle,
1896 &isDirectory))
1897 return NULL;
1898 _rv = CFURLCreateWithFileSystemPath((CFAllocatorRef)NULL,
1899 _self->ob_itself,
1900 pathStyle,
1901 isDirectory);
1902 _res = Py_BuildValue("O&",
1903 CFURLRefObj_New, _rv);
1904 return _res;
1905}
1906
Jack Jansen2168e9d2001-12-16 20:18:40 +00001907static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase(CFStringRefObject *_self, PyObject *_args)
1908{
1909 PyObject *_res = NULL;
1910 CFURLRef _rv;
1911 CFURLPathStyle pathStyle;
1912 Boolean isDirectory;
1913 CFURLRef baseURL;
1914 if (!PyArg_ParseTuple(_args, "llO&",
1915 &pathStyle,
1916 &isDirectory,
1917 OptionalCFURLRefObj_Convert, &baseURL))
1918 return NULL;
1919 _rv = CFURLCreateWithFileSystemPathRelativeToBase((CFAllocatorRef)NULL,
1920 _self->ob_itself,
1921 pathStyle,
1922 isDirectory,
1923 baseURL);
1924 _res = Py_BuildValue("O&",
1925 CFURLRefObj_New, _rv);
1926 return _res;
1927}
1928
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001929static PyObject *CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
1930{
1931 PyObject *_res = NULL;
1932 CFStringRef _rv;
1933 CFStringRef charactersToLeaveEscaped;
1934 if (!PyArg_ParseTuple(_args, "O&",
1935 CFStringRefObj_Convert, &charactersToLeaveEscaped))
1936 return NULL;
1937 _rv = CFURLCreateStringByReplacingPercentEscapes((CFAllocatorRef)NULL,
1938 _self->ob_itself,
1939 charactersToLeaveEscaped);
1940 _res = Py_BuildValue("O&",
1941 CFStringRefObj_New, _rv);
1942 return _res;
1943}
1944
Jack Jansen2168e9d2001-12-16 20:18:40 +00001945static PyObject *CFStringRefObj_CFURLCreateStringByAddingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
1946{
1947 PyObject *_res = NULL;
1948 CFStringRef _rv;
1949 CFStringRef charactersToLeaveUnescaped;
1950 CFStringRef legalURLCharactersToBeEscaped;
1951 CFStringEncoding encoding;
1952 if (!PyArg_ParseTuple(_args, "O&O&l",
1953 CFStringRefObj_Convert, &charactersToLeaveUnescaped,
1954 CFStringRefObj_Convert, &legalURLCharactersToBeEscaped,
1955 &encoding))
1956 return NULL;
1957 _rv = CFURLCreateStringByAddingPercentEscapes((CFAllocatorRef)NULL,
1958 _self->ob_itself,
1959 charactersToLeaveUnescaped,
1960 legalURLCharactersToBeEscaped,
1961 encoding);
1962 _res = Py_BuildValue("O&",
1963 CFStringRefObj_New, _rv);
1964 return _res;
1965}
1966
Jack Jansen50ecb0a2001-08-23 14:02:09 +00001967static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyObject *_args)
1968{
1969 PyObject *_res = NULL;
1970
1971 int size = CFStringGetLength(_self->ob_itself)+1;
1972 char *data = malloc(size);
1973
1974 if( data == NULL ) return PyErr_NoMemory();
1975 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
1976 _res = (PyObject *)PyString_FromString(data);
1977 } else {
1978 PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
1979 _res = NULL;
1980 }
1981 free(data);
1982 return _res;
1983
1984}
1985
1986static PyObject *CFStringRefObj_CFStringGetUnicode(CFStringRefObject *_self, PyObject *_args)
1987{
1988 PyObject *_res = NULL;
1989
1990 int size = CFStringGetLength(_self->ob_itself)+1;
1991 Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
1992 CFRange range;
1993
1994 range.location = 0;
1995 range.length = size;
1996 if( data == NULL ) return PyErr_NoMemory();
1997 CFStringGetCharacters(_self->ob_itself, range, data);
1998 _res = (PyObject *)PyUnicode_FromUnicode(data, size);
1999 free(data);
2000 return _res;
2001
2002}
2003
2004static PyMethodDef CFStringRefObj_methods[] = {
2005 {"CFStringCreateWithSubstring", (PyCFunction)CFStringRefObj_CFStringCreateWithSubstring, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002006 PyDoc_STR("(CFRange range) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002007 {"CFStringCreateCopy", (PyCFunction)CFStringRefObj_CFStringCreateCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002008 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002009 {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002010 PyDoc_STR("() -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002011 {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002012 PyDoc_STR("(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002013 {"CFStringCreateExternalRepresentation", (PyCFunction)CFStringRefObj_CFStringCreateExternalRepresentation, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002014 PyDoc_STR("(CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002015 {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002016 PyDoc_STR("() -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002017 {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002018 PyDoc_STR("() -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002019 {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002020 PyDoc_STR("(CFStringRef theString2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002021 {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002022 PyDoc_STR("(CFStringRef theString2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002023 {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002024 PyDoc_STR("(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002025 {"CFStringCreateArrayWithFindResults", (PyCFunction)CFStringRefObj_CFStringCreateArrayWithFindResults, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002026 PyDoc_STR("(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002027 {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002028 PyDoc_STR("(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002029 {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002030 PyDoc_STR("(CFStringRef prefix) -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002031 {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002032 PyDoc_STR("(CFStringRef suffix) -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002033 {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002034 PyDoc_STR("(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002035 {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CFStringRefObj_CFStringCreateArrayBySeparatingStrings, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002036 PyDoc_STR("(CFStringRef separatorString) -> (CFArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002037 {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002038 PyDoc_STR("() -> (SInt32 _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002039 {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002040 PyDoc_STR("() -> (double _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002041 {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002042 PyDoc_STR("() -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002043 {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002044 PyDoc_STR("() -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002045 {"CFURLCreateWithString", (PyCFunction)CFStringRefObj_CFURLCreateWithString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002046 PyDoc_STR("(CFURLRef baseURL) -> (CFURLRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002047 {"CFURLCreateWithFileSystemPath", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPath, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002048 PyDoc_STR("(CFURLPathStyle pathStyle, Boolean isDirectory) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002049 {"CFURLCreateWithFileSystemPathRelativeToBase", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPathRelativeToBase, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002050 PyDoc_STR("(CFURLPathStyle pathStyle, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002051 {"CFURLCreateStringByReplacingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002052 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002053 {"CFURLCreateStringByAddingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByAddingPercentEscapes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002054 PyDoc_STR("(CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002055 {"CFStringGetString", (PyCFunction)CFStringRefObj_CFStringGetString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002056 PyDoc_STR("() -> (string _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002057 {"CFStringGetUnicode", (PyCFunction)CFStringRefObj_CFStringGetUnicode, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002058 PyDoc_STR("() -> (unicode _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002059 {NULL, NULL, 0}
2060};
2061
2062PyMethodChain CFStringRefObj_chain = { CFStringRefObj_methods, &CFTypeRefObj_chain };
2063
2064static PyObject *CFStringRefObj_getattr(CFStringRefObject *self, char *name)
2065{
2066 return Py_FindMethodInChain(&CFStringRefObj_chain, (PyObject *)self, name);
2067}
2068
2069#define CFStringRefObj_setattr NULL
2070
2071static int CFStringRefObj_compare(CFStringRefObject *self, CFStringRefObject *other)
2072{
2073 /* XXXX Or should we use CFEqual?? */
2074 if ( self->ob_itself > other->ob_itself ) return 1;
2075 if ( self->ob_itself < other->ob_itself ) return -1;
2076 return 0;
2077}
2078
2079static PyObject * CFStringRefObj_repr(CFStringRefObject *self)
2080{
2081 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00002082 sprintf(buf, "<CFStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002083 return PyString_FromString(buf);
2084}
2085
2086static int CFStringRefObj_hash(CFStringRefObject *self)
2087{
2088 /* XXXX Or should we use CFHash?? */
2089 return (int)self->ob_itself;
2090}
2091
2092PyTypeObject CFStringRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00002093 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002094 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00002095 "_CF.CFStringRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002096 sizeof(CFStringRefObject), /*tp_basicsize*/
2097 0, /*tp_itemsize*/
2098 /* methods */
2099 (destructor) CFStringRefObj_dealloc, /*tp_dealloc*/
2100 0, /*tp_print*/
2101 (getattrfunc) CFStringRefObj_getattr, /*tp_getattr*/
2102 (setattrfunc) CFStringRefObj_setattr, /*tp_setattr*/
2103 (cmpfunc) CFStringRefObj_compare, /*tp_compare*/
2104 (reprfunc) CFStringRefObj_repr, /*tp_repr*/
2105 (PyNumberMethods *)0, /* tp_as_number */
2106 (PySequenceMethods *)0, /* tp_as_sequence */
2107 (PyMappingMethods *)0, /* tp_as_mapping */
2108 (hashfunc) CFStringRefObj_hash, /*tp_hash*/
2109};
2110
2111/* ------------------ End object type CFStringRef ------------------- */
2112
2113
2114/* ----------------- Object type CFMutableStringRef ----------------- */
2115
2116PyTypeObject CFMutableStringRef_Type;
2117
Jack Jansenf9557842002-12-19 21:24:35 +00002118#define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type || PyObject_TypeCheck((x), &CFMutableStringRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002119
2120typedef struct CFMutableStringRefObject {
2121 PyObject_HEAD
2122 CFMutableStringRef ob_itself;
2123 void (*ob_freeit)(CFTypeRef ptr);
2124} CFMutableStringRefObject;
2125
2126PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself)
2127{
2128 CFMutableStringRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +00002129 if (itself == NULL)
2130 {
2131 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
2132 return NULL;
2133 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002134 it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type);
2135 if (it == NULL) return NULL;
2136 it->ob_itself = itself;
2137 it->ob_freeit = CFRelease;
2138 return (PyObject *)it;
2139}
Jack Jansen06d2e1a2001-09-04 22:19:18 +00002140int CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002141{
2142
2143 if (v == Py_None) { *p_itself = NULL; return 1; }
2144 /* Check for other CF objects here */
2145
2146 if (!CFMutableStringRefObj_Check(v))
2147 {
2148 PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required");
2149 return 0;
2150 }
2151 *p_itself = ((CFMutableStringRefObject *)v)->ob_itself;
2152 return 1;
2153}
2154
2155static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self)
2156{
2157 if (self->ob_freeit && self->ob_itself)
2158 {
2159 self->ob_freeit((CFTypeRef)self->ob_itself);
2160 }
Jack Jansen234d0742002-12-23 22:35:38 +00002161 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002162}
2163
2164static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args)
2165{
2166 PyObject *_res = NULL;
2167 CFStringRef appendedString;
Jack Jansenb3be2162001-11-30 14:16:36 +00002168#ifndef CFStringAppend
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002169 PyMac_PRECHECK(CFStringAppend);
Jack Jansenb3be2162001-11-30 14:16:36 +00002170#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002171 if (!PyArg_ParseTuple(_args, "O&",
2172 CFStringRefObj_Convert, &appendedString))
2173 return NULL;
2174 CFStringAppend(_self->ob_itself,
2175 appendedString);
2176 Py_INCREF(Py_None);
2177 _res = Py_None;
2178 return _res;
2179}
2180
Jack Jansen69ac3612002-01-01 22:43:13 +00002181static PyObject *CFMutableStringRefObj_CFStringAppendCharacters(CFMutableStringRefObject *_self, PyObject *_args)
2182{
2183 PyObject *_res = NULL;
2184 UniChar *chars__in__;
2185 UniCharCount chars__len__;
2186 int chars__in_len__;
2187#ifndef CFStringAppendCharacters
2188 PyMac_PRECHECK(CFStringAppendCharacters);
2189#endif
2190 if (!PyArg_ParseTuple(_args, "u#",
2191 &chars__in__, &chars__in_len__))
2192 return NULL;
2193 chars__len__ = chars__in_len__;
2194 CFStringAppendCharacters(_self->ob_itself,
2195 chars__in__, chars__len__);
2196 Py_INCREF(Py_None);
2197 _res = Py_None;
2198 return _res;
2199}
2200
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002201static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args)
2202{
2203 PyObject *_res = NULL;
Jack Jansen2168e9d2001-12-16 20:18:40 +00002204 Str255 pStr;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002205 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00002206#ifndef CFStringAppendPascalString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002207 PyMac_PRECHECK(CFStringAppendPascalString);
Jack Jansenb3be2162001-11-30 14:16:36 +00002208#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002209 if (!PyArg_ParseTuple(_args, "O&l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00002210 PyMac_GetStr255, pStr,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002211 &encoding))
2212 return NULL;
2213 CFStringAppendPascalString(_self->ob_itself,
2214 pStr,
2215 encoding);
2216 Py_INCREF(Py_None);
2217 _res = Py_None;
2218 return _res;
2219}
2220
2221static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args)
2222{
2223 PyObject *_res = NULL;
2224 char* cStr;
2225 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00002226#ifndef CFStringAppendCString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002227 PyMac_PRECHECK(CFStringAppendCString);
Jack Jansenb3be2162001-11-30 14:16:36 +00002228#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002229 if (!PyArg_ParseTuple(_args, "sl",
2230 &cStr,
2231 &encoding))
2232 return NULL;
2233 CFStringAppendCString(_self->ob_itself,
2234 cStr,
2235 encoding);
2236 Py_INCREF(Py_None);
2237 _res = Py_None;
2238 return _res;
2239}
2240
2241static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args)
2242{
2243 PyObject *_res = NULL;
2244 CFIndex idx;
2245 CFStringRef insertedStr;
Jack Jansenb3be2162001-11-30 14:16:36 +00002246#ifndef CFStringInsert
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002247 PyMac_PRECHECK(CFStringInsert);
Jack Jansenb3be2162001-11-30 14:16:36 +00002248#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002249 if (!PyArg_ParseTuple(_args, "lO&",
2250 &idx,
2251 CFStringRefObj_Convert, &insertedStr))
2252 return NULL;
2253 CFStringInsert(_self->ob_itself,
2254 idx,
2255 insertedStr);
2256 Py_INCREF(Py_None);
2257 _res = Py_None;
2258 return _res;
2259}
2260
2261static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args)
2262{
2263 PyObject *_res = NULL;
2264 CFRange range;
Jack Jansenb3be2162001-11-30 14:16:36 +00002265#ifndef CFStringDelete
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002266 PyMac_PRECHECK(CFStringDelete);
Jack Jansenb3be2162001-11-30 14:16:36 +00002267#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002268 if (!PyArg_ParseTuple(_args, "O&",
2269 CFRange_Convert, &range))
2270 return NULL;
2271 CFStringDelete(_self->ob_itself,
2272 range);
2273 Py_INCREF(Py_None);
2274 _res = Py_None;
2275 return _res;
2276}
2277
2278static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args)
2279{
2280 PyObject *_res = NULL;
2281 CFRange range;
2282 CFStringRef replacement;
Jack Jansenb3be2162001-11-30 14:16:36 +00002283#ifndef CFStringReplace
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002284 PyMac_PRECHECK(CFStringReplace);
Jack Jansenb3be2162001-11-30 14:16:36 +00002285#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002286 if (!PyArg_ParseTuple(_args, "O&O&",
2287 CFRange_Convert, &range,
2288 CFStringRefObj_Convert, &replacement))
2289 return NULL;
2290 CFStringReplace(_self->ob_itself,
2291 range,
2292 replacement);
2293 Py_INCREF(Py_None);
2294 _res = Py_None;
2295 return _res;
2296}
2297
2298static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args)
2299{
2300 PyObject *_res = NULL;
2301 CFStringRef replacement;
Jack Jansenb3be2162001-11-30 14:16:36 +00002302#ifndef CFStringReplaceAll
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002303 PyMac_PRECHECK(CFStringReplaceAll);
Jack Jansenb3be2162001-11-30 14:16:36 +00002304#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002305 if (!PyArg_ParseTuple(_args, "O&",
2306 CFStringRefObj_Convert, &replacement))
2307 return NULL;
2308 CFStringReplaceAll(_self->ob_itself,
2309 replacement);
2310 Py_INCREF(Py_None);
2311 _res = Py_None;
2312 return _res;
2313}
2314
2315static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args)
2316{
2317 PyObject *_res = NULL;
2318 CFStringRef padString;
2319 CFIndex length;
2320 CFIndex indexIntoPad;
Jack Jansenb3be2162001-11-30 14:16:36 +00002321#ifndef CFStringPad
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002322 PyMac_PRECHECK(CFStringPad);
Jack Jansenb3be2162001-11-30 14:16:36 +00002323#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002324 if (!PyArg_ParseTuple(_args, "O&ll",
2325 CFStringRefObj_Convert, &padString,
2326 &length,
2327 &indexIntoPad))
2328 return NULL;
2329 CFStringPad(_self->ob_itself,
2330 padString,
2331 length,
2332 indexIntoPad);
2333 Py_INCREF(Py_None);
2334 _res = Py_None;
2335 return _res;
2336}
2337
2338static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args)
2339{
2340 PyObject *_res = NULL;
2341 CFStringRef trimString;
Jack Jansenb3be2162001-11-30 14:16:36 +00002342#ifndef CFStringTrim
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002343 PyMac_PRECHECK(CFStringTrim);
Jack Jansenb3be2162001-11-30 14:16:36 +00002344#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002345 if (!PyArg_ParseTuple(_args, "O&",
2346 CFStringRefObj_Convert, &trimString))
2347 return NULL;
2348 CFStringTrim(_self->ob_itself,
2349 trimString);
2350 Py_INCREF(Py_None);
2351 _res = Py_None;
2352 return _res;
2353}
2354
2355static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args)
2356{
2357 PyObject *_res = NULL;
Jack Jansenb3be2162001-11-30 14:16:36 +00002358#ifndef CFStringTrimWhitespace
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002359 PyMac_PRECHECK(CFStringTrimWhitespace);
Jack Jansenb3be2162001-11-30 14:16:36 +00002360#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002361 if (!PyArg_ParseTuple(_args, ""))
2362 return NULL;
2363 CFStringTrimWhitespace(_self->ob_itself);
2364 Py_INCREF(Py_None);
2365 _res = Py_None;
2366 return _res;
2367}
2368
2369static PyMethodDef CFMutableStringRefObj_methods[] = {
2370 {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002371 PyDoc_STR("(CFStringRef appendedString) -> None")},
Jack Jansen69ac3612002-01-01 22:43:13 +00002372 {"CFStringAppendCharacters", (PyCFunction)CFMutableStringRefObj_CFStringAppendCharacters, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002373 PyDoc_STR("(Buffer chars) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002374 {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002375 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002376 {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002377 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002378 {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002379 PyDoc_STR("(CFIndex idx, CFStringRef insertedStr) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002380 {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002381 PyDoc_STR("(CFRange range) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002382 {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002383 PyDoc_STR("(CFRange range, CFStringRef replacement) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002384 {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002385 PyDoc_STR("(CFStringRef replacement) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002386 {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002387 PyDoc_STR("(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002388 {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002389 PyDoc_STR("(CFStringRef trimString) -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002390 {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002391 PyDoc_STR("() -> None")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002392 {NULL, NULL, 0}
2393};
2394
2395PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, &CFStringRefObj_chain };
2396
2397static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name)
2398{
2399 return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name);
2400}
2401
2402#define CFMutableStringRefObj_setattr NULL
2403
2404static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other)
2405{
2406 /* XXXX Or should we use CFEqual?? */
2407 if ( self->ob_itself > other->ob_itself ) return 1;
2408 if ( self->ob_itself < other->ob_itself ) return -1;
2409 return 0;
2410}
2411
2412static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self)
2413{
2414 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00002415 sprintf(buf, "<CFMutableStringRef object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002416 return PyString_FromString(buf);
2417}
2418
2419static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self)
2420{
2421 /* XXXX Or should we use CFHash?? */
2422 return (int)self->ob_itself;
2423}
2424
2425PyTypeObject CFMutableStringRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00002426 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002427 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00002428 "_CF.CFMutableStringRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002429 sizeof(CFMutableStringRefObject), /*tp_basicsize*/
2430 0, /*tp_itemsize*/
2431 /* methods */
2432 (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/
2433 0, /*tp_print*/
2434 (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/
2435 (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/
2436 (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/
2437 (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/
2438 (PyNumberMethods *)0, /* tp_as_number */
2439 (PySequenceMethods *)0, /* tp_as_sequence */
2440 (PyMappingMethods *)0, /* tp_as_mapping */
2441 (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/
2442};
2443
2444/* --------------- End object type CFMutableStringRef --------------- */
2445
2446
2447/* ---------------------- Object type CFURLRef ---------------------- */
2448
2449PyTypeObject CFURLRef_Type;
2450
Jack Jansenf9557842002-12-19 21:24:35 +00002451#define CFURLRefObj_Check(x) ((x)->ob_type == &CFURLRef_Type || PyObject_TypeCheck((x), &CFURLRef_Type))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002452
2453typedef struct CFURLRefObject {
2454 PyObject_HEAD
2455 CFURLRef ob_itself;
2456 void (*ob_freeit)(CFTypeRef ptr);
2457} CFURLRefObject;
2458
2459PyObject *CFURLRefObj_New(CFURLRef itself)
2460{
2461 CFURLRefObject *it;
Jack Jansen79066342002-05-12 22:04:14 +00002462 if (itself == NULL)
2463 {
2464 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
2465 return NULL;
2466 }
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002467 it = PyObject_NEW(CFURLRefObject, &CFURLRef_Type);
2468 if (it == NULL) return NULL;
2469 it->ob_itself = itself;
2470 it->ob_freeit = CFRelease;
2471 return (PyObject *)it;
2472}
Jack Jansen06d2e1a2001-09-04 22:19:18 +00002473int CFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002474{
2475
2476 if (v == Py_None) { *p_itself = NULL; return 1; }
2477 /* Check for other CF objects here */
2478
2479 if (!CFURLRefObj_Check(v))
2480 {
2481 PyErr_SetString(PyExc_TypeError, "CFURLRef required");
2482 return 0;
2483 }
2484 *p_itself = ((CFURLRefObject *)v)->ob_itself;
2485 return 1;
2486}
2487
2488static void CFURLRefObj_dealloc(CFURLRefObject *self)
2489{
2490 if (self->ob_freeit && self->ob_itself)
2491 {
2492 self->ob_freeit((CFTypeRef)self->ob_itself);
2493 }
Jack Jansen234d0742002-12-23 22:35:38 +00002494 PyObject_Free((PyObject *)self);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002495}
2496
2497static PyObject *CFURLRefObj_CFURLCreateData(CFURLRefObject *_self, PyObject *_args)
2498{
2499 PyObject *_res = NULL;
2500 CFDataRef _rv;
2501 CFStringEncoding encoding;
2502 Boolean escapeWhitespace;
2503 if (!PyArg_ParseTuple(_args, "ll",
2504 &encoding,
2505 &escapeWhitespace))
2506 return NULL;
2507 _rv = CFURLCreateData((CFAllocatorRef)NULL,
2508 _self->ob_itself,
2509 encoding,
2510 escapeWhitespace);
2511 _res = Py_BuildValue("O&",
2512 CFDataRefObj_New, _rv);
2513 return _res;
2514}
2515
Jack Jansen2168e9d2001-12-16 20:18:40 +00002516static PyObject *CFURLRefObj_CFURLGetFileSystemRepresentation(CFURLRefObject *_self, PyObject *_args)
2517{
2518 PyObject *_res = NULL;
2519 Boolean _rv;
2520 Boolean resolveAgainstBase;
2521 UInt8 buffer;
2522 CFIndex maxBufLen;
2523#ifndef CFURLGetFileSystemRepresentation
2524 PyMac_PRECHECK(CFURLGetFileSystemRepresentation);
2525#endif
2526 if (!PyArg_ParseTuple(_args, "ll",
2527 &resolveAgainstBase,
2528 &maxBufLen))
2529 return NULL;
2530 _rv = CFURLGetFileSystemRepresentation(_self->ob_itself,
2531 resolveAgainstBase,
2532 &buffer,
2533 maxBufLen);
2534 _res = Py_BuildValue("lb",
2535 _rv,
2536 buffer);
2537 return _res;
2538}
2539
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002540static PyObject *CFURLRefObj_CFURLCopyAbsoluteURL(CFURLRefObject *_self, PyObject *_args)
2541{
2542 PyObject *_res = NULL;
2543 CFURLRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002544#ifndef CFURLCopyAbsoluteURL
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002545 PyMac_PRECHECK(CFURLCopyAbsoluteURL);
Jack Jansenb3be2162001-11-30 14:16:36 +00002546#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002547 if (!PyArg_ParseTuple(_args, ""))
2548 return NULL;
2549 _rv = CFURLCopyAbsoluteURL(_self->ob_itself);
2550 _res = Py_BuildValue("O&",
2551 CFURLRefObj_New, _rv);
2552 return _res;
2553}
2554
2555static PyObject *CFURLRefObj_CFURLGetString(CFURLRefObject *_self, PyObject *_args)
2556{
2557 PyObject *_res = NULL;
2558 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002559#ifndef CFURLGetString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002560 PyMac_PRECHECK(CFURLGetString);
Jack Jansenb3be2162001-11-30 14:16:36 +00002561#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002562 if (!PyArg_ParseTuple(_args, ""))
2563 return NULL;
2564 _rv = CFURLGetString(_self->ob_itself);
2565 _res = Py_BuildValue("O&",
2566 CFStringRefObj_New, _rv);
2567 return _res;
2568}
2569
2570static PyObject *CFURLRefObj_CFURLGetBaseURL(CFURLRefObject *_self, PyObject *_args)
2571{
2572 PyObject *_res = NULL;
2573 CFURLRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002574#ifndef CFURLGetBaseURL
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002575 PyMac_PRECHECK(CFURLGetBaseURL);
Jack Jansenb3be2162001-11-30 14:16:36 +00002576#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002577 if (!PyArg_ParseTuple(_args, ""))
2578 return NULL;
2579 _rv = CFURLGetBaseURL(_self->ob_itself);
2580 _res = Py_BuildValue("O&",
2581 CFURLRefObj_New, _rv);
2582 return _res;
2583}
2584
2585static PyObject *CFURLRefObj_CFURLCanBeDecomposed(CFURLRefObject *_self, PyObject *_args)
2586{
2587 PyObject *_res = NULL;
2588 Boolean _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002589#ifndef CFURLCanBeDecomposed
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002590 PyMac_PRECHECK(CFURLCanBeDecomposed);
Jack Jansenb3be2162001-11-30 14:16:36 +00002591#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002592 if (!PyArg_ParseTuple(_args, ""))
2593 return NULL;
2594 _rv = CFURLCanBeDecomposed(_self->ob_itself);
2595 _res = Py_BuildValue("l",
2596 _rv);
2597 return _res;
2598}
2599
2600static PyObject *CFURLRefObj_CFURLCopyScheme(CFURLRefObject *_self, PyObject *_args)
2601{
2602 PyObject *_res = NULL;
2603 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002604#ifndef CFURLCopyScheme
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002605 PyMac_PRECHECK(CFURLCopyScheme);
Jack Jansenb3be2162001-11-30 14:16:36 +00002606#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002607 if (!PyArg_ParseTuple(_args, ""))
2608 return NULL;
2609 _rv = CFURLCopyScheme(_self->ob_itself);
2610 _res = Py_BuildValue("O&",
2611 CFStringRefObj_New, _rv);
2612 return _res;
2613}
2614
2615static PyObject *CFURLRefObj_CFURLCopyNetLocation(CFURLRefObject *_self, PyObject *_args)
2616{
2617 PyObject *_res = NULL;
2618 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002619#ifndef CFURLCopyNetLocation
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002620 PyMac_PRECHECK(CFURLCopyNetLocation);
Jack Jansenb3be2162001-11-30 14:16:36 +00002621#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002622 if (!PyArg_ParseTuple(_args, ""))
2623 return NULL;
2624 _rv = CFURLCopyNetLocation(_self->ob_itself);
2625 _res = Py_BuildValue("O&",
2626 CFStringRefObj_New, _rv);
2627 return _res;
2628}
2629
2630static PyObject *CFURLRefObj_CFURLCopyPath(CFURLRefObject *_self, PyObject *_args)
2631{
2632 PyObject *_res = NULL;
2633 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002634#ifndef CFURLCopyPath
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002635 PyMac_PRECHECK(CFURLCopyPath);
Jack Jansenb3be2162001-11-30 14:16:36 +00002636#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002637 if (!PyArg_ParseTuple(_args, ""))
2638 return NULL;
2639 _rv = CFURLCopyPath(_self->ob_itself);
2640 _res = Py_BuildValue("O&",
2641 CFStringRefObj_New, _rv);
2642 return _res;
2643}
2644
Jack Jansen2168e9d2001-12-16 20:18:40 +00002645static PyObject *CFURLRefObj_CFURLCopyStrictPath(CFURLRefObject *_self, PyObject *_args)
2646{
2647 PyObject *_res = NULL;
2648 CFStringRef _rv;
2649 Boolean isAbsolute;
2650#ifndef CFURLCopyStrictPath
2651 PyMac_PRECHECK(CFURLCopyStrictPath);
2652#endif
2653 if (!PyArg_ParseTuple(_args, ""))
2654 return NULL;
2655 _rv = CFURLCopyStrictPath(_self->ob_itself,
2656 &isAbsolute);
2657 _res = Py_BuildValue("O&l",
2658 CFStringRefObj_New, _rv,
2659 isAbsolute);
2660 return _res;
2661}
2662
2663static PyObject *CFURLRefObj_CFURLCopyFileSystemPath(CFURLRefObject *_self, PyObject *_args)
2664{
2665 PyObject *_res = NULL;
2666 CFStringRef _rv;
2667 CFURLPathStyle pathStyle;
2668#ifndef CFURLCopyFileSystemPath
2669 PyMac_PRECHECK(CFURLCopyFileSystemPath);
2670#endif
2671 if (!PyArg_ParseTuple(_args, "l",
2672 &pathStyle))
2673 return NULL;
2674 _rv = CFURLCopyFileSystemPath(_self->ob_itself,
2675 pathStyle);
2676 _res = Py_BuildValue("O&",
2677 CFStringRefObj_New, _rv);
2678 return _res;
2679}
2680
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002681static PyObject *CFURLRefObj_CFURLHasDirectoryPath(CFURLRefObject *_self, PyObject *_args)
2682{
2683 PyObject *_res = NULL;
2684 Boolean _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002685#ifndef CFURLHasDirectoryPath
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002686 PyMac_PRECHECK(CFURLHasDirectoryPath);
Jack Jansenb3be2162001-11-30 14:16:36 +00002687#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002688 if (!PyArg_ParseTuple(_args, ""))
2689 return NULL;
2690 _rv = CFURLHasDirectoryPath(_self->ob_itself);
2691 _res = Py_BuildValue("l",
2692 _rv);
2693 return _res;
2694}
2695
2696static PyObject *CFURLRefObj_CFURLCopyResourceSpecifier(CFURLRefObject *_self, PyObject *_args)
2697{
2698 PyObject *_res = NULL;
2699 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002700#ifndef CFURLCopyResourceSpecifier
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002701 PyMac_PRECHECK(CFURLCopyResourceSpecifier);
Jack Jansenb3be2162001-11-30 14:16:36 +00002702#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002703 if (!PyArg_ParseTuple(_args, ""))
2704 return NULL;
2705 _rv = CFURLCopyResourceSpecifier(_self->ob_itself);
2706 _res = Py_BuildValue("O&",
2707 CFStringRefObj_New, _rv);
2708 return _res;
2709}
2710
2711static PyObject *CFURLRefObj_CFURLCopyHostName(CFURLRefObject *_self, PyObject *_args)
2712{
2713 PyObject *_res = NULL;
2714 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002715#ifndef CFURLCopyHostName
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002716 PyMac_PRECHECK(CFURLCopyHostName);
Jack Jansenb3be2162001-11-30 14:16:36 +00002717#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002718 if (!PyArg_ParseTuple(_args, ""))
2719 return NULL;
2720 _rv = CFURLCopyHostName(_self->ob_itself);
2721 _res = Py_BuildValue("O&",
2722 CFStringRefObj_New, _rv);
2723 return _res;
2724}
2725
2726static PyObject *CFURLRefObj_CFURLGetPortNumber(CFURLRefObject *_self, PyObject *_args)
2727{
2728 PyObject *_res = NULL;
2729 SInt32 _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002730#ifndef CFURLGetPortNumber
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002731 PyMac_PRECHECK(CFURLGetPortNumber);
Jack Jansenb3be2162001-11-30 14:16:36 +00002732#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002733 if (!PyArg_ParseTuple(_args, ""))
2734 return NULL;
2735 _rv = CFURLGetPortNumber(_self->ob_itself);
2736 _res = Py_BuildValue("l",
2737 _rv);
2738 return _res;
2739}
2740
2741static PyObject *CFURLRefObj_CFURLCopyUserName(CFURLRefObject *_self, PyObject *_args)
2742{
2743 PyObject *_res = NULL;
2744 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002745#ifndef CFURLCopyUserName
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002746 PyMac_PRECHECK(CFURLCopyUserName);
Jack Jansenb3be2162001-11-30 14:16:36 +00002747#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002748 if (!PyArg_ParseTuple(_args, ""))
2749 return NULL;
2750 _rv = CFURLCopyUserName(_self->ob_itself);
2751 _res = Py_BuildValue("O&",
2752 CFStringRefObj_New, _rv);
2753 return _res;
2754}
2755
2756static PyObject *CFURLRefObj_CFURLCopyPassword(CFURLRefObject *_self, PyObject *_args)
2757{
2758 PyObject *_res = NULL;
2759 CFStringRef _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00002760#ifndef CFURLCopyPassword
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002761 PyMac_PRECHECK(CFURLCopyPassword);
Jack Jansenb3be2162001-11-30 14:16:36 +00002762#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002763 if (!PyArg_ParseTuple(_args, ""))
2764 return NULL;
2765 _rv = CFURLCopyPassword(_self->ob_itself);
2766 _res = Py_BuildValue("O&",
2767 CFStringRefObj_New, _rv);
2768 return _res;
2769}
2770
2771static PyObject *CFURLRefObj_CFURLCopyParameterString(CFURLRefObject *_self, PyObject *_args)
2772{
2773 PyObject *_res = NULL;
2774 CFStringRef _rv;
2775 CFStringRef charactersToLeaveEscaped;
Jack Jansenb3be2162001-11-30 14:16:36 +00002776#ifndef CFURLCopyParameterString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002777 PyMac_PRECHECK(CFURLCopyParameterString);
Jack Jansenb3be2162001-11-30 14:16:36 +00002778#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002779 if (!PyArg_ParseTuple(_args, "O&",
2780 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2781 return NULL;
2782 _rv = CFURLCopyParameterString(_self->ob_itself,
2783 charactersToLeaveEscaped);
2784 _res = Py_BuildValue("O&",
2785 CFStringRefObj_New, _rv);
2786 return _res;
2787}
2788
2789static PyObject *CFURLRefObj_CFURLCopyQueryString(CFURLRefObject *_self, PyObject *_args)
2790{
2791 PyObject *_res = NULL;
2792 CFStringRef _rv;
2793 CFStringRef charactersToLeaveEscaped;
Jack Jansenb3be2162001-11-30 14:16:36 +00002794#ifndef CFURLCopyQueryString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002795 PyMac_PRECHECK(CFURLCopyQueryString);
Jack Jansenb3be2162001-11-30 14:16:36 +00002796#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002797 if (!PyArg_ParseTuple(_args, "O&",
2798 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2799 return NULL;
2800 _rv = CFURLCopyQueryString(_self->ob_itself,
2801 charactersToLeaveEscaped);
2802 _res = Py_BuildValue("O&",
2803 CFStringRefObj_New, _rv);
2804 return _res;
2805}
2806
2807static PyObject *CFURLRefObj_CFURLCopyFragment(CFURLRefObject *_self, PyObject *_args)
2808{
2809 PyObject *_res = NULL;
2810 CFStringRef _rv;
2811 CFStringRef charactersToLeaveEscaped;
Jack Jansenb3be2162001-11-30 14:16:36 +00002812#ifndef CFURLCopyFragment
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002813 PyMac_PRECHECK(CFURLCopyFragment);
Jack Jansenb3be2162001-11-30 14:16:36 +00002814#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002815 if (!PyArg_ParseTuple(_args, "O&",
2816 CFStringRefObj_Convert, &charactersToLeaveEscaped))
2817 return NULL;
2818 _rv = CFURLCopyFragment(_self->ob_itself,
2819 charactersToLeaveEscaped);
2820 _res = Py_BuildValue("O&",
2821 CFStringRefObj_New, _rv);
2822 return _res;
2823}
2824
Jack Jansen2168e9d2001-12-16 20:18:40 +00002825static PyObject *CFURLRefObj_CFURLCopyLastPathComponent(CFURLRefObject *_self, PyObject *_args)
2826{
2827 PyObject *_res = NULL;
2828 CFStringRef _rv;
2829#ifndef CFURLCopyLastPathComponent
2830 PyMac_PRECHECK(CFURLCopyLastPathComponent);
2831#endif
2832 if (!PyArg_ParseTuple(_args, ""))
2833 return NULL;
2834 _rv = CFURLCopyLastPathComponent(_self->ob_itself);
2835 _res = Py_BuildValue("O&",
2836 CFStringRefObj_New, _rv);
2837 return _res;
2838}
2839
2840static PyObject *CFURLRefObj_CFURLCopyPathExtension(CFURLRefObject *_self, PyObject *_args)
2841{
2842 PyObject *_res = NULL;
2843 CFStringRef _rv;
2844#ifndef CFURLCopyPathExtension
2845 PyMac_PRECHECK(CFURLCopyPathExtension);
2846#endif
2847 if (!PyArg_ParseTuple(_args, ""))
2848 return NULL;
2849 _rv = CFURLCopyPathExtension(_self->ob_itself);
2850 _res = Py_BuildValue("O&",
2851 CFStringRefObj_New, _rv);
2852 return _res;
2853}
2854
2855static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathComponent(CFURLRefObject *_self, PyObject *_args)
2856{
2857 PyObject *_res = NULL;
2858 CFURLRef _rv;
2859 CFStringRef pathComponent;
2860 Boolean isDirectory;
2861 if (!PyArg_ParseTuple(_args, "O&l",
2862 CFStringRefObj_Convert, &pathComponent,
2863 &isDirectory))
2864 return NULL;
2865 _rv = CFURLCreateCopyAppendingPathComponent((CFAllocatorRef)NULL,
2866 _self->ob_itself,
2867 pathComponent,
2868 isDirectory);
2869 _res = Py_BuildValue("O&",
2870 CFURLRefObj_New, _rv);
2871 return _res;
2872}
2873
2874static PyObject *CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent(CFURLRefObject *_self, PyObject *_args)
2875{
2876 PyObject *_res = NULL;
2877 CFURLRef _rv;
2878 if (!PyArg_ParseTuple(_args, ""))
2879 return NULL;
2880 _rv = CFURLCreateCopyDeletingLastPathComponent((CFAllocatorRef)NULL,
2881 _self->ob_itself);
2882 _res = Py_BuildValue("O&",
2883 CFURLRefObj_New, _rv);
2884 return _res;
2885}
2886
2887static PyObject *CFURLRefObj_CFURLCreateCopyAppendingPathExtension(CFURLRefObject *_self, PyObject *_args)
2888{
2889 PyObject *_res = NULL;
2890 CFURLRef _rv;
2891 CFStringRef extension;
2892 if (!PyArg_ParseTuple(_args, "O&",
2893 CFStringRefObj_Convert, &extension))
2894 return NULL;
2895 _rv = CFURLCreateCopyAppendingPathExtension((CFAllocatorRef)NULL,
2896 _self->ob_itself,
2897 extension);
2898 _res = Py_BuildValue("O&",
2899 CFURLRefObj_New, _rv);
2900 return _res;
2901}
2902
2903static PyObject *CFURLRefObj_CFURLCreateCopyDeletingPathExtension(CFURLRefObject *_self, PyObject *_args)
2904{
2905 PyObject *_res = NULL;
2906 CFURLRef _rv;
2907 if (!PyArg_ParseTuple(_args, ""))
2908 return NULL;
2909 _rv = CFURLCreateCopyDeletingPathExtension((CFAllocatorRef)NULL,
2910 _self->ob_itself);
2911 _res = Py_BuildValue("O&",
2912 CFURLRefObj_New, _rv);
2913 return _res;
2914}
2915
2916static PyObject *CFURLRefObj_CFURLGetFSRef(CFURLRefObject *_self, PyObject *_args)
2917{
2918 PyObject *_res = NULL;
2919 Boolean _rv;
2920 FSRef fsRef;
2921#ifndef CFURLGetFSRef
2922 PyMac_PRECHECK(CFURLGetFSRef);
2923#endif
2924 if (!PyArg_ParseTuple(_args, ""))
2925 return NULL;
2926 _rv = CFURLGetFSRef(_self->ob_itself,
2927 &fsRef);
2928 _res = Py_BuildValue("lO&",
2929 _rv,
Jack Jansenca9a4a62002-03-18 15:41:32 +00002930 PyMac_BuildFSRef, &fsRef);
Jack Jansen2168e9d2001-12-16 20:18:40 +00002931 return _res;
2932}
2933
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002934static PyMethodDef CFURLRefObj_methods[] = {
2935 {"CFURLCreateData", (PyCFunction)CFURLRefObj_CFURLCreateData, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002936 PyDoc_STR("(CFStringEncoding encoding, Boolean escapeWhitespace) -> (CFDataRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002937 {"CFURLGetFileSystemRepresentation", (PyCFunction)CFURLRefObj_CFURLGetFileSystemRepresentation, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002938 PyDoc_STR("(Boolean resolveAgainstBase, CFIndex maxBufLen) -> (Boolean _rv, UInt8 buffer)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002939 {"CFURLCopyAbsoluteURL", (PyCFunction)CFURLRefObj_CFURLCopyAbsoluteURL, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002940 PyDoc_STR("() -> (CFURLRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002941 {"CFURLGetString", (PyCFunction)CFURLRefObj_CFURLGetString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002942 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002943 {"CFURLGetBaseURL", (PyCFunction)CFURLRefObj_CFURLGetBaseURL, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002944 PyDoc_STR("() -> (CFURLRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002945 {"CFURLCanBeDecomposed", (PyCFunction)CFURLRefObj_CFURLCanBeDecomposed, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002946 PyDoc_STR("() -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002947 {"CFURLCopyScheme", (PyCFunction)CFURLRefObj_CFURLCopyScheme, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002948 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002949 {"CFURLCopyNetLocation", (PyCFunction)CFURLRefObj_CFURLCopyNetLocation, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002950 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002951 {"CFURLCopyPath", (PyCFunction)CFURLRefObj_CFURLCopyPath, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002952 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002953 {"CFURLCopyStrictPath", (PyCFunction)CFURLRefObj_CFURLCopyStrictPath, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002954 PyDoc_STR("() -> (CFStringRef _rv, Boolean isAbsolute)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002955 {"CFURLCopyFileSystemPath", (PyCFunction)CFURLRefObj_CFURLCopyFileSystemPath, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002956 PyDoc_STR("(CFURLPathStyle pathStyle) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002957 {"CFURLHasDirectoryPath", (PyCFunction)CFURLRefObj_CFURLHasDirectoryPath, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002958 PyDoc_STR("() -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002959 {"CFURLCopyResourceSpecifier", (PyCFunction)CFURLRefObj_CFURLCopyResourceSpecifier, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002960 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002961 {"CFURLCopyHostName", (PyCFunction)CFURLRefObj_CFURLCopyHostName, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002962 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002963 {"CFURLGetPortNumber", (PyCFunction)CFURLRefObj_CFURLGetPortNumber, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002964 PyDoc_STR("() -> (SInt32 _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002965 {"CFURLCopyUserName", (PyCFunction)CFURLRefObj_CFURLCopyUserName, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002966 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002967 {"CFURLCopyPassword", (PyCFunction)CFURLRefObj_CFURLCopyPassword, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002968 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002969 {"CFURLCopyParameterString", (PyCFunction)CFURLRefObj_CFURLCopyParameterString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002970 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002971 {"CFURLCopyQueryString", (PyCFunction)CFURLRefObj_CFURLCopyQueryString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002972 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002973 {"CFURLCopyFragment", (PyCFunction)CFURLRefObj_CFURLCopyFragment, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002974 PyDoc_STR("(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002975 {"CFURLCopyLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCopyLastPathComponent, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002976 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002977 {"CFURLCopyPathExtension", (PyCFunction)CFURLRefObj_CFURLCopyPathExtension, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002978 PyDoc_STR("() -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002979 {"CFURLCreateCopyAppendingPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathComponent, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002980 PyDoc_STR("(CFStringRef pathComponent, Boolean isDirectory) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002981 {"CFURLCreateCopyDeletingLastPathComponent", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingLastPathComponent, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002982 PyDoc_STR("() -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002983 {"CFURLCreateCopyAppendingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyAppendingPathExtension, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002984 PyDoc_STR("(CFStringRef extension) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002985 {"CFURLCreateCopyDeletingPathExtension", (PyCFunction)CFURLRefObj_CFURLCreateCopyDeletingPathExtension, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002986 PyDoc_STR("() -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00002987 {"CFURLGetFSRef", (PyCFunction)CFURLRefObj_CFURLGetFSRef, 1,
Jack Jansen49931882002-08-16 09:09:31 +00002988 PyDoc_STR("() -> (Boolean _rv, FSRef fsRef)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00002989 {NULL, NULL, 0}
2990};
2991
2992PyMethodChain CFURLRefObj_chain = { CFURLRefObj_methods, &CFTypeRefObj_chain };
2993
2994static PyObject *CFURLRefObj_getattr(CFURLRefObject *self, char *name)
2995{
2996 return Py_FindMethodInChain(&CFURLRefObj_chain, (PyObject *)self, name);
2997}
2998
2999#define CFURLRefObj_setattr NULL
3000
3001static int CFURLRefObj_compare(CFURLRefObject *self, CFURLRefObject *other)
3002{
3003 /* XXXX Or should we use CFEqual?? */
3004 if ( self->ob_itself > other->ob_itself ) return 1;
3005 if ( self->ob_itself < other->ob_itself ) return -1;
3006 return 0;
3007}
3008
3009static PyObject * CFURLRefObj_repr(CFURLRefObject *self)
3010{
3011 char buf[100];
Jack Jansenfd064862001-09-05 10:31:52 +00003012 sprintf(buf, "<CFURL object at 0x%8.8x for 0x%8.8x>", (unsigned)self, (unsigned)self->ob_itself);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003013 return PyString_FromString(buf);
3014}
3015
3016static int CFURLRefObj_hash(CFURLRefObject *self)
3017{
3018 /* XXXX Or should we use CFHash?? */
3019 return (int)self->ob_itself;
3020}
3021
3022PyTypeObject CFURLRef_Type = {
Jack Jansenb3be2162001-11-30 14:16:36 +00003023 PyObject_HEAD_INIT(NULL)
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003024 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00003025 "_CF.CFURLRef", /*tp_name*/
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003026 sizeof(CFURLRefObject), /*tp_basicsize*/
3027 0, /*tp_itemsize*/
3028 /* methods */
3029 (destructor) CFURLRefObj_dealloc, /*tp_dealloc*/
3030 0, /*tp_print*/
3031 (getattrfunc) CFURLRefObj_getattr, /*tp_getattr*/
3032 (setattrfunc) CFURLRefObj_setattr, /*tp_setattr*/
3033 (cmpfunc) CFURLRefObj_compare, /*tp_compare*/
3034 (reprfunc) CFURLRefObj_repr, /*tp_repr*/
3035 (PyNumberMethods *)0, /* tp_as_number */
3036 (PySequenceMethods *)0, /* tp_as_sequence */
3037 (PyMappingMethods *)0, /* tp_as_mapping */
3038 (hashfunc) CFURLRefObj_hash, /*tp_hash*/
3039};
3040
3041/* -------------------- End object type CFURLRef -------------------- */
3042
3043
Jack Jansen2168e9d2001-12-16 20:18:40 +00003044static PyObject *CF___CFRangeMake(PyObject *_self, PyObject *_args)
3045{
3046 PyObject *_res = NULL;
3047 CFRange _rv;
3048 CFIndex loc;
3049 CFIndex len;
3050#ifndef __CFRangeMake
3051 PyMac_PRECHECK(__CFRangeMake);
3052#endif
3053 if (!PyArg_ParseTuple(_args, "ll",
3054 &loc,
3055 &len))
3056 return NULL;
3057 _rv = __CFRangeMake(loc,
3058 len);
3059 _res = Py_BuildValue("O&",
3060 CFRange_New, _rv);
3061 return _res;
3062}
3063
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003064static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args)
3065{
3066 PyObject *_res = NULL;
3067 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003068#ifndef CFAllocatorGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003069 PyMac_PRECHECK(CFAllocatorGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00003070#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003071 if (!PyArg_ParseTuple(_args, ""))
3072 return NULL;
3073 _rv = CFAllocatorGetTypeID();
3074 _res = Py_BuildValue("l",
3075 _rv);
3076 return _res;
3077}
3078
3079static PyObject *CF_CFAllocatorGetPreferredSizeForSize(PyObject *_self, PyObject *_args)
3080{
3081 PyObject *_res = NULL;
3082 CFIndex _rv;
3083 CFIndex size;
3084 CFOptionFlags hint;
Jack Jansenb3be2162001-11-30 14:16:36 +00003085#ifndef CFAllocatorGetPreferredSizeForSize
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003086 PyMac_PRECHECK(CFAllocatorGetPreferredSizeForSize);
Jack Jansenb3be2162001-11-30 14:16:36 +00003087#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003088 if (!PyArg_ParseTuple(_args, "ll",
3089 &size,
3090 &hint))
3091 return NULL;
3092 _rv = CFAllocatorGetPreferredSizeForSize((CFAllocatorRef)NULL,
3093 size,
3094 hint);
3095 _res = Py_BuildValue("l",
3096 _rv);
3097 return _res;
3098}
3099
3100static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args)
3101{
3102 PyObject *_res = NULL;
3103 CFStringRef _rv;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003104 CFTypeID type_id;
Jack Jansenb3be2162001-11-30 14:16:36 +00003105#ifndef CFCopyTypeIDDescription
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003106 PyMac_PRECHECK(CFCopyTypeIDDescription);
Jack Jansenb3be2162001-11-30 14:16:36 +00003107#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003108 if (!PyArg_ParseTuple(_args, "l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00003109 &type_id))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003110 return NULL;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003111 _rv = CFCopyTypeIDDescription(type_id);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003112 _res = Py_BuildValue("O&",
3113 CFStringRefObj_New, _rv);
3114 return _res;
3115}
3116
3117static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args)
3118{
3119 PyObject *_res = NULL;
3120 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003121#ifndef CFArrayGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003122 PyMac_PRECHECK(CFArrayGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00003123#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003124 if (!PyArg_ParseTuple(_args, ""))
3125 return NULL;
3126 _rv = CFArrayGetTypeID();
3127 _res = Py_BuildValue("l",
3128 _rv);
3129 return _res;
3130}
3131
3132static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args)
3133{
3134 PyObject *_res = NULL;
3135 CFMutableArrayRef _rv;
3136 CFIndex capacity;
Jack Jansenb3be2162001-11-30 14:16:36 +00003137#ifndef CFArrayCreateMutable
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003138 PyMac_PRECHECK(CFArrayCreateMutable);
Jack Jansenb3be2162001-11-30 14:16:36 +00003139#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003140 if (!PyArg_ParseTuple(_args, "l",
3141 &capacity))
3142 return NULL;
3143 _rv = CFArrayCreateMutable((CFAllocatorRef)NULL,
3144 capacity,
3145 &kCFTypeArrayCallBacks);
3146 _res = Py_BuildValue("O&",
3147 CFMutableArrayRefObj_New, _rv);
3148 return _res;
3149}
3150
3151static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args)
3152{
3153 PyObject *_res = NULL;
3154 CFMutableArrayRef _rv;
3155 CFIndex capacity;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003156 CFArrayRef theArray;
Jack Jansenb3be2162001-11-30 14:16:36 +00003157#ifndef CFArrayCreateMutableCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003158 PyMac_PRECHECK(CFArrayCreateMutableCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003159#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003160 if (!PyArg_ParseTuple(_args, "lO&",
3161 &capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003162 CFArrayRefObj_Convert, &theArray))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003163 return NULL;
3164 _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL,
3165 capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003166 theArray);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003167 _res = Py_BuildValue("O&",
3168 CFMutableArrayRefObj_New, _rv);
3169 return _res;
3170}
3171
3172static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args)
3173{
3174 PyObject *_res = NULL;
3175 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003176#ifndef CFDataGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003177 PyMac_PRECHECK(CFDataGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00003178#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003179 if (!PyArg_ParseTuple(_args, ""))
3180 return NULL;
3181 _rv = CFDataGetTypeID();
3182 _res = Py_BuildValue("l",
3183 _rv);
3184 return _res;
3185}
3186
3187static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args)
3188{
3189 PyObject *_res = NULL;
3190 CFDataRef _rv;
3191 unsigned char *bytes__in__;
3192 long bytes__len__;
3193 int bytes__in_len__;
Jack Jansenb3be2162001-11-30 14:16:36 +00003194#ifndef CFDataCreate
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003195 PyMac_PRECHECK(CFDataCreate);
Jack Jansenb3be2162001-11-30 14:16:36 +00003196#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003197 if (!PyArg_ParseTuple(_args, "s#",
3198 &bytes__in__, &bytes__in_len__))
3199 return NULL;
3200 bytes__len__ = bytes__in_len__;
3201 _rv = CFDataCreate((CFAllocatorRef)NULL,
3202 bytes__in__, bytes__len__);
3203 _res = Py_BuildValue("O&",
3204 CFDataRefObj_New, _rv);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003205 return _res;
3206}
3207
3208static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args)
3209{
3210 PyObject *_res = NULL;
3211 CFDataRef _rv;
3212 unsigned char *bytes__in__;
3213 long bytes__len__;
3214 int bytes__in_len__;
Jack Jansenb3be2162001-11-30 14:16:36 +00003215#ifndef CFDataCreateWithBytesNoCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003216 PyMac_PRECHECK(CFDataCreateWithBytesNoCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003217#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003218 if (!PyArg_ParseTuple(_args, "s#",
3219 &bytes__in__, &bytes__in_len__))
3220 return NULL;
3221 bytes__len__ = bytes__in_len__;
3222 _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL,
3223 bytes__in__, bytes__len__,
3224 (CFAllocatorRef)NULL);
3225 _res = Py_BuildValue("O&",
3226 CFDataRefObj_New, _rv);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003227 return _res;
3228}
3229
3230static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args)
3231{
3232 PyObject *_res = NULL;
3233 CFMutableDataRef _rv;
3234 CFIndex capacity;
Jack Jansenb3be2162001-11-30 14:16:36 +00003235#ifndef CFDataCreateMutable
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003236 PyMac_PRECHECK(CFDataCreateMutable);
Jack Jansenb3be2162001-11-30 14:16:36 +00003237#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003238 if (!PyArg_ParseTuple(_args, "l",
3239 &capacity))
3240 return NULL;
3241 _rv = CFDataCreateMutable((CFAllocatorRef)NULL,
3242 capacity);
3243 _res = Py_BuildValue("O&",
3244 CFMutableDataRefObj_New, _rv);
3245 return _res;
3246}
3247
3248static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args)
3249{
3250 PyObject *_res = NULL;
3251 CFMutableDataRef _rv;
3252 CFIndex capacity;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003253 CFDataRef theData;
Jack Jansenb3be2162001-11-30 14:16:36 +00003254#ifndef CFDataCreateMutableCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003255 PyMac_PRECHECK(CFDataCreateMutableCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003256#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003257 if (!PyArg_ParseTuple(_args, "lO&",
3258 &capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003259 CFDataRefObj_Convert, &theData))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003260 return NULL;
3261 _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL,
3262 capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003263 theData);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003264 _res = Py_BuildValue("O&",
3265 CFMutableDataRefObj_New, _rv);
3266 return _res;
3267}
3268
3269static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args)
3270{
3271 PyObject *_res = NULL;
3272 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003273#ifndef CFDictionaryGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003274 PyMac_PRECHECK(CFDictionaryGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00003275#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003276 if (!PyArg_ParseTuple(_args, ""))
3277 return NULL;
3278 _rv = CFDictionaryGetTypeID();
3279 _res = Py_BuildValue("l",
3280 _rv);
3281 return _res;
3282}
3283
3284static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args)
3285{
3286 PyObject *_res = NULL;
3287 CFMutableDictionaryRef _rv;
3288 CFIndex capacity;
Jack Jansenb3be2162001-11-30 14:16:36 +00003289#ifndef CFDictionaryCreateMutable
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003290 PyMac_PRECHECK(CFDictionaryCreateMutable);
Jack Jansenb3be2162001-11-30 14:16:36 +00003291#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003292 if (!PyArg_ParseTuple(_args, "l",
3293 &capacity))
3294 return NULL;
3295 _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL,
3296 capacity,
3297 &kCFTypeDictionaryKeyCallBacks,
3298 &kCFTypeDictionaryValueCallBacks);
3299 _res = Py_BuildValue("O&",
3300 CFMutableDictionaryRefObj_New, _rv);
3301 return _res;
3302}
3303
3304static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args)
3305{
3306 PyObject *_res = NULL;
3307 CFMutableDictionaryRef _rv;
3308 CFIndex capacity;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003309 CFDictionaryRef theDict;
Jack Jansenb3be2162001-11-30 14:16:36 +00003310#ifndef CFDictionaryCreateMutableCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003311 PyMac_PRECHECK(CFDictionaryCreateMutableCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003312#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003313 if (!PyArg_ParseTuple(_args, "lO&",
3314 &capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003315 CFDictionaryRefObj_Convert, &theDict))
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003316 return NULL;
3317 _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL,
3318 capacity,
Jack Jansen2168e9d2001-12-16 20:18:40 +00003319 theDict);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003320 _res = Py_BuildValue("O&",
3321 CFMutableDictionaryRefObj_New, _rv);
3322 return _res;
3323}
3324
Jack Jansen23be1ce2002-05-13 21:21:49 +00003325static PyObject *CF_CFPreferencesCopyAppValue(PyObject *_self, PyObject *_args)
3326{
3327 PyObject *_res = NULL;
3328 CFTypeRef _rv;
3329 CFStringRef key;
3330 CFStringRef applicationID;
3331#ifndef CFPreferencesCopyAppValue
3332 PyMac_PRECHECK(CFPreferencesCopyAppValue);
3333#endif
3334 if (!PyArg_ParseTuple(_args, "O&O&",
3335 CFStringRefObj_Convert, &key,
3336 CFStringRefObj_Convert, &applicationID))
3337 return NULL;
3338 _rv = CFPreferencesCopyAppValue(key,
3339 applicationID);
3340 _res = Py_BuildValue("O&",
3341 CFTypeRefObj_New, _rv);
3342 return _res;
3343}
3344
3345static PyObject *CF_CFPreferencesGetAppBooleanValue(PyObject *_self, PyObject *_args)
3346{
3347 PyObject *_res = NULL;
3348 Boolean _rv;
3349 CFStringRef key;
3350 CFStringRef applicationID;
3351 Boolean keyExistsAndHasValidFormat;
3352#ifndef CFPreferencesGetAppBooleanValue
3353 PyMac_PRECHECK(CFPreferencesGetAppBooleanValue);
3354#endif
3355 if (!PyArg_ParseTuple(_args, "O&O&",
3356 CFStringRefObj_Convert, &key,
3357 CFStringRefObj_Convert, &applicationID))
3358 return NULL;
3359 _rv = CFPreferencesGetAppBooleanValue(key,
3360 applicationID,
3361 &keyExistsAndHasValidFormat);
3362 _res = Py_BuildValue("ll",
3363 _rv,
3364 keyExistsAndHasValidFormat);
3365 return _res;
3366}
3367
3368static PyObject *CF_CFPreferencesGetAppIntegerValue(PyObject *_self, PyObject *_args)
3369{
3370 PyObject *_res = NULL;
3371 CFIndex _rv;
3372 CFStringRef key;
3373 CFStringRef applicationID;
3374 Boolean keyExistsAndHasValidFormat;
3375#ifndef CFPreferencesGetAppIntegerValue
3376 PyMac_PRECHECK(CFPreferencesGetAppIntegerValue);
3377#endif
3378 if (!PyArg_ParseTuple(_args, "O&O&",
3379 CFStringRefObj_Convert, &key,
3380 CFStringRefObj_Convert, &applicationID))
3381 return NULL;
3382 _rv = CFPreferencesGetAppIntegerValue(key,
3383 applicationID,
3384 &keyExistsAndHasValidFormat);
3385 _res = Py_BuildValue("ll",
3386 _rv,
3387 keyExistsAndHasValidFormat);
3388 return _res;
3389}
3390
3391static PyObject *CF_CFPreferencesSetAppValue(PyObject *_self, PyObject *_args)
3392{
3393 PyObject *_res = NULL;
3394 CFStringRef key;
3395 CFTypeRef value;
3396 CFStringRef applicationID;
3397#ifndef CFPreferencesSetAppValue
3398 PyMac_PRECHECK(CFPreferencesSetAppValue);
3399#endif
3400 if (!PyArg_ParseTuple(_args, "O&O&O&",
3401 CFStringRefObj_Convert, &key,
3402 CFTypeRefObj_Convert, &value,
3403 CFStringRefObj_Convert, &applicationID))
3404 return NULL;
3405 CFPreferencesSetAppValue(key,
3406 value,
3407 applicationID);
3408 Py_INCREF(Py_None);
3409 _res = Py_None;
3410 return _res;
3411}
3412
3413static PyObject *CF_CFPreferencesAddSuitePreferencesToApp(PyObject *_self, PyObject *_args)
3414{
3415 PyObject *_res = NULL;
3416 CFStringRef applicationID;
3417 CFStringRef suiteID;
3418#ifndef CFPreferencesAddSuitePreferencesToApp
3419 PyMac_PRECHECK(CFPreferencesAddSuitePreferencesToApp);
3420#endif
3421 if (!PyArg_ParseTuple(_args, "O&O&",
3422 CFStringRefObj_Convert, &applicationID,
3423 CFStringRefObj_Convert, &suiteID))
3424 return NULL;
3425 CFPreferencesAddSuitePreferencesToApp(applicationID,
3426 suiteID);
3427 Py_INCREF(Py_None);
3428 _res = Py_None;
3429 return _res;
3430}
3431
3432static PyObject *CF_CFPreferencesRemoveSuitePreferencesFromApp(PyObject *_self, PyObject *_args)
3433{
3434 PyObject *_res = NULL;
3435 CFStringRef applicationID;
3436 CFStringRef suiteID;
3437#ifndef CFPreferencesRemoveSuitePreferencesFromApp
3438 PyMac_PRECHECK(CFPreferencesRemoveSuitePreferencesFromApp);
3439#endif
3440 if (!PyArg_ParseTuple(_args, "O&O&",
3441 CFStringRefObj_Convert, &applicationID,
3442 CFStringRefObj_Convert, &suiteID))
3443 return NULL;
3444 CFPreferencesRemoveSuitePreferencesFromApp(applicationID,
3445 suiteID);
3446 Py_INCREF(Py_None);
3447 _res = Py_None;
3448 return _res;
3449}
3450
3451static PyObject *CF_CFPreferencesAppSynchronize(PyObject *_self, PyObject *_args)
3452{
3453 PyObject *_res = NULL;
3454 Boolean _rv;
3455 CFStringRef applicationID;
3456#ifndef CFPreferencesAppSynchronize
3457 PyMac_PRECHECK(CFPreferencesAppSynchronize);
3458#endif
3459 if (!PyArg_ParseTuple(_args, "O&",
3460 CFStringRefObj_Convert, &applicationID))
3461 return NULL;
3462 _rv = CFPreferencesAppSynchronize(applicationID);
3463 _res = Py_BuildValue("l",
3464 _rv);
3465 return _res;
3466}
3467
3468static PyObject *CF_CFPreferencesCopyValue(PyObject *_self, PyObject *_args)
3469{
3470 PyObject *_res = NULL;
3471 CFTypeRef _rv;
3472 CFStringRef key;
3473 CFStringRef applicationID;
3474 CFStringRef userName;
3475 CFStringRef hostName;
3476#ifndef CFPreferencesCopyValue
3477 PyMac_PRECHECK(CFPreferencesCopyValue);
3478#endif
3479 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
3480 CFStringRefObj_Convert, &key,
3481 CFStringRefObj_Convert, &applicationID,
3482 CFStringRefObj_Convert, &userName,
3483 CFStringRefObj_Convert, &hostName))
3484 return NULL;
3485 _rv = CFPreferencesCopyValue(key,
3486 applicationID,
3487 userName,
3488 hostName);
3489 _res = Py_BuildValue("O&",
3490 CFTypeRefObj_New, _rv);
3491 return _res;
3492}
3493
3494static PyObject *CF_CFPreferencesCopyMultiple(PyObject *_self, PyObject *_args)
3495{
3496 PyObject *_res = NULL;
3497 CFDictionaryRef _rv;
3498 CFArrayRef keysToFetch;
3499 CFStringRef applicationID;
3500 CFStringRef userName;
3501 CFStringRef hostName;
3502#ifndef CFPreferencesCopyMultiple
3503 PyMac_PRECHECK(CFPreferencesCopyMultiple);
3504#endif
3505 if (!PyArg_ParseTuple(_args, "O&O&O&O&",
3506 CFArrayRefObj_Convert, &keysToFetch,
3507 CFStringRefObj_Convert, &applicationID,
3508 CFStringRefObj_Convert, &userName,
3509 CFStringRefObj_Convert, &hostName))
3510 return NULL;
3511 _rv = CFPreferencesCopyMultiple(keysToFetch,
3512 applicationID,
3513 userName,
3514 hostName);
3515 _res = Py_BuildValue("O&",
3516 CFDictionaryRefObj_New, _rv);
3517 return _res;
3518}
3519
3520static PyObject *CF_CFPreferencesSetValue(PyObject *_self, PyObject *_args)
3521{
3522 PyObject *_res = NULL;
3523 CFStringRef key;
3524 CFTypeRef value;
3525 CFStringRef applicationID;
3526 CFStringRef userName;
3527 CFStringRef hostName;
3528#ifndef CFPreferencesSetValue
3529 PyMac_PRECHECK(CFPreferencesSetValue);
3530#endif
3531 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
3532 CFStringRefObj_Convert, &key,
3533 CFTypeRefObj_Convert, &value,
3534 CFStringRefObj_Convert, &applicationID,
3535 CFStringRefObj_Convert, &userName,
3536 CFStringRefObj_Convert, &hostName))
3537 return NULL;
3538 CFPreferencesSetValue(key,
3539 value,
3540 applicationID,
3541 userName,
3542 hostName);
3543 Py_INCREF(Py_None);
3544 _res = Py_None;
3545 return _res;
3546}
3547
3548static PyObject *CF_CFPreferencesSetMultiple(PyObject *_self, PyObject *_args)
3549{
3550 PyObject *_res = NULL;
3551 CFDictionaryRef keysToSet;
3552 CFArrayRef keysToRemove;
3553 CFStringRef applicationID;
3554 CFStringRef userName;
3555 CFStringRef hostName;
3556#ifndef CFPreferencesSetMultiple
3557 PyMac_PRECHECK(CFPreferencesSetMultiple);
3558#endif
3559 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
3560 CFDictionaryRefObj_Convert, &keysToSet,
3561 CFArrayRefObj_Convert, &keysToRemove,
3562 CFStringRefObj_Convert, &applicationID,
3563 CFStringRefObj_Convert, &userName,
3564 CFStringRefObj_Convert, &hostName))
3565 return NULL;
3566 CFPreferencesSetMultiple(keysToSet,
3567 keysToRemove,
3568 applicationID,
3569 userName,
3570 hostName);
3571 Py_INCREF(Py_None);
3572 _res = Py_None;
3573 return _res;
3574}
3575
3576static PyObject *CF_CFPreferencesSynchronize(PyObject *_self, PyObject *_args)
3577{
3578 PyObject *_res = NULL;
3579 Boolean _rv;
3580 CFStringRef applicationID;
3581 CFStringRef userName;
3582 CFStringRef hostName;
3583#ifndef CFPreferencesSynchronize
3584 PyMac_PRECHECK(CFPreferencesSynchronize);
3585#endif
3586 if (!PyArg_ParseTuple(_args, "O&O&O&",
3587 CFStringRefObj_Convert, &applicationID,
3588 CFStringRefObj_Convert, &userName,
3589 CFStringRefObj_Convert, &hostName))
3590 return NULL;
3591 _rv = CFPreferencesSynchronize(applicationID,
3592 userName,
3593 hostName);
3594 _res = Py_BuildValue("l",
3595 _rv);
3596 return _res;
3597}
3598
3599static PyObject *CF_CFPreferencesCopyApplicationList(PyObject *_self, PyObject *_args)
3600{
3601 PyObject *_res = NULL;
3602 CFArrayRef _rv;
3603 CFStringRef userName;
3604 CFStringRef hostName;
3605#ifndef CFPreferencesCopyApplicationList
3606 PyMac_PRECHECK(CFPreferencesCopyApplicationList);
3607#endif
3608 if (!PyArg_ParseTuple(_args, "O&O&",
3609 CFStringRefObj_Convert, &userName,
3610 CFStringRefObj_Convert, &hostName))
3611 return NULL;
3612 _rv = CFPreferencesCopyApplicationList(userName,
3613 hostName);
3614 _res = Py_BuildValue("O&",
3615 CFArrayRefObj_New, _rv);
3616 return _res;
3617}
3618
3619static PyObject *CF_CFPreferencesCopyKeyList(PyObject *_self, PyObject *_args)
3620{
3621 PyObject *_res = NULL;
3622 CFArrayRef _rv;
3623 CFStringRef applicationID;
3624 CFStringRef userName;
3625 CFStringRef hostName;
3626#ifndef CFPreferencesCopyKeyList
3627 PyMac_PRECHECK(CFPreferencesCopyKeyList);
3628#endif
3629 if (!PyArg_ParseTuple(_args, "O&O&O&",
3630 CFStringRefObj_Convert, &applicationID,
3631 CFStringRefObj_Convert, &userName,
3632 CFStringRefObj_Convert, &hostName))
3633 return NULL;
3634 _rv = CFPreferencesCopyKeyList(applicationID,
3635 userName,
3636 hostName);
3637 _res = Py_BuildValue("O&",
3638 CFArrayRefObj_New, _rv);
3639 return _res;
3640}
3641
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003642static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args)
3643{
3644 PyObject *_res = NULL;
3645 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003646#ifndef CFStringGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003647 PyMac_PRECHECK(CFStringGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00003648#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003649 if (!PyArg_ParseTuple(_args, ""))
3650 return NULL;
3651 _rv = CFStringGetTypeID();
3652 _res = Py_BuildValue("l",
3653 _rv);
3654 return _res;
3655}
3656
3657static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args)
3658{
3659 PyObject *_res = NULL;
3660 CFStringRef _rv;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003661 Str255 pStr;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003662 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003663#ifndef CFStringCreateWithPascalString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003664 PyMac_PRECHECK(CFStringCreateWithPascalString);
Jack Jansenb3be2162001-11-30 14:16:36 +00003665#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003666 if (!PyArg_ParseTuple(_args, "O&l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00003667 PyMac_GetStr255, pStr,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003668 &encoding))
3669 return NULL;
3670 _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL,
3671 pStr,
3672 encoding);
3673 _res = Py_BuildValue("O&",
3674 CFStringRefObj_New, _rv);
3675 return _res;
3676}
3677
3678static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args)
3679{
3680 PyObject *_res = NULL;
3681 CFStringRef _rv;
3682 char* cStr;
3683 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003684#ifndef CFStringCreateWithCString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003685 PyMac_PRECHECK(CFStringCreateWithCString);
Jack Jansenb3be2162001-11-30 14:16:36 +00003686#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003687 if (!PyArg_ParseTuple(_args, "sl",
3688 &cStr,
3689 &encoding))
3690 return NULL;
3691 _rv = CFStringCreateWithCString((CFAllocatorRef)NULL,
3692 cStr,
3693 encoding);
3694 _res = Py_BuildValue("O&",
3695 CFStringRefObj_New, _rv);
3696 return _res;
3697}
3698
Jack Jansen69ac3612002-01-01 22:43:13 +00003699static PyObject *CF_CFStringCreateWithCharacters(PyObject *_self, PyObject *_args)
3700{
3701 PyObject *_res = NULL;
3702 CFStringRef _rv;
3703 UniChar *chars__in__;
3704 UniCharCount chars__len__;
3705 int chars__in_len__;
3706#ifndef CFStringCreateWithCharacters
3707 PyMac_PRECHECK(CFStringCreateWithCharacters);
3708#endif
3709 if (!PyArg_ParseTuple(_args, "u#",
3710 &chars__in__, &chars__in_len__))
3711 return NULL;
3712 chars__len__ = chars__in_len__;
3713 _rv = CFStringCreateWithCharacters((CFAllocatorRef)NULL,
3714 chars__in__, chars__len__);
3715 _res = Py_BuildValue("O&",
3716 CFStringRefObj_New, _rv);
3717 return _res;
3718}
3719
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003720static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args)
3721{
3722 PyObject *_res = NULL;
3723 CFStringRef _rv;
Jack Jansen2168e9d2001-12-16 20:18:40 +00003724 Str255 pStr;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003725 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003726#ifndef CFStringCreateWithPascalStringNoCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003727 PyMac_PRECHECK(CFStringCreateWithPascalStringNoCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003728#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003729 if (!PyArg_ParseTuple(_args, "O&l",
Jack Jansen2168e9d2001-12-16 20:18:40 +00003730 PyMac_GetStr255, pStr,
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003731 &encoding))
3732 return NULL;
3733 _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL,
3734 pStr,
3735 encoding,
3736 (CFAllocatorRef)NULL);
3737 _res = Py_BuildValue("O&",
3738 CFStringRefObj_New, _rv);
3739 return _res;
3740}
3741
3742static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args)
3743{
3744 PyObject *_res = NULL;
3745 CFStringRef _rv;
3746 char* cStr;
3747 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003748#ifndef CFStringCreateWithCStringNoCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003749 PyMac_PRECHECK(CFStringCreateWithCStringNoCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003750#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003751 if (!PyArg_ParseTuple(_args, "sl",
3752 &cStr,
3753 &encoding))
3754 return NULL;
3755 _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL,
3756 cStr,
3757 encoding,
3758 (CFAllocatorRef)NULL);
3759 _res = Py_BuildValue("O&",
3760 CFStringRefObj_New, _rv);
3761 return _res;
3762}
3763
Jack Jansen69ac3612002-01-01 22:43:13 +00003764static PyObject *CF_CFStringCreateWithCharactersNoCopy(PyObject *_self, PyObject *_args)
3765{
3766 PyObject *_res = NULL;
3767 CFStringRef _rv;
3768 UniChar *chars__in__;
3769 UniCharCount chars__len__;
3770 int chars__in_len__;
3771#ifndef CFStringCreateWithCharactersNoCopy
3772 PyMac_PRECHECK(CFStringCreateWithCharactersNoCopy);
3773#endif
3774 if (!PyArg_ParseTuple(_args, "u#",
3775 &chars__in__, &chars__in_len__))
3776 return NULL;
3777 chars__len__ = chars__in_len__;
3778 _rv = CFStringCreateWithCharactersNoCopy((CFAllocatorRef)NULL,
3779 chars__in__, chars__len__,
3780 (CFAllocatorRef)NULL);
3781 _res = Py_BuildValue("O&",
3782 CFStringRefObj_New, _rv);
3783 return _res;
3784}
3785
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003786static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args)
3787{
3788 PyObject *_res = NULL;
3789 CFMutableStringRef _rv;
3790 CFIndex maxLength;
Jack Jansenb3be2162001-11-30 14:16:36 +00003791#ifndef CFStringCreateMutable
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003792 PyMac_PRECHECK(CFStringCreateMutable);
Jack Jansenb3be2162001-11-30 14:16:36 +00003793#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003794 if (!PyArg_ParseTuple(_args, "l",
3795 &maxLength))
3796 return NULL;
3797 _rv = CFStringCreateMutable((CFAllocatorRef)NULL,
3798 maxLength);
3799 _res = Py_BuildValue("O&",
3800 CFMutableStringRefObj_New, _rv);
3801 return _res;
3802}
3803
3804static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args)
3805{
3806 PyObject *_res = NULL;
3807 CFMutableStringRef _rv;
3808 CFIndex maxLength;
3809 CFStringRef theString;
Jack Jansenb3be2162001-11-30 14:16:36 +00003810#ifndef CFStringCreateMutableCopy
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003811 PyMac_PRECHECK(CFStringCreateMutableCopy);
Jack Jansenb3be2162001-11-30 14:16:36 +00003812#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003813 if (!PyArg_ParseTuple(_args, "lO&",
3814 &maxLength,
3815 CFStringRefObj_Convert, &theString))
3816 return NULL;
3817 _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL,
3818 maxLength,
3819 theString);
3820 _res = Py_BuildValue("O&",
3821 CFMutableStringRefObj_New, _rv);
3822 return _res;
3823}
3824
3825static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args)
3826{
3827 PyObject *_res = NULL;
3828 CFStringRef _rv;
3829 unsigned char *bytes__in__;
3830 long bytes__len__;
3831 int bytes__in_len__;
3832 CFStringEncoding encoding;
3833 Boolean isExternalRepresentation;
Jack Jansenb3be2162001-11-30 14:16:36 +00003834#ifndef CFStringCreateWithBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003835 PyMac_PRECHECK(CFStringCreateWithBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00003836#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003837 if (!PyArg_ParseTuple(_args, "s#ll",
3838 &bytes__in__, &bytes__in_len__,
3839 &encoding,
3840 &isExternalRepresentation))
3841 return NULL;
3842 bytes__len__ = bytes__in_len__;
3843 _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL,
3844 bytes__in__, bytes__len__,
3845 encoding,
3846 isExternalRepresentation);
3847 _res = Py_BuildValue("O&",
3848 CFStringRefObj_New, _rv);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003849 return _res;
3850}
3851
3852static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args)
3853{
3854 PyObject *_res = NULL;
3855 CFStringEncoding _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00003856#ifndef CFStringGetSystemEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003857 PyMac_PRECHECK(CFStringGetSystemEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003858#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003859 if (!PyArg_ParseTuple(_args, ""))
3860 return NULL;
3861 _rv = CFStringGetSystemEncoding();
3862 _res = Py_BuildValue("l",
3863 _rv);
3864 return _res;
3865}
3866
3867static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args)
3868{
3869 PyObject *_res = NULL;
3870 CFIndex _rv;
3871 CFIndex length;
3872 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003873#ifndef CFStringGetMaximumSizeForEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003874 PyMac_PRECHECK(CFStringGetMaximumSizeForEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003875#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003876 if (!PyArg_ParseTuple(_args, "ll",
3877 &length,
3878 &encoding))
3879 return NULL;
3880 _rv = CFStringGetMaximumSizeForEncoding(length,
3881 encoding);
3882 _res = Py_BuildValue("l",
3883 _rv);
3884 return _res;
3885}
3886
3887static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args)
3888{
3889 PyObject *_res = NULL;
3890 Boolean _rv;
3891 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003892#ifndef CFStringIsEncodingAvailable
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003893 PyMac_PRECHECK(CFStringIsEncodingAvailable);
Jack Jansenb3be2162001-11-30 14:16:36 +00003894#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003895 if (!PyArg_ParseTuple(_args, "l",
3896 &encoding))
3897 return NULL;
3898 _rv = CFStringIsEncodingAvailable(encoding);
3899 _res = Py_BuildValue("l",
3900 _rv);
3901 return _res;
3902}
3903
3904static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args)
3905{
3906 PyObject *_res = NULL;
3907 CFStringRef _rv;
3908 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003909#ifndef CFStringGetNameOfEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003910 PyMac_PRECHECK(CFStringGetNameOfEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003911#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003912 if (!PyArg_ParseTuple(_args, "l",
3913 &encoding))
3914 return NULL;
3915 _rv = CFStringGetNameOfEncoding(encoding);
3916 _res = Py_BuildValue("O&",
3917 CFStringRefObj_New, _rv);
3918 return _res;
3919}
3920
3921static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args)
3922{
3923 PyObject *_res = NULL;
3924 UInt32 _rv;
3925 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003926#ifndef CFStringConvertEncodingToNSStringEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003927 PyMac_PRECHECK(CFStringConvertEncodingToNSStringEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003928#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003929 if (!PyArg_ParseTuple(_args, "l",
3930 &encoding))
3931 return NULL;
3932 _rv = CFStringConvertEncodingToNSStringEncoding(encoding);
3933 _res = Py_BuildValue("l",
3934 _rv);
3935 return _res;
3936}
3937
3938static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args)
3939{
3940 PyObject *_res = NULL;
3941 CFStringEncoding _rv;
3942 UInt32 encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003943#ifndef CFStringConvertNSStringEncodingToEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003944 PyMac_PRECHECK(CFStringConvertNSStringEncodingToEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003945#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003946 if (!PyArg_ParseTuple(_args, "l",
3947 &encoding))
3948 return NULL;
3949 _rv = CFStringConvertNSStringEncodingToEncoding(encoding);
3950 _res = Py_BuildValue("l",
3951 _rv);
3952 return _res;
3953}
3954
3955static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args)
3956{
3957 PyObject *_res = NULL;
3958 UInt32 _rv;
3959 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003960#ifndef CFStringConvertEncodingToWindowsCodepage
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003961 PyMac_PRECHECK(CFStringConvertEncodingToWindowsCodepage);
Jack Jansenb3be2162001-11-30 14:16:36 +00003962#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003963 if (!PyArg_ParseTuple(_args, "l",
3964 &encoding))
3965 return NULL;
3966 _rv = CFStringConvertEncodingToWindowsCodepage(encoding);
3967 _res = Py_BuildValue("l",
3968 _rv);
3969 return _res;
3970}
3971
3972static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args)
3973{
3974 PyObject *_res = NULL;
3975 CFStringEncoding _rv;
3976 UInt32 codepage;
Jack Jansenb3be2162001-11-30 14:16:36 +00003977#ifndef CFStringConvertWindowsCodepageToEncoding
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003978 PyMac_PRECHECK(CFStringConvertWindowsCodepageToEncoding);
Jack Jansenb3be2162001-11-30 14:16:36 +00003979#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003980 if (!PyArg_ParseTuple(_args, "l",
3981 &codepage))
3982 return NULL;
3983 _rv = CFStringConvertWindowsCodepageToEncoding(codepage);
3984 _res = Py_BuildValue("l",
3985 _rv);
3986 return _res;
3987}
3988
3989static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args)
3990{
3991 PyObject *_res = NULL;
3992 CFStringRef _rv;
3993 CFStringEncoding encoding;
Jack Jansenb3be2162001-11-30 14:16:36 +00003994#ifndef CFStringConvertEncodingToIANACharSetName
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003995 PyMac_PRECHECK(CFStringConvertEncodingToIANACharSetName);
Jack Jansenb3be2162001-11-30 14:16:36 +00003996#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00003997 if (!PyArg_ParseTuple(_args, "l",
3998 &encoding))
3999 return NULL;
4000 _rv = CFStringConvertEncodingToIANACharSetName(encoding);
4001 _res = Py_BuildValue("O&",
4002 CFStringRefObj_New, _rv);
4003 return _res;
4004}
4005
Jack Jansen2168e9d2001-12-16 20:18:40 +00004006static PyObject *CF_CFStringGetMostCompatibleMacStringEncoding(PyObject *_self, PyObject *_args)
4007{
4008 PyObject *_res = NULL;
4009 CFStringEncoding _rv;
4010 CFStringEncoding encoding;
4011#ifndef CFStringGetMostCompatibleMacStringEncoding
4012 PyMac_PRECHECK(CFStringGetMostCompatibleMacStringEncoding);
4013#endif
4014 if (!PyArg_ParseTuple(_args, "l",
4015 &encoding))
4016 return NULL;
4017 _rv = CFStringGetMostCompatibleMacStringEncoding(encoding);
4018 _res = Py_BuildValue("l",
4019 _rv);
4020 return _res;
4021}
4022
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004023static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args)
4024{
4025 PyObject *_res = NULL;
4026 CFStringRef _rv;
4027 char* cStr;
Jack Jansenb3be2162001-11-30 14:16:36 +00004028#ifndef __CFStringMakeConstantString
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004029 PyMac_PRECHECK(__CFStringMakeConstantString);
Jack Jansenb3be2162001-11-30 14:16:36 +00004030#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004031 if (!PyArg_ParseTuple(_args, "s",
4032 &cStr))
4033 return NULL;
4034 _rv = __CFStringMakeConstantString(cStr);
4035 _res = Py_BuildValue("O&",
4036 CFStringRefObj_New, _rv);
4037 return _res;
4038}
4039
4040static PyObject *CF_CFURLGetTypeID(PyObject *_self, PyObject *_args)
4041{
4042 PyObject *_res = NULL;
4043 CFTypeID _rv;
Jack Jansenb3be2162001-11-30 14:16:36 +00004044#ifndef CFURLGetTypeID
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004045 PyMac_PRECHECK(CFURLGetTypeID);
Jack Jansenb3be2162001-11-30 14:16:36 +00004046#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004047 if (!PyArg_ParseTuple(_args, ""))
4048 return NULL;
4049 _rv = CFURLGetTypeID();
4050 _res = Py_BuildValue("l",
4051 _rv);
4052 return _res;
4053}
4054
4055static PyObject *CF_CFURLCreateWithBytes(PyObject *_self, PyObject *_args)
4056{
4057 PyObject *_res = NULL;
4058 CFURLRef _rv;
4059 unsigned char *URLBytes__in__;
4060 long URLBytes__len__;
4061 int URLBytes__in_len__;
4062 CFStringEncoding encoding;
4063 CFURLRef baseURL;
Jack Jansenb3be2162001-11-30 14:16:36 +00004064#ifndef CFURLCreateWithBytes
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004065 PyMac_PRECHECK(CFURLCreateWithBytes);
Jack Jansenb3be2162001-11-30 14:16:36 +00004066#endif
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004067 if (!PyArg_ParseTuple(_args, "s#lO&",
4068 &URLBytes__in__, &URLBytes__in_len__,
4069 &encoding,
4070 OptionalCFURLRefObj_Convert, &baseURL))
4071 return NULL;
4072 URLBytes__len__ = URLBytes__in_len__;
4073 _rv = CFURLCreateWithBytes((CFAllocatorRef)NULL,
4074 URLBytes__in__, URLBytes__len__,
4075 encoding,
4076 baseURL);
4077 _res = Py_BuildValue("O&",
4078 CFURLRefObj_New, _rv);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004079 return _res;
4080}
4081
Jack Jansen2168e9d2001-12-16 20:18:40 +00004082static PyObject *CF_CFURLCreateFromFileSystemRepresentation(PyObject *_self, PyObject *_args)
4083{
4084 PyObject *_res = NULL;
4085 CFURLRef _rv;
4086 unsigned char *buffer__in__;
4087 long buffer__len__;
4088 int buffer__in_len__;
4089 Boolean isDirectory;
4090#ifndef CFURLCreateFromFileSystemRepresentation
4091 PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentation);
4092#endif
4093 if (!PyArg_ParseTuple(_args, "s#l",
4094 &buffer__in__, &buffer__in_len__,
4095 &isDirectory))
4096 return NULL;
4097 buffer__len__ = buffer__in_len__;
4098 _rv = CFURLCreateFromFileSystemRepresentation((CFAllocatorRef)NULL,
4099 buffer__in__, buffer__len__,
4100 isDirectory);
4101 _res = Py_BuildValue("O&",
4102 CFURLRefObj_New, _rv);
4103 return _res;
4104}
4105
4106static PyObject *CF_CFURLCreateFromFileSystemRepresentationRelativeToBase(PyObject *_self, PyObject *_args)
4107{
4108 PyObject *_res = NULL;
4109 CFURLRef _rv;
4110 unsigned char *buffer__in__;
4111 long buffer__len__;
4112 int buffer__in_len__;
4113 Boolean isDirectory;
4114 CFURLRef baseURL;
4115#ifndef CFURLCreateFromFileSystemRepresentationRelativeToBase
4116 PyMac_PRECHECK(CFURLCreateFromFileSystemRepresentationRelativeToBase);
4117#endif
4118 if (!PyArg_ParseTuple(_args, "s#lO&",
4119 &buffer__in__, &buffer__in_len__,
4120 &isDirectory,
4121 OptionalCFURLRefObj_Convert, &baseURL))
4122 return NULL;
4123 buffer__len__ = buffer__in_len__;
4124 _rv = CFURLCreateFromFileSystemRepresentationRelativeToBase((CFAllocatorRef)NULL,
4125 buffer__in__, buffer__len__,
4126 isDirectory,
4127 baseURL);
4128 _res = Py_BuildValue("O&",
4129 CFURLRefObj_New, _rv);
4130 return _res;
4131}
4132
4133static PyObject *CF_CFURLCreateFromFSRef(PyObject *_self, PyObject *_args)
4134{
4135 PyObject *_res = NULL;
4136 CFURLRef _rv;
4137 FSRef fsRef;
4138#ifndef CFURLCreateFromFSRef
4139 PyMac_PRECHECK(CFURLCreateFromFSRef);
4140#endif
4141 if (!PyArg_ParseTuple(_args, "O&",
4142 PyMac_GetFSRef, &fsRef))
4143 return NULL;
4144 _rv = CFURLCreateFromFSRef((CFAllocatorRef)NULL,
4145 &fsRef);
4146 _res = Py_BuildValue("O&",
4147 CFURLRefObj_New, _rv);
4148 return _res;
4149}
4150
Jack Jansen5ad6f7a2002-05-07 23:00:03 +00004151static PyObject *CF_toCF(PyObject *_self, PyObject *_args)
4152{
4153 PyObject *_res = NULL;
4154
4155 CFTypeRef rv;
4156 CFTypeID typeid;
4157
4158 if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
4159 return NULL;
4160 typeid = CFGetTypeID(rv);
4161
4162 if (typeid == CFStringGetTypeID())
4163 return Py_BuildValue("O&", CFStringRefObj_New, rv);
4164 if (typeid == CFArrayGetTypeID())
4165 return Py_BuildValue("O&", CFArrayRefObj_New, rv);
4166 if (typeid == CFDictionaryGetTypeID())
4167 return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
4168 if (typeid == CFURLGetTypeID())
4169 return Py_BuildValue("O&", CFURLRefObj_New, rv);
4170
Jack Jansen234d0742002-12-23 22:35:38 +00004171 _res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
4172 return _res;
Jack Jansen5ad6f7a2002-05-07 23:00:03 +00004173
4174}
4175
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004176static PyMethodDef CF_methods[] = {
Jack Jansen2168e9d2001-12-16 20:18:40 +00004177 {"__CFRangeMake", (PyCFunction)CF___CFRangeMake, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004178 PyDoc_STR("(CFIndex loc, CFIndex len) -> (CFRange _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004179 {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004180 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004181 {"CFAllocatorGetPreferredSizeForSize", (PyCFunction)CF_CFAllocatorGetPreferredSizeForSize, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004182 PyDoc_STR("(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004183 {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004184 PyDoc_STR("(CFTypeID type_id) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004185 {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004186 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004187 {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004188 PyDoc_STR("(CFIndex capacity) -> (CFMutableArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004189 {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004190 PyDoc_STR("(CFIndex capacity, CFArrayRef theArray) -> (CFMutableArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004191 {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004192 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004193 {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004194 PyDoc_STR("(Buffer bytes) -> (CFDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004195 {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004196 PyDoc_STR("(Buffer bytes) -> (CFDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004197 {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004198 PyDoc_STR("(CFIndex capacity) -> (CFMutableDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004199 {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004200 PyDoc_STR("(CFIndex capacity, CFDataRef theData) -> (CFMutableDataRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004201 {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004202 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004203 {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004204 PyDoc_STR("(CFIndex capacity) -> (CFMutableDictionaryRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004205 {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004206 PyDoc_STR("(CFIndex capacity, CFDictionaryRef theDict) -> (CFMutableDictionaryRef _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004207 {"CFPreferencesCopyAppValue", (PyCFunction)CF_CFPreferencesCopyAppValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004208 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (CFTypeRef _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004209 {"CFPreferencesGetAppBooleanValue", (PyCFunction)CF_CFPreferencesGetAppBooleanValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004210 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (Boolean _rv, Boolean keyExistsAndHasValidFormat)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004211 {"CFPreferencesGetAppIntegerValue", (PyCFunction)CF_CFPreferencesGetAppIntegerValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004212 PyDoc_STR("(CFStringRef key, CFStringRef applicationID) -> (CFIndex _rv, Boolean keyExistsAndHasValidFormat)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004213 {"CFPreferencesSetAppValue", (PyCFunction)CF_CFPreferencesSetAppValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004214 PyDoc_STR("(CFStringRef key, CFTypeRef value, CFStringRef applicationID) -> None")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004215 {"CFPreferencesAddSuitePreferencesToApp", (PyCFunction)CF_CFPreferencesAddSuitePreferencesToApp, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004216 PyDoc_STR("(CFStringRef applicationID, CFStringRef suiteID) -> None")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004217 {"CFPreferencesRemoveSuitePreferencesFromApp", (PyCFunction)CF_CFPreferencesRemoveSuitePreferencesFromApp, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004218 PyDoc_STR("(CFStringRef applicationID, CFStringRef suiteID) -> None")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004219 {"CFPreferencesAppSynchronize", (PyCFunction)CF_CFPreferencesAppSynchronize, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004220 PyDoc_STR("(CFStringRef applicationID) -> (Boolean _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004221 {"CFPreferencesCopyValue", (PyCFunction)CF_CFPreferencesCopyValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004222 PyDoc_STR("(CFStringRef key, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFTypeRef _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004223 {"CFPreferencesCopyMultiple", (PyCFunction)CF_CFPreferencesCopyMultiple, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004224 PyDoc_STR("(CFArrayRef keysToFetch, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFDictionaryRef _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004225 {"CFPreferencesSetValue", (PyCFunction)CF_CFPreferencesSetValue, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004226 PyDoc_STR("(CFStringRef key, CFTypeRef value, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> None")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004227 {"CFPreferencesSetMultiple", (PyCFunction)CF_CFPreferencesSetMultiple, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004228 PyDoc_STR("(CFDictionaryRef keysToSet, CFArrayRef keysToRemove, CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> None")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004229 {"CFPreferencesSynchronize", (PyCFunction)CF_CFPreferencesSynchronize, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004230 PyDoc_STR("(CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (Boolean _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004231 {"CFPreferencesCopyApplicationList", (PyCFunction)CF_CFPreferencesCopyApplicationList, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004232 PyDoc_STR("(CFStringRef userName, CFStringRef hostName) -> (CFArrayRef _rv)")},
Jack Jansen23be1ce2002-05-13 21:21:49 +00004233 {"CFPreferencesCopyKeyList", (PyCFunction)CF_CFPreferencesCopyKeyList, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004234 PyDoc_STR("(CFStringRef applicationID, CFStringRef userName, CFStringRef hostName) -> (CFArrayRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004235 {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004236 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004237 {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004238 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004239 {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004240 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen69ac3612002-01-01 22:43:13 +00004241 {"CFStringCreateWithCharacters", (PyCFunction)CF_CFStringCreateWithCharacters, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004242 PyDoc_STR("(Buffer chars) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004243 {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004244 PyDoc_STR("(Str255 pStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004245 {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004246 PyDoc_STR("(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen69ac3612002-01-01 22:43:13 +00004247 {"CFStringCreateWithCharactersNoCopy", (PyCFunction)CF_CFStringCreateWithCharactersNoCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004248 PyDoc_STR("(Buffer chars) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004249 {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004250 PyDoc_STR("(CFIndex maxLength) -> (CFMutableStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004251 {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004252 PyDoc_STR("(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004253 {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004254 PyDoc_STR("(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004255 {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004256 PyDoc_STR("() -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004257 {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004258 PyDoc_STR("(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004259 {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004260 PyDoc_STR("(CFStringEncoding encoding) -> (Boolean _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004261 {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004262 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004263 {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004264 PyDoc_STR("(CFStringEncoding encoding) -> (UInt32 _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004265 {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004266 PyDoc_STR("(UInt32 encoding) -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004267 {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004268 PyDoc_STR("(CFStringEncoding encoding) -> (UInt32 _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004269 {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004270 PyDoc_STR("(UInt32 codepage) -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004271 {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004272 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00004273 {"CFStringGetMostCompatibleMacStringEncoding", (PyCFunction)CF_CFStringGetMostCompatibleMacStringEncoding, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004274 PyDoc_STR("(CFStringEncoding encoding) -> (CFStringEncoding _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004275 {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004276 PyDoc_STR("(char* cStr) -> (CFStringRef _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004277 {"CFURLGetTypeID", (PyCFunction)CF_CFURLGetTypeID, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004278 PyDoc_STR("() -> (CFTypeID _rv)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004279 {"CFURLCreateWithBytes", (PyCFunction)CF_CFURLCreateWithBytes, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004280 PyDoc_STR("(Buffer URLBytes, CFStringEncoding encoding, CFURLRef baseURL) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00004281 {"CFURLCreateFromFileSystemRepresentation", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentation, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004282 PyDoc_STR("(Buffer buffer, Boolean isDirectory) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00004283 {"CFURLCreateFromFileSystemRepresentationRelativeToBase", (PyCFunction)CF_CFURLCreateFromFileSystemRepresentationRelativeToBase, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004284 PyDoc_STR("(Buffer buffer, Boolean isDirectory, CFURLRef baseURL) -> (CFURLRef _rv)")},
Jack Jansen2168e9d2001-12-16 20:18:40 +00004285 {"CFURLCreateFromFSRef", (PyCFunction)CF_CFURLCreateFromFSRef, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004286 PyDoc_STR("(FSRef fsRef) -> (CFURLRef _rv)")},
Jack Jansen5ad6f7a2002-05-07 23:00:03 +00004287 {"toCF", (PyCFunction)CF_toCF, 1,
Jack Jansen49931882002-08-16 09:09:31 +00004288 PyDoc_STR("(python_object) -> (CF_object)")},
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004289 {NULL, NULL, 0}
4290};
4291
4292
4293
4294
4295void init_CF(void)
4296{
4297 PyObject *m;
4298 PyObject *d;
4299
4300
4301
Jack Jansen537a69f2001-11-05 14:39:22 +00004302 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
4303 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
4304 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
4305 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
4306 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
4307 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
4308
4309 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
4310 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
4311 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
4312 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
4313 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
4314 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
4315 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
4316 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
4317 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
4318 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
4319 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004320
4321
4322 m = Py_InitModule("_CF", CF_methods);
4323 d = PyModule_GetDict(m);
4324 CF_Error = PyMac_GetOSErrException();
4325 if (CF_Error == NULL ||
4326 PyDict_SetItemString(d, "Error", CF_Error) != 0)
4327 return;
4328 CFTypeRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004329 if (PyType_Ready(&CFTypeRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004330 Py_INCREF(&CFTypeRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004331 PyModule_AddObject(m, "CFTypeRef", (PyObject *)&CFTypeRef_Type);
4332 /* Backward-compatible name */
4333 Py_INCREF(&CFTypeRef_Type);
4334 PyModule_AddObject(m, "CFTypeRefType", (PyObject *)&CFTypeRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004335 CFArrayRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004336 if (PyType_Ready(&CFArrayRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004337 Py_INCREF(&CFArrayRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004338 PyModule_AddObject(m, "CFArrayRef", (PyObject *)&CFArrayRef_Type);
4339 /* Backward-compatible name */
4340 Py_INCREF(&CFArrayRef_Type);
4341 PyModule_AddObject(m, "CFArrayRefType", (PyObject *)&CFArrayRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004342 CFMutableArrayRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004343 if (PyType_Ready(&CFMutableArrayRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004344 Py_INCREF(&CFMutableArrayRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004345 PyModule_AddObject(m, "CFMutableArrayRef", (PyObject *)&CFMutableArrayRef_Type);
4346 /* Backward-compatible name */
4347 Py_INCREF(&CFMutableArrayRef_Type);
4348 PyModule_AddObject(m, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004349 CFDictionaryRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004350 if (PyType_Ready(&CFDictionaryRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004351 Py_INCREF(&CFDictionaryRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004352 PyModule_AddObject(m, "CFDictionaryRef", (PyObject *)&CFDictionaryRef_Type);
4353 /* Backward-compatible name */
4354 Py_INCREF(&CFDictionaryRef_Type);
4355 PyModule_AddObject(m, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004356 CFMutableDictionaryRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004357 if (PyType_Ready(&CFMutableDictionaryRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004358 Py_INCREF(&CFMutableDictionaryRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004359 PyModule_AddObject(m, "CFMutableDictionaryRef", (PyObject *)&CFMutableDictionaryRef_Type);
4360 /* Backward-compatible name */
4361 Py_INCREF(&CFMutableDictionaryRef_Type);
4362 PyModule_AddObject(m, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004363 CFDataRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004364 if (PyType_Ready(&CFDataRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004365 Py_INCREF(&CFDataRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004366 PyModule_AddObject(m, "CFDataRef", (PyObject *)&CFDataRef_Type);
4367 /* Backward-compatible name */
4368 Py_INCREF(&CFDataRef_Type);
4369 PyModule_AddObject(m, "CFDataRefType", (PyObject *)&CFDataRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004370 CFMutableDataRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004371 if (PyType_Ready(&CFMutableDataRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004372 Py_INCREF(&CFMutableDataRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004373 PyModule_AddObject(m, "CFMutableDataRef", (PyObject *)&CFMutableDataRef_Type);
4374 /* Backward-compatible name */
4375 Py_INCREF(&CFMutableDataRef_Type);
4376 PyModule_AddObject(m, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004377 CFStringRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004378 if (PyType_Ready(&CFStringRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004379 Py_INCREF(&CFStringRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004380 PyModule_AddObject(m, "CFStringRef", (PyObject *)&CFStringRef_Type);
4381 /* Backward-compatible name */
4382 Py_INCREF(&CFStringRef_Type);
4383 PyModule_AddObject(m, "CFStringRefType", (PyObject *)&CFStringRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004384 CFMutableStringRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004385 if (PyType_Ready(&CFMutableStringRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004386 Py_INCREF(&CFMutableStringRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004387 PyModule_AddObject(m, "CFMutableStringRef", (PyObject *)&CFMutableStringRef_Type);
4388 /* Backward-compatible name */
4389 Py_INCREF(&CFMutableStringRef_Type);
4390 PyModule_AddObject(m, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type);
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004391 CFURLRef_Type.ob_type = &PyType_Type;
Jack Jansen234d0742002-12-23 22:35:38 +00004392 if (PyType_Ready(&CFURLRef_Type) < 0) return;
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004393 Py_INCREF(&CFURLRef_Type);
Jack Jansen96cebde2002-12-03 23:40:22 +00004394 PyModule_AddObject(m, "CFURLRef", (PyObject *)&CFURLRef_Type);
4395 /* Backward-compatible name */
4396 Py_INCREF(&CFURLRef_Type);
4397 PyModule_AddObject(m, "CFURLRefType", (PyObject *)&CFURLRef_Type);
Jack Jansen23be1ce2002-05-13 21:21:49 +00004398
4399#define _STRINGCONST(name) PyModule_AddObject(m, #name, CFStringRefObj_New(name))
4400 _STRINGCONST(kCFPreferencesAnyApplication);
4401 _STRINGCONST(kCFPreferencesCurrentApplication);
4402 _STRINGCONST(kCFPreferencesAnyHost);
4403 _STRINGCONST(kCFPreferencesCurrentHost);
4404 _STRINGCONST(kCFPreferencesAnyUser);
4405 _STRINGCONST(kCFPreferencesCurrentUser);
4406
4407
4408
Jack Jansen50ecb0a2001-08-23 14:02:09 +00004409}
4410
4411/* ========================= End module _CF ========================= */
4412