Blame python/generator.py

Packit 423ecb
#!/usr/bin/python -u
Packit 423ecb
#
Packit 423ecb
# generate python wrappers from the XML API description
Packit 423ecb
#
Packit 423ecb
Packit 423ecb
functions = {}
Packit 423ecb
enums = {} # { enumType: { enumConstant: enumValue } }
Packit 423ecb
Packit 423ecb
import os
Packit 423ecb
import sys
Packit 423ecb
import string
Packit 423ecb
Packit 423ecb
if __name__ == "__main__":
Packit 423ecb
    # launched as a script
Packit 423ecb
    srcPref = os.path.dirname(sys.argv[0])
Packit 423ecb
else:
Packit 423ecb
    # imported
Packit 423ecb
    srcPref = os.path.dirname(__file__)
Packit 423ecb
Packit 423ecb
#######################################################################
Packit 423ecb
#
Packit 423ecb
#  That part if purely the API acquisition phase from the
Packit 423ecb
#  XML API description
Packit 423ecb
#
Packit 423ecb
#######################################################################
Packit 423ecb
import os
Packit 423ecb
import xml.sax
Packit 423ecb
Packit 423ecb
debug = 0
Packit 423ecb
Packit 423ecb
def getparser():
Packit 423ecb
    # Attach parser to an unmarshalling object. return both objects.
Packit 423ecb
    target = docParser()
Packit 423ecb
    parser = xml.sax.make_parser()
Packit 423ecb
    parser.setContentHandler(target)
Packit 423ecb
    return parser, target
Packit 423ecb
Packit 423ecb
class docParser(xml.sax.handler.ContentHandler):
Packit 423ecb
    def __init__(self):
Packit 423ecb
        self._methodname = None
Packit 423ecb
        self._data = []
Packit 423ecb
        self.in_function = 0
Packit 423ecb
Packit 423ecb
        self.startElement = self.start
Packit 423ecb
        self.endElement = self.end
Packit 423ecb
        self.characters = self.data
Packit 423ecb
Packit 423ecb
    def close(self):
Packit 423ecb
        if debug:
Packit 423ecb
            print("close")
Packit 423ecb
Packit 423ecb
    def getmethodname(self):
Packit 423ecb
        return self._methodname
Packit 423ecb
Packit 423ecb
    def data(self, text):
Packit 423ecb
        if debug:
Packit 423ecb
            print("data %s" % text)
Packit 423ecb
        self._data.append(text)
Packit 423ecb
Packit 423ecb
    def start(self, tag, attrs):
Packit 423ecb
        if debug:
Packit 423ecb
            print("start %s, %s" % (tag, attrs))
Packit 423ecb
        if tag == 'function':
Packit 423ecb
            self._data = []
Packit 423ecb
            self.in_function = 1
Packit 423ecb
            self.function = None
Packit 423ecb
            self.function_cond = None
Packit 423ecb
            self.function_args = []
Packit 423ecb
            self.function_descr = None
Packit 423ecb
            self.function_return = None
Packit 423ecb
            self.function_file = None
Packit 423ecb
            if 'name' in attrs.keys():
Packit 423ecb
                self.function = attrs['name']
Packit 423ecb
            if 'file' in attrs.keys():
Packit 423ecb
                self.function_file = attrs['file']
Packit 423ecb
        elif tag == 'cond':
Packit 423ecb
            self._data = []
Packit 423ecb
        elif tag == 'info':
Packit 423ecb
            self._data = []
Packit 423ecb
        elif tag == 'arg':
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_arg_name = None
Packit 423ecb
                self.function_arg_type = None
Packit 423ecb
                self.function_arg_info = None
Packit 423ecb
                if 'name' in attrs.keys():
Packit 423ecb
                    self.function_arg_name = attrs['name']
Packit 423ecb
                if 'type' in attrs.keys():
Packit 423ecb
                    self.function_arg_type = attrs['type']
Packit 423ecb
                if 'info' in attrs.keys():
Packit 423ecb
                    self.function_arg_info = attrs['info']
Packit 423ecb
        elif tag == 'return':
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_return_type = None
Packit 423ecb
                self.function_return_info = None
Packit 423ecb
                self.function_return_field = None
Packit 423ecb
                if 'type' in attrs.keys():
Packit 423ecb
                    self.function_return_type = attrs['type']
Packit 423ecb
                if 'info' in attrs.keys():
Packit 423ecb
                    self.function_return_info = attrs['info']
Packit 423ecb
                if 'field' in attrs.keys():
Packit 423ecb
                    self.function_return_field = attrs['field']
Packit 423ecb
        elif tag == 'enum':
Packit 423ecb
            enum(attrs['type'],attrs['name'],attrs['value'])
Packit 423ecb
Packit 423ecb
    def end(self, tag):
Packit 423ecb
        if debug:
Packit 423ecb
            print("end %s" % tag)
Packit 423ecb
        if tag == 'function':
Packit 423ecb
            if self.function != None:
Packit 423ecb
                function(self.function, self.function_descr,
Packit 423ecb
                         self.function_return, self.function_args,
Packit 423ecb
                         self.function_file, self.function_cond)
Packit 423ecb
                self.in_function = 0
Packit 423ecb
        elif tag == 'arg':
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_args.append([self.function_arg_name,
Packit 423ecb
                                           self.function_arg_type,
Packit 423ecb
                                           self.function_arg_info])
Packit 423ecb
        elif tag == 'return':
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_return = [self.function_return_type,
Packit 423ecb
                                        self.function_return_info,
Packit 423ecb
                                        self.function_return_field]
Packit 423ecb
        elif tag == 'info':
Packit 423ecb
            str = ''
Packit 423ecb
            for c in self._data:
Packit 423ecb
                str = str + c
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_descr = str
Packit 423ecb
        elif tag == 'cond':
Packit 423ecb
            str = ''
Packit 423ecb
            for c in self._data:
Packit 423ecb
                str = str + c
Packit 423ecb
            if self.in_function == 1:
Packit 423ecb
                self.function_cond = str
Packit 423ecb
Packit 423ecb
Packit 423ecb
def function(name, desc, ret, args, file, cond):
Packit 423ecb
    functions[name] = (desc, ret, args, file, cond)
Packit 423ecb
Packit 423ecb
def enum(type, name, value):
Packit 423ecb
    if type not in enums:
Packit 423ecb
        enums[type] = {}
Packit 423ecb
    enums[type][name] = value
Packit 423ecb
Packit 423ecb
#######################################################################
Packit 423ecb
#
Packit 423ecb
#  Some filtering rukes to drop functions/types which should not
Packit 423ecb
#  be exposed as-is on the Python interface
Packit 423ecb
#
Packit 423ecb
#######################################################################
Packit 423ecb
Packit 423ecb
skipped_modules = {
Packit 423ecb
    'xmlmemory': None,
Packit 423ecb
    'DOCBparser': None,
Packit 423ecb
    'SAX': None,
Packit 423ecb
    'hash': None,
Packit 423ecb
    'list': None,
Packit 423ecb
    'threads': None,
Packit 423ecb
#    'xpointer': None,
Packit 423ecb
}
Packit 423ecb
skipped_types = {
Packit 423ecb
    'int *': "usually a return type",
Packit 423ecb
    'xmlSAXHandlerPtr': "not the proper interface for SAX",
Packit 423ecb
    'htmlSAXHandlerPtr': "not the proper interface for SAX",
Packit 423ecb
    'xmlRMutexPtr': "thread specific, skipped",
Packit 423ecb
    'xmlMutexPtr': "thread specific, skipped",
Packit 423ecb
    'xmlGlobalStatePtr': "thread specific, skipped",
Packit 423ecb
    'xmlListPtr': "internal representation not suitable for python",
Packit 423ecb
    'xmlBufferPtr': "internal representation not suitable for python",
Packit 423ecb
    'FILE *': None,
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
#######################################################################
Packit 423ecb
#
Packit 423ecb
#  Table of remapping to/from the python type or class to the C
Packit 423ecb
#  counterpart.
Packit 423ecb
#
Packit 423ecb
#######################################################################
Packit 423ecb
Packit 423ecb
py_types = {
Packit 423ecb
    'void': (None, None, None, None),
Packit 423ecb
    'int':  ('i', None, "int", "int"),
Packit 423ecb
    'long':  ('l', None, "long", "long"),
Packit 423ecb
    'double':  ('d', None, "double", "double"),
Packit 423ecb
    'unsigned int':  ('i', None, "int", "int"),
Packit 423ecb
    'xmlChar':  ('c', None, "int", "int"),
Packit 423ecb
    'unsigned char *':  ('z', None, "charPtr", "char *"),
Packit 423ecb
    'char *':  ('z', None, "charPtr", "char *"),
Packit 423ecb
    'const char *':  ('z', None, "charPtrConst", "const char *"),
Packit 423ecb
    'xmlChar *':  ('z', None, "xmlCharPtr", "xmlChar *"),
Packit 423ecb
    'const xmlChar *':  ('z', None, "xmlCharPtrConst", "const xmlChar *"),
Packit 423ecb
    'xmlNodePtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlNodePtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlNode *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlNode *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlDtdPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlDtdPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlDtd *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlDtd *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlAttrPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlAttrPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlAttr *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlAttr *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlEntityPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlEntityPtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlEntity *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const xmlEntity *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlElementPtr':  ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
Packit 423ecb
    'const xmlElementPtr':  ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
Packit 423ecb
    'xmlElement *':  ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
Packit 423ecb
    'const xmlElement *':  ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"),
Packit 423ecb
    'xmlAttributePtr':  ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
Packit 423ecb
    'const xmlAttributePtr':  ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
Packit 423ecb
    'xmlAttribute *':  ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
Packit 423ecb
    'const xmlAttribute *':  ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"),
Packit 423ecb
    'xmlNsPtr':  ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
Packit 423ecb
    'const xmlNsPtr':  ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
Packit 423ecb
    'xmlNs *':  ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
Packit 423ecb
    'const xmlNs *':  ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"),
Packit 423ecb
    'xmlDocPtr':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'const xmlDocPtr':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'xmlDoc *':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'const xmlDoc *':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'htmlDocPtr':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'const htmlDocPtr':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'htmlDoc *':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'const htmlDoc *':  ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"),
Packit 423ecb
    'htmlNodePtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const htmlNodePtr':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'htmlNode *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'const htmlNode *':  ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
Packit 423ecb
    'xmlXPathContextPtr':  ('O', "xmlXPathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"),
Packit 423ecb
    'xmlXPathContext *':  ('O', "xpathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"),
Packit 423ecb
    'xmlXPathParserContextPtr':  ('O', "xmlXPathParserContext", "xmlXPathParserContextPtr", "xmlXPathParserContextPtr"),
Packit 423ecb
    'xmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
Packit 423ecb
    'xmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
Packit 423ecb
    'htmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
Packit 423ecb
    'htmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"),
Packit 423ecb
    'xmlValidCtxtPtr': ('O', "ValidCtxt", "xmlValidCtxtPtr", "xmlValidCtxtPtr"),
Packit 423ecb
    'xmlCatalogPtr': ('O', "catalog", "xmlCatalogPtr", "xmlCatalogPtr"),
Packit 423ecb
    'FILE *': ('O', "File", "FILEPtr", "FILE *"),
Packit 423ecb
    'xmlURIPtr': ('O', "URI", "xmlURIPtr", "xmlURIPtr"),
Packit 423ecb
    'xmlErrorPtr': ('O', "Error", "xmlErrorPtr", "xmlErrorPtr"),
Packit 423ecb
    'xmlOutputBufferPtr': ('O', "outputBuffer", "xmlOutputBufferPtr", "xmlOutputBufferPtr"),
Packit 423ecb
    'xmlParserInputBufferPtr': ('O', "inputBuffer", "xmlParserInputBufferPtr", "xmlParserInputBufferPtr"),
Packit 423ecb
    'xmlRegexpPtr': ('O', "xmlReg", "xmlRegexpPtr", "xmlRegexpPtr"),
Packit 423ecb
    'xmlTextReaderLocatorPtr': ('O', "xmlTextReaderLocator", "xmlTextReaderLocatorPtr", "xmlTextReaderLocatorPtr"),
Packit 423ecb
    'xmlTextReaderPtr': ('O', "xmlTextReader", "xmlTextReaderPtr", "xmlTextReaderPtr"),
Packit 423ecb
    'xmlRelaxNGPtr': ('O', "relaxNgSchema", "xmlRelaxNGPtr", "xmlRelaxNGPtr"),
Packit 423ecb
    'xmlRelaxNGParserCtxtPtr': ('O', "relaxNgParserCtxt", "xmlRelaxNGParserCtxtPtr", "xmlRelaxNGParserCtxtPtr"),
Packit 423ecb
    'xmlRelaxNGValidCtxtPtr': ('O', "relaxNgValidCtxt", "xmlRelaxNGValidCtxtPtr", "xmlRelaxNGValidCtxtPtr"),
Packit 423ecb
    'xmlSchemaPtr': ('O', "Schema", "xmlSchemaPtr", "xmlSchemaPtr"),
Packit 423ecb
    'xmlSchemaParserCtxtPtr': ('O', "SchemaParserCtxt", "xmlSchemaParserCtxtPtr", "xmlSchemaParserCtxtPtr"),
Packit 423ecb
    'xmlSchemaValidCtxtPtr': ('O', "SchemaValidCtxt", "xmlSchemaValidCtxtPtr", "xmlSchemaValidCtxtPtr"),
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
py_return_types = {
Packit 423ecb
    'xmlXPathObjectPtr':  ('O', "foo", "xmlXPathObjectPtr", "xmlXPathObjectPtr"),
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
unknown_types = {}
Packit 423ecb
Packit 423ecb
foreign_encoding_args = (
Packit 423ecb
    'htmlCreateMemoryParserCtxt',
Packit 423ecb
    'htmlCtxtReadMemory',
Packit 423ecb
    'htmlParseChunk',
Packit 423ecb
    'htmlReadMemory',
Packit 423ecb
    'xmlCreateMemoryParserCtxt',
Packit 423ecb
    'xmlCtxtReadMemory',
Packit 423ecb
    'xmlCtxtResetPush',
Packit 423ecb
    'xmlParseChunk',
Packit 423ecb
    'xmlParseMemory',
Packit 423ecb
    'xmlReadMemory',
Packit 423ecb
    'xmlRecoverMemory',
Packit 423ecb
)
Packit 423ecb
Packit 423ecb
#######################################################################
Packit 423ecb
#
Packit 423ecb
#  This part writes the C <-> Python stubs libxml2-py.[ch] and
Packit 423ecb
#  the table libxml2-export.c to add when registrering the Python module
Packit 423ecb
#
Packit 423ecb
#######################################################################
Packit 423ecb
Packit 423ecb
# Class methods which are written by hand in libxml.c but the Python-level
Packit 423ecb
# code is still automatically generated (so they are not in skip_function()).
Packit 423ecb
skip_impl = (
Packit 423ecb
    'xmlSaveFileTo',
Packit 423ecb
    'xmlSaveFormatFileTo',
Packit 423ecb
)
Packit 423ecb
Packit 423ecb
def skip_function(name):
Packit 423ecb
    if name[0:12] == "xmlXPathWrap":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlFreeParserCtxt":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlCleanupParser":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlFreeTextReader":
Packit 423ecb
        return 1
Packit 423ecb
#    if name[0:11] == "xmlXPathNew":
Packit 423ecb
#        return 1
Packit 423ecb
    # the next function is defined in libxml.c
Packit 423ecb
    if name == "xmlRelaxNGFreeValidCtxt":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlFreeValidCtxt":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlSchemaFreeValidCtxt":
Packit 423ecb
        return 1
Packit 423ecb
Packit 423ecb
#
Packit 423ecb
# Those are skipped because the Const version is used of the bindings
Packit 423ecb
# instead.
Packit 423ecb
#
Packit 423ecb
    if name == "xmlTextReaderBaseUri":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderLocalName":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderName":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderNamespaceUri":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderPrefix":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderXmlLang":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlTextReaderValue":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlOutputBufferClose": # handled by by the superclass
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlOutputBufferFlush": # handled by by the superclass
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlErrMemory":
Packit 423ecb
        return 1
Packit 423ecb
Packit 423ecb
    if name == "xmlValidBuildContentModel":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlValidateElementDecl":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlValidateAttributeDecl":
Packit 423ecb
        return 1
Packit 423ecb
    if name == "xmlPopInputCallbacks":
Packit 423ecb
        return 1
Packit 423ecb
Packit 423ecb
    return 0
Packit 423ecb
Packit 423ecb
def print_function_wrapper(name, output, export, include):
Packit 423ecb
    global py_types
Packit 423ecb
    global unknown_types
Packit 423ecb
    global functions
Packit 423ecb
    global skipped_modules
Packit 423ecb
Packit 423ecb
    try:
Packit 423ecb
        (desc, ret, args, file, cond) = functions[name]
Packit 423ecb
    except:
Packit 423ecb
        print("failed to get function %s infos")
Packit 423ecb
        return
Packit 423ecb
Packit 423ecb
    if file in skipped_modules:
Packit 423ecb
        return 0
Packit 423ecb
    if skip_function(name) == 1:
Packit 423ecb
        return 0
Packit 423ecb
    if name in skip_impl:
Packit 423ecb
        # Don't delete the function entry in the caller.
Packit 423ecb
        return 1
Packit 423ecb
Packit 423ecb
    c_call = ""
Packit 423ecb
    format=""
Packit 423ecb
    format_args=""
Packit 423ecb
    c_args=""
Packit 423ecb
    c_return=""
Packit 423ecb
    c_convert=""
Packit 423ecb
    c_release=""
Packit 423ecb
    num_bufs=0
Packit 423ecb
    for arg in args:
Packit 423ecb
        # This should be correct
Packit 423ecb
        if arg[1][0:6] == "const ":
Packit 423ecb
            arg[1] = arg[1][6:]
Packit 423ecb
        c_args = c_args + "    %s %s;\n" % (arg[1], arg[0])
Packit 423ecb
        if arg[1] in py_types:
Packit 423ecb
            (f, t, n, c) = py_types[arg[1]]
Packit 423ecb
            if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0):
Packit 423ecb
                f = 's#'
Packit 423ecb
            if f != None:
Packit 423ecb
                format = format + f
Packit 423ecb
            if t != None:
Packit 423ecb
                format_args = format_args + ", &pyobj_%s" % (arg[0])
Packit 423ecb
                c_args = c_args + "    PyObject *pyobj_%s;\n" % (arg[0])
Packit 423ecb
                c_convert = c_convert + \
Packit 423ecb
                   "    %s = (%s) Py%s_Get(pyobj_%s);\n" % (arg[0],
Packit 423ecb
                   arg[1], t, arg[0])
Packit 423ecb
            else:
Packit 423ecb
                format_args = format_args + ", &%s" % (arg[0])
Packit 423ecb
            if f == 's#':
Packit 423ecb
                format_args = format_args + ", &py_buffsize%d" % num_bufs
Packit 423ecb
                c_args = c_args + "    int py_buffsize%d;\n" % num_bufs
Packit 423ecb
                num_bufs = num_bufs + 1
Packit 423ecb
            if c_call != "":
Packit 423ecb
                c_call = c_call + ", "
Packit 423ecb
            c_call = c_call + "%s" % (arg[0])
Packit 423ecb
            if t == "File":
Packit 423ecb
                c_release = c_release + \
Packit 423ecb
		            "    PyFile_Release(%s);\n" % (arg[0])
Packit 423ecb
        else:
Packit 423ecb
            if arg[1] in skipped_types:
Packit 423ecb
                return 0
Packit 423ecb
            if arg[1] in unknown_types:
Packit 423ecb
                lst = unknown_types[arg[1]]
Packit 423ecb
                lst.append(name)
Packit 423ecb
            else:
Packit 423ecb
                unknown_types[arg[1]] = [name]
Packit 423ecb
            return -1
Packit 423ecb
    if format != "":
Packit 423ecb
        format = format + ":%s" % (name)
Packit 423ecb
Packit 423ecb
    if ret[0] == 'void':
Packit 423ecb
        if file == "python_accessor":
Packit 423ecb
            if args[1][1] == "char *" or args[1][1] == "xmlChar *":
Packit 423ecb
                c_call = "\n    if (%s->%s != NULL) xmlFree(%s->%s);\n" % (
Packit 423ecb
                                 args[0][0], args[1][0], args[0][0], args[1][0])
Packit 423ecb
                c_call = c_call + "    %s->%s = (%s)xmlStrdup((const xmlChar *)%s);\n" % (args[0][0],
Packit 423ecb
                                 args[1][0], args[1][1], args[1][0])
Packit 423ecb
            else:
Packit 423ecb
                c_call = "\n    %s->%s = %s;\n" % (args[0][0], args[1][0],
Packit 423ecb
                                                   args[1][0])
Packit 423ecb
        else:
Packit 423ecb
            c_call = "\n    %s(%s);\n" % (name, c_call)
Packit 423ecb
        ret_convert = "    Py_INCREF(Py_None);\n    return(Py_None);\n"
Packit 423ecb
    elif ret[0] in py_types:
Packit 423ecb
        (f, t, n, c) = py_types[ret[0]]
Packit 423ecb
        c_return = c_return + "    %s c_retval;\n" % (ret[0])
Packit 423ecb
        if file == "python_accessor" and ret[2] != None:
Packit 423ecb
            c_call = "\n    c_retval = %s->%s;\n" % (args[0][0], ret[2])
Packit 423ecb
        else:
Packit 423ecb
            c_call = "\n    c_retval = %s(%s);\n" % (name, c_call)
Packit 423ecb
        ret_convert = "    py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
Packit 423ecb
        ret_convert = ret_convert + "    return(py_retval);\n"
Packit 423ecb
    elif ret[0] in py_return_types:
Packit 423ecb
        (f, t, n, c) = py_return_types[ret[0]]
Packit 423ecb
        c_return = c_return + "    %s c_retval;\n" % (ret[0])
Packit 423ecb
        c_call = "\n    c_retval = %s(%s);\n" % (name, c_call)
Packit 423ecb
        ret_convert = "    py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
Packit 423ecb
        ret_convert = ret_convert + "    return(py_retval);\n"
Packit 423ecb
    else:
Packit 423ecb
        if ret[0] in skipped_types:
Packit 423ecb
            return 0
Packit 423ecb
        if ret[0] in unknown_types:
Packit 423ecb
            lst = unknown_types[ret[0]]
Packit 423ecb
            lst.append(name)
Packit 423ecb
        else:
Packit 423ecb
            unknown_types[ret[0]] = [name]
Packit 423ecb
        return -1
Packit 423ecb
Packit 423ecb
    if cond != None and cond != "":
Packit 423ecb
        include.write("#if %s\n" % cond)
Packit 423ecb
        export.write("#if %s\n" % cond)
Packit 423ecb
        output.write("#if %s\n" % cond)
Packit 423ecb
Packit 423ecb
    include.write("PyObject * ")
Packit 423ecb
    include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name))
Packit 423ecb
Packit 423ecb
    export.write("    { (char *)\"%s\", libxml_%s, METH_VARARGS, NULL },\n" %
Packit 423ecb
                 (name, name))
Packit 423ecb
Packit 423ecb
    if file == "python":
Packit 423ecb
        # Those have been manually generated
Packit 423ecb
        if cond != None and cond != "":
Packit 423ecb
            include.write("#endif\n")
Packit 423ecb
            export.write("#endif\n")
Packit 423ecb
            output.write("#endif\n")
Packit 423ecb
        return 1
Packit 423ecb
    if file == "python_accessor" and ret[0] != "void" and ret[2] is None:
Packit 423ecb
        # Those have been manually generated
Packit 423ecb
        if cond != None and cond != "":
Packit 423ecb
            include.write("#endif\n")
Packit 423ecb
            export.write("#endif\n")
Packit 423ecb
            output.write("#endif\n")
Packit 423ecb
        return 1
Packit 423ecb
Packit 423ecb
    output.write("PyObject *\n")
Packit 423ecb
    output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
Packit 423ecb
    output.write(" PyObject *args")
Packit 423ecb
    if format == "":
Packit 423ecb
        output.write(" ATTRIBUTE_UNUSED")
Packit 423ecb
    output.write(") {\n")
Packit 423ecb
    if ret[0] != 'void':
Packit 423ecb
        output.write("    PyObject *py_retval;\n")
Packit 423ecb
    if c_return != "":
Packit 423ecb
        output.write(c_return)
Packit 423ecb
    if c_args != "":
Packit 423ecb
        output.write(c_args)
Packit 423ecb
    if format != "":
Packit 423ecb
        output.write("\n    if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
Packit 423ecb
                     (format, format_args))
Packit 423ecb
        output.write("        return(NULL);\n")
Packit 423ecb
    if c_convert != "":
Packit 423ecb
        output.write(c_convert)
Packit 423ecb
Packit 423ecb
    output.write(c_call)
Packit 423ecb
    if c_release != "":
Packit 423ecb
        output.write(c_release)
Packit 423ecb
    output.write(ret_convert)
Packit 423ecb
    output.write("}\n\n")
Packit 423ecb
    if cond != None and cond != "":
Packit 423ecb
        include.write("#endif /* %s */\n" % cond)
Packit 423ecb
        export.write("#endif /* %s */\n" % cond)
Packit 423ecb
        output.write("#endif /* %s */\n" % cond)
Packit 423ecb
    return 1
Packit 423ecb
Packit 423ecb
def buildStubs():
Packit 423ecb
    global py_types
Packit 423ecb
    global py_return_types
Packit 423ecb
    global unknown_types
Packit 423ecb
Packit 423ecb
    try:
Packit 423ecb
        f = open(os.path.join(srcPref,"libxml2-api.xml"))
Packit 423ecb
        data = f.read()
Packit 423ecb
        (parser, target)  = getparser()
Packit 423ecb
        parser.feed(data)
Packit 423ecb
        parser.close()
Packit 423ecb
    except IOError as msg:
Packit 423ecb
        try:
Packit 423ecb
            f = open(os.path.join(srcPref,"..","doc","libxml2-api.xml"))
Packit 423ecb
            data = f.read()
Packit 423ecb
            (parser, target)  = getparser()
Packit 423ecb
            parser.feed(data)
Packit 423ecb
            parser.close()
Packit 423ecb
        except IOError as msg:
Packit 423ecb
            print(file, ":", msg)
Packit 423ecb
            sys.exit(1)
Packit 423ecb
Packit 423ecb
    n = len(list(functions.keys()))
Packit 423ecb
    print("Found %d functions in libxml2-api.xml" % (n))
Packit 423ecb
Packit 423ecb
    py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject")
Packit 423ecb
    try:
Packit 423ecb
        f = open(os.path.join(srcPref,"libxml2-python-api.xml"))
Packit 423ecb
        data = f.read()
Packit 423ecb
        (parser, target)  = getparser()
Packit 423ecb
        parser.feed(data)
Packit 423ecb
        parser.close()
Packit 423ecb
    except IOError as msg:
Packit 423ecb
        print(file, ":", msg)
Packit 423ecb
Packit 423ecb
Packit 423ecb
    print("Found %d functions in libxml2-python-api.xml" % (
Packit 423ecb
          len(list(functions.keys())) - n))
Packit 423ecb
    nb_wrap = 0
Packit 423ecb
    failed = 0
Packit 423ecb
    skipped = 0
Packit 423ecb
Packit 423ecb
    include = open("libxml2-py.h", "w")
Packit 423ecb
    include.write("/* Generated */\n\n")
Packit 423ecb
    export = open("libxml2-export.c", "w")
Packit 423ecb
    export.write("/* Generated */\n\n")
Packit 423ecb
    wrapper = open("libxml2-py.c", "w")
Packit 423ecb
    wrapper.write("/* Generated */\n\n")
Packit 423ecb
    wrapper.write("#include <Python.h>\n")
Packit 423ecb
    wrapper.write("#include <libxml/xmlversion.h>\n")
Packit 423ecb
    wrapper.write("#include <libxml/tree.h>\n")
Packit 423ecb
    wrapper.write("#include <libxml/xmlschemastypes.h>\n")
Packit 423ecb
    wrapper.write("#include \"libxml_wrap.h\"\n")
Packit 423ecb
    wrapper.write("#include \"libxml2-py.h\"\n\n")
Packit 423ecb
    for function in sorted(functions.keys()):
Packit 423ecb
        ret = print_function_wrapper(function, wrapper, export, include)
Packit 423ecb
        if ret < 0:
Packit 423ecb
            failed = failed + 1
Packit 423ecb
            del functions[function]
Packit 423ecb
        if ret == 0:
Packit 423ecb
            skipped = skipped + 1
Packit 423ecb
            del functions[function]
Packit 423ecb
        if ret == 1:
Packit 423ecb
            nb_wrap = nb_wrap + 1
Packit 423ecb
    include.close()
Packit 423ecb
    export.close()
Packit 423ecb
    wrapper.close()
Packit 423ecb
Packit 423ecb
    print("Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
Packit 423ecb
                                                              failed, skipped))
Packit 423ecb
    print("Missing type converters: ")
Packit 423ecb
    for type in list(unknown_types.keys()):
Packit 423ecb
        print("%s:%d " % (type, len(unknown_types[type])))
Packit 423ecb
    print()
Packit 423ecb
Packit 423ecb
#######################################################################
Packit 423ecb
#
Packit 423ecb
#  This part writes part of the Python front-end classes based on
Packit 423ecb
#  mapping rules between types and classes and also based on function
Packit 423ecb
#  renaming to get consistent function names at the Python level
Packit 423ecb
#
Packit 423ecb
#######################################################################
Packit 423ecb
Packit 423ecb
#
Packit 423ecb
# The type automatically remapped to generated classes
Packit 423ecb
#
Packit 423ecb
classes_type = {
Packit 423ecb
    "xmlNodePtr": ("._o", "xmlNode(_obj=%s)", "xmlNode"),
Packit 423ecb
    "xmlNode *": ("._o", "xmlNode(_obj=%s)", "xmlNode"),
Packit 423ecb
    "xmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
Packit 423ecb
    "xmlDoc *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
Packit 423ecb
    "htmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
Packit 423ecb
    "htmlxmlDocPtr *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"),
Packit 423ecb
    "xmlAttrPtr": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"),
Packit 423ecb
    "xmlAttr *": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"),
Packit 423ecb
    "xmlNsPtr": ("._o", "xmlNs(_obj=%s)", "xmlNs"),
Packit 423ecb
    "xmlNs *": ("._o", "xmlNs(_obj=%s)", "xmlNs"),
Packit 423ecb
    "xmlDtdPtr": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"),
Packit 423ecb
    "xmlDtd *": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"),
Packit 423ecb
    "xmlEntityPtr": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"),
Packit 423ecb
    "xmlEntity *": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"),
Packit 423ecb
    "xmlElementPtr": ("._o", "xmlElement(_obj=%s)", "xmlElement"),
Packit 423ecb
    "xmlElement *": ("._o", "xmlElement(_obj=%s)", "xmlElement"),
Packit 423ecb
    "xmlAttributePtr": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"),
Packit 423ecb
    "xmlAttribute *": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"),
Packit 423ecb
    "xmlXPathContextPtr": ("._o", "xpathContext(_obj=%s)", "xpathContext"),
Packit 423ecb
    "xmlXPathContext *": ("._o", "xpathContext(_obj=%s)", "xpathContext"),
Packit 423ecb
    "xmlXPathParserContext *": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"),
Packit 423ecb
    "xmlXPathParserContextPtr": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"),
Packit 423ecb
    "xmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Packit 423ecb
    "xmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Packit 423ecb
    "htmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Packit 423ecb
    "htmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"),
Packit 423ecb
    "xmlValidCtxtPtr": ("._o", "ValidCtxt(_obj=%s)", "ValidCtxt"),
Packit 423ecb
    "xmlCatalogPtr": ("._o", "catalog(_obj=%s)", "catalog"),
Packit 423ecb
    "xmlURIPtr": ("._o", "URI(_obj=%s)", "URI"),
Packit 423ecb
    "xmlErrorPtr": ("._o", "Error(_obj=%s)", "Error"),
Packit 423ecb
    "xmlOutputBufferPtr": ("._o", "outputBuffer(_obj=%s)", "outputBuffer"),
Packit 423ecb
    "xmlParserInputBufferPtr": ("._o", "inputBuffer(_obj=%s)", "inputBuffer"),
Packit 423ecb
    "xmlRegexpPtr": ("._o", "xmlReg(_obj=%s)", "xmlReg"),
Packit 423ecb
    "xmlTextReaderLocatorPtr": ("._o", "xmlTextReaderLocator(_obj=%s)", "xmlTextReaderLocator"),
Packit 423ecb
    "xmlTextReaderPtr": ("._o", "xmlTextReader(_obj=%s)", "xmlTextReader"),
Packit 423ecb
    'xmlRelaxNGPtr': ('._o', "relaxNgSchema(_obj=%s)", "relaxNgSchema"),
Packit 423ecb
    'xmlRelaxNGParserCtxtPtr': ('._o', "relaxNgParserCtxt(_obj=%s)", "relaxNgParserCtxt"),
Packit 423ecb
    'xmlRelaxNGValidCtxtPtr': ('._o', "relaxNgValidCtxt(_obj=%s)", "relaxNgValidCtxt"),
Packit 423ecb
    'xmlSchemaPtr': ("._o", "Schema(_obj=%s)", "Schema"),
Packit 423ecb
    'xmlSchemaParserCtxtPtr': ("._o", "SchemaParserCtxt(_obj=%s)", "SchemaParserCtxt"),
Packit 423ecb
    'xmlSchemaValidCtxtPtr': ("._o", "SchemaValidCtxt(_obj=%s)", "SchemaValidCtxt"),
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
converter_type = {
Packit 423ecb
    "xmlXPathObjectPtr": "xpathObjectRet(%s)",
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
primary_classes = ["xmlNode", "xmlDoc"]
Packit 423ecb
Packit 423ecb
classes_ancestor = {
Packit 423ecb
    "xmlNode" : "xmlCore",
Packit 423ecb
    "xmlDtd" : "xmlNode",
Packit 423ecb
    "xmlDoc" : "xmlNode",
Packit 423ecb
    "xmlAttr" : "xmlNode",
Packit 423ecb
    "xmlNs" : "xmlNode",
Packit 423ecb
    "xmlEntity" : "xmlNode",
Packit 423ecb
    "xmlElement" : "xmlNode",
Packit 423ecb
    "xmlAttribute" : "xmlNode",
Packit 423ecb
    "outputBuffer": "ioWriteWrapper",
Packit 423ecb
    "inputBuffer": "ioReadWrapper",
Packit 423ecb
    "parserCtxt": "parserCtxtCore",
Packit 423ecb
    "xmlTextReader": "xmlTextReaderCore",
Packit 423ecb
    "ValidCtxt": "ValidCtxtCore",
Packit 423ecb
    "SchemaValidCtxt": "SchemaValidCtxtCore",
Packit 423ecb
    "relaxNgValidCtxt": "relaxNgValidCtxtCore",
Packit 423ecb
}
Packit 423ecb
classes_destructors = {
Packit 423ecb
    "parserCtxt": "xmlFreeParserCtxt",
Packit 423ecb
    "catalog": "xmlFreeCatalog",
Packit 423ecb
    "URI": "xmlFreeURI",
Packit 423ecb
#    "outputBuffer": "xmlOutputBufferClose",
Packit 423ecb
    "inputBuffer": "xmlFreeParserInputBuffer",
Packit 423ecb
    "xmlReg": "xmlRegFreeRegexp",
Packit 423ecb
    "xmlTextReader": "xmlFreeTextReader",
Packit 423ecb
    "relaxNgSchema": "xmlRelaxNGFree",
Packit 423ecb
    "relaxNgParserCtxt": "xmlRelaxNGFreeParserCtxt",
Packit 423ecb
    "relaxNgValidCtxt": "xmlRelaxNGFreeValidCtxt",
Packit 423ecb
        "Schema": "xmlSchemaFree",
Packit 423ecb
        "SchemaParserCtxt": "xmlSchemaFreeParserCtxt",
Packit 423ecb
        "SchemaValidCtxt": "xmlSchemaFreeValidCtxt",
Packit 423ecb
        "ValidCtxt": "xmlFreeValidCtxt",
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
functions_noexcept = {
Packit 423ecb
    "xmlHasProp": 1,
Packit 423ecb
    "xmlHasNsProp": 1,
Packit 423ecb
    "xmlDocSetRootElement": 1,
Packit 423ecb
    "xmlNodeGetNs": 1,
Packit 423ecb
    "xmlNodeGetNsDefs": 1,
Packit 423ecb
    "xmlNextElementSibling": 1,
Packit 423ecb
    "xmlPreviousElementSibling": 1,
Packit 423ecb
    "xmlFirstElementChild": 1,
Packit 423ecb
    "xmlLastElementChild": 1,
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
reference_keepers = {
Packit 423ecb
    "xmlTextReader": [('inputBuffer', 'input')],
Packit 423ecb
    "relaxNgValidCtxt": [('relaxNgSchema', 'schema')],
Packit 423ecb
        "SchemaValidCtxt": [('Schema', 'schema')],
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
function_classes = {}
Packit 423ecb
Packit 423ecb
function_classes["None"] = []
Packit 423ecb
Packit 423ecb
def nameFixup(name, classe, type, file):
Packit 423ecb
    listname = classe + "List"
Packit 423ecb
    ll = len(listname)
Packit 423ecb
    l = len(classe)
Packit 423ecb
    if name[0:l] == listname:
Packit 423ecb
        func = name[l:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:12] == "xmlParserGet" and file == "python_accessor":
Packit 423ecb
        func = name[12:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:12] == "xmlParserSet" and file == "python_accessor":
Packit 423ecb
        func = name[12:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:10] == "xmlNodeGet" and file == "python_accessor":
Packit 423ecb
        func = name[10:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:9] == "xmlURIGet" and file == "python_accessor":
Packit 423ecb
        func = name[9:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:9] == "xmlURISet" and file == "python_accessor":
Packit 423ecb
        func = name[6:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:11] == "xmlErrorGet" and file == "python_accessor":
Packit 423ecb
        func = name[11:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:17] == "xmlXPathParserGet" and file == "python_accessor":
Packit 423ecb
        func = name[17:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:11] == "xmlXPathGet" and file == "python_accessor":
Packit 423ecb
        func = name[11:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:11] == "xmlXPathSet" and file == "python_accessor":
Packit 423ecb
        func = name[8:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:15] == "xmlOutputBuffer" and file != "python":
Packit 423ecb
        func = name[15:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:20] == "xmlParserInputBuffer" and file != "python":
Packit 423ecb
        func = name[20:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:9] == "xmlRegexp" and file == "xmlregexp":
Packit 423ecb
        func = "regexp" + name[9:]
Packit 423ecb
    elif name[0:6] == "xmlReg" and file == "xmlregexp":
Packit 423ecb
        func = "regexp" + name[6:]
Packit 423ecb
    elif name[0:20] == "xmlTextReaderLocator" and file == "xmlreader":
Packit 423ecb
        func = name[20:]
Packit 423ecb
    elif name[0:18] == "xmlTextReaderConst" and file == "xmlreader":
Packit 423ecb
        func = name[18:]
Packit 423ecb
    elif name[0:13] == "xmlTextReader" and file == "xmlreader":
Packit 423ecb
        func = name[13:]
Packit 423ecb
    elif name[0:12] == "xmlReaderNew" and file == "xmlreader":
Packit 423ecb
        func = name[9:]
Packit 423ecb
    elif name[0:11] == "xmlACatalog":
Packit 423ecb
        func = name[11:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:l] == classe:
Packit 423ecb
        func = name[l:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:7] == "libxml_":
Packit 423ecb
        func = name[7:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:6] == "xmlGet":
Packit 423ecb
        func = name[6:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    elif name[0:3] == "xml":
Packit 423ecb
        func = name[3:]
Packit 423ecb
        func = func[0:1].lower() + func[1:]
Packit 423ecb
    else:
Packit 423ecb
        func = name
Packit 423ecb
    if func[0:5] == "xPath":
Packit 423ecb
        func = "xpath" + func[5:]
Packit 423ecb
    elif func[0:4] == "xPtr":
Packit 423ecb
        func = "xpointer" + func[4:]
Packit 423ecb
    elif func[0:8] == "xInclude":
Packit 423ecb
        func = "xinclude" + func[8:]
Packit 423ecb
    elif func[0:2] == "iD":
Packit 423ecb
        func = "ID" + func[2:]
Packit 423ecb
    elif func[0:3] == "uRI":
Packit 423ecb
        func = "URI" + func[3:]
Packit 423ecb
    elif func[0:4] == "uTF8":
Packit 423ecb
        func = "UTF8" + func[4:]
Packit 423ecb
    elif func[0:3] == 'sAX':
Packit 423ecb
        func = "SAX" + func[3:]
Packit 423ecb
    return func
Packit 423ecb
Packit 423ecb
Packit 423ecb
def functionCompare(info1, info2):
Packit 423ecb
    (index1, func1, name1, ret1, args1, file1) = info1
Packit 423ecb
    (index2, func2, name2, ret2, args2, file2) = info2
Packit 423ecb
    if file1 == file2:
Packit 423ecb
        if func1 < func2:
Packit 423ecb
            return -1
Packit 423ecb
        if func1 > func2:
Packit 423ecb
            return 1
Packit 423ecb
    if file1 == "python_accessor":
Packit 423ecb
        return -1
Packit 423ecb
    if file2 == "python_accessor":
Packit 423ecb
        return 1
Packit 423ecb
    if file1 < file2:
Packit 423ecb
        return -1
Packit 423ecb
    if file1 > file2:
Packit 423ecb
        return 1
Packit 423ecb
    return 0
Packit 423ecb
Packit 423ecb
def cmp_to_key(mycmp):
Packit 423ecb
    'Convert a cmp= function into a key= function'
Packit 423ecb
    class K(object):
Packit 423ecb
        def __init__(self, obj, *args):
Packit 423ecb
            self.obj = obj
Packit 423ecb
        def __lt__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) < 0
Packit 423ecb
        def __gt__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) > 0
Packit 423ecb
        def __eq__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) == 0
Packit 423ecb
        def __le__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) <= 0
Packit 423ecb
        def __ge__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) >= 0
Packit 423ecb
        def __ne__(self, other):
Packit 423ecb
            return mycmp(self.obj, other.obj) != 0
Packit 423ecb
    return K
Packit 423ecb
def writeDoc(name, args, indent, output):
Packit 423ecb
     if functions[name][0] is None or functions[name][0] == "":
Packit 423ecb
         return
Packit 423ecb
     val = functions[name][0]
Packit 423ecb
     val = val.replace("NULL", "None")
Packit 423ecb
     output.write(indent)
Packit 423ecb
     output.write('"""')
Packit 423ecb
     while len(val) > 60:
Packit 423ecb
         if val[0] == " ":
Packit 423ecb
             val = val[1:]
Packit 423ecb
             continue
Packit 423ecb
         str = val[0:60]
Packit 423ecb
         i = str.rfind(" ")
Packit 423ecb
         if i < 0:
Packit 423ecb
             i = 60
Packit 423ecb
         str = val[0:i]
Packit 423ecb
         val = val[i:]
Packit 423ecb
         output.write(str)
Packit 423ecb
         output.write('\n  ')
Packit 423ecb
         output.write(indent)
Packit 423ecb
     output.write(val)
Packit 423ecb
     output.write(' """\n')
Packit 423ecb
Packit 423ecb
def buildWrappers():
Packit 423ecb
    global ctypes
Packit 423ecb
    global py_types
Packit 423ecb
    global py_return_types
Packit 423ecb
    global unknown_types
Packit 423ecb
    global functions
Packit 423ecb
    global function_classes
Packit 423ecb
    global classes_type
Packit 423ecb
    global classes_list
Packit 423ecb
    global converter_type
Packit 423ecb
    global primary_classes
Packit 423ecb
    global converter_type
Packit 423ecb
    global classes_ancestor
Packit 423ecb
    global converter_type
Packit 423ecb
    global primary_classes
Packit 423ecb
    global classes_ancestor
Packit 423ecb
    global classes_destructors
Packit 423ecb
    global functions_noexcept
Packit 423ecb
Packit 423ecb
    for type in classes_type.keys():
Packit 423ecb
        function_classes[classes_type[type][2]] = []
Packit 423ecb
Packit 423ecb
    #
Packit 423ecb
    # Build the list of C types to look for ordered to start
Packit 423ecb
    # with primary classes
Packit 423ecb
    #
Packit 423ecb
    ctypes = []
Packit 423ecb
    classes_list = []
Packit 423ecb
    ctypes_processed = {}
Packit 423ecb
    classes_processed = {}
Packit 423ecb
    for classe in primary_classes:
Packit 423ecb
        classes_list.append(classe)
Packit 423ecb
        classes_processed[classe] = ()
Packit 423ecb
        for type in classes_type.keys():
Packit 423ecb
            tinfo = classes_type[type]
Packit 423ecb
            if tinfo[2] == classe:
Packit 423ecb
                ctypes.append(type)
Packit 423ecb
                ctypes_processed[type] = ()
Packit 423ecb
    for type in sorted(classes_type.keys()):
Packit 423ecb
        if type in ctypes_processed:
Packit 423ecb
            continue
Packit 423ecb
        tinfo = classes_type[type]
Packit 423ecb
        if tinfo[2] not in classes_processed:
Packit 423ecb
            classes_list.append(tinfo[2])
Packit 423ecb
            classes_processed[tinfo[2]] = ()
Packit 423ecb
Packit 423ecb
        ctypes.append(type)
Packit 423ecb
        ctypes_processed[type] = ()
Packit 423ecb
Packit 423ecb
    for name in functions.keys():
Packit 423ecb
        found = 0
Packit 423ecb
        (desc, ret, args, file, cond) = functions[name]
Packit 423ecb
        for type in ctypes:
Packit 423ecb
            classe = classes_type[type][2]
Packit 423ecb
Packit 423ecb
            if name[0:3] == "xml" and len(args) >= 1 and args[0][1] == type:
Packit 423ecb
                found = 1
Packit 423ecb
                func = nameFixup(name, classe, type, file)
Packit 423ecb
                info = (0, func, name, ret, args, file)
Packit 423ecb
                function_classes[classe].append(info)
Packit 423ecb
            elif name[0:3] == "xml" and len(args) >= 2 and args[1][1] == type \
Packit 423ecb
                and file != "python_accessor":
Packit 423ecb
                found = 1
Packit 423ecb
                func = nameFixup(name, classe, type, file)
Packit 423ecb
                info = (1, func, name, ret, args, file)
Packit 423ecb
                function_classes[classe].append(info)
Packit 423ecb
            elif name[0:4] == "html" and len(args) >= 1 and args[0][1] == type:
Packit 423ecb
                found = 1
Packit 423ecb
                func = nameFixup(name, classe, type, file)
Packit 423ecb
                info = (0, func, name, ret, args, file)
Packit 423ecb
                function_classes[classe].append(info)
Packit 423ecb
            elif name[0:4] == "html" and len(args) >= 2 and args[1][1] == type \
Packit 423ecb
                and file != "python_accessor":
Packit 423ecb
                found = 1
Packit 423ecb
                func = nameFixup(name, classe, type, file)
Packit 423ecb
                info = (1, func, name, ret, args, file)
Packit 423ecb
                function_classes[classe].append(info)
Packit 423ecb
        if found == 1:
Packit 423ecb
            continue
Packit 423ecb
        if name[0:8] == "xmlXPath":
Packit 423ecb
            continue
Packit 423ecb
        if name[0:6] == "xmlStr":
Packit 423ecb
            continue
Packit 423ecb
        if name[0:10] == "xmlCharStr":
Packit 423ecb
            continue
Packit 423ecb
        func = nameFixup(name, "None", file, file)
Packit 423ecb
        info = (0, func, name, ret, args, file)
Packit 423ecb
        function_classes['None'].append(info)
Packit 423ecb
   
Packit 423ecb
    classes = open("libxml2class.py", "w")
Packit 423ecb
    txt = open("libxml2class.txt", "w")
Packit 423ecb
    txt.write("          Generated Classes for libxml2-python\n\n")
Packit 423ecb
Packit 423ecb
    txt.write("#\n# Global functions of the module\n#\n\n")
Packit 423ecb
    if "None" in function_classes:
Packit 423ecb
        flist = function_classes["None"]
Packit 423ecb
        flist = sorted(flist, key=cmp_to_key(functionCompare))
Packit 423ecb
        oldfile = ""
Packit 423ecb
        for info in flist:
Packit 423ecb
            (index, func, name, ret, args, file) = info
Packit 423ecb
            if file != oldfile:
Packit 423ecb
                classes.write("#\n# Functions from module %s\n#\n\n" % file)
Packit 423ecb
                txt.write("\n# functions from module %s\n" % file)
Packit 423ecb
                oldfile = file
Packit 423ecb
            classes.write("def %s(" % func)
Packit 423ecb
            txt.write("%s()\n" % func)
Packit 423ecb
            n = 0
Packit 423ecb
            for arg in args:
Packit 423ecb
                if n != 0:
Packit 423ecb
                    classes.write(", ")
Packit 423ecb
                classes.write("%s" % arg[0])
Packit 423ecb
                n = n + 1
Packit 423ecb
            classes.write("):\n")
Packit 423ecb
            writeDoc(name, args, '    ', classes)
Packit 423ecb
Packit 423ecb
            for arg in args:
Packit 423ecb
                if arg[1] in classes_type:
Packit 423ecb
                    classes.write("    if %s is None: %s__o = None\n" %
Packit 423ecb
                                  (arg[0], arg[0]))
Packit 423ecb
                    classes.write("    else: %s__o = %s%s\n" %
Packit 423ecb
                                  (arg[0], arg[0], classes_type[arg[1]][0]))
Packit 423ecb
                if arg[1] in py_types:
Packit 423ecb
                    (f, t, n, c) = py_types[arg[1]]
Packit 423ecb
                    if t == "File":
Packit 423ecb
                        classes.write("    if %s is not None: %s.flush()\n" % (
Packit 423ecb
                                      arg[0], arg[0]))
Packit 423ecb
Packit 423ecb
            if ret[0] != "void":
Packit 423ecb
                classes.write("    ret = ")
Packit 423ecb
            else:
Packit 423ecb
                classes.write("    ")
Packit 423ecb
            classes.write("libxml2mod.%s(" % name)
Packit 423ecb
            n = 0
Packit 423ecb
            for arg in args:
Packit 423ecb
                if n != 0:
Packit 423ecb
                    classes.write(", ")
Packit 423ecb
                classes.write("%s" % arg[0])
Packit 423ecb
                if arg[1] in classes_type:
Packit 423ecb
                    classes.write("__o")
Packit 423ecb
                n = n + 1
Packit 423ecb
            classes.write(")\n")
Packit 423ecb
Packit 423ecb
# This may be needed to reposition the I/O, but likely to cause more harm
Packit 423ecb
# than good. Those changes in Python3 really break the model.
Packit 423ecb
#           for arg in args:
Packit 423ecb
#               if arg[1] in py_types:
Packit 423ecb
#                   (f, t, n, c) = py_types[arg[1]]
Packit 423ecb
#                   if t == "File":
Packit 423ecb
#                       classes.write("    if %s is not None: %s.seek(0,0)\n"%(
Packit 423ecb
#                                     arg[0], arg[0]))
Packit 423ecb
Packit 423ecb
            if ret[0] != "void":
Packit 423ecb
                if ret[0] in classes_type:
Packit 423ecb
                    #
Packit 423ecb
                    # Raise an exception
Packit 423ecb
                    #
Packit 423ecb
                    if name in functions_noexcept:
Packit 423ecb
                        classes.write("    if ret is None:return None\n")
Packit 423ecb
                    elif name.find("URI") >= 0:
Packit 423ecb
                        classes.write(
Packit 423ecb
                        "    if ret is None:raise uriError('%s() failed')\n"
Packit 423ecb
                                      % (name))
Packit 423ecb
                    elif name.find("XPath") >= 0:
Packit 423ecb
                        classes.write(
Packit 423ecb
                        "    if ret is None:raise xpathError('%s() failed')\n"
Packit 423ecb
                                      % (name))
Packit 423ecb
                    elif name.find("Parse") >= 0:
Packit 423ecb
                        classes.write(
Packit 423ecb
                        "    if ret is None:raise parserError('%s() failed')\n"
Packit 423ecb
                                      % (name))
Packit 423ecb
                    else:
Packit 423ecb
                        classes.write(
Packit 423ecb
                        "    if ret is None:raise treeError('%s() failed')\n"
Packit 423ecb
                                      % (name))
Packit 423ecb
                    classes.write("    return ")
Packit 423ecb
                    classes.write(classes_type[ret[0]][1] % ("ret"))
Packit 423ecb
                    classes.write("\n")
Packit 423ecb
                else:
Packit 423ecb
                    classes.write("    return ret\n")
Packit 423ecb
            classes.write("\n")
Packit 423ecb
Packit 423ecb
    txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
Packit 423ecb
    for classname in classes_list:
Packit 423ecb
        if classname == "None":
Packit 423ecb
            pass
Packit 423ecb
        else:
Packit 423ecb
            if classname in classes_ancestor:
Packit 423ecb
                txt.write("\n\nClass %s(%s)\n" % (classname,
Packit 423ecb
                          classes_ancestor[classname]))
Packit 423ecb
                classes.write("class %s(%s):\n" % (classname,
Packit 423ecb
                              classes_ancestor[classname]))
Packit 423ecb
                classes.write("    def __init__(self, _obj=None):\n")
Packit 423ecb
                if classes_ancestor[classname] == "xmlCore" or \
Packit 423ecb
                   classes_ancestor[classname] == "xmlNode":
Packit 423ecb
                    classes.write("        if checkWrapper(_obj) != 0:")
Packit 423ecb
                    classes.write("            raise TypeError")
Packit 423ecb
                    classes.write("('%s got a wrong wrapper object type')\n" % \
Packit 423ecb
                                classname)
Packit 423ecb
                if classname in reference_keepers:
Packit 423ecb
                    rlist = reference_keepers[classname]
Packit 423ecb
                    for ref in rlist:
Packit 423ecb
                        classes.write("        self.%s = None\n" % ref[1])
Packit 423ecb
                classes.write("        self._o = _obj\n")
Packit 423ecb
                classes.write("        %s.__init__(self, _obj=_obj)\n\n" % (
Packit 423ecb
                              classes_ancestor[classname]))
Packit 423ecb
                if classes_ancestor[classname] == "xmlCore" or \
Packit 423ecb
                   classes_ancestor[classname] == "xmlNode":
Packit 423ecb
                    classes.write("    def __repr__(self):\n")
Packit 423ecb
                    format = "<%s (%%s) object at 0x%%x>" % (classname)
Packit 423ecb
                    classes.write("        return \"%s\" %% (self.name, int(pos_id (self)))\n\n" % (
Packit 423ecb
                                  format))
Packit 423ecb
            else:
Packit 423ecb
                txt.write("Class %s()\n" % (classname))
Packit 423ecb
                classes.write("class %s:\n" % (classname))
Packit 423ecb
                classes.write("    def __init__(self, _obj=None):\n")
Packit 423ecb
                if classname in reference_keepers:
Packit 423ecb
                    list = reference_keepers[classname]
Packit 423ecb
                    for ref in list:
Packit 423ecb
                        classes.write("        self.%s = None\n" % ref[1])
Packit 423ecb
                classes.write("        if _obj != None:self._o = _obj;return\n")
Packit 423ecb
                classes.write("        self._o = None\n\n")
Packit 423ecb
            destruct=None
Packit 423ecb
            if classname in classes_destructors:
Packit 423ecb
                classes.write("    def __del__(self):\n")
Packit 423ecb
                classes.write("        if self._o != None:\n")
Packit 423ecb
                classes.write("            libxml2mod.%s(self._o)\n" %
Packit 423ecb
                              classes_destructors[classname])
Packit 423ecb
                classes.write("        self._o = None\n\n")
Packit 423ecb
                destruct=classes_destructors[classname]
Packit 423ecb
            flist = function_classes[classname]
Packit 423ecb
            flist = sorted(flist, key=cmp_to_key(functionCompare))
Packit 423ecb
            oldfile = ""
Packit 423ecb
            for info in flist:
Packit 423ecb
                (index, func, name, ret, args, file) = info
Packit 423ecb
                #
Packit 423ecb
                # Do not provide as method the destructors for the class
Packit 423ecb
                # to avoid double free
Packit 423ecb
                #
Packit 423ecb
                if name == destruct:
Packit 423ecb
                    continue
Packit 423ecb
                if file != oldfile:
Packit 423ecb
                    if file == "python_accessor":
Packit 423ecb
                        classes.write("    # accessors for %s\n" % (classname))
Packit 423ecb
                        txt.write("    # accessors\n")
Packit 423ecb
                    else:
Packit 423ecb
                        classes.write("    #\n")
Packit 423ecb
                        classes.write("    # %s functions from module %s\n" % (
Packit 423ecb
                                      classname, file))
Packit 423ecb
                        txt.write("\n    # functions from module %s\n" % file)
Packit 423ecb
                        classes.write("    #\n\n")
Packit 423ecb
                oldfile = file
Packit 423ecb
                classes.write("    def %s(self" % func)
Packit 423ecb
                txt.write("    %s()\n" % func)
Packit 423ecb
                n = 0
Packit 423ecb
                for arg in args:
Packit 423ecb
                    if n != index:
Packit 423ecb
                        classes.write(", %s" % arg[0])
Packit 423ecb
                    n = n + 1
Packit 423ecb
                classes.write("):\n")
Packit 423ecb
                writeDoc(name, args, '        ', classes)
Packit 423ecb
                n = 0
Packit 423ecb
                for arg in args:
Packit 423ecb
                    if arg[1] in classes_type:
Packit 423ecb
                        if n != index:
Packit 423ecb
                            classes.write("        if %s is None: %s__o = None\n" %
Packit 423ecb
                                          (arg[0], arg[0]))
Packit 423ecb
                            classes.write("        else: %s__o = %s%s\n" %
Packit 423ecb
                                          (arg[0], arg[0], classes_type[arg[1]][0]))
Packit 423ecb
                    n = n + 1
Packit 423ecb
                if ret[0] != "void":
Packit 423ecb
                    classes.write("        ret = ")
Packit 423ecb
                else:
Packit 423ecb
                    classes.write("        ")
Packit 423ecb
                classes.write("libxml2mod.%s(" % name)
Packit 423ecb
                n = 0
Packit 423ecb
                for arg in args:
Packit 423ecb
                    if n != 0:
Packit 423ecb
                        classes.write(", ")
Packit 423ecb
                    if n != index:
Packit 423ecb
                        classes.write("%s" % arg[0])
Packit 423ecb
                        if arg[1] in classes_type:
Packit 423ecb
                            classes.write("__o")
Packit 423ecb
                    else:
Packit 423ecb
                        classes.write("self")
Packit 423ecb
                        if arg[1] in classes_type:
Packit 423ecb
                            classes.write(classes_type[arg[1]][0])
Packit 423ecb
                    n = n + 1
Packit 423ecb
                classes.write(")\n")
Packit 423ecb
                if ret[0] != "void":
Packit 423ecb
                    if ret[0] in classes_type:
Packit 423ecb
                        #
Packit 423ecb
                        # Raise an exception
Packit 423ecb
                        #
Packit 423ecb
                        if name in functions_noexcept:
Packit 423ecb
                            classes.write(
Packit 423ecb
                                "        if ret is None:return None\n")
Packit 423ecb
                        elif name.find("URI") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise uriError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        elif name.find("XPath") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise xpathError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        elif name.find("Parse") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise parserError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        else:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise treeError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
Packit 423ecb
                        #
Packit 423ecb
                        # generate the returned class wrapper for the object
Packit 423ecb
                        #
Packit 423ecb
                        classes.write("        __tmp = ")
Packit 423ecb
                        classes.write(classes_type[ret[0]][1] % ("ret"))
Packit 423ecb
                        classes.write("\n")
Packit 423ecb
Packit 423ecb
                        #
Packit 423ecb
                        # Sometime one need to keep references of the source
Packit 423ecb
                        # class in the returned class object.
Packit 423ecb
                        # See reference_keepers for the list
Packit 423ecb
                        #
Packit 423ecb
                        tclass = classes_type[ret[0]][2]
Packit 423ecb
                        if tclass in reference_keepers:
Packit 423ecb
                            list = reference_keepers[tclass]
Packit 423ecb
                            for pref in list:
Packit 423ecb
                                if pref[0] == classname:
Packit 423ecb
                                    classes.write("        __tmp.%s = self\n" %
Packit 423ecb
                                                  pref[1])
Packit 423ecb
                        #
Packit 423ecb
                        # return the class
Packit 423ecb
                        #
Packit 423ecb
                        classes.write("        return __tmp\n")
Packit 423ecb
                    elif ret[0] in converter_type:
Packit 423ecb
                        #
Packit 423ecb
                        # Raise an exception
Packit 423ecb
                        #
Packit 423ecb
                        if name in functions_noexcept:
Packit 423ecb
                            classes.write(
Packit 423ecb
                                "        if ret is None:return None")
Packit 423ecb
                        elif name.find("URI") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise uriError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        elif name.find("XPath") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise xpathError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        elif name.find("Parse") >= 0:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise parserError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        else:
Packit 423ecb
                            classes.write(
Packit 423ecb
                    "        if ret is None:raise treeError('%s() failed')\n"
Packit 423ecb
                                          % (name))
Packit 423ecb
                        classes.write("        return ")
Packit 423ecb
                        classes.write(converter_type[ret[0]] % ("ret"))
Packit 423ecb
                        classes.write("\n")
Packit 423ecb
                    else:
Packit 423ecb
                        classes.write("        return ret\n")
Packit 423ecb
                classes.write("\n")
Packit 423ecb
Packit 423ecb
    #
Packit 423ecb
    # Generate enum constants
Packit 423ecb
    #
Packit 423ecb
    for type,enum in enums.items():
Packit 423ecb
        classes.write("# %s\n" % type)
Packit 423ecb
        items = enum.items()
Packit 423ecb
        items = sorted(items, key=(lambda i: int(i[1])))
Packit 423ecb
        for name,value in items:
Packit 423ecb
            classes.write("%s = %s\n" % (name,value))
Packit 423ecb
        classes.write("\n")
Packit 423ecb
Packit 423ecb
    txt.close()
Packit 423ecb
    classes.close()
Packit 423ecb
Packit 423ecb
buildStubs()
Packit 423ecb
buildWrappers()