PageRenderTime 71ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Mac/Modules/file/_Filemodule.c

http://unladen-swallow.googlecode.com/
C | 3410 lines | 3040 code | 322 blank | 48 comment | 380 complexity | cf7ba1a10e4ee6fdbeaf4f9220fe8bfd MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause
  1. /* ========================== Module _File ========================== */
  2. #include "Python.h"
  3. #include "pymactoolbox.h"
  4. #ifndef HAVE_OSX105_SDK
  5. typedef SInt16 FSIORefNum;
  6. #endif
  7. /* Macro to test whether a weak-loaded CFM function exists */
  8. #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
  9. PyErr_SetString(PyExc_NotImplementedError, \
  10. "Not available in this shared library/OS version"); \
  11. return NULL; \
  12. }} while(0)
  13. #include <Carbon/Carbon.h>
  14. #ifdef USE_TOOLBOX_OBJECT_GLUE
  15. #ifndef __LP64__
  16. extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
  17. extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
  18. #define PyMac_BuildFSSpec _PyMac_BuildFSSpec
  19. #endif /* __LP64__*/
  20. extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
  21. extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
  22. #define PyMac_BuildFSRef _PyMac_BuildFSRef
  23. #define PyMac_GetFSSpec _PyMac_GetFSSpec
  24. #define PyMac_GetFSRef _PyMac_GetFSRef
  25. #else /* !USE_TOOLBOX_OBJECT_GLUE */
  26. #ifndef __LP64__
  27. extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
  28. extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
  29. #endif /* !__LP64__*/
  30. extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
  31. extern PyObject *PyMac_BuildFSRef(FSRef *spec);
  32. #endif /* !USE_TOOLBOX_OBJECT_GLUE */
  33. /* Forward declarations */
  34. static PyObject *FSRef_New(FSRef *itself);
  35. #ifndef __LP64__
  36. static PyObject *FInfo_New(FInfo *itself);
  37. static PyObject *FSSpec_New(FSSpec *itself);
  38. #define FSSpec_Convert PyMac_GetFSSpec
  39. #endif /* !__LP64__ */
  40. static PyObject *Alias_New(AliasHandle itself);
  41. #ifndef __LP64__
  42. static int FInfo_Convert(PyObject *v, FInfo *p_itself);
  43. #endif /* !__LP64__ */
  44. #define FSRef_Convert PyMac_GetFSRef
  45. static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
  46. /*
  47. ** UTCDateTime records
  48. */
  49. static int
  50. UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr)
  51. {
  52. return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction);
  53. }
  54. static PyObject *
  55. UTCDateTime_New(UTCDateTime *ptr)
  56. {
  57. return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction);
  58. }
  59. /*
  60. ** Optional fsspec and fsref pointers. None will pass NULL
  61. */
  62. #ifndef __LP64__
  63. static int
  64. myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
  65. {
  66. if (v == Py_None) {
  67. *spec = NULL;
  68. return 1;
  69. }
  70. return PyMac_GetFSSpec(v, *spec);
  71. }
  72. #endif /* !__LP64__ */
  73. static int
  74. myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
  75. {
  76. if (v == Py_None) {
  77. *ref = NULL;
  78. return 1;
  79. }
  80. return PyMac_GetFSRef(v, *ref);
  81. }
  82. /*
  83. ** Parse/generate objsect
  84. */
  85. static PyObject *
  86. PyMac_BuildHFSUniStr255(HFSUniStr255 *itself)
  87. {
  88. return Py_BuildValue("u#", itself->unicode, itself->length);
  89. }
  90. #ifndef __LP64__
  91. static OSErr
  92. _PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
  93. {
  94. FSRef fsr;
  95. OSErr err;
  96. *path = '\0';
  97. err = FSpMakeFSRef(fss, &fsr);
  98. if (err == fnfErr) {
  99. /* FSSpecs can point to non-existing files, fsrefs can't. */
  100. FSSpec fss2;
  101. int tocopy;
  102. err = FSMakeFSSpec(fss->vRefNum, fss->parID,
  103. (unsigned char*)"", &fss2);
  104. if (err)
  105. return err;
  106. err = FSpMakeFSRef(&fss2, &fsr);
  107. if (err)
  108. return err;
  109. err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len-1);
  110. if (err)
  111. return err;
  112. /* This part is not 100% safe: we append the filename part, but
  113. ** I'm not sure that we don't run afoul of the various 8bit
  114. ** encodings here. Will have to look this up at some point...
  115. */
  116. strcat(path, "/");
  117. tocopy = fss->name[0];
  118. if ((strlen(path) + tocopy) >= len)
  119. tocopy = len - strlen(path) - 1;
  120. if (tocopy > 0)
  121. strncat(path, (char*)fss->name+1, tocopy);
  122. }
  123. else {
  124. if (err)
  125. return err;
  126. err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len);
  127. if (err)
  128. return err;
  129. }
  130. return 0;
  131. }
  132. #endif /* !__LP64__ */
  133. static PyObject *File_Error;
  134. /* ------------------- Object type FSCatalogInfo -------------------- */
  135. static PyTypeObject FSCatalogInfo_Type;
  136. #define FSCatalogInfo_Check(x) ((x)->ob_type == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type))
  137. typedef struct FSCatalogInfoObject {
  138. PyObject_HEAD
  139. FSCatalogInfo ob_itself;
  140. } FSCatalogInfoObject;
  141. static PyObject *FSCatalogInfo_New(FSCatalogInfo *itself)
  142. {
  143. FSCatalogInfoObject *it;
  144. if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }
  145. it = PyObject_NEW(FSCatalogInfoObject, &FSCatalogInfo_Type);
  146. if (it == NULL) return NULL;
  147. it->ob_itself = *itself;
  148. return (PyObject *)it;
  149. }
  150. static int FSCatalogInfo_Convert(PyObject *v, FSCatalogInfo *p_itself)
  151. {
  152. if (!FSCatalogInfo_Check(v))
  153. {
  154. PyErr_SetString(PyExc_TypeError, "FSCatalogInfo required");
  155. return 0;
  156. }
  157. *p_itself = ((FSCatalogInfoObject *)v)->ob_itself;
  158. return 1;
  159. }
  160. static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
  161. {
  162. /* Cleanup of self->ob_itself goes here */
  163. self->ob_type->tp_free((PyObject *)self);
  164. }
  165. static PyMethodDef FSCatalogInfo_methods[] = {
  166. {NULL, NULL, 0}
  167. };
  168. static PyObject *FSCatalogInfo_get_nodeFlags(FSCatalogInfoObject *self, void *closure)
  169. {
  170. return Py_BuildValue("H", self->ob_itself.nodeFlags);
  171. }
  172. static int FSCatalogInfo_set_nodeFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
  173. {
  174. return PyArg_Parse(v, "H", &self->ob_itself.nodeFlags)-1;
  175. return 0;
  176. }
  177. static PyObject *FSCatalogInfo_get_volume(FSCatalogInfoObject *self, void *closure)
  178. {
  179. return Py_BuildValue("h", self->ob_itself.volume);
  180. }
  181. static int FSCatalogInfo_set_volume(FSCatalogInfoObject *self, PyObject *v, void *closure)
  182. {
  183. return PyArg_Parse(v, "h", &self->ob_itself.volume)-1;
  184. return 0;
  185. }
  186. static PyObject *FSCatalogInfo_get_parentDirID(FSCatalogInfoObject *self, void *closure)
  187. {
  188. return Py_BuildValue("l", self->ob_itself.parentDirID);
  189. }
  190. static int FSCatalogInfo_set_parentDirID(FSCatalogInfoObject *self, PyObject *v, void *closure)
  191. {
  192. return PyArg_Parse(v, "l", &self->ob_itself.parentDirID)-1;
  193. return 0;
  194. }
  195. static PyObject *FSCatalogInfo_get_nodeID(FSCatalogInfoObject *self, void *closure)
  196. {
  197. return Py_BuildValue("l", self->ob_itself.nodeID);
  198. }
  199. static int FSCatalogInfo_set_nodeID(FSCatalogInfoObject *self, PyObject *v, void *closure)
  200. {
  201. return PyArg_Parse(v, "l", &self->ob_itself.nodeID)-1;
  202. return 0;
  203. }
  204. static PyObject *FSCatalogInfo_get_createDate(FSCatalogInfoObject *self, void *closure)
  205. {
  206. return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.createDate);
  207. }
  208. static int FSCatalogInfo_set_createDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
  209. {
  210. return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.createDate)-1;
  211. return 0;
  212. }
  213. static PyObject *FSCatalogInfo_get_contentModDate(FSCatalogInfoObject *self, void *closure)
  214. {
  215. return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.contentModDate);
  216. }
  217. static int FSCatalogInfo_set_contentModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
  218. {
  219. return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.contentModDate)-1;
  220. return 0;
  221. }
  222. static PyObject *FSCatalogInfo_get_attributeModDate(FSCatalogInfoObject *self, void *closure)
  223. {
  224. return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.attributeModDate);
  225. }
  226. static int FSCatalogInfo_set_attributeModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
  227. {
  228. return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.attributeModDate)-1;
  229. return 0;
  230. }
  231. static PyObject *FSCatalogInfo_get_accessDate(FSCatalogInfoObject *self, void *closure)
  232. {
  233. return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.accessDate);
  234. }
  235. static int FSCatalogInfo_set_accessDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
  236. {
  237. return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.accessDate)-1;
  238. return 0;
  239. }
  240. static PyObject *FSCatalogInfo_get_backupDate(FSCatalogInfoObject *self, void *closure)
  241. {
  242. return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.backupDate);
  243. }
  244. static int FSCatalogInfo_set_backupDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
  245. {
  246. return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.backupDate)-1;
  247. return 0;
  248. }
  249. static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
  250. {
  251. FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
  252. return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
  253. }
  254. static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
  255. {
  256. long userID;
  257. long groupID;
  258. long userAccess;
  259. long mode;
  260. int r;
  261. FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
  262. r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
  263. if (!r) {
  264. return -1;
  265. }
  266. info->userID = userID;
  267. info->groupID = groupID;
  268. info->userAccess = userAccess;
  269. info->mode = mode;
  270. return 0;
  271. }
  272. static PyObject *FSCatalogInfo_get_valence(FSCatalogInfoObject *self, void *closure)
  273. {
  274. return Py_BuildValue("l", self->ob_itself.valence);
  275. }
  276. static int FSCatalogInfo_set_valence(FSCatalogInfoObject *self, PyObject *v, void *closure)
  277. {
  278. return PyArg_Parse(v, "l", &self->ob_itself.valence)-1;
  279. return 0;
  280. }
  281. static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject *self, void *closure)
  282. {
  283. return Py_BuildValue("l", self->ob_itself.dataLogicalSize);
  284. }
  285. static int FSCatalogInfo_set_dataLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
  286. {
  287. return PyArg_Parse(v, "l", &self->ob_itself.dataLogicalSize)-1;
  288. return 0;
  289. }
  290. static PyObject *FSCatalogInfo_get_dataPhysicalSize(FSCatalogInfoObject *self, void *closure)
  291. {
  292. return Py_BuildValue("l", self->ob_itself.dataPhysicalSize);
  293. }
  294. static int FSCatalogInfo_set_dataPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
  295. {
  296. return PyArg_Parse(v, "l", &self->ob_itself.dataPhysicalSize)-1;
  297. return 0;
  298. }
  299. static PyObject *FSCatalogInfo_get_rsrcLogicalSize(FSCatalogInfoObject *self, void *closure)
  300. {
  301. return Py_BuildValue("l", self->ob_itself.rsrcLogicalSize);
  302. }
  303. static int FSCatalogInfo_set_rsrcLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
  304. {
  305. return PyArg_Parse(v, "l", &self->ob_itself.rsrcLogicalSize)-1;
  306. return 0;
  307. }
  308. static PyObject *FSCatalogInfo_get_rsrcPhysicalSize(FSCatalogInfoObject *self, void *closure)
  309. {
  310. return Py_BuildValue("l", self->ob_itself.rsrcPhysicalSize);
  311. }
  312. static int FSCatalogInfo_set_rsrcPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
  313. {
  314. return PyArg_Parse(v, "l", &self->ob_itself.rsrcPhysicalSize)-1;
  315. return 0;
  316. }
  317. static PyObject *FSCatalogInfo_get_sharingFlags(FSCatalogInfoObject *self, void *closure)
  318. {
  319. return Py_BuildValue("l", self->ob_itself.sharingFlags);
  320. }
  321. static int FSCatalogInfo_set_sharingFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
  322. {
  323. return PyArg_Parse(v, "l", &self->ob_itself.sharingFlags)-1;
  324. return 0;
  325. }
  326. static PyObject *FSCatalogInfo_get_userPrivileges(FSCatalogInfoObject *self, void *closure)
  327. {
  328. return Py_BuildValue("b", self->ob_itself.userPrivileges);
  329. }
  330. static int FSCatalogInfo_set_userPrivileges(FSCatalogInfoObject *self, PyObject *v, void *closure)
  331. {
  332. return PyArg_Parse(v, "b", &self->ob_itself.userPrivileges)-1;
  333. return 0;
  334. }
  335. static PyGetSetDef FSCatalogInfo_getsetlist[] = {
  336. {"nodeFlags", (getter)FSCatalogInfo_get_nodeFlags, (setter)FSCatalogInfo_set_nodeFlags, NULL},
  337. {"volume", (getter)FSCatalogInfo_get_volume, (setter)FSCatalogInfo_set_volume, NULL},
  338. {"parentDirID", (getter)FSCatalogInfo_get_parentDirID, (setter)FSCatalogInfo_set_parentDirID, NULL},
  339. {"nodeID", (getter)FSCatalogInfo_get_nodeID, (setter)FSCatalogInfo_set_nodeID, NULL},
  340. {"createDate", (getter)FSCatalogInfo_get_createDate, (setter)FSCatalogInfo_set_createDate, NULL},
  341. {"contentModDate", (getter)FSCatalogInfo_get_contentModDate, (setter)FSCatalogInfo_set_contentModDate, NULL},
  342. {"attributeModDate", (getter)FSCatalogInfo_get_attributeModDate, (setter)FSCatalogInfo_set_attributeModDate, NULL},
  343. {"accessDate", (getter)FSCatalogInfo_get_accessDate, (setter)FSCatalogInfo_set_accessDate, NULL},
  344. {"backupDate", (getter)FSCatalogInfo_get_backupDate, (setter)FSCatalogInfo_set_backupDate, NULL},
  345. {"permissions", (getter)FSCatalogInfo_get_permissions, (setter)FSCatalogInfo_set_permissions, NULL},
  346. {"valence", (getter)FSCatalogInfo_get_valence, (setter)FSCatalogInfo_set_valence, NULL},
  347. {"dataLogicalSize", (getter)FSCatalogInfo_get_dataLogicalSize, (setter)FSCatalogInfo_set_dataLogicalSize, NULL},
  348. {"dataPhysicalSize", (getter)FSCatalogInfo_get_dataPhysicalSize, (setter)FSCatalogInfo_set_dataPhysicalSize, NULL},
  349. {"rsrcLogicalSize", (getter)FSCatalogInfo_get_rsrcLogicalSize, (setter)FSCatalogInfo_set_rsrcLogicalSize, NULL},
  350. {"rsrcPhysicalSize", (getter)FSCatalogInfo_get_rsrcPhysicalSize, (setter)FSCatalogInfo_set_rsrcPhysicalSize, NULL},
  351. {"sharingFlags", (getter)FSCatalogInfo_get_sharingFlags, (setter)FSCatalogInfo_set_sharingFlags, NULL},
  352. {"userPrivileges", (getter)FSCatalogInfo_get_userPrivileges, (setter)FSCatalogInfo_set_userPrivileges, NULL},
  353. {NULL, NULL, NULL, NULL},
  354. };
  355. #define FSCatalogInfo_compare NULL
  356. #define FSCatalogInfo_repr NULL
  357. #define FSCatalogInfo_hash NULL
  358. static int FSCatalogInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  359. {
  360. static char *kw[] = {
  361. "nodeFlags",
  362. "volume",
  363. "parentDirID",
  364. "nodeID",
  365. "createDate",
  366. "contentModDate",
  367. "atributeModDate",
  368. "accessDate",
  369. "backupDate",
  370. "valence",
  371. "dataLogicalSize",
  372. "dataPhysicalSize",
  373. "rsrcLogicalSize",
  374. "rsrcPhysicalSize",
  375. "sharingFlags",
  376. "userPrivileges"
  377. , 0};
  378. if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|HhllO&O&O&O&O&llllllb", kw, &((FSCatalogInfoObject *)_self)->ob_itself.nodeFlags,
  379. &((FSCatalogInfoObject *)_self)->ob_itself.volume,
  380. &((FSCatalogInfoObject *)_self)->ob_itself.parentDirID,
  381. &((FSCatalogInfoObject *)_self)->ob_itself.nodeID,
  382. UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.createDate,
  383. UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.contentModDate,
  384. UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.attributeModDate,
  385. UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.accessDate,
  386. UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.backupDate,
  387. &((FSCatalogInfoObject *)_self)->ob_itself.valence,
  388. &((FSCatalogInfoObject *)_self)->ob_itself.dataLogicalSize,
  389. &((FSCatalogInfoObject *)_self)->ob_itself.dataPhysicalSize,
  390. &((FSCatalogInfoObject *)_self)->ob_itself.rsrcLogicalSize,
  391. &((FSCatalogInfoObject *)_self)->ob_itself.rsrcPhysicalSize,
  392. &((FSCatalogInfoObject *)_self)->ob_itself.sharingFlags,
  393. &((FSCatalogInfoObject *)_self)->ob_itself.userPrivileges))
  394. {
  395. return -1;
  396. }
  397. return 0;
  398. }
  399. #define FSCatalogInfo_tp_alloc PyType_GenericAlloc
  400. static PyObject *FSCatalogInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  401. {
  402. PyObject *self;
  403. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  404. memset(&((FSCatalogInfoObject *)self)->ob_itself, 0, sizeof(FSCatalogInfo));
  405. return self;
  406. }
  407. #define FSCatalogInfo_tp_free PyObject_Del
  408. static PyTypeObject FSCatalogInfo_Type = {
  409. PyObject_HEAD_INIT(NULL)
  410. 0, /*ob_size*/
  411. "Carbon.File.FSCatalogInfo", /*tp_name*/
  412. sizeof(FSCatalogInfoObject), /*tp_basicsize*/
  413. 0, /*tp_itemsize*/
  414. /* methods */
  415. (destructor) FSCatalogInfo_dealloc, /*tp_dealloc*/
  416. 0, /*tp_print*/
  417. (getattrfunc)0, /*tp_getattr*/
  418. (setattrfunc)0, /*tp_setattr*/
  419. (cmpfunc) FSCatalogInfo_compare, /*tp_compare*/
  420. (reprfunc) FSCatalogInfo_repr, /*tp_repr*/
  421. (PyNumberMethods *)0, /* tp_as_number */
  422. (PySequenceMethods *)0, /* tp_as_sequence */
  423. (PyMappingMethods *)0, /* tp_as_mapping */
  424. (hashfunc) FSCatalogInfo_hash, /*tp_hash*/
  425. 0, /*tp_call*/
  426. 0, /*tp_str*/
  427. PyObject_GenericGetAttr, /*tp_getattro*/
  428. PyObject_GenericSetAttr, /*tp_setattro */
  429. 0, /*tp_as_buffer*/
  430. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  431. 0, /*tp_doc*/
  432. 0, /*tp_traverse*/
  433. 0, /*tp_clear*/
  434. 0, /*tp_richcompare*/
  435. 0, /*tp_weaklistoffset*/
  436. 0, /*tp_iter*/
  437. 0, /*tp_iternext*/
  438. FSCatalogInfo_methods, /* tp_methods */
  439. 0, /*tp_members*/
  440. FSCatalogInfo_getsetlist, /*tp_getset*/
  441. 0, /*tp_base*/
  442. 0, /*tp_dict*/
  443. 0, /*tp_descr_get*/
  444. 0, /*tp_descr_set*/
  445. 0, /*tp_dictoffset*/
  446. FSCatalogInfo_tp_init, /* tp_init */
  447. FSCatalogInfo_tp_alloc, /* tp_alloc */
  448. FSCatalogInfo_tp_new, /* tp_new */
  449. FSCatalogInfo_tp_free, /* tp_free */
  450. };
  451. /* ----------------- End object type FSCatalogInfo ------------------ */
  452. /* ----------------------- Object type FInfo ------------------------ */
  453. #ifndef __LP64__
  454. static PyTypeObject FInfo_Type;
  455. #define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
  456. typedef struct FInfoObject {
  457. PyObject_HEAD
  458. FInfo ob_itself;
  459. } FInfoObject;
  460. static PyObject *FInfo_New(FInfo *itself)
  461. {
  462. FInfoObject *it;
  463. if (itself == NULL) return PyMac_Error(resNotFound);
  464. it = PyObject_NEW(FInfoObject, &FInfo_Type);
  465. if (it == NULL) return NULL;
  466. it->ob_itself = *itself;
  467. return (PyObject *)it;
  468. }
  469. static int FInfo_Convert(PyObject *v, FInfo *p_itself)
  470. {
  471. if (!FInfo_Check(v))
  472. {
  473. PyErr_SetString(PyExc_TypeError, "FInfo required");
  474. return 0;
  475. }
  476. *p_itself = ((FInfoObject *)v)->ob_itself;
  477. return 1;
  478. }
  479. static void FInfo_dealloc(FInfoObject *self)
  480. {
  481. /* Cleanup of self->ob_itself goes here */
  482. self->ob_type->tp_free((PyObject *)self);
  483. }
  484. static PyMethodDef FInfo_methods[] = {
  485. {NULL, NULL, 0}
  486. };
  487. static PyObject *FInfo_get_Type(FInfoObject *self, void *closure)
  488. {
  489. return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdType);
  490. }
  491. static int FInfo_set_Type(FInfoObject *self, PyObject *v, void *closure)
  492. {
  493. return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdType)-1;
  494. return 0;
  495. }
  496. static PyObject *FInfo_get_Creator(FInfoObject *self, void *closure)
  497. {
  498. return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdCreator);
  499. }
  500. static int FInfo_set_Creator(FInfoObject *self, PyObject *v, void *closure)
  501. {
  502. return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;
  503. return 0;
  504. }
  505. static PyObject *FInfo_get_Flags(FInfoObject *self, void *closure)
  506. {
  507. return Py_BuildValue("H", self->ob_itself.fdFlags);
  508. }
  509. static int FInfo_set_Flags(FInfoObject *self, PyObject *v, void *closure)
  510. {
  511. return PyArg_Parse(v, "H", &self->ob_itself.fdFlags)-1;
  512. return 0;
  513. }
  514. static PyObject *FInfo_get_Location(FInfoObject *self, void *closure)
  515. {
  516. return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself.fdLocation);
  517. }
  518. static int FInfo_set_Location(FInfoObject *self, PyObject *v, void *closure)
  519. {
  520. return PyArg_Parse(v, "O&", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;
  521. return 0;
  522. }
  523. static PyObject *FInfo_get_Fldr(FInfoObject *self, void *closure)
  524. {
  525. return Py_BuildValue("h", self->ob_itself.fdFldr);
  526. }
  527. static int FInfo_set_Fldr(FInfoObject *self, PyObject *v, void *closure)
  528. {
  529. return PyArg_Parse(v, "h", &self->ob_itself.fdFldr)-1;
  530. return 0;
  531. }
  532. static PyGetSetDef FInfo_getsetlist[] = {
  533. {"Type", (getter)FInfo_get_Type, (setter)FInfo_set_Type, "4-char file type"},
  534. {"Creator", (getter)FInfo_get_Creator, (setter)FInfo_set_Creator, "4-char file creator"},
  535. {"Flags", (getter)FInfo_get_Flags, (setter)FInfo_set_Flags, "Finder flag bits"},
  536. {"Location", (getter)FInfo_get_Location, (setter)FInfo_set_Location, "(x, y) location of the file's icon in its parent finder window"},
  537. {"Fldr", (getter)FInfo_get_Fldr, (setter)FInfo_set_Fldr, "Original folder, for 'put away'"},
  538. {NULL, NULL, NULL, NULL},
  539. };
  540. #define FInfo_compare NULL
  541. #define FInfo_repr NULL
  542. #define FInfo_hash NULL
  543. static int FInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  544. {
  545. FInfo *itself = NULL;
  546. static char *kw[] = {"itself", 0};
  547. if (PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&", kw, FInfo_Convert, &itself))
  548. {
  549. if (itself) memcpy(&((FInfoObject *)_self)->ob_itself, itself, sizeof(FInfo));
  550. return 0;
  551. }
  552. return -1;
  553. }
  554. #define FInfo_tp_alloc PyType_GenericAlloc
  555. static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  556. {
  557. PyObject *self;
  558. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  559. memset(&((FInfoObject *)self)->ob_itself, 0, sizeof(FInfo));
  560. return self;
  561. }
  562. #define FInfo_tp_free PyObject_Del
  563. static PyTypeObject FInfo_Type = {
  564. PyObject_HEAD_INIT(NULL)
  565. 0, /*ob_size*/
  566. "Carbon.File.FInfo", /*tp_name*/
  567. sizeof(FInfoObject), /*tp_basicsize*/
  568. 0, /*tp_itemsize*/
  569. /* methods */
  570. (destructor) FInfo_dealloc, /*tp_dealloc*/
  571. 0, /*tp_print*/
  572. (getattrfunc)0, /*tp_getattr*/
  573. (setattrfunc)0, /*tp_setattr*/
  574. (cmpfunc) FInfo_compare, /*tp_compare*/
  575. (reprfunc) FInfo_repr, /*tp_repr*/
  576. (PyNumberMethods *)0, /* tp_as_number */
  577. (PySequenceMethods *)0, /* tp_as_sequence */
  578. (PyMappingMethods *)0, /* tp_as_mapping */
  579. (hashfunc) FInfo_hash, /*tp_hash*/
  580. 0, /*tp_call*/
  581. 0, /*tp_str*/
  582. PyObject_GenericGetAttr, /*tp_getattro*/
  583. PyObject_GenericSetAttr, /*tp_setattro */
  584. 0, /*tp_as_buffer*/
  585. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  586. 0, /*tp_doc*/
  587. 0, /*tp_traverse*/
  588. 0, /*tp_clear*/
  589. 0, /*tp_richcompare*/
  590. 0, /*tp_weaklistoffset*/
  591. 0, /*tp_iter*/
  592. 0, /*tp_iternext*/
  593. FInfo_methods, /* tp_methods */
  594. 0, /*tp_members*/
  595. FInfo_getsetlist, /*tp_getset*/
  596. 0, /*tp_base*/
  597. 0, /*tp_dict*/
  598. 0, /*tp_descr_get*/
  599. 0, /*tp_descr_set*/
  600. 0, /*tp_dictoffset*/
  601. FInfo_tp_init, /* tp_init */
  602. FInfo_tp_alloc, /* tp_alloc */
  603. FInfo_tp_new, /* tp_new */
  604. FInfo_tp_free, /* tp_free */
  605. };
  606. #endif /* !__LP64__ */
  607. /* --------------------- End object type FInfo ---------------------- */
  608. /* ----------------------- Object type Alias ------------------------ */
  609. static PyTypeObject Alias_Type;
  610. #define Alias_Check(x) ((x)->ob_type == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
  611. typedef struct AliasObject {
  612. PyObject_HEAD
  613. AliasHandle ob_itself;
  614. void (*ob_freeit)(AliasHandle ptr);
  615. } AliasObject;
  616. static PyObject *Alias_New(AliasHandle itself)
  617. {
  618. AliasObject *it;
  619. if (itself == NULL) return PyMac_Error(resNotFound);
  620. it = PyObject_NEW(AliasObject, &Alias_Type);
  621. if (it == NULL) return NULL;
  622. it->ob_itself = itself;
  623. it->ob_freeit = NULL;
  624. return (PyObject *)it;
  625. }
  626. static int Alias_Convert(PyObject *v, AliasHandle *p_itself)
  627. {
  628. if (!Alias_Check(v))
  629. {
  630. PyErr_SetString(PyExc_TypeError, "Alias required");
  631. return 0;
  632. }
  633. *p_itself = ((AliasObject *)v)->ob_itself;
  634. return 1;
  635. }
  636. static void Alias_dealloc(AliasObject *self)
  637. {
  638. if (self->ob_freeit && self->ob_itself)
  639. {
  640. self->ob_freeit(self->ob_itself);
  641. }
  642. self->ob_itself = NULL;
  643. self->ob_type->tp_free((PyObject *)self);
  644. }
  645. #ifndef __LP64__
  646. static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
  647. {
  648. PyObject *_res = NULL;
  649. OSErr _err;
  650. FSSpec fromFile__buf__;
  651. FSSpec *fromFile = &fromFile__buf__;
  652. FSSpec target;
  653. Boolean wasChanged;
  654. if (!PyArg_ParseTuple(_args, "O&",
  655. myPyMac_GetOptFSSpecPtr, &fromFile))
  656. return NULL;
  657. _err = ResolveAlias(fromFile,
  658. _self->ob_itself,
  659. &target,
  660. &wasChanged);
  661. if (_err != noErr) return PyMac_Error(_err);
  662. _res = Py_BuildValue("O&b",
  663. FSSpec_New, &target,
  664. wasChanged);
  665. return _res;
  666. }
  667. static PyObject *Alias_GetAliasInfo(AliasObject *_self, PyObject *_args)
  668. {
  669. PyObject *_res = NULL;
  670. OSErr _err;
  671. AliasInfoType index;
  672. Str63 theString;
  673. if (!PyArg_ParseTuple(_args, "h",
  674. &index))
  675. return NULL;
  676. _err = GetAliasInfo(_self->ob_itself,
  677. index,
  678. theString);
  679. if (_err != noErr) return PyMac_Error(_err);
  680. _res = Py_BuildValue("O&",
  681. PyMac_BuildStr255, theString);
  682. return _res;
  683. }
  684. static PyObject *Alias_ResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
  685. {
  686. PyObject *_res = NULL;
  687. OSErr _err;
  688. FSSpec fromFile__buf__;
  689. FSSpec *fromFile = &fromFile__buf__;
  690. FSSpec target;
  691. Boolean wasChanged;
  692. unsigned long mountFlags;
  693. if (!PyArg_ParseTuple(_args, "O&l",
  694. myPyMac_GetOptFSSpecPtr, &fromFile,
  695. &mountFlags))
  696. return NULL;
  697. _err = ResolveAliasWithMountFlags(fromFile,
  698. _self->ob_itself,
  699. &target,
  700. &wasChanged,
  701. mountFlags);
  702. if (_err != noErr) return PyMac_Error(_err);
  703. _res = Py_BuildValue("O&b",
  704. FSSpec_New, &target,
  705. wasChanged);
  706. return _res;
  707. }
  708. static PyObject *Alias_FollowFinderAlias(AliasObject *_self, PyObject *_args)
  709. {
  710. PyObject *_res = NULL;
  711. OSErr _err;
  712. FSSpec fromFile__buf__;
  713. FSSpec *fromFile = &fromFile__buf__;
  714. Boolean logon;
  715. FSSpec target;
  716. Boolean wasChanged;
  717. if (!PyArg_ParseTuple(_args, "O&b",
  718. myPyMac_GetOptFSSpecPtr, &fromFile,
  719. &logon))
  720. return NULL;
  721. _err = FollowFinderAlias(fromFile,
  722. _self->ob_itself,
  723. logon,
  724. &target,
  725. &wasChanged);
  726. if (_err != noErr) return PyMac_Error(_err);
  727. _res = Py_BuildValue("O&b",
  728. FSSpec_New, &target,
  729. wasChanged);
  730. return _res;
  731. }
  732. #endif /* !__LP64__ */
  733. static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
  734. {
  735. PyObject *_res = NULL;
  736. OSErr _err;
  737. FSRef fromFile__buf__;
  738. FSRef *fromFile = &fromFile__buf__;
  739. FSRef target;
  740. Boolean wasChanged;
  741. unsigned long mountFlags;
  742. if (!PyArg_ParseTuple(_args, "O&l",
  743. myPyMac_GetOptFSRefPtr, &fromFile,
  744. &mountFlags))
  745. return NULL;
  746. _err = FSResolveAliasWithMountFlags(fromFile,
  747. _self->ob_itself,
  748. &target,
  749. &wasChanged,
  750. mountFlags);
  751. if (_err != noErr) return PyMac_Error(_err);
  752. _res = Py_BuildValue("O&b",
  753. FSRef_New, &target,
  754. wasChanged);
  755. return _res;
  756. }
  757. static PyObject *Alias_FSResolveAlias(AliasObject *_self, PyObject *_args)
  758. {
  759. PyObject *_res = NULL;
  760. OSErr _err;
  761. FSRef fromFile__buf__;
  762. FSRef *fromFile = &fromFile__buf__;
  763. FSRef target;
  764. Boolean wasChanged;
  765. if (!PyArg_ParseTuple(_args, "O&",
  766. myPyMac_GetOptFSRefPtr, &fromFile))
  767. return NULL;
  768. _err = FSResolveAlias(fromFile,
  769. _self->ob_itself,
  770. &target,
  771. &wasChanged);
  772. if (_err != noErr) return PyMac_Error(_err);
  773. _res = Py_BuildValue("O&b",
  774. FSRef_New, &target,
  775. wasChanged);
  776. return _res;
  777. }
  778. static PyObject *Alias_FSFollowFinderAlias(AliasObject *_self, PyObject *_args)
  779. {
  780. PyObject *_res = NULL;
  781. OSErr _err;
  782. FSRef fromFile;
  783. Boolean logon;
  784. FSRef target;
  785. Boolean wasChanged;
  786. if (!PyArg_ParseTuple(_args, "b",
  787. &logon))
  788. return NULL;
  789. _err = FSFollowFinderAlias(&fromFile,
  790. _self->ob_itself,
  791. logon,
  792. &target,
  793. &wasChanged);
  794. if (_err != noErr) return PyMac_Error(_err);
  795. _res = Py_BuildValue("O&O&b",
  796. FSRef_New, &fromFile,
  797. FSRef_New, &target,
  798. wasChanged);
  799. return _res;
  800. }
  801. static PyMethodDef Alias_methods[] = {
  802. #ifndef __LP64__
  803. {"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
  804. PyDoc_STR("(FSSpec fromFile) -> (FSSpec target, Boolean wasChanged)")},
  805. {"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
  806. PyDoc_STR("(AliasInfoType index) -> (Str63 theString)")},
  807. {"ResolveAliasWithMountFlags", (PyCFunction)Alias_ResolveAliasWithMountFlags, 1,
  808. PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
  809. {"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
  810. PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
  811. #endif /* !__LP64__ */
  812. {"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
  813. PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
  814. {"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
  815. PyDoc_STR("(FSRef fromFile) -> (FSRef target, Boolean wasChanged)")},
  816. {"FSFollowFinderAlias", (PyCFunction)Alias_FSFollowFinderAlias, 1,
  817. PyDoc_STR("(Boolean logon) -> (FSRef fromFile, FSRef target, Boolean wasChanged)")},
  818. {NULL, NULL, 0}
  819. };
  820. static PyObject *Alias_get_data(AliasObject *self, void *closure)
  821. {
  822. int size;
  823. PyObject *rv;
  824. size = GetHandleSize((Handle)self->ob_itself);
  825. HLock((Handle)self->ob_itself);
  826. rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size);
  827. HUnlock((Handle)self->ob_itself);
  828. return rv;
  829. }
  830. #define Alias_set_data NULL
  831. static PyGetSetDef Alias_getsetlist[] = {
  832. {"data", (getter)Alias_get_data, (setter)Alias_set_data, "Raw data of the alias object"},
  833. {NULL, NULL, NULL, NULL},
  834. };
  835. #define Alias_compare NULL
  836. #define Alias_repr NULL
  837. #define Alias_hash NULL
  838. static int Alias_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  839. {
  840. AliasHandle itself = NULL;
  841. char *rawdata = NULL;
  842. int rawdatalen = 0;
  843. Handle h;
  844. static char *kw[] = {"itself", "rawdata", 0};
  845. if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen))
  846. return -1;
  847. if (itself && rawdata)
  848. {
  849. PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
  850. return -1;
  851. }
  852. if (!itself && !rawdata)
  853. {
  854. PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
  855. return -1;
  856. }
  857. if (rawdata)
  858. {
  859. if ((h = NewHandle(rawdatalen)) == NULL)
  860. {
  861. PyErr_NoMemory();
  862. return -1;
  863. }
  864. HLock(h);
  865. memcpy((char *)*h, rawdata, rawdatalen);
  866. HUnlock(h);
  867. ((AliasObject *)_self)->ob_itself = (AliasHandle)h;
  868. return 0;
  869. }
  870. ((AliasObject *)_self)->ob_itself = itself;
  871. return 0;
  872. }
  873. #define Alias_tp_alloc PyType_GenericAlloc
  874. static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  875. {
  876. PyObject *self;
  877. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  878. ((AliasObject *)self)->ob_itself = NULL;
  879. return self;
  880. }
  881. #define Alias_tp_free PyObject_Del
  882. static PyTypeObject Alias_Type = {
  883. PyObject_HEAD_INIT(NULL)
  884. 0, /*ob_size*/
  885. "Carbon.File.Alias", /*tp_name*/
  886. sizeof(AliasObject), /*tp_basicsize*/
  887. 0, /*tp_itemsize*/
  888. /* methods */
  889. (destructor) Alias_dealloc, /*tp_dealloc*/
  890. 0, /*tp_print*/
  891. (getattrfunc)0, /*tp_getattr*/
  892. (setattrfunc)0, /*tp_setattr*/
  893. (cmpfunc) Alias_compare, /*tp_compare*/
  894. (reprfunc) Alias_repr, /*tp_repr*/
  895. (PyNumberMethods *)0, /* tp_as_number */
  896. (PySequenceMethods *)0, /* tp_as_sequence */
  897. (PyMappingMethods *)0, /* tp_as_mapping */
  898. (hashfunc) Alias_hash, /*tp_hash*/
  899. 0, /*tp_call*/
  900. 0, /*tp_str*/
  901. PyObject_GenericGetAttr, /*tp_getattro*/
  902. PyObject_GenericSetAttr, /*tp_setattro */
  903. 0, /*tp_as_buffer*/
  904. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  905. 0, /*tp_doc*/
  906. 0, /*tp_traverse*/
  907. 0, /*tp_clear*/
  908. 0, /*tp_richcompare*/
  909. 0, /*tp_weaklistoffset*/
  910. 0, /*tp_iter*/
  911. 0, /*tp_iternext*/
  912. Alias_methods, /* tp_methods */
  913. 0, /*tp_members*/
  914. Alias_getsetlist, /*tp_getset*/
  915. 0, /*tp_base*/
  916. 0, /*tp_dict*/
  917. 0, /*tp_descr_get*/
  918. 0, /*tp_descr_set*/
  919. 0, /*tp_dictoffset*/
  920. Alias_tp_init, /* tp_init */
  921. Alias_tp_alloc, /* tp_alloc */
  922. Alias_tp_new, /* tp_new */
  923. Alias_tp_free, /* tp_free */
  924. };
  925. /* --------------------- End object type Alias ---------------------- */
  926. /* ----------------------- Object type FSSpec ----------------------- */
  927. #ifndef __LP64__
  928. static PyTypeObject FSSpec_Type;
  929. #define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type || PyObject_TypeCheck((x), &FSSpec_Type))
  930. typedef struct FSSpecObject {
  931. PyObject_HEAD
  932. FSSpec ob_itself;
  933. } FSSpecObject;
  934. static PyObject *FSSpec_New(FSSpec *itself)
  935. {
  936. FSSpecObject *it;
  937. if (itself == NULL) return PyMac_Error(resNotFound);
  938. it = PyObject_NEW(FSSpecObject, &FSSpec_Type);
  939. if (it == NULL) return NULL;
  940. it->ob_itself = *itself;
  941. return (PyObject *)it;
  942. }
  943. static void FSSpec_dealloc(FSSpecObject *self)
  944. {
  945. /* Cleanup of self->ob_itself goes here */
  946. self->ob_type->tp_free((PyObject *)self);
  947. }
  948. static PyObject *FSSpec_FSpOpenDF(FSSpecObject *_self, PyObject *_args)
  949. {
  950. PyObject *_res = NULL;
  951. OSErr _err;
  952. SInt8 permission;
  953. short refNum;
  954. if (!PyArg_ParseTuple(_args, "b",
  955. &permission))
  956. return NULL;
  957. _err = FSpOpenDF(&_self->ob_itself,
  958. permission,
  959. &refNum);
  960. if (_err != noErr) return PyMac_Error(_err);
  961. _res = Py_BuildValue("h",
  962. refNum);
  963. return _res;
  964. }
  965. static PyObject *FSSpec_FSpOpenRF(FSSpecObject *_self, PyObject *_args)
  966. {
  967. PyObject *_res = NULL;
  968. OSErr _err;
  969. SInt8 permission;
  970. short refNum;
  971. if (!PyArg_ParseTuple(_args, "b",
  972. &permission))
  973. return NULL;
  974. _err = FSpOpenRF(&_self->ob_itself,
  975. permission,
  976. &refNum);
  977. if (_err != noErr) return PyMac_Error(_err);
  978. _res = Py_BuildValue("h",
  979. refNum);
  980. return _res;
  981. }
  982. static PyObject *FSSpec_FSpCreate(FSSpecObject *_self, PyObject *_args)
  983. {
  984. PyObject *_res = NULL;
  985. OSErr _err;
  986. OSType creator;
  987. OSType fileType;
  988. ScriptCode scriptTag;
  989. if (!PyArg_ParseTuple(_args, "O&O&h",
  990. PyMac_GetOSType, &creator,
  991. PyMac_GetOSType, &fileType,
  992. &scriptTag))
  993. return NULL;
  994. _err = FSpCreate(&_self->ob_itself,
  995. creator,
  996. fileType,
  997. scriptTag);
  998. if (_err != noErr) return PyMac_Error(_err);
  999. Py_INCREF(Py_None);
  1000. _res = Py_None;
  1001. return _res;
  1002. }
  1003. static PyObject *FSSpec_FSpDirCreate(FSSpecObject *_self, PyObject *_args)
  1004. {
  1005. PyObject *_res = NULL;
  1006. OSErr _err;
  1007. ScriptCode scriptTag;
  1008. long createdDirID;
  1009. if (!PyArg_ParseTuple(_args, "h",
  1010. &scriptTag))
  1011. return NULL;
  1012. _err = FSpDirCreate(&_self->ob_itself,
  1013. scriptTag,
  1014. &createdDirID);
  1015. if (_err != noErr) return PyMac_Error(_err);
  1016. _res = Py_BuildValue("l",
  1017. createdDirID);
  1018. return _res;
  1019. }
  1020. static PyObject *FSSpec_FSpDelete(FSSpecObject *_self, PyObject *_args)
  1021. {
  1022. PyObject *_res = NULL;
  1023. OSErr _err;
  1024. if (!PyArg_ParseTuple(_args, ""))
  1025. return NULL;
  1026. _err = FSpDelete(&_self->ob_itself);
  1027. if (_err != noErr) return PyMac_Error(_err);
  1028. Py_INCREF(Py_None);
  1029. _res = Py_None;
  1030. return _res;
  1031. }
  1032. static PyObject *FSSpec_FSpGetFInfo(FSSpecObject *_self, PyObject *_args)
  1033. {
  1034. PyObject *_res = NULL;
  1035. OSErr _err;
  1036. FInfo fndrInfo;
  1037. if (!PyArg_ParseTuple(_args, ""))
  1038. return NULL;
  1039. _err = FSpGetFInfo(&_self->ob_itself,
  1040. &fndrInfo);
  1041. if (_err != noErr) return PyMac_Error(_err);
  1042. _res = Py_BuildValue("O&",
  1043. FInfo_New, &fndrInfo);
  1044. return _res;
  1045. }
  1046. static PyObject *FSSpec_FSpSetFInfo(FSSpecObject *_self, PyObject *_args)
  1047. {
  1048. PyObject *_res = NULL;
  1049. OSErr _err;
  1050. FInfo fndrInfo;
  1051. if (!PyArg_ParseTuple(_args, "O&",
  1052. FInfo_Convert, &fndrInfo))
  1053. return NULL;
  1054. _err = FSpSetFInfo(&_self->ob_itself,
  1055. &fndrInfo);
  1056. if (_err != noErr) return PyMac_Error(_err);
  1057. Py_INCREF(Py_None);
  1058. _res = Py_None;
  1059. return _res;
  1060. }
  1061. static PyObject *FSSpec_FSpSetFLock(FSSpecObject *_self, PyObject *_args)
  1062. {
  1063. PyObject *_res = NULL;
  1064. OSErr _err;
  1065. if (!PyArg_ParseTuple(_args, ""))
  1066. return NULL;
  1067. _err = FSpSetFLock(&_self->ob_itself);
  1068. if (_err != noErr) return PyMac_Error(_err);
  1069. Py_INCREF(Py_None);
  1070. _res = Py_None;
  1071. return _res;
  1072. }
  1073. static PyObject *FSSpec_FSpRstFLock(FSSpecObject *_self, PyObject *_args)
  1074. {
  1075. PyObject *_res = NULL;
  1076. OSErr _err;
  1077. if (!PyArg_ParseTuple(_args, ""))
  1078. return NULL;
  1079. _err = FSpRstFLock(&_self->ob_itself);
  1080. if (_err != noErr) return PyMac_Error(_err);
  1081. Py_INCREF(Py_None);
  1082. _res = Py_None;
  1083. return _res;
  1084. }
  1085. static PyObject *FSSpec_FSpRename(FSSpecObject *_self, PyObject *_args)
  1086. {
  1087. PyObject *_res = NULL;
  1088. OSErr _err;
  1089. Str255 newName;
  1090. if (!PyArg_ParseTuple(_args, "O&",
  1091. PyMac_GetStr255, newName))
  1092. return NULL;
  1093. _err = FSpRename(&_self->ob_itself,
  1094. newName);
  1095. if (_err != noErr) return PyMac_Error(_err);
  1096. Py_INCREF(Py_None);
  1097. _res = Py_None;
  1098. return _res;
  1099. }
  1100. static PyObject *FSSpec_FSpCatMove(FSSpecObject *_self, PyObject *_args)
  1101. {
  1102. PyObject *_res = NULL;
  1103. OSErr _err;
  1104. FSSpec dest;
  1105. if (!PyArg_ParseTuple(_args, "O&",
  1106. FSSpec_Convert, &dest))
  1107. return NULL;
  1108. _err = FSpCatMove(&_self->ob_itself,
  1109. &dest);
  1110. if (_err != noErr) return PyMac_Error(_err);
  1111. Py_INCREF(Py_None);
  1112. _res = Py_None;
  1113. return _res;
  1114. }
  1115. static PyObject *FSSpec_FSpExchangeFiles(FSSpecObject *_self, PyObject *_args)
  1116. {
  1117. PyObject *_res = NULL;
  1118. OSErr _err;
  1119. FSSpec dest;
  1120. if (!PyArg_ParseTuple(_args, "O&",
  1121. FSSpec_Convert, &dest))
  1122. return NULL;
  1123. _err = FSpExchangeFiles(&_self->ob_itself,
  1124. &dest);
  1125. if (_err != noErr) return PyMac_Error(_err);
  1126. Py_INCREF(Py_None);
  1127. _res = Py_None;
  1128. return _res;
  1129. }
  1130. static PyObject *FSSpec_FSpMakeFSRef(FSSpecObject *_self, PyObject *_args)
  1131. {
  1132. PyObject *_res = NULL;
  1133. OSErr _err;
  1134. FSRef newRef;
  1135. if (!PyArg_ParseTuple(_args, ""))
  1136. return NULL;
  1137. _err = FSpMakeFSRef(&_self->ob_itself,
  1138. &newRef);
  1139. if (_err != noErr) return PyMac_Error(_err);
  1140. _res = Py_BuildValue("O&",
  1141. FSRef_New, &newRef);
  1142. return _res;
  1143. }
  1144. static PyObject *FSSpec_NewAliasMinimal(FSSpecObject *_self, PyObject *_args)
  1145. {
  1146. PyObject *_res = NULL;
  1147. OSErr _err;
  1148. AliasHandle alias;
  1149. if (!PyArg_ParseTuple(_args, ""))
  1150. return NULL;
  1151. _err = NewAliasMinimal(&_self->ob_itself,
  1152. &alias);
  1153. if (_err != noErr) return PyMac_Error(_err);
  1154. _res = Py_BuildValue("O&",
  1155. Alias_New, alias);
  1156. return _res;
  1157. }
  1158. static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
  1159. {
  1160. PyObject *_res = NULL;
  1161. OSErr _err;
  1162. Boolean aliasFileFlag;
  1163. Boolean folderFlag;
  1164. if (!PyArg_ParseTuple(_args, ""))
  1165. return NULL;
  1166. _err = IsAliasFile(&_self->ob_itself,
  1167. &aliasFileFlag,
  1168. &folderFlag);
  1169. if (_err != noErr) return PyMac_Error(_err);
  1170. _res = Py_BuildValue("bb",
  1171. aliasFileFlag,
  1172. folderFlag);
  1173. return _res;
  1174. }
  1175. static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
  1176. {
  1177. PyObject *_res = NULL;
  1178. char strbuf[1024];
  1179. OSErr err;
  1180. if (!PyArg_ParseTuple(_args, ""))
  1181. return NULL;
  1182. err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
  1183. if ( err ) {
  1184. PyMac_Error(err);
  1185. return NULL;
  1186. }
  1187. _res = PyString_FromString(strbuf);
  1188. return _res;
  1189. }
  1190. static PyObject *FSSpec_as_tuple(FSSpecObject *_self, PyObject *_args)
  1191. {
  1192. PyObject *_res = NULL;
  1193. if (!PyArg_ParseTuple(_args, ""))
  1194. return NULL;
  1195. _res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID,
  1196. &_self->ob_itself.name[1], _self->ob_itself.name[0]);
  1197. return _res;
  1198. }
  1199. static PyMethodDef FSSpec_methods[] = {
  1200. {"FSpOpenDF", (PyCFunction)FSSpec_FSpOpenDF, 1,
  1201. PyDoc_STR("(SInt8 permission) -> (short refNum)")},
  1202. {"FSpOpenRF", (PyCFunction)FSSpec_FSpOpenRF, 1,
  1203. PyDoc_STR("(SInt8 permission) -> (short refNum)")},
  1204. {"FSpCreate", (PyCFunction)FSSpec_FSpCreate, 1,
  1205. PyDoc_STR("(OSType creator, OSType fileType, ScriptCode scriptTag) -> None")},
  1206. {"FSpDirCreate", (PyCFunction)FSSpec_FSpDirCreate, 1,
  1207. PyDoc_STR("(ScriptCode scriptTag) -> (long createdDirID)")},
  1208. {"FSpDelete", (PyCFunction)FSSpec_FSpDelete, 1,
  1209. PyDoc_STR("() -> None")},
  1210. {"FSpGetFInfo", (PyCFunction)FSSpec_FSpGetFInfo, 1,
  1211. PyDoc_STR("() -> (FInfo fndrInfo)")},
  1212. {"FSpSetFInfo", (PyCFunction)FSSpec_FSpSetFInfo, 1,
  1213. PyDoc_STR("(FInfo fndrInfo) -> None")},
  1214. {"FSpSetFLock", (PyCFunction)FSSpec_FSpSetFLock, 1,
  1215. PyDoc_STR("() -> None")},
  1216. {"FSpRstFLock", (PyCFunction)FSSpec_FSpRstFLock, 1,
  1217. PyDoc_STR("() -> None")},
  1218. {"FSpRename", (PyCFunction)FSSpec_FSpRename, 1,
  1219. PyDoc_STR("(Str255 newName) -> None")},
  1220. {"FSpCatMove", (PyCFunction)FSSpec_FSpCatMove, 1,
  1221. PyDoc_STR("(FSSpec dest) -> None")},
  1222. {"FSpExchangeFiles", (PyCFunction)FSSpec_FSpExchangeFiles, 1,
  1223. PyDoc_STR("(FSSpec dest) -> None")},
  1224. {"FSpMakeFSRef", (PyCFunction)FSSpec_FSpMakeFSRef, 1,
  1225. PyDoc_STR("() -> (FSRef newRef)")},
  1226. {"NewAliasMinimal", (PyCFunction)FSSpec_NewAliasMinimal, 1,
  1227. PyDoc_STR("() -> (AliasHandle alias)")},
  1228. {"IsAliasFile", (PyCFunction)FSSpec_IsAliasFile, 1,
  1229. PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
  1230. {"as_pathname", (PyCFunction)FSSpec_as_pathname, 1,
  1231. PyDoc_STR("() -> string")},
  1232. {"as_tuple", (PyCFunction)FSSpec_as_tuple, 1,
  1233. PyDoc_STR("() -> (vRefNum, dirID, name)")},
  1234. {NULL, NULL, 0}
  1235. };
  1236. static PyObject *FSSpec_get_data(FSSpecObject *self, void *closure)
  1237. {
  1238. return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
  1239. }
  1240. #define FSSpec_set_data NULL
  1241. static PyGetSetDef FSSpec_getsetlist[] = {
  1242. {"data", (getter)FSSpec_get_data, (setter)FSSpec_set_data, "Raw data of the FSSpec object"},
  1243. {NULL, NULL, NULL, NULL},
  1244. };
  1245. #define FSSpec_compare NULL
  1246. static PyObject * FSSpec_repr(FSSpecObject *self)
  1247. {
  1248. char buf[512];
  1249. PyOS_snprintf(buf, sizeof(buf), "%s((%d, %ld, '%.*s'))",
  1250. self->ob_type->tp_name,
  1251. self->ob_itself.vRefNum,
  1252. self->ob_itself.parID,
  1253. self->ob_itself.name[0], self->ob_itself.name+1);
  1254. return PyString_FromString(buf);
  1255. }
  1256. #define FSSpec_hash NULL
  1257. static int FSSpec_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  1258. {
  1259. PyObject *v = NULL;
  1260. char *rawdata = NULL;
  1261. int rawdatalen = 0;
  1262. static char *kw[] = {"itself", "rawdata", 0};
  1263. if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
  1264. return -1;
  1265. if (v && rawdata)
  1266. {
  1267. PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
  1268. return -1;
  1269. }
  1270. if (!v && !rawdata)
  1271. {
  1272. PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
  1273. return -1;
  1274. }
  1275. if (rawdata)
  1276. {
  1277. if (rawdatalen != sizeof(FSSpec))
  1278. {
  1279. PyErr_SetString(PyExc_TypeError, "FSSpec rawdata incorrect size");
  1280. return -1;
  1281. }
  1282. memcpy(&((FSSpecObject *)_self)->ob_itself, rawdata, rawdatalen);
  1283. return 0;
  1284. }
  1285. if (PyMac_GetFSSpec(v, &((FSSpecObject *)_self)->ob_itself)) return 0;
  1286. return -1;
  1287. }
  1288. #define FSSpec_tp_alloc PyType_GenericAlloc
  1289. static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  1290. {
  1291. PyObject *self;
  1292. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  1293. memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpec));
  1294. return self;
  1295. }
  1296. #define FSSpec_tp_free PyObject_Del
  1297. static PyTypeObject FSSpec_Type = {
  1298. PyObject_HEAD_INIT(NULL)
  1299. 0, /*ob_size*/
  1300. "Carbon.File.FSSpec", /*tp_name*/
  1301. sizeof(FSSpecObject), /*tp_basicsize*/
  1302. 0, /*tp_itemsize*/
  1303. /* methods */
  1304. (destructor) FSSpec_dealloc, /*tp_dealloc*/
  1305. 0, /*tp_print*/
  1306. (getattrfunc)0, /*tp_getattr*/
  1307. (setattrfunc)0, /*tp_setattr*/
  1308. (cmpfunc) FSSpec_compare, /*tp_compare*/
  1309. (reprfunc) FSSpec_repr, /*tp_repr*/
  1310. (PyNumberMethods *)0, /* tp_as_number */
  1311. (PySequenceMethods *)0, /* tp_as_sequence */
  1312. (PyMappingMethods *)0, /* tp_as_mapping */
  1313. (hashfunc) FSSpec_hash, /*tp_hash*/
  1314. 0, /*tp_call*/
  1315. 0, /*tp_str*/
  1316. PyObject_GenericGetAttr, /*tp_getattro*/
  1317. PyObject_GenericSetAttr, /*tp_setattro */
  1318. 0, /*tp_as_buffer*/
  1319. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  1320. 0, /*tp_doc*/
  1321. 0, /*tp_traverse*/
  1322. 0, /*tp_clear*/
  1323. 0, /*tp_richcompare*/
  1324. 0, /*tp_weaklistoffset*/
  1325. 0, /*tp_iter*/
  1326. 0, /*tp_iternext*/
  1327. FSSpec_methods, /* tp_methods */
  1328. 0, /*tp_members*/
  1329. FSSpec_getsetlist, /*tp_getset*/
  1330. 0, /*tp_base*/
  1331. 0, /*tp_dict*/
  1332. 0, /*tp_descr_get*/
  1333. 0, /*tp_descr_set*/
  1334. 0, /*tp_dictoffset*/
  1335. FSSpec_tp_init, /* tp_init */
  1336. FSSpec_tp_alloc, /* tp_alloc */
  1337. FSSpec_tp_new, /* tp_new */
  1338. FSSpec_tp_free, /* tp_free */
  1339. };
  1340. #endif /* !__LP64__ */
  1341. /* --------------------- End object type FSSpec --------------------- */
  1342. /* ----------------------- Object type FSRef ------------------------ */
  1343. static PyTypeObject FSRef_Type;
  1344. #define FSRef_Check(x) ((x)->ob_type == &FSRef_Type || PyObject_TypeCheck((x), &FSRef_Type))
  1345. typedef struct FSRefObject {
  1346. PyObject_HEAD
  1347. FSRef ob_itself;
  1348. } FSRefObject;
  1349. static PyObject *FSRef_New(FSRef *itself)
  1350. {
  1351. FSRefObject *it;
  1352. if (itself == NULL) return PyMac_Error(resNotFound);
  1353. it = PyObject_NEW(FSRefObject, &FSRef_Type);
  1354. if (it == NULL) return NULL;
  1355. it->ob_itself = *itself;
  1356. return (PyObject *)it;
  1357. }
  1358. static void FSRef_dealloc(FSRefObject *self)
  1359. {
  1360. /* Cleanup of self->ob_itself goes here */
  1361. self->ob_type->tp_free((PyObject *)self);
  1362. }
  1363. static PyObject *FSRef_FSMakeFSRefUnicode(FSRefObject *_self, PyObject *_args)
  1364. {
  1365. PyObject *_res = NULL;
  1366. OSErr _err;
  1367. UniChar *nameLength__in__;
  1368. UniCharCount nameLength__len__;
  1369. int nameLength__in_len__;
  1370. TextEncoding textEncodingHint;
  1371. FSRef newRef;
  1372. if (!PyArg_ParseTuple(_args, "u#l",
  1373. &nameLength__in__, &nameLength__in_len__,
  1374. &textEncodingHint))
  1375. return NULL;
  1376. nameLength__len__ = nameLength__in_len__;
  1377. _err = FSMakeFSRefUnicode(&_self->ob_itself,
  1378. nameLength__len__, nameLength__in__,
  1379. textEncodingHint,
  1380. &newRef);
  1381. if (_err != noErr) return PyMac_Error(_err);
  1382. _res = Py_BuildValue("O&",
  1383. FSRef_New, &newRef);
  1384. return _res;
  1385. }
  1386. static PyObject *FSRef_FSCompareFSRefs(FSRefObject *_self, PyObject *_args)
  1387. {
  1388. PyObject *_res = NULL;
  1389. OSErr _err;
  1390. FSRef ref2;
  1391. if (!PyArg_ParseTuple(_args, "O&",
  1392. FSRef_Convert, &ref2))
  1393. return NULL;
  1394. _err = FSCompareFSRefs(&_self->ob_itself,
  1395. &ref2);
  1396. if (_err != noErr) return PyMac_Error(_err);
  1397. Py_INCREF(Py_None);
  1398. _res = Py_None;
  1399. return _res;
  1400. }
  1401. static PyObject *FSRef_FSCreateFileUnicode(FSRefObject *_self, PyObject *_args)
  1402. {
  1403. PyObject *_res = NULL;
  1404. OSErr _err;
  1405. UniChar *nameLength__in__;
  1406. UniCharCount nameLength__len__;
  1407. int nameLength__in_len__;
  1408. FSCatalogInfoBitmap whichInfo;
  1409. FSCatalogInfo catalogInfo;
  1410. FSRef newRef;
  1411. #ifndef __LP64__
  1412. FSSpec newSpec;
  1413. #endif
  1414. if (!PyArg_ParseTuple(_args, "u#lO&",
  1415. &nameLength__in__, &nameLength__in_len__,
  1416. &whichInfo,
  1417. FSCatalogInfo_Convert, &catalogInfo))
  1418. return NULL;
  1419. nameLength__len__ = nameLength__in_len__;
  1420. _err = FSCreateFileUnicode(&_self->ob_itself,
  1421. nameLength__len__, nameLength__in__,
  1422. whichInfo,
  1423. &catalogInfo,
  1424. &newRef,
  1425. #ifndef __LP64__
  1426. &newSpec
  1427. #else /* __LP64__ */
  1428. NULL
  1429. #endif /* __LP64__*/
  1430. );
  1431. if (_err != noErr) return PyMac_Error(_err);
  1432. #ifndef __LP64__
  1433. _res = Py_BuildValue("O&O&",
  1434. FSRef_New, &newRef,
  1435. FSSpec_New, &newSpec);
  1436. #else /* __LP64__ */
  1437. _res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
  1438. #endif /* __LP64__ */
  1439. return _res;
  1440. }
  1441. static PyObject *FSRef_FSCreateDirectoryUnicode(FSRefObject *_self, PyObject *_args)
  1442. {
  1443. PyObject *_res = NULL;
  1444. OSErr _err;
  1445. UniChar *nameLength__in__;
  1446. UniCharCount nameLength__len__;
  1447. int nameLength__in_len__;
  1448. FSCatalogInfoBitmap whichInfo;
  1449. FSCatalogInfo catalogInfo;
  1450. FSRef newRef;
  1451. #ifndef __LP64__
  1452. FSSpec newSpec;
  1453. #endif /* !__LP64__ */
  1454. UInt32 newDirID;
  1455. if (!PyArg_ParseTuple(_args, "u#lO&",
  1456. &nameLength__in__, &nameLength__in_len__,
  1457. &whichInfo,
  1458. FSCatalogInfo_Convert, &catalogInfo))
  1459. return NULL;
  1460. nameLength__len__ = nameLength__in_len__;
  1461. _err = FSCreateDirectoryUnicode(&_self->ob_itself,
  1462. nameLength__len__, nameLength__in__,
  1463. whichInfo,
  1464. &catalogInfo,
  1465. &newRef,
  1466. #ifndef __LP64__
  1467. &newSpec,
  1468. #else /* !__LP64__ */
  1469. NULL,
  1470. #endif /* !__LP64__ */
  1471. &newDirID);
  1472. if (_err != noErr) return PyMac_Error(_err);
  1473. #ifndef __LP64__
  1474. _res = Py_BuildValue("O&O&l",
  1475. FSRef_New, &newRef,
  1476. FSSpec_New, &newSpec,
  1477. newDirID);
  1478. #else /* __LP64__ */
  1479. _res = Py_BuildValue("O&Ol",
  1480. FSRef_New, &newRef,
  1481. Py_None,
  1482. newDirID);
  1483. #endif /* __LP64__ */
  1484. return _res;
  1485. }
  1486. static PyObject *FSRef_FSDeleteObject(FSRefObject *_self, PyObject *_args)
  1487. {
  1488. PyObject *_res = NULL;
  1489. OSErr _err;
  1490. if (!PyArg_ParseTuple(_args, ""))
  1491. return NULL;
  1492. _err = FSDeleteObject(&_self->ob_itself);
  1493. if (_err != noErr) return PyMac_Error(_err);
  1494. Py_INCREF(Py_None);
  1495. _res = Py_None;
  1496. return _res;
  1497. }
  1498. static PyObject *FSRef_FSMoveObject(FSRefObject *_self, PyObject *_args)
  1499. {
  1500. PyObject *_res = NULL;
  1501. OSErr _err;
  1502. FSRef destDirectory;
  1503. FSRef newRef;
  1504. if (!PyArg_ParseTuple(_args, "O&",
  1505. FSRef_Convert, &destDirectory))
  1506. return NULL;
  1507. _err = FSMoveObject(&_self->ob_itself,
  1508. &destDirectory,
  1509. &newRef);
  1510. if (_err != noErr) return PyMac_Error(_err);
  1511. _res = Py_BuildValue("O&",
  1512. FSRef_New, &newRef);
  1513. return _res;
  1514. }
  1515. static PyObject *FSRef_FSExchangeObjects(FSRefObject *_self, PyObject *_args)
  1516. {
  1517. PyObject *_res = NULL;
  1518. OSErr _err;
  1519. FSRef destRef;
  1520. if (!PyArg_ParseTuple(_args, "O&",
  1521. FSRef_Convert, &destRef))
  1522. return NULL;
  1523. _err = FSExchangeObjects(&_self->ob_itself,
  1524. &destRef);
  1525. if (_err != noErr) return PyMac_Error(_err);
  1526. Py_INCREF(Py_None);
  1527. _res = Py_None;
  1528. return _res;
  1529. }
  1530. static PyObject *FSRef_FSRenameUnicode(FSRefObject *_self, PyObject *_args)
  1531. {
  1532. PyObject *_res = NULL;
  1533. OSErr _err;
  1534. UniChar *nameLength__in__;
  1535. UniCharCount nameLength__len__;
  1536. int nameLength__in_len__;
  1537. TextEncoding textEncodingHint;
  1538. FSRef newRef;
  1539. if (!PyArg_ParseTuple(_args, "u#l",
  1540. &nameLength__in__, &nameLength__in_len__,
  1541. &textEncodingHint))
  1542. return NULL;
  1543. nameLength__len__ = nameLength__in_len__;
  1544. _err = FSRenameUnicode(&_self->ob_itself,
  1545. nameLength__len__, nameLength__in__,
  1546. textEncodingHint,
  1547. &newRef);
  1548. if (_err != noErr) return PyMac_Error(_err);
  1549. _res = Py_BuildValue("O&",
  1550. FSRef_New, &newRef);
  1551. return _res;
  1552. }
  1553. static PyObject *FSRef_FSGetCatalogInfo(FSRefObject *_self, PyObject *_args)
  1554. {
  1555. PyObject *_res = NULL;
  1556. OSErr _err;
  1557. FSCatalogInfoBitmap whichInfo;
  1558. FSCatalogInfo catalogInfo;
  1559. HFSUniStr255 outName;
  1560. #ifndef __LP64__
  1561. FSSpec fsSpec;
  1562. #endif /* !__LP64__ */
  1563. FSRef parentRef;
  1564. if (!PyArg_ParseTuple(_args, "l",
  1565. &whichInfo))
  1566. return NULL;
  1567. _err = FSGetCatalogInfo(&_self->ob_itself,
  1568. whichInfo,
  1569. &catalogInfo,
  1570. &outName,
  1571. #ifndef __LP64__
  1572. &fsSpec,
  1573. #else /* __LP64__ */
  1574. NULL,
  1575. #endif /* __LP64__ */
  1576. &parentRef);
  1577. if (_err != noErr) return PyMac_Error(_err);
  1578. #ifndef __LP64__
  1579. _res = Py_BuildValue("O&O&O&O&",
  1580. FSCatalogInfo_New, &catalogInfo,
  1581. PyMac_BuildHFSUniStr255, &outName,
  1582. FSSpec_New, &fsSpec,
  1583. FSRef_New, &parentRef);
  1584. #else /* __LP64__ */
  1585. _res = Py_BuildValue("O&O&OO&",
  1586. FSCatalogInfo_New, &catalogInfo,
  1587. PyMac_BuildHFSUniStr255, &outName,
  1588. Py_None,
  1589. FSRef_New, &parentRef);
  1590. #endif /* __LP64__ */
  1591. return _res;
  1592. }
  1593. static PyObject *FSRef_FSSetCatalogInfo(FSRefObject *_self, PyObject *_args)
  1594. {
  1595. PyObject *_res = NULL;
  1596. OSErr _err;
  1597. FSCatalogInfoBitmap whichInfo;
  1598. FSCatalogInfo catalogInfo;
  1599. if (!PyArg_ParseTuple(_args, "lO&",
  1600. &whichInfo,
  1601. FSCatalogInfo_Convert, &catalogInfo))
  1602. return NULL;
  1603. _err = FSSetCatalogInfo(&_self->ob_itself,
  1604. whichInfo,
  1605. &catalogInfo);
  1606. if (_err != noErr) return PyMac_Error(_err);
  1607. Py_INCREF(Py_None);
  1608. _res = Py_None;
  1609. return _res;
  1610. }
  1611. static PyObject *FSRef_FSCreateFork(FSRefObject *_self, PyObject *_args)
  1612. {
  1613. PyObject *_res = NULL;
  1614. OSErr _err;
  1615. UniChar *forkNameLength__in__;
  1616. UniCharCount forkNameLength__len__;
  1617. int forkNameLength__in_len__;
  1618. if (!PyArg_ParseTuple(_args, "u#",
  1619. &forkNameLength__in__, &forkNameLength__in_len__))
  1620. return NULL;
  1621. forkNameLength__len__ = forkNameLength__in_len__;
  1622. _err = FSCreateFork(&_self->ob_itself,
  1623. forkNameLength__len__, forkNameLength__in__);
  1624. if (_err != noErr) return PyMac_Error(_err);
  1625. Py_INCREF(Py_None);
  1626. _res = Py_None;
  1627. return _res;
  1628. }
  1629. static PyObject *FSRef_FSDeleteFork(FSRefObject *_self, PyObject *_args)
  1630. {
  1631. PyObject *_res = NULL;
  1632. OSErr _err;
  1633. UniChar *forkNameLength__in__;
  1634. UniCharCount forkNameLength__len__;
  1635. int forkNameLength__in_len__;
  1636. if (!PyArg_ParseTuple(_args, "u#",
  1637. &forkNameLength__in__, &forkNameLength__in_len__))
  1638. return NULL;
  1639. forkNameLength__len__ = forkNameLength__in_len__;
  1640. _err = FSDeleteFork(&_self->ob_itself,
  1641. forkNameLength__len__, forkNameLength__in__);
  1642. if (_err != noErr) return PyMac_Error(_err);
  1643. Py_INCREF(Py_None);
  1644. _res = Py_None;
  1645. return _res;
  1646. }
  1647. static PyObject *FSRef_FSOpenFork(FSRefObject *_self, PyObject *_args)
  1648. {
  1649. PyObject *_res = NULL;
  1650. OSErr _err;
  1651. UniChar *forkNameLength__in__;
  1652. UniCharCount forkNameLength__len__;
  1653. int forkNameLength__in_len__;
  1654. SInt8 permissions;
  1655. FSIORefNum forkRefNum;
  1656. if (!PyArg_ParseTuple(_args, "u#b",
  1657. &forkNameLength__in__, &forkNameLength__in_len__,
  1658. &permissions))
  1659. return NULL;
  1660. forkNameLength__len__ = forkNameLength__in_len__;
  1661. _err = FSOpenFork(&_self->ob_itself,
  1662. forkNameLength__len__, forkNameLength__in__,
  1663. permissions,
  1664. &forkRefNum);
  1665. if (_err != noErr) return PyMac_Error(_err);
  1666. _res = Py_BuildValue("h",
  1667. forkRefNum);
  1668. return _res;
  1669. }
  1670. static PyObject *FSRef_FNNotify(FSRefObject *_self, PyObject *_args)
  1671. {
  1672. PyObject *_res = NULL;
  1673. OSStatus _err;
  1674. FNMessage message;
  1675. OptionBits flags;
  1676. if (!PyArg_ParseTuple(_args, "ll",
  1677. &message,
  1678. &flags))
  1679. return NULL;
  1680. _err = FNNotify(&_self->ob_itself,
  1681. message,
  1682. flags);
  1683. if (_err != noErr) return PyMac_Error(_err);
  1684. Py_INCREF(Py_None);
  1685. _res = Py_None;
  1686. return _res;
  1687. }
  1688. static PyObject *FSRef_FSNewAliasMinimal(FSRefObject *_self, PyObject *_args)
  1689. {
  1690. PyObject *_res = NULL;
  1691. OSErr _err;
  1692. AliasHandle inAlias;
  1693. if (!PyArg_ParseTuple(_args, ""))
  1694. return NULL;
  1695. _err = FSNewAliasMinimal(&_self->ob_itself,
  1696. &inAlias);
  1697. if (_err != noErr) return PyMac_Error(_err);
  1698. _res = Py_BuildValue("O&",
  1699. Alias_New, inAlias);
  1700. return _res;
  1701. }
  1702. static PyObject *FSRef_FSIsAliasFile(FSRefObject *_self, PyObject *_args)
  1703. {
  1704. PyObject *_res = NULL;
  1705. OSErr _err;
  1706. Boolean aliasFileFlag;
  1707. Boolean folderFlag;
  1708. if (!PyArg_ParseTuple(_args, ""))
  1709. return NULL;
  1710. _err = FSIsAliasFile(&_self->ob_itself,
  1711. &aliasFileFlag,
  1712. &folderFlag);
  1713. if (_err != noErr) return PyMac_Error(_err);
  1714. _res = Py_BuildValue("bb",
  1715. aliasFileFlag,
  1716. folderFlag);
  1717. return _res;
  1718. }
  1719. static PyObject *FSRef_FSRefMakePath(FSRefObject *_self, PyObject *_args)
  1720. {
  1721. PyObject *_res = NULL;
  1722. OSStatus _err;
  1723. #define MAXPATHNAME 1024
  1724. UInt8 path[MAXPATHNAME];
  1725. UInt32 maxPathSize = MAXPATHNAME;
  1726. if (!PyArg_ParseTuple(_args, ""))
  1727. return NULL;
  1728. _err = FSRefMakePath(&_self->ob_itself,
  1729. path,
  1730. maxPathSize);
  1731. if (_err != noErr) return PyMac_Error(_err);
  1732. _res = Py_BuildValue("s", path);
  1733. return _res;
  1734. }
  1735. static PyObject *FSRef_as_pathname(FSRefObject *_self, PyObject *_args)
  1736. {
  1737. PyObject *_res = NULL;
  1738. if (!PyArg_ParseTuple(_args, ""))
  1739. return NULL;
  1740. _res = FSRef_FSRefMakePath(_self, _args);
  1741. return _res;
  1742. }
  1743. static PyMethodDef FSRef_methods[] = {
  1744. {"FSMakeFSRefUnicode", (PyCFunction)FSRef_FSMakeFSRefUnicode, 1,
  1745. PyDoc_STR("(Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
  1746. {"FSCompareFSRefs", (PyCFunction)FSRef_FSCompareFSRefs, 1,
  1747. PyDoc_STR("(FSRef ref2) -> None")},
  1748. {"FSCreateFileUnicode", (PyCFunction)FSRef_FSCreateFileUnicode, 1,
  1749. PyDoc_STR("(Buffer nameLength, FSCatalogInfoBitmap whichInfo, FSCatalogInfo catalogInfo) -> (FSRef newRef, FSSpec newSpec)")},
  1750. {"FSCreateDirectoryUnicode", (PyCFunction)FSRef_FSCreateDirectoryUnicode, 1,
  1751. PyDoc_STR("(Buffer nameLength, FSCatalogInfoBitmap whichInfo, FSCatalogInfo catalogInfo) -> (FSRef newRef, FSSpec newSpec, UInt32 newDirID)")},
  1752. {"FSDeleteObject", (PyCFunction)FSRef_FSDeleteObject, 1,
  1753. PyDoc_STR("() -> None")},
  1754. {"FSMoveObject", (PyCFunction)FSRef_FSMoveObject, 1,
  1755. PyDoc_STR("(FSRef destDirectory) -> (FSRef newRef)")},
  1756. {"FSExchangeObjects", (PyCFunction)FSRef_FSExchangeObjects, 1,
  1757. PyDoc_STR("(FSRef destRef) -> None")},
  1758. {"FSRenameUnicode", (PyCFunction)FSRef_FSRenameUnicode, 1,
  1759. PyDoc_STR("(Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
  1760. {"FSGetCatalogInfo", (PyCFunction)FSRef_FSGetCatalogInfo, 1,
  1761. PyDoc_STR("(FSCatalogInfoBitmap whichInfo) -> (FSCatalogInfo catalogInfo, HFSUniStr255 outName, FSSpec fsSpec, FSRef parentRef)")},
  1762. {"FSSetCatalogInfo", (PyCFunction)FSRef_FSSetCatalogInfo, 1,
  1763. PyDoc_STR("(FSCatalogInfoBitmap whichInfo, FSCatalogInfo catalogInfo) -> None")},
  1764. {"FSCreateFork", (PyCFunction)FSRef_FSCreateFork, 1,
  1765. PyDoc_STR("(Buffer forkNameLength) -> None")},
  1766. {"FSDeleteFork", (PyCFunction)FSRef_FSDeleteFork, 1,
  1767. PyDoc_STR("(Buffer forkNameLength) -> None")},
  1768. {"FSOpenFork", (PyCFunction)FSRef_FSOpenFork, 1,
  1769. PyDoc_STR("(Buffer forkNameLength, SInt8 permissions) -> (SInt16 forkRefNum)")},
  1770. {"FNNotify", (PyCFunction)FSRef_FNNotify, 1,
  1771. PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
  1772. {"FSNewAliasMinimal", (PyCFunction)FSRef_FSNewAliasMinimal, 1,
  1773. PyDoc_STR("() -> (AliasHandle inAlias)")},
  1774. {"FSIsAliasFile", (PyCFunction)FSRef_FSIsAliasFile, 1,
  1775. PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
  1776. {"FSRefMakePath", (PyCFunction)FSRef_FSRefMakePath, 1,
  1777. PyDoc_STR("() -> string")},
  1778. {"as_pathname", (PyCFunction)FSRef_as_pathname, 1,
  1779. PyDoc_STR("() -> string")},
  1780. {NULL, NULL, 0}
  1781. };
  1782. static PyObject *FSRef_get_data(FSRefObject *self, void *closure)
  1783. {
  1784. return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
  1785. }
  1786. #define FSRef_set_data NULL
  1787. static PyGetSetDef FSRef_getsetlist[] = {
  1788. {"data", (getter)FSRef_get_data, (setter)FSRef_set_data, "Raw data of the FSRef object"},
  1789. {NULL, NULL, NULL, NULL},
  1790. };
  1791. #define FSRef_compare NULL
  1792. #define FSRef_repr NULL
  1793. #define FSRef_hash NULL
  1794. static int FSRef_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
  1795. {
  1796. PyObject *v = NULL;
  1797. char *rawdata = NULL;
  1798. int rawdatalen = 0;
  1799. static char *kw[] = {"itself", "rawdata", 0};
  1800. if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
  1801. return -1;
  1802. if (v && rawdata)
  1803. {
  1804. PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
  1805. return -1;
  1806. }
  1807. if (!v && !rawdata)
  1808. {
  1809. PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
  1810. return -1;
  1811. }
  1812. if (rawdata)
  1813. {
  1814. if (rawdatalen != sizeof(FSRef))
  1815. {
  1816. PyErr_SetString(PyExc_TypeError, "FSRef rawdata incorrect size");
  1817. return -1;
  1818. }
  1819. memcpy(&((FSRefObject *)_self)->ob_itself, rawdata, rawdatalen);
  1820. return 0;
  1821. }
  1822. if (PyMac_GetFSRef(v, &((FSRefObject *)_self)->ob_itself)) return 0;
  1823. return -1;
  1824. }
  1825. #define FSRef_tp_alloc PyType_GenericAlloc
  1826. static PyObject *FSRef_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  1827. {
  1828. PyObject *self;
  1829. if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
  1830. memset(&((FSRefObject *)self)->ob_itself, 0, sizeof(FSRef));
  1831. return self;
  1832. }
  1833. #define FSRef_tp_free PyObject_Del
  1834. static PyTypeObject FSRef_Type = {
  1835. PyObject_HEAD_INIT(NULL)
  1836. 0, /*ob_size*/
  1837. "Carbon.File.FSRef", /*tp_name*/
  1838. sizeof(FSRefObject), /*tp_basicsize*/
  1839. 0, /*tp_itemsize*/
  1840. /* methods */
  1841. (destructor) FSRef_dealloc, /*tp_dealloc*/
  1842. 0, /*tp_print*/
  1843. (getattrfunc)0, /*tp_getattr*/
  1844. (setattrfunc)0, /*tp_setattr*/
  1845. (cmpfunc) FSRef_compare, /*tp_compare*/
  1846. (reprfunc) FSRef_repr, /*tp_repr*/
  1847. (PyNumberMethods *)0, /* tp_as_number */
  1848. (PySequenceMethods *)0, /* tp_as_sequence */
  1849. (PyMappingMethods *)0, /* tp_as_mapping */
  1850. (hashfunc) FSRef_hash, /*tp_hash*/
  1851. 0, /*tp_call*/
  1852. 0, /*tp_str*/
  1853. PyObject_GenericGetAttr, /*tp_getattro*/
  1854. PyObject_GenericSetAttr, /*tp_setattro */
  1855. 0, /*tp_as_buffer*/
  1856. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  1857. 0, /*tp_doc*/
  1858. 0, /*tp_traverse*/
  1859. 0, /*tp_clear*/
  1860. 0, /*tp_richcompare*/
  1861. 0, /*tp_weaklistoffset*/
  1862. 0, /*tp_iter*/
  1863. 0, /*tp_iternext*/
  1864. FSRef_methods, /* tp_methods */
  1865. 0, /*tp_members*/
  1866. FSRef_getsetlist, /*tp_getset*/
  1867. 0, /*tp_base*/
  1868. 0, /*tp_dict*/
  1869. 0, /*tp_descr_get*/
  1870. 0, /*tp_descr_set*/
  1871. 0, /*tp_dictoffset*/
  1872. FSRef_tp_init, /* tp_init */
  1873. FSRef_tp_alloc, /* tp_alloc */
  1874. FSRef_tp_new, /* tp_new */
  1875. FSRef_tp_free, /* tp_free */
  1876. };
  1877. /* --------------------- End object type FSRef ---------------------- */
  1878. #ifndef __LP64__
  1879. static PyObject *File_UnmountVol(PyObject *_self, PyObject *_args)
  1880. {
  1881. PyObject *_res = NULL;
  1882. OSErr _err;
  1883. Str63 volName;
  1884. short vRefNum;
  1885. if (!PyArg_ParseTuple(_args, "O&h",
  1886. PyMac_GetStr255, volName,
  1887. &vRefNum))
  1888. return NULL;
  1889. _err = UnmountVol(volName,
  1890. vRefNum);
  1891. if (_err != noErr) return PyMac_Error(_err);
  1892. Py_INCREF(Py_None);
  1893. _res = Py_None;
  1894. return _res;
  1895. }
  1896. static PyObject *File_FlushVol(PyObject *_self, PyObject *_args)
  1897. {
  1898. PyObject *_res = NULL;
  1899. OSErr _err;
  1900. Str63 volName;
  1901. short vRefNum;
  1902. if (!PyArg_ParseTuple(_args, "O&h",
  1903. PyMac_GetStr255, volName,
  1904. &vRefNum))
  1905. return NULL;
  1906. _err = FlushVol(volName,
  1907. vRefNum);
  1908. if (_err != noErr) return PyMac_Error(_err);
  1909. Py_INCREF(Py_None);
  1910. _res = Py_None;
  1911. return _res;
  1912. }
  1913. static PyObject *File_HSetVol(PyObject *_self, PyObject *_args)
  1914. {
  1915. PyObject *_res = NULL;
  1916. OSErr _err;
  1917. Str63 volName;
  1918. short vRefNum;
  1919. long dirID;
  1920. if (!PyArg_ParseTuple(_args, "O&hl",
  1921. PyMac_GetStr255, volName,
  1922. &vRefNum,
  1923. &dirID))
  1924. return NULL;
  1925. _err = HSetVol(volName,
  1926. vRefNum,
  1927. dirID);
  1928. if (_err != noErr) return PyMac_Error(_err);
  1929. Py_INCREF(Py_None);
  1930. _res = Py_None;
  1931. return _res;
  1932. }
  1933. static PyObject *File_FSClose(PyObject *_self, PyObject *_args)
  1934. {
  1935. PyObject *_res = NULL;
  1936. OSErr _err;
  1937. short refNum;
  1938. if (!PyArg_ParseTuple(_args, "h",
  1939. &refNum))
  1940. return NULL;
  1941. _err = FSClose(refNum);
  1942. if (_err != noErr) return PyMac_Error(_err);
  1943. Py_INCREF(Py_None);
  1944. _res = Py_None;
  1945. return _res;
  1946. }
  1947. static PyObject *File_Allocate(PyObject *_self, PyObject *_args)
  1948. {
  1949. PyObject *_res = NULL;
  1950. OSErr _err;
  1951. short refNum;
  1952. long count;
  1953. if (!PyArg_ParseTuple(_args, "h",
  1954. &refNum))
  1955. return NULL;
  1956. _err = Allocate(refNum,
  1957. &count);
  1958. if (_err != noErr) return PyMac_Error(_err);
  1959. _res = Py_BuildValue("l",
  1960. count);
  1961. return _res;
  1962. }
  1963. static PyObject *File_GetEOF(PyObject *_self, PyObject *_args)
  1964. {
  1965. PyObject *_res = NULL;
  1966. OSErr _err;
  1967. short refNum;
  1968. long logEOF;
  1969. if (!PyArg_ParseTuple(_args, "h",
  1970. &refNum))
  1971. return NULL;
  1972. _err = GetEOF(refNum,
  1973. &logEOF);
  1974. if (_err != noErr) return PyMac_Error(_err);
  1975. _res = Py_BuildValue("l",
  1976. logEOF);
  1977. return _res;
  1978. }
  1979. static PyObject *File_SetEOF(PyObject *_self, PyObject *_args)
  1980. {
  1981. PyObject *_res = NULL;
  1982. OSErr _err;
  1983. short refNum;
  1984. long logEOF;
  1985. if (!PyArg_ParseTuple(_args, "hl",
  1986. &refNum,
  1987. &logEOF))
  1988. return NULL;
  1989. _err = SetEOF(refNum,
  1990. logEOF);
  1991. if (_err != noErr) return PyMac_Error(_err);
  1992. Py_INCREF(Py_None);
  1993. _res = Py_None;
  1994. return _res;
  1995. }
  1996. static PyObject *File_GetFPos(PyObject *_self, PyObject *_args)
  1997. {
  1998. PyObject *_res = NULL;
  1999. OSErr _err;
  2000. short refNum;
  2001. long filePos;
  2002. if (!PyArg_ParseTuple(_args, "h",
  2003. &refNum))
  2004. return NULL;
  2005. _err = GetFPos(refNum,
  2006. &filePos);
  2007. if (_err != noErr) return PyMac_Error(_err);
  2008. _res = Py_BuildValue("l",
  2009. filePos);
  2010. return _res;
  2011. }
  2012. static PyObject *File_SetFPos(PyObject *_self, PyObject *_args)
  2013. {
  2014. PyObject *_res = NULL;
  2015. OSErr _err;
  2016. short refNum;
  2017. short posMode;
  2018. long posOff;
  2019. if (!PyArg_ParseTuple(_args, "hhl",
  2020. &refNum,
  2021. &posMode,
  2022. &posOff))
  2023. return NULL;
  2024. _err = SetFPos(refNum,
  2025. posMode,
  2026. posOff);
  2027. if (_err != noErr) return PyMac_Error(_err);
  2028. Py_INCREF(Py_None);
  2029. _res = Py_None;
  2030. return _res;
  2031. }
  2032. static PyObject *File_GetVRefNum(PyObject *_self, PyObject *_args)
  2033. {
  2034. PyObject *_res = NULL;
  2035. OSErr _err;
  2036. short fileRefNum;
  2037. short vRefNum;
  2038. if (!PyArg_ParseTuple(_args, "h",
  2039. &fileRefNum))
  2040. return NULL;
  2041. _err = GetVRefNum(fileRefNum,
  2042. &vRefNum);
  2043. if (_err != noErr) return PyMac_Error(_err);
  2044. _res = Py_BuildValue("h",
  2045. vRefNum);
  2046. return _res;
  2047. }
  2048. static PyObject *File_HGetVol(PyObject *_self, PyObject *_args)
  2049. {
  2050. PyObject *_res = NULL;
  2051. OSErr _err;
  2052. StringPtr volName;
  2053. short vRefNum;
  2054. long dirID;
  2055. if (!PyArg_ParseTuple(_args, "O&",
  2056. PyMac_GetStr255, &volName))
  2057. return NULL;
  2058. _err = HGetVol(volName,
  2059. &vRefNum,
  2060. &dirID);
  2061. if (_err != noErr) return PyMac_Error(_err);
  2062. _res = Py_BuildValue("hl",
  2063. vRefNum,
  2064. dirID);
  2065. return _res;
  2066. }
  2067. static PyObject *File_HOpen(PyObject *_self, PyObject *_args)
  2068. {
  2069. PyObject *_res = NULL;
  2070. OSErr _err;
  2071. short vRefNum;
  2072. long dirID;
  2073. Str255 fileName;
  2074. SInt8 permission;
  2075. short refNum;
  2076. if (!PyArg_ParseTuple(_args, "hlO&b",
  2077. &vRefNum,
  2078. &dirID,
  2079. PyMac_GetStr255, fileName,
  2080. &permission))
  2081. return NULL;
  2082. _err = HOpen(vRefNum,
  2083. dirID,
  2084. fileName,
  2085. permission,
  2086. &refNum);
  2087. if (_err != noErr) return PyMac_Error(_err);
  2088. _res = Py_BuildValue("h",
  2089. refNum);
  2090. return _res;
  2091. }
  2092. static PyObject *File_HOpenDF(PyObject *_self, PyObject *_args)
  2093. {
  2094. PyObject *_res = NULL;
  2095. OSErr _err;
  2096. short vRefNum;
  2097. long dirID;
  2098. Str255 fileName;
  2099. SInt8 permission;
  2100. short refNum;
  2101. if (!PyArg_ParseTuple(_args, "hlO&b",
  2102. &vRefNum,
  2103. &dirID,
  2104. PyMac_GetStr255, fileName,
  2105. &permission))
  2106. return NULL;
  2107. _err = HOpenDF(vRefNum,
  2108. dirID,
  2109. fileName,
  2110. permission,
  2111. &refNum);
  2112. if (_err != noErr) return PyMac_Error(_err);
  2113. _res = Py_BuildValue("h",
  2114. refNum);
  2115. return _res;
  2116. }
  2117. static PyObject *File_HOpenRF(PyObject *_self, PyObject *_args)
  2118. {
  2119. PyObject *_res = NULL;
  2120. OSErr _err;
  2121. short vRefNum;
  2122. long dirID;
  2123. Str255 fileName;
  2124. SInt8 permission;
  2125. short refNum;
  2126. if (!PyArg_ParseTuple(_args, "hlO&b",
  2127. &vRefNum,
  2128. &dirID,
  2129. PyMac_GetStr255, fileName,
  2130. &permission))
  2131. return NULL;
  2132. _err = HOpenRF(vRefNum,
  2133. dirID,
  2134. fileName,
  2135. permission,
  2136. &refNum);
  2137. if (_err != noErr) return PyMac_Error(_err);
  2138. _res = Py_BuildValue("h",
  2139. refNum);
  2140. return _res;
  2141. }
  2142. static PyObject *File_AllocContig(PyObject *_self, PyObject *_args)
  2143. {
  2144. PyObject *_res = NULL;
  2145. OSErr _err;
  2146. short refNum;
  2147. long count;
  2148. if (!PyArg_ParseTuple(_args, "h",
  2149. &refNum))
  2150. return NULL;
  2151. _err = AllocContig(refNum,
  2152. &count);
  2153. if (_err != noErr) return PyMac_Error(_err);
  2154. _res = Py_BuildValue("l",
  2155. count);
  2156. return _res;
  2157. }
  2158. static PyObject *File_HCreate(PyObject *_self, PyObject *_args)
  2159. {
  2160. PyObject *_res = NULL;
  2161. OSErr _err;
  2162. short vRefNum;
  2163. long dirID;
  2164. Str255 fileName;
  2165. OSType creator;
  2166. OSType fileType;
  2167. if (!PyArg_ParseTuple(_args, "hlO&O&O&",
  2168. &vRefNum,
  2169. &dirID,
  2170. PyMac_GetStr255, fileName,
  2171. PyMac_GetOSType, &creator,
  2172. PyMac_GetOSType, &fileType))
  2173. return NULL;
  2174. _err = HCreate(vRefNum,
  2175. dirID,
  2176. fileName,
  2177. creator,
  2178. fileType);
  2179. if (_err != noErr) return PyMac_Error(_err);
  2180. Py_INCREF(Py_None);
  2181. _res = Py_None;
  2182. return _res;
  2183. }
  2184. static PyObject *File_DirCreate(PyObject *_self, PyObject *_args)
  2185. {
  2186. PyObject *_res = NULL;
  2187. OSErr _err;
  2188. short vRefNum;
  2189. long parentDirID;
  2190. Str255 directoryName;
  2191. long createdDirID;
  2192. if (!PyArg_ParseTuple(_args, "hlO&",
  2193. &vRefNum,
  2194. &parentDirID,
  2195. PyMac_GetStr255, directoryName))
  2196. return NULL;
  2197. _err = DirCreate(vRefNum,
  2198. parentDirID,
  2199. directoryName,
  2200. &createdDirID);
  2201. if (_err != noErr) return PyMac_Error(_err);
  2202. _res = Py_BuildValue("l",
  2203. createdDirID);
  2204. return _res;
  2205. }
  2206. static PyObject *File_HDelete(PyObject *_self, PyObject *_args)
  2207. {
  2208. PyObject *_res = NULL;
  2209. OSErr _err;
  2210. short vRefNum;
  2211. long dirID;
  2212. Str255 fileName;
  2213. if (!PyArg_ParseTuple(_args, "hlO&",
  2214. &vRefNum,
  2215. &dirID,
  2216. PyMac_GetStr255, fileName))
  2217. return NULL;
  2218. _err = HDelete(vRefNum,
  2219. dirID,
  2220. fileName);
  2221. if (_err != noErr) return PyMac_Error(_err);
  2222. Py_INCREF(Py_None);
  2223. _res = Py_None;
  2224. return _res;
  2225. }
  2226. static PyObject *File_HGetFInfo(PyObject *_self, PyObject *_args)
  2227. {
  2228. PyObject *_res = NULL;
  2229. OSErr _err;
  2230. short vRefNum;
  2231. long dirID;
  2232. Str255 fileName;
  2233. FInfo fndrInfo;
  2234. if (!PyArg_ParseTuple(_args, "hlO&",
  2235. &vRefNum,
  2236. &dirID,
  2237. PyMac_GetStr255, fileName))
  2238. return NULL;
  2239. _err = HGetFInfo(vRefNum,
  2240. dirID,
  2241. fileName,
  2242. &fndrInfo);
  2243. if (_err != noErr) return PyMac_Error(_err);
  2244. _res = Py_BuildValue("O&",
  2245. FInfo_New, &fndrInfo);
  2246. return _res;
  2247. }
  2248. static PyObject *File_HSetFInfo(PyObject *_self, PyObject *_args)
  2249. {
  2250. PyObject *_res = NULL;
  2251. OSErr _err;
  2252. short vRefNum;
  2253. long dirID;
  2254. Str255 fileName;
  2255. FInfo fndrInfo;
  2256. if (!PyArg_ParseTuple(_args, "hlO&O&",
  2257. &vRefNum,
  2258. &dirID,
  2259. PyMac_GetStr255, fileName,
  2260. FInfo_Convert, &fndrInfo))
  2261. return NULL;
  2262. _err = HSetFInfo(vRefNum,
  2263. dirID,
  2264. fileName,
  2265. &fndrInfo);
  2266. if (_err != noErr) return PyMac_Error(_err);
  2267. Py_INCREF(Py_None);
  2268. _res = Py_None;
  2269. return _res;
  2270. }
  2271. static PyObject *File_HSetFLock(PyObject *_self, PyObject *_args)
  2272. {
  2273. PyObject *_res = NULL;
  2274. OSErr _err;
  2275. short vRefNum;
  2276. long dirID;
  2277. Str255 fileName;
  2278. if (!PyArg_ParseTuple(_args, "hlO&",
  2279. &vRefNum,
  2280. &dirID,
  2281. PyMac_GetStr255, fileName))
  2282. return NULL;
  2283. _err = HSetFLock(vRefNum,
  2284. dirID,
  2285. fileName);
  2286. if (_err != noErr) return PyMac_Error(_err);
  2287. Py_INCREF(Py_None);
  2288. _res = Py_None;
  2289. return _res;
  2290. }
  2291. static PyObject *File_HRstFLock(PyObject *_self, PyObject *_args)
  2292. {
  2293. PyObject *_res = NULL;
  2294. OSErr _err;
  2295. short vRefNum;
  2296. long dirID;
  2297. Str255 fileName;
  2298. if (!PyArg_ParseTuple(_args, "hlO&",
  2299. &vRefNum,
  2300. &dirID,
  2301. PyMac_GetStr255, fileName))
  2302. return NULL;
  2303. _err = HRstFLock(vRefNum,
  2304. dirID,
  2305. fileName);
  2306. if (_err != noErr) return PyMac_Error(_err);
  2307. Py_INCREF(Py_None);
  2308. _res = Py_None;
  2309. return _res;
  2310. }
  2311. static PyObject *File_HRename(PyObject *_self, PyObject *_args)
  2312. {
  2313. PyObject *_res = NULL;
  2314. OSErr _err;
  2315. short vRefNum;
  2316. long dirID;
  2317. Str255 oldName;
  2318. Str255 newName;
  2319. if (!PyArg_ParseTuple(_args, "hlO&O&",
  2320. &vRefNum,
  2321. &dirID,
  2322. PyMac_GetStr255, oldName,
  2323. PyMac_GetStr255, newName))
  2324. return NULL;
  2325. _err = HRename(vRefNum,
  2326. dirID,
  2327. oldName,
  2328. newName);
  2329. if (_err != noErr) return PyMac_Error(_err);
  2330. Py_INCREF(Py_None);
  2331. _res = Py_None;
  2332. return _res;
  2333. }
  2334. static PyObject *File_CatMove(PyObject *_self, PyObject *_args)
  2335. {
  2336. PyObject *_res = NULL;
  2337. OSErr _err;
  2338. short vRefNum;
  2339. long dirID;
  2340. Str255 oldName;
  2341. long newDirID;
  2342. Str255 newName;
  2343. if (!PyArg_ParseTuple(_args, "hlO&lO&",
  2344. &vRefNum,
  2345. &dirID,
  2346. PyMac_GetStr255, oldName,
  2347. &newDirID,
  2348. PyMac_GetStr255, newName))
  2349. return NULL;
  2350. _err = CatMove(vRefNum,
  2351. dirID,
  2352. oldName,
  2353. newDirID,
  2354. newName);
  2355. if (_err != noErr) return PyMac_Error(_err);
  2356. Py_INCREF(Py_None);
  2357. _res = Py_None;
  2358. return _res;
  2359. }
  2360. static PyObject *File_FSMakeFSSpec(PyObject *_self, PyObject *_args)
  2361. {
  2362. PyObject *_res = NULL;
  2363. OSErr _err;
  2364. short vRefNum;
  2365. long dirID;
  2366. Str255 fileName;
  2367. FSSpec spec;
  2368. if (!PyArg_ParseTuple(_args, "hlO&",
  2369. &vRefNum,
  2370. &dirID,
  2371. PyMac_GetStr255, fileName))
  2372. return NULL;
  2373. _err = FSMakeFSSpec(vRefNum,
  2374. dirID,
  2375. fileName,
  2376. &spec);
  2377. if (_err != noErr) return PyMac_Error(_err);
  2378. _res = Py_BuildValue("O&",
  2379. FSSpec_New, &spec);
  2380. return _res;
  2381. }
  2382. #endif /* !__LP64__ */
  2383. static PyObject *File_FSGetForkPosition(PyObject *_self, PyObject *_args)
  2384. {
  2385. PyObject *_res = NULL;
  2386. OSErr _err;
  2387. SInt16 forkRefNum;
  2388. SInt64 position;
  2389. if (!PyArg_ParseTuple(_args, "h",
  2390. &forkRefNum))
  2391. return NULL;
  2392. _err = FSGetForkPosition(forkRefNum,
  2393. &position);
  2394. if (_err != noErr) return PyMac_Error(_err);
  2395. _res = Py_BuildValue("L",
  2396. position);
  2397. return _res;
  2398. }
  2399. static PyObject *File_FSSetForkPosition(PyObject *_self, PyObject *_args)
  2400. {
  2401. PyObject *_res = NULL;
  2402. OSErr _err;
  2403. SInt16 forkRefNum;
  2404. UInt16 positionMode;
  2405. SInt64 positionOffset;
  2406. if (!PyArg_ParseTuple(_args, "hHL",
  2407. &forkRefNum,
  2408. &positionMode,
  2409. &positionOffset))
  2410. return NULL;
  2411. _err = FSSetForkPosition(forkRefNum,
  2412. positionMode,
  2413. positionOffset);
  2414. if (_err != noErr) return PyMac_Error(_err);
  2415. Py_INCREF(Py_None);
  2416. _res = Py_None;
  2417. return _res;
  2418. }
  2419. static PyObject *File_FSGetForkSize(PyObject *_self, PyObject *_args)
  2420. {
  2421. PyObject *_res = NULL;
  2422. OSErr _err;
  2423. SInt16 forkRefNum;
  2424. SInt64 forkSize;
  2425. if (!PyArg_ParseTuple(_args, "h",
  2426. &forkRefNum))
  2427. return NULL;
  2428. _err = FSGetForkSize(forkRefNum,
  2429. &forkSize);
  2430. if (_err != noErr) return PyMac_Error(_err);
  2431. _res = Py_BuildValue("L",
  2432. forkSize);
  2433. return _res;
  2434. }
  2435. static PyObject *File_FSSetForkSize(PyObject *_self, PyObject *_args)
  2436. {
  2437. PyObject *_res = NULL;
  2438. OSErr _err;
  2439. SInt16 forkRefNum;
  2440. UInt16 positionMode;
  2441. SInt64 positionOffset;
  2442. if (!PyArg_ParseTuple(_args, "hHL",
  2443. &forkRefNum,
  2444. &positionMode,
  2445. &positionOffset))
  2446. return NULL;
  2447. _err = FSSetForkSize(forkRefNum,
  2448. positionMode,
  2449. positionOffset);
  2450. if (_err != noErr) return PyMac_Error(_err);
  2451. Py_INCREF(Py_None);
  2452. _res = Py_None;
  2453. return _res;
  2454. }
  2455. static PyObject *File_FSAllocateFork(PyObject *_self, PyObject *_args)
  2456. {
  2457. PyObject *_res = NULL;
  2458. OSErr _err;
  2459. SInt16 forkRefNum;
  2460. FSAllocationFlags flags;
  2461. UInt16 positionMode;
  2462. SInt64 positionOffset;
  2463. UInt64 requestCount;
  2464. UInt64 actualCount;
  2465. if (!PyArg_ParseTuple(_args, "hHHLL",
  2466. &forkRefNum,
  2467. &flags,
  2468. &positionMode,
  2469. &positionOffset,
  2470. &requestCount))
  2471. return NULL;
  2472. _err = FSAllocateFork(forkRefNum,
  2473. flags,
  2474. positionMode,
  2475. positionOffset,
  2476. requestCount,
  2477. &actualCount);
  2478. if (_err != noErr) return PyMac_Error(_err);
  2479. _res = Py_BuildValue("L",
  2480. actualCount);
  2481. return _res;
  2482. }
  2483. static PyObject *File_FSFlushFork(PyObject *_self, PyObject *_args)
  2484. {
  2485. PyObject *_res = NULL;
  2486. OSErr _err;
  2487. SInt16 forkRefNum;
  2488. if (!PyArg_ParseTuple(_args, "h",
  2489. &forkRefNum))
  2490. return NULL;
  2491. _err = FSFlushFork(forkRefNum);
  2492. if (_err != noErr) return PyMac_Error(_err);
  2493. Py_INCREF(Py_None);
  2494. _res = Py_None;
  2495. return _res;
  2496. }
  2497. static PyObject *File_FSCloseFork(PyObject *_self, PyObject *_args)
  2498. {
  2499. PyObject *_res = NULL;
  2500. OSErr _err;
  2501. SInt16 forkRefNum;
  2502. if (!PyArg_ParseTuple(_args, "h",
  2503. &forkRefNum))
  2504. return NULL;
  2505. _err = FSCloseFork(forkRefNum);
  2506. if (_err != noErr) return PyMac_Error(_err);
  2507. Py_INCREF(Py_None);
  2508. _res = Py_None;
  2509. return _res;
  2510. }
  2511. static PyObject *File_FSGetDataForkName(PyObject *_self, PyObject *_args)
  2512. {
  2513. PyObject *_res = NULL;
  2514. OSErr _err;
  2515. HFSUniStr255 dataForkName;
  2516. if (!PyArg_ParseTuple(_args, ""))
  2517. return NULL;
  2518. _err = FSGetDataForkName(&dataForkName);
  2519. if (_err != noErr) return PyMac_Error(_err);
  2520. _res = Py_BuildValue("O&",
  2521. PyMac_BuildHFSUniStr255, &dataForkName);
  2522. return _res;
  2523. }
  2524. static PyObject *File_FSGetResourceForkName(PyObject *_self, PyObject *_args)
  2525. {
  2526. PyObject *_res = NULL;
  2527. OSErr _err;
  2528. HFSUniStr255 resourceForkName;
  2529. if (!PyArg_ParseTuple(_args, ""))
  2530. return NULL;
  2531. _err = FSGetResourceForkName(&resourceForkName);
  2532. if (_err != noErr) return PyMac_Error(_err);
  2533. _res = Py_BuildValue("O&",
  2534. PyMac_BuildHFSUniStr255, &resourceForkName);
  2535. return _res;
  2536. }
  2537. static PyObject *File_FSPathMakeRef(PyObject *_self, PyObject *_args)
  2538. {
  2539. PyObject *_res = NULL;
  2540. OSStatus _err;
  2541. UInt8 * path;
  2542. FSRef ref;
  2543. Boolean isDirectory;
  2544. if (!PyArg_ParseTuple(_args, "s",
  2545. &path))
  2546. return NULL;
  2547. _err = FSPathMakeRef(path,
  2548. &ref,
  2549. &isDirectory);
  2550. if (_err != noErr) return PyMac_Error(_err);
  2551. _res = Py_BuildValue("O&b",
  2552. FSRef_New, &ref,
  2553. isDirectory);
  2554. return _res;
  2555. }
  2556. static PyObject *File_FNNotifyByPath(PyObject *_self, PyObject *_args)
  2557. {
  2558. PyObject *_res = NULL;
  2559. OSStatus _err;
  2560. UInt8 * path;
  2561. FNMessage message;
  2562. OptionBits flags;
  2563. if (!PyArg_ParseTuple(_args, "sll",
  2564. &path,
  2565. &message,
  2566. &flags))
  2567. return NULL;
  2568. _err = FNNotifyByPath(path,
  2569. message,
  2570. flags);
  2571. if (_err != noErr) return PyMac_Error(_err);
  2572. Py_INCREF(Py_None);
  2573. _res = Py_None;
  2574. return _res;
  2575. }
  2576. static PyObject *File_FNNotifyAll(PyObject *_self, PyObject *_args)
  2577. {
  2578. PyObject *_res = NULL;
  2579. OSStatus _err;
  2580. FNMessage message;
  2581. OptionBits flags;
  2582. if (!PyArg_ParseTuple(_args, "ll",
  2583. &message,
  2584. &flags))
  2585. return NULL;
  2586. _err = FNNotifyAll(message,
  2587. flags);
  2588. if (_err != noErr) return PyMac_Error(_err);
  2589. Py_INCREF(Py_None);
  2590. _res = Py_None;
  2591. return _res;
  2592. }
  2593. #ifndef __LP64__
  2594. static PyObject *File_NewAlias(PyObject *_self, PyObject *_args)
  2595. {
  2596. PyObject *_res = NULL;
  2597. OSErr _err;
  2598. FSSpec fromFile__buf__;
  2599. FSSpec *fromFile = &fromFile__buf__;
  2600. FSSpec target;
  2601. AliasHandle alias;
  2602. if (!PyArg_ParseTuple(_args, "O&O&",
  2603. myPyMac_GetOptFSSpecPtr, &fromFile,
  2604. FSSpec_Convert, &target))
  2605. return NULL;
  2606. _err = NewAlias(fromFile,
  2607. &target,
  2608. &alias);
  2609. if (_err != noErr) return PyMac_Error(_err);
  2610. _res = Py_BuildValue("O&",
  2611. Alias_New, alias);
  2612. return _res;
  2613. }
  2614. static PyObject *File_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args)
  2615. {
  2616. PyObject *_res = NULL;
  2617. OSErr _err;
  2618. char *fullPath__in__;
  2619. int fullPath__len__;
  2620. int fullPath__in_len__;
  2621. Str32 zoneName;
  2622. Str31 serverName;
  2623. AliasHandle alias;
  2624. if (!PyArg_ParseTuple(_args, "s#O&O&",
  2625. &fullPath__in__, &fullPath__in_len__,
  2626. PyMac_GetStr255, zoneName,
  2627. PyMac_GetStr255, serverName))
  2628. return NULL;
  2629. fullPath__len__ = fullPath__in_len__;
  2630. _err = NewAliasMinimalFromFullPath(fullPath__len__, fullPath__in__,
  2631. zoneName,
  2632. serverName,
  2633. &alias);
  2634. if (_err != noErr) return PyMac_Error(_err);
  2635. _res = Py_BuildValue("O&",
  2636. Alias_New, alias);
  2637. return _res;
  2638. }
  2639. static PyObject *File_ResolveAliasFile(PyObject *_self, PyObject *_args)
  2640. {
  2641. PyObject *_res = NULL;
  2642. OSErr _err;
  2643. FSSpec theSpec;
  2644. Boolean resolveAliasChains;
  2645. Boolean targetIsFolder;
  2646. Boolean wasAliased;
  2647. if (!PyArg_ParseTuple(_args, "O&b",
  2648. FSSpec_Convert, &theSpec,
  2649. &resolveAliasChains))
  2650. return NULL;
  2651. _err = ResolveAliasFile(&theSpec,
  2652. resolveAliasChains,
  2653. &targetIsFolder,
  2654. &wasAliased);
  2655. if (_err != noErr) return PyMac_Error(_err);
  2656. _res = Py_BuildValue("O&bb",
  2657. FSSpec_New, &theSpec,
  2658. targetIsFolder,
  2659. wasAliased);
  2660. return _res;
  2661. }
  2662. static PyObject *File_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
  2663. {
  2664. PyObject *_res = NULL;
  2665. OSErr _err;
  2666. FSSpec theSpec;
  2667. Boolean resolveAliasChains;
  2668. Boolean targetIsFolder;
  2669. Boolean wasAliased;
  2670. unsigned long mountFlags;
  2671. if (!PyArg_ParseTuple(_args, "O&bl",
  2672. FSSpec_Convert, &theSpec,
  2673. &resolveAliasChains,
  2674. &mountFlags))
  2675. return NULL;
  2676. _err = ResolveAliasFileWithMountFlags(&theSpec,
  2677. resolveAliasChains,
  2678. &targetIsFolder,
  2679. &wasAliased,
  2680. mountFlags);
  2681. if (_err != noErr) return PyMac_Error(_err);
  2682. _res = Py_BuildValue("O&bb",
  2683. FSSpec_New, &theSpec,
  2684. targetIsFolder,
  2685. wasAliased);
  2686. return _res;
  2687. }
  2688. static PyObject *File_UpdateAlias(PyObject *_self, PyObject *_args)
  2689. {
  2690. PyObject *_res = NULL;
  2691. OSErr _err;
  2692. FSSpec fromFile__buf__;
  2693. FSSpec *fromFile = &fromFile__buf__;
  2694. FSSpec target;
  2695. AliasHandle alias;
  2696. Boolean wasChanged;
  2697. if (!PyArg_ParseTuple(_args, "O&O&O&",
  2698. myPyMac_GetOptFSSpecPtr, &fromFile,
  2699. FSSpec_Convert, &target,
  2700. Alias_Convert, &alias))
  2701. return NULL;
  2702. _err = UpdateAlias(fromFile,
  2703. &target,
  2704. alias,
  2705. &wasChanged);
  2706. if (_err != noErr) return PyMac_Error(_err);
  2707. _res = Py_BuildValue("b",
  2708. wasChanged);
  2709. return _res;
  2710. }
  2711. static PyObject *File_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args)
  2712. {
  2713. PyObject *_res = NULL;
  2714. OSErr _err;
  2715. FSSpec theSpec;
  2716. Boolean resolveAliasChains;
  2717. Boolean targetIsFolder;
  2718. Boolean wasAliased;
  2719. unsigned long mountFlags;
  2720. if (!PyArg_ParseTuple(_args, "O&bl",
  2721. FSSpec_Convert, &theSpec,
  2722. &resolveAliasChains,
  2723. &mountFlags))
  2724. return NULL;
  2725. _err = ResolveAliasFileWithMountFlagsNoUI(&theSpec,
  2726. resolveAliasChains,
  2727. &targetIsFolder,
  2728. &wasAliased,
  2729. mountFlags);
  2730. if (_err != noErr) return PyMac_Error(_err);
  2731. _res = Py_BuildValue("O&bb",
  2732. FSSpec_New, &theSpec,
  2733. targetIsFolder,
  2734. wasAliased);
  2735. return _res;
  2736. }
  2737. #endif /* !__LP64__ */
  2738. static PyObject *File_FSNewAlias(PyObject *_self, PyObject *_args)
  2739. {
  2740. PyObject *_res = NULL;
  2741. OSErr _err;
  2742. FSRef fromFile__buf__;
  2743. FSRef *fromFile = &fromFile__buf__;
  2744. FSRef target;
  2745. AliasHandle inAlias;
  2746. if (!PyArg_ParseTuple(_args, "O&O&",
  2747. myPyMac_GetOptFSRefPtr, &fromFile,
  2748. FSRef_Convert, &target))
  2749. return NULL;
  2750. _err = FSNewAlias(fromFile,
  2751. &target,
  2752. &inAlias);
  2753. if (_err != noErr) return PyMac_Error(_err);
  2754. _res = Py_BuildValue("O&",
  2755. Alias_New, inAlias);
  2756. return _res;
  2757. }
  2758. static PyObject *File_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
  2759. {
  2760. PyObject *_res = NULL;
  2761. OSErr _err;
  2762. FSRef theRef;
  2763. Boolean resolveAliasChains;
  2764. Boolean targetIsFolder;
  2765. Boolean wasAliased;
  2766. unsigned long mountFlags;
  2767. if (!PyArg_ParseTuple(_args, "O&bl",
  2768. FSRef_Convert, &theRef,
  2769. &resolveAliasChains,
  2770. &mountFlags))
  2771. return NULL;
  2772. _err = FSResolveAliasFileWithMountFlags(&theRef,
  2773. resolveAliasChains,
  2774. &targetIsFolder,
  2775. &wasAliased,
  2776. mountFlags);
  2777. if (_err != noErr) return PyMac_Error(_err);
  2778. _res = Py_BuildValue("O&bb",
  2779. FSRef_New, &theRef,
  2780. targetIsFolder,
  2781. wasAliased);
  2782. return _res;
  2783. }
  2784. static PyObject *File_FSResolveAliasFile(PyObject *_self, PyObject *_args)
  2785. {
  2786. PyObject *_res = NULL;
  2787. OSErr _err;
  2788. FSRef theRef;
  2789. Boolean resolveAliasChains;
  2790. Boolean targetIsFolder;
  2791. Boolean wasAliased;
  2792. if (!PyArg_ParseTuple(_args, "O&b",
  2793. FSRef_Convert, &theRef,
  2794. &resolveAliasChains))
  2795. return NULL;
  2796. _err = FSResolveAliasFile(&theRef,
  2797. resolveAliasChains,
  2798. &targetIsFolder,
  2799. &wasAliased);
  2800. if (_err != noErr) return PyMac_Error(_err);
  2801. _res = Py_BuildValue("O&bb",
  2802. FSRef_New, &theRef,
  2803. targetIsFolder,
  2804. wasAliased);
  2805. return _res;
  2806. }
  2807. static PyObject *File_FSUpdateAlias(PyObject *_self, PyObject *_args)
  2808. {
  2809. PyObject *_res = NULL;
  2810. OSErr _err;
  2811. FSRef fromFile__buf__;
  2812. FSRef *fromFile = &fromFile__buf__;
  2813. FSRef target;
  2814. AliasHandle alias;
  2815. Boolean wasChanged;
  2816. if (!PyArg_ParseTuple(_args, "O&O&O&",
  2817. myPyMac_GetOptFSRefPtr, &fromFile,
  2818. FSRef_Convert, &target,
  2819. Alias_Convert, &alias))
  2820. return NULL;
  2821. _err = FSUpdateAlias(fromFile,
  2822. &target,
  2823. alias,
  2824. &wasChanged);
  2825. if (_err != noErr) return PyMac_Error(_err);
  2826. _res = Py_BuildValue("b",
  2827. wasChanged);
  2828. return _res;
  2829. }
  2830. static PyObject *File_pathname(PyObject *_self, PyObject *_args)
  2831. {
  2832. PyObject *_res = NULL;
  2833. PyObject *obj;
  2834. if (!PyArg_ParseTuple(_args, "O", &obj))
  2835. return NULL;
  2836. if (PyString_Check(obj)) {
  2837. Py_INCREF(obj);
  2838. return obj;
  2839. }
  2840. if (PyUnicode_Check(obj))
  2841. return PyUnicode_AsEncodedString(obj, "utf8", "strict");
  2842. _res = PyObject_CallMethod(obj, "as_pathname", NULL);
  2843. return _res;
  2844. }
  2845. static PyMethodDef File_methods[] = {
  2846. #ifndef __LP64__
  2847. {"UnmountVol", (PyCFunction)File_UnmountVol, 1,
  2848. PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
  2849. {"FlushVol", (PyCFunction)File_FlushVol, 1,
  2850. PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
  2851. {"HSetVol", (PyCFunction)File_HSetVol, 1,
  2852. PyDoc_STR("(Str63 volName, short vRefNum, long dirID) -> None")},
  2853. {"FSClose", (PyCFunction)File_FSClose, 1,
  2854. PyDoc_STR("(short refNum) -> None")},
  2855. {"Allocate", (PyCFunction)File_Allocate, 1,
  2856. PyDoc_STR("(short refNum) -> (long count)")},
  2857. {"GetEOF", (PyCFunction)File_GetEOF, 1,
  2858. PyDoc_STR("(short refNum) -> (long logEOF)")},
  2859. {"SetEOF", (PyCFunction)File_SetEOF, 1,
  2860. PyDoc_STR("(short refNum, long logEOF) -> None")},
  2861. {"GetFPos", (PyCFunction)File_GetFPos, 1,
  2862. PyDoc_STR("(short refNum) -> (long filePos)")},
  2863. {"SetFPos", (PyCFunction)File_SetFPos, 1,
  2864. PyDoc_STR("(short refNum, short posMode, long posOff) -> None")},
  2865. {"GetVRefNum", (PyCFunction)File_GetVRefNum, 1,
  2866. PyDoc_STR("(short fileRefNum) -> (short vRefNum)")},
  2867. {"HGetVol", (PyCFunction)File_HGetVol, 1,
  2868. PyDoc_STR("(StringPtr volName) -> (short vRefNum, long dirID)")},
  2869. {"HOpen", (PyCFunction)File_HOpen, 1,
  2870. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, SInt8 permission) -> (short refNum)")},
  2871. {"HOpenDF", (PyCFunction)File_HOpenDF, 1,
  2872. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, SInt8 permission) -> (short refNum)")},
  2873. {"HOpenRF", (PyCFunction)File_HOpenRF, 1,
  2874. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, SInt8 permission) -> (short refNum)")},
  2875. {"AllocContig", (PyCFunction)File_AllocContig, 1,
  2876. PyDoc_STR("(short refNum) -> (long count)")},
  2877. {"HCreate", (PyCFunction)File_HCreate, 1,
  2878. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, OSType creator, OSType fileType) -> None")},
  2879. {"DirCreate", (PyCFunction)File_DirCreate, 1,
  2880. PyDoc_STR("(short vRefNum, long parentDirID, Str255 directoryName) -> (long createdDirID)")},
  2881. {"HDelete", (PyCFunction)File_HDelete, 1,
  2882. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> None")},
  2883. {"HGetFInfo", (PyCFunction)File_HGetFInfo, 1,
  2884. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FInfo fndrInfo)")},
  2885. {"HSetFInfo", (PyCFunction)File_HSetFInfo, 1,
  2886. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, FInfo fndrInfo) -> None")},
  2887. {"HSetFLock", (PyCFunction)File_HSetFLock, 1,
  2888. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> None")},
  2889. {"HRstFLock", (PyCFunction)File_HRstFLock, 1,
  2890. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> None")},
  2891. {"HRename", (PyCFunction)File_HRename, 1,
  2892. PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, Str255 newName) -> None")},
  2893. {"CatMove", (PyCFunction)File_CatMove, 1,
  2894. PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, long newDirID, Str255 newName) -> None")},
  2895. {"FSMakeFSSpec", (PyCFunction)File_FSMakeFSSpec, 1,
  2896. PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FSSpec spec)")},
  2897. #endif /* !__LP64__*/
  2898. {"FSGetForkPosition", (PyCFunction)File_FSGetForkPosition, 1,
  2899. PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 position)")},
  2900. {"FSSetForkPosition", (PyCFunction)File_FSSetForkPosition, 1,
  2901. PyDoc_STR("(SInt16 forkRefNum, UInt16 positionMode, SInt64 positionOffset) -> None")},
  2902. {"FSGetForkSize", (PyCFunction)File_FSGetForkSize, 1,
  2903. PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 forkSize)")},
  2904. {"FSSetForkSize", (PyCFunction)File_FSSetForkSize, 1,
  2905. PyDoc_STR("(SInt16 forkRefNum, UInt16 positionMode, SInt64 positionOffset) -> None")},
  2906. {"FSAllocateFork", (PyCFunction)File_FSAllocateFork, 1,
  2907. PyDoc_STR("(SInt16 forkRefNum, FSAllocationFlags flags, UInt16 positionMode, SInt64 positionOffset, UInt64 requestCount) -> (UInt64 actualCount)")},
  2908. {"FSFlushFork", (PyCFunction)File_FSFlushFork, 1,
  2909. PyDoc_STR("(SInt16 forkRefNum) -> None")},
  2910. {"FSCloseFork", (PyCFunction)File_FSCloseFork, 1,
  2911. PyDoc_STR("(SInt16 forkRefNum) -> None")},
  2912. {"FSGetDataForkName", (PyCFunction)File_FSGetDataForkName, 1,
  2913. PyDoc_STR("() -> (HFSUniStr255 dataForkName)")},
  2914. {"FSGetResourceForkName", (PyCFunction)File_FSGetResourceForkName, 1,
  2915. PyDoc_STR("() -> (HFSUniStr255 resourceForkName)")},
  2916. {"FSPathMakeRef", (PyCFunction)File_FSPathMakeRef, 1,
  2917. PyDoc_STR("(UInt8 * path) -> (FSRef ref, Boolean isDirectory)")},
  2918. {"FNNotifyByPath", (PyCFunction)File_FNNotifyByPath, 1,
  2919. PyDoc_STR("(UInt8 * path, FNMessage message, OptionBits flags) -> None")},
  2920. {"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
  2921. PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
  2922. #ifndef __LP64__
  2923. {"NewAlias", (PyCFunction)File_NewAlias, 1,
  2924. PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
  2925. {"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
  2926. PyDoc_STR("(Buffer fullPath, Str32 zoneName, Str31 serverName) -> (AliasHandle alias)")},
  2927. {"ResolveAliasFile", (PyCFunction)File_ResolveAliasFile, 1,
  2928. PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
  2929. {"ResolveAliasFileWithMountFlags", (PyCFunction)File_ResolveAliasFileWithMountFlags, 1,
  2930. PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
  2931. {"UpdateAlias", (PyCFunction)File_UpdateAlias, 1,
  2932. PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
  2933. {"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
  2934. PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
  2935. #endif /* !__LP64__ */
  2936. {"FSNewAlias", (PyCFunction)File_FSNewAlias, 1,
  2937. PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
  2938. {"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
  2939. PyDoc_STR("(FSRef theRef, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
  2940. {"FSResolveAliasFile", (PyCFunction)File_FSResolveAliasFile, 1,
  2941. PyDoc_STR("(FSRef theRef, Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
  2942. {"FSUpdateAlias", (PyCFunction)File_FSUpdateAlias, 1,
  2943. PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
  2944. {"pathname", (PyCFunction)File_pathname, 1,
  2945. PyDoc_STR("(str|unicode|FSSpec|FSref) -> pathname")},
  2946. {NULL, NULL, 0}
  2947. };
  2948. #ifndef __LP64__
  2949. int
  2950. PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
  2951. {
  2952. Str255 path;
  2953. short refnum;
  2954. long parid;
  2955. OSErr err;
  2956. FSRef fsr;
  2957. if (FSSpec_Check(v)) {
  2958. *spec = ((FSSpecObject *)v)->ob_itself;
  2959. return 1;
  2960. }
  2961. if (PyArg_Parse(v, "(hlO&)",
  2962. &refnum, &parid, PyMac_GetStr255, &path)) {
  2963. err = FSMakeFSSpec(refnum, parid, path, spec);
  2964. if ( err && err != fnfErr ) {
  2965. PyMac_Error(err);
  2966. return 0;
  2967. }
  2968. return 1;
  2969. }
  2970. PyErr_Clear();
  2971. /* Otherwise we try to go via an FSRef. On OSX we go all the way,
  2972. ** on OS9 we accept only a real FSRef object
  2973. */
  2974. if ( PyMac_GetFSRef(v, &fsr) ) {
  2975. err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL);
  2976. if (err != noErr) {
  2977. PyMac_Error(err);
  2978. return 0;
  2979. }
  2980. return 1;
  2981. }
  2982. return 0;
  2983. }
  2984. #endif /* !__LP64__ */
  2985. int
  2986. PyMac_GetFSRef(PyObject *v, FSRef *fsr)
  2987. {
  2988. OSStatus err;
  2989. #ifndef __LP64__
  2990. FSSpec fss;
  2991. #endif /* !__LP64__ */
  2992. if (FSRef_Check(v)) {
  2993. *fsr = ((FSRefObject *)v)->ob_itself;
  2994. return 1;
  2995. }
  2996. /* On OSX we now try a pathname */
  2997. if ( PyString_Check(v) || PyUnicode_Check(v)) {
  2998. char *path = NULL;
  2999. if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
  3000. return 0;
  3001. if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
  3002. PyMac_Error(err);
  3003. PyMem_Free(path);
  3004. return !err;
  3005. }
  3006. /* XXXX Should try unicode here too */
  3007. #ifndef __LP64__
  3008. /* Otherwise we try to go via an FSSpec */
  3009. if (FSSpec_Check(v)) {
  3010. fss = ((FSSpecObject *)v)->ob_itself;
  3011. if ((err=FSpMakeFSRef(&fss, fsr)) == 0)
  3012. return 1;
  3013. PyMac_Error(err);
  3014. return 0;
  3015. }
  3016. #endif /* !__LP64__ */
  3017. PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
  3018. return 0;
  3019. }
  3020. #ifndef __LP64__
  3021. extern PyObject *
  3022. PyMac_BuildFSSpec(FSSpec *spec)
  3023. {
  3024. return FSSpec_New(spec);
  3025. }
  3026. #endif /* !__LP64__ */
  3027. extern PyObject *
  3028. PyMac_BuildFSRef(FSRef *spec)
  3029. {
  3030. return FSRef_New(spec);
  3031. }
  3032. void init_File(void)
  3033. {
  3034. PyObject *m;
  3035. PyObject *d;
  3036. #ifndef __LP64__
  3037. PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
  3038. PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
  3039. #endif /* !__LP64__ */
  3040. PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
  3041. PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
  3042. m = Py_InitModule("_File", File_methods);
  3043. d = PyModule_GetDict(m);
  3044. File_Error = PyMac_GetOSErrException();
  3045. if (File_Error == NULL ||
  3046. PyDict_SetItemString(d, "Error", File_Error) != 0)
  3047. return;
  3048. FSCatalogInfo_Type.ob_type = &PyType_Type;
  3049. if (PyType_Ready(&FSCatalogInfo_Type) < 0) return;
  3050. Py_INCREF(&FSCatalogInfo_Type);
  3051. PyModule_AddObject(m, "FSCatalogInfo", (PyObject *)&FSCatalogInfo_Type);
  3052. /* Backward-compatible name */
  3053. Py_INCREF(&FSCatalogInfo_Type);
  3054. PyModule_AddObject(m, "FSCatalogInfoType", (PyObject *)&FSCatalogInfo_Type);
  3055. #ifndef __LP64__
  3056. FInfo_Type.ob_type = &PyType_Type;
  3057. if (PyType_Ready(&FInfo_Type) < 0) return;
  3058. Py_INCREF(&FInfo_Type);
  3059. PyModule_AddObject(m, "FInfo", (PyObject *)&FInfo_Type);
  3060. /* Backward-compatible name */
  3061. Py_INCREF(&FInfo_Type);
  3062. PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
  3063. #endif /* !__LP64__ */
  3064. Alias_Type.ob_type = &PyType_Type;
  3065. if (PyType_Ready(&Alias_Type) < 0) return;
  3066. Py_INCREF(&Alias_Type);
  3067. PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
  3068. /* Backward-compatible name */
  3069. Py_INCREF(&Alias_Type);
  3070. PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
  3071. #ifndef __LP64__
  3072. FSSpec_Type.ob_type = &PyType_Type;
  3073. if (PyType_Ready(&FSSpec_Type) < 0) return;
  3074. Py_INCREF(&FSSpec_Type);
  3075. PyModule_AddObject(m, "FSSpec", (PyObject *)&FSSpec_Type);
  3076. /* Backward-compatible name */
  3077. Py_INCREF(&FSSpec_Type);
  3078. PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
  3079. #endif /* !__LP64__ */
  3080. FSRef_Type.ob_type = &PyType_Type;
  3081. if (PyType_Ready(&FSRef_Type) < 0) return;
  3082. Py_INCREF(&FSRef_Type);
  3083. PyModule_AddObject(m, "FSRef", (PyObject *)&FSRef_Type);
  3084. /* Backward-compatible name */
  3085. Py_INCREF(&FSRef_Type);
  3086. PyModule_AddObject(m, "FSRefType", (PyObject *)&FSRef_Type);
  3087. }
  3088. /* ======================== End module _File ======================== */