ยปCore Development>Code coverage>Mac/Modules/cm/cmsupport.py

Python code coverage for Mac/Modules/cm/cmsupport.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 = 'Components.h' # The Apple header file
10n/aMODNAME = '_Cm' # The name of the module
11n/a
12n/a# The following is *usually* unchanged but may still require tuning
13n/aMODPREFIX = 'Cm' # The prefix for module-wide routines
14n/aC_OBJECTPREFIX = 'CmpObj' # The prefix for object methods
15n/aCI_OBJECTPREFIX = 'CmpInstObj'
16n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
17n/aOUTPUTFILE = MODNAME + "module.c" # The file generated by this program
18n/a
19n/afrom macsupport import *
20n/a
21n/a# Create the type objects
22n/a
23n/aincludestuff = includestuff + """
24n/a#include <Carbon/Carbon.h>
25n/a
26n/a#ifdef USE_TOOLBOX_OBJECT_GLUE
27n/aextern PyObject *_CmpObj_New(Component);
28n/aextern int _CmpObj_Convert(PyObject *, Component *);
29n/aextern PyObject *_CmpInstObj_New(ComponentInstance);
30n/aextern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
31n/a
32n/a#define CmpObj_New _CmpObj_New
33n/a#define CmpObj_Convert _CmpObj_Convert
34n/a#define CmpInstObj_New _CmpInstObj_New
35n/a#define CmpInstObj_Convert _CmpInstObj_Convert
36n/a#endif
37n/a
38n/a/*
39n/a** Parse/generate ComponentDescriptor records
40n/a*/
41n/astatic PyObject *
42n/aCmpDesc_New(ComponentDescription *itself)
43n/a{
44n/a
45n/a return Py_BuildValue("O&O&O&ll",
46n/a PyMac_BuildOSType, itself->componentType,
47n/a PyMac_BuildOSType, itself->componentSubType,
48n/a PyMac_BuildOSType, itself->componentManufacturer,
49n/a itself->componentFlags, itself->componentFlagsMask);
50n/a}
51n/a
52n/astatic int
53n/aCmpDesc_Convert(PyObject *v, ComponentDescription *p_itself)
54n/a{
55n/a return PyArg_ParseTuple(v, "O&O&O&ll",
56n/a PyMac_GetOSType, &p_itself->componentType,
57n/a PyMac_GetOSType, &p_itself->componentSubType,
58n/a PyMac_GetOSType, &p_itself->componentManufacturer,
59n/a &p_itself->componentFlags, &p_itself->componentFlagsMask);
60n/a}
61n/a
62n/a"""
63n/a
64n/ainitstuff = initstuff + """
65n/a PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New);
66n/a PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert);
67n/a PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New);
68n/a PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert);
69n/a"""
70n/a
71n/aComponentDescription = OpaqueType('ComponentDescription', 'CmpDesc')
72n/aComponent = OpaqueByValueType('Component', C_OBJECTPREFIX)
73n/aComponentInstance = OpaqueByValueType('ComponentInstance', CI_OBJECTPREFIX)
74n/aComponentResult = Type("ComponentResult", "l")
75n/a
76n/aComponentResourceHandle = OpaqueByValueType("ComponentResourceHandle", "ResObj")
77n/a
78n/aclass MyCIObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
79n/a def outputCheckNewArg(self):
80n/a Output("""if (itself == NULL) {
81n/a PyErr_SetString(Cm_Error,"NULL ComponentInstance");
82n/a return NULL;
83n/a }""")
84n/a
85n/aclass MyCObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
86n/a def outputCheckNewArg(self):
87n/a Output("""if (itself == NULL) {
88n/a /* XXXX Or should we return None? */
89n/a PyErr_SetString(Cm_Error,"No such component");
90n/a return NULL;
91n/a }""")
92n/a
93n/a def outputCheckConvertArg(self):
94n/a Output("""if ( v == Py_None ) {
95n/a *p_itself = 0;
96n/a return 1;
97n/a }""")
98n/a
99n/a# Create the generator groups and link them
100n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
101n/aci_object = MyCIObjectDefinition('ComponentInstance', CI_OBJECTPREFIX,
102n/a 'ComponentInstance')
103n/ac_object = MyCObjectDefinition('Component', C_OBJECTPREFIX, 'Component')
104n/amodule.addobject(ci_object)
105n/amodule.addobject(c_object)
106n/a
107n/a# Create the generator classes used to populate the lists
108n/aFunction = OSErrWeakLinkFunctionGenerator
109n/aMethod = OSErrWeakLinkMethodGenerator
110n/a
111n/a# Create and populate the lists
112n/afunctions = []
113n/ac_methods = []
114n/aci_methods = []
115n/aexecfile(INPUTFILE)
116n/a
117n/a# add the populated lists to the generator groups
118n/a# (in a different wordl the scan program would generate this)
119n/afor f in functions: module.add(f)
120n/afor f in c_methods: c_object.add(f)
121n/afor f in ci_methods: ci_object.add(f)
122n/a
123n/a# generate output (open the output file as late as possible)
124n/aSetOutputFileName(OUTPUTFILE)
125n/amodule.generate()