ยปCore Development>Code coverage>Mac/Modules/osa/osasupport.py

Python code coverage for Mac/Modules/osa/osasupport.py

#countcontent
1n/a# This script generates a Python interface for an Apple Macintosh Manager.
2n/a# It uses the "bgen" package to generate C code.
3n/a# The function specifications are generated by scanning the mamager's header file,
4n/a# using the "scantools" package (customized for this particular manager).
5n/a
6n/aimport string
7n/a
8n/a# Declarations that change for each manager
9n/aMACHEADERFILE = 'OSA.h' # The Apple header file
10n/aMODNAME = '_OSA' # The name of the module
11n/a
12n/a# The following is *usually* unchanged but may still require tuning
13n/aMODPREFIX = 'OSA' # The prefix for module-wide routines
14n/aOBJECTPREFIX = 'OSAObj' # The prefix for object methods
15n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
16n/aOUTPUTFILE = MODNAME + "module.c" # The file generated by this program
17n/a
18n/afrom macsupport import *
19n/a
20n/a# Create the type objects
21n/a
22n/aincludestuff = includestuff + """
23n/a#if PY_VERSION_HEX < 0x02040000
24n/aPyObject *PyMac_GetOSErrException(void);
25n/a#endif
26n/a#include <Carbon/Carbon.h>
27n/a
28n/a#ifdef USE_TOOLBOX_OBJECT_GLUE
29n/aextern PyObject *_OSAObj_New(ComponentInstance);
30n/aextern int _OSAObj_Convert(PyObject *, ComponentInstance *);
31n/a
32n/a#define OSAObj_New _OSAObj_New
33n/a#define OSAObj_Convert _OSAObj_Convert
34n/a#endif
35n/a"""
36n/a
37n/ainitstuff = initstuff + """
38n/a/*
39n/a PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New);
40n/a PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert);
41n/a*/
42n/a"""
43n/a
44n/aComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX)
45n/aOSAError = OSErrType("OSAError", "l")
46n/a# OSALocalOrGlobal = Type("OSALocalOrGlobal", "l")
47n/aOSAID = Type("OSAID", "l")
48n/aOSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l")
49n/aOSADebugSessionRef = Type("OSADebugSessionRef", "l")
50n/aOSADebugStepKind = Type("OSADebugStepKind", "l")
51n/aDescType = OSTypeType("DescType")
52n/aAEDesc = OpaqueType('AEDesc')
53n/aAEDesc_ptr = OpaqueType('AEDesc')
54n/aAEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
55n/aAEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
56n/aAEDescList = OpaqueType('AEDescList', 'AEDesc')
57n/aAEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
58n/aAERecord = OpaqueType('AERecord', 'AEDesc')
59n/aAERecord_ptr = OpaqueType('AERecord', 'AEDesc')
60n/aAppleEvent = OpaqueType('AppleEvent', 'AEDesc')
61n/aAppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
62n/a
63n/a# NOTE: at the moment OSA.ComponentInstance is not a subclass
64n/a# of Cm.ComponentInstance. If this is a problem it can be fixed.
65n/aclass MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
66n/a def outputCheckNewArg(self):
67n/a Output("""if (itself == NULL) {
68n/a PyErr_SetString(OSA_Error,"NULL ComponentInstance");
69n/a return NULL;
70n/a }""")
71n/a
72n/a def outputCheckConvertArg(self):
73n/a Output("""
74n/a if (CmpInstObj_Convert(v, p_itself))
75n/a return 1;
76n/a PyErr_Clear();
77n/a """)
78n/a
79n/a
80n/a# Create the generator groups and link them
81n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
82n/aobject = MyObjectDefinition('OSAComponentInstance', OBJECTPREFIX,
83n/a 'ComponentInstance')
84n/amodule.addobject(object)
85n/a
86n/a# Create the generator classes used to populate the lists
87n/aFunction = OSErrWeakLinkFunctionGenerator
88n/aMethod = OSErrWeakLinkMethodGenerator
89n/a
90n/a# Test which types we are still missing.
91n/aexecfile(string.lower(MODPREFIX) + 'typetest.py')
92n/a
93n/a# Create and populate the lists
94n/afunctions = []
95n/amethods = []
96n/aexecfile(INPUTFILE)
97n/a
98n/a# add the populated lists to the generator groups
99n/a# (in a different wordl the scan program would generate this)
100n/afor f in functions: module.add(f)
101n/afor f in methods: object.add(f)
102n/a
103n/a# generate output (open the output file as late as possible)
104n/aSetOutputFileName(OUTPUTFILE)
105n/amodule.generate()