Changeset 391 for python/trunk/Mac/Modules/res
- 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/res/_Resmodule.c
r2 r391 9 9 /* Macro to test whether a weak-loaded CFM function exists */ 10 10 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ 11 12 13 11 PyErr_SetString(PyExc_NotImplementedError, \ 12 "Not available in this shared library/OS version"); \ 13 return NULL; \ 14 14 }} while(0) 15 15 … … 32 32 PyMac_AutoDisposeHandle(Handle h) 33 33 { 34 34 DisposeHandle(h); 35 35 } 36 36 … … 44 44 45 45 typedef struct ResourceObject { 46 47 48 46 PyObject_HEAD 47 Handle ob_itself; 48 void (*ob_freeit)(Handle ptr); 49 49 } ResourceObject; 50 50 51 51 PyObject *ResObj_New(Handle itself) 52 52 { 53 54 55 56 57 58 59 53 ResourceObject *it; 54 if (itself == NULL) return PyMac_Error(resNotFound); 55 it = PyObject_NEW(ResourceObject, &Resource_Type); 56 if (it == NULL) return NULL; 57 it->ob_itself = itself; 58 it->ob_freeit = NULL; 59 return (PyObject *)it; 60 60 } 61 61 62 62 int ResObj_Convert(PyObject *v, Handle *p_itself) 63 63 { 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 64 if (!ResObj_Check(v)) 65 { 66 PyObject *tmp; 67 if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) 68 { 69 *p_itself = ((ResourceObject *)tmp)->ob_itself; 70 Py_DECREF(tmp); 71 return 1; 72 } 73 PyErr_Clear(); 74 } 75 if (!ResObj_Check(v)) 76 { 77 PyErr_SetString(PyExc_TypeError, "Resource required"); 78 return 0; 79 } 80 *p_itself = ((ResourceObject *)v)->ob_itself; 81 return 1; 82 82 } 83 83 84 84 static void ResObj_dealloc(ResourceObject *self) 85 85 { 86 87 88 89 90 91 86 if (self->ob_freeit && self->ob_itself) 87 { 88 self->ob_freeit(self->ob_itself); 89 } 90 self->ob_itself = NULL; 91 self->ob_type->tp_free((PyObject *)self); 92 92 } 93 93 94 94 static PyObject *ResObj_HomeResFile(ResourceObject *_self, PyObject *_args) 95 95 { 96 97 96 PyObject *_res = NULL; 97 short _rv; 98 98 #ifndef HomeResFile 99 100 #endif 101 102 103 104 105 106 107 108 109 110 99 PyMac_PRECHECK(HomeResFile); 100 #endif 101 if (!PyArg_ParseTuple(_args, "")) 102 return NULL; 103 _rv = HomeResFile(_self->ob_itself); 104 { 105 OSErr _err = ResError(); 106 if (_err != noErr) return PyMac_Error(_err); 107 } 108 _res = Py_BuildValue("h", 109 _rv); 110 return _res; 111 111 } 112 112 113 113 static PyObject *ResObj_MacLoadResource(ResourceObject *_self, PyObject *_args) 114 114 { 115 115 PyObject *_res = NULL; 116 116 #ifndef MacLoadResource 117 118 #endif 119 120 121 122 123 124 125 126 127 128 117 PyMac_PRECHECK(MacLoadResource); 118 #endif 119 if (!PyArg_ParseTuple(_args, "")) 120 return NULL; 121 MacLoadResource(_self->ob_itself); 122 { 123 OSErr _err = ResError(); 124 if (_err != noErr) return PyMac_Error(_err); 125 } 126 Py_INCREF(Py_None); 127 _res = Py_None; 128 return _res; 129 129 } 130 130 131 131 static PyObject *ResObj_ReleaseResource(ResourceObject *_self, PyObject *_args) 132 132 { 133 133 PyObject *_res = NULL; 134 134 #ifndef ReleaseResource 135 136 #endif 137 138 139 140 141 142 143 144 145 146 135 PyMac_PRECHECK(ReleaseResource); 136 #endif 137 if (!PyArg_ParseTuple(_args, "")) 138 return NULL; 139 ReleaseResource(_self->ob_itself); 140 { 141 OSErr _err = ResError(); 142 if (_err != noErr) return PyMac_Error(_err); 143 } 144 Py_INCREF(Py_None); 145 _res = Py_None; 146 return _res; 147 147 } 148 148 149 149 static PyObject *ResObj_DetachResource(ResourceObject *_self, PyObject *_args) 150 150 { 151 151 PyObject *_res = NULL; 152 152 #ifndef DetachResource 153 154 #endif 155 156 157 158 159 160 161 162 163 164 153 PyMac_PRECHECK(DetachResource); 154 #endif 155 if (!PyArg_ParseTuple(_args, "")) 156 return NULL; 157 DetachResource(_self->ob_itself); 158 { 159 OSErr _err = ResError(); 160 if (_err != noErr) return PyMac_Error(_err); 161 } 162 Py_INCREF(Py_None); 163 _res = Py_None; 164 return _res; 165 165 } 166 166 167 167 static PyObject *ResObj_GetResAttrs(ResourceObject *_self, PyObject *_args) 168 168 { 169 170 169 PyObject *_res = NULL; 170 short _rv; 171 171 #ifndef GetResAttrs 172 173 #endif 174 175 176 177 178 179 180 181 182 183 172 PyMac_PRECHECK(GetResAttrs); 173 #endif 174 if (!PyArg_ParseTuple(_args, "")) 175 return NULL; 176 _rv = GetResAttrs(_self->ob_itself); 177 { 178 OSErr _err = ResError(); 179 if (_err != noErr) return PyMac_Error(_err); 180 } 181 _res = Py_BuildValue("h", 182 _rv); 183 return _res; 184 184 } 185 185 186 186 static PyObject *ResObj_GetResInfo(ResourceObject *_self, PyObject *_args) 187 187 { 188 189 190 191 188 PyObject *_res = NULL; 189 short theID; 190 ResType theType; 191 Str255 name; 192 192 #ifndef GetResInfo 193 194 #endif 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 193 PyMac_PRECHECK(GetResInfo); 194 #endif 195 if (!PyArg_ParseTuple(_args, "")) 196 return NULL; 197 GetResInfo(_self->ob_itself, 198 &theID, 199 &theType, 200 name); 201 { 202 OSErr _err = ResError(); 203 if (_err != noErr) return PyMac_Error(_err); 204 } 205 _res = Py_BuildValue("hO&O&", 206 theID, 207 PyMac_BuildOSType, theType, 208 PyMac_BuildStr255, name); 209 return _res; 210 210 } 211 211 212 212 static PyObject *ResObj_SetResInfo(ResourceObject *_self, PyObject *_args) 213 213 { 214 215 216 214 PyObject *_res = NULL; 215 short theID; 216 Str255 name; 217 217 #ifndef SetResInfo 218 219 #endif 220 221 222 223 224 225 226 227 228 229 230 231 232 233 218 PyMac_PRECHECK(SetResInfo); 219 #endif 220 if (!PyArg_ParseTuple(_args, "hO&", 221 &theID, 222 PyMac_GetStr255, name)) 223 return NULL; 224 SetResInfo(_self->ob_itself, 225 theID, 226 name); 227 { 228 OSErr _err = ResError(); 229 if (_err != noErr) return PyMac_Error(_err); 230 } 231 Py_INCREF(Py_None); 232 _res = Py_None; 233 return _res; 234 234 } 235 235 236 236 static PyObject *ResObj_AddResource(ResourceObject *_self, PyObject *_args) 237 237 { 238 239 240 241 238 PyObject *_res = NULL; 239 ResType theType; 240 short theID; 241 Str255 name; 242 242 #ifndef AddResource 243 244 #endif 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 243 PyMac_PRECHECK(AddResource); 244 #endif 245 if (!PyArg_ParseTuple(_args, "O&hO&", 246 PyMac_GetOSType, &theType, 247 &theID, 248 PyMac_GetStr255, name)) 249 return NULL; 250 AddResource(_self->ob_itself, 251 theType, 252 theID, 253 name); 254 { 255 OSErr _err = ResError(); 256 if (_err != noErr) return PyMac_Error(_err); 257 } 258 Py_INCREF(Py_None); 259 _res = Py_None; 260 return _res; 261 261 } 262 262 263 263 static PyObject *ResObj_GetResourceSizeOnDisk(ResourceObject *_self, PyObject *_args) 264 264 { 265 266 265 PyObject *_res = NULL; 266 long _rv; 267 267 #ifndef GetResourceSizeOnDisk 268 269 #endif 270 271 272 273 274 275 276 277 278 279 268 PyMac_PRECHECK(GetResourceSizeOnDisk); 269 #endif 270 if (!PyArg_ParseTuple(_args, "")) 271 return NULL; 272 _rv = GetResourceSizeOnDisk(_self->ob_itself); 273 { 274 OSErr _err = ResError(); 275 if (_err != noErr) return PyMac_Error(_err); 276 } 277 _res = Py_BuildValue("l", 278 _rv); 279 return _res; 280 280 } 281 281 282 282 static PyObject *ResObj_GetMaxResourceSize(ResourceObject *_self, PyObject *_args) 283 283 { 284 285 284 PyObject *_res = NULL; 285 long _rv; 286 286 #ifndef GetMaxResourceSize 287 288 #endif 289 290 291 292 293 294 295 296 297 298 287 PyMac_PRECHECK(GetMaxResourceSize); 288 #endif 289 if (!PyArg_ParseTuple(_args, "")) 290 return NULL; 291 _rv = GetMaxResourceSize(_self->ob_itself); 292 { 293 OSErr _err = ResError(); 294 if (_err != noErr) return PyMac_Error(_err); 295 } 296 _res = Py_BuildValue("l", 297 _rv); 298 return _res; 299 299 } 300 300 301 301 static PyObject *ResObj_SetResAttrs(ResourceObject *_self, PyObject *_args) 302 302 { 303 304 303 PyObject *_res = NULL; 304 short attrs; 305 305 #ifndef SetResAttrs 306 307 #endif 308 309 310 311 312 313 314 315 316 317 318 319 306 PyMac_PRECHECK(SetResAttrs); 307 #endif 308 if (!PyArg_ParseTuple(_args, "h", 309 &attrs)) 310 return NULL; 311 SetResAttrs(_self->ob_itself, 312 attrs); 313 { 314 OSErr _err = ResError(); 315 if (_err != noErr) return PyMac_Error(_err); 316 } 317 Py_INCREF(Py_None); 318 _res = Py_None; 319 return _res; 320 320 } 321 321 322 322 static PyObject *ResObj_ChangedResource(ResourceObject *_self, PyObject *_args) 323 323 { 324 324 PyObject *_res = NULL; 325 325 #ifndef ChangedResource 326 327 #endif 328 329 330 331 332 333 334 335 336 337 326 PyMac_PRECHECK(ChangedResource); 327 #endif 328 if (!PyArg_ParseTuple(_args, "")) 329 return NULL; 330 ChangedResource(_self->ob_itself); 331 { 332 OSErr _err = ResError(); 333 if (_err != noErr) return PyMac_Error(_err); 334 } 335 Py_INCREF(Py_None); 336 _res = Py_None; 337 return _res; 338 338 } 339 339 340 340 static PyObject *ResObj_RemoveResource(ResourceObject *_self, PyObject *_args) 341 341 { 342 342 PyObject *_res = NULL; 343 343 #ifndef RemoveResource 344 345 #endif 346 347 348 349 350 351 352 353 354 355 344 PyMac_PRECHECK(RemoveResource); 345 #endif 346 if (!PyArg_ParseTuple(_args, "")) 347 return NULL; 348 RemoveResource(_self->ob_itself); 349 { 350 OSErr _err = ResError(); 351 if (_err != noErr) return PyMac_Error(_err); 352 } 353 Py_INCREF(Py_None); 354 _res = Py_None; 355 return _res; 356 356 } 357 357 358 358 static PyObject *ResObj_WriteResource(ResourceObject *_self, PyObject *_args) 359 359 { 360 360 PyObject *_res = NULL; 361 361 #ifndef WriteResource 362 363 #endif 364 365 366 367 368 369 370 371 372 373 362 PyMac_PRECHECK(WriteResource); 363 #endif 364 if (!PyArg_ParseTuple(_args, "")) 365 return NULL; 366 WriteResource(_self->ob_itself); 367 { 368 OSErr _err = ResError(); 369 if (_err != noErr) return PyMac_Error(_err); 370 } 371 Py_INCREF(Py_None); 372 _res = Py_None; 373 return _res; 374 374 } 375 375 376 376 static PyObject *ResObj_SetResourceSize(ResourceObject *_self, PyObject *_args) 377 377 { 378 379 378 PyObject *_res = NULL; 379 long newSize; 380 380 #ifndef SetResourceSize 381 382 #endif 383 384 385 386 387 388 389 390 391 392 393 394 381 PyMac_PRECHECK(SetResourceSize); 382 #endif 383 if (!PyArg_ParseTuple(_args, "l", 384 &newSize)) 385 return NULL; 386 SetResourceSize(_self->ob_itself, 387 newSize); 388 { 389 OSErr _err = ResError(); 390 if (_err != noErr) return PyMac_Error(_err); 391 } 392 Py_INCREF(Py_None); 393 _res = Py_None; 394 return _res; 395 395 } 396 396 397 397 static PyObject *ResObj_GetNextFOND(ResourceObject *_self, PyObject *_args) 398 398 { 399 400 399 PyObject *_res = NULL; 400 Handle _rv; 401 401 #ifndef GetNextFOND 402 403 #endif 404 405 406 407 408 409 410 411 412 413 402 PyMac_PRECHECK(GetNextFOND); 403 #endif 404 if (!PyArg_ParseTuple(_args, "")) 405 return NULL; 406 _rv = GetNextFOND(_self->ob_itself); 407 { 408 OSErr _err = ResError(); 409 if (_err != noErr) return PyMac_Error(_err); 410 } 411 _res = Py_BuildValue("O&", 412 ResObj_New, _rv); 413 return _res; 414 414 } 415 415 … … 417 417 static PyObject *ResObj_as_Control(ResourceObject *_self, PyObject *_args) 418 418 { 419 420 421 422 419 PyObject *_res = NULL; 420 421 _res = CtlObj_New((ControlHandle)_self->ob_itself); 422 return _res; 423 423 424 424 } … … 426 426 static PyObject *ResObj_as_Menu(ResourceObject *_self, PyObject *_args) 427 427 { 428 429 430 431 428 PyObject *_res = NULL; 429 430 _res = MenuObj_New((MenuHandle)_self->ob_itself); 431 return _res; 432 432 433 433 } … … 436 436 static PyObject *ResObj_LoadResource(ResourceObject *_self, PyObject *_args) 437 437 { 438 438 PyObject *_res = NULL; 439 439 #ifndef LoadResource 440 441 #endif 442 443 444 445 446 447 448 449 450 451 440 PyMac_PRECHECK(LoadResource); 441 #endif 442 if (!PyArg_ParseTuple(_args, "")) 443 return NULL; 444 LoadResource(_self->ob_itself); 445 { 446 OSErr _err = ResError(); 447 if (_err != noErr) return PyMac_Error(_err); 448 } 449 Py_INCREF(Py_None); 450 _res = Py_None; 451 return _res; 452 452 } 453 453 454 454 static PyObject *ResObj_AutoDispose(ResourceObject *_self, PyObject *_args) 455 455 { 456 457 458 459 460 461 462 463 464 465 466 467 468 456 PyObject *_res = NULL; 457 458 int onoff, old = 0; 459 if (!PyArg_ParseTuple(_args, "i", &onoff)) 460 return NULL; 461 if ( _self->ob_freeit ) 462 old = 1; 463 if ( onoff ) 464 _self->ob_freeit = PyMac_AutoDisposeHandle; 465 else 466 _self->ob_freeit = NULL; 467 _res = Py_BuildValue("i", old); 468 return _res; 469 469 470 470 } 471 471 472 472 static PyMethodDef ResObj_methods[] = { 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 473 {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, 474 PyDoc_STR("() -> (short _rv)")}, 475 {"MacLoadResource", (PyCFunction)ResObj_MacLoadResource, 1, 476 PyDoc_STR("() -> None")}, 477 {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, 478 PyDoc_STR("() -> None")}, 479 {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, 480 PyDoc_STR("() -> None")}, 481 {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, 482 PyDoc_STR("() -> (short _rv)")}, 483 {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, 484 PyDoc_STR("() -> (short theID, ResType theType, Str255 name)")}, 485 {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, 486 PyDoc_STR("(short theID, Str255 name) -> None")}, 487 {"AddResource", (PyCFunction)ResObj_AddResource, 1, 488 PyDoc_STR("(ResType theType, short theID, Str255 name) -> None")}, 489 {"GetResourceSizeOnDisk", (PyCFunction)ResObj_GetResourceSizeOnDisk, 1, 490 PyDoc_STR("() -> (long _rv)")}, 491 {"GetMaxResourceSize", (PyCFunction)ResObj_GetMaxResourceSize, 1, 492 PyDoc_STR("() -> (long _rv)")}, 493 {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, 494 PyDoc_STR("(short attrs) -> None")}, 495 {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, 496 PyDoc_STR("() -> None")}, 497 {"RemoveResource", (PyCFunction)ResObj_RemoveResource, 1, 498 PyDoc_STR("() -> None")}, 499 {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, 500 PyDoc_STR("() -> None")}, 501 {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, 502 PyDoc_STR("(long newSize) -> None")}, 503 {"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1, 504 PyDoc_STR("() -> (Handle _rv)")}, 505 505 #ifndef __LP64__ 506 507 508 509 506 {"as_Control", (PyCFunction)ResObj_as_Control, 1, 507 PyDoc_STR("Return this resource/handle as a Control")}, 508 {"as_Menu", (PyCFunction)ResObj_as_Menu, 1, 509 PyDoc_STR("Return this resource/handle as a Menu")}, 510 510 #endif /* !__LP64__ */ 511 512 513 514 515 511 {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, 512 PyDoc_STR("() -> None")}, 513 {"AutoDispose", (PyCFunction)ResObj_AutoDispose, 1, 514 PyDoc_STR("(int)->int. Automatically DisposeHandle the object on Python object cleanup")}, 515 {NULL, NULL, 0} 516 516 }; 517 517 … … 519 519 { 520 520 521 522 523 524 525 526 527 528 529 530 531 532 521 PyObject *res; 522 char state; 523 524 state = HGetState(self->ob_itself); 525 HLock(self->ob_itself); 526 res = PyString_FromStringAndSize( 527 *self->ob_itself, 528 GetHandleSize(self->ob_itself)); 529 HUnlock(self->ob_itself); 530 HSetState(self->ob_itself, state); 531 return res; 532 533 533 } 534 534 … … 536 536 { 537 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 538 char *data; 539 long size; 540 541 if ( v == NULL ) 542 return -1; 543 if ( !PyString_Check(v) ) 544 return -1; 545 size = PyString_Size(v); 546 data = PyString_AsString(v); 547 /* XXXX Do I need the GetState/SetState calls? */ 548 SetHandleSize(self->ob_itself, size); 549 if ( MemError()) 550 return -1; 551 HLock(self->ob_itself); 552 memcpy((char *)*self->ob_itself, data, size); 553 HUnlock(self->ob_itself); 554 /* XXXX Should I do the Changed call immedeately? */ 555 return 0; 556 557 return 0; 558 558 } 559 559 560 560 static PyObject *ResObj_get_size(ResourceObject *self, void *closure) 561 561 { 562 562 return PyInt_FromLong(GetHandleSize(self->ob_itself)); 563 563 } 564 564 … … 566 566 567 567 static PyGetSetDef ResObj_getsetlist[] = { 568 569 570 568 {"data", (getter)ResObj_get_data, (setter)ResObj_set_data, "The resource data"}, 569 {"size", (getter)ResObj_get_size, (setter)ResObj_set_size, "The length of the resource data"}, 570 {NULL, NULL, NULL, NULL}, 571 571 }; 572 572 … … 579 579 static int ResObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) 580 580 { 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 581 char *srcdata = NULL; 582 int srclen = 0; 583 Handle itself; 584 char *kw[] = {"itself", 0}; 585 586 if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, ResObj_Convert, &itself)) 587 { 588 ((ResourceObject *)_self)->ob_itself = itself; 589 return 0; 590 } 591 PyErr_Clear(); 592 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|s#", kw, &srcdata, &srclen)) return -1; 593 if ((itself = NewHandle(srclen)) == NULL) 594 { 595 PyErr_NoMemory(); 596 return 0; 597 } 598 ((ResourceObject *)_self)->ob_itself = itself; 599 if (srclen && srcdata) 600 { 601 HLock(itself); 602 memcpy(*itself, srcdata, srclen); 603 HUnlock(itself); 604 } 605 return 0; 606 606 } 607 607 … … 610 610 static PyObject *ResObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 611 611 { 612 613 614 615 616 612 PyObject *self; 613 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL; 614 ((ResourceObject *)self)->ob_itself = NULL; 615 ((ResourceObject *)self)->ob_freeit = NULL; 616 return self; 617 617 } 618 618 … … 621 621 622 622 PyTypeObject Resource_Type = { 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 623 PyObject_HEAD_INIT(NULL) 624 0, /*ob_size*/ 625 "_Res.Resource", /*tp_name*/ 626 sizeof(ResourceObject), /*tp_basicsize*/ 627 0, /*tp_itemsize*/ 628 /* methods */ 629 (destructor) ResObj_dealloc, /*tp_dealloc*/ 630 0, /*tp_print*/ 631 (getattrfunc)0, /*tp_getattr*/ 632 (setattrfunc)0, /*tp_setattr*/ 633 (cmpfunc) ResObj_compare, /*tp_compare*/ 634 (reprfunc) ResObj_repr, /*tp_repr*/ 635 (PyNumberMethods *)0, /* tp_as_number */ 636 (PySequenceMethods *)0, /* tp_as_sequence */ 637 (PyMappingMethods *)0, /* tp_as_mapping */ 638 (hashfunc) ResObj_hash, /*tp_hash*/ 639 0, /*tp_call*/ 640 0, /*tp_str*/ 641 PyObject_GenericGetAttr, /*tp_getattro*/ 642 PyObject_GenericSetAttr, /*tp_setattro */ 643 0, /*tp_as_buffer*/ 644 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 645 0, /*tp_doc*/ 646 0, /*tp_traverse*/ 647 0, /*tp_clear*/ 648 0, /*tp_richcompare*/ 649 0, /*tp_weaklistoffset*/ 650 0, /*tp_iter*/ 651 0, /*tp_iternext*/ 652 ResObj_methods, /* tp_methods */ 653 0, /*tp_members*/ 654 ResObj_getsetlist, /*tp_getset*/ 655 0, /*tp_base*/ 656 0, /*tp_dict*/ 657 0, /*tp_descr_get*/ 658 0, /*tp_descr_set*/ 659 0, /*tp_dictoffset*/ 660 ResObj_tp_init, /* tp_init */ 661 ResObj_tp_alloc, /* tp_alloc */ 662 ResObj_tp_new, /* tp_new */ 663 ResObj_tp_free, /* tp_free */ 664 664 }; 665 665 … … 669 669 static PyObject *Res_CloseResFile(PyObject *_self, PyObject *_args) 670 670 { 671 672 671 PyObject *_res = NULL; 672 short refNum; 673 673 #ifndef CloseResFile 674 675 #endif 676 677 678 679 680 681 682 683 684 685 686 674 PyMac_PRECHECK(CloseResFile); 675 #endif 676 if (!PyArg_ParseTuple(_args, "h", 677 &refNum)) 678 return NULL; 679 CloseResFile(refNum); 680 { 681 OSErr _err = ResError(); 682 if (_err != noErr) return PyMac_Error(_err); 683 } 684 Py_INCREF(Py_None); 685 _res = Py_None; 686 return _res; 687 687 } 688 688 689 689 static PyObject *Res_ResError(PyObject *_self, PyObject *_args) 690 690 { 691 692 691 PyObject *_res = NULL; 692 OSErr _err; 693 693 #ifndef ResError 694 695 #endif 696 697 698 699 700 701 702 694 PyMac_PRECHECK(ResError); 695 #endif 696 if (!PyArg_ParseTuple(_args, "")) 697 return NULL; 698 _err = ResError(); 699 if (_err != noErr) return PyMac_Error(_err); 700 Py_INCREF(Py_None); 701 _res = Py_None; 702 return _res; 703 703 } 704 704 705 705 static PyObject *Res_CurResFile(PyObject *_self, PyObject *_args) 706 706 { 707 708 707 PyObject *_res = NULL; 708 short _rv; 709 709 #ifndef CurResFile 710 711 #endif 712 713 714 715 716 717 718 719 720 721 710 PyMac_PRECHECK(CurResFile); 711 #endif 712 if (!PyArg_ParseTuple(_args, "")) 713 return NULL; 714 _rv = CurResFile(); 715 { 716 OSErr _err = ResError(); 717 if (_err != noErr) return PyMac_Error(_err); 718 } 719 _res = Py_BuildValue("h", 720 _rv); 721 return _res; 722 722 } 723 723 724 724 static PyObject *Res_UseResFile(PyObject *_self, PyObject *_args) 725 725 { 726 727 726 PyObject *_res = NULL; 727 short refNum; 728 728 #ifndef UseResFile 729 730 #endif 731 732 733 734 735 736 737 738 739 740 741 729 PyMac_PRECHECK(UseResFile); 730 #endif 731 if (!PyArg_ParseTuple(_args, "h", 732 &refNum)) 733 return NULL; 734 UseResFile(refNum); 735 { 736 OSErr _err = ResError(); 737 if (_err != noErr) return PyMac_Error(_err); 738 } 739 Py_INCREF(Py_None); 740 _res = Py_None; 741 return _res; 742 742 } 743 743 744 744 static PyObject *Res_CountTypes(PyObject *_self, PyObject *_args) 745 745 { 746 747 746 PyObject *_res = NULL; 747 short _rv; 748 748 #ifndef CountTypes 749 750 #endif 751 752 753 754 755 756 757 758 759 760 749 PyMac_PRECHECK(CountTypes); 750 #endif 751 if (!PyArg_ParseTuple(_args, "")) 752 return NULL; 753 _rv = CountTypes(); 754 { 755 OSErr _err = ResError(); 756 if (_err != noErr) return PyMac_Error(_err); 757 } 758 _res = Py_BuildValue("h", 759 _rv); 760 return _res; 761 761 } 762 762 763 763 static PyObject *Res_Count1Types(PyObject *_self, PyObject *_args) 764 764 { 765 766 765 PyObject *_res = NULL; 766 short _rv; 767 767 #ifndef Count1Types 768 769 #endif 770 771 772 773 774 775 776 777 778 779 768 PyMac_PRECHECK(Count1Types); 769 #endif 770 if (!PyArg_ParseTuple(_args, "")) 771 return NULL; 772 _rv = Count1Types(); 773 { 774 OSErr _err = ResError(); 775 if (_err != noErr) return PyMac_Error(_err); 776 } 777 _res = Py_BuildValue("h", 778 _rv); 779 return _res; 780 780 } 781 781 782 782 static PyObject *Res_GetIndType(PyObject *_self, PyObject *_args) 783 783 { 784 785 786 784 PyObject *_res = NULL; 785 ResType theType; 786 short index; 787 787 #ifndef GetIndType 788 789 #endif 790 791 792 793 794 795 796 797 798 799 800 801 788 PyMac_PRECHECK(GetIndType); 789 #endif 790 if (!PyArg_ParseTuple(_args, "h", 791 &index)) 792 return NULL; 793 GetIndType(&theType, 794 index); 795 { 796 OSErr _err = ResError(); 797 if (_err != noErr) return PyMac_Error(_err); 798 } 799 _res = Py_BuildValue("O&", 800 PyMac_BuildOSType, theType); 801 return _res; 802 802 } 803 803 804 804 static PyObject *Res_Get1IndType(PyObject *_self, PyObject *_args) 805 805 { 806 807 808 806 PyObject *_res = NULL; 807 ResType theType; 808 short index; 809 809 #ifndef Get1IndType 810 811 #endif 812 813 814 815 816 817 818 819 820 821 822 823 810 PyMac_PRECHECK(Get1IndType); 811 #endif 812 if (!PyArg_ParseTuple(_args, "h", 813 &index)) 814 return NULL; 815 Get1IndType(&theType, 816 index); 817 { 818 OSErr _err = ResError(); 819 if (_err != noErr) return PyMac_Error(_err); 820 } 821 _res = Py_BuildValue("O&", 822 PyMac_BuildOSType, theType); 823 return _res; 824 824 } 825 825 826 826 static PyObject *Res_SetResLoad(PyObject *_self, PyObject *_args) 827 827 { 828 829 828 PyObject *_res = NULL; 829 Boolean load; 830 830 #ifndef SetResLoad 831 832 #endif 833 834 835 836 837 838 839 840 841 842 843 831 PyMac_PRECHECK(SetResLoad); 832 #endif 833 if (!PyArg_ParseTuple(_args, "b", 834 &load)) 835 return NULL; 836 SetResLoad(load); 837 { 838 OSErr _err = ResError(); 839 if (_err != noErr) return PyMac_Error(_err); 840 } 841 Py_INCREF(Py_None); 842 _res = Py_None; 843 return _res; 844 844 } 845 845 846 846 static PyObject *Res_CountResources(PyObject *_self, PyObject *_args) 847 847 { 848 849 850 848 PyObject *_res = NULL; 849 short _rv; 850 ResType theType; 851 851 #ifndef CountResources 852 853 #endif 854 855 856 857 858 859 860 861 862 863 864 852 PyMac_PRECHECK(CountResources); 853 #endif 854 if (!PyArg_ParseTuple(_args, "O&", 855 PyMac_GetOSType, &theType)) 856 return NULL; 857 _rv = CountResources(theType); 858 { 859 OSErr _err = ResError(); 860 if (_err != noErr) return PyMac_Error(_err); 861 } 862 _res = Py_BuildValue("h", 863 _rv); 864 return _res; 865 865 } 866 866 867 867 static PyObject *Res_Count1Resources(PyObject *_self, PyObject *_args) 868 868 { 869 870 871 869 PyObject *_res = NULL; 870 short _rv; 871 ResType theType; 872 872 #ifndef Count1Resources 873 874 #endif 875 876 877 878 879 880 881 882 883 884 885 873 PyMac_PRECHECK(Count1Resources); 874 #endif 875 if (!PyArg_ParseTuple(_args, "O&", 876 PyMac_GetOSType, &theType)) 877 return NULL; 878 _rv = Count1Resources(theType); 879 { 880 OSErr _err = ResError(); 881 if (_err != noErr) return PyMac_Error(_err); 882 } 883 _res = Py_BuildValue("h", 884 _rv); 885 return _res; 886 886 } 887 887 888 888 static PyObject *Res_GetIndResource(PyObject *_self, PyObject *_args) 889 889 { 890 891 892 893 890 PyObject *_res = NULL; 891 Handle _rv; 892 ResType theType; 893 short index; 894 894 #ifndef GetIndResource 895 896 #endif 897 898 899 900 901 902 903 904 905 906 907 908 909 895 PyMac_PRECHECK(GetIndResource); 896 #endif 897 if (!PyArg_ParseTuple(_args, "O&h", 898 PyMac_GetOSType, &theType, 899 &index)) 900 return NULL; 901 _rv = GetIndResource(theType, 902 index); 903 { 904 OSErr _err = ResError(); 905 if (_err != noErr) return PyMac_Error(_err); 906 } 907 _res = Py_BuildValue("O&", 908 ResObj_New, _rv); 909 return _res; 910 910 } 911 911 912 912 static PyObject *Res_Get1IndResource(PyObject *_self, PyObject *_args) 913 913 { 914 915 916 917 914 PyObject *_res = NULL; 915 Handle _rv; 916 ResType theType; 917 short index; 918 918 #ifndef Get1IndResource 919 920 #endif 921 922 923 924 925 926 927 928 929 930 931 932 933 919 PyMac_PRECHECK(Get1IndResource); 920 #endif 921 if (!PyArg_ParseTuple(_args, "O&h", 922 PyMac_GetOSType, &theType, 923 &index)) 924 return NULL; 925 _rv = Get1IndResource(theType, 926 index); 927 { 928 OSErr _err = ResError(); 929 if (_err != noErr) return PyMac_Error(_err); 930 } 931 _res = Py_BuildValue("O&", 932 ResObj_New, _rv); 933 return _res; 934 934 } 935 935 936 936 static PyObject *Res_GetResource(PyObject *_self, PyObject *_args) 937 937 { 938 939 940 941 938 PyObject *_res = NULL; 939 Handle _rv; 940 ResType theType; 941 short theID; 942 942 #ifndef GetResource 943 944 #endif 945 946 947 948 949 950 951 952 953 954 955 956 957 943 PyMac_PRECHECK(GetResource); 944 #endif 945 if (!PyArg_ParseTuple(_args, "O&h", 946 PyMac_GetOSType, &theType, 947 &theID)) 948 return NULL; 949 _rv = GetResource(theType, 950 theID); 951 { 952 OSErr _err = ResError(); 953 if (_err != noErr) return PyMac_Error(_err); 954 } 955 _res = Py_BuildValue("O&", 956 ResObj_New, _rv); 957 return _res; 958 958 } 959 959 960 960 static PyObject *Res_Get1Resource(PyObject *_self, PyObject *_args) 961 961 { 962 963 964 965 962 PyObject *_res = NULL; 963 Handle _rv; 964 ResType theType; 965 short theID; 966 966 #ifndef Get1Resource 967 968 #endif 969 970 971 972 973 974 975 976 977 978 979 980 981 967 PyMac_PRECHECK(Get1Resource); 968 #endif 969 if (!PyArg_ParseTuple(_args, "O&h", 970 PyMac_GetOSType, &theType, 971 &theID)) 972 return NULL; 973 _rv = Get1Resource(theType, 974 theID); 975 { 976 OSErr _err = ResError(); 977 if (_err != noErr) return PyMac_Error(_err); 978 } 979 _res = Py_BuildValue("O&", 980 ResObj_New, _rv); 981 return _res; 982 982 } 983 983 984 984 static PyObject *Res_GetNamedResource(PyObject *_self, PyObject *_args) 985 985 { 986 987 988 989 986 PyObject *_res = NULL; 987 Handle _rv; 988 ResType theType; 989 Str255 name; 990 990 #ifndef GetNamedResource 991 992 #endif 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 991 PyMac_PRECHECK(GetNamedResource); 992 #endif 993 if (!PyArg_ParseTuple(_args, "O&O&", 994 PyMac_GetOSType, &theType, 995 PyMac_GetStr255, name)) 996 return NULL; 997 _rv = GetNamedResource(theType, 998 name); 999 { 1000 OSErr _err = ResError(); 1001 if (_err != noErr) return PyMac_Error(_err); 1002 } 1003 _res = Py_BuildValue("O&", 1004 ResObj_New, _rv); 1005 return _res; 1006 1006 } 1007 1007 1008 1008 static PyObject *Res_Get1NamedResource(PyObject *_self, PyObject *_args) 1009 1009 { 1010 1011 1012 1013 1010 PyObject *_res = NULL; 1011 Handle _rv; 1012 ResType theType; 1013 Str255 name; 1014 1014 #ifndef Get1NamedResource 1015 1016 #endif 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1015 PyMac_PRECHECK(Get1NamedResource); 1016 #endif 1017 if (!PyArg_ParseTuple(_args, "O&O&", 1018 PyMac_GetOSType, &theType, 1019 PyMac_GetStr255, name)) 1020 return NULL; 1021 _rv = Get1NamedResource(theType, 1022 name); 1023 { 1024 OSErr _err = ResError(); 1025 if (_err != noErr) return PyMac_Error(_err); 1026 } 1027 _res = Py_BuildValue("O&", 1028 ResObj_New, _rv); 1029 return _res; 1030 1030 } 1031 1031 1032 1032 static PyObject *Res_UniqueID(PyObject *_self, PyObject *_args) 1033 1033 { 1034 1035 1036 1034 PyObject *_res = NULL; 1035 short _rv; 1036 ResType theType; 1037 1037 #ifndef UniqueID 1038 1039 #endif 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1038 PyMac_PRECHECK(UniqueID); 1039 #endif 1040 if (!PyArg_ParseTuple(_args, "O&", 1041 PyMac_GetOSType, &theType)) 1042 return NULL; 1043 _rv = UniqueID(theType); 1044 { 1045 OSErr _err = ResError(); 1046 if (_err != noErr) return PyMac_Error(_err); 1047 } 1048 _res = Py_BuildValue("h", 1049 _rv); 1050 return _res; 1051 1051 } 1052 1052 1053 1053 static PyObject *Res_Unique1ID(PyObject *_self, PyObject *_args) 1054 1054 { 1055 1056 1057 1055 PyObject *_res = NULL; 1056 short _rv; 1057 ResType theType; 1058 1058 #ifndef Unique1ID 1059 1060 #endif 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1059 PyMac_PRECHECK(Unique1ID); 1060 #endif 1061 if (!PyArg_ParseTuple(_args, "O&", 1062 PyMac_GetOSType, &theType)) 1063 return NULL; 1064 _rv = Unique1ID(theType); 1065 { 1066 OSErr _err = ResError(); 1067 if (_err != noErr) return PyMac_Error(_err); 1068 } 1069 _res = Py_BuildValue("h", 1070 _rv); 1071 return _res; 1072 1072 } 1073 1073 1074 1074 static PyObject *Res_UpdateResFile(PyObject *_self, PyObject *_args) 1075 1075 { 1076 1077 1076 PyObject *_res = NULL; 1077 short refNum; 1078 1078 #ifndef UpdateResFile 1079 1080 #endif 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1079 PyMac_PRECHECK(UpdateResFile); 1080 #endif 1081 if (!PyArg_ParseTuple(_args, "h", 1082 &refNum)) 1083 return NULL; 1084 UpdateResFile(refNum); 1085 { 1086 OSErr _err = ResError(); 1087 if (_err != noErr) return PyMac_Error(_err); 1088 } 1089 Py_INCREF(Py_None); 1090 _res = Py_None; 1091 return _res; 1092 1092 } 1093 1093 1094 1094 static PyObject *Res_SetResPurge(PyObject *_self, PyObject *_args) 1095 1095 { 1096 1097 1096 PyObject *_res = NULL; 1097 Boolean install; 1098 1098 #ifndef SetResPurge 1099 1100 #endif 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1099 PyMac_PRECHECK(SetResPurge); 1100 #endif 1101 if (!PyArg_ParseTuple(_args, "b", 1102 &install)) 1103 return NULL; 1104 SetResPurge(install); 1105 { 1106 OSErr _err = ResError(); 1107 if (_err != noErr) return PyMac_Error(_err); 1108 } 1109 Py_INCREF(Py_None); 1110 _res = Py_None; 1111 return _res; 1112 1112 } 1113 1113 1114 1114 static PyObject *Res_GetResFileAttrs(PyObject *_self, PyObject *_args) 1115 1115 { 1116 1117 1118 1116 PyObject *_res = NULL; 1117 short _rv; 1118 short refNum; 1119 1119 #ifndef GetResFileAttrs 1120 1121 #endif 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1120 PyMac_PRECHECK(GetResFileAttrs); 1121 #endif 1122 if (!PyArg_ParseTuple(_args, "h", 1123 &refNum)) 1124 return NULL; 1125 _rv = GetResFileAttrs(refNum); 1126 { 1127 OSErr _err = ResError(); 1128 if (_err != noErr) return PyMac_Error(_err); 1129 } 1130 _res = Py_BuildValue("h", 1131 _rv); 1132 return _res; 1133 1133 } 1134 1134 1135 1135 static PyObject *Res_SetResFileAttrs(PyObject *_self, PyObject *_args) 1136 1136 { 1137 1138 1139 1137 PyObject *_res = NULL; 1138 short refNum; 1139 short attrs; 1140 1140 #ifndef SetResFileAttrs 1141 1142 #endif 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1141 PyMac_PRECHECK(SetResFileAttrs); 1142 #endif 1143 if (!PyArg_ParseTuple(_args, "hh", 1144 &refNum, 1145 &attrs)) 1146 return NULL; 1147 SetResFileAttrs(refNum, 1148 attrs); 1149 { 1150 OSErr _err = ResError(); 1151 if (_err != noErr) return PyMac_Error(_err); 1152 } 1153 Py_INCREF(Py_None); 1154 _res = Py_None; 1155 return _res; 1156 1156 } 1157 1157 … … 1159 1159 static PyObject *Res_OpenRFPerm(PyObject *_self, PyObject *_args) 1160 1160 { 1161 1162 1163 1164 1165 1161 PyObject *_res = NULL; 1162 short _rv; 1163 Str255 fileName; 1164 short vRefNum; 1165 SignedByte permission; 1166 1166 #ifndef OpenRFPerm 1167 1168 #endif 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1167 PyMac_PRECHECK(OpenRFPerm); 1168 #endif 1169 if (!PyArg_ParseTuple(_args, "O&hb", 1170 PyMac_GetStr255, fileName, 1171 &vRefNum, 1172 &permission)) 1173 return NULL; 1174 _rv = OpenRFPerm(fileName, 1175 vRefNum, 1176 permission); 1177 { 1178 OSErr _err = ResError(); 1179 if (_err != noErr) return PyMac_Error(_err); 1180 } 1181 _res = Py_BuildValue("h", 1182 _rv); 1183 return _res; 1184 1184 } 1185 1185 1186 1186 static PyObject *Res_HOpenResFile(PyObject *_self, PyObject *_args) 1187 1187 { 1188 1189 1190 1191 1192 1193 1188 PyObject *_res = NULL; 1189 short _rv; 1190 short vRefNum; 1191 long dirID; 1192 Str255 fileName; 1193 SignedByte permission; 1194 1194 #ifndef HOpenResFile 1195 1196 #endif 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1195 PyMac_PRECHECK(HOpenResFile); 1196 #endif 1197 if (!PyArg_ParseTuple(_args, "hlO&b", 1198 &vRefNum, 1199 &dirID, 1200 PyMac_GetStr255, fileName, 1201 &permission)) 1202 return NULL; 1203 _rv = HOpenResFile(vRefNum, 1204 dirID, 1205 fileName, 1206 permission); 1207 { 1208 OSErr _err = ResError(); 1209 if (_err != noErr) return PyMac_Error(_err); 1210 } 1211 _res = Py_BuildValue("h", 1212 _rv); 1213 return _res; 1214 1214 } 1215 1215 1216 1216 static PyObject *Res_HCreateResFile(PyObject *_self, PyObject *_args) 1217 1217 { 1218 1219 1220 1221 1218 PyObject *_res = NULL; 1219 short vRefNum; 1220 long dirID; 1221 Str255 fileName; 1222 1222 #ifndef HCreateResFile 1223 1224 #endif 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1223 PyMac_PRECHECK(HCreateResFile); 1224 #endif 1225 if (!PyArg_ParseTuple(_args, "hlO&", 1226 &vRefNum, 1227 &dirID, 1228 PyMac_GetStr255, fileName)) 1229 return NULL; 1230 HCreateResFile(vRefNum, 1231 dirID, 1232 fileName); 1233 { 1234 OSErr _err = ResError(); 1235 if (_err != noErr) return PyMac_Error(_err); 1236 } 1237 Py_INCREF(Py_None); 1238 _res = Py_None; 1239 return _res; 1240 1240 } 1241 1241 1242 1242 static PyObject *Res_FSpOpenResFile(PyObject *_self, PyObject *_args) 1243 1243 { 1244 1245 1246 1247 1244 PyObject *_res = NULL; 1245 short _rv; 1246 FSSpec spec; 1247 SignedByte permission; 1248 1248 #ifndef FSpOpenResFile 1249 1250 #endif 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1249 PyMac_PRECHECK(FSpOpenResFile); 1250 #endif 1251 if (!PyArg_ParseTuple(_args, "O&b", 1252 PyMac_GetFSSpec, &spec, 1253 &permission)) 1254 return NULL; 1255 _rv = FSpOpenResFile(&spec, 1256 permission); 1257 { 1258 OSErr _err = ResError(); 1259 if (_err != noErr) return PyMac_Error(_err); 1260 } 1261 _res = Py_BuildValue("h", 1262 _rv); 1263 return _res; 1264 1264 } 1265 1265 1266 1266 static PyObject *Res_FSpCreateResFile(PyObject *_self, PyObject *_args) 1267 1267 { 1268 1269 1270 1271 1272 1268 PyObject *_res = NULL; 1269 FSSpec spec; 1270 OSType creator; 1271 OSType fileType; 1272 ScriptCode scriptTag; 1273 1273 #ifndef FSpCreateResFile 1274 1275 #endif 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1274 PyMac_PRECHECK(FSpCreateResFile); 1275 #endif 1276 if (!PyArg_ParseTuple(_args, "O&O&O&h", 1277 PyMac_GetFSSpec, &spec, 1278 PyMac_GetOSType, &creator, 1279 PyMac_GetOSType, &fileType, 1280 &scriptTag)) 1281 return NULL; 1282 FSpCreateResFile(&spec, 1283 creator, 1284 fileType, 1285 scriptTag); 1286 { 1287 OSErr _err = ResError(); 1288 if (_err != noErr) return PyMac_Error(_err); 1289 } 1290 Py_INCREF(Py_None); 1291 _res = Py_None; 1292 return _res; 1293 1293 } 1294 1294 #endif /* !__LP64__ */ … … 1296 1296 static PyObject *Res_InsertResourceFile(PyObject *_self, PyObject *_args) 1297 1297 { 1298 1299 1300 1301 1298 PyObject *_res = NULL; 1299 OSErr _err; 1300 SInt16 refNum; 1301 RsrcChainLocation where; 1302 1302 #ifndef InsertResourceFile 1303 1304 #endif 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1303 PyMac_PRECHECK(InsertResourceFile); 1304 #endif 1305 if (!PyArg_ParseTuple(_args, "hh", 1306 &refNum, 1307 &where)) 1308 return NULL; 1309 _err = InsertResourceFile(refNum, 1310 where); 1311 if (_err != noErr) return PyMac_Error(_err); 1312 Py_INCREF(Py_None); 1313 _res = Py_None; 1314 return _res; 1315 1315 } 1316 1316 1317 1317 static PyObject *Res_DetachResourceFile(PyObject *_self, PyObject *_args) 1318 1318 { 1319 1320 1321 1319 PyObject *_res = NULL; 1320 OSErr _err; 1321 SInt16 refNum; 1322 1322 #ifndef DetachResourceFile 1323 1324 #endif 1325 1326 1327 1328 1329 1330 1331 1332 1323 PyMac_PRECHECK(DetachResourceFile); 1324 #endif 1325 if (!PyArg_ParseTuple(_args, "h", 1326 &refNum)) 1327 return NULL; 1328 _err = DetachResourceFile(refNum); 1329 if (_err != noErr) return PyMac_Error(_err); 1330 Py_INCREF(Py_None); 1331 _res = Py_None; 1332 return _res; 1333 1333 } 1334 1334 … … 1336 1336 static PyObject *Res_FSpResourceFileAlreadyOpen(PyObject *_self, PyObject *_args) 1337 1337 { 1338 1339 1340 1341 1342 1338 PyObject *_res = NULL; 1339 Boolean _rv; 1340 FSSpec resourceFile; 1341 Boolean inChain; 1342 SInt16 refNum; 1343 1343 #ifndef FSpResourceFileAlreadyOpen 1344 1345 #endif 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1344 PyMac_PRECHECK(FSpResourceFileAlreadyOpen); 1345 #endif 1346 if (!PyArg_ParseTuple(_args, "O&", 1347 PyMac_GetFSSpec, &resourceFile)) 1348 return NULL; 1349 _rv = FSpResourceFileAlreadyOpen(&resourceFile, 1350 &inChain, 1351 &refNum); 1352 { 1353 OSErr _err = ResError(); 1354 if (_err != noErr) return PyMac_Error(_err); 1355 } 1356 _res = Py_BuildValue("bbh", 1357 _rv, 1358 inChain, 1359 refNum); 1360 return _res; 1361 1361 } 1362 1362 1363 1363 static PyObject *Res_FSpOpenOrphanResFile(PyObject *_self, PyObject *_args) 1364 1364 { 1365 1366 1367 1368 1369 1365 PyObject *_res = NULL; 1366 OSErr _err; 1367 FSSpec spec; 1368 SignedByte permission; 1369 SInt16 refNum; 1370 1370 #ifndef FSpOpenOrphanResFile 1371 1372 #endif 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1371 PyMac_PRECHECK(FSpOpenOrphanResFile); 1372 #endif 1373 if (!PyArg_ParseTuple(_args, "O&b", 1374 PyMac_GetFSSpec, &spec, 1375 &permission)) 1376 return NULL; 1377 _err = FSpOpenOrphanResFile(&spec, 1378 permission, 1379 &refNum); 1380 if (_err != noErr) return PyMac_Error(_err); 1381 _res = Py_BuildValue("h", 1382 refNum); 1383 return _res; 1384 1384 } 1385 1385 1386 1386 static PyObject *Res_GetTopResourceFile(PyObject *_self, PyObject *_args) 1387 1387 { 1388 1389 1390 1388 PyObject *_res = NULL; 1389 OSErr _err; 1390 SInt16 refNum; 1391 1391 #ifndef GetTopResourceFile 1392 1393 #endif 1394 1395 1396 1397 1398 1399 1400 1392 PyMac_PRECHECK(GetTopResourceFile); 1393 #endif 1394 if (!PyArg_ParseTuple(_args, "")) 1395 return NULL; 1396 _err = GetTopResourceFile(&refNum); 1397 if (_err != noErr) return PyMac_Error(_err); 1398 _res = Py_BuildValue("h", 1399 refNum); 1400 return _res; 1401 1401 } 1402 1402 … … 1404 1404 static PyObject *Res_GetNextResourceFile(PyObject *_self, PyObject *_args) 1405 1405 { 1406 1407 1408 1409 1406 PyObject *_res = NULL; 1407 OSErr _err; 1408 SInt16 curRefNum; 1409 SInt16 nextRefNum; 1410 1410 #ifndef GetNextResourceFile 1411 1412 #endif 1413 1414 1415 1416 1417 1418 1419 1420 1421 1411 PyMac_PRECHECK(GetNextResourceFile); 1412 #endif 1413 if (!PyArg_ParseTuple(_args, "h", 1414 &curRefNum)) 1415 return NULL; 1416 _err = GetNextResourceFile(curRefNum, 1417 &nextRefNum); 1418 if (_err != noErr) return PyMac_Error(_err); 1419 _res = Py_BuildValue("h", 1420 nextRefNum); 1421 return _res; 1422 1422 } 1423 1423 #endif /* !__LP64__ */ … … 1425 1425 static PyObject *Res_FSOpenResFile(PyObject *_self, PyObject *_args) 1426 1426 { 1427 1428 1429 1430 1427 PyObject *_res = NULL; 1428 short _rv; 1429 FSRef ref; 1430 SignedByte permission; 1431 1431 #ifndef FSOpenResFile 1432 1433 #endif 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1432 PyMac_PRECHECK(FSOpenResFile); 1433 #endif 1434 if (!PyArg_ParseTuple(_args, "O&b", 1435 PyMac_GetFSRef, &ref, 1436 &permission)) 1437 return NULL; 1438 _rv = FSOpenResFile(&ref, 1439 permission); 1440 { 1441 OSErr _err = ResError(); 1442 if (_err != noErr) return PyMac_Error(_err); 1443 } 1444 _res = Py_BuildValue("h", 1445 _rv); 1446 return _res; 1447 1447 } 1448 1448 … … 1451 1451 static PyObject *Res_FSCreateResFile(PyObject *_self, PyObject *_args) 1452 1452 { 1453 1454 1455 1456 1457 1458 1459 1453 PyObject *_res = NULL; 1454 FSRef parentRef; 1455 UniChar *nameLength__in__; 1456 UniCharCount nameLength__len__; 1457 int nameLength__in_len__; 1458 FSRef newRef; 1459 FSSpec newSpec; 1460 1460 #ifndef FSCreateResFile 1461 1462 #endif 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1461 PyMac_PRECHECK(FSCreateResFile); 1462 #endif 1463 if (!PyArg_ParseTuple(_args, "O&u#", 1464 PyMac_GetFSRef, &parentRef, 1465 &nameLength__in__, &nameLength__in_len__)) 1466 return NULL; 1467 nameLength__len__ = nameLength__in_len__; 1468 FSCreateResFile(&parentRef, 1469 nameLength__len__, nameLength__in__, 1470 0, 1471 (FSCatalogInfo *)0, 1472 &newRef, 1473 &newSpec); 1474 { 1475 OSErr _err = ResError(); 1476 if (_err != noErr) return PyMac_Error(_err); 1477 } 1478 _res = Py_BuildValue("O&O&", 1479 PyMac_BuildFSRef, &newRef, 1480 PyMac_BuildFSSpec, &newSpec); 1481 return _res; 1482 1482 } 1483 1483 1484 1484 static PyObject *Res_FSResourceFileAlreadyOpen(PyObject *_self, PyObject *_args) 1485 1485 { 1486 1487 1488 1489 1490 1486 PyObject *_res = NULL; 1487 Boolean _rv; 1488 FSRef resourceFileRef; 1489 Boolean inChain; 1490 SInt16 refNum; 1491 1491 #ifndef FSResourceFileAlreadyOpen 1492 1493 #endif 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1492 PyMac_PRECHECK(FSResourceFileAlreadyOpen); 1493 #endif 1494 if (!PyArg_ParseTuple(_args, "O&", 1495 PyMac_GetFSRef, &resourceFileRef)) 1496 return NULL; 1497 _rv = FSResourceFileAlreadyOpen(&resourceFileRef, 1498 &inChain, 1499 &refNum); 1500 { 1501 OSErr _err = ResError(); 1502 if (_err != noErr) return PyMac_Error(_err); 1503 } 1504 _res = Py_BuildValue("bbh", 1505 _rv, 1506 inChain, 1507 refNum); 1508 return _res; 1509 1509 } 1510 1510 1511 1511 static PyObject *Res_FSCreateResourceFile(PyObject *_self, PyObject *_args) 1512 1512 { 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1513 PyObject *_res = NULL; 1514 OSErr _err; 1515 FSRef parentRef; 1516 UniChar *nameLength__in__; 1517 UniCharCount nameLength__len__; 1518 int nameLength__in_len__; 1519 UniChar *forkNameLength__in__; 1520 UniCharCount forkNameLength__len__; 1521 int forkNameLength__in_len__; 1522 FSRef newRef; 1523 FSSpec newSpec; 1524 1524 #ifndef FSCreateResourceFile 1525 1526 #endif 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1525 PyMac_PRECHECK(FSCreateResourceFile); 1526 #endif 1527 if (!PyArg_ParseTuple(_args, "O&u#u#", 1528 PyMac_GetFSRef, &parentRef, 1529 &nameLength__in__, &nameLength__in_len__, 1530 &forkNameLength__in__, &forkNameLength__in_len__)) 1531 return NULL; 1532 nameLength__len__ = nameLength__in_len__; 1533 forkNameLength__len__ = forkNameLength__in_len__; 1534 _err = FSCreateResourceFile(&parentRef, 1535 nameLength__len__, nameLength__in__, 1536 0, 1537 (FSCatalogInfo *)0, 1538 forkNameLength__len__, forkNameLength__in__, 1539 &newRef, 1540 &newSpec); 1541 if (_err != noErr) return PyMac_Error(_err); 1542 _res = Py_BuildValue("O&O&", 1543 PyMac_BuildFSRef, &newRef, 1544 PyMac_BuildFSSpec, &newSpec); 1545 return _res; 1546 1546 } 1547 1547 #endif /* __LP64__ */ … … 1549 1549 static PyObject *Res_FSOpenResourceFile(PyObject *_self, PyObject *_args) 1550 1550 { 1551 1552 1553 1554 1555 1556 1557 1558 1551 PyObject *_res = NULL; 1552 OSErr _err; 1553 FSRef ref; 1554 UniChar *forkNameLength__in__; 1555 UniCharCount forkNameLength__len__; 1556 int forkNameLength__in_len__; 1557 SignedByte permissions; 1558 ResFileRefNum refNum; 1559 1559 #ifndef FSOpenResourceFile 1560 1561 #endif 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1560 PyMac_PRECHECK(FSOpenResourceFile); 1561 #endif 1562 if (!PyArg_ParseTuple(_args, "O&u#b", 1563 PyMac_GetFSRef, &ref, 1564 &forkNameLength__in__, &forkNameLength__in_len__, 1565 &permissions)) 1566 return NULL; 1567 forkNameLength__len__ = forkNameLength__in_len__; 1568 _err = FSOpenResourceFile(&ref, 1569 forkNameLength__len__, forkNameLength__in__, 1570 permissions, 1571 &refNum); 1572 if (_err != noErr) return PyMac_Error(_err); 1573 _res = Py_BuildValue("h", 1574 refNum); 1575 return _res; 1576 1576 } 1577 1577 1578 1578 static PyObject *Res_Handle(PyObject *_self, PyObject *_args) 1579 1579 { 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1580 PyObject *_res = NULL; 1581 1582 char *buf; 1583 int len; 1584 Handle h; 1585 ResourceObject *rv; 1586 1587 if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) 1588 return NULL; 1589 h = NewHandle(len); 1590 if ( h == NULL ) { 1591 PyErr_NoMemory(); 1592 return NULL; 1593 } 1594 HLock(h); 1595 memcpy(*h, buf, len); 1596 HUnlock(h); 1597 rv = (ResourceObject *)ResObj_New(h); 1598 rv->ob_freeit = PyMac_AutoDisposeHandle; 1599 _res = (PyObject *)rv; 1600 return _res; 1601 1601 1602 1602 } 1603 1603 1604 1604 static PyMethodDef Res_methods[] = { 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1605 {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, 1606 PyDoc_STR("(short refNum) -> None")}, 1607 {"ResError", (PyCFunction)Res_ResError, 1, 1608 PyDoc_STR("() -> None")}, 1609 {"CurResFile", (PyCFunction)Res_CurResFile, 1, 1610 PyDoc_STR("() -> (short _rv)")}, 1611 {"UseResFile", (PyCFunction)Res_UseResFile, 1, 1612 PyDoc_STR("(short refNum) -> None")}, 1613 {"CountTypes", (PyCFunction)Res_CountTypes, 1, 1614 PyDoc_STR("() -> (short _rv)")}, 1615 {"Count1Types", (PyCFunction)Res_Count1Types, 1, 1616 PyDoc_STR("() -> (short _rv)")}, 1617 {"GetIndType", (PyCFunction)Res_GetIndType, 1, 1618 PyDoc_STR("(short index) -> (ResType theType)")}, 1619 {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, 1620 PyDoc_STR("(short index) -> (ResType theType)")}, 1621 {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, 1622 PyDoc_STR("(Boolean load) -> None")}, 1623 {"CountResources", (PyCFunction)Res_CountResources, 1, 1624 PyDoc_STR("(ResType theType) -> (short _rv)")}, 1625 {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, 1626 PyDoc_STR("(ResType theType) -> (short _rv)")}, 1627 {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, 1628 PyDoc_STR("(ResType theType, short index) -> (Handle _rv)")}, 1629 {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, 1630 PyDoc_STR("(ResType theType, short index) -> (Handle _rv)")}, 1631 {"GetResource", (PyCFunction)Res_GetResource, 1, 1632 PyDoc_STR("(ResType theType, short theID) -> (Handle _rv)")}, 1633 {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, 1634 PyDoc_STR("(ResType theType, short theID) -> (Handle _rv)")}, 1635 {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, 1636 PyDoc_STR("(ResType theType, Str255 name) -> (Handle _rv)")}, 1637 {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, 1638 PyDoc_STR("(ResType theType, Str255 name) -> (Handle _rv)")}, 1639 {"UniqueID", (PyCFunction)Res_UniqueID, 1, 1640 PyDoc_STR("(ResType theType) -> (short _rv)")}, 1641 {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, 1642 PyDoc_STR("(ResType theType) -> (short _rv)")}, 1643 {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, 1644 PyDoc_STR("(short refNum) -> None")}, 1645 {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, 1646 PyDoc_STR("(Boolean install) -> None")}, 1647 {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, 1648 PyDoc_STR("(short refNum) -> (short _rv)")}, 1649 {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, 1650 PyDoc_STR("(short refNum, short attrs) -> None")}, 1651 1651 #ifndef __LP64__ 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1652 {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, 1653 PyDoc_STR("(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)")}, 1654 {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, 1655 PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv)")}, 1656 {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, 1657 PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> None")}, 1658 {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, 1659 PyDoc_STR("(FSSpec spec, SignedByte permission) -> (short _rv)")}, 1660 {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, 1661 PyDoc_STR("(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None")}, 1662 1662 #endif /* !__LP64__ */ 1663 1664 1665 1666 1663 {"InsertResourceFile", (PyCFunction)Res_InsertResourceFile, 1, 1664 PyDoc_STR("(SInt16 refNum, RsrcChainLocation where) -> None")}, 1665 {"DetachResourceFile", (PyCFunction)Res_DetachResourceFile, 1, 1666 PyDoc_STR("(SInt16 refNum) -> None")}, 1667 1667 #ifndef __LP64__ 1668 1669 1670 1671 1672 1673 1674 1675 1668 {"FSpResourceFileAlreadyOpen", (PyCFunction)Res_FSpResourceFileAlreadyOpen, 1, 1669 PyDoc_STR("(FSSpec resourceFile) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")}, 1670 {"FSpOpenOrphanResFile", (PyCFunction)Res_FSpOpenOrphanResFile, 1, 1671 PyDoc_STR("(FSSpec spec, SignedByte permission) -> (SInt16 refNum)")}, 1672 {"GetTopResourceFile", (PyCFunction)Res_GetTopResourceFile, 1, 1673 PyDoc_STR("() -> (SInt16 refNum)")}, 1674 {"GetNextResourceFile", (PyCFunction)Res_GetNextResourceFile, 1, 1675 PyDoc_STR("(SInt16 curRefNum) -> (SInt16 nextRefNum)")}, 1676 1676 #endif /* __LP64__ */ 1677 1678 1677 {"FSOpenResFile", (PyCFunction)Res_FSOpenResFile, 1, 1678 PyDoc_STR("(FSRef ref, SignedByte permission) -> (short _rv)")}, 1679 1679 #ifndef __LP64__ 1680 1681 1682 1683 1684 1685 1680 {"FSCreateResFile", (PyCFunction)Res_FSCreateResFile, 1, 1681 PyDoc_STR("(FSRef parentRef, Buffer nameLength) -> (FSRef newRef, FSSpec newSpec)")}, 1682 {"FSResourceFileAlreadyOpen", (PyCFunction)Res_FSResourceFileAlreadyOpen, 1, 1683 PyDoc_STR("(FSRef resourceFileRef) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")}, 1684 {"FSCreateResourceFile", (PyCFunction)Res_FSCreateResourceFile, 1, 1685 PyDoc_STR("(FSRef parentRef, Buffer nameLength, Buffer forkNameLength) -> (FSRef newRef, FSSpec newSpec)")}, 1686 1686 #endif /* __LP64__ */ 1687 1688 1689 1690 1691 1687 {"FSOpenResourceFile", (PyCFunction)Res_FSOpenResourceFile, 1, 1688 PyDoc_STR("(FSRef ref, Buffer forkNameLength, SignedByte permissions) -> (SInt16 refNum)")}, 1689 {"Handle", (PyCFunction)Res_Handle, 1, 1690 PyDoc_STR("Convert a string to a Handle object.\n\nResource() and Handle() are very similar, but objects created with Handle() are\nby default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()\nto change this.\n")}, 1691 {NULL, NULL, 0} 1692 1692 }; 1693 1693 … … 1697 1697 PyObject *OptResObj_New(Handle itself) 1698 1698 { 1699 1700 1701 1702 1703 1699 if (itself == NULL) { 1700 Py_INCREF(Py_None); 1701 return Py_None; 1702 } 1703 return ResObj_New(itself); 1704 1704 } 1705 1705 1706 1706 int OptResObj_Convert(PyObject *v, Handle *p_itself) 1707 1707 { 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1708 PyObject *tmp; 1709 1710 if ( v == Py_None ) { 1711 *p_itself = NULL; 1712 return 1; 1713 } 1714 if (ResObj_Check(v)) 1715 { 1716 *p_itself = ((ResourceObject *)v)->ob_itself; 1717 return 1; 1718 } 1719 /* If it isn't a resource yet see whether it is convertible */ 1720 if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) { 1721 *p_itself = ((ResourceObject *)tmp)->ob_itself; 1722 Py_DECREF(tmp); 1723 return 1; 1724 } 1725 PyErr_Clear(); 1726 PyErr_SetString(PyExc_TypeError, "Resource required"); 1727 return 0; 1728 1728 } 1729 1729 … … 1731 1731 void init_Res(void) 1732 1732 { 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1733 PyObject *m; 1734 PyObject *d; 1735 1736 1737 1738 PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, ResObj_New); 1739 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, ResObj_Convert); 1740 PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, OptResObj_New); 1741 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, OptResObj_Convert); 1742 1743 1744 m = Py_InitModule("_Res", Res_methods); 1745 d = PyModule_GetDict(m); 1746 Res_Error = PyMac_GetOSErrException(); 1747 if (Res_Error == NULL || 1748 PyDict_SetItemString(d, "Error", Res_Error) != 0) 1749 return; 1750 Resource_Type.ob_type = &PyType_Type; 1751 if (PyType_Ready(&Resource_Type) < 0) return; 1752 Py_INCREF(&Resource_Type); 1753 PyModule_AddObject(m, "Resource", (PyObject *)&Resource_Type); 1754 /* Backward-compatible name */ 1755 Py_INCREF(&Resource_Type); 1756 PyModule_AddObject(m, "ResourceType", (PyObject *)&Resource_Type); 1757 1757 } 1758 1758
Note:
See TracChangeset
for help on using the changeset viewer.