PageRenderTime 60ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/Mac/Modules/cf/_CFmodule.c

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