Issue 706585: Expose FinderInfo in FSCatalogInfo (original) (raw)

Logged In: YES user_id=747684

Here's a patch for _Filemodule.c which exposes the finderInfo. It assumes it's always a FileInfo, which is not exactly right -- you may want to do things a bit more carefully.

Also, someone with more knowledge of bgen than me will have to figure out what should really be patched and how.

--- _Filemodule.c.orig Tue Oct 14 19:04:56 2003 +++ _Filemodule.c Sun Sep 21 13:41:04 2003 @@ -1,5 +1,10 @@ +/* + * This is a hacked version of _Filemodule.c from the Python 2.3 + * distribution to support access to the finderInfo field of the + * FSCatalogInfo data structure. + / / ========================== Module _File ========================== */ #include "Python.h" @@ -101,10 +106,23 @@ return Py_BuildValue("u#", itself->unicode, itself->length); } static PyObject File_Error; +/ ----------------------- Object type FInfo declarations ------------------------ */ + +static PyTypeObject FInfo_Type; + +#define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type)) + +typedef struct FInfoObject { + PyObject_HEAD + FInfo ob_itself; +} FInfoObject; + +static PyObject *FInfo_New(FInfo itself); + / ------------------- Object type FSCatalogInfo -------------------- */ static PyTypeObject FSCatalogInfo_Type; #define FSCatalogInfo_Check(x) ((x)->ob_type == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type)) @@ -329,10 +347,25 @@ { return PyArg_Parse(v, "b", &self->ob_itself.userPrivileges)-1; return 0; } +static PyObject *FSCatalogInfo_get_finderInfo(FSCatalogInfoObject *self, void *closure) +{ + return FInfo_New((FInfo *)self->ob_itself.finderInfo); +} + +static int FSCatalogInfo_set_finderInfo(FSCatalogInfoObject *self, PyObject *v, void *closure) +{ + if (!FInfo_Check(v)) { + PyErr_SetString(PyExc_TypeError, "Expected an FInfo object"); + return -1; + } + *(FInfo *)self->ob_itself.finderInfo = ((FInfoObject )v)->ob_itself; + return 0; +} + static PyGetSetDef FSCatalogInfo_getsetlist[] = { {"nodeFlags", (getter)FSCatalogInfo_get_nodeFlags, (setter)FSCatalogInfo_set_nodeFlags, NULL}, {"volume", (getter)FSCatalogInfo_get_volume, (setter)FSCatalogInfo_set_volume, NULL}, {"parentDirID", (getter)FSCatalogInfo_get_parentDirID, (setter)FSCatalogInfo_set_parentDirID, NULL}, {"nodeID", (getter)FSCatalogInfo_get_nodeID, (setter)FSCatalogInfo_set_nodeID, NULL}, @@ -347,10 +380,11 @@ {"dataPhysicalSize", (getter)FSCatalogInfo_get_dataPhysicalSize, (setter)FSCatalogInfo_set_dataPhysicalSize, NULL}, {"rsrcLogicalSize", (getter)FSCatalogInfo_get_rsrcLogicalSize, (setter)FSCatalogInfo_set_rsrcLogicalSize, NULL}, {"rsrcPhysicalSize", (getter)FSCatalogInfo_get_rsrcPhysicalSize, (setter)FSCatalogInfo_set_rsrcPhysicalSize, NULL}, {"sharingFlags", (getter)FSCatalogInfo_get_sharingFlags, (setter)FSCatalogInfo_set_sharingFlags, NULL}, {"userPrivileges", (getter)FSCatalogInfo_get_userPrivileges, (setter)FSCatalogInfo_set_userPrivileges, NULL}, + {"finderInfo", (getter)FSCatalogInfo_get_finderInfo, (setter)FSCatalogInfo_set_finderInfo, NULL}, {NULL, NULL, NULL, NULL}, }; #define FSCatalogInfo_compare NULL @@ -460,20 +494,11 @@ }; / ----------------- End object type FSCatalogInfo ------------------ / -/ ----------------------- Object type FInfo ------------------------ */

-static PyTypeObject FInfo_Type;

-#define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))

-typedef struct FInfoObject { - PyObject_HEAD - FInfo ob_itself; -} FInfoObject; +/* ----------------------- Object type FInfo implementation ------------------------ */

static PyObject *FInfo_New(FInfo *itself) { FInfoObject *it; if (itself == NULL) return PyMac_Error(resNotFound);