summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-12-15 19:55:07 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-12-15 19:55:07 (GMT)
commite3a1c8f8756904e42ce3551db6a4fe5f40c97910 (patch)
tree317e7c8ad2843b4e382e172e1b49df55d0cbb0c8 /Mac
parentbbfd859521073e1e399f91b78016d621a78e60d1 (diff)
downloadcpython-e3a1c8f8756904e42ce3551db6a4fe5f40c97910.zip
cpython-e3a1c8f8756904e42ce3551db6a4fe5f40c97910.tar.gz
cpython-e3a1c8f8756904e42ce3551db6a4fe5f40c97910.tar.bz2
Combined alias and file into a single module. This is the only reasonable
way to get various alias creation routines as methods of FSSpec or FSRef objects (which is the logical thing, from a Python POV). Also started on the code that will contain all the macfs functionality, so macfs can becode a Python module, to be used mainly for backward compatibility.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Modules/alias/_Aliasmodule.c702
-rw-r--r--Mac/Modules/alias/aliasscan.py71
-rw-r--r--Mac/Modules/alias/aliassupport.py118
-rw-r--r--Mac/Modules/file/_Filemodule.c1978
-rw-r--r--Mac/Modules/file/filescan.py40
-rw-r--r--Mac/Modules/file/filesupport.py303
6 files changed, 1742 insertions, 1470 deletions
diff --git a/Mac/Modules/alias/_Aliasmodule.c b/Mac/Modules/alias/_Aliasmodule.c
deleted file mode 100644
index a35d5d0..0000000
--- a/Mac/Modules/alias/_Aliasmodule.c
+++ /dev/null
@@ -1,702 +0,0 @@
-
-/* ========================= Module _Alias ========================== */
-
-#include "Python.h"
-
-
-
-#ifdef _WIN32
-#include "pywintoolbox.h"
-#else
-#include "macglue.h"
-#include "pymactoolbox.h"
-#endif
-
-/* Macro to test whether a weak-loaded CFM function exists */
-#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
- }} while(0)
-
-
-#ifdef WITHOUT_FRAMEWORKS
-#include <Files.h>
-#else
-#include <Carbon/Carbon.h>
-#endif
-
-static PyObject *Alias_Error;
-
-/* ----------------------- Object type Alias ------------------------ */
-
-PyTypeObject Alias_Type;
-
-#define AliasObj_Check(x) ((x)->ob_type == &Alias_Type)
-
-typedef struct AliasObject {
- PyObject_HEAD
- AliasHandle ob_itself;
- void (*ob_freeit)(AliasHandle ptr);
-} AliasObject;
-
-PyObject *AliasObj_New(AliasHandle itself)
-{
- AliasObject *it;
- if (itself == NULL) return PyMac_Error(resNotFound);
- it = PyObject_NEW(AliasObject, &Alias_Type);
- if (it == NULL) return NULL;
- it->ob_itself = itself;
- it->ob_freeit = NULL;
- return (PyObject *)it;
-}
-int AliasObj_Convert(PyObject *v, AliasHandle *p_itself)
-{
- if (!AliasObj_Check(v))
- {
- PyErr_SetString(PyExc_TypeError, "Alias required");
- return 0;
- }
- *p_itself = ((AliasObject *)v)->ob_itself;
- return 1;
-}
-
-static void AliasObj_dealloc(AliasObject *self)
-{
- if (self->ob_freeit && self->ob_itself)
- {
- self->ob_freeit(self->ob_itself);
- }
- self->ob_itself = NULL;
- PyObject_Del(self);
-}
-
-static PyObject *AliasObj_GetAliasInfo(AliasObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- AliasInfoType index;
- Str63 theString;
- if (!PyArg_ParseTuple(_args, "h",
- &index))
- return NULL;
- _err = GetAliasInfo(_self->ob_itself,
- index,
- theString);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildStr255, theString);
- return _res;
-}
-
-static PyMethodDef AliasObj_methods[] = {
- {"GetAliasInfo", (PyCFunction)AliasObj_GetAliasInfo, 1,
- PyDoc_STR("(AliasInfoType index) -> (Str63 theString)")},
- {NULL, NULL, 0}
-};
-
-#define AliasObj_getsetlist NULL
-
-
-#define AliasObj_compare NULL
-
-#define AliasObj_repr NULL
-
-#define AliasObj_hash NULL
-#define AliasObj_tp_init 0
-
-#define AliasObj_tp_alloc PyType_GenericAlloc
-
-static PyObject *AliasObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *self;
- AliasHandle itself;
- char *kw[] = {"itself", 0};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, AliasObj_Convert, &itself)) return NULL;
- if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
- ((AliasObject *)self)->ob_itself = itself;
- return self;
-}
-
-#define AliasObj_tp_free PyObject_Del
-
-
-PyTypeObject Alias_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "_Alias.Alias", /*tp_name*/
- sizeof(AliasObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor) AliasObj_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)0, /*tp_getattr*/
- (setattrfunc)0, /*tp_setattr*/
- (cmpfunc) AliasObj_compare, /*tp_compare*/
- (reprfunc) AliasObj_repr, /*tp_repr*/
- (PyNumberMethods *)0, /* tp_as_number */
- (PySequenceMethods *)0, /* tp_as_sequence */
- (PyMappingMethods *)0, /* tp_as_mapping */
- (hashfunc) AliasObj_hash, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- PyObject_GenericGetAttr, /*tp_getattro*/
- PyObject_GenericSetAttr, /*tp_setattro */
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- AliasObj_methods, /* tp_methods */
- 0, /*tp_members*/
- AliasObj_getsetlist, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- AliasObj_tp_init, /* tp_init */
- AliasObj_tp_alloc, /* tp_alloc */
- AliasObj_tp_new, /* tp_new */
- AliasObj_tp_free, /* tp_free */
-};
-
-/* --------------------- End object type Alias ---------------------- */
-
-
-static PyObject *Alias_NewAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fromFile;
- FSSpec target;
- AliasHandle alias;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &fromFile,
- PyMac_GetFSSpec, &target))
- return NULL;
- _err = NewAlias(&fromFile,
- &target,
- &alias);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- AliasObj_New, alias);
- return _res;
-}
-
-static PyObject *Alias_NewAliasMinimal(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec target;
- AliasHandle alias;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &target))
- return NULL;
- _err = NewAliasMinimal(&target,
- &alias);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- AliasObj_New, alias);
- return _res;
-}
-
-static PyObject *Alias_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- char *fullPath__in__;
- int fullPath__len__;
- int fullPath__in_len__;
- Str32 zoneName;
- Str31 serverName;
- AliasHandle alias;
- if (!PyArg_ParseTuple(_args, "s#O&O&",
- &fullPath__in__, &fullPath__in_len__,
- PyMac_GetStr255, zoneName,
- PyMac_GetStr255, serverName))
- return NULL;
- fullPath__len__ = fullPath__in_len__;
- _err = NewAliasMinimalFromFullPath(fullPath__len__, fullPath__in__,
- zoneName,
- serverName,
- &alias);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- AliasObj_New, alias);
- return _res;
-}
-
-static PyObject *Alias_ResolveAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fromFile;
- AliasHandle alias;
- FSSpec target;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &fromFile,
- AliasObj_Convert, &alias))
- return NULL;
- _err = ResolveAlias(&fromFile,
- alias,
- &target,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&b",
- PyMac_BuildFSSpec, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_IsAliasFile(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fileFSSpec;
- Boolean aliasFileFlag;
- Boolean folderFlag;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &fileFSSpec))
- return NULL;
- _err = IsAliasFile(&fileFSSpec,
- &aliasFileFlag,
- &folderFlag);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("bb",
- aliasFileFlag,
- folderFlag);
- return _res;
-}
-
-static PyObject *Alias_ResolveAliasWithMountFlags(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fromFile;
- AliasHandle alias;
- FSSpec target;
- Boolean wasChanged;
- unsigned long mountFlags;
- if (!PyArg_ParseTuple(_args, "O&O&l",
- PyMac_GetFSSpec, &fromFile,
- AliasObj_Convert, &alias,
- &mountFlags))
- return NULL;
- _err = ResolveAliasWithMountFlags(&fromFile,
- alias,
- &target,
- &wasChanged,
- mountFlags);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&b",
- PyMac_BuildFSSpec, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_ResolveAliasFile(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec theSpec;
- Boolean resolveAliasChains;
- Boolean targetIsFolder;
- Boolean wasAliased;
- if (!PyArg_ParseTuple(_args, "b",
- &resolveAliasChains))
- return NULL;
- _err = ResolveAliasFile(&theSpec,
- resolveAliasChains,
- &targetIsFolder,
- &wasAliased);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&bb",
- PyMac_BuildFSSpec, &theSpec,
- targetIsFolder,
- wasAliased);
- return _res;
-}
-
-static PyObject *Alias_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec theSpec;
- Boolean resolveAliasChains;
- Boolean targetIsFolder;
- Boolean wasAliased;
- unsigned long mountFlags;
- if (!PyArg_ParseTuple(_args, "bl",
- &resolveAliasChains,
- &mountFlags))
- return NULL;
- _err = ResolveAliasFileWithMountFlags(&theSpec,
- resolveAliasChains,
- &targetIsFolder,
- &wasAliased,
- mountFlags);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&bb",
- PyMac_BuildFSSpec, &theSpec,
- targetIsFolder,
- wasAliased);
- return _res;
-}
-
-static PyObject *Alias_FollowFinderAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fromFile;
- AliasHandle alias;
- Boolean logon;
- FSSpec target;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&O&b",
- PyMac_GetFSSpec, &fromFile,
- AliasObj_Convert, &alias,
- &logon))
- return NULL;
- _err = FollowFinderAlias(&fromFile,
- alias,
- logon,
- &target,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&b",
- PyMac_BuildFSSpec, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_UpdateAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec fromFile;
- FSSpec target;
- AliasHandle alias;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&O&O&",
- PyMac_GetFSSpec, &fromFile,
- PyMac_GetFSSpec, &target,
- AliasObj_Convert, &alias))
- return NULL;
- _err = UpdateAlias(&fromFile,
- &target,
- alias,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("b",
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec theSpec;
- Boolean resolveAliasChains;
- Boolean targetIsFolder;
- Boolean wasAliased;
- unsigned long mountFlags;
- if (!PyArg_ParseTuple(_args, "bl",
- &resolveAliasChains,
- &mountFlags))
- return NULL;
- _err = ResolveAliasFileWithMountFlagsNoUI(&theSpec,
- resolveAliasChains,
- &targetIsFolder,
- &wasAliased,
- mountFlags);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&bb",
- PyMac_BuildFSSpec, &theSpec,
- targetIsFolder,
- wasAliased);
- return _res;
-}
-
-static PyObject *Alias_FSNewAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fromFile;
- FSRef target;
- AliasHandle inAlias;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSRef, &fromFile,
- PyMac_GetFSRef, &target))
- return NULL;
- _err = FSNewAlias(&fromFile,
- &target,
- &inAlias);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- AliasObj_New, inAlias);
- return _res;
-}
-
-static PyObject *Alias_FSNewAliasMinimal(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef target;
- AliasHandle inAlias;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSRef, &target))
- return NULL;
- _err = FSNewAliasMinimal(&target,
- &inAlias);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- AliasObj_New, inAlias);
- return _res;
-}
-
-static PyObject *Alias_FSIsAliasFile(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fileRef;
- Boolean aliasFileFlag;
- Boolean folderFlag;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSRef, &fileRef))
- return NULL;
- _err = FSIsAliasFile(&fileRef,
- &aliasFileFlag,
- &folderFlag);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("bb",
- aliasFileFlag,
- folderFlag);
- return _res;
-}
-
-static PyObject *Alias_FSResolveAliasWithMountFlags(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fromFile;
- AliasHandle inAlias;
- FSRef target;
- Boolean wasChanged;
- unsigned long mountFlags;
- if (!PyArg_ParseTuple(_args, "O&O&l",
- PyMac_GetFSRef, &fromFile,
- AliasObj_Convert, &inAlias,
- &mountFlags))
- return NULL;
- _err = FSResolveAliasWithMountFlags(&fromFile,
- inAlias,
- &target,
- &wasChanged,
- mountFlags);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&b",
- PyMac_BuildFSRef, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_FSResolveAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fromFile;
- AliasHandle alias;
- FSRef target;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSRef, &fromFile,
- AliasObj_Convert, &alias))
- return NULL;
- _err = FSResolveAlias(&fromFile,
- alias,
- &target,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&b",
- PyMac_BuildFSRef, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef theRef;
- Boolean resolveAliasChains;
- Boolean targetIsFolder;
- Boolean wasAliased;
- unsigned long mountFlags;
- if (!PyArg_ParseTuple(_args, "bl",
- &resolveAliasChains,
- &mountFlags))
- return NULL;
- _err = FSResolveAliasFileWithMountFlags(&theRef,
- resolveAliasChains,
- &targetIsFolder,
- &wasAliased,
- mountFlags);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&bb",
- PyMac_BuildFSRef, &theRef,
- targetIsFolder,
- wasAliased);
- return _res;
-}
-
-static PyObject *Alias_FSResolveAliasFile(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef theRef;
- Boolean resolveAliasChains;
- Boolean targetIsFolder;
- Boolean wasAliased;
- if (!PyArg_ParseTuple(_args, "b",
- &resolveAliasChains))
- return NULL;
- _err = FSResolveAliasFile(&theRef,
- resolveAliasChains,
- &targetIsFolder,
- &wasAliased);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&bb",
- PyMac_BuildFSRef, &theRef,
- targetIsFolder,
- wasAliased);
- return _res;
-}
-
-static PyObject *Alias_FSFollowFinderAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fromFile;
- AliasHandle alias;
- Boolean logon;
- FSRef target;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&b",
- AliasObj_Convert, &alias,
- &logon))
- return NULL;
- _err = FSFollowFinderAlias(&fromFile,
- alias,
- logon,
- &target,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&O&b",
- PyMac_BuildFSRef, &fromFile,
- PyMac_BuildFSRef, &target,
- wasChanged);
- return _res;
-}
-
-static PyObject *Alias_FSUpdateAlias(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef fromFile;
- FSRef target;
- AliasHandle alias;
- Boolean wasChanged;
- if (!PyArg_ParseTuple(_args, "O&O&O&",
- PyMac_GetFSRef, &fromFile,
- PyMac_GetFSRef, &target,
- AliasObj_Convert, &alias))
- return NULL;
- _err = FSUpdateAlias(&fromFile,
- &target,
- alias,
- &wasChanged);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("b",
- wasChanged);
- return _res;
-}
-
-static PyMethodDef Alias_methods[] = {
- {"NewAlias", (PyCFunction)Alias_NewAlias, 1,
- PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
- {"NewAliasMinimal", (PyCFunction)Alias_NewAliasMinimal, 1,
- PyDoc_STR("(FSSpec target) -> (AliasHandle alias)")},
- {"NewAliasMinimalFromFullPath", (PyCFunction)Alias_NewAliasMinimalFromFullPath, 1,
- PyDoc_STR("(Buffer fullPath, Str32 zoneName, Str31 serverName) -> (AliasHandle alias)")},
- {"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
- PyDoc_STR("(FSSpec fromFile, AliasHandle alias) -> (FSSpec target, Boolean wasChanged)")},
- {"IsAliasFile", (PyCFunction)Alias_IsAliasFile, 1,
- PyDoc_STR("(FSSpec fileFSSpec) -> (Boolean aliasFileFlag, Boolean folderFlag)")},
- {"ResolveAliasWithMountFlags", (PyCFunction)Alias_ResolveAliasWithMountFlags, 1,
- PyDoc_STR("(FSSpec fromFile, AliasHandle alias, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
- {"ResolveAliasFile", (PyCFunction)Alias_ResolveAliasFile, 1,
- PyDoc_STR("(Boolean resolveAliasChains) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
- {"ResolveAliasFileWithMountFlags", (PyCFunction)Alias_ResolveAliasFileWithMountFlags, 1,
- PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
- {"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
- PyDoc_STR("(FSSpec fromFile, AliasHandle alias, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
- {"UpdateAlias", (PyCFunction)Alias_UpdateAlias, 1,
- PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
- {"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)Alias_ResolveAliasFileWithMountFlagsNoUI, 1,
- PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
- {"FSNewAlias", (PyCFunction)Alias_FSNewAlias, 1,
- PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
- {"FSNewAliasMinimal", (PyCFunction)Alias_FSNewAliasMinimal, 1,
- PyDoc_STR("(FSRef target) -> (AliasHandle inAlias)")},
- {"FSIsAliasFile", (PyCFunction)Alias_FSIsAliasFile, 1,
- PyDoc_STR("(FSRef fileRef) -> (Boolean aliasFileFlag, Boolean folderFlag)")},
- {"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
- PyDoc_STR("(FSRef fromFile, AliasHandle inAlias, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
- {"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
- PyDoc_STR("(FSRef fromFile, AliasHandle alias) -> (FSRef target, Boolean wasChanged)")},
- {"FSResolveAliasFileWithMountFlags", (PyCFunction)Alias_FSResolveAliasFileWithMountFlags, 1,
- PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
- {"FSResolveAliasFile", (PyCFunction)Alias_FSResolveAliasFile, 1,
- PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
- {"FSFollowFinderAlias", (PyCFunction)Alias_FSFollowFinderAlias, 1,
- PyDoc_STR("(AliasHandle alias, Boolean logon) -> (FSRef fromFile, FSRef target, Boolean wasChanged)")},
- {"FSUpdateAlias", (PyCFunction)Alias_FSUpdateAlias, 1,
- PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
- {NULL, NULL, 0}
-};
-
-
-
-
-void init_Alias(void)
-{
- PyObject *m;
- PyObject *d;
-
-
-
-
- m = Py_InitModule("_Alias", Alias_methods);
- d = PyModule_GetDict(m);
- Alias_Error = PyMac_GetOSErrException();
- if (Alias_Error == NULL ||
- PyDict_SetItemString(d, "Error", Alias_Error) != 0)
- return;
- Alias_Type.ob_type = &PyType_Type;
- Py_INCREF(&Alias_Type);
- PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
- /* Backward-compatible name */
- Py_INCREF(&Alias_Type);
- PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
-}
-
-/* ======================= End module _Alias ======================== */
-
diff --git a/Mac/Modules/alias/aliasscan.py b/Mac/Modules/alias/aliasscan.py
deleted file mode 100644
index a21d3f2..0000000
--- a/Mac/Modules/alias/aliasscan.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# Scan an Apple header file, generating a Python file of generator calls.
-
-import sys
-import os
-from bgenlocations import TOOLBOXDIR, BGENDIR
-sys.path.append(BGENDIR)
-from scantools import Scanner_OSX
-
-LONG = "Aliases"
-SHORT = "alias"
-OBJECT = "AliasHandle"
-
-def main():
- input = LONG + ".h"
- output = SHORT + "gen.py"
- defsoutput = TOOLBOXDIR + LONG + ".py"
- scanner = MyScanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- scanner.gentypetest(SHORT+"typetest.py")
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "=== Done scanning and generating, now importing the generated code... ==="
- exec "import " + SHORT + "support"
- print "=== Done. It's up to you to compile it now! ==="
-
-class MyScanner(Scanner_OSX):
-
- def destination(self, type, name, arglist):
- classname = "Function"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- # This is non-functional today
- if t == OBJECT and m == "InMode":
- classname = "Method"
- listname = "methods"
- return classname, listname
-
- def makeblacklistnames(self):
- return [
- # Constants with incompatible definitions
-
- ]
-
- def makeblacklisttypes(self):
- return [
- "AliasFilterProcPtr",
- "AliasFilterUPP",
- "CInfoPBPtr",
- ]
-
- def makerepairinstructions(self):
- return [
- ([('Str63', 'theString', 'InMode')],
- [('Str63', 'theString', 'OutMode')]),
-
- ([('short', 'fullPathLength', 'InMode'),
- ('void_ptr', 'fullPath', 'InMode')],
- [('FullPathName', 'fullPath', 'InMode')]),
-
- ]
-
-
- def writeinitialdefs(self):
- self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
- self.defsfile.write("true = True\n")
- self.defsfile.write("false = False\n")
-
-if __name__ == "__main__":
- main()
diff --git a/Mac/Modules/alias/aliassupport.py b/Mac/Modules/alias/aliassupport.py
deleted file mode 100644
index d019c36..0000000
--- a/Mac/Modules/alias/aliassupport.py
+++ /dev/null
@@ -1,118 +0,0 @@
-# This script generates a Python interface for an Apple Macintosh Manager.
-# It uses the "bgen" package to generate C code.
-# The function specifications are generated by scanning the mamager's header file,
-# using the "scantools" package (customized for this particular manager).
-
-import string
-
-# Declarations that change for each manager
-MACHEADERFILE = 'Aliases.h' # The Apple header file
-MODNAME = '_Alias' # The name of the module
-
-# The following is *usually* unchanged but may still require tuning
-MODPREFIX = 'Alias' # The prefix for module-wide routines
-INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
-OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
-
-from macsupport import *
-
-
-# Create the type objects
-
-class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType):
- pass
-
-FullPathName = VarReverseInputBufferType()
-
-AliasHandle = OpaqueByValueType("AliasHandle", "AliasObj")
-AliasInfoType = Type("AliasInfoType", "h")
-ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255")
-ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255")
-#FSSpecArrayPtr
-#Ptr
-Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
-#void_ptr
-# class UniCharCountBuffer(InputOnlyType):
-# pass
-#
-# #CatPositionRec
-# ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
-# FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
-# FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
-# FNMessage = Type("FNMessage", "l")
-# FSAllocationFlags = Type("FSAllocationFlags", "H")
-# #FSCatalogInfo
-# FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
-# #FSForkInfo
-# #FSIterator
-# FSIteratorFlags = Type("FSIteratorFlags", "l")
-# #FSVolumeInfo
-# FSVolumeRefNum = Type("FSVolumeRefNum", "h")
-# HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
-# SInt64 = Type("SInt64", "L")
-# UInt64 = Type("UInt64", "L")
-# #UInt8_ptr
-# #UniCharCount
-# #char_ptr
-# #void_ptr
-
-
-includestuff = includestuff + """
-#ifdef WITHOUT_FRAMEWORKS
-#include <Files.h>
-#else
-#include <Carbon/Carbon.h>
-#endif
-"""
-
-execfile(string.lower(MODPREFIX) + 'typetest.py')
-
-# From here on it's basically all boiler plate...
-
-# Create the generator groups and link them
-module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
-
-class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
- # XXXX Should inherit from resource?
-
- def outputCheckNewArg(self):
- Output("if (itself == NULL) return PyMac_Error(resNotFound);")
-
- def outputStructMembers(self):
- GlobalObjectDefinition.outputStructMembers(self)
- Output("void (*ob_freeit)(%s ptr);", self.itselftype)
-
- def outputInitStructMembers(self):
- GlobalObjectDefinition.outputInitStructMembers(self)
- Output("it->ob_freeit = NULL;")
-
- def outputCleanupStructMembers(self):
- Output("if (self->ob_freeit && self->ob_itself)")
- OutLbrace()
- Output("self->ob_freeit(self->ob_itself);")
- OutRbrace()
- Output("self->ob_itself = NULL;")
-
-
-aliasobject = AliasDefinition('Alias', 'AliasObj', 'AliasHandle')
-module.addobject(aliasobject)
-# Create the generator classes used to populate the lists
-Function = OSErrFunctionGenerator
-Method = OSErrMethodGenerator
-
-# Create and populate the lists
-functions = []
-methods = []
-execfile(INPUTFILE)
-
-# Manual generators:
-
-# add the populated lists to the generator groups
-# (in a different wordl the scan program would generate this)
-for f in methods: aliasobject.add(f)
-for f in functions: module.add(f)
-
-# generate output (open the output file as late as possible)
-SetOutputFileName(OUTPUTFILE)
-module.generate()
-
diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c
index 0029d6c..e76939f 100644
--- a/Mac/Modules/file/_Filemodule.c
+++ b/Mac/Modules/file/_Filemodule.c
@@ -26,6 +26,16 @@
#include <Carbon/Carbon.h>
#endif
+/* Forward declarations */
+extern PyObject *FSRef_New(FSRef *itself);
+extern PyObject *FSSpec_New(FSSpec *itself);
+extern PyObject *Alias_New(AliasHandle itself);
+extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
+extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
+extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
+static int myPyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+static int myPyMac_GetFSRef(PyObject *v, FSRef *fsr);
+
/*
** Parse/generate objsect
*/
@@ -36,19 +46,6 @@ PyMac_BuildHFSUniStr255(HFSUniStr255 *itself)
return Py_BuildValue("u#", itself->unicode, itself->length);
}
-#if 0
-static int
-PyMac_GetHFSUniStr255(PyObject *v, HFSUniStr255 *itself)
-{
- return PyArg_ParseTuple(v, "O&O&O&O&O&",
- PyMac_GetFixed, &itself->ascent,
- PyMac_GetFixed, &itself->descent,
- PyMac_GetFixed, &itself->leading,
- PyMac_GetFixed, &itself->widMax,
- ResObj_Convert, &itself->wTabHandle);
-}
-#endif
-
/*
** Parse/generate objsect
*/
@@ -75,9 +72,1182 @@ PyMac_GetFInfo(PyObject *v, FInfo *itself)
&itself->fdFldr);
}
-
static PyObject *File_Error;
+/* ----------------------- Object type Alias ------------------------ */
+
+PyTypeObject Alias_Type;
+
+#define Alias_Check(x) ((x)->ob_type == &Alias_Type)
+
+typedef struct AliasObject {
+ PyObject_HEAD
+ AliasHandle ob_itself;
+ void (*ob_freeit)(AliasHandle ptr);
+} AliasObject;
+
+PyObject *Alias_New(AliasHandle itself)
+{
+ AliasObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(AliasObject, &Alias_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = NULL;
+ return (PyObject *)it;
+}
+int Alias_Convert(PyObject *v, AliasHandle *p_itself)
+{
+ if (!Alias_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "Alias required");
+ return 0;
+ }
+ *p_itself = ((AliasObject *)v)->ob_itself;
+ return 1;
+}
+
+static void Alias_dealloc(AliasObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit(self->ob_itself);
+ }
+ self->ob_itself = NULL;
+ PyObject_Del(self);
+}
+
+static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSSpec fromFile;
+ FSSpec target;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSSpec_Convert, &fromFile))
+ return NULL;
+ _rv = ResolveAlias(&fromFile,
+ _self->ob_itself,
+ &target,
+ &wasChanged);
+ _res = Py_BuildValue("hO&b",
+ _rv,
+ FSSpec_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyObject *Alias_GetAliasInfo(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AliasInfoType index;
+ Str63 theString;
+ if (!PyArg_ParseTuple(_args, "h",
+ &index))
+ return NULL;
+ _err = GetAliasInfo(_self->ob_itself,
+ index,
+ theString);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildStr255, theString);
+ return _res;
+}
+
+static PyObject *Alias_ResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSSpec fromFile;
+ FSSpec target;
+ Boolean wasChanged;
+ unsigned long mountFlags;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ FSSpec_Convert, &fromFile,
+ &mountFlags))
+ return NULL;
+ _rv = ResolveAliasWithMountFlags(&fromFile,
+ _self->ob_itself,
+ &target,
+ &wasChanged,
+ mountFlags);
+ _res = Py_BuildValue("hO&b",
+ _rv,
+ FSSpec_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyObject *Alias_FollowFinderAlias(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSSpec fromFile;
+ Boolean logon;
+ FSSpec target;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ FSSpec_Convert, &fromFile,
+ &logon))
+ return NULL;
+ _rv = FollowFinderAlias(&fromFile,
+ _self->ob_itself,
+ logon,
+ &target,
+ &wasChanged);
+ _res = Py_BuildValue("hO&b",
+ _rv,
+ FSSpec_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSRef fromFile;
+ FSRef target;
+ Boolean wasChanged;
+ unsigned long mountFlags;
+ if (!PyArg_ParseTuple(_args, "O&l",
+ FSRef_Convert, &fromFile,
+ &mountFlags))
+ return NULL;
+ _rv = FSResolveAliasWithMountFlags(&fromFile,
+ _self->ob_itself,
+ &target,
+ &wasChanged,
+ mountFlags);
+ _res = Py_BuildValue("hO&b",
+ _rv,
+ FSRef_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyObject *Alias_FSResolveAlias(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSRef fromFile;
+ FSRef target;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSRef_Convert, &fromFile))
+ return NULL;
+ _rv = FSResolveAlias(&fromFile,
+ _self->ob_itself,
+ &target,
+ &wasChanged);
+ _res = Py_BuildValue("hO&b",
+ _rv,
+ FSRef_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyObject *Alias_FSFollowFinderAlias(AliasObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _rv;
+ FSRef fromFile;
+ Boolean logon;
+ FSRef target;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "b",
+ &logon))
+ return NULL;
+ _rv = FSFollowFinderAlias(&fromFile,
+ _self->ob_itself,
+ logon,
+ &target,
+ &wasChanged);
+ _res = Py_BuildValue("hO&O&b",
+ _rv,
+ FSRef_New, &fromFile,
+ FSRef_New, &target,
+ wasChanged);
+ return _res;
+}
+
+static PyMethodDef Alias_methods[] = {
+ {"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
+ PyDoc_STR("(FSSpec fromFile) -> (OSErr _rv, FSSpec target, Boolean wasChanged)")},
+ {"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
+ PyDoc_STR("(AliasInfoType index) -> (Str63 theString)")},
+ {"ResolveAliasWithMountFlags", (PyCFunction)Alias_ResolveAliasWithMountFlags, 1,
+ PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (OSErr _rv, FSSpec target, Boolean wasChanged)")},
+ {"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
+ PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (OSErr _rv, FSSpec target, Boolean wasChanged)")},
+ {"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
+ PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (OSErr _rv, FSRef target, Boolean wasChanged)")},
+ {"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
+ PyDoc_STR("(FSRef fromFile) -> (OSErr _rv, FSRef target, Boolean wasChanged)")},
+ {"FSFollowFinderAlias", (PyCFunction)Alias_FSFollowFinderAlias, 1,
+ PyDoc_STR("(Boolean logon) -> (OSErr _rv, FSRef fromFile, FSRef target, Boolean wasChanged)")},
+ {NULL, NULL, 0}
+};
+
+#define Alias_getsetlist NULL
+
+
+#define Alias_compare NULL
+
+#define Alias_repr NULL
+
+#define Alias_hash NULL
+static int Alias_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ AliasHandle itself;
+ char *kw[] = {"itself", 0};
+
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, Alias_Convert, &itself))
+ {
+ ((AliasObject *)self)->ob_itself = itself;
+ return 0;
+ }
+ return -1;
+}
+
+#define Alias_tp_alloc PyType_GenericAlloc
+
+static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *self;
+
+ if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
+ ((AliasObject *)self)->ob_itself = NULL;
+ return self;
+}
+
+#define Alias_tp_free PyObject_Del
+
+
+PyTypeObject Alias_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "_File.Alias", /*tp_name*/
+ sizeof(AliasObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) Alias_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
+ (cmpfunc) Alias_compare, /*tp_compare*/
+ (reprfunc) Alias_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) Alias_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ Alias_methods, /* tp_methods */
+ 0, /*tp_members*/
+ Alias_getsetlist, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ Alias_tp_init, /* tp_init */
+ Alias_tp_alloc, /* tp_alloc */
+ Alias_tp_new, /* tp_new */
+ Alias_tp_free, /* tp_free */
+};
+
+/* --------------------- End object type Alias ---------------------- */
+
+
+/* ----------------------- Object type FSSpec ----------------------- */
+
+PyTypeObject FSSpec_Type;
+
+#define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type)
+
+typedef struct FSSpecObject {
+ PyObject_HEAD
+ FSSpec ob_itself;
+} FSSpecObject;
+
+PyObject *FSSpec_New(FSSpec *itself)
+{
+ FSSpecObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(FSSpecObject, &FSSpec_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = *itself;
+ return (PyObject *)it;
+}
+int FSSpec_Convert(PyObject *v, FSSpec *p_itself)
+{
+ if (!FSSpec_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "FSSpec required");
+ return 0;
+ }
+ *p_itself = ((FSSpecObject *)v)->ob_itself;
+ return 1;
+}
+
+static void FSSpec_dealloc(FSSpecObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyObject_Del(self);
+}
+
+static PyObject *FSSpec_FSpOpenDF(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt8 permission;
+ short refNum;
+ if (!PyArg_ParseTuple(_args, "b",
+ &permission))
+ return NULL;
+ _err = FSpOpenDF(&_self->ob_itself,
+ permission,
+ &refNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("h",
+ refNum);
+ return _res;
+}
+
+static PyObject *FSSpec_FSpOpenRF(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ SInt8 permission;
+ short refNum;
+ if (!PyArg_ParseTuple(_args, "b",
+ &permission))
+ return NULL;
+ _err = FSpOpenRF(&_self->ob_itself,
+ permission,
+ &refNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("h",
+ refNum);
+ return _res;
+}
+
+static PyObject *FSSpec_FSpCreate(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ OSType creator;
+ OSType fileType;
+ ScriptCode scriptTag;
+ if (!PyArg_ParseTuple(_args, "O&O&h",
+ PyMac_GetOSType, &creator,
+ PyMac_GetOSType, &fileType,
+ &scriptTag))
+ return NULL;
+ _err = FSpCreate(&_self->ob_itself,
+ creator,
+ fileType,
+ scriptTag);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpDirCreate(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ ScriptCode scriptTag;
+ long createdDirID;
+ if (!PyArg_ParseTuple(_args, "h",
+ &scriptTag))
+ return NULL;
+ _err = FSpDirCreate(&_self->ob_itself,
+ scriptTag,
+ &createdDirID);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ createdDirID);
+ return _res;
+}
+
+static PyObject *FSSpec_FSpDelete(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSpDelete(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpGetFInfo(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FInfo fndrInfo;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSpGetFInfo(&_self->ob_itself,
+ &fndrInfo);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildFInfo, &fndrInfo);
+ return _res;
+}
+
+static PyObject *FSSpec_FSpSetFInfo(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FInfo fndrInfo;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetFInfo, &fndrInfo))
+ return NULL;
+ _err = FSpSetFInfo(&_self->ob_itself,
+ &fndrInfo);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpSetFLock(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSpSetFLock(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpRstFLock(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSpRstFLock(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpRename(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Str255 newName;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, newName))
+ return NULL;
+ _err = FSpRename(&_self->ob_itself,
+ newName);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpCatMove(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec dest;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSSpec_Convert, &dest))
+ return NULL;
+ _err = FSpCatMove(&_self->ob_itself,
+ &dest);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpExchangeFiles(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec dest;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSSpec_Convert, &dest))
+ return NULL;
+ _err = FSpExchangeFiles(&_self->ob_itself,
+ &dest);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSSpec_FSpMakeFSRef(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef newRef;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSpMakeFSRef(&_self->ob_itself,
+ &newRef);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ FSRef_New, &newRef);
+ return _res;
+}
+
+static PyObject *FSSpec_NewAlias(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec target;
+ AliasHandle alias;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSSpec_Convert, &target))
+ return NULL;
+ _err = NewAlias(&_self->ob_itself,
+ &target,
+ &alias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ Alias_New, alias);
+ return _res;
+}
+
+static PyObject *FSSpec_NewAliasMinimal(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AliasHandle alias;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = NewAliasMinimal(&_self->ob_itself,
+ &alias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ Alias_New, alias);
+ return _res;
+}
+
+static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Boolean aliasFileFlag;
+ Boolean folderFlag;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = IsAliasFile(&_self->ob_itself,
+ &aliasFileFlag,
+ &folderFlag);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("bb",
+ aliasFileFlag,
+ folderFlag);
+ return _res;
+}
+
+static PyObject *FSSpec_UpdateAlias(FSSpecObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec target;
+ AliasHandle alias;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ FSSpec_Convert, &target,
+ Alias_Convert, &alias))
+ return NULL;
+ _err = UpdateAlias(&_self->ob_itself,
+ &target,
+ alias,
+ &wasChanged);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ wasChanged);
+ return _res;
+}
+
+static PyMethodDef FSSpec_methods[] = {
+ {"FSpOpenDF", (PyCFunction)FSSpec_FSpOpenDF, 1,
+ PyDoc_STR("(SInt8 permission) -> (short refNum)")},
+ {"FSpOpenRF", (PyCFunction)FSSpec_FSpOpenRF, 1,
+ PyDoc_STR("(SInt8 permission) -> (short refNum)")},
+ {"FSpCreate", (PyCFunction)FSSpec_FSpCreate, 1,
+ PyDoc_STR("(OSType creator, OSType fileType, ScriptCode scriptTag) -> None")},
+ {"FSpDirCreate", (PyCFunction)FSSpec_FSpDirCreate, 1,
+ PyDoc_STR("(ScriptCode scriptTag) -> (long createdDirID)")},
+ {"FSpDelete", (PyCFunction)FSSpec_FSpDelete, 1,
+ PyDoc_STR("() -> None")},
+ {"FSpGetFInfo", (PyCFunction)FSSpec_FSpGetFInfo, 1,
+ PyDoc_STR("() -> (FInfo fndrInfo)")},
+ {"FSpSetFInfo", (PyCFunction)FSSpec_FSpSetFInfo, 1,
+ PyDoc_STR("(FInfo fndrInfo) -> None")},
+ {"FSpSetFLock", (PyCFunction)FSSpec_FSpSetFLock, 1,
+ PyDoc_STR("() -> None")},
+ {"FSpRstFLock", (PyCFunction)FSSpec_FSpRstFLock, 1,
+ PyDoc_STR("() -> None")},
+ {"FSpRename", (PyCFunction)FSSpec_FSpRename, 1,
+ PyDoc_STR("(Str255 newName) -> None")},
+ {"FSpCatMove", (PyCFunction)FSSpec_FSpCatMove, 1,
+ PyDoc_STR("(FSSpec dest) -> None")},
+ {"FSpExchangeFiles", (PyCFunction)FSSpec_FSpExchangeFiles, 1,
+ PyDoc_STR("(FSSpec dest) -> None")},
+ {"FSpMakeFSRef", (PyCFunction)FSSpec_FSpMakeFSRef, 1,
+ PyDoc_STR("() -> (FSRef newRef)")},
+ {"NewAlias", (PyCFunction)FSSpec_NewAlias, 1,
+ PyDoc_STR("(FSSpec target) -> (AliasHandle alias)")},
+ {"NewAliasMinimal", (PyCFunction)FSSpec_NewAliasMinimal, 1,
+ PyDoc_STR("() -> (AliasHandle alias)")},
+ {"IsAliasFile", (PyCFunction)FSSpec_IsAliasFile, 1,
+ PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
+ {"UpdateAlias", (PyCFunction)FSSpec_UpdateAlias, 1,
+ PyDoc_STR("(FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
+ {NULL, NULL, 0}
+};
+
+#define FSSpec_getsetlist NULL
+
+
+#define FSSpec_compare NULL
+
+#define FSSpec_repr NULL
+
+#define FSSpec_hash NULL
+static int FSSpec_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ PyObject *v;
+ char *kw[] = {"itself", 0};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kw, &v))
+ return -1;
+ if (myPyMac_GetFSSpec(v, &((FSSpecObject *)self)->ob_itself)) return 0;
+ return -1;
+}
+
+#define FSSpec_tp_alloc PyType_GenericAlloc
+
+static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *self;
+
+ if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
+ memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpecObject));
+ return self;
+}
+
+#define FSSpec_tp_free PyObject_Del
+
+
+PyTypeObject FSSpec_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "_File.FSSpec", /*tp_name*/
+ sizeof(FSSpecObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) FSSpec_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
+ (cmpfunc) FSSpec_compare, /*tp_compare*/
+ (reprfunc) FSSpec_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) FSSpec_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ FSSpec_methods, /* tp_methods */
+ 0, /*tp_members*/
+ FSSpec_getsetlist, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ FSSpec_tp_init, /* tp_init */
+ FSSpec_tp_alloc, /* tp_alloc */
+ FSSpec_tp_new, /* tp_new */
+ FSSpec_tp_free, /* tp_free */
+};
+
+/* --------------------- End object type FSSpec --------------------- */
+
+
+/* ----------------------- Object type FSRef ------------------------ */
+
+PyTypeObject FSRef_Type;
+
+#define FSRef_Check(x) ((x)->ob_type == &FSRef_Type)
+
+typedef struct FSRefObject {
+ PyObject_HEAD
+ FSRef ob_itself;
+} FSRefObject;
+
+PyObject *FSRef_New(FSRef *itself)
+{
+ FSRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(FSRefObject, &FSRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = *itself;
+ return (PyObject *)it;
+}
+int FSRef_Convert(PyObject *v, FSRef *p_itself)
+{
+ if (!FSRef_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "FSRef required");
+ return 0;
+ }
+ *p_itself = ((FSRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void FSRef_dealloc(FSRefObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyObject_Del(self);
+}
+
+static PyObject *FSRef_FSMakeFSRefUnicode(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UniChar *nameLength__in__;
+ UniCharCount nameLength__len__;
+ int nameLength__in_len__;
+ TextEncoding textEncodingHint;
+ FSRef newRef;
+ if (!PyArg_ParseTuple(_args, "u#l",
+ &nameLength__in__, &nameLength__in_len__,
+ &textEncodingHint))
+ return NULL;
+ nameLength__len__ = nameLength__in_len__;
+ _err = FSMakeFSRefUnicode(&_self->ob_itself,
+ nameLength__len__, nameLength__in__,
+ textEncodingHint,
+ &newRef);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ FSRef_New, &newRef);
+ return _res;
+}
+
+static PyObject *FSRef_FSCompareFSRefs(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef ref2;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSRef_Convert, &ref2))
+ return NULL;
+ _err = FSCompareFSRefs(&_self->ob_itself,
+ &ref2);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSRef_FSDeleteObject(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSDeleteObject(&_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSRef_FSMoveObject(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef destDirectory;
+ FSRef newRef;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSRef_Convert, &destDirectory))
+ return NULL;
+ _err = FSMoveObject(&_self->ob_itself,
+ &destDirectory,
+ &newRef);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ FSRef_New, &newRef);
+ return _res;
+}
+
+static PyObject *FSRef_FSExchangeObjects(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef destRef;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSRef_Convert, &destRef))
+ return NULL;
+ _err = FSExchangeObjects(&_self->ob_itself,
+ &destRef);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSRef_FSRenameUnicode(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UniChar *nameLength__in__;
+ UniCharCount nameLength__len__;
+ int nameLength__in_len__;
+ TextEncoding textEncodingHint;
+ FSRef newRef;
+ if (!PyArg_ParseTuple(_args, "u#l",
+ &nameLength__in__, &nameLength__in_len__,
+ &textEncodingHint))
+ return NULL;
+ nameLength__len__ = nameLength__in_len__;
+ _err = FSRenameUnicode(&_self->ob_itself,
+ nameLength__len__, nameLength__in__,
+ textEncodingHint,
+ &newRef);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ FSRef_New, &newRef);
+ return _res;
+}
+
+static PyObject *FSRef_FSCreateFork(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UniChar *forkNameLength__in__;
+ UniCharCount forkNameLength__len__;
+ int forkNameLength__in_len__;
+ if (!PyArg_ParseTuple(_args, "u#",
+ &forkNameLength__in__, &forkNameLength__in_len__))
+ return NULL;
+ forkNameLength__len__ = forkNameLength__in_len__;
+ _err = FSCreateFork(&_self->ob_itself,
+ forkNameLength__len__, forkNameLength__in__);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSRef_FSDeleteFork(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UniChar *forkNameLength__in__;
+ UniCharCount forkNameLength__len__;
+ int forkNameLength__in_len__;
+ if (!PyArg_ParseTuple(_args, "u#",
+ &forkNameLength__in__, &forkNameLength__in_len__))
+ return NULL;
+ forkNameLength__len__ = forkNameLength__in_len__;
+ _err = FSDeleteFork(&_self->ob_itself,
+ forkNameLength__len__, forkNameLength__in__);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *FSRef_FSOpenFork(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ UniChar *forkNameLength__in__;
+ UniCharCount forkNameLength__len__;
+ int forkNameLength__in_len__;
+ SInt8 permissions;
+ SInt16 forkRefNum;
+ if (!PyArg_ParseTuple(_args, "u#b",
+ &forkNameLength__in__, &forkNameLength__in_len__,
+ &permissions))
+ return NULL;
+ forkNameLength__len__ = forkNameLength__in_len__;
+ _err = FSOpenFork(&_self->ob_itself,
+ forkNameLength__len__, forkNameLength__in__,
+ permissions,
+ &forkRefNum);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("h",
+ forkRefNum);
+ return _res;
+}
+
+#if TARGET_API_MAC_OSX
+
+static PyObject *FSRef_FNNotify(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ FNMessage message;
+ OptionBits flags;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &message,
+ &flags))
+ return NULL;
+ _err = FNNotify(&_self->ob_itself,
+ message,
+ flags);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+#endif
+
+static PyObject *FSRef_FSNewAlias(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef target;
+ AliasHandle inAlias;
+ if (!PyArg_ParseTuple(_args, "O&",
+ FSRef_Convert, &target))
+ return NULL;
+ _err = FSNewAlias(&_self->ob_itself,
+ &target,
+ &inAlias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ Alias_New, inAlias);
+ return _res;
+}
+
+static PyObject *FSRef_FSNewAliasMinimal(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ AliasHandle inAlias;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSNewAliasMinimal(&_self->ob_itself,
+ &inAlias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ Alias_New, inAlias);
+ return _res;
+}
+
+static PyObject *FSRef_FSIsAliasFile(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ Boolean aliasFileFlag;
+ Boolean folderFlag;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = FSIsAliasFile(&_self->ob_itself,
+ &aliasFileFlag,
+ &folderFlag);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("bb",
+ aliasFileFlag,
+ folderFlag);
+ return _res;
+}
+
+static PyObject *FSRef_FSUpdateAlias(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef target;
+ AliasHandle alias;
+ Boolean wasChanged;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ FSRef_Convert, &target,
+ Alias_Convert, &alias))
+ return NULL;
+ _err = FSUpdateAlias(&_self->ob_itself,
+ &target,
+ alias,
+ &wasChanged);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("b",
+ wasChanged);
+ return _res;
+}
+
+static PyObject *FSRef_FSRefMakePath(FSRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSStatus _err;
+#define MAXPATHNAME 1024
+ UInt8 path[MAXPATHNAME];
+ UInt32 maxPathSize = MAXPATHNAME;
+
+ _err = FSRefMakePath(&_self->ob_itself,
+ path,
+ maxPathSize);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("s", path);
+ return _res;
+
+}
+
+static PyMethodDef FSRef_methods[] = {
+ {"FSMakeFSRefUnicode", (PyCFunction)FSRef_FSMakeFSRefUnicode, 1,
+ PyDoc_STR("(Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
+ {"FSCompareFSRefs", (PyCFunction)FSRef_FSCompareFSRefs, 1,
+ PyDoc_STR("(FSRef ref2) -> None")},
+ {"FSDeleteObject", (PyCFunction)FSRef_FSDeleteObject, 1,
+ PyDoc_STR("() -> None")},
+ {"FSMoveObject", (PyCFunction)FSRef_FSMoveObject, 1,
+ PyDoc_STR("(FSRef destDirectory) -> (FSRef newRef)")},
+ {"FSExchangeObjects", (PyCFunction)FSRef_FSExchangeObjects, 1,
+ PyDoc_STR("(FSRef destRef) -> None")},
+ {"FSRenameUnicode", (PyCFunction)FSRef_FSRenameUnicode, 1,
+ PyDoc_STR("(Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
+ {"FSCreateFork", (PyCFunction)FSRef_FSCreateFork, 1,
+ PyDoc_STR("(Buffer forkNameLength) -> None")},
+ {"FSDeleteFork", (PyCFunction)FSRef_FSDeleteFork, 1,
+ PyDoc_STR("(Buffer forkNameLength) -> None")},
+ {"FSOpenFork", (PyCFunction)FSRef_FSOpenFork, 1,
+ PyDoc_STR("(Buffer forkNameLength, SInt8 permissions) -> (SInt16 forkRefNum)")},
+
+#if TARGET_API_MAC_OSX
+ {"FNNotify", (PyCFunction)FSRef_FNNotify, 1,
+ PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
+#endif
+ {"FSNewAlias", (PyCFunction)FSRef_FSNewAlias, 1,
+ PyDoc_STR("(FSRef target) -> (AliasHandle inAlias)")},
+ {"FSNewAliasMinimal", (PyCFunction)FSRef_FSNewAliasMinimal, 1,
+ PyDoc_STR("() -> (AliasHandle inAlias)")},
+ {"FSIsAliasFile", (PyCFunction)FSRef_FSIsAliasFile, 1,
+ PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
+ {"FSUpdateAlias", (PyCFunction)FSRef_FSUpdateAlias, 1,
+ PyDoc_STR("(FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
+ {"FSRefMakePath", (PyCFunction)FSRef_FSRefMakePath, 1,
+ PyDoc_STR("() -> string")},
+ {NULL, NULL, 0}
+};
+
+#define FSRef_getsetlist NULL
+
+
+#define FSRef_compare NULL
+
+#define FSRef_repr NULL
+
+#define FSRef_hash NULL
+static int FSRef_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ PyObject *v;
+ char *kw[] = {"itself", 0};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kw, &v))
+ return -1;
+ if (myPyMac_GetFSRef(v, &((FSRefObject *)self)->ob_itself)) return 0;
+ return -1;
+}
+
+#define FSRef_tp_alloc PyType_GenericAlloc
+
+static PyObject *FSRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *self;
+
+ if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
+ memset(&((FSRefObject *)self)->ob_itself, 0, sizeof(FSRefObject));
+ return self;
+}
+
+#define FSRef_tp_free PyObject_Del
+
+
+PyTypeObject FSRef_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "_File.FSRef", /*tp_name*/
+ sizeof(FSRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) FSRef_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
+ (cmpfunc) FSRef_compare, /*tp_compare*/
+ (reprfunc) FSRef_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) FSRef_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ FSRef_methods, /* tp_methods */
+ 0, /*tp_members*/
+ FSRef_getsetlist, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ FSRef_tp_init, /* tp_init */
+ FSRef_tp_alloc, /* tp_alloc */
+ FSRef_tp_new, /* tp_new */
+ FSRef_tp_free, /* tp_free */
+};
+
+/* --------------------- End object type FSRef ---------------------- */
+
+
static PyObject *File_UnmountVol(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@@ -602,433 +1772,7 @@ static PyObject *File_FSMakeFSSpec(PyObject *_self, PyObject *_args)
&spec);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
- PyMac_BuildFSSpec, &spec);
- return _res;
-}
-
-static PyObject *File_FSpOpenDF(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- SInt8 permission;
- short refNum;
- if (!PyArg_ParseTuple(_args, "O&b",
- PyMac_GetFSSpec, &spec,
- &permission))
- return NULL;
- _err = FSpOpenDF(&spec,
- permission,
- &refNum);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("h",
- refNum);
- return _res;
-}
-
-static PyObject *File_FSpOpenRF(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- SInt8 permission;
- short refNum;
- if (!PyArg_ParseTuple(_args, "O&b",
- PyMac_GetFSSpec, &spec,
- &permission))
- return NULL;
- _err = FSpOpenRF(&spec,
- permission,
- &refNum);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("h",
- refNum);
- return _res;
-}
-
-static PyObject *File_FSpCreate(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- OSType creator;
- OSType fileType;
- ScriptCode scriptTag;
- if (!PyArg_ParseTuple(_args, "O&O&O&h",
- PyMac_GetFSSpec, &spec,
- PyMac_GetOSType, &creator,
- PyMac_GetOSType, &fileType,
- &scriptTag))
- return NULL;
- _err = FSpCreate(&spec,
- creator,
- fileType,
- scriptTag);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpDirCreate(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- ScriptCode scriptTag;
- long createdDirID;
- if (!PyArg_ParseTuple(_args, "O&h",
- PyMac_GetFSSpec, &spec,
- &scriptTag))
- return NULL;
- _err = FSpDirCreate(&spec,
- scriptTag,
- &createdDirID);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("l",
- createdDirID);
- return _res;
-}
-
-static PyObject *File_FSpDelete(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &spec))
- return NULL;
- _err = FSpDelete(&spec);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpGetFInfo(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- FInfo fndrInfo;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &spec))
- return NULL;
- _err = FSpGetFInfo(&spec,
- &fndrInfo);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildFInfo, &fndrInfo);
- return _res;
-}
-
-static PyObject *File_FSpSetFInfo(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- FInfo fndrInfo;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &spec,
- PyMac_GetFInfo, &fndrInfo))
- return NULL;
- _err = FSpSetFInfo(&spec,
- &fndrInfo);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpSetFLock(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &spec))
- return NULL;
- _err = FSpSetFLock(&spec);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpRstFLock(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &spec))
- return NULL;
- _err = FSpRstFLock(&spec);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpRename(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec spec;
- Str255 newName;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &spec,
- PyMac_GetStr255, newName))
- return NULL;
- _err = FSpRename(&spec,
- newName);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpCatMove(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec source;
- FSSpec dest;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &source,
- PyMac_GetFSSpec, &dest))
- return NULL;
- _err = FSpCatMove(&source,
- &dest);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpExchangeFiles(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec source;
- FSSpec dest;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSSpec, &source,
- PyMac_GetFSSpec, &dest))
- return NULL;
- _err = FSpExchangeFiles(&source,
- &dest);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSpMakeFSRef(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSSpec source;
- FSRef newRef;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSSpec, &source))
- return NULL;
- _err = FSpMakeFSRef(&source,
- &newRef);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildFSRef, &newRef);
- return _res;
-}
-
-static PyObject *File_FSMakeFSRefUnicode(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef parentRef;
- UniChar *nameLength__in__;
- UniCharCount nameLength__len__;
- int nameLength__in_len__;
- TextEncoding textEncodingHint;
- FSRef newRef;
- if (!PyArg_ParseTuple(_args, "O&u#l",
- PyMac_GetFSRef, &parentRef,
- &nameLength__in__, &nameLength__in_len__,
- &textEncodingHint))
- return NULL;
- nameLength__len__ = nameLength__in_len__;
- _err = FSMakeFSRefUnicode(&parentRef,
- nameLength__len__, nameLength__in__,
- textEncodingHint,
- &newRef);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildFSRef, &newRef);
- return _res;
-}
-
-static PyObject *File_FSCompareFSRefs(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref1;
- FSRef ref2;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSRef, &ref1,
- PyMac_GetFSRef, &ref2))
- return NULL;
- _err = FSCompareFSRefs(&ref1,
- &ref2);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSDeleteObject(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSRef, &ref))
- return NULL;
- _err = FSDeleteObject(&ref);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSMoveObject(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- FSRef destDirectory;
- FSRef newRef;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSRef, &ref,
- PyMac_GetFSRef, &destDirectory))
- return NULL;
- _err = FSMoveObject(&ref,
- &destDirectory,
- &newRef);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildFSRef, &newRef);
- return _res;
-}
-
-static PyObject *File_FSExchangeObjects(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- FSRef destRef;
- if (!PyArg_ParseTuple(_args, "O&O&",
- PyMac_GetFSRef, &ref,
- PyMac_GetFSRef, &destRef))
- return NULL;
- _err = FSExchangeObjects(&ref,
- &destRef);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSRenameUnicode(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- UniChar *nameLength__in__;
- UniCharCount nameLength__len__;
- int nameLength__in_len__;
- TextEncoding textEncodingHint;
- FSRef newRef;
- if (!PyArg_ParseTuple(_args, "O&u#l",
- PyMac_GetFSRef, &ref,
- &nameLength__in__, &nameLength__in_len__,
- &textEncodingHint))
- return NULL;
- nameLength__len__ = nameLength__in_len__;
- _err = FSRenameUnicode(&ref,
- nameLength__len__, nameLength__in__,
- textEncodingHint,
- &newRef);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("O&",
- PyMac_BuildFSRef, &newRef);
- return _res;
-}
-
-static PyObject *File_FSCreateFork(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- UniChar *forkNameLength__in__;
- UniCharCount forkNameLength__len__;
- int forkNameLength__in_len__;
- if (!PyArg_ParseTuple(_args, "O&u#",
- PyMac_GetFSRef, &ref,
- &forkNameLength__in__, &forkNameLength__in_len__))
- return NULL;
- forkNameLength__len__ = forkNameLength__in_len__;
- _err = FSCreateFork(&ref,
- forkNameLength__len__, forkNameLength__in__);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSDeleteFork(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- UniChar *forkNameLength__in__;
- UniCharCount forkNameLength__len__;
- int forkNameLength__in_len__;
- if (!PyArg_ParseTuple(_args, "O&u#",
- PyMac_GetFSRef, &ref,
- &forkNameLength__in__, &forkNameLength__in_len__))
- return NULL;
- forkNameLength__len__ = forkNameLength__in_len__;
- _err = FSDeleteFork(&ref,
- forkNameLength__len__, forkNameLength__in__);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-
-static PyObject *File_FSOpenFork(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSErr _err;
- FSRef ref;
- UniChar *forkNameLength__in__;
- UniCharCount forkNameLength__len__;
- int forkNameLength__in_len__;
- SInt8 permissions;
- SInt16 forkRefNum;
- if (!PyArg_ParseTuple(_args, "O&u#b",
- PyMac_GetFSRef, &ref,
- &forkNameLength__in__, &forkNameLength__in_len__,
- &permissions))
- return NULL;
- forkNameLength__len__ = forkNameLength__in_len__;
- _err = FSOpenFork(&ref,
- forkNameLength__len__, forkNameLength__in__,
- permissions,
- &forkRefNum);
- if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("h",
- forkRefNum);
+ FSSpec_New, &spec);
return _res;
}
@@ -1210,37 +1954,13 @@ static PyObject *File_FSPathMakeRef(PyObject *_self, PyObject *_args)
&isDirectory);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&b",
- PyMac_BuildFSRef, &ref,
+ FSRef_New, &ref,
isDirectory);
return _res;
}
#if TARGET_API_MAC_OSX
-static PyObject *File_FNNotify(PyObject *_self, PyObject *_args)
-{
- PyObject *_res = NULL;
- OSStatus _err;
- FSRef ref;
- FNMessage message;
- OptionBits flags;
- if (!PyArg_ParseTuple(_args, "O&ll",
- PyMac_GetFSRef, &ref,
- &message,
- &flags))
- return NULL;
- _err = FNNotify(&ref,
- message,
- flags);
- if (_err != noErr) return PyMac_Error(_err);
- Py_INCREF(Py_None);
- _res = Py_None;
- return _res;
-}
-#endif
-
-#if TARGET_API_MAC_OSX
-
static PyObject *File_FNNotifyByPath(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@@ -1284,26 +2004,157 @@ static PyObject *File_FNNotifyAll(PyObject *_self, PyObject *_args)
}
#endif
-static PyObject *File_FSRefMakePath(PyObject *_self, PyObject *_args)
+static PyObject *File_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
+ OSErr _err;
+ char *fullPath__in__;
+ int fullPath__len__;
+ int fullPath__in_len__;
+ Str32 zoneName;
+ Str31 serverName;
+ AliasHandle alias;
+ if (!PyArg_ParseTuple(_args, "s#O&O&",
+ &fullPath__in__, &fullPath__in_len__,
+ PyMac_GetStr255, zoneName,
+ PyMac_GetStr255, serverName))
+ return NULL;
+ fullPath__len__ = fullPath__in_len__;
+ _err = NewAliasMinimalFromFullPath(fullPath__len__, fullPath__in__,
+ zoneName,
+ serverName,
+ &alias);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ Alias_New, alias);
+ return _res;
+}
- OSStatus _err;
- FSRef ref;
-#define MAXPATHNAME 1024
- UInt8 path[MAXPATHNAME];
- UInt32 maxPathSize = MAXPATHNAME;
+static PyObject *File_ResolveAliasFile(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec theSpec;
+ Boolean resolveAliasChains;
+ Boolean targetIsFolder;
+ Boolean wasAliased;
+ if (!PyArg_ParseTuple(_args, "O&b",
+ FSSpec_Convert, &theSpec,
+ &resolveAliasChains))
+ return NULL;
+ _err = ResolveAliasFile(&theSpec,
+ resolveAliasChains,
+ &targetIsFolder,
+ &wasAliased);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&bb",
+ FSSpec_New, &theSpec,
+ targetIsFolder,
+ wasAliased);
+ return _res;
+}
- if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSRef, &ref))
+static PyObject *File_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec theSpec;
+ Boolean resolveAliasChains;
+ Boolean targetIsFolder;
+ Boolean wasAliased;
+ unsigned long mountFlags;
+ if (!PyArg_ParseTuple(_args, "O&bl",
+ FSSpec_Convert, &theSpec,
+ &resolveAliasChains,
+ &mountFlags))
return NULL;
- _err = FSRefMakePath(&ref,
- path,
- maxPathSize);
+ _err = ResolveAliasFileWithMountFlags(&theSpec,
+ resolveAliasChains,
+ &targetIsFolder,
+ &wasAliased,
+ mountFlags);
if (_err != noErr) return PyMac_Error(_err);
- _res = Py_BuildValue("s", path);
+ _res = Py_BuildValue("O&bb",
+ FSSpec_New, &theSpec,
+ targetIsFolder,
+ wasAliased);
+ return _res;
+}
+
+static PyObject *File_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSSpec theSpec;
+ Boolean resolveAliasChains;
+ Boolean targetIsFolder;
+ Boolean wasAliased;
+ unsigned long mountFlags;
+ if (!PyArg_ParseTuple(_args, "O&bl",
+ FSSpec_Convert, &theSpec,
+ &resolveAliasChains,
+ &mountFlags))
+ return NULL;
+ _err = ResolveAliasFileWithMountFlagsNoUI(&theSpec,
+ resolveAliasChains,
+ &targetIsFolder,
+ &wasAliased,
+ mountFlags);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&bb",
+ FSSpec_New, &theSpec,
+ targetIsFolder,
+ wasAliased);
return _res;
+}
+static PyObject *File_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef theRef;
+ Boolean resolveAliasChains;
+ Boolean targetIsFolder;
+ Boolean wasAliased;
+ unsigned long mountFlags;
+ if (!PyArg_ParseTuple(_args, "bl",
+ &resolveAliasChains,
+ &mountFlags))
+ return NULL;
+ _err = FSResolveAliasFileWithMountFlags(&theRef,
+ resolveAliasChains,
+ &targetIsFolder,
+ &wasAliased,
+ mountFlags);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&bb",
+ FSRef_New, &theRef,
+ targetIsFolder,
+ wasAliased);
+ return _res;
+}
+
+static PyObject *File_FSResolveAliasFile(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ FSRef theRef;
+ Boolean resolveAliasChains;
+ Boolean targetIsFolder;
+ Boolean wasAliased;
+ if (!PyArg_ParseTuple(_args, "b",
+ &resolveAliasChains))
+ return NULL;
+ _err = FSResolveAliasFile(&theRef,
+ resolveAliasChains,
+ &targetIsFolder,
+ &wasAliased);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&bb",
+ FSRef_New, &theRef,
+ targetIsFolder,
+ wasAliased);
+ return _res;
}
static PyMethodDef File_methods[] = {
@@ -1357,50 +2208,6 @@ static PyMethodDef File_methods[] = {
PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, long newDirID, Str255 newName) -> None")},
{"FSMakeFSSpec", (PyCFunction)File_FSMakeFSSpec, 1,
PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FSSpec spec)")},
- {"FSpOpenDF", (PyCFunction)File_FSpOpenDF, 1,
- PyDoc_STR("(FSSpec spec, SInt8 permission) -> (short refNum)")},
- {"FSpOpenRF", (PyCFunction)File_FSpOpenRF, 1,
- PyDoc_STR("(FSSpec spec, SInt8 permission) -> (short refNum)")},
- {"FSpCreate", (PyCFunction)File_FSpCreate, 1,
- PyDoc_STR("(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None")},
- {"FSpDirCreate", (PyCFunction)File_FSpDirCreate, 1,
- PyDoc_STR("(FSSpec spec, ScriptCode scriptTag) -> (long createdDirID)")},
- {"FSpDelete", (PyCFunction)File_FSpDelete, 1,
- PyDoc_STR("(FSSpec spec) -> None")},
- {"FSpGetFInfo", (PyCFunction)File_FSpGetFInfo, 1,
- PyDoc_STR("(FSSpec spec) -> (FInfo fndrInfo)")},
- {"FSpSetFInfo", (PyCFunction)File_FSpSetFInfo, 1,
- PyDoc_STR("(FSSpec spec, FInfo fndrInfo) -> None")},
- {"FSpSetFLock", (PyCFunction)File_FSpSetFLock, 1,
- PyDoc_STR("(FSSpec spec) -> None")},
- {"FSpRstFLock", (PyCFunction)File_FSpRstFLock, 1,
- PyDoc_STR("(FSSpec spec) -> None")},
- {"FSpRename", (PyCFunction)File_FSpRename, 1,
- PyDoc_STR("(FSSpec spec, Str255 newName) -> None")},
- {"FSpCatMove", (PyCFunction)File_FSpCatMove, 1,
- PyDoc_STR("(FSSpec source, FSSpec dest) -> None")},
- {"FSpExchangeFiles", (PyCFunction)File_FSpExchangeFiles, 1,
- PyDoc_STR("(FSSpec source, FSSpec dest) -> None")},
- {"FSpMakeFSRef", (PyCFunction)File_FSpMakeFSRef, 1,
- PyDoc_STR("(FSSpec source) -> (FSRef newRef)")},
- {"FSMakeFSRefUnicode", (PyCFunction)File_FSMakeFSRefUnicode, 1,
- PyDoc_STR("(FSRef parentRef, Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
- {"FSCompareFSRefs", (PyCFunction)File_FSCompareFSRefs, 1,
- PyDoc_STR("(FSRef ref1, FSRef ref2) -> None")},
- {"FSDeleteObject", (PyCFunction)File_FSDeleteObject, 1,
- PyDoc_STR("(FSRef ref) -> None")},
- {"FSMoveObject", (PyCFunction)File_FSMoveObject, 1,
- PyDoc_STR("(FSRef ref, FSRef destDirectory) -> (FSRef newRef)")},
- {"FSExchangeObjects", (PyCFunction)File_FSExchangeObjects, 1,
- PyDoc_STR("(FSRef ref, FSRef destRef) -> None")},
- {"FSRenameUnicode", (PyCFunction)File_FSRenameUnicode, 1,
- PyDoc_STR("(FSRef ref, Buffer nameLength, TextEncoding textEncodingHint) -> (FSRef newRef)")},
- {"FSCreateFork", (PyCFunction)File_FSCreateFork, 1,
- PyDoc_STR("(FSRef ref, Buffer forkNameLength) -> None")},
- {"FSDeleteFork", (PyCFunction)File_FSDeleteFork, 1,
- PyDoc_STR("(FSRef ref, Buffer forkNameLength) -> None")},
- {"FSOpenFork", (PyCFunction)File_FSOpenFork, 1,
- PyDoc_STR("(FSRef ref, Buffer forkNameLength, SInt8 permissions) -> (SInt16 forkRefNum)")},
{"FSGetForkPosition", (PyCFunction)File_FSGetForkPosition, 1,
PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 position)")},
{"FSSetForkPosition", (PyCFunction)File_FSSetForkPosition, 1,
@@ -1423,11 +2230,6 @@ static PyMethodDef File_methods[] = {
PyDoc_STR("(UInt8 * path) -> (FSRef ref, Boolean isDirectory)")},
#if TARGET_API_MAC_OSX
- {"FNNotify", (PyCFunction)File_FNNotify, 1,
- PyDoc_STR("(FSRef ref, FNMessage message, OptionBits flags) -> None")},
-#endif
-
-#if TARGET_API_MAC_OSX
{"FNNotifyByPath", (PyCFunction)File_FNNotifyByPath, 1,
PyDoc_STR("(UInt8 * path, FNMessage message, OptionBits flags) -> None")},
#endif
@@ -1436,13 +2238,113 @@ static PyMethodDef File_methods[] = {
{"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
#endif
- {"FSRefMakePath", (PyCFunction)File_FSRefMakePath, 1,
- PyDoc_STR("(FSRef) -> string")},
+ {"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
+ PyDoc_STR("(Buffer fullPath, Str32 zoneName, Str31 serverName) -> (AliasHandle alias)")},
+ {"ResolveAliasFile", (PyCFunction)File_ResolveAliasFile, 1,
+ PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
+ {"ResolveAliasFileWithMountFlags", (PyCFunction)File_ResolveAliasFileWithMountFlags, 1,
+ PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
+ {"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
+ PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
+ {"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
+ PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
+ {"FSResolveAliasFile", (PyCFunction)File_FSResolveAliasFile, 1,
+ PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
{NULL, NULL, 0}
};
+static int
+myPyMac_GetFSSpec(PyObject *v, FSSpec *spec)
+{
+ Str255 path;
+ short refnum;
+ long parid;
+ OSErr err;
+ FSRef fsr;
+
+ if (FSSpec_Check(v)) {
+ *spec = ((FSSpecObject *)v)->ob_itself;
+ return 1;
+ }
+
+ if (PyArg_Parse(v, "(hlO&)",
+ &refnum, &parid, PyMac_GetStr255, &path)) {
+ err = FSMakeFSSpec(refnum, parid, path, spec);
+ if ( err && err != fnfErr ) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_Clear();
+#if !TARGET_API_MAC_OSX
+ /* On OS9 we now try a pathname */
+ if ( PyString_Check(v) ) {
+ /* It's a pathname */
+ if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
+ return 0;
+ refnum = 0; /* XXXX Should get CurWD here?? */
+ parid = 0;
+ err = FSMakeFSSpec(refnum, parid, path, spec);
+ if ( err && err != fnfErr ) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_Clear();
+#endif
+ /* Otherwise we try to go via an FSRef. On OSX we go all the way,
+ ** on OS9 we accept only a real FSRef object
+ */
+#if TARGET_API_MAX_OSX
+ if ( myPyMac_GetFSRef(v, &fsr) >= 0 ) {
+#else
+ if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
+#endif
+ err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL);
+ if (err != noErr) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_SetString(PyExc_TypeError, "FSSpec, FSRef, pathname or (refnum, parid, path) required");
+ return 0;
+}
+
+static int
+myPyMac_GetFSRef(PyObject *v, FSRef *fsr)
+{
+ if (FSRef_Check(v)) {
+ *fsr = ((FSRefObject *)v)->ob_itself;
+ return 1;
+ }
+
+#if !TARGET_API_MAC_OSX
+ /* On OSX we now try a pathname */
+ if ( PyString_Check(args) ) {
+ OSStatus err;
+ if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
+ PyErr_Mac(ErrorObject, err);
+ return 0;
+ }
+ return 1;
+ }
+ /* XXXX Should try unicode here too */
+#endif
+ /* Otherwise we try to go via an FSSpec */
+ if (FSSpec_Check(v)) {
+ if (FSpMakeFSRef(&((FSSpecObject *)v)->ob_itself, fsr))
+ return 1;
+ return 0;
+ }
+ PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
+ return 0;
+}
+
void init_File(void)
{
@@ -1458,6 +2360,24 @@ void init_File(void)
if (File_Error == NULL ||
PyDict_SetItemString(d, "Error", File_Error) != 0)
return;
+ Alias_Type.ob_type = &PyType_Type;
+ Py_INCREF(&Alias_Type);
+ PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
+ /* Backward-compatible name */
+ Py_INCREF(&Alias_Type);
+ PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
+ FSSpec_Type.ob_type = &PyType_Type;
+ Py_INCREF(&FSSpec_Type);
+ PyModule_AddObject(m, "FSSpec", (PyObject *)&FSSpec_Type);
+ /* Backward-compatible name */
+ Py_INCREF(&FSSpec_Type);
+ PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
+ FSRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&FSRef_Type);
+ PyModule_AddObject(m, "FSRef", (PyObject *)&FSRef_Type);
+ /* Backward-compatible name */
+ Py_INCREF(&FSRef_Type);
+ PyModule_AddObject(m, "FSRefType", (PyObject *)&FSRef_Type);
}
/* ======================== End module _File ======================== */
diff --git a/Mac/Modules/file/filescan.py b/Mac/Modules/file/filescan.py
index 454fefc7..0195fea 100644
--- a/Mac/Modules/file/filescan.py
+++ b/Mac/Modules/file/filescan.py
@@ -8,10 +8,9 @@ from scantools import Scanner_OSX
LONG = "Files"
SHORT = "file"
-OBJECT = "NOTUSED"
def main():
- input = LONG + ".h"
+ input = ["Files.h", "Aliases.h"]
output = SHORT + "gen.py"
defsoutput = TOOLBOXDIR + LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
@@ -30,11 +29,24 @@ class MyScanner(Scanner_OSX):
classname = "Function"
listname = "functions"
if arglist:
+ # Funny special case
+ if len(arglist) > 2:
+ t, n, m = arglist[1]
+ if t == "AliasHandle" and m == "InMode":
+ classname = "Arg2MethodGenerator"
+ listname = "alias_methods"
+ return classname, listname
+ # Normal cases
t, n, m = arglist[0]
- # This is non-functional today
- if t == OBJECT and m == "InMode":
+ if t == "AliasHandle" and m == "InMode":
classname = "Method"
- listname = "methods"
+ listname = "alias_methods"
+ if t == "FSSpec_ptr" and m == "InMode":
+ classname = "Method"
+ listname = "fsspec_methods"
+ if t == "FSRef_ptr" and m == "InMode":
+ classname = "Method"
+ listname = "fsref_methods"
return classname, listname
def makeblacklistnames(self):
@@ -45,6 +57,9 @@ class MyScanner(Scanner_OSX):
"kFSIterateReserved",
"FSRefMakePath", # Do this manually
+# "ResolveAlias", # Do this manually
+# "ResolveAliasWithMountFlags", # Do this manually
+# "FollowFinderAlias", # Do this manually
"FSRead", # Couldn't be bothered
"FSWrite", # ditto
@@ -128,7 +143,8 @@ class MyScanner(Scanner_OSX):
"IOCompletionProcPtr", # proc pointer
"IOCompletionUPP", # Proc pointer
-
+ "AliasFilterProcPtr",
+ "AliasFilterUPP",
]
@@ -144,6 +160,18 @@ class MyScanner(Scanner_OSX):
('UniChar_ptr', '*', 'InMode')],
[('UnicodeReverseInBuffer', '*', 'InMode')]
),
+ # Wrong guess
+ ([('Str63', 'theString', 'InMode')],
+ [('Str63', 'theString', 'OutMode')]),
+
+ # Yet another way to give a pathname:-)
+ ([('short', 'fullPathLength', 'InMode'),
+ ('void_ptr', 'fullPath', 'InMode')],
+ [('FullPathName', 'fullPath', 'InMode')]),
+
+ # Various ResolveAliasFileXXXX functions
+ ([('FSSpec', 'theSpec', 'OutMode')],
+ [('FSSpec_ptr', 'theSpec', 'InOutMode')]),
]
diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py
index f916c34..c431d42 100644
--- a/Mac/Modules/file/filesupport.py
+++ b/Mac/Modules/file/filesupport.py
@@ -6,7 +6,7 @@
import string
# Declarations that change for each manager
-MACHEADERFILE = 'Files.h' # The Apple header file
+#MACHEADERFILE = 'Files.h' # The Apple header file
MODNAME = '_File' # The name of the module
# The following is *usually* unchanged but may still require tuning
@@ -16,37 +16,46 @@ OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
-# Create the type objects
-#ConstStrFileNameParam = ConstStr255Param
-#StrFileName = Str255
-#FolderClass = OSTypeType("FolderClass")
-# FolderDesc
-#FolderDescFlags = Type("FolderDescFlags", "l")
-#FolderLocation = OSTypeType("FolderLocation")
-# FolderRouting
-#FolderType = OSTypeType("FolderType")
-#RoutingFlags = Type("RoutingFlags", "l")
-
-class UniCharCountBuffer(InputOnlyType):
- pass
+# Various integers:
+SInt64 = Type("SInt64", "L")
+UInt64 = Type("UInt64", "L")
+FNMessage = Type("FNMessage", "l")
+FSAllocationFlags = Type("FSAllocationFlags", "H")
+FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
+FSIteratorFlags = Type("FSIteratorFlags", "l")
+FSVolumeRefNum = Type("FSVolumeRefNum", "h")
+AliasInfoType = Type("AliasInfoType", "h")
-#CatPositionRec
+# Various types of strings:
+#class UniCharCountBuffer(InputOnlyType):
+# pass
+class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType):
+ pass
+FullPathName = VarReverseInputBufferType()
+ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255")
+ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255")
ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
+Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
+
+HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
+UInt8_ptr = InputOnlyType("UInt8 *", "s")
+
+# Other types:
FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
-FNMessage = Type("FNMessage", "l")
-FSAllocationFlags = Type("FSAllocationFlags", "H")
+AliasHandle = OpaqueByValueType("AliasHandle", "Alias")
+FSSpec = OpaqueType("FSSpec", "FSSpec")
+FSSpec_ptr = OpaqueType("FSSpec", "FSSpec")
+FSRef = OpaqueType("FSRef", "FSRef")
+FSRef_ptr = OpaqueType("FSRef", "FSRef")
+
+# To be done:
+#CatPositionRec
#FSCatalogInfo
-FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
#FSForkInfo
#FSIterator
-FSIteratorFlags = Type("FSIteratorFlags", "l")
#FSVolumeInfo
-FSVolumeRefNum = Type("FSVolumeRefNum", "h")
-HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
-SInt64 = Type("SInt64", "L")
-UInt64 = Type("UInt64", "L")
-UInt8_ptr = InputOnlyType("UInt8 *", "s")
+#FSSpecArrayPtr
includestuff = includestuff + """
#ifdef WITHOUT_FRAMEWORKS
@@ -55,6 +64,16 @@ includestuff = includestuff + """
#include <Carbon/Carbon.h>
#endif
+/* Forward declarations */
+extern PyObject *FSRef_New(FSRef *itself);
+extern PyObject *FSSpec_New(FSSpec *itself);
+extern PyObject *Alias_New(AliasHandle itself);
+extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
+extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
+extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
+static int myPyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+static int myPyMac_GetFSRef(PyObject *v, FSRef *fsr);
+
/*
** Parse/generate objsect
*/
@@ -65,19 +84,6 @@ PyMac_BuildHFSUniStr255(HFSUniStr255 *itself)
return Py_BuildValue("u#", itself->unicode, itself->length);
}
-#if 0
-static int
-PyMac_GetHFSUniStr255(PyObject *v, HFSUniStr255 *itself)
-{
- return PyArg_ParseTuple(v, "O&O&O&O&O&",
- PyMac_GetFixed, &itself->ascent,
- PyMac_GetFixed, &itself->descent,
- PyMac_GetFixed, &itself->leading,
- PyMac_GetFixed, &itself->widMax,
- ResObj_Convert, &itself->wTabHandle);
-}
-#endif
-
/*
** Parse/generate objsect
*/
@@ -103,35 +109,240 @@ PyMac_GetFInfo(PyObject *v, FInfo *itself)
PyMac_GetPoint, &itself->fdLocation,
&itself->fdFldr);
}
+"""
+
+finalstuff = finalstuff + """
+static int
+myPyMac_GetFSSpec(PyObject *v, FSSpec *spec)
+{
+ Str255 path;
+ short refnum;
+ long parid;
+ OSErr err;
+ FSRef fsr;
+
+ if (FSSpec_Check(v)) {
+ *spec = ((FSSpecObject *)v)->ob_itself;
+ return 1;
+ }
+
+ if (PyArg_Parse(v, "(hlO&)",
+ &refnum, &parid, PyMac_GetStr255, &path)) {
+ err = FSMakeFSSpec(refnum, parid, path, spec);
+ if ( err && err != fnfErr ) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_Clear();
+#if !TARGET_API_MAC_OSX
+ /* On OS9 we now try a pathname */
+ if ( PyString_Check(v) ) {
+ /* It's a pathname */
+ if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
+ return 0;
+ refnum = 0; /* XXXX Should get CurWD here?? */
+ parid = 0;
+ err = FSMakeFSSpec(refnum, parid, path, spec);
+ if ( err && err != fnfErr ) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_Clear();
+#endif
+ /* Otherwise we try to go via an FSRef. On OSX we go all the way,
+ ** on OS9 we accept only a real FSRef object
+ */
+#if TARGET_API_MAX_OSX
+ if ( myPyMac_GetFSRef(v, &fsr) >= 0 ) {
+#else
+ if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
+#endif
+ err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL);
+ if (err != noErr) {
+ PyMac_Error(err);
+ return 0;
+ }
+ return 1;
+ }
+ PyErr_SetString(PyExc_TypeError, "FSSpec, FSRef, pathname or (refnum, parid, path) required");
+ return 0;
+}
+
+static int
+myPyMac_GetFSRef(PyObject *v, FSRef *fsr)
+{
+ if (FSRef_Check(v)) {
+ *fsr = ((FSRefObject *)v)->ob_itself;
+ return 1;
+ }
+#if !TARGET_API_MAC_OSX
+ /* On OSX we now try a pathname */
+ if ( PyString_Check(args) ) {
+ OSStatus err;
+ if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
+ PyErr_Mac(ErrorObject, err);
+ return 0;
+ }
+ return 1;
+ }
+ /* XXXX Should try unicode here too */
+#endif
+ /* Otherwise we try to go via an FSSpec */
+ if (FSSpec_Check(v)) {
+ if (FSpMakeFSRef(&((FSSpecObject *)v)->ob_itself, fsr))
+ return 1;
+ return 0;
+ }
+ PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
+ return 0;
+}
"""
execfile(string.lower(MODPREFIX) + 'typetest.py')
+# Our object types:
+class FSSpecDefinition(PEP253Mixin, GlobalObjectDefinition):
+ def __init__(self, name, prefix, itselftype):
+ GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
+ self.argref = "*" # Store FSSpecs, but pass them by address
+
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ def output_tp_newBody(self):
+ Output("PyObject *self;");
+ Output()
+ Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
+ self.objecttype, self.objecttype)
+ Output("return self;")
+
+ def output_tp_initBody(self):
+ Output("PyObject *v;")
+ Output("char *kw[] = {\"itself\", 0};")
+ Output()
+ Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
+ Output("return -1;")
+ Output("if (myPyMac_GetFSSpec(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
+ Output("return -1;")
+
+class FSRefDefinition(PEP253Mixin, GlobalObjectDefinition):
+ def __init__(self, name, prefix, itselftype):
+ GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
+ self.argref = "*" # Store FSRefs, but pass them by address
+
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ def output_tp_newBody(self):
+ Output("PyObject *self;");
+ Output()
+ Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
+ self.objecttype, self.objecttype)
+ Output("return self;")
+
+ def output_tp_initBody(self):
+ Output("PyObject *v;")
+ Output("char *kw[] = {\"itself\", 0};")
+ Output()
+ Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
+ Output("return -1;")
+ Output("if (myPyMac_GetFSRef(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
+ Output("return -1;")
+
+class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
+ # XXXX Should inherit from resource?
+
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("void (*ob_freeit)(%s ptr);", self.itselftype)
+
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_freeit = NULL;")
+
+ def outputCleanupStructMembers(self):
+ Output("if (self->ob_freeit && self->ob_itself)")
+ OutLbrace()
+ Output("self->ob_freeit(self->ob_itself);")
+ OutRbrace()
+ Output("self->ob_itself = NULL;")
+
+ def output_tp_newBody(self):
+ Output("PyObject *self;");
+ Output()
+ Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
+ Output("return self;")
+
+ def output_tp_initBody(self):
+ Output("%s itself;", self.itselftype);
+ Output("char *kw[] = {\"itself\", 0};")
+ Output()
+ Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
+ self.prefix)
+ OutLbrace()
+ Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+ Output("return 0;")
+ OutRbrace()
+ Output("return -1;")
+
+# Alias methods come in two flavors: those with the alias as arg1 and
+# those with the alias as arg 2.
+class Arg2MethodGenerator(MethodGenerator):
+ """Similar to MethodGenerator, but has self as second argument"""
+
+ def parseArgumentList(self, args):
+ args0, arg1, argsrest = args[:1], args[1], args[2:]
+ t0, n0, m0 = arg1
+ args = args0 + argsrest
+ if m0 != InMode:
+ raise ValueError, "method's 'self' must be 'InMode'"
+ self.itself = Variable(t0, "_self->ob_itself", SelfMode)
+ FunctionGenerator.parseArgumentList(self, args)
+ self.argumentList.insert(2, self.itself)
+
# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+aliasobject = AliasDefinition('Alias', 'Alias', 'AliasHandle')
+fsspecobject = FSSpecDefinition('FSSpec', 'FSSpec', 'FSSpec')
+fsrefobject = FSRefDefinition('FSRef', 'FSRef', 'FSRef')
+
+module.addobject(aliasobject)
+module.addobject(fsspecobject)
+module.addobject(fsrefobject)
+
# Create the generator classes used to populate the lists
Function = OSErrFunctionGenerator
+Method = OSErrMethodGenerator
# Create and populate the lists
functions = []
+alias_methods = []
+fsref_methods = []
+fsspec_methods = []
execfile(INPUTFILE)
# Manual generators:
FSRefMakePath_body = """
OSStatus _err;
-FSRef ref;
#define MAXPATHNAME 1024
UInt8 path[MAXPATHNAME];
UInt32 maxPathSize = MAXPATHNAME;
-if (!PyArg_ParseTuple(_args, "O&",
- PyMac_GetFSRef, &ref))
- return NULL;
-_err = FSRefMakePath(&ref,
+_err = FSRefMakePath(&_self->ob_itself,
path,
maxPathSize);
if (_err != noErr) return PyMac_Error(_err);
@@ -139,12 +350,16 @@ _res = Py_BuildValue("s", path);
return _res;
"""
f = ManualGenerator("FSRefMakePath", FSRefMakePath_body)
-f.docstring = lambda: "(FSRef) -> string"
-functions.append(f)
+f.docstring = lambda: "() -> string"
+fsref_methods.append(f)
+
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
+for f in alias_methods: aliasobject.add(f)
+for f in fsspec_methods: fsspecobject.add(f)
+for f in fsref_methods: fsrefobject.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)