PageRenderTime 201ms CodeModel.GetById 62ms app.highlight 127ms RepoModel.GetById 0ms app.codeStats 1ms

/Mac/Modules/file/_Filemodule.c

http://unladen-swallow.googlecode.com/
C | 3410 lines | 3040 code | 322 blank | 48 comment | 380 complexity | cf7ba1a10e4ee6fdbeaf4f9220fe8bfd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1
   2/* ========================== Module _File ========================== */
   3
   4#include "Python.h"
   5
   6
   7
   8#include "pymactoolbox.h"
   9
  10#ifndef HAVE_OSX105_SDK
  11typedef SInt16	FSIORefNum;
  12#endif
  13
  14/* Macro to test whether a weak-loaded CFM function exists */
  15#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
  16        PyErr_SetString(PyExc_NotImplementedError, \
  17        "Not available in this shared library/OS version"); \
  18        return NULL; \
  19    }} while(0)
  20
  21
  22#include <Carbon/Carbon.h>
  23
  24#ifdef USE_TOOLBOX_OBJECT_GLUE
  25
  26#ifndef __LP64__
  27extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
  28extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
  29#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
  30#endif /* __LP64__*/
  31
  32extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
  33extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
  34#define PyMac_BuildFSRef _PyMac_BuildFSRef
  35#define PyMac_GetFSSpec _PyMac_GetFSSpec
  36#define PyMac_GetFSRef _PyMac_GetFSRef
  37
  38#else	/* !USE_TOOLBOX_OBJECT_GLUE */
  39
  40#ifndef __LP64__
  41extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
  42extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
  43#endif /* !__LP64__*/
  44
  45extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
  46extern PyObject *PyMac_BuildFSRef(FSRef *spec);
  47
  48#endif	/* !USE_TOOLBOX_OBJECT_GLUE */
  49
  50/* Forward declarations */
  51static PyObject *FSRef_New(FSRef *itself);
  52#ifndef __LP64__
  53static PyObject *FInfo_New(FInfo *itself);
  54
  55static PyObject *FSSpec_New(FSSpec *itself);
  56#define FSSpec_Convert PyMac_GetFSSpec
  57#endif /* !__LP64__ */
  58
  59static PyObject *Alias_New(AliasHandle itself);
  60#ifndef __LP64__
  61static int FInfo_Convert(PyObject *v, FInfo *p_itself);
  62#endif /* !__LP64__ */
  63#define FSRef_Convert PyMac_GetFSRef
  64static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
  65
  66/*
  67** UTCDateTime records
  68*/
  69static int
  70UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr)
  71{
  72        return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction);
  73}
  74
  75static PyObject *
  76UTCDateTime_New(UTCDateTime *ptr)
  77{
  78        return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction);
  79}
  80
  81/*
  82** Optional fsspec and fsref pointers. None will pass NULL
  83*/
  84#ifndef __LP64__
  85static int
  86myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
  87{
  88        if (v == Py_None) {
  89                *spec = NULL;
  90                return 1;
  91        }
  92        return PyMac_GetFSSpec(v, *spec);
  93}
  94#endif /* !__LP64__ */
  95
  96static int
  97myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
  98{
  99        if (v == Py_None) {
 100                *ref = NULL;
 101                return 1;
 102        }
 103        return PyMac_GetFSRef(v, *ref);
 104}
 105
 106/*
 107** Parse/generate objsect
 108*/
 109static PyObject *
 110PyMac_BuildHFSUniStr255(HFSUniStr255 *itself)
 111{
 112
 113        return Py_BuildValue("u#", itself->unicode, itself->length);
 114}
 115
 116#ifndef __LP64__
 117static OSErr
 118_PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
 119{
 120	FSRef fsr;
 121	OSErr err;
 122
 123	*path = '\0';
 124	err = FSpMakeFSRef(fss, &fsr);
 125	if (err == fnfErr) {
 126		/* FSSpecs can point to non-existing files, fsrefs can't. */
 127		FSSpec fss2;
 128		int tocopy;
 129
 130		err = FSMakeFSSpec(fss->vRefNum, fss->parID,
 131				   (unsigned char*)"", &fss2);
 132		if (err)
 133			return err;
 134		err = FSpMakeFSRef(&fss2, &fsr);
 135		if (err)
 136			return err;
 137		err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len-1);
 138		if (err)
 139			return err;
 140		/* This part is not 100% safe: we append the filename part, but
 141		** I'm not sure that we don't run afoul of the various 8bit
 142		** encodings here. Will have to look this up at some point...
 143		*/
 144		strcat(path, "/");
 145		tocopy = fss->name[0];
 146		if ((strlen(path) + tocopy) >= len)
 147			tocopy = len - strlen(path) - 1;
 148		if (tocopy > 0)
 149			strncat(path, (char*)fss->name+1, tocopy);
 150	}
 151	else {
 152		if (err)
 153			return err;
 154		err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len);
 155		if (err)
 156			return err;
 157	}
 158	return 0;
 159}
 160#endif /* !__LP64__ */
 161
 162
 163static PyObject *File_Error;
 164
 165/* ------------------- Object type FSCatalogInfo -------------------- */
 166
 167static PyTypeObject FSCatalogInfo_Type;
 168
 169#define FSCatalogInfo_Check(x) ((x)->ob_type == &FSCatalogInfo_Type || PyObject_TypeCheck((x), &FSCatalogInfo_Type))
 170
 171typedef struct FSCatalogInfoObject {
 172	PyObject_HEAD
 173	FSCatalogInfo ob_itself;
 174} FSCatalogInfoObject;
 175
 176static PyObject *FSCatalogInfo_New(FSCatalogInfo *itself)
 177{
 178	FSCatalogInfoObject *it;
 179	if (itself == NULL) { Py_INCREF(Py_None); return Py_None; }
 180	it = PyObject_NEW(FSCatalogInfoObject, &FSCatalogInfo_Type);
 181	if (it == NULL) return NULL;
 182	it->ob_itself = *itself;
 183	return (PyObject *)it;
 184}
 185
 186static int FSCatalogInfo_Convert(PyObject *v, FSCatalogInfo *p_itself)
 187{
 188	if (!FSCatalogInfo_Check(v))
 189	{
 190		PyErr_SetString(PyExc_TypeError, "FSCatalogInfo required");
 191		return 0;
 192	}
 193	*p_itself = ((FSCatalogInfoObject *)v)->ob_itself;
 194	return 1;
 195}
 196
 197static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
 198{
 199	/* Cleanup of self->ob_itself goes here */
 200	self->ob_type->tp_free((PyObject *)self);
 201}
 202
 203static PyMethodDef FSCatalogInfo_methods[] = {
 204	{NULL, NULL, 0}
 205};
 206
 207static PyObject *FSCatalogInfo_get_nodeFlags(FSCatalogInfoObject *self, void *closure)
 208{
 209	return Py_BuildValue("H", self->ob_itself.nodeFlags);
 210}
 211
 212static int FSCatalogInfo_set_nodeFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
 213{
 214	return PyArg_Parse(v, "H", &self->ob_itself.nodeFlags)-1;
 215	return 0;
 216}
 217
 218static PyObject *FSCatalogInfo_get_volume(FSCatalogInfoObject *self, void *closure)
 219{
 220	return Py_BuildValue("h", self->ob_itself.volume);
 221}
 222
 223static int FSCatalogInfo_set_volume(FSCatalogInfoObject *self, PyObject *v, void *closure)
 224{
 225	return PyArg_Parse(v, "h", &self->ob_itself.volume)-1;
 226	return 0;
 227}
 228
 229static PyObject *FSCatalogInfo_get_parentDirID(FSCatalogInfoObject *self, void *closure)
 230{
 231	return Py_BuildValue("l", self->ob_itself.parentDirID);
 232}
 233
 234static int FSCatalogInfo_set_parentDirID(FSCatalogInfoObject *self, PyObject *v, void *closure)
 235{
 236	return PyArg_Parse(v, "l", &self->ob_itself.parentDirID)-1;
 237	return 0;
 238}
 239
 240static PyObject *FSCatalogInfo_get_nodeID(FSCatalogInfoObject *self, void *closure)
 241{
 242	return Py_BuildValue("l", self->ob_itself.nodeID);
 243}
 244
 245static int FSCatalogInfo_set_nodeID(FSCatalogInfoObject *self, PyObject *v, void *closure)
 246{
 247	return PyArg_Parse(v, "l", &self->ob_itself.nodeID)-1;
 248	return 0;
 249}
 250
 251static PyObject *FSCatalogInfo_get_createDate(FSCatalogInfoObject *self, void *closure)
 252{
 253	return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.createDate);
 254}
 255
 256static int FSCatalogInfo_set_createDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
 257{
 258	return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.createDate)-1;
 259	return 0;
 260}
 261
 262static PyObject *FSCatalogInfo_get_contentModDate(FSCatalogInfoObject *self, void *closure)
 263{
 264	return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.contentModDate);
 265}
 266
 267static int FSCatalogInfo_set_contentModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
 268{
 269	return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.contentModDate)-1;
 270	return 0;
 271}
 272
 273static PyObject *FSCatalogInfo_get_attributeModDate(FSCatalogInfoObject *self, void *closure)
 274{
 275	return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.attributeModDate);
 276}
 277
 278static int FSCatalogInfo_set_attributeModDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
 279{
 280	return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.attributeModDate)-1;
 281	return 0;
 282}
 283
 284static PyObject *FSCatalogInfo_get_accessDate(FSCatalogInfoObject *self, void *closure)
 285{
 286	return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.accessDate);
 287}
 288
 289static int FSCatalogInfo_set_accessDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
 290{
 291	return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.accessDate)-1;
 292	return 0;
 293}
 294
 295static PyObject *FSCatalogInfo_get_backupDate(FSCatalogInfoObject *self, void *closure)
 296{
 297	return Py_BuildValue("O&", UTCDateTime_New, &self->ob_itself.backupDate);
 298}
 299
 300static int FSCatalogInfo_set_backupDate(FSCatalogInfoObject *self, PyObject *v, void *closure)
 301{
 302	return PyArg_Parse(v, "O&", UTCDateTime_Convert, &self->ob_itself.backupDate)-1;
 303	return 0;
 304}
 305
 306static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
 307{
 308	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
 309	return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
 310}
 311
 312static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
 313{
 314	long userID;
 315	long groupID;
 316	long userAccess;
 317	long mode;
 318	int r;
 319
 320	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
 321
 322	r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
 323	if (!r) {
 324		return -1;
 325	}
 326	info->userID = userID;
 327	info->groupID = groupID;
 328	info->userAccess = userAccess;
 329	info->mode = mode;
 330	return 0;
 331}
 332
 333static PyObject *FSCatalogInfo_get_valence(FSCatalogInfoObject *self, void *closure)
 334{
 335	return Py_BuildValue("l", self->ob_itself.valence);
 336}
 337
 338static int FSCatalogInfo_set_valence(FSCatalogInfoObject *self, PyObject *v, void *closure)
 339{
 340	return PyArg_Parse(v, "l", &self->ob_itself.valence)-1;
 341	return 0;
 342}
 343
 344static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject *self, void *closure)
 345{
 346	return Py_BuildValue("l", self->ob_itself.dataLogicalSize);
 347}
 348
 349static int FSCatalogInfo_set_dataLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
 350{
 351	return PyArg_Parse(v, "l", &self->ob_itself.dataLogicalSize)-1;
 352	return 0;
 353}
 354
 355static PyObject *FSCatalogInfo_get_dataPhysicalSize(FSCatalogInfoObject *self, void *closure)
 356{
 357	return Py_BuildValue("l", self->ob_itself.dataPhysicalSize);
 358}
 359
 360static int FSCatalogInfo_set_dataPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
 361{
 362	return PyArg_Parse(v, "l", &self->ob_itself.dataPhysicalSize)-1;
 363	return 0;
 364}
 365
 366static PyObject *FSCatalogInfo_get_rsrcLogicalSize(FSCatalogInfoObject *self, void *closure)
 367{
 368	return Py_BuildValue("l", self->ob_itself.rsrcLogicalSize);
 369}
 370
 371static int FSCatalogInfo_set_rsrcLogicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
 372{
 373	return PyArg_Parse(v, "l", &self->ob_itself.rsrcLogicalSize)-1;
 374	return 0;
 375}
 376
 377static PyObject *FSCatalogInfo_get_rsrcPhysicalSize(FSCatalogInfoObject *self, void *closure)
 378{
 379	return Py_BuildValue("l", self->ob_itself.rsrcPhysicalSize);
 380}
 381
 382static int FSCatalogInfo_set_rsrcPhysicalSize(FSCatalogInfoObject *self, PyObject *v, void *closure)
 383{
 384	return PyArg_Parse(v, "l", &self->ob_itself.rsrcPhysicalSize)-1;
 385	return 0;
 386}
 387
 388static PyObject *FSCatalogInfo_get_sharingFlags(FSCatalogInfoObject *self, void *closure)
 389{
 390	return Py_BuildValue("l", self->ob_itself.sharingFlags);
 391}
 392
 393static int FSCatalogInfo_set_sharingFlags(FSCatalogInfoObject *self, PyObject *v, void *closure)
 394{
 395	return PyArg_Parse(v, "l", &self->ob_itself.sharingFlags)-1;
 396	return 0;
 397}
 398
 399static PyObject *FSCatalogInfo_get_userPrivileges(FSCatalogInfoObject *self, void *closure)
 400{
 401	return Py_BuildValue("b", self->ob_itself.userPrivileges);
 402}
 403
 404static int FSCatalogInfo_set_userPrivileges(FSCatalogInfoObject *self, PyObject *v, void *closure)
 405{
 406	return PyArg_Parse(v, "b", &self->ob_itself.userPrivileges)-1;
 407	return 0;
 408}
 409
 410static PyGetSetDef FSCatalogInfo_getsetlist[] = {
 411	{"nodeFlags", (getter)FSCatalogInfo_get_nodeFlags, (setter)FSCatalogInfo_set_nodeFlags, NULL},
 412	{"volume", (getter)FSCatalogInfo_get_volume, (setter)FSCatalogInfo_set_volume, NULL},
 413	{"parentDirID", (getter)FSCatalogInfo_get_parentDirID, (setter)FSCatalogInfo_set_parentDirID, NULL},
 414	{"nodeID", (getter)FSCatalogInfo_get_nodeID, (setter)FSCatalogInfo_set_nodeID, NULL},
 415	{"createDate", (getter)FSCatalogInfo_get_createDate, (setter)FSCatalogInfo_set_createDate, NULL},
 416	{"contentModDate", (getter)FSCatalogInfo_get_contentModDate, (setter)FSCatalogInfo_set_contentModDate, NULL},
 417	{"attributeModDate", (getter)FSCatalogInfo_get_attributeModDate, (setter)FSCatalogInfo_set_attributeModDate, NULL},
 418	{"accessDate", (getter)FSCatalogInfo_get_accessDate, (setter)FSCatalogInfo_set_accessDate, NULL},
 419	{"backupDate", (getter)FSCatalogInfo_get_backupDate, (setter)FSCatalogInfo_set_backupDate, NULL},
 420	{"permissions", (getter)FSCatalogInfo_get_permissions, (setter)FSCatalogInfo_set_permissions, NULL},
 421	{"valence", (getter)FSCatalogInfo_get_valence, (setter)FSCatalogInfo_set_valence, NULL},
 422	{"dataLogicalSize", (getter)FSCatalogInfo_get_dataLogicalSize, (setter)FSCatalogInfo_set_dataLogicalSize, NULL},
 423	{"dataPhysicalSize", (getter)FSCatalogInfo_get_dataPhysicalSize, (setter)FSCatalogInfo_set_dataPhysicalSize, NULL},
 424	{"rsrcLogicalSize", (getter)FSCatalogInfo_get_rsrcLogicalSize, (setter)FSCatalogInfo_set_rsrcLogicalSize, NULL},
 425	{"rsrcPhysicalSize", (getter)FSCatalogInfo_get_rsrcPhysicalSize, (setter)FSCatalogInfo_set_rsrcPhysicalSize, NULL},
 426	{"sharingFlags", (getter)FSCatalogInfo_get_sharingFlags, (setter)FSCatalogInfo_set_sharingFlags, NULL},
 427	{"userPrivileges", (getter)FSCatalogInfo_get_userPrivileges, (setter)FSCatalogInfo_set_userPrivileges, NULL},
 428	{NULL, NULL, NULL, NULL},
 429};
 430
 431
 432#define FSCatalogInfo_compare NULL
 433
 434#define FSCatalogInfo_repr NULL
 435
 436#define FSCatalogInfo_hash NULL
 437static int FSCatalogInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
 438{
 439	static char *kw[] = {
 440	            "nodeFlags",
 441	            "volume",
 442	            "parentDirID",
 443	            "nodeID",
 444	            "createDate",
 445	            "contentModDate",
 446	            "atributeModDate",
 447	            "accessDate",
 448	            "backupDate",
 449	            "valence",
 450	            "dataLogicalSize",
 451	            "dataPhysicalSize",
 452	            "rsrcLogicalSize",
 453	            "rsrcPhysicalSize",
 454	            "sharingFlags",
 455	            "userPrivileges"
 456	            , 0};
 457
 458	if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|HhllO&O&O&O&O&llllllb", kw, &((FSCatalogInfoObject *)_self)->ob_itself.nodeFlags,
 459	            &((FSCatalogInfoObject *)_self)->ob_itself.volume,
 460	            &((FSCatalogInfoObject *)_self)->ob_itself.parentDirID,
 461	            &((FSCatalogInfoObject *)_self)->ob_itself.nodeID,
 462	            UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.createDate,
 463	            UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.contentModDate,
 464	            UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.attributeModDate,
 465	            UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.accessDate,
 466	            UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.backupDate,
 467	            &((FSCatalogInfoObject *)_self)->ob_itself.valence,
 468	            &((FSCatalogInfoObject *)_self)->ob_itself.dataLogicalSize,
 469	            &((FSCatalogInfoObject *)_self)->ob_itself.dataPhysicalSize,
 470	            &((FSCatalogInfoObject *)_self)->ob_itself.rsrcLogicalSize,
 471	            &((FSCatalogInfoObject *)_self)->ob_itself.rsrcPhysicalSize,
 472	            &((FSCatalogInfoObject *)_self)->ob_itself.sharingFlags,
 473	            &((FSCatalogInfoObject *)_self)->ob_itself.userPrivileges))
 474	{
 475		return -1;
 476	}
 477	return 0;
 478}
 479
 480#define FSCatalogInfo_tp_alloc PyType_GenericAlloc
 481
 482static PyObject *FSCatalogInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
 483{
 484	PyObject *self;
 485
 486	if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
 487	memset(&((FSCatalogInfoObject *)self)->ob_itself, 0, sizeof(FSCatalogInfo));
 488	return self;
 489}
 490
 491#define FSCatalogInfo_tp_free PyObject_Del
 492
 493
 494static PyTypeObject FSCatalogInfo_Type = {
 495	PyObject_HEAD_INIT(NULL)
 496	0, /*ob_size*/
 497	"Carbon.File.FSCatalogInfo", /*tp_name*/
 498	sizeof(FSCatalogInfoObject), /*tp_basicsize*/
 499	0, /*tp_itemsize*/
 500	/* methods */
 501	(destructor) FSCatalogInfo_dealloc, /*tp_dealloc*/
 502	0, /*tp_print*/
 503	(getattrfunc)0, /*tp_getattr*/
 504	(setattrfunc)0, /*tp_setattr*/
 505	(cmpfunc) FSCatalogInfo_compare, /*tp_compare*/
 506	(reprfunc) FSCatalogInfo_repr, /*tp_repr*/
 507	(PyNumberMethods *)0, /* tp_as_number */
 508	(PySequenceMethods *)0, /* tp_as_sequence */
 509	(PyMappingMethods *)0, /* tp_as_mapping */
 510	(hashfunc) FSCatalogInfo_hash, /*tp_hash*/
 511	0, /*tp_call*/
 512	0, /*tp_str*/
 513	PyObject_GenericGetAttr, /*tp_getattro*/
 514	PyObject_GenericSetAttr, /*tp_setattro */
 515	0, /*tp_as_buffer*/
 516	Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
 517	0, /*tp_doc*/
 518	0, /*tp_traverse*/
 519	0, /*tp_clear*/
 520	0, /*tp_richcompare*/
 521	0, /*tp_weaklistoffset*/
 522	0, /*tp_iter*/
 523	0, /*tp_iternext*/
 524	FSCatalogInfo_methods, /* tp_methods */
 525	0, /*tp_members*/
 526	FSCatalogInfo_getsetlist, /*tp_getset*/
 527	0, /*tp_base*/
 528	0, /*tp_dict*/
 529	0, /*tp_descr_get*/
 530	0, /*tp_descr_set*/
 531	0, /*tp_dictoffset*/
 532	FSCatalogInfo_tp_init, /* tp_init */
 533	FSCatalogInfo_tp_alloc, /* tp_alloc */
 534	FSCatalogInfo_tp_new, /* tp_new */
 535	FSCatalogInfo_tp_free, /* tp_free */
 536};
 537
 538/* ----------------- End object type FSCatalogInfo ------------------ */
 539
 540
 541/* ----------------------- Object type FInfo ------------------------ */
 542
 543#ifndef __LP64__
 544
 545static PyTypeObject FInfo_Type;
 546
 547#define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
 548
 549typedef struct FInfoObject {
 550	PyObject_HEAD
 551	FInfo ob_itself;
 552} FInfoObject;
 553
 554static PyObject *FInfo_New(FInfo *itself)
 555{
 556	FInfoObject *it;
 557	if (itself == NULL) return PyMac_Error(resNotFound);
 558	it = PyObject_NEW(FInfoObject, &FInfo_Type);
 559	if (it == NULL) return NULL;
 560	it->ob_itself = *itself;
 561	return (PyObject *)it;
 562}
 563
 564static int FInfo_Convert(PyObject *v, FInfo *p_itself)
 565{
 566	if (!FInfo_Check(v))
 567	{
 568		PyErr_SetString(PyExc_TypeError, "FInfo required");
 569		return 0;
 570	}
 571	*p_itself = ((FInfoObject *)v)->ob_itself;
 572	return 1;
 573}
 574
 575static void FInfo_dealloc(FInfoObject *self)
 576{
 577	/* Cleanup of self->ob_itself goes here */
 578	self->ob_type->tp_free((PyObject *)self);
 579}
 580
 581static PyMethodDef FInfo_methods[] = {
 582	{NULL, NULL, 0}
 583};
 584
 585static PyObject *FInfo_get_Type(FInfoObject *self, void *closure)
 586{
 587	return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdType);
 588}
 589
 590static int FInfo_set_Type(FInfoObject *self, PyObject *v, void *closure)
 591{
 592	return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdType)-1;
 593	return 0;
 594}
 595
 596static PyObject *FInfo_get_Creator(FInfoObject *self, void *closure)
 597{
 598	return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdCreator);
 599}
 600
 601static int FInfo_set_Creator(FInfoObject *self, PyObject *v, void *closure)
 602{
 603	return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;
 604	return 0;
 605}
 606
 607static PyObject *FInfo_get_Flags(FInfoObject *self, void *closure)
 608{
 609	return Py_BuildValue("H", self->ob_itself.fdFlags);
 610}
 611
 612static int FInfo_set_Flags(FInfoObject *self, PyObject *v, void *closure)
 613{
 614	return PyArg_Parse(v, "H", &self->ob_itself.fdFlags)-1;
 615	return 0;
 616}
 617
 618static PyObject *FInfo_get_Location(FInfoObject *self, void *closure)
 619{
 620	return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself.fdLocation);
 621}
 622
 623static int FInfo_set_Location(FInfoObject *self, PyObject *v, void *closure)
 624{
 625	return PyArg_Parse(v, "O&", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;
 626	return 0;
 627}
 628
 629static PyObject *FInfo_get_Fldr(FInfoObject *self, void *closure)
 630{
 631	return Py_BuildValue("h", self->ob_itself.fdFldr);
 632}
 633
 634static int FInfo_set_Fldr(FInfoObject *self, PyObject *v, void *closure)
 635{
 636	return PyArg_Parse(v, "h", &self->ob_itself.fdFldr)-1;
 637	return 0;
 638}
 639
 640static PyGetSetDef FInfo_getsetlist[] = {
 641	{"Type", (getter)FInfo_get_Type, (setter)FInfo_set_Type, "4-char file type"},
 642	{"Creator", (getter)FInfo_get_Creator, (setter)FInfo_set_Creator, "4-char file creator"},
 643	{"Flags", (getter)FInfo_get_Flags, (setter)FInfo_set_Flags, "Finder flag bits"},
 644	{"Location", (getter)FInfo_get_Location, (setter)FInfo_set_Location, "(x, y) location of the file's icon in its parent finder window"},
 645	{"Fldr", (getter)FInfo_get_Fldr, (setter)FInfo_set_Fldr, "Original folder, for 'put away'"},
 646	{NULL, NULL, NULL, NULL},
 647};
 648
 649
 650#define FInfo_compare NULL
 651
 652#define FInfo_repr NULL
 653
 654#define FInfo_hash NULL
 655static int FInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
 656{
 657	FInfo *itself = NULL;
 658	static char *kw[] = {"itself", 0};
 659
 660	if (PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&", kw, FInfo_Convert, &itself))
 661	{
 662		if (itself) memcpy(&((FInfoObject *)_self)->ob_itself, itself, sizeof(FInfo));
 663		return 0;
 664	}
 665	return -1;
 666}
 667
 668#define FInfo_tp_alloc PyType_GenericAlloc
 669
 670static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
 671{
 672	PyObject *self;
 673
 674	if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
 675	memset(&((FInfoObject *)self)->ob_itself, 0, sizeof(FInfo));
 676	return self;
 677}
 678
 679#define FInfo_tp_free PyObject_Del
 680
 681
 682static PyTypeObject FInfo_Type = {
 683	PyObject_HEAD_INIT(NULL)
 684	0, /*ob_size*/
 685	"Carbon.File.FInfo", /*tp_name*/
 686	sizeof(FInfoObject), /*tp_basicsize*/
 687	0, /*tp_itemsize*/
 688	/* methods */
 689	(destructor) FInfo_dealloc, /*tp_dealloc*/
 690	0, /*tp_print*/
 691	(getattrfunc)0, /*tp_getattr*/
 692	(setattrfunc)0, /*tp_setattr*/
 693	(cmpfunc) FInfo_compare, /*tp_compare*/
 694	(reprfunc) FInfo_repr, /*tp_repr*/
 695	(PyNumberMethods *)0, /* tp_as_number */
 696	(PySequenceMethods *)0, /* tp_as_sequence */
 697	(PyMappingMethods *)0, /* tp_as_mapping */
 698	(hashfunc) FInfo_hash, /*tp_hash*/
 699	0, /*tp_call*/
 700	0, /*tp_str*/
 701	PyObject_GenericGetAttr, /*tp_getattro*/
 702	PyObject_GenericSetAttr, /*tp_setattro */
 703	0, /*tp_as_buffer*/
 704	Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
 705	0, /*tp_doc*/
 706	0, /*tp_traverse*/
 707	0, /*tp_clear*/
 708	0, /*tp_richcompare*/
 709	0, /*tp_weaklistoffset*/
 710	0, /*tp_iter*/
 711	0, /*tp_iternext*/
 712	FInfo_methods, /* tp_methods */
 713	0, /*tp_members*/
 714	FInfo_getsetlist, /*tp_getset*/
 715	0, /*tp_base*/
 716	0, /*tp_dict*/
 717	0, /*tp_descr_get*/
 718	0, /*tp_descr_set*/
 719	0, /*tp_dictoffset*/
 720	FInfo_tp_init, /* tp_init */
 721	FInfo_tp_alloc, /* tp_alloc */
 722	FInfo_tp_new, /* tp_new */
 723	FInfo_tp_free, /* tp_free */
 724};
 725
 726#endif /* !__LP64__ */
 727/* --------------------- End object type FInfo ---------------------- */
 728
 729
 730/* ----------------------- Object type Alias ------------------------ */
 731
 732static PyTypeObject Alias_Type;
 733
 734#define Alias_Check(x) ((x)->ob_type == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
 735
 736typedef struct AliasObject {
 737	PyObject_HEAD
 738	AliasHandle ob_itself;
 739	void (*ob_freeit)(AliasHandle ptr);
 740} AliasObject;
 741
 742static PyObject *Alias_New(AliasHandle itself)
 743{
 744	AliasObject *it;
 745	if (itself == NULL) return PyMac_Error(resNotFound);
 746	it = PyObject_NEW(AliasObject, &Alias_Type);
 747	if (it == NULL) return NULL;
 748	it->ob_itself = itself;
 749	it->ob_freeit = NULL;
 750	return (PyObject *)it;
 751}
 752
 753static int Alias_Convert(PyObject *v, AliasHandle *p_itself)
 754{
 755	if (!Alias_Check(v))
 756	{
 757		PyErr_SetString(PyExc_TypeError, "Alias required");
 758		return 0;
 759	}
 760	*p_itself = ((AliasObject *)v)->ob_itself;
 761	return 1;
 762}
 763
 764static void Alias_dealloc(AliasObject *self)
 765{
 766	if (self->ob_freeit && self->ob_itself)
 767	{
 768		self->ob_freeit(self->ob_itself);
 769	}
 770	self->ob_itself = NULL;
 771	self->ob_type->tp_free((PyObject *)self);
 772}
 773
 774#ifndef __LP64__
 775static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
 776{
 777	PyObject *_res = NULL;
 778	OSErr _err;
 779	FSSpec fromFile__buf__;
 780	FSSpec *fromFile = &fromFile__buf__;
 781	FSSpec target;
 782	Boolean wasChanged;
 783	if (!PyArg_ParseTuple(_args, "O&",
 784	                      myPyMac_GetOptFSSpecPtr, &fromFile))
 785		return NULL;
 786	_err = ResolveAlias(fromFile,
 787	                    _self->ob_itself,
 788	                    &target,
 789	                    &wasChanged);
 790	if (_err != noErr) return PyMac_Error(_err);
 791	_res = Py_BuildValue("O&b",
 792	                     FSSpec_New, &target,
 793	                     wasChanged);
 794	return _res;
 795}
 796
 797static PyObject *Alias_GetAliasInfo(AliasObject *_self, PyObject *_args)
 798{
 799	PyObject *_res = NULL;
 800	OSErr _err;
 801	AliasInfoType index;
 802	Str63 theString;
 803	if (!PyArg_ParseTuple(_args, "h",
 804	                      &index))
 805		return NULL;
 806	_err = GetAliasInfo(_self->ob_itself,
 807	                    index,
 808	                    theString);
 809	if (_err != noErr) return PyMac_Error(_err);
 810	_res = Py_BuildValue("O&",
 811	                     PyMac_BuildStr255, theString);
 812	return _res;
 813}
 814
 815static PyObject *Alias_ResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
 816{
 817	PyObject *_res = NULL;
 818	OSErr _err;
 819	FSSpec fromFile__buf__;
 820	FSSpec *fromFile = &fromFile__buf__;
 821	FSSpec target;
 822	Boolean wasChanged;
 823	unsigned long mountFlags;
 824	if (!PyArg_ParseTuple(_args, "O&l",
 825	                      myPyMac_GetOptFSSpecPtr, &fromFile,
 826	                      &mountFlags))
 827		return NULL;
 828	_err = ResolveAliasWithMountFlags(fromFile,
 829	                                  _self->ob_itself,
 830	                                  &target,
 831	                                  &wasChanged,
 832	                                  mountFlags);
 833	if (_err != noErr) return PyMac_Error(_err);
 834	_res = Py_BuildValue("O&b",
 835	                     FSSpec_New, &target,
 836	                     wasChanged);
 837	return _res;
 838}
 839
 840static PyObject *Alias_FollowFinderAlias(AliasObject *_self, PyObject *_args)
 841{
 842	PyObject *_res = NULL;
 843	OSErr _err;
 844	FSSpec fromFile__buf__;
 845	FSSpec *fromFile = &fromFile__buf__;
 846	Boolean logon;
 847	FSSpec target;
 848	Boolean wasChanged;
 849	if (!PyArg_ParseTuple(_args, "O&b",
 850	                      myPyMac_GetOptFSSpecPtr, &fromFile,
 851	                      &logon))
 852		return NULL;
 853	_err = FollowFinderAlias(fromFile,
 854	                         _self->ob_itself,
 855	                         logon,
 856	                         &target,
 857	                         &wasChanged);
 858	if (_err != noErr) return PyMac_Error(_err);
 859	_res = Py_BuildValue("O&b",
 860	                     FSSpec_New, &target,
 861	                     wasChanged);
 862	return _res;
 863}
 864#endif /* !__LP64__ */
 865
 866static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
 867{
 868	PyObject *_res = NULL;
 869	OSErr _err;
 870	FSRef fromFile__buf__;
 871	FSRef *fromFile = &fromFile__buf__;
 872	FSRef target;
 873	Boolean wasChanged;
 874	unsigned long mountFlags;
 875	if (!PyArg_ParseTuple(_args, "O&l",
 876	                      myPyMac_GetOptFSRefPtr, &fromFile,
 877	                      &mountFlags))
 878		return NULL;
 879	_err = FSResolveAliasWithMountFlags(fromFile,
 880	                                    _self->ob_itself,
 881	                                    &target,
 882	                                    &wasChanged,
 883	                                    mountFlags);
 884	if (_err != noErr) return PyMac_Error(_err);
 885	_res = Py_BuildValue("O&b",
 886	                     FSRef_New, &target,
 887	                     wasChanged);
 888	return _res;
 889}
 890
 891static PyObject *Alias_FSResolveAlias(AliasObject *_self, PyObject *_args)
 892{
 893	PyObject *_res = NULL;
 894	OSErr _err;
 895	FSRef fromFile__buf__;
 896	FSRef *fromFile = &fromFile__buf__;
 897	FSRef target;
 898	Boolean wasChanged;
 899	if (!PyArg_ParseTuple(_args, "O&",
 900	                      myPyMac_GetOptFSRefPtr, &fromFile))
 901		return NULL;
 902	_err = FSResolveAlias(fromFile,
 903	                      _self->ob_itself,
 904	                      &target,
 905	                      &wasChanged);
 906	if (_err != noErr) return PyMac_Error(_err);
 907	_res = Py_BuildValue("O&b",
 908	                     FSRef_New, &target,
 909	                     wasChanged);
 910	return _res;
 911}
 912
 913static PyObject *Alias_FSFollowFinderAlias(AliasObject *_self, PyObject *_args)
 914{
 915	PyObject *_res = NULL;
 916	OSErr _err;
 917	FSRef fromFile;
 918	Boolean logon;
 919	FSRef target;
 920	Boolean wasChanged;
 921	if (!PyArg_ParseTuple(_args, "b",
 922	                      &logon))
 923		return NULL;
 924	_err = FSFollowFinderAlias(&fromFile,
 925	                           _self->ob_itself,
 926	                           logon,
 927	                           &target,
 928	                           &wasChanged);
 929	if (_err != noErr) return PyMac_Error(_err);
 930	_res = Py_BuildValue("O&O&b",
 931	                     FSRef_New, &fromFile,
 932	                     FSRef_New, &target,
 933	                     wasChanged);
 934	return _res;
 935}
 936
 937static PyMethodDef Alias_methods[] = {
 938#ifndef __LP64__
 939	{"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
 940	 PyDoc_STR("(FSSpec fromFile) -> (FSSpec target, Boolean wasChanged)")},
 941	{"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
 942	 PyDoc_STR("(AliasInfoType index) -> (Str63 theString)")},
 943	{"ResolveAliasWithMountFlags", (PyCFunction)Alias_ResolveAliasWithMountFlags, 1,
 944	 PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
 945	{"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
 946	 PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
 947#endif /* !__LP64__ */
 948	{"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
 949	 PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
 950	{"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
 951	 PyDoc_STR("(FSRef fromFile) -> (FSRef target, Boolean wasChanged)")},
 952	{"FSFollowFinderAlias", (PyCFunction)Alias_FSFollowFinderAlias, 1,
 953	 PyDoc_STR("(Boolean logon) -> (FSRef fromFile, FSRef target, Boolean wasChanged)")},
 954	{NULL, NULL, 0}
 955};
 956
 957static PyObject *Alias_get_data(AliasObject *self, void *closure)
 958{
 959	int size;
 960	                    PyObject *rv;
 961
 962	                    size = GetHandleSize((Handle)self->ob_itself);
 963	                    HLock((Handle)self->ob_itself);
 964	                    rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size);
 965	                    HUnlock((Handle)self->ob_itself);
 966	                    return rv;
 967	            
 968}
 969
 970#define Alias_set_data NULL
 971
 972static PyGetSetDef Alias_getsetlist[] = {
 973	{"data", (getter)Alias_get_data, (setter)Alias_set_data, "Raw data of the alias object"},
 974	{NULL, NULL, NULL, NULL},
 975};
 976
 977
 978#define Alias_compare NULL
 979
 980#define Alias_repr NULL
 981
 982#define Alias_hash NULL
 983static int Alias_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
 984{
 985	AliasHandle itself = NULL;
 986	char *rawdata = NULL;
 987	int rawdatalen = 0;
 988	Handle h;
 989	static char *kw[] = {"itself", "rawdata", 0};
 990
 991	if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen))
 992	return -1;
 993	if (itself && rawdata)
 994	{
 995		PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
 996		return -1;
 997	}
 998	if (!itself && !rawdata)
 999	{
1000		PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
1001		return -1;
1002	}
1003	if (rawdata)
1004	{
1005		if ((h = NewHandle(rawdatalen)) == NULL)
1006		{
1007			PyErr_NoMemory();
1008			return -1;
1009		}
1010		HLock(h);
1011		memcpy((char *)*h, rawdata, rawdatalen);
1012		HUnlock(h);
1013		((AliasObject *)_self)->ob_itself = (AliasHandle)h;
1014		return 0;
1015	}
1016	((AliasObject *)_self)->ob_itself = itself;
1017	return 0;
1018}
1019
1020#define Alias_tp_alloc PyType_GenericAlloc
1021
1022static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
1023{
1024	PyObject *self;
1025
1026	if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1027	((AliasObject *)self)->ob_itself = NULL;
1028	return self;
1029}
1030
1031#define Alias_tp_free PyObject_Del
1032
1033
1034static PyTypeObject Alias_Type = {
1035	PyObject_HEAD_INIT(NULL)
1036	0, /*ob_size*/
1037	"Carbon.File.Alias", /*tp_name*/
1038	sizeof(AliasObject), /*tp_basicsize*/
1039	0, /*tp_itemsize*/
1040	/* methods */
1041	(destructor) Alias_dealloc, /*tp_dealloc*/
1042	0, /*tp_print*/
1043	(getattrfunc)0, /*tp_getattr*/
1044	(setattrfunc)0, /*tp_setattr*/
1045	(cmpfunc) Alias_compare, /*tp_compare*/
1046	(reprfunc) Alias_repr, /*tp_repr*/
1047	(PyNumberMethods *)0, /* tp_as_number */
1048	(PySequenceMethods *)0, /* tp_as_sequence */
1049	(PyMappingMethods *)0, /* tp_as_mapping */
1050	(hashfunc) Alias_hash, /*tp_hash*/
1051	0, /*tp_call*/
1052	0, /*tp_str*/
1053	PyObject_GenericGetAttr, /*tp_getattro*/
1054	PyObject_GenericSetAttr, /*tp_setattro */
1055	0, /*tp_as_buffer*/
1056	Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1057	0, /*tp_doc*/
1058	0, /*tp_traverse*/
1059	0, /*tp_clear*/
1060	0, /*tp_richcompare*/
1061	0, /*tp_weaklistoffset*/
1062	0, /*tp_iter*/
1063	0, /*tp_iternext*/
1064	Alias_methods, /* tp_methods */
1065	0, /*tp_members*/
1066	Alias_getsetlist, /*tp_getset*/
1067	0, /*tp_base*/
1068	0, /*tp_dict*/
1069	0, /*tp_descr_get*/
1070	0, /*tp_descr_set*/
1071	0, /*tp_dictoffset*/
1072	Alias_tp_init, /* tp_init */
1073	Alias_tp_alloc, /* tp_alloc */
1074	Alias_tp_new, /* tp_new */
1075	Alias_tp_free, /* tp_free */
1076};
1077
1078/* --------------------- End object type Alias ---------------------- */
1079
1080
1081/* ----------------------- Object type FSSpec ----------------------- */
1082#ifndef __LP64__
1083
1084static PyTypeObject FSSpec_Type;
1085
1086#define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type || PyObject_TypeCheck((x), &FSSpec_Type))
1087
1088typedef struct FSSpecObject {
1089	PyObject_HEAD
1090	FSSpec ob_itself;
1091} FSSpecObject;
1092
1093static PyObject *FSSpec_New(FSSpec *itself)
1094{
1095	FSSpecObject *it;
1096	if (itself == NULL) return PyMac_Error(resNotFound);
1097	it = PyObject_NEW(FSSpecObject, &FSSpec_Type);
1098	if (it == NULL) return NULL;
1099	it->ob_itself = *itself;
1100	return (PyObject *)it;
1101}
1102
1103static void FSSpec_dealloc(FSSpecObject *self)
1104{
1105	/* Cleanup of self->ob_itself goes here */
1106	self->ob_type->tp_free((PyObject *)self);
1107}
1108
1109static PyObject *FSSpec_FSpOpenDF(FSSpecObject *_self, PyObject *_args)
1110{
1111	PyObject *_res = NULL;
1112	OSErr _err;
1113	SInt8 permission;
1114	short refNum;
1115	if (!PyArg_ParseTuple(_args, "b",
1116	                      &permission))
1117		return NULL;
1118	_err = FSpOpenDF(&_self->ob_itself,
1119	                 permission,
1120	                 &refNum);
1121	if (_err != noErr) return PyMac_Error(_err);
1122	_res = Py_BuildValue("h",
1123	                     refNum);
1124	return _res;
1125}
1126
1127static PyObject *FSSpec_FSpOpenRF(FSSpecObject *_self, PyObject *_args)
1128{
1129	PyObject *_res = NULL;
1130	OSErr _err;
1131	SInt8 permission;
1132	short refNum;
1133	if (!PyArg_ParseTuple(_args, "b",
1134	                      &permission))
1135		return NULL;
1136	_err = FSpOpenRF(&_self->ob_itself,
1137	                 permission,
1138	                 &refNum);
1139	if (_err != noErr) return PyMac_Error(_err);
1140	_res = Py_BuildValue("h",
1141	                     refNum);
1142	return _res;
1143}
1144
1145static PyObject *FSSpec_FSpCreate(FSSpecObject *_self, PyObject *_args)
1146{
1147	PyObject *_res = NULL;
1148	OSErr _err;
1149	OSType creator;
1150	OSType fileType;
1151	ScriptCode scriptTag;
1152	if (!PyArg_ParseTuple(_args, "O&O&h",
1153	                      PyMac_GetOSType, &creator,
1154	                      PyMac_GetOSType, &fileType,
1155	                      &scriptTag))
1156		return NULL;
1157	_err = FSpCreate(&_self->ob_itself,
1158	                 creator,
1159	                 fileType,
1160	                 scriptTag);
1161	if (_err != noErr) return PyMac_Error(_err);
1162	Py_INCREF(Py_None);
1163	_res = Py_None;
1164	return _res;
1165}
1166
1167static PyObject *FSSpec_FSpDirCreate(FSSpecObject *_self, PyObject *_args)
1168{
1169	PyObject *_res = NULL;
1170	OSErr _err;
1171	ScriptCode scriptTag;
1172	long createdDirID;
1173	if (!PyArg_ParseTuple(_args, "h",
1174	                      &scriptTag))
1175		return NULL;
1176	_err = FSpDirCreate(&_self->ob_itself,
1177	                    scriptTag,
1178	                    &createdDirID);
1179	if (_err != noErr) return PyMac_Error(_err);
1180	_res = Py_BuildValue("l",
1181	                     createdDirID);
1182	return _res;
1183}
1184
1185static PyObject *FSSpec_FSpDelete(FSSpecObject *_self, PyObject *_args)
1186{
1187	PyObject *_res = NULL;
1188	OSErr _err;
1189	if (!PyArg_ParseTuple(_args, ""))
1190		return NULL;
1191	_err = FSpDelete(&_self->ob_itself);
1192	if (_err != noErr) return PyMac_Error(_err);
1193	Py_INCREF(Py_None);
1194	_res = Py_None;
1195	return _res;
1196}
1197
1198static PyObject *FSSpec_FSpGetFInfo(FSSpecObject *_self, PyObject *_args)
1199{
1200	PyObject *_res = NULL;
1201	OSErr _err;
1202	FInfo fndrInfo;
1203	if (!PyArg_ParseTuple(_args, ""))
1204		return NULL;
1205	_err = FSpGetFInfo(&_self->ob_itself,
1206	                   &fndrInfo);
1207	if (_err != noErr) return PyMac_Error(_err);
1208	_res = Py_BuildValue("O&",
1209	                     FInfo_New, &fndrInfo);
1210	return _res;
1211}
1212
1213static PyObject *FSSpec_FSpSetFInfo(FSSpecObject *_self, PyObject *_args)
1214{
1215	PyObject *_res = NULL;
1216	OSErr _err;
1217	FInfo fndrInfo;
1218	if (!PyArg_ParseTuple(_args, "O&",
1219	                      FInfo_Convert, &fndrInfo))
1220		return NULL;
1221	_err = FSpSetFInfo(&_self->ob_itself,
1222	                   &fndrInfo);
1223	if (_err != noErr) return PyMac_Error(_err);
1224	Py_INCREF(Py_None);
1225	_res = Py_None;
1226	return _res;
1227}
1228
1229static PyObject *FSSpec_FSpSetFLock(FSSpecObject *_self, PyObject *_args)
1230{
1231	PyObject *_res = NULL;
1232	OSErr _err;
1233	if (!PyArg_ParseTuple(_args, ""))
1234		return NULL;
1235	_err = FSpSetFLock(&_self->ob_itself);
1236	if (_err != noErr) return PyMac_Error(_err);
1237	Py_INCREF(Py_None);
1238	_res = Py_None;
1239	return _res;
1240}
1241
1242static PyObject *FSSpec_FSpRstFLock(FSSpecObject *_self, PyObject *_args)
1243{
1244	PyObject *_res = NULL;
1245	OSErr _err;
1246	if (!PyArg_ParseTuple(_args, ""))
1247		return NULL;
1248	_err = FSpRstFLock(&_self->ob_itself);
1249	if (_err != noErr) return PyMac_Error(_err);
1250	Py_INCREF(Py_None);
1251	_res = Py_None;
1252	return _res;
1253}
1254
1255static PyObject *FSSpec_FSpRename(FSSpecObject *_self, PyObject *_args)
1256{
1257	PyObject *_res = NULL;
1258	OSErr _err;
1259	Str255 newName;
1260	if (!PyArg_ParseTuple(_args, "O&",
1261	                      PyMac_GetStr255, newName))
1262		return NULL;
1263	_err = FSpRename(&_self->ob_itself,
1264	                 newName);
1265	if (_err != noErr) return PyMac_Error(_err);
1266	Py_INCREF(Py_None);
1267	_res = Py_None;
1268	return _res;
1269}
1270
1271static PyObject *FSSpec_FSpCatMove(FSSpecObject *_self, PyObject *_args)
1272{
1273	PyObject *_res = NULL;
1274	OSErr _err;
1275	FSSpec dest;
1276	if (!PyArg_ParseTuple(_args, "O&",
1277	                      FSSpec_Convert, &dest))
1278		return NULL;
1279	_err = FSpCatMove(&_self->ob_itself,
1280	                  &dest);
1281	if (_err != noErr) return PyMac_Error(_err);
1282	Py_INCREF(Py_None);
1283	_res = Py_None;
1284	return _res;
1285}
1286
1287static PyObject *FSSpec_FSpExchangeFiles(FSSpecObject *_self, PyObject *_args)
1288{
1289	PyObject *_res = NULL;
1290	OSErr _err;
1291	FSSpec dest;
1292	if (!PyArg_ParseTuple(_args, "O&",
1293	                      FSSpec_Convert, &dest))
1294		return NULL;
1295	_err = FSpExchangeFiles(&_self->ob_itself,
1296	                        &dest);
1297	if (_err != noErr) return PyMac_Error(_err);
1298	Py_INCREF(Py_None);
1299	_res = Py_None;
1300	return _res;
1301}
1302
1303static PyObject *FSSpec_FSpMakeFSRef(FSSpecObject *_self, PyObject *_args)
1304{
1305	PyObject *_res = NULL;
1306	OSErr _err;
1307	FSRef newRef;
1308	if (!PyArg_ParseTuple(_args, ""))
1309		return NULL;
1310	_err = FSpMakeFSRef(&_self->ob_itself,
1311	                    &newRef);
1312	if (_err != noErr) return PyMac_Error(_err);
1313	_res = Py_BuildValue("O&",
1314	                     FSRef_New, &newRef);
1315	return _res;
1316}
1317
1318static PyObject *FSSpec_NewAliasMinimal(FSSpecObject *_self, PyObject *_args)
1319{
1320	PyObject *_res = NULL;
1321	OSErr _err;
1322	AliasHandle alias;
1323	if (!PyArg_ParseTuple(_args, ""))
1324		return NULL;
1325	_err = NewAliasMinimal(&_self->ob_itself,
1326	                       &alias);
1327	if (_err != noErr) return PyMac_Error(_err);
1328	_res = Py_BuildValue("O&",
1329	                     Alias_New, alias);
1330	return _res;
1331}
1332
1333static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
1334{
1335	PyObject *_res = NULL;
1336	OSErr _err;
1337	Boolean aliasFileFlag;
1338	Boolean folderFlag;
1339	if (!PyArg_ParseTuple(_args, ""))
1340		return NULL;
1341	_err = IsAliasFile(&_self->ob_itself,
1342	                   &aliasFileFlag,
1343	                   &folderFlag);
1344	if (_err != noErr) return PyMac_Error(_err);
1345	_res = Py_BuildValue("bb",
1346	                     aliasFileFlag,
1347	                     folderFlag);
1348	return _res;
1349}
1350
1351static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
1352{
1353	PyObject *_res = NULL;
1354
1355	char strbuf[1024];
1356	OSErr err;
1357
1358	if (!PyArg_ParseTuple(_args, ""))
1359	        return NULL;
1360	err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf));
1361	if ( err ) {
1362	        PyMac_Error(err);
1363	        return NULL;
1364	}
1365	_res = PyString_FromString(strbuf);
1366	return _res;
1367
1368}
1369
1370static PyObject *FSSpec_as_tuple(FSSpecObject *_self, PyObject *_args)
1371{
1372	PyObject *_res = NULL;
1373
1374	if (!PyArg_ParseTuple(_args, ""))
1375	        return NULL;
1376	_res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID,
1377	                                        &_self->ob_itself.name[1], _self->ob_itself.name[0]);
1378	return _res;
1379
1380}
1381
1382static PyMethodDef FSSpec_methods[] = {
1383	{"FSpOpenDF", (PyCFunction)FSSpec_FSpOpenDF, 1,
1384	 PyDoc_STR("(SInt8 permission) -> (short refNum)")},
1385	{"FSpOpenRF", (PyCFunction)FSSpec_FSpOpenRF, 1,
1386	 PyDoc_STR("(SInt8 permission) -> (short refNum)")},
1387	{"FSpCreate", (PyCFunction)FSSpec_FSpCreate, 1,
1388	 PyDoc_STR("(OSType creator, OSType fileType, ScriptCode scriptTag) -> None")},
1389	{"FSpDirCreate", (PyCFunction)FSSpec_FSpDirCreate, 1,
1390	 PyDoc_STR("(ScriptCode scriptTag) -> (long createdDirID)")},
1391	{"FSpDelete", (PyCFunction)FSSpec_FSpDelete, 1,
1392	 PyDoc_STR("() -> None")},
1393	{"FSpGetFInfo", (PyCFunction)FSSpec_FSpGetFInfo, 1,
1394	 PyDoc_STR("() -> (FInfo fndrInfo)")},
1395	{"FSpSetFInfo", (PyCFunction)FSSpec_FSpSetFInfo, 1,
1396	 PyDoc_STR("(FInfo fndrInfo) -> None")},
1397	{"FSpSetFLock", (PyCFunction)FSSpec_FSpSetFLock, 1,
1398	 PyDoc_STR("() -> None")},
1399	{"FSpRstFLock", (PyCFunction)FSSpec_FSpRstFLock, 1,
1400	 PyDoc_STR("() -> None")},
1401	{"FSpRename", (PyCFunction)FSSpec_FSpRename, 1,
1402	 PyDoc_STR("(Str255 newName) -> None")},
1403	{"FSpCatMove", (PyCFunction)FSSpec_FSpCatMove, 1,
1404	 PyDoc_STR("(FSSpec dest) -> None")},
1405	{"FSpExchangeFiles", (PyCFunction)FSSpec_FSpExchangeFiles, 1,
1406	 PyDoc_STR("(FSSpec dest) -> None")},
1407	{"FSpMakeFSRef", (PyCFunction)FSSpec_FSpMakeFSRef, 1,
1408	 PyDoc_STR("() -> (FSRef newRef)")},
1409	{"NewAliasMinimal", (PyCFunction)FSSpec_NewAliasMinimal, 1,
1410	 PyDoc_STR("() -> (AliasHandle alias)")},
1411	{"IsAliasFile", (PyCFunction)FSSpec_IsAliasFile, 1,
1412	 PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
1413	{"as_pathname", (PyCFunction)FSSpec_as_pathname, 1,
1414	 PyDoc_STR("() -> string")},
1415	{"as_tuple", (PyCFunction)FSSpec_as_tuple, 1,
1416	 PyDoc_STR("() -> (vRefNum, dirID, name)")},
1417	{NULL, NULL, 0}
1418};
1419
1420static PyObject *FSSpec_get_data(FSSpecObject *self, void *closure)
1421{
1422	return PyString_FromStringAndSize((char *)&self->ob_itself, sizeof(self->ob_itself));
1423}
1424
1425#define FSSpec_set_data NULL
1426
1427static PyGetSetDef FSSpec_getsetlist[] = {
1428	{"data", (getter)FSSpec_get_data, (setter)FSSpec_set_data, "Raw data of the FSSpec object"},
1429	{NULL, NULL, NULL, NULL},
1430};
1431
1432
1433#define FSSpec_compare NULL
1434
1435static PyObject * FSSpec_repr(FSSpecObject *self)
1436{
1437	char buf[512];
1438	PyOS_snprintf(buf, sizeof(buf), "%s((%d, %ld, '%.*s'))",
1439	        self->ob_type->tp_name,
1440	        self->ob_itself.vRefNum,
1441	        self->ob_itself.parID,
1442	        self->ob_itself.name[0], self->ob_itself.name+1);
1443	return PyString_FromString(buf);
1444}
1445
1446#define FSSpec_hash NULL
1447static int FSSpec_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)
1448{
1449	PyObject *v = NULL;
1450	char *rawdata = NULL;
1451	int rawdatalen = 0;
1452	static char *kw[] = {"itself", "rawdata", 0};
1453
1454	if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
1455	return -1;
1456	if (v && rawdata)
1457	{
1458		PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
1459		return -1;
1460	}
1461	if (!v && !rawdata)
1462	{
1463		PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
1464		return -1;
1465	}
1466	if (rawdata)
1467	{
1468		if (rawdatalen != sizeof(FSSpec))
1469		{
1470			PyErr_SetString(PyExc_TypeError, "FSSpec rawdata incorrect size");
1471			return -1;
1472		}
1473		memcpy(&((FSSpecObject *)_self)->ob_itself, rawdata, rawdatalen);
1474		return 0;
1475	}
1476	if (PyMac_GetFSSpec(v, &((FSSpecObject *)_self)->ob_itself)) return 0;
1477	return -1;
1478}
1479
1480#define FSSpec_tp_alloc PyType_GenericAlloc
1481
1482static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
1483{
1484	PyObject *self;
1485
1486	if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1487	memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpec));
1488	return self;
1489}
1490
1491#define FSSpec_tp_free PyObject_Del
1492
1493
1494static PyTypeObject FSSpec_Type = {
1495	PyObject_HEAD_INIT(NULL)
1496	0, /*ob_size*/
1497	"Carbon.File.FSSpec", /*tp_name*/
1498	sizeof(FSSpecObject), /*tp_basicsize*/
1499	0, /*tp_itemsize*/
1500	/* methods */
1501	(destructor) FSSpec_dealloc, /*tp_dealloc*/
1502	0, /*tp_print*/
1503	(getattrfunc)0, /*tp_getattr*/
1504	(setattrfunc)0, /*tp_setattr*/
1505	(cmpfunc) FSSpec_compare, /*tp_compare*/
1506	(reprfunc) FSSpec_repr, /*tp_repr*/
1507	(PyNumberMethods *)0, /* tp_as_number */
1508	(PySequenceMethods *)0, /* tp_as_sequence */
1509	(PyMappingMethods *)0, /* tp_as_mapping */
1510	(hashfunc) FSSpec_hash, /*tp_hash*/
1511	0, /*tp_call*/
1512	0, /*tp_str*/
1513	PyObject_GenericGetAttr, /*tp_getattro*/
1514	PyObject_GenericSetAttr, /*tp_setattro */
1515	0, /*tp_as_buffer*/
1516	Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1517	0, /*tp_doc*/
1518	0, /*tp_traverse*/
1519	0, /*tp_clear*/
1520	0, /*tp_richcompare*/
1521	0, /*tp_weaklistoffset*/
1522	0, /*tp_iter*/
1523	0, /*tp_iternext*/
1524	FSSpec_methods, /* tp_methods */
1525	0, /*tp_members*/
1526	FSSpec_getsetlist, /*tp_getset*/
1527	0, /*tp_base*/
1528	0, /*tp_dict*/
1529	0, /*tp_descr_get*/
1530	0, /*tp_descr_set*/
1531	0, /*tp_dictoffset*/
1532	FSSpec_tp_init, /* tp_init */
1533	FSSpec_tp_alloc, /* tp_alloc */
1534	FSSpec_tp_new, /* tp_new */
1535	FSSpec_tp_free, /* tp_free */
1536};
1537
1538#endif /* !__LP64__ */
1539/* --------------------- End object type FSSpec --------------------- */
1540
1541
1542/* ----------------------- Object type FSRef ------------------------ */
1543
1544static PyTypeObject FSRef_Type;
1545
1546#define FSRef_Check(x) ((x)->ob_type == &FSRef_Type || PyObject_TypeCheck((x), &FSRef_Type))
1547
1548typedef struct FSRefObject {
1549	PyObject_HEAD
1550	FSRef ob_itself;
1551} FSRefObject;
1552
1553static PyObject *FSRef_New(FSRef *itself)
1554{
1555	FSRefObject *it;
1556	if (itself == NULL) return PyMac_Error(resNotFound);
1557	it = PyObject_NEW(FSRefObject, &FSRef_Type);
1558	if (it == NULL) return NULL;
1559	it->ob_itself = *itself;
1560	return (PyObject *)it;
1561}
1562
1563static void FSRef_dealloc(FSRefObject *self)
1564{
1565	/* Cleanup of self->ob_itself goes here */
1566	self->ob_type->tp_free((PyObject *)self);
1567}
1568
1569static PyObject *FSRef_FSMakeFSRefUnicode(FSRefObject *_self, PyObject *_args)
1570{
1571	PyObject *_res = NULL;
1572	OSErr _err;
1573	UniChar *nameLength__in__;
1574	UniCharCount nameLength__len__;
1575	int nameLength__in_len__;
1576	TextEncoding textEncodingHint;
1577	FSRef newRef;
1578	if (!PyArg_ParseTuple(_args, "u#l",
1579	                      &nameLength__in__, &nameLength__in_len__,
1580	                      &textEncodingHint))
1581		return NULL;
1582	nameLength__len__ = nameLength__in_len__;
1583	_err = FSMakeFSRefUnicode(&_self->ob_itself,
1584	                          nameLength__len__, nameLength__in__,
1585	                          textEncodingHint,
1586	                          &newRef);
1587	if (_err != noErr) return PyMac_Error(_err);
1588	_res = Py_BuildValue("O&",
1589	                     FSRef_New, &newRef);
1590	return _res;
1591}
1592
1593static PyObject *FSRef_FSCompareFSRefs(FSRefObject *_self, PyObject *_args)
1594{
1595	PyObject *_res = NULL;
1596	OSErr _err;
1597	FSRef ref2;
1598	if (!PyArg_ParseTuple(_args, "O&",
1599	                      FSRef_Convert, &ref2))
1600		return NULL;
1601	_err = FSCompareFSRefs(&_self->ob_itself,
1602	                       &ref2);
1603	if (_err != noErr) return PyMac_Error(_err);
1604	Py_INCREF(Py_None);
1605	_res = Py_None;
1606	return _res;
1607}
1608
1609static PyObject *FSRef_FSCreateFileUnicode(FSRefObject *_self, PyObject *_args)
1610{
1611	PyObject *_res = NULL;
1612	OSErr _err;
1613	UniChar *nameLength__in__;
1614	UniCharCount nameLength__len__;
1615	int nameLength__in_len__;
1616	FSCatalogInfoBitmap whichInfo;
1617	FSCatalogInfo catalogInfo;
1618	FSRef newRef;
1619#ifndef __LP64__
1620	FSSpec newSpec;
1621#endif
1622	if (!PyArg_ParseTuple(_args, "u#lO&",
1623	                      &nameLength__in__, &nameLength__in_len__,
1624	                      &whichInfo,
1625	                      FSCatalogInfo_Convert, &catalogInfo))
1626		return NULL;
1627	nameLength__len__ = nameLength__in_len__;
1628	_err = FSCreateFileUnicode(&_self->ob_itself,
1629	                           nameLength__len__, nameLength__in__,
1630	                           whichInfo,
1631	                           &catalogInfo,
1632	                           &newRef,
1633#ifndef __LP64__
1634	                           &newSpec
1635#else	/* __LP64__ */
1636				   NULL
1637#endif /* __LP64__*/
1638				  );
1639	if (_err != noErr) return PyMac_Error(_err);
1640
1641#ifndef __LP64__
1642	_res = Py_BuildValue("O&O&",
1643	                     FSRef_New, &newRef,
1644	                     FSSpec_New, &newSpec);
1645#else /* __LP64__ */
1646	_res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
1647#endif /* __LP64__ */
1648
1649	return _res;
1650}
1651
1652static PyObject *FSRef_FSCreateDirectoryUnicode(FSRefObject *_self, PyObject *_args)
1653{
1654	PyObject *_res = NULL;
1655	OSErr _err;
1656	UniChar *nameLength__in__;
1657	UniCharCount nameLength__len__;
1658	int nameLength__in_len__;
1659	FSCatalogInfoBitmap whichInfo;
1660	FSCatalogInfo catalogInfo;
1661	FSRef newRef;
1662#ifndef __LP64__
1663	FSSpec newSpec;
1664#endif /* !__LP64__ */
1665	UInt32 newDirID;
1666	if (!PyArg_ParseTuple(_args, "u#lO&",
1667	                      &nameLength__in__, &nameLength__in_len__,
1668	                      &whichInfo,
1669	                      FSCatalogInfo_Convert, &catalogInfo))
1670		return NULL;
1671	nameLength__len__ = nameLength__in_len__;
1672	_err = FSCreateDirectoryUnicode(&_self->ob_itself,
1673	                                nameLength__len__, nameLength__in__,
1674	                                whichInfo,
1675	                                &catalogInfo,
1676	                                &newRef,
1677#ifndef __LP64__
1678	                                &newSpec,
1679#else /* !__LP64__ */
1680					NULL,
1681#endif /* !__LP64__ */
1682	                                &newDirID);
1683	if (_err != noErr) return PyMac_Error(_err);
1684
1685#ifndef __LP64__
1686	_res = Py_BuildValue("O&O&l",
1687	                     FSRef_New, &newRef,
1688	                     FSSpec_New, &newSpec,
1689	                     newDirID);
1690#else	/* __LP64__ */
1691	_res = Py_BuildValue("O&Ol",
1692	                     FSRef_New, &newRef,
1693	                     Py_None,
1694	                     newDirID);
1695#endif /* __LP64__ */
1696	return _res;
1697}
1698
1699static PyObject *FSRef_FSDeleteObject(FSRefObject *_self, PyObject *_args)
1700{
1701	PyObject *_res = NULL;
1702	OSErr _err;
1703	if (!PyArg_ParseTuple(_args, ""))
1704		return NULL;
1705	_err = FSDeleteObject(&_self->ob_itself);
1706	if (_err != noErr) return PyMac_Error(_err);
1707	Py_INCREF(Py_None);
1708	_res = Py_None;
1709	return _res;
1710}
1711
1712static PyObject *FSRef_FSMoveObject(FSRefObject *_self, PyObject *_args)
1713{
1714	PyObject *_res = NULL;
1715	OSErr _err;
1716	FSRef destDirectory;
1717	FSRef newRef;
1718	if (!PyArg_ParseTuple(_args, "O&",
1719	                      FSRef_Convert, &destDirectory))
1720		return NULL;
1721	_err = FSMoveObject(&_self->ob_itself,
1722	                    &destDirectory,
1723	                    &newRef);
1724	if (_err != noErr) return PyMac_Error(_err);
1725	_res = Py_BuildValue("O&",
1726	                     FSRef_New, &newRef);
1727	return _res;
1728}
1729
1730static PyObject *FSRef_FSExchangeObjects(FSRefObject *_self, PyObject *_args)
1731{
1732	PyObject *_res = NULL;
1733	OSErr _err;
1734	FSRef destRef;
1735	if (!PyArg_ParseTuple(_args, "O&",
1736	                      FSRef_Convert, &destRef))
1737		return NULL;
1738	_err = FSExchangeObjects(&_self->ob_itself,
1739	                         &destRef);
1740	if (_err != noErr) return PyMac_Error(_

Large files files are truncated, but you can click here to view the full file