fix to work on python <= 2.1
[python/dscho.git] / Mac / Modules / ae / aescan.py
blob80c198c38a9ff485d915edbe283fa9ba1df8f3db
1 # Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files.
2 # Then run aesupport to generate AEmodule.c.
3 # (Should learn how to tell the compiler to compile it as well.)
5 import sys
6 import os
7 import string
8 import MacOS
10 from bgenlocations import TOOLBOXDIR, BGENDIR
11 sys.path.append(BGENDIR)
13 from scantools import Scanner
15 def main():
16 print "=== Scanning AEDataModel.h, AppleEvents.h, AERegistry.h, AEObjects.h ==="
17 input = ["AEDataModel.h", "AEInteraction.h", "AppleEvents.h", "AERegistry.h", "AEObjects.h"]
18 output = "aegen.py"
19 defsoutput = TOOLBOXDIR + "AppleEvents.py"
20 scanner = AppleEventsScanner(input, output, defsoutput)
21 scanner.scan()
22 scanner.close()
23 print "=== Testing definitions output code ==="
24 execfile(defsoutput, {}, {})
25 print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
26 import aesupport
27 print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ==="
29 class AppleEventsScanner(Scanner):
31 def destination(self, type, name, arglist):
32 classname = "AEFunction"
33 listname = "functions"
34 if arglist:
35 t, n, m = arglist[0]
36 if t[-4:] == "_ptr" and m == "InMode" and \
37 t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
38 "AERecord", "AppleEvent"):
39 classname = "AEMethod"
40 listname = "aedescmethods"
41 return classname, listname
43 def makeblacklistnames(self):
44 return [
45 "AEDisposeDesc",
46 # "AEGetEventHandler",
47 "AEGetDescData", # Use object.data
48 "AEGetSpecialHandler",
49 # Constants with funny definitions
50 "kAEDontDisposeOnResume",
51 "kAEUseStandardDispatch",
54 def makeblacklisttypes(self):
55 return [
56 "ProcPtr",
57 "AEArrayType",
58 "AECoercionHandlerUPP",
59 "UniversalProcPtr",
60 "OSLCompareUPP",
61 "OSLAccessorUPP",
64 def makerepairinstructions(self):
65 return [
66 ([("Boolean", "isSysHandler", "InMode")],
67 [("AlwaysFalse", "*", "*")]),
69 ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
70 [("InBuffer", "*", "*")]),
72 ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
73 [("EventHandler", "*", "*")]),
75 ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
76 [("EventHandler", "*", "*")]),
78 ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
79 [("EventHandler", "*", "*")]),
81 ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
82 [("EventHandler", "*", "*")]),
84 ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
85 ("Size", "*", "OutMode")],
86 [("VarVarOutBuffer", "*", "InOutMode")]),
88 ([("AppleEvent", "theAppleEvent", "OutMode")],
89 [("AppleEvent_ptr", "*", "InMode")]),
91 ([("AEDescList", "theAEDescList", "OutMode")],
92 [("AEDescList_ptr", "*", "InMode")]),
95 def writeinitialdefs(self):
96 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
98 if __name__ == "__main__":
99 main()