This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / ae / _AEmodule.c
blobaf88dd4eca5aa3642be14932cbcdfbc6cc451065
2 /* =========================== Module _AE =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <AppleEvents.h>
25 #include <AEObjects.h>
26 #else
27 #include <Carbon/Carbon.h>
28 #endif
30 #ifdef USE_TOOLBOX_OBJECT_GLUE
31 extern PyObject *_AEDesc_New(AEDesc *);
32 extern int _AEDesc_Convert(PyObject *, AEDesc *);
34 #define AEDesc_New _AEDesc_New
35 #define AEDesc_Convert _AEDesc_Convert
36 #endif
38 static pascal OSErr GenericEventHandler(); /* Forward */
40 AEEventHandlerUPP upp_GenericEventHandler;
42 static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
44 if ( PyOS_InterruptOccurred() )
45 return 1;
46 #if !TARGET_API_MAC_OSX
47 if ( PyMac_HandleEvent(theEvent) < 0 ) {
48 PySys_WriteStderr("Exception in user event handler during AE processing\n");
49 PyErr_Clear();
51 #endif
52 return 0;
55 AEIdleUPP upp_AEIdleProc;
57 static PyObject *AE_Error;
59 /* ----------------------- Object type AEDesc ----------------------- */
61 PyTypeObject AEDesc_Type;
63 #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type)
65 typedef struct AEDescObject {
66 PyObject_HEAD
67 AEDesc ob_itself;
68 } AEDescObject;
70 PyObject *AEDesc_New(AEDesc *itself)
72 AEDescObject *it;
73 it = PyObject_NEW(AEDescObject, &AEDesc_Type);
74 if (it == NULL) return NULL;
75 it->ob_itself = *itself;
76 return (PyObject *)it;
78 int AEDesc_Convert(PyObject *v, AEDesc *p_itself)
80 if (!AEDesc_Check(v))
82 PyErr_SetString(PyExc_TypeError, "AEDesc required");
83 return 0;
85 *p_itself = ((AEDescObject *)v)->ob_itself;
86 return 1;
89 static void AEDesc_dealloc(AEDescObject *self)
91 AEDisposeDesc(&self->ob_itself);
92 PyMem_DEL(self);
95 static PyObject *AEDesc_AECoerceDesc(AEDescObject *_self, PyObject *_args)
97 PyObject *_res = NULL;
98 OSErr _err;
99 DescType toType;
100 AEDesc result;
101 #ifndef AECoerceDesc
102 PyMac_PRECHECK(AECoerceDesc);
103 #endif
104 if (!PyArg_ParseTuple(_args, "O&",
105 PyMac_GetOSType, &toType))
106 return NULL;
107 _err = AECoerceDesc(&_self->ob_itself,
108 toType,
109 &result);
110 if (_err != noErr) return PyMac_Error(_err);
111 _res = Py_BuildValue("O&",
112 AEDesc_New, &result);
113 return _res;
116 static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args)
118 PyObject *_res = NULL;
119 OSErr _err;
120 AEDesc result;
121 #ifndef AEDuplicateDesc
122 PyMac_PRECHECK(AEDuplicateDesc);
123 #endif
124 if (!PyArg_ParseTuple(_args, ""))
125 return NULL;
126 _err = AEDuplicateDesc(&_self->ob_itself,
127 &result);
128 if (_err != noErr) return PyMac_Error(_err);
129 _res = Py_BuildValue("O&",
130 AEDesc_New, &result);
131 return _res;
134 static PyObject *AEDesc_AECountItems(AEDescObject *_self, PyObject *_args)
136 PyObject *_res = NULL;
137 OSErr _err;
138 long theCount;
139 #ifndef AECountItems
140 PyMac_PRECHECK(AECountItems);
141 #endif
142 if (!PyArg_ParseTuple(_args, ""))
143 return NULL;
144 _err = AECountItems(&_self->ob_itself,
145 &theCount);
146 if (_err != noErr) return PyMac_Error(_err);
147 _res = Py_BuildValue("l",
148 theCount);
149 return _res;
152 static PyObject *AEDesc_AEPutPtr(AEDescObject *_self, PyObject *_args)
154 PyObject *_res = NULL;
155 OSErr _err;
156 long index;
157 DescType typeCode;
158 char *dataPtr__in__;
159 long dataPtr__len__;
160 int dataPtr__in_len__;
161 #ifndef AEPutPtr
162 PyMac_PRECHECK(AEPutPtr);
163 #endif
164 if (!PyArg_ParseTuple(_args, "lO&s#",
165 &index,
166 PyMac_GetOSType, &typeCode,
167 &dataPtr__in__, &dataPtr__in_len__))
168 return NULL;
169 dataPtr__len__ = dataPtr__in_len__;
170 _err = AEPutPtr(&_self->ob_itself,
171 index,
172 typeCode,
173 dataPtr__in__, dataPtr__len__);
174 if (_err != noErr) return PyMac_Error(_err);
175 Py_INCREF(Py_None);
176 _res = Py_None;
177 return _res;
180 static PyObject *AEDesc_AEPutDesc(AEDescObject *_self, PyObject *_args)
182 PyObject *_res = NULL;
183 OSErr _err;
184 long index;
185 AEDesc theAEDesc;
186 #ifndef AEPutDesc
187 PyMac_PRECHECK(AEPutDesc);
188 #endif
189 if (!PyArg_ParseTuple(_args, "lO&",
190 &index,
191 AEDesc_Convert, &theAEDesc))
192 return NULL;
193 _err = AEPutDesc(&_self->ob_itself,
194 index,
195 &theAEDesc);
196 if (_err != noErr) return PyMac_Error(_err);
197 Py_INCREF(Py_None);
198 _res = Py_None;
199 return _res;
202 static PyObject *AEDesc_AEGetNthPtr(AEDescObject *_self, PyObject *_args)
204 PyObject *_res = NULL;
205 OSErr _err;
206 long index;
207 DescType desiredType;
208 AEKeyword theAEKeyword;
209 DescType typeCode;
210 char *dataPtr__out__;
211 long dataPtr__len__;
212 int dataPtr__in_len__;
213 #ifndef AEGetNthPtr
214 PyMac_PRECHECK(AEGetNthPtr);
215 #endif
216 if (!PyArg_ParseTuple(_args, "lO&i",
217 &index,
218 PyMac_GetOSType, &desiredType,
219 &dataPtr__in_len__))
220 return NULL;
221 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
223 PyErr_NoMemory();
224 goto dataPtr__error__;
226 dataPtr__len__ = dataPtr__in_len__;
227 _err = AEGetNthPtr(&_self->ob_itself,
228 index,
229 desiredType,
230 &theAEKeyword,
231 &typeCode,
232 dataPtr__out__, dataPtr__len__, &dataPtr__len__);
233 if (_err != noErr) return PyMac_Error(_err);
234 _res = Py_BuildValue("O&O&s#",
235 PyMac_BuildOSType, theAEKeyword,
236 PyMac_BuildOSType, typeCode,
237 dataPtr__out__, (int)dataPtr__len__);
238 free(dataPtr__out__);
239 dataPtr__error__: ;
240 return _res;
243 static PyObject *AEDesc_AEGetNthDesc(AEDescObject *_self, PyObject *_args)
245 PyObject *_res = NULL;
246 OSErr _err;
247 long index;
248 DescType desiredType;
249 AEKeyword theAEKeyword;
250 AEDesc result;
251 #ifndef AEGetNthDesc
252 PyMac_PRECHECK(AEGetNthDesc);
253 #endif
254 if (!PyArg_ParseTuple(_args, "lO&",
255 &index,
256 PyMac_GetOSType, &desiredType))
257 return NULL;
258 _err = AEGetNthDesc(&_self->ob_itself,
259 index,
260 desiredType,
261 &theAEKeyword,
262 &result);
263 if (_err != noErr) return PyMac_Error(_err);
264 _res = Py_BuildValue("O&O&",
265 PyMac_BuildOSType, theAEKeyword,
266 AEDesc_New, &result);
267 return _res;
270 static PyObject *AEDesc_AESizeOfNthItem(AEDescObject *_self, PyObject *_args)
272 PyObject *_res = NULL;
273 OSErr _err;
274 long index;
275 DescType typeCode;
276 Size dataSize;
277 #ifndef AESizeOfNthItem
278 PyMac_PRECHECK(AESizeOfNthItem);
279 #endif
280 if (!PyArg_ParseTuple(_args, "l",
281 &index))
282 return NULL;
283 _err = AESizeOfNthItem(&_self->ob_itself,
284 index,
285 &typeCode,
286 &dataSize);
287 if (_err != noErr) return PyMac_Error(_err);
288 _res = Py_BuildValue("O&l",
289 PyMac_BuildOSType, typeCode,
290 dataSize);
291 return _res;
294 static PyObject *AEDesc_AEDeleteItem(AEDescObject *_self, PyObject *_args)
296 PyObject *_res = NULL;
297 OSErr _err;
298 long index;
299 #ifndef AEDeleteItem
300 PyMac_PRECHECK(AEDeleteItem);
301 #endif
302 if (!PyArg_ParseTuple(_args, "l",
303 &index))
304 return NULL;
305 _err = AEDeleteItem(&_self->ob_itself,
306 index);
307 if (_err != noErr) return PyMac_Error(_err);
308 Py_INCREF(Py_None);
309 _res = Py_None;
310 return _res;
313 static PyObject *AEDesc_AEPutParamPtr(AEDescObject *_self, PyObject *_args)
315 PyObject *_res = NULL;
316 OSErr _err;
317 AEKeyword theAEKeyword;
318 DescType typeCode;
319 char *dataPtr__in__;
320 long dataPtr__len__;
321 int dataPtr__in_len__;
322 #ifndef AEPutParamPtr
323 PyMac_PRECHECK(AEPutParamPtr);
324 #endif
325 if (!PyArg_ParseTuple(_args, "O&O&s#",
326 PyMac_GetOSType, &theAEKeyword,
327 PyMac_GetOSType, &typeCode,
328 &dataPtr__in__, &dataPtr__in_len__))
329 return NULL;
330 dataPtr__len__ = dataPtr__in_len__;
331 _err = AEPutParamPtr(&_self->ob_itself,
332 theAEKeyword,
333 typeCode,
334 dataPtr__in__, dataPtr__len__);
335 if (_err != noErr) return PyMac_Error(_err);
336 Py_INCREF(Py_None);
337 _res = Py_None;
338 return _res;
341 static PyObject *AEDesc_AEPutParamDesc(AEDescObject *_self, PyObject *_args)
343 PyObject *_res = NULL;
344 OSErr _err;
345 AEKeyword theAEKeyword;
346 AEDesc theAEDesc;
347 #ifndef AEPutParamDesc
348 PyMac_PRECHECK(AEPutParamDesc);
349 #endif
350 if (!PyArg_ParseTuple(_args, "O&O&",
351 PyMac_GetOSType, &theAEKeyword,
352 AEDesc_Convert, &theAEDesc))
353 return NULL;
354 _err = AEPutParamDesc(&_self->ob_itself,
355 theAEKeyword,
356 &theAEDesc);
357 if (_err != noErr) return PyMac_Error(_err);
358 Py_INCREF(Py_None);
359 _res = Py_None;
360 return _res;
363 static PyObject *AEDesc_AEGetParamPtr(AEDescObject *_self, PyObject *_args)
365 PyObject *_res = NULL;
366 OSErr _err;
367 AEKeyword theAEKeyword;
368 DescType desiredType;
369 DescType typeCode;
370 char *dataPtr__out__;
371 long dataPtr__len__;
372 int dataPtr__in_len__;
373 #ifndef AEGetParamPtr
374 PyMac_PRECHECK(AEGetParamPtr);
375 #endif
376 if (!PyArg_ParseTuple(_args, "O&O&i",
377 PyMac_GetOSType, &theAEKeyword,
378 PyMac_GetOSType, &desiredType,
379 &dataPtr__in_len__))
380 return NULL;
381 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
383 PyErr_NoMemory();
384 goto dataPtr__error__;
386 dataPtr__len__ = dataPtr__in_len__;
387 _err = AEGetParamPtr(&_self->ob_itself,
388 theAEKeyword,
389 desiredType,
390 &typeCode,
391 dataPtr__out__, dataPtr__len__, &dataPtr__len__);
392 if (_err != noErr) return PyMac_Error(_err);
393 _res = Py_BuildValue("O&s#",
394 PyMac_BuildOSType, typeCode,
395 dataPtr__out__, (int)dataPtr__len__);
396 free(dataPtr__out__);
397 dataPtr__error__: ;
398 return _res;
401 static PyObject *AEDesc_AEGetParamDesc(AEDescObject *_self, PyObject *_args)
403 PyObject *_res = NULL;
404 OSErr _err;
405 AEKeyword theAEKeyword;
406 DescType desiredType;
407 AEDesc result;
408 #ifndef AEGetParamDesc
409 PyMac_PRECHECK(AEGetParamDesc);
410 #endif
411 if (!PyArg_ParseTuple(_args, "O&O&",
412 PyMac_GetOSType, &theAEKeyword,
413 PyMac_GetOSType, &desiredType))
414 return NULL;
415 _err = AEGetParamDesc(&_self->ob_itself,
416 theAEKeyword,
417 desiredType,
418 &result);
419 if (_err != noErr) return PyMac_Error(_err);
420 _res = Py_BuildValue("O&",
421 AEDesc_New, &result);
422 return _res;
425 static PyObject *AEDesc_AESizeOfParam(AEDescObject *_self, PyObject *_args)
427 PyObject *_res = NULL;
428 OSErr _err;
429 AEKeyword theAEKeyword;
430 DescType typeCode;
431 Size dataSize;
432 #ifndef AESizeOfParam
433 PyMac_PRECHECK(AESizeOfParam);
434 #endif
435 if (!PyArg_ParseTuple(_args, "O&",
436 PyMac_GetOSType, &theAEKeyword))
437 return NULL;
438 _err = AESizeOfParam(&_self->ob_itself,
439 theAEKeyword,
440 &typeCode,
441 &dataSize);
442 if (_err != noErr) return PyMac_Error(_err);
443 _res = Py_BuildValue("O&l",
444 PyMac_BuildOSType, typeCode,
445 dataSize);
446 return _res;
449 static PyObject *AEDesc_AEDeleteParam(AEDescObject *_self, PyObject *_args)
451 PyObject *_res = NULL;
452 OSErr _err;
453 AEKeyword theAEKeyword;
454 #ifndef AEDeleteParam
455 PyMac_PRECHECK(AEDeleteParam);
456 #endif
457 if (!PyArg_ParseTuple(_args, "O&",
458 PyMac_GetOSType, &theAEKeyword))
459 return NULL;
460 _err = AEDeleteParam(&_self->ob_itself,
461 theAEKeyword);
462 if (_err != noErr) return PyMac_Error(_err);
463 Py_INCREF(Py_None);
464 _res = Py_None;
465 return _res;
468 static PyObject *AEDesc_AEGetAttributePtr(AEDescObject *_self, PyObject *_args)
470 PyObject *_res = NULL;
471 OSErr _err;
472 AEKeyword theAEKeyword;
473 DescType desiredType;
474 DescType typeCode;
475 char *dataPtr__out__;
476 long dataPtr__len__;
477 int dataPtr__in_len__;
478 #ifndef AEGetAttributePtr
479 PyMac_PRECHECK(AEGetAttributePtr);
480 #endif
481 if (!PyArg_ParseTuple(_args, "O&O&i",
482 PyMac_GetOSType, &theAEKeyword,
483 PyMac_GetOSType, &desiredType,
484 &dataPtr__in_len__))
485 return NULL;
486 if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
488 PyErr_NoMemory();
489 goto dataPtr__error__;
491 dataPtr__len__ = dataPtr__in_len__;
492 _err = AEGetAttributePtr(&_self->ob_itself,
493 theAEKeyword,
494 desiredType,
495 &typeCode,
496 dataPtr__out__, dataPtr__len__, &dataPtr__len__);
497 if (_err != noErr) return PyMac_Error(_err);
498 _res = Py_BuildValue("O&s#",
499 PyMac_BuildOSType, typeCode,
500 dataPtr__out__, (int)dataPtr__len__);
501 free(dataPtr__out__);
502 dataPtr__error__: ;
503 return _res;
506 static PyObject *AEDesc_AEGetAttributeDesc(AEDescObject *_self, PyObject *_args)
508 PyObject *_res = NULL;
509 OSErr _err;
510 AEKeyword theAEKeyword;
511 DescType desiredType;
512 AEDesc result;
513 #ifndef AEGetAttributeDesc
514 PyMac_PRECHECK(AEGetAttributeDesc);
515 #endif
516 if (!PyArg_ParseTuple(_args, "O&O&",
517 PyMac_GetOSType, &theAEKeyword,
518 PyMac_GetOSType, &desiredType))
519 return NULL;
520 _err = AEGetAttributeDesc(&_self->ob_itself,
521 theAEKeyword,
522 desiredType,
523 &result);
524 if (_err != noErr) return PyMac_Error(_err);
525 _res = Py_BuildValue("O&",
526 AEDesc_New, &result);
527 return _res;
530 static PyObject *AEDesc_AESizeOfAttribute(AEDescObject *_self, PyObject *_args)
532 PyObject *_res = NULL;
533 OSErr _err;
534 AEKeyword theAEKeyword;
535 DescType typeCode;
536 Size dataSize;
537 #ifndef AESizeOfAttribute
538 PyMac_PRECHECK(AESizeOfAttribute);
539 #endif
540 if (!PyArg_ParseTuple(_args, "O&",
541 PyMac_GetOSType, &theAEKeyword))
542 return NULL;
543 _err = AESizeOfAttribute(&_self->ob_itself,
544 theAEKeyword,
545 &typeCode,
546 &dataSize);
547 if (_err != noErr) return PyMac_Error(_err);
548 _res = Py_BuildValue("O&l",
549 PyMac_BuildOSType, typeCode,
550 dataSize);
551 return _res;
554 static PyObject *AEDesc_AEPutAttributePtr(AEDescObject *_self, PyObject *_args)
556 PyObject *_res = NULL;
557 OSErr _err;
558 AEKeyword theAEKeyword;
559 DescType typeCode;
560 char *dataPtr__in__;
561 long dataPtr__len__;
562 int dataPtr__in_len__;
563 #ifndef AEPutAttributePtr
564 PyMac_PRECHECK(AEPutAttributePtr);
565 #endif
566 if (!PyArg_ParseTuple(_args, "O&O&s#",
567 PyMac_GetOSType, &theAEKeyword,
568 PyMac_GetOSType, &typeCode,
569 &dataPtr__in__, &dataPtr__in_len__))
570 return NULL;
571 dataPtr__len__ = dataPtr__in_len__;
572 _err = AEPutAttributePtr(&_self->ob_itself,
573 theAEKeyword,
574 typeCode,
575 dataPtr__in__, dataPtr__len__);
576 if (_err != noErr) return PyMac_Error(_err);
577 Py_INCREF(Py_None);
578 _res = Py_None;
579 return _res;
582 static PyObject *AEDesc_AEPutAttributeDesc(AEDescObject *_self, PyObject *_args)
584 PyObject *_res = NULL;
585 OSErr _err;
586 AEKeyword theAEKeyword;
587 AEDesc theAEDesc;
588 #ifndef AEPutAttributeDesc
589 PyMac_PRECHECK(AEPutAttributeDesc);
590 #endif
591 if (!PyArg_ParseTuple(_args, "O&O&",
592 PyMac_GetOSType, &theAEKeyword,
593 AEDesc_Convert, &theAEDesc))
594 return NULL;
595 _err = AEPutAttributeDesc(&_self->ob_itself,
596 theAEKeyword,
597 &theAEDesc);
598 if (_err != noErr) return PyMac_Error(_err);
599 Py_INCREF(Py_None);
600 _res = Py_None;
601 return _res;
604 #if TARGET_API_MAC_CARBON
606 static PyObject *AEDesc_AEGetDescDataSize(AEDescObject *_self, PyObject *_args)
608 PyObject *_res = NULL;
609 Size _rv;
610 #ifndef AEGetDescDataSize
611 PyMac_PRECHECK(AEGetDescDataSize);
612 #endif
613 if (!PyArg_ParseTuple(_args, ""))
614 return NULL;
615 _rv = AEGetDescDataSize(&_self->ob_itself);
616 _res = Py_BuildValue("l",
617 _rv);
618 return _res;
620 #endif
622 static PyObject *AEDesc_AESend(AEDescObject *_self, PyObject *_args)
624 PyObject *_res = NULL;
625 OSErr _err;
626 AppleEvent reply;
627 AESendMode sendMode;
628 AESendPriority sendPriority;
629 long timeOutInTicks;
630 #ifndef AESend
631 PyMac_PRECHECK(AESend);
632 #endif
633 if (!PyArg_ParseTuple(_args, "lhl",
634 &sendMode,
635 &sendPriority,
636 &timeOutInTicks))
637 return NULL;
638 _err = AESend(&_self->ob_itself,
639 &reply,
640 sendMode,
641 sendPriority,
642 timeOutInTicks,
643 upp_AEIdleProc,
644 (AEFilterUPP)0);
645 if (_err != noErr) return PyMac_Error(_err);
646 _res = Py_BuildValue("O&",
647 AEDesc_New, &reply);
648 return _res;
651 static PyObject *AEDesc_AEResetTimer(AEDescObject *_self, PyObject *_args)
653 PyObject *_res = NULL;
654 OSErr _err;
655 #ifndef AEResetTimer
656 PyMac_PRECHECK(AEResetTimer);
657 #endif
658 if (!PyArg_ParseTuple(_args, ""))
659 return NULL;
660 _err = AEResetTimer(&_self->ob_itself);
661 if (_err != noErr) return PyMac_Error(_err);
662 Py_INCREF(Py_None);
663 _res = Py_None;
664 return _res;
667 static PyObject *AEDesc_AESuspendTheCurrentEvent(AEDescObject *_self, PyObject *_args)
669 PyObject *_res = NULL;
670 OSErr _err;
671 #ifndef AESuspendTheCurrentEvent
672 PyMac_PRECHECK(AESuspendTheCurrentEvent);
673 #endif
674 if (!PyArg_ParseTuple(_args, ""))
675 return NULL;
676 _err = AESuspendTheCurrentEvent(&_self->ob_itself);
677 if (_err != noErr) return PyMac_Error(_err);
678 Py_INCREF(Py_None);
679 _res = Py_None;
680 return _res;
683 static PyObject *AEDesc_AEResumeTheCurrentEvent(AEDescObject *_self, PyObject *_args)
685 PyObject *_res = NULL;
686 OSErr _err;
687 AppleEvent reply;
688 AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler;
689 PyObject *dispatcher;
690 #ifndef AEResumeTheCurrentEvent
691 PyMac_PRECHECK(AEResumeTheCurrentEvent);
692 #endif
693 if (!PyArg_ParseTuple(_args, "O&O",
694 AEDesc_Convert, &reply,
695 &dispatcher))
696 return NULL;
697 _err = AEResumeTheCurrentEvent(&_self->ob_itself,
698 &reply,
699 dispatcher__proc__, (long)dispatcher);
700 if (_err != noErr) return PyMac_Error(_err);
701 Py_INCREF(Py_None);
702 _res = Py_None;
703 Py_INCREF(dispatcher); /* XXX leak, but needed */
704 return _res;
707 static PyObject *AEDesc_AEGetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
709 PyObject *_res = NULL;
710 OSErr _err;
711 #ifndef AEGetTheCurrentEvent
712 PyMac_PRECHECK(AEGetTheCurrentEvent);
713 #endif
714 if (!PyArg_ParseTuple(_args, ""))
715 return NULL;
716 _err = AEGetTheCurrentEvent(&_self->ob_itself);
717 if (_err != noErr) return PyMac_Error(_err);
718 Py_INCREF(Py_None);
719 _res = Py_None;
720 return _res;
723 static PyObject *AEDesc_AESetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
725 PyObject *_res = NULL;
726 OSErr _err;
727 #ifndef AESetTheCurrentEvent
728 PyMac_PRECHECK(AESetTheCurrentEvent);
729 #endif
730 if (!PyArg_ParseTuple(_args, ""))
731 return NULL;
732 _err = AESetTheCurrentEvent(&_self->ob_itself);
733 if (_err != noErr) return PyMac_Error(_err);
734 Py_INCREF(Py_None);
735 _res = Py_None;
736 return _res;
739 static PyObject *AEDesc_AEResolve(AEDescObject *_self, PyObject *_args)
741 PyObject *_res = NULL;
742 OSErr _err;
743 short callbackFlags;
744 AEDesc theToken;
745 #ifndef AEResolve
746 PyMac_PRECHECK(AEResolve);
747 #endif
748 if (!PyArg_ParseTuple(_args, "h",
749 &callbackFlags))
750 return NULL;
751 _err = AEResolve(&_self->ob_itself,
752 callbackFlags,
753 &theToken);
754 if (_err != noErr) return PyMac_Error(_err);
755 _res = Py_BuildValue("O&",
756 AEDesc_New, &theToken);
757 return _res;
760 static PyMethodDef AEDesc_methods[] = {
761 {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1,
762 "(DescType toType) -> (AEDesc result)"},
763 {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1,
764 "() -> (AEDesc result)"},
765 {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1,
766 "() -> (long theCount)"},
767 {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1,
768 "(long index, DescType typeCode, Buffer dataPtr) -> None"},
769 {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1,
770 "(long index, AEDesc theAEDesc) -> None"},
771 {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1,
772 "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"},
773 {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1,
774 "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"},
775 {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1,
776 "(long index) -> (DescType typeCode, Size dataSize)"},
777 {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1,
778 "(long index) -> None"},
779 {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1,
780 "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
781 {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1,
782 "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
783 {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1,
784 "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
785 {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1,
786 "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
787 {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1,
788 "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
789 {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1,
790 "(AEKeyword theAEKeyword) -> None"},
791 {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1,
792 "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
793 {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1,
794 "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
795 {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1,
796 "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
797 {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1,
798 "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
799 {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1,
800 "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
802 #if TARGET_API_MAC_CARBON
803 {"AEGetDescDataSize", (PyCFunction)AEDesc_AEGetDescDataSize, 1,
804 "() -> (Size _rv)"},
805 #endif
806 {"AESend", (PyCFunction)AEDesc_AESend, 1,
807 "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"},
808 {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1,
809 "() -> None"},
810 {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1,
811 "() -> None"},
812 {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1,
813 "(AppleEvent reply, EventHandler dispatcher) -> None"},
814 {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1,
815 "() -> None"},
816 {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1,
817 "() -> None"},
818 {"AEResolve", (PyCFunction)AEDesc_AEResolve, 1,
819 "(short callbackFlags) -> (AEDesc theToken)"},
820 {NULL, NULL, 0}
823 PyMethodChain AEDesc_chain = { AEDesc_methods, NULL };
825 static PyObject *AEDesc_getattr(AEDescObject *self, char *name)
828 if (strcmp(name, "type") == 0)
829 return PyMac_BuildOSType(self->ob_itself.descriptorType);
830 if (strcmp(name, "data") == 0) {
831 PyObject *res;
832 #if !TARGET_API_MAC_CARBON
833 char state;
834 state = HGetState(self->ob_itself.dataHandle);
835 HLock(self->ob_itself.dataHandle);
836 res = PyString_FromStringAndSize(
837 *self->ob_itself.dataHandle,
838 GetHandleSize(self->ob_itself.dataHandle));
839 HUnlock(self->ob_itself.dataHandle);
840 HSetState(self->ob_itself.dataHandle, state);
841 #else
842 Size size;
843 char *ptr;
844 OSErr err;
846 size = AEGetDescDataSize(&self->ob_itself);
847 if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
848 return NULL;
849 if ( (ptr = PyString_AsString(res)) == NULL )
850 return NULL;
851 if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
852 return PyMac_Error(err);
853 #endif
854 return res;
856 if (strcmp(name, "__members__") == 0)
857 return Py_BuildValue("[ss]", "data", "type");
859 return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name);
862 #define AEDesc_setattr NULL
864 #define AEDesc_compare NULL
866 #define AEDesc_repr NULL
868 #define AEDesc_hash NULL
870 PyTypeObject AEDesc_Type = {
871 PyObject_HEAD_INIT(NULL)
872 0, /*ob_size*/
873 "_AE.AEDesc", /*tp_name*/
874 sizeof(AEDescObject), /*tp_basicsize*/
875 0, /*tp_itemsize*/
876 /* methods */
877 (destructor) AEDesc_dealloc, /*tp_dealloc*/
878 0, /*tp_print*/
879 (getattrfunc) AEDesc_getattr, /*tp_getattr*/
880 (setattrfunc) AEDesc_setattr, /*tp_setattr*/
881 (cmpfunc) AEDesc_compare, /*tp_compare*/
882 (reprfunc) AEDesc_repr, /*tp_repr*/
883 (PyNumberMethods *)0, /* tp_as_number */
884 (PySequenceMethods *)0, /* tp_as_sequence */
885 (PyMappingMethods *)0, /* tp_as_mapping */
886 (hashfunc) AEDesc_hash, /*tp_hash*/
889 /* --------------------- End object type AEDesc --------------------- */
892 static PyObject *AE_AECoercePtr(PyObject *_self, PyObject *_args)
894 PyObject *_res = NULL;
895 OSErr _err;
896 DescType typeCode;
897 char *dataPtr__in__;
898 long dataPtr__len__;
899 int dataPtr__in_len__;
900 DescType toType;
901 AEDesc result;
902 #ifndef AECoercePtr
903 PyMac_PRECHECK(AECoercePtr);
904 #endif
905 if (!PyArg_ParseTuple(_args, "O&s#O&",
906 PyMac_GetOSType, &typeCode,
907 &dataPtr__in__, &dataPtr__in_len__,
908 PyMac_GetOSType, &toType))
909 return NULL;
910 dataPtr__len__ = dataPtr__in_len__;
911 _err = AECoercePtr(typeCode,
912 dataPtr__in__, dataPtr__len__,
913 toType,
914 &result);
915 if (_err != noErr) return PyMac_Error(_err);
916 _res = Py_BuildValue("O&",
917 AEDesc_New, &result);
918 return _res;
921 static PyObject *AE_AECreateDesc(PyObject *_self, PyObject *_args)
923 PyObject *_res = NULL;
924 OSErr _err;
925 DescType typeCode;
926 char *dataPtr__in__;
927 long dataPtr__len__;
928 int dataPtr__in_len__;
929 AEDesc result;
930 #ifndef AECreateDesc
931 PyMac_PRECHECK(AECreateDesc);
932 #endif
933 if (!PyArg_ParseTuple(_args, "O&s#",
934 PyMac_GetOSType, &typeCode,
935 &dataPtr__in__, &dataPtr__in_len__))
936 return NULL;
937 dataPtr__len__ = dataPtr__in_len__;
938 _err = AECreateDesc(typeCode,
939 dataPtr__in__, dataPtr__len__,
940 &result);
941 if (_err != noErr) return PyMac_Error(_err);
942 _res = Py_BuildValue("O&",
943 AEDesc_New, &result);
944 return _res;
947 static PyObject *AE_AECreateList(PyObject *_self, PyObject *_args)
949 PyObject *_res = NULL;
950 OSErr _err;
951 char *factoringPtr__in__;
952 long factoringPtr__len__;
953 int factoringPtr__in_len__;
954 Boolean isRecord;
955 AEDescList resultList;
956 #ifndef AECreateList
957 PyMac_PRECHECK(AECreateList);
958 #endif
959 if (!PyArg_ParseTuple(_args, "s#b",
960 &factoringPtr__in__, &factoringPtr__in_len__,
961 &isRecord))
962 return NULL;
963 factoringPtr__len__ = factoringPtr__in_len__;
964 _err = AECreateList(factoringPtr__in__, factoringPtr__len__,
965 isRecord,
966 &resultList);
967 if (_err != noErr) return PyMac_Error(_err);
968 _res = Py_BuildValue("O&",
969 AEDesc_New, &resultList);
970 return _res;
973 static PyObject *AE_AECreateAppleEvent(PyObject *_self, PyObject *_args)
975 PyObject *_res = NULL;
976 OSErr _err;
977 AEEventClass theAEEventClass;
978 AEEventID theAEEventID;
979 AEAddressDesc target;
980 AEReturnID returnID;
981 AETransactionID transactionID;
982 AppleEvent result;
983 #ifndef AECreateAppleEvent
984 PyMac_PRECHECK(AECreateAppleEvent);
985 #endif
986 if (!PyArg_ParseTuple(_args, "O&O&O&hl",
987 PyMac_GetOSType, &theAEEventClass,
988 PyMac_GetOSType, &theAEEventID,
989 AEDesc_Convert, &target,
990 &returnID,
991 &transactionID))
992 return NULL;
993 _err = AECreateAppleEvent(theAEEventClass,
994 theAEEventID,
995 &target,
996 returnID,
997 transactionID,
998 &result);
999 if (_err != noErr) return PyMac_Error(_err);
1000 _res = Py_BuildValue("O&",
1001 AEDesc_New, &result);
1002 return _res;
1005 #if TARGET_API_MAC_CARBON
1007 static PyObject *AE_AEReplaceDescData(PyObject *_self, PyObject *_args)
1009 PyObject *_res = NULL;
1010 OSErr _err;
1011 DescType typeCode;
1012 char *dataPtr__in__;
1013 long dataPtr__len__;
1014 int dataPtr__in_len__;
1015 AEDesc theAEDesc;
1016 #ifndef AEReplaceDescData
1017 PyMac_PRECHECK(AEReplaceDescData);
1018 #endif
1019 if (!PyArg_ParseTuple(_args, "O&s#",
1020 PyMac_GetOSType, &typeCode,
1021 &dataPtr__in__, &dataPtr__in_len__))
1022 return NULL;
1023 dataPtr__len__ = dataPtr__in_len__;
1024 _err = AEReplaceDescData(typeCode,
1025 dataPtr__in__, dataPtr__len__,
1026 &theAEDesc);
1027 if (_err != noErr) return PyMac_Error(_err);
1028 _res = Py_BuildValue("O&",
1029 AEDesc_New, &theAEDesc);
1030 return _res;
1032 #endif
1034 static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args)
1036 PyObject *_res = NULL;
1037 OSErr _err;
1038 EventRecord theEventRecord;
1039 #ifndef AEProcessAppleEvent
1040 PyMac_PRECHECK(AEProcessAppleEvent);
1041 #endif
1042 if (!PyArg_ParseTuple(_args, "O&",
1043 PyMac_GetEventRecord, &theEventRecord))
1044 return NULL;
1045 _err = AEProcessAppleEvent(&theEventRecord);
1046 if (_err != noErr) return PyMac_Error(_err);
1047 Py_INCREF(Py_None);
1048 _res = Py_None;
1049 return _res;
1052 static PyObject *AE_AEGetInteractionAllowed(PyObject *_self, PyObject *_args)
1054 PyObject *_res = NULL;
1055 OSErr _err;
1056 AEInteractAllowed level;
1057 #ifndef AEGetInteractionAllowed
1058 PyMac_PRECHECK(AEGetInteractionAllowed);
1059 #endif
1060 if (!PyArg_ParseTuple(_args, ""))
1061 return NULL;
1062 _err = AEGetInteractionAllowed(&level);
1063 if (_err != noErr) return PyMac_Error(_err);
1064 _res = Py_BuildValue("b",
1065 level);
1066 return _res;
1069 static PyObject *AE_AESetInteractionAllowed(PyObject *_self, PyObject *_args)
1071 PyObject *_res = NULL;
1072 OSErr _err;
1073 AEInteractAllowed level;
1074 #ifndef AESetInteractionAllowed
1075 PyMac_PRECHECK(AESetInteractionAllowed);
1076 #endif
1077 if (!PyArg_ParseTuple(_args, "b",
1078 &level))
1079 return NULL;
1080 _err = AESetInteractionAllowed(level);
1081 if (_err != noErr) return PyMac_Error(_err);
1082 Py_INCREF(Py_None);
1083 _res = Py_None;
1084 return _res;
1087 static PyObject *AE_AEInteractWithUser(PyObject *_self, PyObject *_args)
1089 PyObject *_res = NULL;
1090 OSErr _err;
1091 long timeOutInTicks;
1092 #ifndef AEInteractWithUser
1093 PyMac_PRECHECK(AEInteractWithUser);
1094 #endif
1095 if (!PyArg_ParseTuple(_args, "l",
1096 &timeOutInTicks))
1097 return NULL;
1098 _err = AEInteractWithUser(timeOutInTicks,
1099 (NMRecPtr)0,
1100 upp_AEIdleProc);
1101 if (_err != noErr) return PyMac_Error(_err);
1102 Py_INCREF(Py_None);
1103 _res = Py_None;
1104 return _res;
1107 static PyObject *AE_AEInstallEventHandler(PyObject *_self, PyObject *_args)
1109 PyObject *_res = NULL;
1110 OSErr _err;
1111 AEEventClass theAEEventClass;
1112 AEEventID theAEEventID;
1113 AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
1114 PyObject *handler;
1115 #ifndef AEInstallEventHandler
1116 PyMac_PRECHECK(AEInstallEventHandler);
1117 #endif
1118 if (!PyArg_ParseTuple(_args, "O&O&O",
1119 PyMac_GetOSType, &theAEEventClass,
1120 PyMac_GetOSType, &theAEEventID,
1121 &handler))
1122 return NULL;
1123 _err = AEInstallEventHandler(theAEEventClass,
1124 theAEEventID,
1125 handler__proc__, (long)handler,
1127 if (_err != noErr) return PyMac_Error(_err);
1128 Py_INCREF(Py_None);
1129 _res = Py_None;
1130 Py_INCREF(handler); /* XXX leak, but needed */
1131 return _res;
1134 static PyObject *AE_AERemoveEventHandler(PyObject *_self, PyObject *_args)
1136 PyObject *_res = NULL;
1137 OSErr _err;
1138 AEEventClass theAEEventClass;
1139 AEEventID theAEEventID;
1140 #ifndef AERemoveEventHandler
1141 PyMac_PRECHECK(AERemoveEventHandler);
1142 #endif
1143 if (!PyArg_ParseTuple(_args, "O&O&",
1144 PyMac_GetOSType, &theAEEventClass,
1145 PyMac_GetOSType, &theAEEventID))
1146 return NULL;
1147 _err = AERemoveEventHandler(theAEEventClass,
1148 theAEEventID,
1149 upp_GenericEventHandler,
1151 if (_err != noErr) return PyMac_Error(_err);
1152 Py_INCREF(Py_None);
1153 _res = Py_None;
1154 return _res;
1157 static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args)
1159 PyObject *_res = NULL;
1160 OSErr _err;
1161 AEEventClass theAEEventClass;
1162 AEEventID theAEEventID;
1163 AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
1164 PyObject *handler;
1165 #ifndef AEGetEventHandler
1166 PyMac_PRECHECK(AEGetEventHandler);
1167 #endif
1168 if (!PyArg_ParseTuple(_args, "O&O&",
1169 PyMac_GetOSType, &theAEEventClass,
1170 PyMac_GetOSType, &theAEEventID))
1171 return NULL;
1172 _err = AEGetEventHandler(theAEEventClass,
1173 theAEEventID,
1174 &handler__proc__, (long *)&handler,
1176 if (_err != noErr) return PyMac_Error(_err);
1177 _res = Py_BuildValue("O",
1178 handler);
1179 Py_INCREF(handler); /* XXX leak, but needed */
1180 return _res;
1183 static PyObject *AE_AEInstallSpecialHandler(PyObject *_self, PyObject *_args)
1185 PyObject *_res = NULL;
1186 OSErr _err;
1187 AEKeyword functionClass;
1188 #ifndef AEInstallSpecialHandler
1189 PyMac_PRECHECK(AEInstallSpecialHandler);
1190 #endif
1191 if (!PyArg_ParseTuple(_args, "O&",
1192 PyMac_GetOSType, &functionClass))
1193 return NULL;
1194 _err = AEInstallSpecialHandler(functionClass,
1195 upp_GenericEventHandler,
1197 if (_err != noErr) return PyMac_Error(_err);
1198 Py_INCREF(Py_None);
1199 _res = Py_None;
1200 return _res;
1203 static PyObject *AE_AERemoveSpecialHandler(PyObject *_self, PyObject *_args)
1205 PyObject *_res = NULL;
1206 OSErr _err;
1207 AEKeyword functionClass;
1208 #ifndef AERemoveSpecialHandler
1209 PyMac_PRECHECK(AERemoveSpecialHandler);
1210 #endif
1211 if (!PyArg_ParseTuple(_args, "O&",
1212 PyMac_GetOSType, &functionClass))
1213 return NULL;
1214 _err = AERemoveSpecialHandler(functionClass,
1215 upp_GenericEventHandler,
1217 if (_err != noErr) return PyMac_Error(_err);
1218 Py_INCREF(Py_None);
1219 _res = Py_None;
1220 return _res;
1223 static PyObject *AE_AEManagerInfo(PyObject *_self, PyObject *_args)
1225 PyObject *_res = NULL;
1226 OSErr _err;
1227 AEKeyword keyWord;
1228 long result;
1229 #ifndef AEManagerInfo
1230 PyMac_PRECHECK(AEManagerInfo);
1231 #endif
1232 if (!PyArg_ParseTuple(_args, "O&",
1233 PyMac_GetOSType, &keyWord))
1234 return NULL;
1235 _err = AEManagerInfo(keyWord,
1236 &result);
1237 if (_err != noErr) return PyMac_Error(_err);
1238 _res = Py_BuildValue("l",
1239 result);
1240 return _res;
1243 static PyObject *AE_AEObjectInit(PyObject *_self, PyObject *_args)
1245 PyObject *_res = NULL;
1246 OSErr _err;
1247 #ifndef AEObjectInit
1248 PyMac_PRECHECK(AEObjectInit);
1249 #endif
1250 if (!PyArg_ParseTuple(_args, ""))
1251 return NULL;
1252 _err = AEObjectInit();
1253 if (_err != noErr) return PyMac_Error(_err);
1254 Py_INCREF(Py_None);
1255 _res = Py_None;
1256 return _res;
1259 static PyObject *AE_AEDisposeToken(PyObject *_self, PyObject *_args)
1261 PyObject *_res = NULL;
1262 OSErr _err;
1263 AEDesc theToken;
1264 #ifndef AEDisposeToken
1265 PyMac_PRECHECK(AEDisposeToken);
1266 #endif
1267 if (!PyArg_ParseTuple(_args, ""))
1268 return NULL;
1269 _err = AEDisposeToken(&theToken);
1270 if (_err != noErr) return PyMac_Error(_err);
1271 _res = Py_BuildValue("O&",
1272 AEDesc_New, &theToken);
1273 return _res;
1276 static PyObject *AE_AECallObjectAccessor(PyObject *_self, PyObject *_args)
1278 PyObject *_res = NULL;
1279 OSErr _err;
1280 DescType desiredClass;
1281 AEDesc containerToken;
1282 DescType containerClass;
1283 DescType keyForm;
1284 AEDesc keyData;
1285 AEDesc token;
1286 #ifndef AECallObjectAccessor
1287 PyMac_PRECHECK(AECallObjectAccessor);
1288 #endif
1289 if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
1290 PyMac_GetOSType, &desiredClass,
1291 AEDesc_Convert, &containerToken,
1292 PyMac_GetOSType, &containerClass,
1293 PyMac_GetOSType, &keyForm,
1294 AEDesc_Convert, &keyData))
1295 return NULL;
1296 _err = AECallObjectAccessor(desiredClass,
1297 &containerToken,
1298 containerClass,
1299 keyForm,
1300 &keyData,
1301 &token);
1302 if (_err != noErr) return PyMac_Error(_err);
1303 _res = Py_BuildValue("O&",
1304 AEDesc_New, &token);
1305 return _res;
1308 static PyMethodDef AE_methods[] = {
1309 {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1,
1310 "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"},
1311 {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1,
1312 "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"},
1313 {"AECreateList", (PyCFunction)AE_AECreateList, 1,
1314 "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"},
1315 {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1,
1316 "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)"},
1318 #if TARGET_API_MAC_CARBON
1319 {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1,
1320 "(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)"},
1321 #endif
1322 {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1,
1323 "(EventRecord theEventRecord) -> None"},
1324 {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1,
1325 "() -> (AEInteractAllowed level)"},
1326 {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1,
1327 "(AEInteractAllowed level) -> None"},
1328 {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1,
1329 "(long timeOutInTicks) -> None"},
1330 {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1,
1331 "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"},
1332 {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1,
1333 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"},
1334 {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1,
1335 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)"},
1336 {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1,
1337 "(AEKeyword functionClass) -> None"},
1338 {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1,
1339 "(AEKeyword functionClass) -> None"},
1340 {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1,
1341 "(AEKeyword keyWord) -> (long result)"},
1342 {"AEObjectInit", (PyCFunction)AE_AEObjectInit, 1,
1343 "() -> None"},
1344 {"AEDisposeToken", (PyCFunction)AE_AEDisposeToken, 1,
1345 "() -> (AEDesc theToken)"},
1346 {"AECallObjectAccessor", (PyCFunction)AE_AECallObjectAccessor, 1,
1347 "(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)"},
1348 {NULL, NULL, 0}
1353 #if UNIVERSAL_INTERFACES_VERSION >= 0x0340
1354 typedef long refcontype;
1355 #else
1356 typedef unsigned long refcontype;
1357 #endif
1359 static pascal OSErr
1360 GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
1362 PyObject *handler = (PyObject *)refcon;
1363 AEDescObject *requestObject, *replyObject;
1364 PyObject *args, *res;
1365 if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
1366 return -1;
1368 if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
1369 Py_DECREF(requestObject);
1370 return -1;
1372 if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
1373 Py_DECREF(requestObject);
1374 Py_DECREF(replyObject);
1375 return -1;
1377 res = PyEval_CallObject(handler, args);
1378 requestObject->ob_itself.descriptorType = 'null';
1379 requestObject->ob_itself.dataHandle = NULL;
1380 replyObject->ob_itself.descriptorType = 'null';
1381 replyObject->ob_itself.dataHandle = NULL;
1382 Py_DECREF(args);
1383 if (res == NULL) {
1384 PySys_WriteStderr("Exception in AE event handler function\n");
1385 PyErr_Print();
1386 return -1;
1388 Py_DECREF(res);
1389 return noErr;
1393 void init_AE(void)
1395 PyObject *m;
1396 PyObject *d;
1400 upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
1401 #if UNIVERSAL_INTERFACES_VERSION >= 0x03400
1402 upp_GenericEventHandler = NewAEEventHandlerUPP(&GenericEventHandler);
1403 #else
1404 upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
1405 #endif
1406 PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
1407 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
1410 m = Py_InitModule("_AE", AE_methods);
1411 d = PyModule_GetDict(m);
1412 AE_Error = PyMac_GetOSErrException();
1413 if (AE_Error == NULL ||
1414 PyDict_SetItemString(d, "Error", AE_Error) != 0)
1415 return;
1416 AEDesc_Type.ob_type = &PyType_Type;
1417 Py_INCREF(&AEDesc_Type);
1418 if (PyDict_SetItemString(d, "AEDescType", (PyObject *)&AEDesc_Type) != 0)
1419 Py_FatalError("can't initialize AEDescType");
1422 /* ========================= End module _AE ========================= */