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