Changeset 391 for python/trunk/Mac/Modules/ae
- 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/ae/_AEmodule.c
r2 r391 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 … … 39 39 static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) 40 40 { 41 if ( PyOS_InterruptOccurred() ) 42 return 1; 41 if ( PyOS_InterruptOccurred() ) 42 return 1; 43 return 0; 44 } 45 46 AEIdleUPP upp_AEIdleProc; 47 48 static PyObject *AE_Error; 49 50 /* ----------------------- Object type AEDesc ----------------------- */ 51 52 PyTypeObject AEDesc_Type; 53 54 #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type)) 55 56 typedef struct AEDescObject { 57 PyObject_HEAD 58 AEDesc ob_itself; 59 int ob_owned; 60 } AEDescObject; 61 62 PyObject *AEDesc_New(AEDesc *itself) 63 { 64 AEDescObject *it; 65 it = PyObject_NEW(AEDescObject, &AEDesc_Type); 66 if (it == NULL) return NULL; 67 it->ob_itself = *itself; 68 it->ob_owned = 1; 69 return (PyObject *)it; 70 } 71 72 int AEDesc_Convert(PyObject *v, AEDesc *p_itself) 73 { 74 if (!AEDesc_Check(v)) 75 { 76 PyErr_SetString(PyExc_TypeError, "AEDesc required"); 43 77 return 0; 44 } 45 46 AEIdleUPP upp_AEIdleProc; 47 48 static PyObject *AE_Error; 49 50 /* ----------------------- Object type AEDesc ----------------------- */ 51 52 PyTypeObject AEDesc_Type; 53 54 #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type)) 55 56 typedef struct AEDescObject { 57 PyObject_HEAD 58 AEDesc ob_itself; 59 int ob_owned; 60 } AEDescObject; 61 62 PyObject *AEDesc_New(AEDesc *itself) 63 { 64 AEDescObject *it; 65 it = PyObject_NEW(AEDescObject, &AEDesc_Type); 66 if (it == NULL) return NULL; 67 it->ob_itself = *itself; 68 it->ob_owned = 1; 69 return (PyObject *)it; 70 } 71 72 int AEDesc_Convert(PyObject *v, AEDesc *p_itself) 73 { 74 if (!AEDesc_Check(v)) 75 { 76 PyErr_SetString(PyExc_TypeError, "AEDesc required"); 77 return 0; 78 } 79 *p_itself = ((AEDescObject *)v)->ob_itself; 80 return 1; 78 } 79 *p_itself = ((AEDescObject *)v)->ob_itself; 80 return 1; 81 81 } 82 82 83 83 static void AEDesc_dealloc(AEDescObject *self) 84 84 { 85 86 85 if (self->ob_owned) AEDisposeDesc(&self->ob_itself); 86 self->ob_type->tp_free((PyObject *)self); 87 87 } 88 88 89 89 static PyObject *AEDesc_AECoerceDesc(AEDescObject *_self, PyObject *_args) 90 90 { 91 92 93 94 91 PyObject *_res = NULL; 92 OSErr _err; 93 DescType toType; 94 AEDesc result; 95 95 #ifndef AECoerceDesc 96 97 #endif 98 99 100 101 102 103 104 105 106 107 96 PyMac_PRECHECK(AECoerceDesc); 97 #endif 98 if (!PyArg_ParseTuple(_args, "O&", 99 PyMac_GetOSType, &toType)) 100 return NULL; 101 _err = AECoerceDesc(&_self->ob_itself, 102 toType, 103 &result); 104 if (_err != noErr) return PyMac_Error(_err); 105 _res = Py_BuildValue("O&", 106 AEDesc_New, &result); 107 return _res; 108 108 } 109 109 110 110 static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args) 111 111 { 112 113 114 112 PyObject *_res = NULL; 113 OSErr _err; 114 AEDesc result; 115 115 #ifndef AEDuplicateDesc 116 117 #endif 118 119 120 121 122 123 124 125 116 PyMac_PRECHECK(AEDuplicateDesc); 117 #endif 118 if (!PyArg_ParseTuple(_args, "")) 119 return NULL; 120 _err = AEDuplicateDesc(&_self->ob_itself, 121 &result); 122 if (_err != noErr) return PyMac_Error(_err); 123 _res = Py_BuildValue("O&", 124 AEDesc_New, &result); 125 return _res; 126 126 } 127 127 128 128 static PyObject *AEDesc_AECountItems(AEDescObject *_self, PyObject *_args) 129 129 { 130 131 132 130 PyObject *_res = NULL; 131 OSErr _err; 132 long theCount; 133 133 #ifndef AECountItems 134 135 #endif 136 137 138 139 140 141 142 143 134 PyMac_PRECHECK(AECountItems); 135 #endif 136 if (!PyArg_ParseTuple(_args, "")) 137 return NULL; 138 _err = AECountItems(&_self->ob_itself, 139 &theCount); 140 if (_err != noErr) return PyMac_Error(_err); 141 _res = Py_BuildValue("l", 142 theCount); 143 return _res; 144 144 } 145 145 146 146 static PyObject *AEDesc_AEPutPtr(AEDescObject *_self, PyObject *_args) 147 147 { 148 149 150 151 152 153 154 148 PyObject *_res = NULL; 149 OSErr _err; 150 long index; 151 DescType typeCode; 152 char *dataPtr__in__; 153 long dataPtr__len__; 154 int dataPtr__in_len__; 155 155 #ifndef AEPutPtr 156 157 #endif 158 159 160 161 162 163 164 165 166 167 168 169 170 171 156 PyMac_PRECHECK(AEPutPtr); 157 #endif 158 if (!PyArg_ParseTuple(_args, "lO&s#", 159 &index, 160 PyMac_GetOSType, &typeCode, 161 &dataPtr__in__, &dataPtr__in_len__)) 162 return NULL; 163 dataPtr__len__ = dataPtr__in_len__; 164 _err = AEPutPtr(&_self->ob_itself, 165 index, 166 typeCode, 167 dataPtr__in__, dataPtr__len__); 168 if (_err != noErr) return PyMac_Error(_err); 169 Py_INCREF(Py_None); 170 _res = Py_None; 171 return _res; 172 172 } 173 173 174 174 static PyObject *AEDesc_AEPutDesc(AEDescObject *_self, PyObject *_args) 175 175 { 176 177 178 179 176 PyObject *_res = NULL; 177 OSErr _err; 178 long index; 179 AEDesc theAEDesc; 180 180 #ifndef AEPutDesc 181 182 #endif 183 184 185 186 187 188 189 190 191 192 193 181 PyMac_PRECHECK(AEPutDesc); 182 #endif 183 if (!PyArg_ParseTuple(_args, "lO&", 184 &index, 185 AEDesc_Convert, &theAEDesc)) 186 return NULL; 187 _err = AEPutDesc(&_self->ob_itself, 188 index, 189 &theAEDesc); 190 if (_err != noErr) return PyMac_Error(_err); 191 Py_INCREF(Py_None); 192 _res = Py_None; 193 return _res; 194 194 } 195 195 196 196 static PyObject *AEDesc_AEGetNthPtr(AEDescObject *_self, PyObject *_args) 197 197 { 198 199 200 201 202 203 204 205 206 198 PyObject *_res = NULL; 199 OSErr _err; 200 long index; 201 DescType desiredType; 202 AEKeyword theAEKeyword; 203 DescType typeCode; 204 char *dataPtr__out__; 205 long dataPtr__len__; 206 int dataPtr__in_len__; 207 207 #ifndef AEGetNthPtr 208 209 #endif 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 208 PyMac_PRECHECK(AEGetNthPtr); 209 #endif 210 if (!PyArg_ParseTuple(_args, "lO&i", 211 &index, 212 PyMac_GetOSType, &desiredType, 213 &dataPtr__in_len__)) 214 return NULL; 215 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) 216 { 217 PyErr_NoMemory(); 218 goto dataPtr__error__; 219 } 220 dataPtr__len__ = dataPtr__in_len__; 221 _err = AEGetNthPtr(&_self->ob_itself, 222 index, 223 desiredType, 224 &theAEKeyword, 225 &typeCode, 226 dataPtr__out__, dataPtr__len__, &dataPtr__len__); 227 if (_err != noErr) return PyMac_Error(_err); 228 _res = Py_BuildValue("O&O&s#", 229 PyMac_BuildOSType, theAEKeyword, 230 PyMac_BuildOSType, typeCode, 231 dataPtr__out__, (int)dataPtr__len__); 232 free(dataPtr__out__); 233 233 dataPtr__error__: ; 234 234 return _res; 235 235 } 236 236 237 237 static PyObject *AEDesc_AEGetNthDesc(AEDescObject *_self, PyObject *_args) 238 238 { 239 240 241 242 243 244 239 PyObject *_res = NULL; 240 OSErr _err; 241 long index; 242 DescType desiredType; 243 AEKeyword theAEKeyword; 244 AEDesc result; 245 245 #ifndef AEGetNthDesc 246 247 #endif 248 249 250 251 252 253 254 255 256 257 258 259 260 261 246 PyMac_PRECHECK(AEGetNthDesc); 247 #endif 248 if (!PyArg_ParseTuple(_args, "lO&", 249 &index, 250 PyMac_GetOSType, &desiredType)) 251 return NULL; 252 _err = AEGetNthDesc(&_self->ob_itself, 253 index, 254 desiredType, 255 &theAEKeyword, 256 &result); 257 if (_err != noErr) return PyMac_Error(_err); 258 _res = Py_BuildValue("O&O&", 259 PyMac_BuildOSType, theAEKeyword, 260 AEDesc_New, &result); 261 return _res; 262 262 } 263 263 264 264 static PyObject *AEDesc_AESizeOfNthItem(AEDescObject *_self, PyObject *_args) 265 265 { 266 267 268 269 270 266 PyObject *_res = NULL; 267 OSErr _err; 268 long index; 269 DescType typeCode; 270 Size dataSize; 271 271 #ifndef AESizeOfNthItem 272 273 #endif 274 275 276 277 278 279 280 281 282 283 284 285 272 PyMac_PRECHECK(AESizeOfNthItem); 273 #endif 274 if (!PyArg_ParseTuple(_args, "l", 275 &index)) 276 return NULL; 277 _err = AESizeOfNthItem(&_self->ob_itself, 278 index, 279 &typeCode, 280 &dataSize); 281 if (_err != noErr) return PyMac_Error(_err); 282 _res = Py_BuildValue("O&l", 283 PyMac_BuildOSType, typeCode, 284 dataSize); 285 return _res; 286 286 } 287 287 288 288 static PyObject *AEDesc_AEDeleteItem(AEDescObject *_self, PyObject *_args) 289 289 { 290 291 292 290 PyObject *_res = NULL; 291 OSErr _err; 292 long index; 293 293 #ifndef AEDeleteItem 294 295 #endif 296 297 298 299 300 301 302 303 304 294 PyMac_PRECHECK(AEDeleteItem); 295 #endif 296 if (!PyArg_ParseTuple(_args, "l", 297 &index)) 298 return NULL; 299 _err = AEDeleteItem(&_self->ob_itself, 300 index); 301 if (_err != noErr) return PyMac_Error(_err); 302 Py_INCREF(Py_None); 303 _res = Py_None; 304 return _res; 305 305 } 306 306 307 307 static PyObject *AEDesc_AEPutParamPtr(AEDescObject *_self, PyObject *_args) 308 308 { 309 310 311 312 313 314 315 309 PyObject *_res = NULL; 310 OSErr _err; 311 AEKeyword theAEKeyword; 312 DescType typeCode; 313 char *dataPtr__in__; 314 long dataPtr__len__; 315 int dataPtr__in_len__; 316 316 #ifndef AEPutParamPtr 317 318 #endif 319 320 321 322 323 324 325 326 327 328 329 330 331 332 317 PyMac_PRECHECK(AEPutParamPtr); 318 #endif 319 if (!PyArg_ParseTuple(_args, "O&O&s#", 320 PyMac_GetOSType, &theAEKeyword, 321 PyMac_GetOSType, &typeCode, 322 &dataPtr__in__, &dataPtr__in_len__)) 323 return NULL; 324 dataPtr__len__ = dataPtr__in_len__; 325 _err = AEPutParamPtr(&_self->ob_itself, 326 theAEKeyword, 327 typeCode, 328 dataPtr__in__, dataPtr__len__); 329 if (_err != noErr) return PyMac_Error(_err); 330 Py_INCREF(Py_None); 331 _res = Py_None; 332 return _res; 333 333 } 334 334 335 335 static PyObject *AEDesc_AEPutParamDesc(AEDescObject *_self, PyObject *_args) 336 336 { 337 338 339 340 337 PyObject *_res = NULL; 338 OSErr _err; 339 AEKeyword theAEKeyword; 340 AEDesc theAEDesc; 341 341 #ifndef AEPutParamDesc 342 343 #endif 344 345 346 347 348 349 350 351 352 353 354 342 PyMac_PRECHECK(AEPutParamDesc); 343 #endif 344 if (!PyArg_ParseTuple(_args, "O&O&", 345 PyMac_GetOSType, &theAEKeyword, 346 AEDesc_Convert, &theAEDesc)) 347 return NULL; 348 _err = AEPutParamDesc(&_self->ob_itself, 349 theAEKeyword, 350 &theAEDesc); 351 if (_err != noErr) return PyMac_Error(_err); 352 Py_INCREF(Py_None); 353 _res = Py_None; 354 return _res; 355 355 } 356 356 357 357 static PyObject *AEDesc_AEGetParamPtr(AEDescObject *_self, PyObject *_args) 358 358 { 359 360 361 362 363 364 365 366 359 PyObject *_res = NULL; 360 OSErr _err; 361 AEKeyword theAEKeyword; 362 DescType desiredType; 363 DescType typeCode; 364 char *dataPtr__out__; 365 long dataPtr__len__; 366 int dataPtr__in_len__; 367 367 #ifndef AEGetParamPtr 368 369 #endif 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 368 PyMac_PRECHECK(AEGetParamPtr); 369 #endif 370 if (!PyArg_ParseTuple(_args, "O&O&i", 371 PyMac_GetOSType, &theAEKeyword, 372 PyMac_GetOSType, &desiredType, 373 &dataPtr__in_len__)) 374 return NULL; 375 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) 376 { 377 PyErr_NoMemory(); 378 goto dataPtr__error__; 379 } 380 dataPtr__len__ = dataPtr__in_len__; 381 _err = AEGetParamPtr(&_self->ob_itself, 382 theAEKeyword, 383 desiredType, 384 &typeCode, 385 dataPtr__out__, dataPtr__len__, &dataPtr__len__); 386 if (_err != noErr) return PyMac_Error(_err); 387 _res = Py_BuildValue("O&s#", 388 PyMac_BuildOSType, typeCode, 389 dataPtr__out__, (int)dataPtr__len__); 390 free(dataPtr__out__); 391 391 dataPtr__error__: ; 392 392 return _res; 393 393 } 394 394 395 395 static PyObject *AEDesc_AEGetParamDesc(AEDescObject *_self, PyObject *_args) 396 396 { 397 398 399 400 401 397 PyObject *_res = NULL; 398 OSErr _err; 399 AEKeyword theAEKeyword; 400 DescType desiredType; 401 AEDesc result; 402 402 #ifndef AEGetParamDesc 403 404 #endif 405 406 407 408 409 410 411 412 413 414 415 416 403 PyMac_PRECHECK(AEGetParamDesc); 404 #endif 405 if (!PyArg_ParseTuple(_args, "O&O&", 406 PyMac_GetOSType, &theAEKeyword, 407 PyMac_GetOSType, &desiredType)) 408 return NULL; 409 _err = AEGetParamDesc(&_self->ob_itself, 410 theAEKeyword, 411 desiredType, 412 &result); 413 if (_err != noErr) return PyMac_Error(_err); 414 _res = Py_BuildValue("O&", 415 AEDesc_New, &result); 416 return _res; 417 417 } 418 418 419 419 static PyObject *AEDesc_AESizeOfParam(AEDescObject *_self, PyObject *_args) 420 420 { 421 422 423 424 425 421 PyObject *_res = NULL; 422 OSErr _err; 423 AEKeyword theAEKeyword; 424 DescType typeCode; 425 Size dataSize; 426 426 #ifndef AESizeOfParam 427 428 #endif 429 430 431 432 433 434 435 436 437 438 439 440 427 PyMac_PRECHECK(AESizeOfParam); 428 #endif 429 if (!PyArg_ParseTuple(_args, "O&", 430 PyMac_GetOSType, &theAEKeyword)) 431 return NULL; 432 _err = AESizeOfParam(&_self->ob_itself, 433 theAEKeyword, 434 &typeCode, 435 &dataSize); 436 if (_err != noErr) return PyMac_Error(_err); 437 _res = Py_BuildValue("O&l", 438 PyMac_BuildOSType, typeCode, 439 dataSize); 440 return _res; 441 441 } 442 442 443 443 static PyObject *AEDesc_AEDeleteParam(AEDescObject *_self, PyObject *_args) 444 444 { 445 446 447 445 PyObject *_res = NULL; 446 OSErr _err; 447 AEKeyword theAEKeyword; 448 448 #ifndef AEDeleteParam 449 450 #endif 451 452 453 454 455 456 457 458 459 449 PyMac_PRECHECK(AEDeleteParam); 450 #endif 451 if (!PyArg_ParseTuple(_args, "O&", 452 PyMac_GetOSType, &theAEKeyword)) 453 return NULL; 454 _err = AEDeleteParam(&_self->ob_itself, 455 theAEKeyword); 456 if (_err != noErr) return PyMac_Error(_err); 457 Py_INCREF(Py_None); 458 _res = Py_None; 459 return _res; 460 460 } 461 461 462 462 static PyObject *AEDesc_AEGetAttributePtr(AEDescObject *_self, PyObject *_args) 463 463 { 464 465 466 467 468 469 470 471 464 PyObject *_res = NULL; 465 OSErr _err; 466 AEKeyword theAEKeyword; 467 DescType desiredType; 468 DescType typeCode; 469 char *dataPtr__out__; 470 long dataPtr__len__; 471 int dataPtr__in_len__; 472 472 #ifndef AEGetAttributePtr 473 474 #endif 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 473 PyMac_PRECHECK(AEGetAttributePtr); 474 #endif 475 if (!PyArg_ParseTuple(_args, "O&O&i", 476 PyMac_GetOSType, &theAEKeyword, 477 PyMac_GetOSType, &desiredType, 478 &dataPtr__in_len__)) 479 return NULL; 480 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) 481 { 482 PyErr_NoMemory(); 483 goto dataPtr__error__; 484 } 485 dataPtr__len__ = dataPtr__in_len__; 486 _err = AEGetAttributePtr(&_self->ob_itself, 487 theAEKeyword, 488 desiredType, 489 &typeCode, 490 dataPtr__out__, dataPtr__len__, &dataPtr__len__); 491 if (_err != noErr) return PyMac_Error(_err); 492 _res = Py_BuildValue("O&s#", 493 PyMac_BuildOSType, typeCode, 494 dataPtr__out__, (int)dataPtr__len__); 495 free(dataPtr__out__); 496 496 dataPtr__error__: ; 497 497 return _res; 498 498 } 499 499 500 500 static PyObject *AEDesc_AEGetAttributeDesc(AEDescObject *_self, PyObject *_args) 501 501 { 502 503 504 505 506 502 PyObject *_res = NULL; 503 OSErr _err; 504 AEKeyword theAEKeyword; 505 DescType desiredType; 506 AEDesc result; 507 507 #ifndef AEGetAttributeDesc 508 509 #endif 510 511 512 513 514 515 516 517 518 519 520 521 508 PyMac_PRECHECK(AEGetAttributeDesc); 509 #endif 510 if (!PyArg_ParseTuple(_args, "O&O&", 511 PyMac_GetOSType, &theAEKeyword, 512 PyMac_GetOSType, &desiredType)) 513 return NULL; 514 _err = AEGetAttributeDesc(&_self->ob_itself, 515 theAEKeyword, 516 desiredType, 517 &result); 518 if (_err != noErr) return PyMac_Error(_err); 519 _res = Py_BuildValue("O&", 520 AEDesc_New, &result); 521 return _res; 522 522 } 523 523 524 524 static PyObject *AEDesc_AESizeOfAttribute(AEDescObject *_self, PyObject *_args) 525 525 { 526 527 528 529 530 526 PyObject *_res = NULL; 527 OSErr _err; 528 AEKeyword theAEKeyword; 529 DescType typeCode; 530 Size dataSize; 531 531 #ifndef AESizeOfAttribute 532 533 #endif 534 535 536 537 538 539 540 541 542 543 544 545 532 PyMac_PRECHECK(AESizeOfAttribute); 533 #endif 534 if (!PyArg_ParseTuple(_args, "O&", 535 PyMac_GetOSType, &theAEKeyword)) 536 return NULL; 537 _err = AESizeOfAttribute(&_self->ob_itself, 538 theAEKeyword, 539 &typeCode, 540 &dataSize); 541 if (_err != noErr) return PyMac_Error(_err); 542 _res = Py_BuildValue("O&l", 543 PyMac_BuildOSType, typeCode, 544 dataSize); 545 return _res; 546 546 } 547 547 548 548 static PyObject *AEDesc_AEPutAttributePtr(AEDescObject *_self, PyObject *_args) 549 549 { 550 551 552 553 554 555 556 550 PyObject *_res = NULL; 551 OSErr _err; 552 AEKeyword theAEKeyword; 553 DescType typeCode; 554 char *dataPtr__in__; 555 long dataPtr__len__; 556 int dataPtr__in_len__; 557 557 #ifndef AEPutAttributePtr 558 559 #endif 560 561 562 563 564 565 566 567 568 569 570 571 572 573 558 PyMac_PRECHECK(AEPutAttributePtr); 559 #endif 560 if (!PyArg_ParseTuple(_args, "O&O&s#", 561 PyMac_GetOSType, &theAEKeyword, 562 PyMac_GetOSType, &typeCode, 563 &dataPtr__in__, &dataPtr__in_len__)) 564 return NULL; 565 dataPtr__len__ = dataPtr__in_len__; 566 _err = AEPutAttributePtr(&_self->ob_itself, 567 theAEKeyword, 568 typeCode, 569 dataPtr__in__, dataPtr__len__); 570 if (_err != noErr) return PyMac_Error(_err); 571 Py_INCREF(Py_None); 572 _res = Py_None; 573 return _res; 574 574 } 575 575 576 576 static PyObject *AEDesc_AEPutAttributeDesc(AEDescObject *_self, PyObject *_args) 577 577 { 578 579 580 581 578 PyObject *_res = NULL; 579 OSErr _err; 580 AEKeyword theAEKeyword; 581 AEDesc theAEDesc; 582 582 #ifndef AEPutAttributeDesc 583 584 #endif 585 586 587 588 589 590 591 592 593 594 595 583 PyMac_PRECHECK(AEPutAttributeDesc); 584 #endif 585 if (!PyArg_ParseTuple(_args, "O&O&", 586 PyMac_GetOSType, &theAEKeyword, 587 AEDesc_Convert, &theAEDesc)) 588 return NULL; 589 _err = AEPutAttributeDesc(&_self->ob_itself, 590 theAEKeyword, 591 &theAEDesc); 592 if (_err != noErr) return PyMac_Error(_err); 593 Py_INCREF(Py_None); 594 _res = Py_None; 595 return _res; 596 596 } 597 597 598 598 static PyObject *AEDesc_AEGetDescDataSize(AEDescObject *_self, PyObject *_args) 599 599 { 600 601 600 PyObject *_res = NULL; 601 Size _rv; 602 602 #ifndef AEGetDescDataSize 603 604 #endif 605 606 607 608 609 610 603 PyMac_PRECHECK(AEGetDescDataSize); 604 #endif 605 if (!PyArg_ParseTuple(_args, "")) 606 return NULL; 607 _rv = AEGetDescDataSize(&_self->ob_itself); 608 _res = Py_BuildValue("l", 609 _rv); 610 return _res; 611 611 } 612 612 613 613 static PyObject *AEDesc_AESend(AEDescObject *_self, PyObject *_args) 614 614 { 615 616 617 618 619 620 615 PyObject *_res = NULL; 616 OSErr _err; 617 AppleEvent reply; 618 AESendMode sendMode; 619 AESendPriority sendPriority; 620 long timeOutInTicks; 621 621 #ifndef AESend 622 623 #endif 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 622 PyMac_PRECHECK(AESend); 623 #endif 624 if (!PyArg_ParseTuple(_args, "lhl", 625 &sendMode, 626 &sendPriority, 627 &timeOutInTicks)) 628 return NULL; 629 _err = AESend(&_self->ob_itself, 630 &reply, 631 sendMode, 632 sendPriority, 633 timeOutInTicks, 634 upp_AEIdleProc, 635 (AEFilterUPP)0); 636 if (_err != noErr) return PyMac_Error(_err); 637 _res = Py_BuildValue("O&", 638 AEDesc_New, &reply); 639 return _res; 640 640 } 641 641 642 642 static PyObject *AEDesc_AEResetTimer(AEDescObject *_self, PyObject *_args) 643 643 { 644 645 644 PyObject *_res = NULL; 645 OSErr _err; 646 646 #ifndef AEResetTimer 647 648 #endif 649 650 651 652 653 654 655 647 PyMac_PRECHECK(AEResetTimer); 648 #endif 649 if (!PyArg_ParseTuple(_args, "")) 650 return NULL; 651 _err = AEResetTimer(&_self->ob_itself); 652 if (_err != noErr) return PyMac_Error(_err); 653 Py_INCREF(Py_None); 654 _res = Py_None; 655 return _res; 656 656 } 657 657 658 658 static PyObject *AEDesc_AESuspendTheCurrentEvent(AEDescObject *_self, PyObject *_args) 659 659 { 660 661 660 PyObject *_res = NULL; 661 OSErr _err; 662 662 #ifndef AESuspendTheCurrentEvent 663 664 #endif 665 666 667 668 669 670 671 663 PyMac_PRECHECK(AESuspendTheCurrentEvent); 664 #endif 665 if (!PyArg_ParseTuple(_args, "")) 666 return NULL; 667 _err = AESuspendTheCurrentEvent(&_self->ob_itself); 668 if (_err != noErr) return PyMac_Error(_err); 669 Py_INCREF(Py_None); 670 _res = Py_None; 671 return _res; 672 672 } 673 673 674 674 static PyObject *AEDesc_AEResumeTheCurrentEvent(AEDescObject *_self, PyObject *_args) 675 675 { 676 677 678 679 680 676 PyObject *_res = NULL; 677 OSErr _err; 678 AppleEvent reply; 679 AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler; 680 PyObject *dispatcher; 681 681 #ifndef AEResumeTheCurrentEvent 682 683 #endif 684 685 686 687 688 689 690 dispatcher__proc__, 691 692 693 694 695 696 682 PyMac_PRECHECK(AEResumeTheCurrentEvent); 683 #endif 684 if (!PyArg_ParseTuple(_args, "O&O", 685 AEDesc_Convert, &reply, 686 &dispatcher)) 687 return NULL; 688 _err = AEResumeTheCurrentEvent(&_self->ob_itself, 689 &reply, 690 dispatcher__proc__, 691 (SRefCon)dispatcher); 692 if (_err != noErr) return PyMac_Error(_err); 693 Py_INCREF(Py_None); 694 _res = Py_None; 695 Py_INCREF(dispatcher); /* XXX leak, but needed */ 696 return _res; 697 697 } 698 698 699 699 static PyObject *AEDesc_AEGetTheCurrentEvent(AEDescObject *_self, PyObject *_args) 700 700 { 701 702 701 PyObject *_res = NULL; 702 OSErr _err; 703 703 #ifndef AEGetTheCurrentEvent 704 705 #endif 706 707 708 709 710 711 712 704 PyMac_PRECHECK(AEGetTheCurrentEvent); 705 #endif 706 if (!PyArg_ParseTuple(_args, "")) 707 return NULL; 708 _err = AEGetTheCurrentEvent(&_self->ob_itself); 709 if (_err != noErr) return PyMac_Error(_err); 710 Py_INCREF(Py_None); 711 _res = Py_None; 712 return _res; 713 713 } 714 714 715 715 static PyObject *AEDesc_AESetTheCurrentEvent(AEDescObject *_self, PyObject *_args) 716 716 { 717 718 717 PyObject *_res = NULL; 718 OSErr _err; 719 719 #ifndef AESetTheCurrentEvent 720 721 #endif 722 723 724 725 726 727 728 720 PyMac_PRECHECK(AESetTheCurrentEvent); 721 #endif 722 if (!PyArg_ParseTuple(_args, "")) 723 return NULL; 724 _err = AESetTheCurrentEvent(&_self->ob_itself); 725 if (_err != noErr) return PyMac_Error(_err); 726 Py_INCREF(Py_None); 727 _res = Py_None; 728 return _res; 729 729 } 730 730 731 731 static PyObject *AEDesc_AEResolve(AEDescObject *_self, PyObject *_args) 732 732 { 733 734 735 736 733 PyObject *_res = NULL; 734 OSErr _err; 735 short callbackFlags; 736 AEDesc theToken; 737 737 #ifndef AEResolve 738 739 #endif 740 741 742 743 744 745 746 747 748 749 738 PyMac_PRECHECK(AEResolve); 739 #endif 740 if (!PyArg_ParseTuple(_args, "h", 741 &callbackFlags)) 742 return NULL; 743 _err = AEResolve(&_self->ob_itself, 744 callbackFlags, 745 &theToken); 746 if (_err != noErr) return PyMac_Error(_err); 747 _res = Py_BuildValue("O&", 748 AEDesc_New, &theToken); 749 return _res; 750 750 } 751 751 752 752 static PyObject *AEDesc_AutoDispose(AEDescObject *_self, PyObject *_args) 753 753 { 754 755 756 757 758 759 760 761 762 754 PyObject *_res = NULL; 755 756 int onoff, old; 757 if (!PyArg_ParseTuple(_args, "i", &onoff)) 758 return NULL; 759 old = _self->ob_owned; 760 _self->ob_owned = onoff; 761 _res = Py_BuildValue("i", old); 762 return _res; 763 763 764 764 } 765 765 766 766 static PyMethodDef AEDesc_methods[] = { 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 767 {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, 768 PyDoc_STR("(DescType toType) -> (AEDesc result)")}, 769 {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1, 770 PyDoc_STR("() -> (AEDesc result)")}, 771 {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1, 772 PyDoc_STR("() -> (long theCount)")}, 773 {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1, 774 PyDoc_STR("(long index, DescType typeCode, Buffer dataPtr) -> None")}, 775 {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1, 776 PyDoc_STR("(long index, AEDesc theAEDesc) -> None")}, 777 {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1, 778 PyDoc_STR("(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)")}, 779 {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1, 780 PyDoc_STR("(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)")}, 781 {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1, 782 PyDoc_STR("(long index) -> (DescType typeCode, Size dataSize)")}, 783 {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1, 784 PyDoc_STR("(long index) -> None")}, 785 {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1, 786 PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")}, 787 {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1, 788 PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")}, 789 {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1, 790 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")}, 791 {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1, 792 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")}, 793 {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1, 794 PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")}, 795 {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1, 796 PyDoc_STR("(AEKeyword theAEKeyword) -> None")}, 797 {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1, 798 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")}, 799 {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1, 800 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")}, 801 {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1, 802 PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")}, 803 {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1, 804 PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")}, 805 {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1, 806 PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")}, 807 {"AEGetDescDataSize", (PyCFunction)AEDesc_AEGetDescDataSize, 1, 808 PyDoc_STR("() -> (Size _rv)")}, 809 {"AESend", (PyCFunction)AEDesc_AESend, 1, 810 PyDoc_STR("(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)")}, 811 {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1, 812 PyDoc_STR("() -> None")}, 813 {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1, 814 PyDoc_STR("() -> None")}, 815 {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1, 816 PyDoc_STR("(AppleEvent reply, EventHandler dispatcher) -> None")}, 817 {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1, 818 PyDoc_STR("() -> None")}, 819 {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1, 820 PyDoc_STR("() -> None")}, 821 {"AEResolve", (PyCFunction)AEDesc_AEResolve, 1, 822 PyDoc_STR("(short callbackFlags) -> (AEDesc theToken)")}, 823 {"AutoDispose", (PyCFunction)AEDesc_AutoDispose, 1, 824 PyDoc_STR("(int)->int. Automatically AEDisposeDesc the object on Python object cleanup")}, 825 {NULL, NULL, 0} 826 826 }; 827 827 828 828 static PyObject *AEDesc_get_type(AEDescObject *self, void *closure) 829 829 { 830 830 return PyMac_BuildOSType(self->ob_itself.descriptorType); 831 831 } 832 832 … … 835 835 static PyObject *AEDesc_get_data(AEDescObject *self, void *closure) 836 836 { 837 838 839 840 841 842 843 844 845 846 847 848 849 837 PyObject *res; 838 Size size; 839 char *ptr; 840 OSErr err; 841 842 size = AEGetDescDataSize(&self->ob_itself); 843 if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL ) 844 return NULL; 845 if ( (ptr = PyString_AsString(res)) == NULL ) 846 return NULL; 847 if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 ) 848 return PyMac_Error(err); 849 return res; 850 850 } 851 851 … … 853 853 854 854 static PyGetSetDef AEDesc_getsetlist[] = { 855 856 857 855 {"type", (getter)AEDesc_get_type, (setter)AEDesc_set_type, "Type of this AEDesc"}, 856 {"data", (getter)AEDesc_get_data, (setter)AEDesc_set_data, "The raw data in this AEDesc"}, 857 {NULL, NULL, NULL, NULL}, 858 858 }; 859 859 … … 870 870 static PyObject *AEDesc_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 871 871 { 872 873 874 875 876 877 878 879 872 PyObject *_self; 873 AEDesc itself; 874 char *kw[] = {"itself", 0}; 875 876 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, AEDesc_Convert, &itself)) return NULL; 877 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; 878 ((AEDescObject *)_self)->ob_itself = itself; 879 return _self; 880 880 } 881 881 … … 884 884 885 885 PyTypeObject AEDesc_Type = { 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 886 PyObject_HEAD_INIT(NULL) 887 0, /*ob_size*/ 888 "_AE.AEDesc", /*tp_name*/ 889 sizeof(AEDescObject), /*tp_basicsize*/ 890 0, /*tp_itemsize*/ 891 /* methods */ 892 (destructor) AEDesc_dealloc, /*tp_dealloc*/ 893 0, /*tp_print*/ 894 (getattrfunc)0, /*tp_getattr*/ 895 (setattrfunc)0, /*tp_setattr*/ 896 (cmpfunc) AEDesc_compare, /*tp_compare*/ 897 (reprfunc) AEDesc_repr, /*tp_repr*/ 898 (PyNumberMethods *)0, /* tp_as_number */ 899 (PySequenceMethods *)0, /* tp_as_sequence */ 900 (PyMappingMethods *)0, /* tp_as_mapping */ 901 (hashfunc) AEDesc_hash, /*tp_hash*/ 902 0, /*tp_call*/ 903 0, /*tp_str*/ 904 PyObject_GenericGetAttr, /*tp_getattro*/ 905 PyObject_GenericSetAttr, /*tp_setattro */ 906 0, /*tp_as_buffer*/ 907 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 908 0, /*tp_doc*/ 909 0, /*tp_traverse*/ 910 0, /*tp_clear*/ 911 0, /*tp_richcompare*/ 912 0, /*tp_weaklistoffset*/ 913 0, /*tp_iter*/ 914 0, /*tp_iternext*/ 915 AEDesc_methods, /* tp_methods */ 916 0, /*tp_members*/ 917 AEDesc_getsetlist, /*tp_getset*/ 918 0, /*tp_base*/ 919 0, /*tp_dict*/ 920 0, /*tp_descr_get*/ 921 0, /*tp_descr_set*/ 922 0, /*tp_dictoffset*/ 923 AEDesc_tp_init, /* tp_init */ 924 AEDesc_tp_alloc, /* tp_alloc */ 925 AEDesc_tp_new, /* tp_new */ 926 AEDesc_tp_free, /* tp_free */ 927 927 }; 928 928 … … 932 932 static PyObject *AE_AECoercePtr(PyObject *_self, PyObject *_args) 933 933 { 934 935 936 937 938 939 940 941 934 PyObject *_res = NULL; 935 OSErr _err; 936 DescType typeCode; 937 char *dataPtr__in__; 938 long dataPtr__len__; 939 int dataPtr__in_len__; 940 DescType toType; 941 AEDesc result; 942 942 #ifndef AECoercePtr 943 944 #endif 945 946 947 948 949 950 951 952 953 954 955 956 957 958 943 PyMac_PRECHECK(AECoercePtr); 944 #endif 945 if (!PyArg_ParseTuple(_args, "O&s#O&", 946 PyMac_GetOSType, &typeCode, 947 &dataPtr__in__, &dataPtr__in_len__, 948 PyMac_GetOSType, &toType)) 949 return NULL; 950 dataPtr__len__ = dataPtr__in_len__; 951 _err = AECoercePtr(typeCode, 952 dataPtr__in__, dataPtr__len__, 953 toType, 954 &result); 955 if (_err != noErr) return PyMac_Error(_err); 956 _res = Py_BuildValue("O&", 957 AEDesc_New, &result); 958 return _res; 959 959 } 960 960 961 961 static PyObject *AE_AECreateDesc(PyObject *_self, PyObject *_args) 962 962 { 963 964 965 966 967 968 969 963 PyObject *_res = NULL; 964 OSErr _err; 965 DescType typeCode; 966 char *dataPtr__in__; 967 long dataPtr__len__; 968 int dataPtr__in_len__; 969 AEDesc result; 970 970 #ifndef AECreateDesc 971 972 #endif 973 974 975 976 977 978 979 980 981 982 983 984 971 PyMac_PRECHECK(AECreateDesc); 972 #endif 973 if (!PyArg_ParseTuple(_args, "O&s#", 974 PyMac_GetOSType, &typeCode, 975 &dataPtr__in__, &dataPtr__in_len__)) 976 return NULL; 977 dataPtr__len__ = dataPtr__in_len__; 978 _err = AECreateDesc(typeCode, 979 dataPtr__in__, dataPtr__len__, 980 &result); 981 if (_err != noErr) return PyMac_Error(_err); 982 _res = Py_BuildValue("O&", 983 AEDesc_New, &result); 984 return _res; 985 985 } 986 986 987 987 static PyObject *AE_AECreateList(PyObject *_self, PyObject *_args) 988 988 { 989 990 991 992 993 994 995 989 PyObject *_res = NULL; 990 OSErr _err; 991 char *factoringPtr__in__; 992 long factoringPtr__len__; 993 int factoringPtr__in_len__; 994 Boolean isRecord; 995 AEDescList resultList; 996 996 #ifndef AECreateList 997 998 #endif 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 997 PyMac_PRECHECK(AECreateList); 998 #endif 999 if (!PyArg_ParseTuple(_args, "s#b", 1000 &factoringPtr__in__, &factoringPtr__in_len__, 1001 &isRecord)) 1002 return NULL; 1003 factoringPtr__len__ = factoringPtr__in_len__; 1004 _err = AECreateList(factoringPtr__in__, factoringPtr__len__, 1005 isRecord, 1006 &resultList); 1007 if (_err != noErr) return PyMac_Error(_err); 1008 _res = Py_BuildValue("O&", 1009 AEDesc_New, &resultList); 1010 return _res; 1011 1011 } 1012 1012 1013 1013 static PyObject *AE_AECreateAppleEvent(PyObject *_self, PyObject *_args) 1014 1014 { 1015 1016 1017 1018 1019 1020 1021 1022 1015 PyObject *_res = NULL; 1016 OSErr _err; 1017 AEEventClass theAEEventClass; 1018 AEEventID theAEEventID; 1019 AEAddressDesc target; 1020 AEReturnID returnID; 1021 AETransactionID transactionID; 1022 AppleEvent result; 1023 1023 #ifndef AECreateAppleEvent 1024 1025 #endif 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1024 PyMac_PRECHECK(AECreateAppleEvent); 1025 #endif 1026 if (!PyArg_ParseTuple(_args, "O&O&O&hl", 1027 PyMac_GetOSType, &theAEEventClass, 1028 PyMac_GetOSType, &theAEEventID, 1029 AEDesc_Convert, &target, 1030 &returnID, 1031 &transactionID)) 1032 return NULL; 1033 _err = AECreateAppleEvent(theAEEventClass, 1034 theAEEventID, 1035 &target, 1036 returnID, 1037 transactionID, 1038 &result); 1039 if (_err != noErr) return PyMac_Error(_err); 1040 _res = Py_BuildValue("O&", 1041 AEDesc_New, &result); 1042 return _res; 1043 1043 } 1044 1044 1045 1045 static PyObject *AE_AEReplaceDescData(PyObject *_self, PyObject *_args) 1046 1046 { 1047 1048 1049 1050 1051 1052 1053 1047 PyObject *_res = NULL; 1048 OSErr _err; 1049 DescType typeCode; 1050 char *dataPtr__in__; 1051 long dataPtr__len__; 1052 int dataPtr__in_len__; 1053 AEDesc theAEDesc; 1054 1054 #ifndef AEReplaceDescData 1055 1056 #endif 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1055 PyMac_PRECHECK(AEReplaceDescData); 1056 #endif 1057 if (!PyArg_ParseTuple(_args, "O&s#", 1058 PyMac_GetOSType, &typeCode, 1059 &dataPtr__in__, &dataPtr__in_len__)) 1060 return NULL; 1061 dataPtr__len__ = dataPtr__in_len__; 1062 _err = AEReplaceDescData(typeCode, 1063 dataPtr__in__, dataPtr__len__, 1064 &theAEDesc); 1065 if (_err != noErr) return PyMac_Error(_err); 1066 _res = Py_BuildValue("O&", 1067 AEDesc_New, &theAEDesc); 1068 return _res; 1069 1069 } 1070 1070 1071 1071 static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args) 1072 1072 { 1073 1074 1075 1073 PyObject *_res = NULL; 1074 OSErr _err; 1075 EventRecord theEventRecord; 1076 1076 #ifndef AEProcessAppleEvent 1077 1078 #endif 1079 1080 1081 1082 1083 1084 1085 1086 1077 PyMac_PRECHECK(AEProcessAppleEvent); 1078 #endif 1079 if (!PyArg_ParseTuple(_args, "O&", 1080 PyMac_GetEventRecord, &theEventRecord)) 1081 return NULL; 1082 _err = AEProcessAppleEvent(&theEventRecord); 1083 if (_err != noErr) return PyMac_Error(_err); 1084 Py_INCREF(Py_None); 1085 _res = Py_None; 1086 return _res; 1087 1087 } 1088 1088 1089 1089 static PyObject *AE_AEGetInteractionAllowed(PyObject *_self, PyObject *_args) 1090 1090 { 1091 1092 1093 1091 PyObject *_res = NULL; 1092 OSErr _err; 1093 AEInteractAllowed level; 1094 1094 #ifndef AEGetInteractionAllowed 1095 1096 #endif 1097 1098 1099 1100 1101 1102 1103 1095 PyMac_PRECHECK(AEGetInteractionAllowed); 1096 #endif 1097 if (!PyArg_ParseTuple(_args, "")) 1098 return NULL; 1099 _err = AEGetInteractionAllowed(&level); 1100 if (_err != noErr) return PyMac_Error(_err); 1101 _res = Py_BuildValue("b", 1102 level); 1103 return _res; 1104 1104 } 1105 1105 1106 1106 static PyObject *AE_AESetInteractionAllowed(PyObject *_self, PyObject *_args) 1107 1107 { 1108 1109 1110 1108 PyObject *_res = NULL; 1109 OSErr _err; 1110 AEInteractAllowed level; 1111 1111 #ifndef AESetInteractionAllowed 1112 1113 #endif 1114 1115 1116 1117 1118 1119 1120 1121 1112 PyMac_PRECHECK(AESetInteractionAllowed); 1113 #endif 1114 if (!PyArg_ParseTuple(_args, "b", 1115 &level)) 1116 return NULL; 1117 _err = AESetInteractionAllowed(level); 1118 if (_err != noErr) return PyMac_Error(_err); 1119 Py_INCREF(Py_None); 1120 _res = Py_None; 1121 return _res; 1122 1122 } 1123 1123 1124 1124 static PyObject *AE_AEInteractWithUser(PyObject *_self, PyObject *_args) 1125 1125 { 1126 1127 1128 1126 PyObject *_res = NULL; 1127 OSErr _err; 1128 long timeOutInTicks; 1129 1129 #ifndef AEInteractWithUser 1130 1131 #endif 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1130 PyMac_PRECHECK(AEInteractWithUser); 1131 #endif 1132 if (!PyArg_ParseTuple(_args, "l", 1133 &timeOutInTicks)) 1134 return NULL; 1135 _err = AEInteractWithUser(timeOutInTicks, 1136 (NMRecPtr)0, 1137 upp_AEIdleProc); 1138 if (_err != noErr) return PyMac_Error(_err); 1139 Py_INCREF(Py_None); 1140 _res = Py_None; 1141 return _res; 1142 1142 } 1143 1143 1144 1144 static PyObject *AE_AEInstallEventHandler(PyObject *_self, PyObject *_args) 1145 1145 { 1146 1147 1148 1149 1150 1151 1146 PyObject *_res = NULL; 1147 OSErr _err; 1148 AEEventClass theAEEventClass; 1149 AEEventID theAEEventID; 1150 AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; 1151 PyObject *handler; 1152 1152 #ifndef AEInstallEventHandler 1153 1154 #endif 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1153 PyMac_PRECHECK(AEInstallEventHandler); 1154 #endif 1155 if (!PyArg_ParseTuple(_args, "O&O&O", 1156 PyMac_GetOSType, &theAEEventClass, 1157 PyMac_GetOSType, &theAEEventID, 1158 &handler)) 1159 return NULL; 1160 _err = AEInstallEventHandler(theAEEventClass, 1161 theAEEventID, 1162 handler__proc__, (SRefCon)handler, 1163 0); 1164 if (_err != noErr) return PyMac_Error(_err); 1165 Py_INCREF(Py_None); 1166 _res = Py_None; 1167 Py_INCREF(handler); /* XXX leak, but needed */ 1168 return _res; 1169 1169 } 1170 1170 1171 1171 static PyObject *AE_AERemoveEventHandler(PyObject *_self, PyObject *_args) 1172 1172 { 1173 1174 1175 1176 1173 PyObject *_res = NULL; 1174 OSErr _err; 1175 AEEventClass theAEEventClass; 1176 AEEventID theAEEventID; 1177 1177 #ifndef AERemoveEventHandler 1178 1179 #endif 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1178 PyMac_PRECHECK(AERemoveEventHandler); 1179 #endif 1180 if (!PyArg_ParseTuple(_args, "O&O&", 1181 PyMac_GetOSType, &theAEEventClass, 1182 PyMac_GetOSType, &theAEEventID)) 1183 return NULL; 1184 _err = AERemoveEventHandler(theAEEventClass, 1185 theAEEventID, 1186 upp_GenericEventHandler, 1187 0); 1188 if (_err != noErr) return PyMac_Error(_err); 1189 Py_INCREF(Py_None); 1190 _res = Py_None; 1191 return _res; 1192 1192 } 1193 1193 1194 1194 static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args) 1195 1195 { 1196 1197 1198 1199 1200 1201 1196 PyObject *_res = NULL; 1197 OSErr _err; 1198 AEEventClass theAEEventClass; 1199 AEEventID theAEEventID; 1200 AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; 1201 PyObject *handler; 1202 1202 #ifndef AEGetEventHandler 1203 1204 #endif 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1203 PyMac_PRECHECK(AEGetEventHandler); 1204 #endif 1205 if (!PyArg_ParseTuple(_args, "O&O&", 1206 PyMac_GetOSType, &theAEEventClass, 1207 PyMac_GetOSType, &theAEEventID)) 1208 return NULL; 1209 _err = AEGetEventHandler(theAEEventClass, 1210 theAEEventID, 1211 &handler__proc__, (SRefCon *)&handler, 1212 0); 1213 if (_err != noErr) return PyMac_Error(_err); 1214 _res = Py_BuildValue("O", 1215 handler); 1216 Py_INCREF(handler); /* XXX leak, but needed */ 1217 return _res; 1218 1218 } 1219 1219 1220 1220 static PyObject *AE_AEInstallSpecialHandler(PyObject *_self, PyObject *_args) 1221 1221 { 1222 1223 1224 1222 PyObject *_res = NULL; 1223 OSErr _err; 1224 AEKeyword functionClass; 1225 1225 #ifndef AEInstallSpecialHandler 1226 1227 #endif 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1226 PyMac_PRECHECK(AEInstallSpecialHandler); 1227 #endif 1228 if (!PyArg_ParseTuple(_args, "O&", 1229 PyMac_GetOSType, &functionClass)) 1230 return NULL; 1231 _err = AEInstallSpecialHandler(functionClass, 1232 upp_GenericEventHandler, 1233 0); 1234 if (_err != noErr) return PyMac_Error(_err); 1235 Py_INCREF(Py_None); 1236 _res = Py_None; 1237 return _res; 1238 1238 } 1239 1239 1240 1240 static PyObject *AE_AERemoveSpecialHandler(PyObject *_self, PyObject *_args) 1241 1241 { 1242 1243 1244 1242 PyObject *_res = NULL; 1243 OSErr _err; 1244 AEKeyword functionClass; 1245 1245 #ifndef AERemoveSpecialHandler 1246 1247 #endif 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1246 PyMac_PRECHECK(AERemoveSpecialHandler); 1247 #endif 1248 if (!PyArg_ParseTuple(_args, "O&", 1249 PyMac_GetOSType, &functionClass)) 1250 return NULL; 1251 _err = AERemoveSpecialHandler(functionClass, 1252 upp_GenericEventHandler, 1253 0); 1254 if (_err != noErr) return PyMac_Error(_err); 1255 Py_INCREF(Py_None); 1256 _res = Py_None; 1257 return _res; 1258 1258 } 1259 1259 1260 1260 static PyObject *AE_AEManagerInfo(PyObject *_self, PyObject *_args) 1261 1261 { 1262 1263 1264 1265 1262 PyObject *_res = NULL; 1263 OSErr _err; 1264 AEKeyword keyWord; 1265 long result; 1266 1266 #ifndef AEManagerInfo 1267 1268 #endif 1269 1270 1271 1272 1273 1274 1275 1276 1277 1267 PyMac_PRECHECK(AEManagerInfo); 1268 #endif 1269 if (!PyArg_ParseTuple(_args, "O&", 1270 PyMac_GetOSType, &keyWord)) 1271 return NULL; 1272 _err = AEManagerInfo(keyWord, 1273 &result); 1274 if (_err != noErr) return PyMac_Error(_err); 1275 _res = Py_BuildValue("l", 1276 result); 1277 return _res; 1278 1278 } 1279 1279 1280 1280 static PyObject *AE_AEObjectInit(PyObject *_self, PyObject *_args) 1281 1281 { 1282 1283 1282 PyObject *_res = NULL; 1283 OSErr _err; 1284 1284 #ifndef AEObjectInit 1285 1286 #endif 1287 1288 1289 1290 1291 1292 1293 1285 PyMac_PRECHECK(AEObjectInit); 1286 #endif 1287 if (!PyArg_ParseTuple(_args, "")) 1288 return NULL; 1289 _err = AEObjectInit(); 1290 if (_err != noErr) return PyMac_Error(_err); 1291 Py_INCREF(Py_None); 1292 _res = Py_None; 1293 return _res; 1294 1294 } 1295 1295 1296 1296 static PyObject *AE_AEDisposeToken(PyObject *_self, PyObject *_args) 1297 1297 { 1298 1299 1300 1298 PyObject *_res = NULL; 1299 OSErr _err; 1300 AEDesc theToken; 1301 1301 #ifndef AEDisposeToken 1302 1303 #endif 1304 1305 1306 1307 1308 1309 1310 1302 PyMac_PRECHECK(AEDisposeToken); 1303 #endif 1304 if (!PyArg_ParseTuple(_args, "")) 1305 return NULL; 1306 _err = AEDisposeToken(&theToken); 1307 if (_err != noErr) return PyMac_Error(_err); 1308 _res = Py_BuildValue("O&", 1309 AEDesc_New, &theToken); 1310 return _res; 1311 1311 } 1312 1312 1313 1313 static PyObject *AE_AECallObjectAccessor(PyObject *_self, PyObject *_args) 1314 1314 { 1315 1316 1317 1318 1319 1320 1321 1322 1315 PyObject *_res = NULL; 1316 OSErr _err; 1317 DescType desiredClass; 1318 AEDesc containerToken; 1319 DescType containerClass; 1320 DescType keyForm; 1321 AEDesc keyData; 1322 AEDesc token; 1323 1323 #ifndef AECallObjectAccessor 1324 1325 #endif 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1324 PyMac_PRECHECK(AECallObjectAccessor); 1325 #endif 1326 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&", 1327 PyMac_GetOSType, &desiredClass, 1328 AEDesc_Convert, &containerToken, 1329 PyMac_GetOSType, &containerClass, 1330 PyMac_GetOSType, &keyForm, 1331 AEDesc_Convert, &keyData)) 1332 return NULL; 1333 _err = AECallObjectAccessor(desiredClass, 1334 &containerToken, 1335 containerClass, 1336 keyForm, 1337 &keyData, 1338 &token); 1339 if (_err != noErr) return PyMac_Error(_err); 1340 _res = Py_BuildValue("O&", 1341 AEDesc_New, &token); 1342 return _res; 1343 1343 } 1344 1344 1345 1345 static PyMethodDef AE_methods[] = { 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1346 {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1, 1347 PyDoc_STR("(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)")}, 1348 {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1, 1349 PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc result)")}, 1350 {"AECreateList", (PyCFunction)AE_AECreateList, 1, 1351 PyDoc_STR("(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)")}, 1352 {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, 1353 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)")}, 1354 {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1, 1355 PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)")}, 1356 {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, 1357 PyDoc_STR("(EventRecord theEventRecord) -> None")}, 1358 {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, 1359 PyDoc_STR("() -> (AEInteractAllowed level)")}, 1360 {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1, 1361 PyDoc_STR("(AEInteractAllowed level) -> None")}, 1362 {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1, 1363 PyDoc_STR("(long timeOutInTicks) -> None")}, 1364 {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1, 1365 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None")}, 1366 {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1, 1367 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None")}, 1368 {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1, 1369 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)")}, 1370 {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1, 1371 PyDoc_STR("(AEKeyword functionClass) -> None")}, 1372 {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1, 1373 PyDoc_STR("(AEKeyword functionClass) -> None")}, 1374 {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1, 1375 PyDoc_STR("(AEKeyword keyWord) -> (long result)")}, 1376 {"AEObjectInit", (PyCFunction)AE_AEObjectInit, 1, 1377 PyDoc_STR("() -> None")}, 1378 {"AEDisposeToken", (PyCFunction)AE_AEDisposeToken, 1, 1379 PyDoc_STR("() -> (AEDesc theToken)")}, 1380 {"AECallObjectAccessor", (PyCFunction)AE_AECallObjectAccessor, 1, 1381 PyDoc_STR("(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)")}, 1382 {NULL, NULL, 0} 1383 1383 }; 1384 1384 … … 1388 1388 GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon) 1389 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 1390 PyObject *handler = (PyObject *)refcon; 1391 AEDescObject *requestObject, *replyObject; 1392 PyObject *args, *res; 1393 if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) { 1394 return -1; 1395 } 1396 if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) { 1397 Py_DECREF(requestObject); 1398 return -1; 1399 } 1400 if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) { 1401 Py_DECREF(requestObject); 1402 Py_DECREF(replyObject); 1403 return -1; 1404 } 1405 res = PyEval_CallObject(handler, args); 1406 requestObject->ob_itself.descriptorType = 'null'; 1407 requestObject->ob_itself.dataHandle = NULL; 1408 replyObject->ob_itself.descriptorType = 'null'; 1409 replyObject->ob_itself.dataHandle = NULL; 1410 Py_DECREF(args); 1411 if (res == NULL) { 1412 PySys_WriteStderr("Exception in AE event handler function\n"); 1413 PyErr_Print(); 1414 return -1; 1415 } 1416 Py_DECREF(res); 1417 return noErr; 1418 1418 } 1419 1419 1420 1420 PyObject *AEDesc_NewBorrowed(AEDesc *itself) 1421 1421 { 1422 1423 1424 1425 1426 1427 1422 PyObject *it; 1423 1424 it = AEDesc_New(itself); 1425 if (it) 1426 ((AEDescObject *)it)->ob_owned = 0; 1427 return (PyObject *)it; 1428 1428 } 1429 1429 … … 1432 1432 void init_AE(void) 1433 1433 { 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1434 PyObject *m; 1435 PyObject *d; 1436 1437 upp_AEIdleProc = NewAEIdleUPP(AEIdleProc); 1438 upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler); 1439 PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New); 1440 PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed); 1441 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert); 1442 1443 m = Py_InitModule("_AE", AE_methods); 1444 d = PyModule_GetDict(m); 1445 AE_Error = PyMac_GetOSErrException(); 1446 if (AE_Error == NULL || 1447 PyDict_SetItemString(d, "Error", AE_Error) != 0) 1448 return; 1449 AEDesc_Type.ob_type = &PyType_Type; 1450 if (PyType_Ready(&AEDesc_Type) < 0) return; 1451 Py_INCREF(&AEDesc_Type); 1452 PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type); 1453 /* Backward-compatible name */ 1454 Py_INCREF(&AEDesc_Type); 1455 PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type); 1456 1456 } 1457 1457
Note:
See TracChangeset
for help on using the changeset viewer.