2
/* ========================== Module _File ========================== */
8
#include "pymactoolbox.h"
10
#ifndef HAVE_OSX105_SDK
11
typedef SInt16 FSIORefNum;
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"); \
22
#include <Carbon/Carbon.h>
24
#ifdef USE_TOOLBOX_OBJECT_GLUE
27
extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
28
extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
29
#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
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
38
#else /* !USE_TOOLBOX_OBJECT_GLUE */
41
extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
42
extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
45
extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
46
extern PyObject *PyMac_BuildFSRef(FSRef *spec);
48
#endif /* !USE_TOOLBOX_OBJECT_GLUE */
50
/* Forward declarations */
51
static PyObject *FSRef_New(FSRef *itself);
53
static PyObject *FInfo_New(FInfo *itself);
55
static PyObject *FSSpec_New(FSSpec *itself);
56
#define FSSpec_Convert PyMac_GetFSSpec
57
#endif /* !__LP64__ */
59
static PyObject *Alias_New(AliasHandle itself);
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);
67
** UTCDateTime records
70
UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr)
72
return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction);
76
UTCDateTime_New(UTCDateTime *ptr)
78
return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction);
82
** Optional fsspec and fsref pointers. None will pass NULL
86
myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
92
return PyMac_GetFSSpec(v, *spec);
94
#endif /* !__LP64__ */
97
myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
103
return PyMac_GetFSRef(v, *ref);
107
** Parse/generate objsect
110
PyMac_BuildHFSUniStr255(HFSUniStr255 *itself)
113
return Py_BuildValue("u#", itself->unicode, itself->length);
118
_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
124
err = FSpMakeFSRef(fss, &fsr);
126
/* FSSpecs can point to non-existing files, fsrefs can't. */
130
err = FSMakeFSSpec(fss->vRefNum, fss->parID,
131
(unsigned char*)"", &fss2);
134
err = FSpMakeFSRef(&fss2, &fsr);
137
err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len-1);
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...
145
tocopy = fss->name[0];
146
if ((strlen(path) + tocopy) >= len)
147
tocopy = len - strlen(path) - 1;
149
strncat(path, (char*)fss->name+1, tocopy);
154
err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len);
160
#endif /* !__LP64__ */
163
static PyObject *File_Error;
165
/* ------------------- Object type FSCatalogInfo -------------------- */
167
static PyTypeObject FSCatalogInfo_Type;
169
#define FSCatalogInfo_Check(x) ((x)->ob_type == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type))
171
typedef struct FSCatalogInfoObject {
173
FSCatalogInfo ob_itself;
174
} FSCatalogInfoObject;
176
static PyObject *FSCatalogInfo_New(FSCatalogInfo *itself)
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;
186
static int FSCatalogInfo_Convert(PyObject *v, FSCatalogInfo *p_itself)
188
if (!FSCatalogInfo_Check(v))
190
PyErr_SetString(PyExc_TypeError, "FSCatalogInfo required");
193
*p_itself = ((FSCatalogInfoObject *)v)->ob_itself;
197
static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
199
/* Cleanup of self->ob_itself goes here */
200
self->ob_type->tp_free((PyObject *)self);
203
static PyMethodDef FSCatalogInfo_methods[] = {
207
static PyObject *FSCatalogInfo_get_nodeFlags(FSCatalogInfoObject *self, void *closure)
209
return Py_BuildValue("H", self->ob_itself.nodeFlags);
212
static int FSCatalogInfo_set_nodeFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
214
return PyArg_Parse(v, "H", &self->ob_itself.nodeFlags)-1;
218
static PyObject *FSCatalogInfo_get_volume(FSCatalogInfoObject *self, void *closure)
220
return Py_BuildValue("h", self->ob_itself.volume);
223
static int FSCatalogInfo_set_volume(FSCatalogInfoObject *self, PyObject *v, void *closure)
225
return PyArg_Parse(v, "h", &self->ob_itself.volume)-1;
229
static PyObject *FSCatalogInfo_get_parentDirID(FSCatalogInfoObject *self, void *closure)
231
return Py_BuildValue("l", self->ob_itself.parentDirID);
234
static int FSCatalogInfo_set_parentDirID(FSCatalogInfoObject *self, PyObject *v, void *closure)
236
return PyArg_Parse(v, "l", &self->ob_itself.parentDirID)-1;
240
static PyObject *FSCatalogInfo_get_nodeID(FSCatalogInfoObject *self, void *closure)
242
return Py_BuildValue("l", self->ob_itself.nodeID);
245
static int FSCatalogInfo_set_nodeID(FSCatalogInfoObject *self, PyObject *v, void *closure)
247
return PyArg_Parse(v, "l", &self->ob_itself.nodeID)-1;
251
static PyObject *FSCatalogInfo_get_createDate(FSCatalogInfoObject *self, void *closure)
253
return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.createDate);
256
static int FSCatalogInfo_set_createDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
258
return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.createDate)-1;
262
static PyObject *FSCatalogInfo_get_contentModDate(FSCatalogInfoObject *self, void *closure)
264
return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.contentModDate);
267
static int FSCatalogInfo_set_contentModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
269
return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.contentModDate)-1;
273
static PyObject *FSCatalogInfo_get_attributeModDate(FSCatalogInfoObject *self, void *closure)
275
return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.attributeModDate);
278
static int FSCatalogInfo_set_attributeModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
280
return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.attributeModDate)-1;
284
static PyObject *FSCatalogInfo_get_accessDate(FSCatalogInfoObject *self, void *closure)
286
return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.accessDate);
289
static int FSCatalogInfo_set_accessDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
291
return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.accessDate)-1;
295
static PyObject *FSCatalogInfo_get_backupDate(FSCatalogInfoObject *self, void *closure)
297
return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.backupDate);
300
static int FSCatalogInfo_set_backupDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
302
return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.backupDate)-1;
306
static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
308
FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
309
return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
312
static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
320
FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
322
r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
326
info->userID = userID;
327
info->groupID = groupID;
328
info->userAccess = userAccess;
333
static PyObject *FSCatalogInfo_get_valence(FSCatalogInfoObject *self, void *closure)
335
return Py_BuildValue("l", self->ob_itself.valence);
338
static int FSCatalogInfo_set_valence(FSCatalogInfoObject *self, PyObject *v, void *closure)
340
return PyArg_Parse(v, "l", &self->ob_itself.valence)-1;
344
static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject *self, void *closure)
346
return Py_BuildValue("l", self->ob_itself.dataLogicalSize);
349
static int FSCatalogInfo_set_dataLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
351
return PyArg_Parse(v, "l", &self->ob_itself.dataLogicalSize)-1;
355
static PyObject *FSCatalogInfo_get_dataPhysicalSize(FSCatalogInfoObject *self, void *closure)
357
return Py_BuildValue("l", self->ob_itself.dataPhysicalSize);
360
static int FSCatalogInfo_set_dataPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
362
return PyArg_Parse(v, "l", &self->ob_itself.dataPhysicalSize)-1;
366
static PyObject *FSCatalogInfo_get_rsrcLogicalSize(FSCatalogInfoObject *self, void *closure)
368
return Py_BuildValue("l", self->ob_itself.rsrcLogicalSize);
371
static int FSCatalogInfo_set_rsrcLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
373
return PyArg_Parse(v, "l", &self->ob_itself.rsrcLogicalSize)-1;
377
static PyObject *FSCatalogInfo_get_rsrcPhysicalSize(FSCatalogInfoObject *self, void *closure)
379
return Py_BuildValue("l", self->ob_itself.rsrcPhysicalSize);
382
static int FSCatalogInfo_set_rsrcPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
384
return PyArg_Parse(v, "l", &self->ob_itself.rsrcPhysicalSize)-1;
388
static PyObject *FSCatalogInfo_get_sharingFlags(FSCatalogInfoObject *self, void *closure)
390
return Py_BuildValue("l", self->ob_itself.sharingFlags);
393
static int FSCatalogInfo_set_sharingFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
395
return PyArg_Parse(v, "l", &self->ob_itself.sharingFlags)-1;
399
static PyObject *FSCatalogInfo_get_userPrivileges(FSCatalogInfoObject *self, void *closure)
401
return Py_BuildValue("b", self->ob_itself.userPrivileges);
404
static int FSCatalogInfo_set_userPrivileges(FSCatalogInfoObject *self, PyObject *v, void *closure)
406
return PyArg_Parse(v, "b", &self->ob_itself.userPrivileges)-1;
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},
432
#define FSCatalogInfo_compare NULL
434
#define FSCatalogInfo_repr NULL
436
#define FSCatalogInfo_hash NULL
437
static int FSCatalogInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
439
static char *kw[] = {
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))
480
#define FSCatalogInfo_tp_alloc PyType_GenericAlloc
482
static PyObject *FSCatalogInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
486
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
487
memset(&((FSCatalogInfoObject *)self)->ob_itself, 0, sizeof(FSCatalogInfo));
491
#define FSCatalogInfo_tp_free PyObject_Del
494
static PyTypeObject FSCatalogInfo_Type = {
495
PyObject_HEAD_INIT(NULL)
497
"Carbon.File.FSCatalogInfo", /*tp_name*/
498
sizeof(FSCatalogInfoObject), /*tp_basicsize*/
501
(destructor) FSCatalogInfo_dealloc, /*tp_dealloc*/
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*/
513
PyObject_GenericGetAttr, /*tp_getattro*/
514
PyObject_GenericSetAttr, /*tp_setattro */
516
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
520
0, /*tp_richcompare*/
521
0, /*tp_weaklistoffset*/
524
FSCatalogInfo_methods, /* tp_methods */
526
FSCatalogInfo_getsetlist, /*tp_getset*/
532
FSCatalogInfo_tp_init, /* tp_init */
533
FSCatalogInfo_tp_alloc, /* tp_alloc */
534
FSCatalogInfo_tp_new, /* tp_new */
535
FSCatalogInfo_tp_free, /* tp_free */
538
/* ----------------- End object type FSCatalogInfo ------------------ */
541
/* ----------------------- Object type FInfo ------------------------ */
545
static PyTypeObject FInfo_Type;
547
#define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
549
typedef struct FInfoObject {
554
static PyObject *FInfo_New(FInfo *itself)
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;
564
static int FInfo_Convert(PyObject *v, FInfo *p_itself)
568
PyErr_SetString(PyExc_TypeError, "FInfo required");
571
*p_itself = ((FInfoObject *)v)->ob_itself;
575
static void FInfo_dealloc(FInfoObject *self)
577
/* Cleanup of self->ob_itself goes here */
578
self->ob_type->tp_free((PyObject *)self);
581
static PyMethodDef FInfo_methods[] = {
585
static PyObject *FInfo_get_Type(FInfoObject *self, void *closure)
587
return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdType);
590
static int FInfo_set_Type(FInfoObject *self, PyObject *v, void *closure)
592
return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdType)-1;
596
static PyObject *FInfo_get_Creator(FInfoObject *self, void *closure)
598
return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdCreator);
601
static int FInfo_set_Creator(FInfoObject *self, PyObject *v, void *closure)
603
return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;
607
static PyObject *FInfo_get_Flags(FInfoObject *self, void *closure)
609
return Py_BuildValue("H", self->ob_itself.fdFlags);
612
static int FInfo_set_Flags(FInfoObject *self, PyObject *v, void *closure)
614
return PyArg_Parse(v, "H", &self->ob_itself.fdFlags)-1;
618
static PyObject *FInfo_get_Location(FInfoObject *self, void *closure)
620
return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself.fdLocation);
623
static int FInfo_set_Location(FInfoObject *self, PyObject *v, void *closure)
625
return PyArg_Parse(v, "O&", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;
629
static PyObject *FInfo_get_Fldr(FInfoObject *self, void *closure)
631
return Py_BuildValue("h", self->ob_itself.fdFldr);
634
static int FInfo_set_Fldr(FInfoObject *self, PyObject *v, void *closure)
636
return PyArg_Parse(v, "h", &self->ob_itself.fdFldr)-1;
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},
650
#define FInfo_compare NULL
652
#define FInfo_repr NULL
654
#define FInfo_hash NULL
655
static int FInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
657
FInfo *itself = NULL;
658
static char *kw[] = {"itself", 0};
660
if (PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&", kw, FInfo_Convert, &itself))
662
if (itself) memcpy(&((FInfoObject *)_self)->ob_itself, itself, sizeof(FInfo));
668
#define FInfo_tp_alloc PyType_GenericAlloc
670
static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
674
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
675
memset(&((FInfoObject *)self)->ob_itself, 0, sizeof(FInfo));
679
#define FInfo_tp_free PyObject_Del
682
static PyTypeObject FInfo_Type = {
683
PyObject_HEAD_INIT(NULL)
685
"Carbon.File.FInfo", /*tp_name*/
686
sizeof(FInfoObject), /*tp_basicsize*/
689
(destructor) FInfo_dealloc, /*tp_dealloc*/
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*/
701
PyObject_GenericGetAttr, /*tp_getattro*/
702
PyObject_GenericSetAttr, /*tp_setattro */
704
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
708
0, /*tp_richcompare*/
709
0, /*tp_weaklistoffset*/
712
FInfo_methods, /* tp_methods */
714
FInfo_getsetlist, /*tp_getset*/
720
FInfo_tp_init, /* tp_init */
721
FInfo_tp_alloc, /* tp_alloc */
722
FInfo_tp_new, /* tp_new */
723
FInfo_tp_free, /* tp_free */
726
#endif /* !__LP64__ */
727
/* --------------------- End object type FInfo ---------------------- */
730
/* ----------------------- Object type Alias ------------------------ */
732
static PyTypeObject Alias_Type;
734
#define Alias_Check(x) ((x)->ob_type == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
736
typedef struct AliasObject {
738
AliasHandle ob_itself;
739
void (*ob_freeit)(AliasHandle ptr);
742
static PyObject *Alias_New(AliasHandle itself)
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;
753
static int Alias_Convert(PyObject *v, AliasHandle *p_itself)
757
PyErr_SetString(PyExc_TypeError, "Alias required");
760
*p_itself = ((AliasObject *)v)->ob_itself;
764
static void Alias_dealloc(AliasObject *self)
766
if (self->ob_freeit && self->ob_itself)
768
self->ob_freeit(self->ob_itself);
770
self->ob_itself = NULL;
771
self->ob_type->tp_free((PyObject *)self);
775
static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
777
PyObject *_res = NULL;
779
FSSpec fromFile__buf__;
780
FSSpec *fromFile = &fromFile__buf__;
783
if (!PyArg_ParseTuple(_args, "O&",
784
myPyMac_GetOptFSSpecPtr, &fromFile))
786
_err = ResolveAlias(fromFile,
790
if (_err != noErr) return PyMac_Error(_err);
791
_res = Py_BuildValue("O&b",
797
static PyObject *Alias_GetAliasInfo(AliasObject *_self, PyObject *_args)
799
PyObject *_res = NULL;
803
if (!PyArg_ParseTuple(_args, "h",
806
_err = GetAliasInfo(_self->ob_itself,
809
if (_err != noErr) return PyMac_Error(_err);
810
_res = Py_BuildValue("O&",
811
PyMac_BuildStr255, theString);
815
static PyObject *Alias_ResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
817
PyObject *_res = NULL;
819
FSSpec fromFile__buf__;
820
FSSpec *fromFile = &fromFile__buf__;
823
unsigned long mountFlags;
824
if (!PyArg_ParseTuple(_args, "O&l",
825
myPyMac_GetOptFSSpecPtr, &fromFile,
828
_err = ResolveAliasWithMountFlags(fromFile,
833
if (_err != noErr) return PyMac_Error(_err);
834
_res = Py_BuildValue("O&b",
840
static PyObject *Alias_FollowFinderAlias(AliasObject *_self, PyObject *_args)
842
PyObject *_res = NULL;
844
FSSpec fromFile__buf__;
845
FSSpec *fromFile = &fromFile__buf__;
849
if (!PyArg_ParseTuple(_args, "O&b",
850
myPyMac_GetOptFSSpecPtr, &fromFile,
853
_err = FollowFinderAlias(fromFile,
858
if (_err != noErr) return PyMac_Error(_err);
859
_res = Py_BuildValue("O&b",
864
#endif /* !__LP64__ */
866
static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
868
PyObject *_res = NULL;
870
FSRef fromFile__buf__;
871
FSRef *fromFile = &fromFile__buf__;
874
unsigned long mountFlags;
875
if (!PyArg_ParseTuple(_args, "O&l",
876
myPyMac_GetOptFSRefPtr, &fromFile,
879
_err = FSResolveAliasWithMountFlags(fromFile,
884
if (_err != noErr) return PyMac_Error(_err);
885
_res = Py_BuildValue("O&b",
891
static PyObject *Alias_FSResolveAlias(AliasObject *_self, PyObject *_args)
893
PyObject *_res = NULL;
895
FSRef fromFile__buf__;
896
FSRef *fromFile = &fromFile__buf__;
899
if (!PyArg_ParseTuple(_args, "O&",
900
myPyMac_GetOptFSRefPtr, &fromFile))
902
_err = FSResolveAlias(fromFile,
906
if (_err != noErr) return PyMac_Error(_err);
907
_res = Py_BuildValue("O&b",
913
static PyObject *Alias_FSFollowFinderAlias(AliasObject *_self, PyObject *_args)
915
PyObject *_res = NULL;
921
if (!PyArg_ParseTuple(_args, "b",
924
_err = FSFollowFinderAlias(&fromFile,
929
if (_err != noErr) return PyMac_Error(_err);
930
_res = Py_BuildValue("O&O&b",
931
FSRef_New, &fromFile,
937
static PyMethodDef Alias_methods[] = {
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)")},
957
static PyObject *Alias_get_data(AliasObject *self, void *closure)
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);
970
#define Alias_set_data NULL
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},
978
#define Alias_compare NULL
980
#define Alias_repr NULL
982
#define Alias_hash NULL
983
static int Alias_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
985
AliasHandle itself = NULL;
986
char *rawdata = NULL;
989
static char *kw[] = {"itself", "rawdata", 0};
991
if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen))
993
if (itself && rawdata)
995
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
998
if (!itself && !rawdata)
1000
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
1005
if ((h = NewHandle(rawdatalen)) == NULL)
1011
memcpy((char *)*h, rawdata, rawdatalen);
1013
((AliasObject *)_self)->ob_itself = (AliasHandle)h;
1016
((AliasObject *)_self)->ob_itself = itself;
1020
#define Alias_tp_alloc PyType_GenericAlloc
1022
static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
1026
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1027
((AliasObject *)self)->ob_itself = NULL;
1031
#define Alias_tp_free PyObject_Del
1034
static PyTypeObject Alias_Type = {
1035
PyObject_HEAD_INIT(NULL)
1037
"Carbon.File.Alias", /*tp_name*/
1038
sizeof(AliasObject), /*tp_basicsize*/
1041
(destructor) Alias_dealloc, /*tp_dealloc*/
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*/
1053
PyObject_GenericGetAttr, /*tp_getattro*/
1054
PyObject_GenericSetAttr, /*tp_setattro */
1056
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1060
0, /*tp_richcompare*/
1061
0, /*tp_weaklistoffset*/
1064
Alias_methods, /* tp_methods */
1066
Alias_getsetlist, /*tp_getset*/
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 */
1078
/* --------------------- End object type Alias ---------------------- */
1081
/* ----------------------- Object type FSSpec ----------------------- */
1084
static PyTypeObject FSSpec_Type;
1086
#define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type || PyObject_TypeCheck((x), &FSSpec_Type))
1088
typedef struct FSSpecObject {
1093
static PyObject *FSSpec_New(FSSpec *itself)
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;
1103
static void FSSpec_dealloc(FSSpecObject *self)
1105
/* Cleanup of self->ob_itself goes here */
1106
self->ob_type->tp_free((PyObject *)self);
1109
static PyObject *FSSpec_FSpOpenDF(FSSpecObject *_self, PyObject *_args)
1111
PyObject *_res = NULL;
1115
if (!PyArg_ParseTuple(_args, "b",
1118
_err = FSpOpenDF(&_self->ob_itself,
1121
if (_err != noErr) return PyMac_Error(_err);
1122
_res = Py_BuildValue("h",
1127
static PyObject *FSSpec_FSpOpenRF(FSSpecObject *_self, PyObject *_args)
1129
PyObject *_res = NULL;
1133
if (!PyArg_ParseTuple(_args, "b",
1136
_err = FSpOpenRF(&_self->ob_itself,
1139
if (_err != noErr) return PyMac_Error(_err);
1140
_res = Py_BuildValue("h",
1145
static PyObject *FSSpec_FSpCreate(FSSpecObject *_self, PyObject *_args)
1147
PyObject *_res = NULL;
1151
ScriptCode scriptTag;
1152
if (!PyArg_ParseTuple(_args, "O&O&h",
1153
PyMac_GetOSType, &creator,
1154
PyMac_GetOSType, &fileType,
1157
_err = FSpCreate(&_self->ob_itself,
1161
if (_err != noErr) return PyMac_Error(_err);
1167
static PyObject *FSSpec_FSpDirCreate(FSSpecObject *_self, PyObject *_args)
1169
PyObject *_res = NULL;
1171
ScriptCode scriptTag;
1173
if (!PyArg_ParseTuple(_args, "h",
1176
_err = FSpDirCreate(&_self->ob_itself,
1179
if (_err != noErr) return PyMac_Error(_err);
1180
_res = Py_BuildValue("l",
1185
static PyObject *FSSpec_FSpDelete(FSSpecObject *_self, PyObject *_args)
1187
PyObject *_res = NULL;
1189
if (!PyArg_ParseTuple(_args, ""))
1191
_err = FSpDelete(&_self->ob_itself);
1192
if (_err != noErr) return PyMac_Error(_err);
1198
static PyObject *FSSpec_FSpGetFInfo(FSSpecObject *_self, PyObject *_args)
1200
PyObject *_res = NULL;
1203
if (!PyArg_ParseTuple(_args, ""))
1205
_err = FSpGetFInfo(&_self->ob_itself,
1207
if (_err != noErr) return PyMac_Error(_err);
1208
_res = Py_BuildValue("O&",
1209
FInfo_New, &fndrInfo);
1213
static PyObject *FSSpec_FSpSetFInfo(FSSpecObject *_self, PyObject *_args)
1215
PyObject *_res = NULL;
1218
if (!PyArg_ParseTuple(_args, "O&",
1219
FInfo_Convert, &fndrInfo))
1221
_err = FSpSetFInfo(&_self->ob_itself,
1223
if (_err != noErr) return PyMac_Error(_err);
1229
static PyObject *FSSpec_FSpSetFLock(FSSpecObject *_self, PyObject *_args)
1231
PyObject *_res = NULL;
1233
if (!PyArg_ParseTuple(_args, ""))
1235
_err = FSpSetFLock(&_self->ob_itself);
1236
if (_err != noErr) return PyMac_Error(_err);
1242
static PyObject *FSSpec_FSpRstFLock(FSSpecObject *_self, PyObject *_args)
1244
PyObject *_res = NULL;
1246
if (!PyArg_ParseTuple(_args, ""))
1248
_err = FSpRstFLock(&_self->ob_itself);
1249
if (_err != noErr) return PyMac_Error(_err);
1255
static PyObject *FSSpec_FSpRename(FSSpecObject *_self, PyObject *_args)
1257
PyObject *_res = NULL;
1260
if (!PyArg_ParseTuple(_args, "O&",
1261
PyMac_GetStr255, newName))
1263
_err = FSpRename(&_self->ob_itself,
1265
if (_err != noErr) return PyMac_Error(_err);
1271
static PyObject *FSSpec_FSpCatMove(FSSpecObject *_self, PyObject *_args)
1273
PyObject *_res = NULL;
1276
if (!PyArg_ParseTuple(_args, "O&",
1277
FSSpec_Convert, &dest))
1279
_err = FSpCatMove(&_self->ob_itself,
1281
if (_err != noErr) return PyMac_Error(_err);
1287
static PyObject *FSSpec_FSpExchangeFiles(FSSpecObject *_self, PyObject *_args)
1289
PyObject *_res = NULL;
1292
if (!PyArg_ParseTuple(_args, "O&",
1293
FSSpec_Convert, &dest))
1295
_err = FSpExchangeFiles(&_self->ob_itself,
1297
if (_err != noErr) return PyMac_Error(_err);
1303
static PyObject *FSSpec_FSpMakeFSRef(FSSpecObject *_self, PyObject *_args)
1305
PyObject *_res = NULL;
1308
if (!PyArg_ParseTuple(_args, ""))
1310
_err = FSpMakeFSRef(&_self->ob_itself,
1312
if (_err != noErr) return PyMac_Error(_err);
1313
_res = Py_BuildValue("O&",
1314
FSRef_New, &newRef);
1318
static PyObject *FSSpec_NewAliasMinimal(FSSpecObject *_self, PyObject *_args)
1320
PyObject *_res = NULL;
1323
if (!PyArg_ParseTuple(_args, ""))
1325
_err = NewAliasMinimal(&_self->ob_itself,
1327
if (_err != noErr) return PyMac_Error(_err);
1328
_res = Py_BuildValue("O&",
1333
static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
1335
PyObject *_res = NULL;
1337
Boolean aliasFileFlag;
1339
if (!PyArg_ParseTuple(_args, ""))
1341
_err = IsAliasFile(&_self->ob_itself,
1344
if (_err != noErr) return PyMac_Error(_err);
1345
_res = Py_BuildValue("bb",
1351
static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
1353
PyObject *_res = NULL;
1358
if (!PyArg_ParseTuple(_args, ""))
1360
err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
1365
_res = PyString_FromString(strbuf);
1370
static PyObject *FSSpec_as_tuple(FSSpecObject *_self, PyObject *_args)
1372
PyObject *_res = NULL;
1374
if (!PyArg_ParseTuple(_args, ""))
1376
_res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID,
1377
&_self->ob_itself.name[1], _self->ob_itself.name[0]);
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)")},
1420
static PyObject *FSSpec_get_data(FSSpecObject *self, void *closure)
1422
return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
1425
#define FSSpec_set_data NULL
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},
1433
#define FSSpec_compare NULL
1435
static PyObject * FSSpec_repr(FSSpecObject *self)
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);
1446
#define FSSpec_hash NULL
1447
static int FSSpec_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
1450
char *rawdata = NULL;
1452
static char *kw[] = {"itself", "rawdata", 0};
1454
if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
1458
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
1463
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
1468
if (rawdatalen != sizeof(FSSpec))
1470
PyErr_SetString(PyExc_TypeError, "FSSpec rawdata incorrect size");
1473
memcpy(&((FSSpecObject *)_self)->ob_itself, rawdata, rawdatalen);
1476
if (PyMac_GetFSSpec(v, &((FSSpecObject *)_self)->ob_itself)) return 0;
1480
#define FSSpec_tp_alloc PyType_GenericAlloc
1482
static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
1486
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1487
memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpec));
1491
#define FSSpec_tp_free PyObject_Del
1494
static PyTypeObject FSSpec_Type = {
1495
PyObject_HEAD_INIT(NULL)
1497
"Carbon.File.FSSpec", /*tp_name*/
1498
sizeof(FSSpecObject), /*tp_basicsize*/
1501
(destructor) FSSpec_dealloc, /*tp_dealloc*/
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*/
1513
PyObject_GenericGetAttr, /*tp_getattro*/
1514
PyObject_GenericSetAttr, /*tp_setattro */
1516
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1520
0, /*tp_richcompare*/
1521
0, /*tp_weaklistoffset*/
1524
FSSpec_methods, /* tp_methods */
1526
FSSpec_getsetlist, /*tp_getset*/
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 */
1538
#endif /* !__LP64__ */
1539
/* --------------------- End object type FSSpec --------------------- */
1542
/* ----------------------- Object type FSRef ------------------------ */
1544
static PyTypeObject FSRef_Type;
1546
#define FSRef_Check(x) ((x)->ob_type == &FSRef_Type || PyObject_TypeCheck((x), &FSRef_Type))
1548
typedef struct FSRefObject {
1553
static PyObject *FSRef_New(FSRef *itself)
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;
1563
static void FSRef_dealloc(FSRefObject *self)
1565
/* Cleanup of self->ob_itself goes here */
1566
self->ob_type->tp_free((PyObject *)self);
1569
static PyObject *FSRef_FSMakeFSRefUnicode(FSRefObject *_self, PyObject *_args)
1571
PyObject *_res = NULL;
1573
UniChar *nameLength__in__;
1574
UniCharCount nameLength__len__;
1575
int nameLength__in_len__;
1576
TextEncoding textEncodingHint;
1578
if (!PyArg_ParseTuple(_args, "u#l",
1579
&nameLength__in__, &nameLength__in_len__,
1582
nameLength__len__ = nameLength__in_len__;
1583
_err = FSMakeFSRefUnicode(&_self->ob_itself,
1584
nameLength__len__, nameLength__in__,
1587
if (_err != noErr) return PyMac_Error(_err);
1588
_res = Py_BuildValue("O&",
1589
FSRef_New, &newRef);
1593
static PyObject *FSRef_FSCompareFSRefs(FSRefObject *_self, PyObject *_args)
1595
PyObject *_res = NULL;
1598
if (!PyArg_ParseTuple(_args, "O&",
1599
FSRef_Convert, &ref2))
1601
_err = FSCompareFSRefs(&_self->ob_itself,
1603
if (_err != noErr) return PyMac_Error(_err);
1609
static PyObject *FSRef_FSCreateFileUnicode(FSRefObject *_self, PyObject *_args)
1611
PyObject *_res = NULL;
1613
UniChar *nameLength__in__;
1614
UniCharCount nameLength__len__;
1615
int nameLength__in_len__;
1616
FSCatalogInfoBitmap whichInfo;
1617
FSCatalogInfo catalogInfo;
1622
if (!PyArg_ParseTuple(_args, "u#lO&",
1623
&nameLength__in__, &nameLength__in_len__,
1625
FSCatalogInfo_Convert, &catalogInfo))
1627
nameLength__len__ = nameLength__in_len__;
1628
_err = FSCreateFileUnicode(&_self->ob_itself,
1629
nameLength__len__, nameLength__in__,
1635
#else /* __LP64__ */
1637
#endif /* __LP64__*/
1639
if (_err != noErr) return PyMac_Error(_err);
1642
_res = Py_BuildValue("O&O&",
1644
FSSpec_New, &newSpec);
1645
#else /* __LP64__ */
1646
_res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
1647
#endif /* __LP64__ */
1652
static PyObject *FSRef_FSCreateDirectoryUnicode(FSRefObject *_self, PyObject *_args)
1654
PyObject *_res = NULL;
1656
UniChar *nameLength__in__;
1657
UniCharCount nameLength__len__;
1658
int nameLength__in_len__;
1659
FSCatalogInfoBitmap whichInfo;
1660
FSCatalogInfo catalogInfo;
1664
#endif /* !__LP64__ */
1666
if (!PyArg_ParseTuple(_args, "u#lO&",
1667
&nameLength__in__, &nameLength__in_len__,
1669
FSCatalogInfo_Convert, &catalogInfo))
1671
nameLength__len__ = nameLength__in_len__;
1672
_err = FSCreateDirectoryUnicode(&_self->ob_itself,
1673
nameLength__len__, nameLength__in__,
1679
#else /* !__LP64__ */
1681
#endif /* !__LP64__ */
1683
if (_err != noErr) return PyMac_Error(_err);
1686
_res = Py_BuildValue("O&O&l",
1688
FSSpec_New, &newSpec,
1690
#else /* __LP64__ */
1691
_res = Py_BuildValue("O&Ol",
1695
#endif /* __LP64__ */
1699
static PyObject *FSRef_FSDeleteObject(FSRefObject *_self, PyObject *_args)
1701
PyObject *_res = NULL;
1703
if (!PyArg_ParseTuple(_args, ""))
1705
_err = FSDeleteObject(&_self->ob_itself);
1706
if (_err != noErr) return PyMac_Error(_err);
1712
static PyObject *FSRef_FSMoveObject(FSRefObject *_self, PyObject *_args)
1714
PyObject *_res = NULL;
1716
FSRef destDirectory;
1718
if (!PyArg_ParseTuple(_args, "O&",
1719
FSRef_Convert, &destDirectory))
1721
_err = FSMoveObject(&_self->ob_itself,
1724
if (_err != noErr) return PyMac_Error(_err);
1725
_res = Py_BuildValue("O&",
1726
FSRef_New, &newRef);
1730
static PyObject *FSRef_FSExchangeObjects(FSRefObject *_self, PyObject *_args)
1732
PyObject *_res = NULL;
1735
if (!PyArg_ParseTuple(_args, "O&",
1736
FSRef_Convert, &destRef))
1738
_err = FSExchangeObjects(&_self->ob_itself,
1740
if (_err != noErr) return PyMac_Error(_err);
1746
static PyObject *FSRef_FSRenameUnicode(FSRefObject *_self, PyObject *_args)
1748
PyObject *_res = NULL;
1750
UniChar *nameLength__in__;
1751
UniCharCount nameLength__len__;
1752
int nameLength__in_len__;
1753
TextEncoding textEncodingHint;
1755
if (!PyArg_ParseTuple(_args, "u#l",
1756
&nameLength__in__, &nameLength__in_len__,
1759
nameLength__len__ = nameLength__in_len__;
1760
_err = FSRenameUnicode(&_self->ob_itself,
1761
nameLength__len__, nameLength__in__,
1764
if (_err != noErr) return PyMac_Error(_err);
1765
_res = Py_BuildValue("O&",
1766
FSRef_New, &newRef);
1770
static PyObject *FSRef_FSGetCatalogInfo(FSRefObject *_self, PyObject *_args)
1772
PyObject *_res = NULL;
1774
FSCatalogInfoBitmap whichInfo;
1775
FSCatalogInfo catalogInfo;
1776
HFSUniStr255 outName;
1779
#endif /* !__LP64__ */
1781
if (!PyArg_ParseTuple(_args, "l",
1784
_err = FSGetCatalogInfo(&_self->ob_itself,
1790
#else /* __LP64__ */
1792
#endif /* __LP64__ */
1794
if (_err != noErr) return PyMac_Error(_err);
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,
1807
FSRef_New, &parentRef);
1808
#endif /* __LP64__ */
1812
static PyObject *FSRef_FSSetCatalogInfo(FSRefObject *_self, PyObject *_args)
1814
PyObject *_res = NULL;
1816
FSCatalogInfoBitmap whichInfo;
1817
FSCatalogInfo catalogInfo;
1818
if (!PyArg_ParseTuple(_args, "lO&",
1820
FSCatalogInfo_Convert, &catalogInfo))
1822
_err = FSSetCatalogInfo(&_self->ob_itself,
1825
if (_err != noErr) return PyMac_Error(_err);
1831
static PyObject *FSRef_FSCreateFork(FSRefObject *_self, PyObject *_args)
1833
PyObject *_res = NULL;
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__))
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);
1850
static PyObject *FSRef_FSDeleteFork(FSRefObject *_self, PyObject *_args)
1852
PyObject *_res = NULL;
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__))
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);
1869
static PyObject *FSRef_FSOpenFork(FSRefObject *_self, PyObject *_args)
1871
PyObject *_res = NULL;
1873
UniChar *forkNameLength__in__;
1874
UniCharCount forkNameLength__len__;
1875
int forkNameLength__in_len__;
1877
FSIORefNum forkRefNum;
1878
if (!PyArg_ParseTuple(_args, "u#b",
1879
&forkNameLength__in__, &forkNameLength__in_len__,
1882
forkNameLength__len__ = forkNameLength__in_len__;
1883
_err = FSOpenFork(&_self->ob_itself,
1884
forkNameLength__len__, forkNameLength__in__,
1887
if (_err != noErr) return PyMac_Error(_err);
1888
_res = Py_BuildValue("h",
1893
static PyObject *FSRef_FNNotify(FSRefObject *_self, PyObject *_args)
1895
PyObject *_res = NULL;
1899
if (!PyArg_ParseTuple(_args, "ll",
1903
_err = FNNotify(&_self->ob_itself,
1906
if (_err != noErr) return PyMac_Error(_err);
1912
static PyObject *FSRef_FSNewAliasMinimal(FSRefObject *_self, PyObject *_args)
1914
PyObject *_res = NULL;
1916
AliasHandle inAlias;
1917
if (!PyArg_ParseTuple(_args, ""))
1919
_err = FSNewAliasMinimal(&_self->ob_itself,
1921
if (_err != noErr) return PyMac_Error(_err);
1922
_res = Py_BuildValue("O&",
1923
Alias_New, inAlias);
1927
static PyObject *FSRef_FSIsAliasFile(FSRefObject *_self, PyObject *_args)
1929
PyObject *_res = NULL;
1931
Boolean aliasFileFlag;
1933
if (!PyArg_ParseTuple(_args, ""))
1935
_err = FSIsAliasFile(&_self->ob_itself,
1938
if (_err != noErr) return PyMac_Error(_err);
1939
_res = Py_BuildValue("bb",
1945
static PyObject *FSRef_FSRefMakePath(FSRefObject *_self, PyObject *_args)
1947
PyObject *_res = NULL;
1950
#define MAXPATHNAME 1024
1951
UInt8 path[MAXPATHNAME];
1952
UInt32 maxPathSize = MAXPATHNAME;
1954
if (!PyArg_ParseTuple(_args, ""))
1956
_err = FSRefMakePath(&_self->ob_itself,
1959
if (_err != noErr) return PyMac_Error(_err);
1960
_res = Py_BuildValue("s", path);
1965
static PyObject *FSRef_as_pathname(FSRefObject *_self, PyObject *_args)
1967
PyObject *_res = NULL;
1969
if (!PyArg_ParseTuple(_args, ""))
1971
_res = FSRef_FSRefMakePath(_self, _args);
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")},
2016
static PyObject *FSRef_get_data(FSRefObject *self, void *closure)
2018
return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
2021
#define FSRef_set_data NULL
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},
2029
#define FSRef_compare NULL
2031
#define FSRef_repr NULL
2033
#define FSRef_hash NULL
2034
static int FSRef_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
2037
char *rawdata = NULL;
2039
static char *kw[] = {"itself", "rawdata", 0};
2041
if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
2045
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
2050
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
2055
if (rawdatalen != sizeof(FSRef))
2057
PyErr_SetString(PyExc_TypeError, "FSRef rawdata incorrect size");
2060
memcpy(&((FSRefObject *)_self)->ob_itself, rawdata, rawdatalen);
2063
if (PyMac_GetFSRef(v, &((FSRefObject *)_self)->ob_itself)) return 0;
2067
#define FSRef_tp_alloc PyType_GenericAlloc
2069
static PyObject *FSRef_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
2073
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
2074
memset(&((FSRefObject *)self)->ob_itself, 0, sizeof(FSRef));
2078
#define FSRef_tp_free PyObject_Del
2081
static PyTypeObject FSRef_Type = {
2082
PyObject_HEAD_INIT(NULL)
2084
"Carbon.File.FSRef", /*tp_name*/
2085
sizeof(FSRefObject), /*tp_basicsize*/
2088
(destructor) FSRef_dealloc, /*tp_dealloc*/
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*/
2100
PyObject_GenericGetAttr, /*tp_getattro*/
2101
PyObject_GenericSetAttr, /*tp_setattro */
2103
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
2107
0, /*tp_richcompare*/
2108
0, /*tp_weaklistoffset*/
2111
FSRef_methods, /* tp_methods */
2113
FSRef_getsetlist, /*tp_getset*/
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 */
2125
/* --------------------- End object type FSRef ---------------------- */
2128
static PyObject *File_UnmountVol(PyObject *_self, PyObject *_args)
2130
PyObject *_res = NULL;
2134
if (!PyArg_ParseTuple(_args, "O&h",
2135
PyMac_GetStr255, volName,
2138
_err = UnmountVol(volName,
2140
if (_err != noErr) return PyMac_Error(_err);
2146
static PyObject *File_FlushVol(PyObject *_self, PyObject *_args)
2148
PyObject *_res = NULL;
2152
if (!PyArg_ParseTuple(_args, "O&h",
2153
PyMac_GetStr255, volName,
2156
_err = FlushVol(volName,
2158
if (_err != noErr) return PyMac_Error(_err);
2164
static PyObject *File_HSetVol(PyObject *_self, PyObject *_args)
2166
PyObject *_res = NULL;
2171
if (!PyArg_ParseTuple(_args, "O&hl",
2172
PyMac_GetStr255, volName,
2176
_err = HSetVol(volName,
2179
if (_err != noErr) return PyMac_Error(_err);
2185
static PyObject *File_FSClose(PyObject *_self, PyObject *_args)
2187
PyObject *_res = NULL;
2190
if (!PyArg_ParseTuple(_args, "h",
2193
_err = FSClose(refNum);
2194
if (_err != noErr) return PyMac_Error(_err);
2200
static PyObject *File_Allocate(PyObject *_self, PyObject *_args)
2202
PyObject *_res = NULL;
2206
if (!PyArg_ParseTuple(_args, "h",
2209
_err = Allocate(refNum,
2211
if (_err != noErr) return PyMac_Error(_err);
2212
_res = Py_BuildValue("l",
2217
static PyObject *File_GetEOF(PyObject *_self, PyObject *_args)
2219
PyObject *_res = NULL;
2223
if (!PyArg_ParseTuple(_args, "h",
2226
_err = GetEOF(refNum,
2228
if (_err != noErr) return PyMac_Error(_err);
2229
_res = Py_BuildValue("l",
2234
static PyObject *File_SetEOF(PyObject *_self, PyObject *_args)
2236
PyObject *_res = NULL;
2240
if (!PyArg_ParseTuple(_args, "hl",
2244
_err = SetEOF(refNum,
2246
if (_err != noErr) return PyMac_Error(_err);
2252
static PyObject *File_GetFPos(PyObject *_self, PyObject *_args)
2254
PyObject *_res = NULL;
2258
if (!PyArg_ParseTuple(_args, "h",
2261
_err = GetFPos(refNum,
2263
if (_err != noErr) return PyMac_Error(_err);
2264
_res = Py_BuildValue("l",
2269
static PyObject *File_SetFPos(PyObject *_self, PyObject *_args)
2271
PyObject *_res = NULL;
2276
if (!PyArg_ParseTuple(_args, "hhl",
2281
_err = SetFPos(refNum,
2284
if (_err != noErr) return PyMac_Error(_err);
2290
static PyObject *File_GetVRefNum(PyObject *_self, PyObject *_args)
2292
PyObject *_res = NULL;
2296
if (!PyArg_ParseTuple(_args, "h",
2299
_err = GetVRefNum(fileRefNum,
2301
if (_err != noErr) return PyMac_Error(_err);
2302
_res = Py_BuildValue("h",
2307
static PyObject *File_HGetVol(PyObject *_self, PyObject *_args)
2309
PyObject *_res = NULL;
2314
if (!PyArg_ParseTuple(_args, "O&",
2315
PyMac_GetStr255, &volName))
2317
_err = HGetVol(volName,
2320
if (_err != noErr) return PyMac_Error(_err);
2321
_res = Py_BuildValue("hl",
2327
static PyObject *File_HOpen(PyObject *_self, PyObject *_args)
2329
PyObject *_res = NULL;
2336
if (!PyArg_ParseTuple(_args, "hlO&b",
2339
PyMac_GetStr255, fileName,
2342
_err = HOpen(vRefNum,
2347
if (_err != noErr) return PyMac_Error(_err);
2348
_res = Py_BuildValue("h",
2353
static PyObject *File_HOpenDF(PyObject *_self, PyObject *_args)
2355
PyObject *_res = NULL;
2362
if (!PyArg_ParseTuple(_args, "hlO&b",
2365
PyMac_GetStr255, fileName,
2368
_err = HOpenDF(vRefNum,
2373
if (_err != noErr) return PyMac_Error(_err);
2374
_res = Py_BuildValue("h",
2379
static PyObject *File_HOpenRF(PyObject *_self, PyObject *_args)
2381
PyObject *_res = NULL;
2388
if (!PyArg_ParseTuple(_args, "hlO&b",
2391
PyMac_GetStr255, fileName,
2394
_err = HOpenRF(vRefNum,
2399
if (_err != noErr) return PyMac_Error(_err);
2400
_res = Py_BuildValue("h",
2405
static PyObject *File_AllocContig(PyObject *_self, PyObject *_args)
2407
PyObject *_res = NULL;
2411
if (!PyArg_ParseTuple(_args, "h",
2414
_err = AllocContig(refNum,
2416
if (_err != noErr) return PyMac_Error(_err);
2417
_res = Py_BuildValue("l",
2422
static PyObject *File_HCreate(PyObject *_self, PyObject *_args)
2424
PyObject *_res = NULL;
2431
if (!PyArg_ParseTuple(_args, "hlO&O&O&",
2434
PyMac_GetStr255, fileName,
2435
PyMac_GetOSType, &creator,
2436
PyMac_GetOSType, &fileType))
2438
_err = HCreate(vRefNum,
2443
if (_err != noErr) return PyMac_Error(_err);
2449
static PyObject *File_DirCreate(PyObject *_self, PyObject *_args)
2451
PyObject *_res = NULL;
2455
Str255 directoryName;
2457
if (!PyArg_ParseTuple(_args, "hlO&",
2460
PyMac_GetStr255, directoryName))
2462
_err = DirCreate(vRefNum,
2466
if (_err != noErr) return PyMac_Error(_err);
2467
_res = Py_BuildValue("l",
2472
static PyObject *File_HDelete(PyObject *_self, PyObject *_args)
2474
PyObject *_res = NULL;
2479
if (!PyArg_ParseTuple(_args, "hlO&",
2482
PyMac_GetStr255, fileName))
2484
_err = HDelete(vRefNum,
2487
if (_err != noErr) return PyMac_Error(_err);
2493
static PyObject *File_HGetFInfo(PyObject *_self, PyObject *_args)
2495
PyObject *_res = NULL;
2501
if (!PyArg_ParseTuple(_args, "hlO&",
2504
PyMac_GetStr255, fileName))
2506
_err = HGetFInfo(vRefNum,
2510
if (_err != noErr) return PyMac_Error(_err);
2511
_res = Py_BuildValue("O&",
2512
FInfo_New, &fndrInfo);
2516
static PyObject *File_HSetFInfo(PyObject *_self, PyObject *_args)
2518
PyObject *_res = NULL;
2524
if (!PyArg_ParseTuple(_args, "hlO&O&",
2527
PyMac_GetStr255, fileName,
2528
FInfo_Convert, &fndrInfo))
2530
_err = HSetFInfo(vRefNum,
2534
if (_err != noErr) return PyMac_Error(_err);
2540
static PyObject *File_HSetFLock(PyObject *_self, PyObject *_args)
2542
PyObject *_res = NULL;
2547
if (!PyArg_ParseTuple(_args, "hlO&",
2550
PyMac_GetStr255, fileName))
2552
_err = HSetFLock(vRefNum,
2555
if (_err != noErr) return PyMac_Error(_err);
2561
static PyObject *File_HRstFLock(PyObject *_self, PyObject *_args)
2563
PyObject *_res = NULL;
2568
if (!PyArg_ParseTuple(_args, "hlO&",
2571
PyMac_GetStr255, fileName))
2573
_err = HRstFLock(vRefNum,
2576
if (_err != noErr) return PyMac_Error(_err);
2582
static PyObject *File_HRename(PyObject *_self, PyObject *_args)
2584
PyObject *_res = NULL;
2590
if (!PyArg_ParseTuple(_args, "hlO&O&",
2593
PyMac_GetStr255, oldName,
2594
PyMac_GetStr255, newName))
2596
_err = HRename(vRefNum,
2600
if (_err != noErr) return PyMac_Error(_err);
2606
static PyObject *File_CatMove(PyObject *_self, PyObject *_args)
2608
PyObject *_res = NULL;
2615
if (!PyArg_ParseTuple(_args, "hlO&lO&",
2618
PyMac_GetStr255, oldName,
2620
PyMac_GetStr255, newName))
2622
_err = CatMove(vRefNum,
2627
if (_err != noErr) return PyMac_Error(_err);
2633
static PyObject *File_FSMakeFSSpec(PyObject *_self, PyObject *_args)
2635
PyObject *_res = NULL;
2641
if (!PyArg_ParseTuple(_args, "hlO&",
2644
PyMac_GetStr255, fileName))
2646
_err = FSMakeFSSpec(vRefNum,
2650
if (_err != noErr) return PyMac_Error(_err);
2651
_res = Py_BuildValue("O&",
2655
#endif /* !__LP64__ */
2657
static PyObject *File_FSGetForkPosition(PyObject *_self, PyObject *_args)
2659
PyObject *_res = NULL;
2663
if (!PyArg_ParseTuple(_args, "h",
2666
_err = FSGetForkPosition(forkRefNum,
2668
if (_err != noErr) return PyMac_Error(_err);
2669
_res = Py_BuildValue("L",
2674
static PyObject *File_FSSetForkPosition(PyObject *_self, PyObject *_args)
2676
PyObject *_res = NULL;
2679
UInt16 positionMode;
2680
SInt64 positionOffset;
2681
if (!PyArg_ParseTuple(_args, "hHL",
2686
_err = FSSetForkPosition(forkRefNum,
2689
if (_err != noErr) return PyMac_Error(_err);
2695
static PyObject *File_FSGetForkSize(PyObject *_self, PyObject *_args)
2697
PyObject *_res = NULL;
2701
if (!PyArg_ParseTuple(_args, "h",
2704
_err = FSGetForkSize(forkRefNum,
2706
if (_err != noErr) return PyMac_Error(_err);
2707
_res = Py_BuildValue("L",
2712
static PyObject *File_FSSetForkSize(PyObject *_self, PyObject *_args)
2714
PyObject *_res = NULL;
2717
UInt16 positionMode;
2718
SInt64 positionOffset;
2719
if (!PyArg_ParseTuple(_args, "hHL",
2724
_err = FSSetForkSize(forkRefNum,
2727
if (_err != noErr) return PyMac_Error(_err);
2733
static PyObject *File_FSAllocateFork(PyObject *_self, PyObject *_args)
2735
PyObject *_res = NULL;
2738
FSAllocationFlags flags;
2739
UInt16 positionMode;
2740
SInt64 positionOffset;
2741
UInt64 requestCount;
2743
if (!PyArg_ParseTuple(_args, "hHHLL",
2750
_err = FSAllocateFork(forkRefNum,
2756
if (_err != noErr) return PyMac_Error(_err);
2757
_res = Py_BuildValue("L",
2762
static PyObject *File_FSFlushFork(PyObject *_self, PyObject *_args)
2764
PyObject *_res = NULL;
2767
if (!PyArg_ParseTuple(_args, "h",
2770
_err = FSFlushFork(forkRefNum);
2771
if (_err != noErr) return PyMac_Error(_err);
2777
static PyObject *File_FSCloseFork(PyObject *_self, PyObject *_args)
2779
PyObject *_res = NULL;
2782
if (!PyArg_ParseTuple(_args, "h",
2785
_err = FSCloseFork(forkRefNum);
2786
if (_err != noErr) return PyMac_Error(_err);
2792
static PyObject *File_FSGetDataForkName(PyObject *_self, PyObject *_args)
2794
PyObject *_res = NULL;
2796
HFSUniStr255 dataForkName;
2797
if (!PyArg_ParseTuple(_args, ""))
2799
_err = FSGetDataForkName(&dataForkName);
2800
if (_err != noErr) return PyMac_Error(_err);
2801
_res = Py_BuildValue("O&",
2802
PyMac_BuildHFSUniStr255, &dataForkName);
2806
static PyObject *File_FSGetResourceForkName(PyObject *_self, PyObject *_args)
2808
PyObject *_res = NULL;
2810
HFSUniStr255 resourceForkName;
2811
if (!PyArg_ParseTuple(_args, ""))
2813
_err = FSGetResourceForkName(&resourceForkName);
2814
if (_err != noErr) return PyMac_Error(_err);
2815
_res = Py_BuildValue("O&",
2816
PyMac_BuildHFSUniStr255, &resourceForkName);
2820
static PyObject *File_FSPathMakeRef(PyObject *_self, PyObject *_args)
2822
PyObject *_res = NULL;
2826
Boolean isDirectory;
2827
if (!PyArg_ParseTuple(_args, "s",
2830
_err = FSPathMakeRef(path,
2833
if (_err != noErr) return PyMac_Error(_err);
2834
_res = Py_BuildValue("O&b",
2840
static PyObject *File_FNNotifyByPath(PyObject *_self, PyObject *_args)
2842
PyObject *_res = NULL;
2847
if (!PyArg_ParseTuple(_args, "sll",
2852
_err = FNNotifyByPath(path,
2855
if (_err != noErr) return PyMac_Error(_err);
2861
static PyObject *File_FNNotifyAll(PyObject *_self, PyObject *_args)
2863
PyObject *_res = NULL;
2867
if (!PyArg_ParseTuple(_args, "ll",
2871
_err = FNNotifyAll(message,
2873
if (_err != noErr) return PyMac_Error(_err);
2880
static PyObject *File_NewAlias(PyObject *_self, PyObject *_args)
2882
PyObject *_res = NULL;
2884
FSSpec fromFile__buf__;
2885
FSSpec *fromFile = &fromFile__buf__;
2888
if (!PyArg_ParseTuple(_args, "O&O&",
2889
myPyMac_GetOptFSSpecPtr, &fromFile,
2890
FSSpec_Convert, &target))
2892
_err = NewAlias(fromFile,
2895
if (_err != noErr) return PyMac_Error(_err);
2896
_res = Py_BuildValue("O&",
2901
static PyObject *File_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args)
2903
PyObject *_res = NULL;
2905
char *fullPath__in__;
2906
int fullPath__len__;
2907
int fullPath__in_len__;
2911
if (!PyArg_ParseTuple(_args, "s#O&O&",
2912
&fullPath__in__, &fullPath__in_len__,
2913
PyMac_GetStr255, zoneName,
2914
PyMac_GetStr255, serverName))
2916
fullPath__len__ = fullPath__in_len__;
2917
_err = NewAliasMinimalFromFullPath(fullPath__len__, fullPath__in__,
2921
if (_err != noErr) return PyMac_Error(_err);
2922
_res = Py_BuildValue("O&",
2927
static PyObject *File_ResolveAliasFile(PyObject *_self, PyObject *_args)
2929
PyObject *_res = NULL;
2932
Boolean resolveAliasChains;
2933
Boolean targetIsFolder;
2935
if (!PyArg_ParseTuple(_args, "O&b",
2936
FSSpec_Convert, &theSpec,
2937
&resolveAliasChains))
2939
_err = ResolveAliasFile(&theSpec,
2943
if (_err != noErr) return PyMac_Error(_err);
2944
_res = Py_BuildValue("O&bb",
2945
FSSpec_New, &theSpec,
2951
static PyObject *File_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
2953
PyObject *_res = NULL;
2956
Boolean resolveAliasChains;
2957
Boolean targetIsFolder;
2959
unsigned long mountFlags;
2960
if (!PyArg_ParseTuple(_args, "O&bl",
2961
FSSpec_Convert, &theSpec,
2962
&resolveAliasChains,
2965
_err = ResolveAliasFileWithMountFlags(&theSpec,
2970
if (_err != noErr) return PyMac_Error(_err);
2971
_res = Py_BuildValue("O&bb",
2972
FSSpec_New, &theSpec,
2978
static PyObject *File_UpdateAlias(PyObject *_self, PyObject *_args)
2980
PyObject *_res = NULL;
2982
FSSpec fromFile__buf__;
2983
FSSpec *fromFile = &fromFile__buf__;
2987
if (!PyArg_ParseTuple(_args, "O&O&O&",
2988
myPyMac_GetOptFSSpecPtr, &fromFile,
2989
FSSpec_Convert, &target,
2990
Alias_Convert, &alias))
2992
_err = UpdateAlias(fromFile,
2996
if (_err != noErr) return PyMac_Error(_err);
2997
_res = Py_BuildValue("b",
3002
static PyObject *File_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args)
3004
PyObject *_res = NULL;
3007
Boolean resolveAliasChains;
3008
Boolean targetIsFolder;
3010
unsigned long mountFlags;
3011
if (!PyArg_ParseTuple(_args, "O&bl",
3012
FSSpec_Convert, &theSpec,
3013
&resolveAliasChains,
3016
_err = ResolveAliasFileWithMountFlagsNoUI(&theSpec,
3021
if (_err != noErr) return PyMac_Error(_err);
3022
_res = Py_BuildValue("O&bb",
3023
FSSpec_New, &theSpec,
3028
#endif /* !__LP64__ */
3030
static PyObject *File_FSNewAlias(PyObject *_self, PyObject *_args)
3032
PyObject *_res = NULL;
3034
FSRef fromFile__buf__;
3035
FSRef *fromFile = &fromFile__buf__;
3037
AliasHandle inAlias;
3038
if (!PyArg_ParseTuple(_args, "O&O&",
3039
myPyMac_GetOptFSRefPtr, &fromFile,
3040
FSRef_Convert, &target))
3042
_err = FSNewAlias(fromFile,
3045
if (_err != noErr) return PyMac_Error(_err);
3046
_res = Py_BuildValue("O&",
3047
Alias_New, inAlias);
3051
static PyObject *File_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
3053
PyObject *_res = NULL;
3056
Boolean resolveAliasChains;
3057
Boolean targetIsFolder;
3059
unsigned long mountFlags;
3060
if (!PyArg_ParseTuple(_args, "O&bl",
3061
FSRef_Convert, &theRef,
3062
&resolveAliasChains,
3065
_err = FSResolveAliasFileWithMountFlags(&theRef,
3070
if (_err != noErr) return PyMac_Error(_err);
3071
_res = Py_BuildValue("O&bb",
3078
static PyObject *File_FSResolveAliasFile(PyObject *_self, PyObject *_args)
3080
PyObject *_res = NULL;
3083
Boolean resolveAliasChains;
3084
Boolean targetIsFolder;
3086
if (!PyArg_ParseTuple(_args, "O&b",
3087
FSRef_Convert, &theRef,
3088
&resolveAliasChains))
3090
_err = FSResolveAliasFile(&theRef,
3094
if (_err != noErr) return PyMac_Error(_err);
3095
_res = Py_BuildValue("O&bb",
3102
static PyObject *File_FSUpdateAlias(PyObject *_self, PyObject *_args)
3104
PyObject *_res = NULL;
3106
FSRef fromFile__buf__;
3107
FSRef *fromFile = &fromFile__buf__;
3111
if (!PyArg_ParseTuple(_args, "O&O&O&",
3112
myPyMac_GetOptFSRefPtr, &fromFile,
3113
FSRef_Convert, &target,
3114
Alias_Convert, &alias))
3116
_err = FSUpdateAlias(fromFile,
3120
if (_err != noErr) return PyMac_Error(_err);
3121
_res = Py_BuildValue("b",
3126
static PyObject *File_pathname(PyObject *_self, PyObject *_args)
3128
PyObject *_res = NULL;
3132
if (!PyArg_ParseTuple(_args, "O", &obj))
3134
if (PyString_Check(obj)) {
3138
if (PyUnicode_Check(obj))
3139
return PyUnicode_AsEncodedString(obj, "utf8", "strict");
3140
_res = PyObject_CallMethod(obj, "as_pathname", NULL);
3145
static PyMethodDef File_methods[] = {
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")},
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")},
3252
PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
3260
if (FSSpec_Check(v)) {
3261
*spec = ((FSSpecObject *)v)->ob_itself;
3265
if (PyArg_Parse(v, "(hlO&)",
3266
&refnum, &parid, PyMac_GetStr255, &path)) {
3267
err = FSMakeFSSpec(refnum, parid, path, spec);
3268
if ( err && err != fnfErr ) {
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
3278
if ( PyMac_GetFSRef(v, &fsr) ) {
3279
err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL);
3288
#endif /* !__LP64__ */
3291
PyMac_GetFSRef(PyObject *v, FSRef *fsr)
3296
#endif /* !__LP64__ */
3298
if (FSRef_Check(v)) {
3299
*fsr = ((FSRefObject *)v)->ob_itself;
3303
/* On OSX we now try a pathname */
3304
if ( PyString_Check(v) || PyUnicode_Check(v)) {
3306
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
3308
if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
3313
/* XXXX Should try unicode here too */
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)
3324
#endif /* !__LP64__ */
3326
PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
3332
PyMac_BuildFSSpec(FSSpec *spec)
3334
return FSSpec_New(spec);
3336
#endif /* !__LP64__ */
3339
PyMac_BuildFSRef(FSRef *spec)
3341
return FSRef_New(spec);
3345
void init_File(void)
3352
PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
3353
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
3354
#endif /* !__LP64__ */
3356
PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
3357
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
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)
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);
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);
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);
3409
/* ======================== End module _File ======================== */