blob: df89c4e7c59028455012683031b576e5b0144030 [file] [log] [blame]
Daniel Veillardd2897fd2002-01-30 16:37:32 +00001#!/usr/bin/python -u
2#
3# generate python wrappers from the XML API description
4#
5
6functions = {}
Daniel Veillard4f4a27f2004-01-14 23:50:34 +00007enums = {} # { enumType: { enumConstant: enumValue } }
Daniel Veillardd2897fd2002-01-30 16:37:32 +00008
Daniel Veillard0fea6f42002-02-22 22:51:13 +00009import sys
Daniel Veillard36ed5292002-01-30 23:49:06 +000010import string
Daniel Veillard1971ee22002-01-31 20:29:19 +000011
12#######################################################################
13#
14# That part if purely the API acquisition phase from the
15# XML API description
16#
17#######################################################################
18import os
Daniel Veillardd2897fd2002-01-30 16:37:32 +000019import xmllib
20try:
21 import sgmlop
22except ImportError:
23 sgmlop = None # accelerator not available
24
25debug = 0
26
27if sgmlop:
28 class FastParser:
Daniel Veillard01a6d412002-02-11 18:42:20 +000029 """sgmlop based XML parser. this is typically 15x faster
30 than SlowParser..."""
Daniel Veillardd2897fd2002-01-30 16:37:32 +000031
Daniel Veillard01a6d412002-02-11 18:42:20 +000032 def __init__(self, target):
Daniel Veillardd2897fd2002-01-30 16:37:32 +000033
Daniel Veillard01a6d412002-02-11 18:42:20 +000034 # setup callbacks
35 self.finish_starttag = target.start
36 self.finish_endtag = target.end
37 self.handle_data = target.data
Daniel Veillardd2897fd2002-01-30 16:37:32 +000038
Daniel Veillard01a6d412002-02-11 18:42:20 +000039 # activate parser
40 self.parser = sgmlop.XMLParser()
41 self.parser.register(self)
42 self.feed = self.parser.feed
43 self.entity = {
44 "amp": "&", "gt": ">", "lt": "<",
45 "apos": "'", "quot": '"'
46 }
Daniel Veillardd2897fd2002-01-30 16:37:32 +000047
Daniel Veillard01a6d412002-02-11 18:42:20 +000048 def close(self):
49 try:
50 self.parser.close()
51 finally:
52 self.parser = self.feed = None # nuke circular reference
Daniel Veillardd2897fd2002-01-30 16:37:32 +000053
Daniel Veillard01a6d412002-02-11 18:42:20 +000054 def handle_entityref(self, entity):
55 # <string> entity
56 try:
57 self.handle_data(self.entity[entity])
58 except KeyError:
59 self.handle_data("&%s;" % entity)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000060
61else:
62 FastParser = None
63
64
65class SlowParser(xmllib.XMLParser):
66 """slow but safe standard parser, based on the XML parser in
67 Python's standard library."""
68
69 def __init__(self, target):
Daniel Veillard01a6d412002-02-11 18:42:20 +000070 self.unknown_starttag = target.start
71 self.handle_data = target.data
72 self.unknown_endtag = target.end
73 xmllib.XMLParser.__init__(self)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000074
75def getparser(target = None):
76 # get the fastest available parser, and attach it to an
77 # unmarshalling object. return both objects.
Daniel Veillard6f46f6c2002-08-01 12:22:24 +000078 if target is None:
Daniel Veillard01a6d412002-02-11 18:42:20 +000079 target = docParser()
Daniel Veillardd2897fd2002-01-30 16:37:32 +000080 if FastParser:
Daniel Veillard01a6d412002-02-11 18:42:20 +000081 return FastParser(target), target
Daniel Veillardd2897fd2002-01-30 16:37:32 +000082 return SlowParser(target), target
83
84class docParser:
85 def __init__(self):
86 self._methodname = None
Daniel Veillard01a6d412002-02-11 18:42:20 +000087 self._data = []
88 self.in_function = 0
Daniel Veillardd2897fd2002-01-30 16:37:32 +000089
90 def close(self):
91 if debug:
Daniel Veillard01a6d412002-02-11 18:42:20 +000092 print "close"
Daniel Veillardd2897fd2002-01-30 16:37:32 +000093
94 def getmethodname(self):
95 return self._methodname
96
97 def data(self, text):
98 if debug:
Daniel Veillard01a6d412002-02-11 18:42:20 +000099 print "data %s" % text
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000100 self._data.append(text)
101
102 def start(self, tag, attrs):
103 if debug:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000104 print "start %s, %s" % (tag, attrs)
105 if tag == 'function':
106 self._data = []
107 self.in_function = 1
108 self.function = None
109 self.function_args = []
110 self.function_descr = None
111 self.function_return = None
112 self.function_file = None
113 if attrs.has_key('name'):
114 self.function = attrs['name']
115 if attrs.has_key('file'):
116 self.function_file = attrs['file']
117 elif tag == 'info':
118 self._data = []
119 elif tag == 'arg':
120 if self.in_function == 1:
121 self.function_arg_name = None
122 self.function_arg_type = None
123 self.function_arg_info = None
124 if attrs.has_key('name'):
125 self.function_arg_name = attrs['name']
126 if attrs.has_key('type'):
127 self.function_arg_type = attrs['type']
128 if attrs.has_key('info'):
129 self.function_arg_info = attrs['info']
130 elif tag == 'return':
131 if self.in_function == 1:
132 self.function_return_type = None
133 self.function_return_info = None
134 self.function_return_field = None
135 if attrs.has_key('type'):
136 self.function_return_type = attrs['type']
137 if attrs.has_key('info'):
138 self.function_return_info = attrs['info']
139 if attrs.has_key('field'):
140 self.function_return_field = attrs['field']
Daniel Veillard4f4a27f2004-01-14 23:50:34 +0000141 elif tag == 'enum':
142 enum(attrs['type'],attrs['name'],attrs['value'])
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000143
144 def end(self, tag):
145 if debug:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000146 print "end %s" % tag
147 if tag == 'function':
148 if self.function != None:
149 function(self.function, self.function_descr,
150 self.function_return, self.function_args,
151 self.function_file)
152 self.in_function = 0
153 elif tag == 'arg':
154 if self.in_function == 1:
155 self.function_args.append([self.function_arg_name,
156 self.function_arg_type,
157 self.function_arg_info])
158 elif tag == 'return':
159 if self.in_function == 1:
160 self.function_return = [self.function_return_type,
161 self.function_return_info,
162 self.function_return_field]
163 elif tag == 'info':
164 str = ''
165 for c in self._data:
166 str = str + c
167 if self.in_function == 1:
168 self.function_descr = str
169
170
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000171def function(name, desc, ret, args, file):
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000172 functions[name] = (desc, ret, args, file)
173
Daniel Veillard4f4a27f2004-01-14 23:50:34 +0000174def enum(type, name, value):
175 if not enums.has_key(type):
176 enums[type] = {}
177 enums[type][name] = value
178
Daniel Veillard1971ee22002-01-31 20:29:19 +0000179#######################################################################
180#
181# Some filtering rukes to drop functions/types which should not
182# be exposed as-is on the Python interface
183#
184#######################################################################
Daniel Veillard36ed5292002-01-30 23:49:06 +0000185
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000186skipped_modules = {
187 'xmlmemory': None,
Daniel Veillard96fe0952002-01-30 20:52:23 +0000188 'DOCBparser': None,
189 'SAX': None,
190 'hash': None,
191 'list': None,
192 'threads': None,
Daniel Veillardff12c492003-01-23 16:42:55 +0000193# 'xpointer': None,
Daniel Veillard96fe0952002-01-30 20:52:23 +0000194}
195skipped_types = {
196 'int *': "usually a return type",
197 'xmlSAXHandlerPtr': "not the proper interface for SAX",
198 'htmlSAXHandlerPtr': "not the proper interface for SAX",
Daniel Veillard96fe0952002-01-30 20:52:23 +0000199 'xmlRMutexPtr': "thread specific, skipped",
200 'xmlMutexPtr': "thread specific, skipped",
201 'xmlGlobalStatePtr': "thread specific, skipped",
202 'xmlListPtr': "internal representation not suitable for python",
203 'xmlBufferPtr': "internal representation not suitable for python",
204 'FILE *': None,
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000205}
Daniel Veillard1971ee22002-01-31 20:29:19 +0000206
207#######################################################################
208#
209# Table of remapping to/from the python type or class to the C
210# counterpart.
211#
212#######################################################################
213
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000214py_types = {
Daniel Veillard96fe0952002-01-30 20:52:23 +0000215 'void': (None, None, None, None),
216 'int': ('i', None, "int", "int"),
217 'long': ('i', None, "int", "int"),
218 'double': ('d', None, "double", "double"),
219 'unsigned int': ('i', None, "int", "int"),
220 'xmlChar': ('c', None, "int", "int"),
Daniel Veillard253aa2c2002-02-02 09:17:16 +0000221 'unsigned char *': ('z', None, "charPtr", "char *"),
222 'char *': ('z', None, "charPtr", "char *"),
Daniel Veillardc575b992002-02-08 13:28:40 +0000223 'const char *': ('z', None, "charPtrConst", "const char *"),
Daniel Veillard253aa2c2002-02-02 09:17:16 +0000224 'xmlChar *': ('z', None, "xmlCharPtr", "xmlChar *"),
Daniel Veillardc575b992002-02-08 13:28:40 +0000225 'const xmlChar *': ('z', None, "xmlCharPtrConst", "const xmlChar *"),
Daniel Veillard96fe0952002-01-30 20:52:23 +0000226 'xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
227 'const xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
228 'xmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
229 'const xmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
230 'xmlDtdPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
231 'const xmlDtdPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
232 'xmlDtd *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
233 'const xmlDtd *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
234 'xmlAttrPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
235 'const xmlAttrPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
236 'xmlAttr *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
237 'const xmlAttr *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
238 'xmlEntityPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
239 'const xmlEntityPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
240 'xmlEntity *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
241 'const xmlEntity *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Daniel Veillard1971ee22002-01-31 20:29:19 +0000242 'xmlElementPtr': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
243 'const xmlElementPtr': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
244 'xmlElement *': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
245 'const xmlElement *': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
246 'xmlAttributePtr': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
247 'const xmlAttributePtr': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
248 'xmlAttribute *': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
249 'const xmlAttribute *': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
250 'xmlNsPtr': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
251 'const xmlNsPtr': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
252 'xmlNs *': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
253 'const xmlNs *': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
Daniel Veillard96fe0952002-01-30 20:52:23 +0000254 'xmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
255 'const xmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
256 'xmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
257 'const xmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
258 'htmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
259 'const htmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
260 'htmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
261 'const htmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
262 'htmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
263 'const htmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
264 'htmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
265 'const htmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Daniel Veillard1971ee22002-01-31 20:29:19 +0000266 'xmlXPathContextPtr': ('O', "xmlXPathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"),
267 'xmlXPathContext *': ('O', "xpathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"),
Daniel Veillard7db38712002-02-07 16:39:11 +0000268 'xmlXPathParserContextPtr': ('O', "xmlXPathParserContext", "xmlXPathParserContextPtr", "xmlXPathParserContextPtr"),
Daniel Veillard3ce52572002-02-03 15:08:05 +0000269 'xmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
270 'xmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
271 'htmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
272 'htmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
Daniel Veillard7db38712002-02-07 16:39:11 +0000273 'xmlCatalogPtr': ('O', "catalog", "xmlCatalogPtr", "xmlCatalogPtr"),
274 'FILE *': ('O', "File", "FILEPtr", "FILE *"),
Daniel Veillard6361da02002-02-23 10:10:33 +0000275 'xmlURIPtr': ('O', "URI", "xmlURIPtr", "xmlURIPtr"),
Daniel Veillard46da4642004-01-06 22:54:57 +0000276 'xmlErrorPtr': ('O', "Error", "xmlErrorPtr", "xmlErrorPtr"),
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000277 'xmlOutputBufferPtr': ('O', "outputBuffer", "xmlOutputBufferPtr", "xmlOutputBufferPtr"),
278 'xmlParserInputBufferPtr': ('O', "inputBuffer", "xmlParserInputBufferPtr", "xmlParserInputBufferPtr"),
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000279 'xmlRegexpPtr': ('O', "xmlReg", "xmlRegexpPtr", "xmlRegexpPtr"),
Daniel Veillard417be3a2003-01-20 21:26:34 +0000280 'xmlTextReaderLocatorPtr': ('O', "xmlTextReaderLocator", "xmlTextReaderLocatorPtr", "xmlTextReaderLocatorPtr"),
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000281 'xmlTextReaderPtr': ('O', "xmlTextReader", "xmlTextReaderPtr", "xmlTextReaderPtr"),
Daniel Veillard591b4be2003-02-09 23:33:36 +0000282 'xmlRelaxNGPtr': ('O', "relaxNgSchema", "xmlRelaxNGPtr", "xmlRelaxNGPtr"),
283 'xmlRelaxNGParserCtxtPtr': ('O', "relaxNgParserCtxt", "xmlRelaxNGParserCtxtPtr", "xmlRelaxNGParserCtxtPtr"),
284 'xmlRelaxNGValidCtxtPtr': ('O', "relaxNgValidCtxt", "xmlRelaxNGValidCtxtPtr", "xmlRelaxNGValidCtxtPtr"),
Daniel Veillard259f0df2004-08-18 09:13:18 +0000285 'xmlSchemaPtr': ('O', "Schema", "xmlSchemaPtr", "xmlSchemaPtr"),
286 'xmlSchemaParserCtxtPtr': ('O', "SchemaParserCtxt", "xmlSchemaParserCtxtPtr", "xmlSchemaParserCtxtPtr"),
287 'xmlSchemaValidCtxtPtr': ('O', "SchemaValidCtxt", "xmlSchemaValidCtxtPtr", "xmlSchemaValidCtxtPtr"),
Daniel Veillard1971ee22002-01-31 20:29:19 +0000288}
289
290py_return_types = {
291 'xmlXPathObjectPtr': ('O', "foo", "xmlXPathObjectPtr", "xmlXPathObjectPtr"),
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000292}
293
294unknown_types = {}
295
Daniel Veillard1971ee22002-01-31 20:29:19 +0000296#######################################################################
297#
298# This part writes the C <-> Python stubs libxml2-py.[ch] and
299# the table libxml2-export.c to add when registrering the Python module
300#
301#######################################################################
302
303def skip_function(name):
304 if name[0:12] == "xmlXPathWrap":
305 return 1
Daniel Veillarde6227e02003-01-14 11:42:39 +0000306 if name == "xmlFreeParserCtxt":
307 return 1
Daniel Veillardf93a8662004-07-01 12:56:30 +0000308 if name == "xmlCleanupParser":
309 return 1
Daniel Veillard26f70262003-01-16 22:45:08 +0000310 if name == "xmlFreeTextReader":
311 return 1
Daniel Veillard1971ee22002-01-31 20:29:19 +0000312# if name[0:11] == "xmlXPathNew":
313# return 1
Daniel Veillardc2664642003-07-29 20:44:53 +0000314 # the next function is defined in libxml.c
315 if name == "xmlRelaxNGFreeValidCtxt":
316 return 1
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000317#
318# Those are skipped because the Const version is used of the bindings
319# instead.
320#
321 if name == "xmlTextReaderBaseUri":
322 return 1
323 if name == "xmlTextReaderLocalName":
324 return 1
325 if name == "xmlTextReaderName":
326 return 1
327 if name == "xmlTextReaderNamespaceUri":
328 return 1
329 if name == "xmlTextReaderPrefix":
330 return 1
331 if name == "xmlTextReaderXmlLang":
332 return 1
333 if name == "xmlTextReaderValue":
334 return 1
Daniel Veillard6cbd6c02003-12-04 12:31:49 +0000335 if name == "xmlOutputBufferClose": # handled by by the superclass
336 return 1
337 if name == "xmlOutputBufferFlush": # handled by by the superclass
338 return 1
William M. Brackf7eb7942003-12-31 07:59:17 +0000339 if name == "xmlErrMemory":
340 return 1
Daniel Veillard1971ee22002-01-31 20:29:19 +0000341 return 0
342
Daniel Veillard96fe0952002-01-30 20:52:23 +0000343def print_function_wrapper(name, output, export, include):
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000344 global py_types
345 global unknown_types
346 global functions
347 global skipped_modules
348
349 try:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000350 (desc, ret, args, file) = functions[name]
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000351 except:
352 print "failed to get function %s infos"
353 return
354
355 if skipped_modules.has_key(file):
356 return 0
Daniel Veillard1971ee22002-01-31 20:29:19 +0000357 if skip_function(name) == 1:
358 return 0
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000359
360 c_call = "";
361 format=""
362 format_args=""
363 c_args=""
364 c_return=""
Daniel Veillard96fe0952002-01-30 20:52:23 +0000365 c_convert=""
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000366 for arg in args:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000367 # This should be correct
368 if arg[1][0:6] == "const ":
369 arg[1] = arg[1][6:]
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000370 c_args = c_args + " %s %s;\n" % (arg[1], arg[0])
Daniel Veillard01a6d412002-02-11 18:42:20 +0000371 if py_types.has_key(arg[1]):
372 (f, t, n, c) = py_types[arg[1]]
373 if f != None:
374 format = format + f
375 if t != None:
376 format_args = format_args + ", &pyobj_%s" % (arg[0])
377 c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
378 c_convert = c_convert + \
379 " %s = (%s) Py%s_Get(pyobj_%s);\n" % (arg[0],
380 arg[1], t, arg[0]);
381 else:
382 format_args = format_args + ", &%s" % (arg[0])
383 if c_call != "":
384 c_call = c_call + ", ";
385 c_call = c_call + "%s" % (arg[0])
386 else:
387 if skipped_types.has_key(arg[1]):
388 return 0
389 if unknown_types.has_key(arg[1]):
390 lst = unknown_types[arg[1]]
391 lst.append(name)
392 else:
393 unknown_types[arg[1]] = [name]
394 return -1
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000395 if format != "":
396 format = format + ":%s" % (name)
397
398 if ret[0] == 'void':
Daniel Veillard01a6d412002-02-11 18:42:20 +0000399 if file == "python_accessor":
Daniel Veillard6361da02002-02-23 10:10:33 +0000400 if args[1][1] == "char *" or args[1][1] == "xmlChar *":
401 c_call = "\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % (
402 args[0][0], args[1][0], args[0][0], args[1][0])
William M. Bracka71a8ef2003-08-06 04:43:55 +0000403 c_call = c_call + " %s->%s = (%s)xmlStrdup((const xmlChar *)%s);\n" % (args[0][0],
404 args[1][0], args[1][1], args[1][0])
Daniel Veillard6361da02002-02-23 10:10:33 +0000405 else:
406 c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
407 args[1][0])
Daniel Veillard01a6d412002-02-11 18:42:20 +0000408 else:
409 c_call = "\n %s(%s);\n" % (name, c_call);
410 ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n"
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000411 elif py_types.has_key(ret[0]):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000412 (f, t, n, c) = py_types[ret[0]]
413 c_return = " %s c_retval;\n" % (ret[0])
414 if file == "python_accessor" and ret[2] != None:
415 c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
416 else:
417 c_call = "\n c_retval = %s(%s);\n" % (name, c_call);
418 ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
419 ret_convert = ret_convert + " return(py_retval);\n"
Daniel Veillard1971ee22002-01-31 20:29:19 +0000420 elif py_return_types.has_key(ret[0]):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000421 (f, t, n, c) = py_return_types[ret[0]]
422 c_return = " %s c_retval;\n" % (ret[0])
Daniel Veillard1971ee22002-01-31 20:29:19 +0000423 c_call = "\n c_retval = %s(%s);\n" % (name, c_call);
Daniel Veillard01a6d412002-02-11 18:42:20 +0000424 ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
425 ret_convert = ret_convert + " return(py_retval);\n"
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000426 else:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000427 if skipped_types.has_key(ret[0]):
428 return 0
429 if unknown_types.has_key(ret[0]):
430 lst = unknown_types[ret[0]]
431 lst.append(name)
432 else:
433 unknown_types[ret[0]] = [name]
434 return -1
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000435
Daniel Veillard42766c02002-08-22 20:52:17 +0000436 if file == "debugXML":
437 include.write("#ifdef LIBXML_DEBUG_ENABLED\n");
438 export.write("#ifdef LIBXML_DEBUG_ENABLED\n");
439 output.write("#ifdef LIBXML_DEBUG_ENABLED\n");
Daniel Veillard656ce942004-04-30 23:11:45 +0000440 elif file == "HTMLtree" or file == "HTMLparser" or name[0:4] == "html":
Daniel Veillard42766c02002-08-22 20:52:17 +0000441 include.write("#ifdef LIBXML_HTML_ENABLED\n");
442 export.write("#ifdef LIBXML_HTML_ENABLED\n");
443 output.write("#ifdef LIBXML_HTML_ENABLED\n");
444 elif file == "c14n":
445 include.write("#ifdef LIBXML_C14N_ENABLED\n");
446 export.write("#ifdef LIBXML_C14N_ENABLED\n");
447 output.write("#ifdef LIBXML_C14N_ENABLED\n");
448 elif file == "xpathInternals" or file == "xpath":
449 include.write("#ifdef LIBXML_XPATH_ENABLED\n");
450 export.write("#ifdef LIBXML_XPATH_ENABLED\n");
451 output.write("#ifdef LIBXML_XPATH_ENABLED\n");
452 elif file == "xpointer":
453 include.write("#ifdef LIBXML_XPTR_ENABLED\n");
454 export.write("#ifdef LIBXML_XPTR_ENABLED\n");
455 output.write("#ifdef LIBXML_XPTR_ENABLED\n");
456 elif file == "xinclude":
457 include.write("#ifdef LIBXML_XINCLUDE_ENABLED\n");
458 export.write("#ifdef LIBXML_XINCLUDE_ENABLED\n");
459 output.write("#ifdef LIBXML_XINCLUDE_ENABLED\n");
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000460 elif file == "xmlregexp":
461 include.write("#ifdef LIBXML_REGEXP_ENABLED\n");
462 export.write("#ifdef LIBXML_REGEXP_ENABLED\n");
463 output.write("#ifdef LIBXML_REGEXP_ENABLED\n");
Daniel Veillard71531f32003-02-05 13:19:53 +0000464 elif file == "xmlschemas" or file == "xmlschemastypes" or \
465 file == "relaxng":
466 include.write("#ifdef LIBXML_SCHEMAS_ENABLED\n");
467 export.write("#ifdef LIBXML_SCHEMAS_ENABLED\n");
468 output.write("#ifdef LIBXML_SCHEMAS_ENABLED\n");
Daniel Veillard42766c02002-08-22 20:52:17 +0000469
Daniel Veillard96fe0952002-01-30 20:52:23 +0000470 include.write("PyObject * ")
Daniel Veillardd2379012002-03-15 22:24:56 +0000471 include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name));
Daniel Veillard9589d452002-02-02 10:28:17 +0000472
Daniel Veillardd2379012002-03-15 22:24:56 +0000473 export.write(" { (char *)\"%s\", libxml_%s, METH_VARARGS, NULL },\n" %
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000474 (name, name))
Daniel Veillard9589d452002-02-02 10:28:17 +0000475
476 if file == "python":
477 # Those have been manually generated
Daniel Veillard656ce942004-04-30 23:11:45 +0000478 if name[0:4] == "html":
479 include.write("#endif /* LIBXML_HTML_ENABLED */\n");
480 export.write("#endif /* LIBXML_HTML_ENABLED */\n");
481 output.write("#endif /* LIBXML_HTML_ENABLED */\n");
Daniel Veillard01a6d412002-02-11 18:42:20 +0000482 return 1
Daniel Veillard6f46f6c2002-08-01 12:22:24 +0000483 if file == "python_accessor" and ret[0] != "void" and ret[2] is None:
Daniel Veillard36eea2d2002-02-04 00:17:01 +0000484 # Those have been manually generated
Daniel Veillard656ce942004-04-30 23:11:45 +0000485 if name[0:4] == "html":
486 include.write("#endif /* LIBXML_HTML_ENABLED */\n");
487 export.write("#endif /* LIBXML_HTML_ENABLED */\n");
488 output.write("#endif /* LIBXML_HTML_ENABLED */\n");
Daniel Veillard01a6d412002-02-11 18:42:20 +0000489 return 1
Daniel Veillard9589d452002-02-02 10:28:17 +0000490
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000491 output.write("PyObject *\n")
William M. Brack6bf4d6f2003-11-04 23:29:16 +0000492 output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
493 output.write(" PyObject *args")
Daniel Veillardd2379012002-03-15 22:24:56 +0000494 if format == "":
William M. Brack6bf4d6f2003-11-04 23:29:16 +0000495 output.write(" ATTRIBUTE_UNUSED")
496 output.write(") {\n")
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000497 if ret[0] != 'void':
Daniel Veillard01a6d412002-02-11 18:42:20 +0000498 output.write(" PyObject *py_retval;\n")
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000499 if c_return != "":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000500 output.write(c_return)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000501 if c_args != "":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000502 output.write(c_args)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000503 if format != "":
Daniel Veillardd2379012002-03-15 22:24:56 +0000504 output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
Daniel Veillard01a6d412002-02-11 18:42:20 +0000505 (format, format_args))
506 output.write(" return(NULL);\n")
Daniel Veillard96fe0952002-01-30 20:52:23 +0000507 if c_convert != "":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000508 output.write(c_convert)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000509
510 output.write(c_call)
511 output.write(ret_convert)
512 output.write("}\n\n")
Daniel Veillard42766c02002-08-22 20:52:17 +0000513 if file == "debugXML":
514 include.write("#endif /* LIBXML_DEBUG_ENABLED */\n");
515 export.write("#endif /* LIBXML_DEBUG_ENABLED */\n");
516 output.write("#endif /* LIBXML_DEBUG_ENABLED */\n");
Daniel Veillard656ce942004-04-30 23:11:45 +0000517 elif file == "HTMLtree" or file == "HTMLparser" or name[0:4] == "html":
Daniel Veillard42766c02002-08-22 20:52:17 +0000518 include.write("#endif /* LIBXML_HTML_ENABLED */\n");
519 export.write("#endif /* LIBXML_HTML_ENABLED */\n");
520 output.write("#endif /* LIBXML_HTML_ENABLED */\n");
521 elif file == "c14n":
522 include.write("#endif /* LIBXML_C14N_ENABLED */\n");
523 export.write("#endif /* LIBXML_C14N_ENABLED */\n");
524 output.write("#endif /* LIBXML_C14N_ENABLED */\n");
525 elif file == "xpathInternals" or file == "xpath":
526 include.write("#endif /* LIBXML_XPATH_ENABLED */\n");
527 export.write("#endif /* LIBXML_XPATH_ENABLED */\n");
528 output.write("#endif /* LIBXML_XPATH_ENABLED */\n");
529 elif file == "xpointer":
530 include.write("#endif /* LIBXML_XPTR_ENABLED */\n");
531 export.write("#endif /* LIBXML_XPTR_ENABLED */\n");
532 output.write("#endif /* LIBXML_XPTR_ENABLED */\n");
533 elif file == "xinclude":
534 include.write("#endif /* LIBXML_XINCLUDE_ENABLED */\n");
535 export.write("#endif /* LIBXML_XINCLUDE_ENABLED */\n");
536 output.write("#endif /* LIBXML_XINCLUDE_ENABLED */\n");
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000537 elif file == "xmlregexp":
538 include.write("#endif /* LIBXML_REGEXP_ENABLED */\n");
539 export.write("#endif /* LIBXML_REGEXP_ENABLED */\n");
540 output.write("#endif /* LIBXML_REGEXP_ENABLED */\n");
Daniel Veillard71531f32003-02-05 13:19:53 +0000541 elif file == "xmlschemas" or file == "xmlschemastypes" or \
542 file == "relaxng":
543 include.write("#endif /* LIBXML_SCHEMAS_ENABLED */\n");
544 export.write("#endif /* LIBXML_SCHEMAS_ENABLED */\n");
545 output.write("#endif /* LIBXML_SCHEMAS_ENABLED */\n");
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000546 return 1
547
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000548def buildStubs():
549 global py_types
550 global py_return_types
551 global unknown_types
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000552
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000553 try:
554 f = open("libxml2-api.xml")
555 data = f.read()
556 (parser, target) = getparser()
557 parser.feed(data)
558 parser.close()
559 except IOError, msg:
560 try:
561 f = open("../doc/libxml2-api.xml")
562 data = f.read()
563 (parser, target) = getparser()
564 parser.feed(data)
565 parser.close()
566 except IOError, msg:
567 print file, ":", msg
568 sys.exit(1)
Daniel Veillard9589d452002-02-02 10:28:17 +0000569
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000570 n = len(functions.keys())
571 print "Found %d functions in libxml2-api.xml" % (n)
572
573 py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject")
574 try:
575 f = open("libxml2-python-api.xml")
576 data = f.read()
577 (parser, target) = getparser()
578 parser.feed(data)
579 parser.close()
580 except IOError, msg:
581 print file, ":", msg
Daniel Veillard9589d452002-02-02 10:28:17 +0000582
583
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000584 print "Found %d functions in libxml2-python-api.xml" % (
585 len(functions.keys()) - n)
586 nb_wrap = 0
587 failed = 0
588 skipped = 0
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000589
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000590 include = open("libxml2-py.h", "w")
591 include.write("/* Generated */\n\n")
592 export = open("libxml2-export.c", "w")
593 export.write("/* Generated */\n\n")
594 wrapper = open("libxml2-py.c", "w")
595 wrapper.write("/* Generated */\n\n")
596 wrapper.write("#include <Python.h>\n")
Daniel Veillardd2379012002-03-15 22:24:56 +0000597 wrapper.write("#include <libxml/xmlversion.h>\n")
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000598 wrapper.write("#include <libxml/tree.h>\n")
William M. Bracka71a8ef2003-08-06 04:43:55 +0000599 wrapper.write("#include <libxml/xmlschemastypes.h>\n")
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000600 wrapper.write("#include \"libxml_wrap.h\"\n")
601 wrapper.write("#include \"libxml2-py.h\"\n\n")
602 for function in functions.keys():
603 ret = print_function_wrapper(function, wrapper, export, include)
604 if ret < 0:
605 failed = failed + 1
606 del functions[function]
607 if ret == 0:
608 skipped = skipped + 1
609 del functions[function]
610 if ret == 1:
611 nb_wrap = nb_wrap + 1
612 include.close()
613 export.close()
614 wrapper.close()
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000615
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000616 print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
617 failed, skipped);
618 print "Missing type converters: "
619 for type in unknown_types.keys():
620 print "%s:%d " % (type, len(unknown_types[type])),
621 print
Daniel Veillard36ed5292002-01-30 23:49:06 +0000622
Daniel Veillard1971ee22002-01-31 20:29:19 +0000623#######################################################################
624#
625# This part writes part of the Python front-end classes based on
626# mapping rules between types and classes and also based on function
627# renaming to get consistent function names at the Python level
628#
629#######################################################################
630
631#
632# The type automatically remapped to generated classes
633#
634classes_type = {
635 "xmlNodePtr": ("._o", "xmlNode(_obj=%s)", "xmlNode"),
636 "xmlNode *": ("._o", "xmlNode(_obj=%s)", "xmlNode"),
637 "xmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
638 "xmlDocPtr *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
639 "htmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
640 "htmlxmlDocPtr *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
641 "xmlAttrPtr": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"),
642 "xmlAttr *": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"),
643 "xmlNsPtr": ("._o", "xmlNs(_obj=%s)", "xmlNs"),
644 "xmlNs *": ("._o", "xmlNs(_obj=%s)", "xmlNs"),
645 "xmlDtdPtr": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"),
646 "xmlDtd *": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"),
647 "xmlEntityPtr": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"),
648 "xmlEntity *": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"),
649 "xmlElementPtr": ("._o", "xmlElement(_obj=%s)", "xmlElement"),
650 "xmlElement *": ("._o", "xmlElement(_obj=%s)", "xmlElement"),
651 "xmlAttributePtr": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"),
652 "xmlAttribute *": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"),
653 "xmlXPathContextPtr": ("._o", "xpathContext(_obj=%s)", "xpathContext"),
Daniel Veillard7db38712002-02-07 16:39:11 +0000654 "xmlXPathContext *": ("._o", "xpathContext(_obj=%s)", "xpathContext"),
655 "xmlXPathParserContext *": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"),
656 "xmlXPathParserContextPtr": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"),
Daniel Veillard3ce52572002-02-03 15:08:05 +0000657 "xmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
658 "xmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Daniel Veillard3cd72402002-05-13 10:33:30 +0000659 "htmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
660 "htmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Daniel Veillard7db38712002-02-07 16:39:11 +0000661 "xmlCatalogPtr": ("._o", "catalog(_obj=%s)", "catalog"),
Daniel Veillard6361da02002-02-23 10:10:33 +0000662 "xmlURIPtr": ("._o", "URI(_obj=%s)", "URI"),
Daniel Veillard46da4642004-01-06 22:54:57 +0000663 "xmlErrorPtr": ("._o", "Error(_obj=%s)", "Error"),
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000664 "xmlOutputBufferPtr": ("._o", "outputBuffer(_obj=%s)", "outputBuffer"),
665 "xmlParserInputBufferPtr": ("._o", "inputBuffer(_obj=%s)", "inputBuffer"),
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000666 "xmlRegexpPtr": ("._o", "xmlReg(_obj=%s)", "xmlReg"),
Daniel Veillard417be3a2003-01-20 21:26:34 +0000667 "xmlTextReaderLocatorPtr": ("._o", "xmlTextReaderLocator(_obj=%s)", "xmlTextReaderLocator"),
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000668 "xmlTextReaderPtr": ("._o", "xmlTextReader(_obj=%s)", "xmlTextReader"),
Daniel Veillard591b4be2003-02-09 23:33:36 +0000669 'xmlRelaxNGPtr': ('._o', "relaxNgSchema(_obj=%s)", "relaxNgSchema"),
670 'xmlRelaxNGParserCtxtPtr': ('._o', "relaxNgParserCtxt(_obj=%s)", "relaxNgParserCtxt"),
671 'xmlRelaxNGValidCtxtPtr': ('._o', "relaxNgValidCtxt(_obj=%s)", "relaxNgValidCtxt"),
Daniel Veillard259f0df2004-08-18 09:13:18 +0000672 'xmlSchemaPtr': ("._o", "Schema(_obj=%s)", "Schema"),
673 'xmlSchemaParserCtxtPtr': ("._o", "SchemaParserCtxt(_obj=%s)", "SchemaParserCtxt"),
674 'xmlSchemaValidCtxtPtr': ("._o", "SchemaValidCtxt(_obj=%s)", "SchemaValidCtxt"),
Daniel Veillard1971ee22002-01-31 20:29:19 +0000675}
676
677converter_type = {
678 "xmlXPathObjectPtr": "xpathObjectRet(%s)",
679}
680
681primary_classes = ["xmlNode", "xmlDoc"]
682
683classes_ancestor = {
684 "xmlNode" : "xmlCore",
Daniel Veillard253aa2c2002-02-02 09:17:16 +0000685 "xmlDtd" : "xmlNode",
686 "xmlDoc" : "xmlNode",
687 "xmlAttr" : "xmlNode",
688 "xmlNs" : "xmlNode",
689 "xmlEntity" : "xmlNode",
690 "xmlElement" : "xmlNode",
691 "xmlAttribute" : "xmlNode",
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000692 "outputBuffer": "ioWriteWrapper",
693 "inputBuffer": "ioReadWrapper",
Daniel Veillarde6227e02003-01-14 11:42:39 +0000694 "parserCtxt": "parserCtxtCore",
Daniel Veillard26f70262003-01-16 22:45:08 +0000695 "xmlTextReader": "xmlTextReaderCore",
Daniel Veillard1971ee22002-01-31 20:29:19 +0000696}
697classes_destructors = {
Daniel Veillard3ce52572002-02-03 15:08:05 +0000698 "parserCtxt": "xmlFreeParserCtxt",
Daniel Veillard7db38712002-02-07 16:39:11 +0000699 "catalog": "xmlFreeCatalog",
Daniel Veillard6361da02002-02-23 10:10:33 +0000700 "URI": "xmlFreeURI",
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000701# "outputBuffer": "xmlOutputBufferClose",
702 "inputBuffer": "xmlFreeParserInputBuffer",
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000703 "xmlReg": "xmlRegFreeRegexp",
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000704 "xmlTextReader": "xmlFreeTextReader",
Daniel Veillard591b4be2003-02-09 23:33:36 +0000705 "relaxNgSchema": "xmlRelaxNGFree",
706 "relaxNgParserCtxt": "xmlRelaxNGFreeParserCtxt",
707 "relaxNgValidCtxt": "xmlRelaxNGFreeValidCtxt",
Daniel Veillard259f0df2004-08-18 09:13:18 +0000708 "Schema": "xmlSchemaFree",
709 "SchemaParserCtxt": "xmlSchemaFreeParserCtxt",
710 "SchemaValidCtxt": "xmlSchemaFreeValidCtxt",
Daniel Veillard1971ee22002-01-31 20:29:19 +0000711}
712
Daniel Veillardef6c46f2002-03-07 22:21:56 +0000713functions_noexcept = {
714 "xmlHasProp": 1,
715 "xmlHasNsProp": 1,
Daniel Veillard3b87b6b2003-01-10 15:21:50 +0000716 "xmlDocSetRootElement": 1,
Daniel Veillardef6c46f2002-03-07 22:21:56 +0000717}
718
Daniel Veillarddc85f282002-12-31 11:18:37 +0000719reference_keepers = {
720 "xmlTextReader": [('inputBuffer', 'input')],
Daniel Veillard591b4be2003-02-09 23:33:36 +0000721 "relaxNgValidCtxt": [('relaxNgSchema', 'schema')],
Daniel Veillard259f0df2004-08-18 09:13:18 +0000722 "SchemaValidCtxt": [('Schema', 'schema')],
Daniel Veillarddc85f282002-12-31 11:18:37 +0000723}
724
Daniel Veillard36ed5292002-01-30 23:49:06 +0000725function_classes = {}
Daniel Veillard1971ee22002-01-31 20:29:19 +0000726
727function_classes["None"] = []
Daniel Veillard1971ee22002-01-31 20:29:19 +0000728
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000729def nameFixup(name, classe, type, file):
Daniel Veillard1971ee22002-01-31 20:29:19 +0000730 listname = classe + "List"
731 ll = len(listname)
732 l = len(classe)
733 if name[0:l] == listname:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000734 func = name[l:]
735 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard3ce52572002-02-03 15:08:05 +0000736 elif name[0:12] == "xmlParserGet" and file == "python_accessor":
737 func = name[12:]
738 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard26f1dcc2002-02-03 16:53:19 +0000739 elif name[0:12] == "xmlParserSet" and file == "python_accessor":
740 func = name[12:]
741 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard36eea2d2002-02-04 00:17:01 +0000742 elif name[0:10] == "xmlNodeGet" and file == "python_accessor":
743 func = name[10:]
744 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard6361da02002-02-23 10:10:33 +0000745 elif name[0:9] == "xmlURIGet" and file == "python_accessor":
746 func = name[9:]
747 func = string.lower(func[0:1]) + func[1:]
748 elif name[0:9] == "xmlURISet" and file == "python_accessor":
749 func = name[6:]
750 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard46da4642004-01-06 22:54:57 +0000751 elif name[0:11] == "xmlErrorGet" and file == "python_accessor":
752 func = name[11:]
753 func = string.lower(func[0:1]) + func[1:]
Daniel Veillardc575b992002-02-08 13:28:40 +0000754 elif name[0:17] == "xmlXPathParserGet" and file == "python_accessor":
755 func = name[17:]
756 func = string.lower(func[0:1]) + func[1:]
757 elif name[0:11] == "xmlXPathGet" and file == "python_accessor":
758 func = name[11:]
759 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000760 elif name[0:11] == "xmlXPathSet" and file == "python_accessor":
761 func = name[8:]
762 func = string.lower(func[0:1]) + func[1:]
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000763 elif name[0:15] == "xmlOutputBuffer" and file != "python":
764 func = name[15:]
765 func = string.lower(func[0:1]) + func[1:]
766 elif name[0:20] == "xmlParserInputBuffer" and file != "python":
767 func = name[20:]
768 func = string.lower(func[0:1]) + func[1:]
Daniel Veillardd4cb1e82002-09-26 09:34:23 +0000769 elif name[0:9] == "xmlRegexp" and file == "xmlregexp":
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000770 func = "regexp" + name[9:]
Daniel Veillardd4cb1e82002-09-26 09:34:23 +0000771 elif name[0:6] == "xmlReg" and file == "xmlregexp":
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000772 func = "regexp" + name[6:]
Daniel Veillard417be3a2003-01-20 21:26:34 +0000773 elif name[0:20] == "xmlTextReaderLocator" and file == "xmlreader":
774 func = name[20:]
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000775 elif name[0:18] == "xmlTextReaderConst" and file == "xmlreader":
776 func = name[18:]
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000777 elif name[0:13] == "xmlTextReader" and file == "xmlreader":
778 func = name[13:]
Daniel Veillard198c1bf2003-10-20 17:07:41 +0000779 elif name[0:12] == "xmlReaderNew" and file == "xmlreader":
780 func = name[9:]
Daniel Veillard7db38712002-02-07 16:39:11 +0000781 elif name[0:11] == "xmlACatalog":
782 func = name[11:]
783 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard1971ee22002-01-31 20:29:19 +0000784 elif name[0:l] == classe:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000785 func = name[l:]
786 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard9589d452002-02-02 10:28:17 +0000787 elif name[0:7] == "libxml_":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000788 func = name[7:]
789 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard1971ee22002-01-31 20:29:19 +0000790 elif name[0:6] == "xmlGet":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000791 func = name[6:]
792 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard1971ee22002-01-31 20:29:19 +0000793 elif name[0:3] == "xml":
Daniel Veillard01a6d412002-02-11 18:42:20 +0000794 func = name[3:]
795 func = string.lower(func[0:1]) + func[1:]
Daniel Veillard36ed5292002-01-30 23:49:06 +0000796 else:
Daniel Veillard1971ee22002-01-31 20:29:19 +0000797 func = name
798 if func[0:5] == "xPath":
799 func = "xpath" + func[5:]
800 elif func[0:4] == "xPtr":
801 func = "xpointer" + func[4:]
802 elif func[0:8] == "xInclude":
803 func = "xinclude" + func[8:]
804 elif func[0:2] == "iD":
805 func = "ID" + func[2:]
806 elif func[0:3] == "uRI":
807 func = "URI" + func[3:]
808 elif func[0:4] == "uTF8":
809 func = "UTF8" + func[4:]
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000810 elif func[0:3] == 'sAX':
811 func = "SAX" + func[3:]
Daniel Veillard1971ee22002-01-31 20:29:19 +0000812 return func
Daniel Veillard36ed5292002-01-30 23:49:06 +0000813
Daniel Veillard36ed5292002-01-30 23:49:06 +0000814
Daniel Veillard1971ee22002-01-31 20:29:19 +0000815def functionCompare(info1, info2):
816 (index1, func1, name1, ret1, args1, file1) = info1
817 (index2, func2, name2, ret2, args2, file2) = info2
Daniel Veillard26f1dcc2002-02-03 16:53:19 +0000818 if file1 == file2:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000819 if func1 < func2:
820 return -1
821 if func1 > func2:
822 return 1
Daniel Veillard3ce52572002-02-03 15:08:05 +0000823 if file1 == "python_accessor":
824 return -1
825 if file2 == "python_accessor":
826 return 1
Daniel Veillard1971ee22002-01-31 20:29:19 +0000827 if file1 < file2:
828 return -1
829 if file1 > file2:
830 return 1
Daniel Veillard1971ee22002-01-31 20:29:19 +0000831 return 0
832
833def writeDoc(name, args, indent, output):
Daniel Veillard6f46f6c2002-08-01 12:22:24 +0000834 if functions[name][0] is None or functions[name][0] == "":
Daniel Veillard1971ee22002-01-31 20:29:19 +0000835 return
836 val = functions[name][0]
837 val = string.replace(val, "NULL", "None");
838 output.write(indent)
839 output.write('"""')
840 while len(val) > 60:
841 str = val[0:60]
Daniel Veillard01a6d412002-02-11 18:42:20 +0000842 i = string.rfind(str, " ");
843 if i < 0:
844 i = 60
Daniel Veillard1971ee22002-01-31 20:29:19 +0000845 str = val[0:i]
Daniel Veillard01a6d412002-02-11 18:42:20 +0000846 val = val[i:]
847 output.write(str)
848 output.write('\n ');
849 output.write(indent)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000850 output.write(val);
Daniel Veillardd076a202002-11-20 13:28:31 +0000851 output.write(' """\n')
Daniel Veillard1971ee22002-01-31 20:29:19 +0000852
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000853def buildWrappers():
854 global ctypes
855 global py_types
856 global py_return_types
857 global unknown_types
858 global functions
859 global function_classes
860 global classes_type
861 global classes_list
862 global converter_type
863 global primary_classes
864 global converter_type
865 global classes_ancestor
866 global converter_type
867 global primary_classes
868 global classes_ancestor
869 global classes_destructors
Daniel Veillardef6c46f2002-03-07 22:21:56 +0000870 global functions_noexcept
Daniel Veillard36eea2d2002-02-04 00:17:01 +0000871
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000872 for type in classes_type.keys():
873 function_classes[classes_type[type][2]] = []
Daniel Veillard36ed5292002-01-30 23:49:06 +0000874
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000875 #
876 # Build the list of C types to look for ordered to start
877 # with primary classes
878 #
879 ctypes = []
880 classes_list = []
881 ctypes_processed = {}
882 classes_processed = {}
883 for classe in primary_classes:
884 classes_list.append(classe)
885 classes_processed[classe] = ()
886 for type in classes_type.keys():
887 tinfo = classes_type[type]
888 if tinfo[2] == classe:
889 ctypes.append(type)
890 ctypes_processed[type] = ()
891 for type in classes_type.keys():
892 if ctypes_processed.has_key(type):
893 continue
894 tinfo = classes_type[type]
895 if not classes_processed.has_key(tinfo[2]):
896 classes_list.append(tinfo[2])
897 classes_processed[tinfo[2]] = ()
898
899 ctypes.append(type)
900 ctypes_processed[type] = ()
Daniel Veillard36ed5292002-01-30 23:49:06 +0000901
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000902 for name in functions.keys():
903 found = 0;
904 (desc, ret, args, file) = functions[name]
905 for type in ctypes:
906 classe = classes_type[type][2]
907
908 if name[0:3] == "xml" and len(args) >= 1 and args[0][1] == type:
909 found = 1
910 func = nameFixup(name, classe, type, file)
911 info = (0, func, name, ret, args, file)
912 function_classes[classe].append(info)
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000913 elif name[0:3] == "xml" and len(args) >= 2 and args[1][1] == type \
914 and file != "python_accessor":
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000915 found = 1
916 func = nameFixup(name, classe, type, file)
917 info = (1, func, name, ret, args, file)
918 function_classes[classe].append(info)
919 elif name[0:4] == "html" and len(args) >= 1 and args[0][1] == type:
920 found = 1
921 func = nameFixup(name, classe, type, file)
922 info = (0, func, name, ret, args, file)
923 function_classes[classe].append(info)
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000924 elif name[0:4] == "html" and len(args) >= 2 and args[1][1] == type \
925 and file != "python_accessor":
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000926 found = 1
927 func = nameFixup(name, classe, type, file)
928 info = (1, func, name, ret, args, file)
929 function_classes[classe].append(info)
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000930 if found == 1:
931 continue
932 if name[0:8] == "xmlXPath":
933 continue
934 if name[0:6] == "xmlStr":
935 continue
936 if name[0:10] == "xmlCharStr":
937 continue
938 func = nameFixup(name, "None", file, file)
939 info = (0, func, name, ret, args, file)
940 function_classes['None'].append(info)
941
942 classes = open("libxml2class.py", "w")
943 txt = open("libxml2class.txt", "w")
944 txt.write(" Generated Classes for libxml2-python\n\n")
945
946 txt.write("#\n# Global functions of the module\n#\n\n")
947 if function_classes.has_key("None"):
948 flist = function_classes["None"]
949 flist.sort(functionCompare)
950 oldfile = ""
951 for info in flist:
952 (index, func, name, ret, args, file) = info
953 if file != oldfile:
954 classes.write("#\n# Functions from module %s\n#\n\n" % file)
955 txt.write("\n# functions from module %s\n" % file)
956 oldfile = file
957 classes.write("def %s(" % func)
958 txt.write("%s()\n" % func);
959 n = 0
960 for arg in args:
961 if n != 0:
962 classes.write(", ")
963 classes.write("%s" % arg[0])
964 n = n + 1
965 classes.write("):\n")
966 writeDoc(name, args, ' ', classes);
967
968 for arg in args:
969 if classes_type.has_key(arg[1]):
Daniel Veillard6f46f6c2002-08-01 12:22:24 +0000970 classes.write(" if %s is None: %s__o = None\n" %
Daniel Veillard0fea6f42002-02-22 22:51:13 +0000971 (arg[0], arg[0]))
972 classes.write(" else: %s__o = %s%s\n" %
973 (arg[0], arg[0], classes_type[arg[1]][0]))
974 if ret[0] != "void":
975 classes.write(" ret = ");
976 else:
977 classes.write(" ");
978 classes.write("libxml2mod.%s(" % name)
979 n = 0
980 for arg in args:
981 if n != 0:
982 classes.write(", ");
983 classes.write("%s" % arg[0])
984 if classes_type.has_key(arg[1]):
985 classes.write("__o");
986 n = n + 1
987 classes.write(")\n");
988 if ret[0] != "void":
989 if classes_type.has_key(ret[0]):
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000990 #
991 # Raise an exception
992 #
Daniel Veillardef6c46f2002-03-07 22:21:56 +0000993 if functions_noexcept.has_key(name):
Daniel Veillard6f46f6c2002-08-01 12:22:24 +0000994 classes.write(" if ret is None:return None\n");
Daniel Veillardef6c46f2002-03-07 22:21:56 +0000995 elif string.find(name, "URI") >= 0:
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000996 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +0000997 " if ret is None:raise uriError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000998 % (name))
999 elif string.find(name, "XPath") >= 0:
1000 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001001 " if ret is None:raise xpathError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001002 % (name))
1003 elif string.find(name, "Parse") >= 0:
1004 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001005 " if ret is None:raise parserError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001006 % (name))
1007 else:
1008 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001009 " if ret is None:raise treeError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001010 % (name))
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001011 classes.write(" return ");
1012 classes.write(classes_type[ret[0]][1] % ("ret"));
1013 classes.write("\n");
1014 else:
1015 classes.write(" return ret\n");
1016 classes.write("\n");
1017
1018 txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
1019 for classname in classes_list:
1020 if classname == "None":
1021 pass
1022 else:
1023 if classes_ancestor.has_key(classname):
1024 txt.write("\n\nClass %s(%s)\n" % (classname,
1025 classes_ancestor[classname]))
1026 classes.write("class %s(%s):\n" % (classname,
1027 classes_ancestor[classname]))
1028 classes.write(" def __init__(self, _obj=None):\n")
William M. Brackc68d78d2004-07-16 10:39:30 +00001029 if classes_ancestor[classname] == "xmlCore" or \
1030 classes_ancestor[classname] == "xmlNode":
1031 classes.write(" if type(_obj).__name__ != ")
1032 classes.write("'PyCObject':\n")
1033 classes.write(" raise TypeError, ")
1034 classes.write("'%s needs a PyCObject argument'\n" % \
1035 classname)
Daniel Veillarddc85f282002-12-31 11:18:37 +00001036 if reference_keepers.has_key(classname):
1037 rlist = reference_keepers[classname]
1038 for ref in rlist:
1039 classes.write(" self.%s = None\n" % ref[1])
Daniel Veillard6cbd6c02003-12-04 12:31:49 +00001040 classes.write(" self._o = _obj\n")
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001041 classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
1042 classes_ancestor[classname]))
1043 if classes_ancestor[classname] == "xmlCore" or \
1044 classes_ancestor[classname] == "xmlNode":
1045 classes.write(" def __repr__(self):\n")
Daniel Veillardba5e18a2002-03-05 09:36:43 +00001046 format = "<%s (%%s) object at 0x%%x>" % (classname)
1047 classes.write(" return \"%s\" %% (self.name, id (self))\n\n" % (
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001048 format))
1049 else:
1050 txt.write("Class %s()\n" % (classname))
1051 classes.write("class %s:\n" % (classname))
1052 classes.write(" def __init__(self, _obj=None):\n")
Daniel Veillarddc85f282002-12-31 11:18:37 +00001053 if reference_keepers.has_key(classname):
1054 list = reference_keepers[classname]
1055 for ref in list:
1056 classes.write(" self.%s = None\n" % ref[1])
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001057 classes.write(" if _obj != None:self._o = _obj;return\n")
1058 classes.write(" self._o = None\n\n");
Daniel Veillardd69cc812004-07-01 09:36:26 +00001059 destruct=None
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001060 if classes_destructors.has_key(classname):
1061 classes.write(" def __del__(self):\n")
1062 classes.write(" if self._o != None:\n")
1063 classes.write(" libxml2mod.%s(self._o)\n" %
1064 classes_destructors[classname]);
1065 classes.write(" self._o = None\n\n");
Daniel Veillardd69cc812004-07-01 09:36:26 +00001066 destruct=classes_destructors[classname]
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001067 flist = function_classes[classname]
1068 flist.sort(functionCompare)
1069 oldfile = ""
1070 for info in flist:
1071 (index, func, name, ret, args, file) = info
Daniel Veillardd69cc812004-07-01 09:36:26 +00001072 #
1073 # Do not provide as method the destructors for the class
1074 # to avoid double free
1075 #
1076 if name == destruct:
1077 continue;
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001078 if file != oldfile:
1079 if file == "python_accessor":
1080 classes.write(" # accessors for %s\n" % (classname))
1081 txt.write(" # accessors\n")
1082 else:
1083 classes.write(" #\n")
1084 classes.write(" # %s functions from module %s\n" % (
1085 classname, file))
1086 txt.write("\n # functions from module %s\n" % file)
1087 classes.write(" #\n\n")
1088 oldfile = file
1089 classes.write(" def %s(self" % func)
1090 txt.write(" %s()\n" % func);
1091 n = 0
1092 for arg in args:
1093 if n != index:
1094 classes.write(", %s" % arg[0])
1095 n = n + 1
1096 classes.write("):\n")
1097 writeDoc(name, args, ' ', classes);
1098 n = 0
1099 for arg in args:
1100 if classes_type.has_key(arg[1]):
1101 if n != index:
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001102 classes.write(" if %s is None: %s__o = None\n" %
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001103 (arg[0], arg[0]))
1104 classes.write(" else: %s__o = %s%s\n" %
1105 (arg[0], arg[0], classes_type[arg[1]][0]))
1106 n = n + 1
1107 if ret[0] != "void":
1108 classes.write(" ret = ");
1109 else:
1110 classes.write(" ");
1111 classes.write("libxml2mod.%s(" % name)
1112 n = 0
1113 for arg in args:
1114 if n != 0:
1115 classes.write(", ");
1116 if n != index:
1117 classes.write("%s" % arg[0])
1118 if classes_type.has_key(arg[1]):
1119 classes.write("__o");
1120 else:
1121 classes.write("self");
1122 if classes_type.has_key(arg[1]):
1123 classes.write(classes_type[arg[1]][0])
1124 n = n + 1
1125 classes.write(")\n");
1126 if ret[0] != "void":
1127 if classes_type.has_key(ret[0]):
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001128 #
1129 # Raise an exception
1130 #
Daniel Veillardef6c46f2002-03-07 22:21:56 +00001131 if functions_noexcept.has_key(name):
1132 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001133 " if ret is None:return None\n");
Daniel Veillardef6c46f2002-03-07 22:21:56 +00001134 elif string.find(name, "URI") >= 0:
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001135 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001136 " if ret is None:raise uriError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001137 % (name))
1138 elif string.find(name, "XPath") >= 0:
1139 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001140 " if ret is None:raise xpathError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001141 % (name))
1142 elif string.find(name, "Parse") >= 0:
1143 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001144 " if ret is None:raise parserError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001145 % (name))
1146 else:
1147 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001148 " if ret is None:raise treeError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001149 % (name))
Daniel Veillarddc85f282002-12-31 11:18:37 +00001150
1151 #
1152 # generate the returned class wrapper for the object
1153 #
1154 classes.write(" __tmp = ");
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001155 classes.write(classes_type[ret[0]][1] % ("ret"));
1156 classes.write("\n");
Daniel Veillarddc85f282002-12-31 11:18:37 +00001157
1158 #
1159 # Sometime one need to keep references of the source
1160 # class in the returned class object.
1161 # See reference_keepers for the list
1162 #
1163 tclass = classes_type[ret[0]][2]
1164 if reference_keepers.has_key(tclass):
1165 list = reference_keepers[tclass]
1166 for pref in list:
Daniel Veillardfebcca42003-02-16 15:44:18 +00001167 if pref[0] == classname:
Daniel Veillarddc85f282002-12-31 11:18:37 +00001168 classes.write(" __tmp.%s = self\n" %
1169 pref[1])
1170 #
1171 # return the class
1172 #
1173 classes.write(" return __tmp\n");
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001174 elif converter_type.has_key(ret[0]):
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001175 #
1176 # Raise an exception
1177 #
Daniel Veillardef6c46f2002-03-07 22:21:56 +00001178 if functions_noexcept.has_key(name):
1179 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001180 " if ret is None:return None");
Daniel Veillardef6c46f2002-03-07 22:21:56 +00001181 elif string.find(name, "URI") >= 0:
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001182 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001183 " if ret is None:raise uriError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001184 % (name))
1185 elif string.find(name, "XPath") >= 0:
1186 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001187 " if ret is None:raise xpathError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001188 % (name))
1189 elif string.find(name, "Parse") >= 0:
1190 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001191 " if ret is None:raise parserError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001192 % (name))
1193 else:
1194 classes.write(
Daniel Veillard6f46f6c2002-08-01 12:22:24 +00001195 " if ret is None:raise treeError('%s() failed')\n"
Daniel Veillard8d24cc12002-03-05 15:41:29 +00001196 % (name))
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001197 classes.write(" return ");
1198 classes.write(converter_type[ret[0]] % ("ret"));
1199 classes.write("\n");
1200 else:
1201 classes.write(" return ret\n");
1202 classes.write("\n");
1203
Daniel Veillard4f4a27f2004-01-14 23:50:34 +00001204 #
1205 # Generate enum constants
1206 #
1207 for type,enum in enums.items():
1208 classes.write("# %s\n" % type)
1209 items = enum.items()
1210 items.sort(lambda i1,i2: cmp(long(i1[1]),long(i2[1])))
1211 for name,value in items:
1212 classes.write("%s = %s\n" % (name,value))
1213 classes.write("\n");
1214
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001215 txt.close()
1216 classes.close()
1217
Daniel Veillard0fea6f42002-02-22 22:51:13 +00001218buildStubs()
1219buildWrappers()