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