generator.py revision 38ae7e4efe803ea78b6499cd05a394db32623e41
"amp":
"&",
"gt":
">",
"lt":
"<",
"""slow but safe standard parser, based on the XML parser in Python's standard library.""" # get the fastest available parser, and attach it to an # unmarshalling object. return both objects. ####################################################################### # be exposed as-is on the Python interface ####################################################################### 'int *':
"usually a return type",
'xmlSAXHandlerPtr':
"not the proper interface for SAX",
'htmlSAXHandlerPtr':
"not the proper interface for SAX",
'xmlRMutexPtr':
"thread specific, skipped",
'xmlMutexPtr':
"thread specific, skipped",
'xmlGlobalStatePtr':
"thread specific, skipped",
'xmlListPtr':
"internal representation not suitable for python",
'xmlBufferPtr':
"internal representation not suitable for python",
####################################################################### # Table of remapping to/from the python type or class to the C ####################################################################### 'void': (
None,
None,
None,
None),
'int': (
'i',
None,
"int",
"int"),
'long': (
'l',
None,
"long",
"long"),
'double': (
'd',
None,
"double",
"double"),
'unsigned int': (
'i',
None,
"int",
"int"),
'xmlChar': (
'c',
None,
"int",
"int"),
'unsigned char *': (
'z',
None,
"charPtr",
"char *"),
'char *': (
'z',
None,
"charPtr",
"char *"),
'const char *': (
'z',
None,
"charPtrConst",
"const char *"),
'xmlChar *': (
'z',
None,
"xmlCharPtr",
"xmlChar *"),
'const xmlChar *': (
'z',
None,
"xmlCharPtrConst",
"const xmlChar *"),
'xmlNodePtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlNodePtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlNode *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlNode *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlDtdPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlDtdPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlDtd *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlDtd *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlAttrPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlAttrPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlAttr *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlAttr *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlEntityPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlEntityPtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlEntity *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const xmlEntity *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlElementPtr': (
'O',
"xmlElement",
"xmlElementPtr",
"xmlElementPtr"),
'const xmlElementPtr': (
'O',
"xmlElement",
"xmlElementPtr",
"xmlElementPtr"),
'xmlElement *': (
'O',
"xmlElement",
"xmlElementPtr",
"xmlElementPtr"),
'const xmlElement *': (
'O',
"xmlElement",
"xmlElementPtr",
"xmlElementPtr"),
'xmlAttributePtr': (
'O',
"xmlAttribute",
"xmlAttributePtr",
"xmlAttributePtr"),
'const xmlAttributePtr': (
'O',
"xmlAttribute",
"xmlAttributePtr",
"xmlAttributePtr"),
'xmlAttribute *': (
'O',
"xmlAttribute",
"xmlAttributePtr",
"xmlAttributePtr"),
'const xmlAttribute *': (
'O',
"xmlAttribute",
"xmlAttributePtr",
"xmlAttributePtr"),
'xmlNsPtr': (
'O',
"xmlNode",
"xmlNsPtr",
"xmlNsPtr"),
'const xmlNsPtr': (
'O',
"xmlNode",
"xmlNsPtr",
"xmlNsPtr"),
'xmlNs *': (
'O',
"xmlNode",
"xmlNsPtr",
"xmlNsPtr"),
'const xmlNs *': (
'O',
"xmlNode",
"xmlNsPtr",
"xmlNsPtr"),
'xmlDocPtr': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'const xmlDocPtr': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'xmlDoc *': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'const xmlDoc *': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'htmlDocPtr': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'const htmlDocPtr': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'htmlDoc *': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'const htmlDoc *': (
'O',
"xmlNode",
"xmlDocPtr",
"xmlDocPtr"),
'htmlNodePtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const htmlNodePtr': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'htmlNode *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'const htmlNode *': (
'O',
"xmlNode",
"xmlNodePtr",
"xmlNodePtr"),
'xmlXPathContextPtr': (
'O',
"xmlXPathContext",
"xmlXPathContextPtr",
"xmlXPathContextPtr"),
'xmlXPathContext *': (
'O',
"xpathContext",
"xmlXPathContextPtr",
"xmlXPathContextPtr"),
'xmlXPathParserContextPtr': (
'O',
"xmlXPathParserContext",
"xmlXPathParserContextPtr",
"xmlXPathParserContextPtr"),
'xmlParserCtxtPtr': (
'O',
"parserCtxt",
"xmlParserCtxtPtr",
"xmlParserCtxtPtr"),
'xmlParserCtxt *': (
'O',
"parserCtxt",
"xmlParserCtxtPtr",
"xmlParserCtxtPtr"),
'htmlParserCtxtPtr': (
'O',
"parserCtxt",
"xmlParserCtxtPtr",
"xmlParserCtxtPtr"),
'htmlParserCtxt *': (
'O',
"parserCtxt",
"xmlParserCtxtPtr",
"xmlParserCtxtPtr"),
'xmlValidCtxtPtr': (
'O',
"ValidCtxt",
"xmlValidCtxtPtr",
"xmlValidCtxtPtr"),
'xmlCatalogPtr': (
'O',
"catalog",
"xmlCatalogPtr",
"xmlCatalogPtr"),
'FILE *': (
'O',
"File",
"FILEPtr",
"FILE *"),
'xmlURIPtr': (
'O',
"URI",
"xmlURIPtr",
"xmlURIPtr"),
'xmlErrorPtr': (
'O',
"Error",
"xmlErrorPtr",
"xmlErrorPtr"),
'xmlOutputBufferPtr': (
'O',
"outputBuffer",
"xmlOutputBufferPtr",
"xmlOutputBufferPtr"),
'xmlParserInputBufferPtr': (
'O',
"inputBuffer",
"xmlParserInputBufferPtr",
"xmlParserInputBufferPtr"),
'xmlRegexpPtr': (
'O',
"xmlReg",
"xmlRegexpPtr",
"xmlRegexpPtr"),
'xmlTextReaderLocatorPtr': (
'O',
"xmlTextReaderLocator",
"xmlTextReaderLocatorPtr",
"xmlTextReaderLocatorPtr"),
'xmlTextReaderPtr': (
'O',
"xmlTextReader",
"xmlTextReaderPtr",
"xmlTextReaderPtr"),
'xmlRelaxNGPtr': (
'O',
"relaxNgSchema",
"xmlRelaxNGPtr",
"xmlRelaxNGPtr"),
'xmlRelaxNGParserCtxtPtr': (
'O',
"relaxNgParserCtxt",
"xmlRelaxNGParserCtxtPtr",
"xmlRelaxNGParserCtxtPtr"),
'xmlRelaxNGValidCtxtPtr': (
'O',
"relaxNgValidCtxt",
"xmlRelaxNGValidCtxtPtr",
"xmlRelaxNGValidCtxtPtr"),
'xmlSchemaPtr': (
'O',
"Schema",
"xmlSchemaPtr",
"xmlSchemaPtr"),
'xmlSchemaParserCtxtPtr': (
'O',
"SchemaParserCtxt",
"xmlSchemaParserCtxtPtr",
"xmlSchemaParserCtxtPtr"),
'xmlSchemaValidCtxtPtr': (
'O',
"SchemaValidCtxt",
"xmlSchemaValidCtxtPtr",
"xmlSchemaValidCtxtPtr"),
'xmlXPathObjectPtr': (
'O',
"foo",
"xmlXPathObjectPtr",
"xmlXPathObjectPtr"),
'htmlCreateMemoryParserCtxt',
'xmlCreateMemoryParserCtxt',
####################################################################### # This part writes the C <-> Python stubs libxml2-py.[ch] and # the table libxml2-export.c to add when registrering the Python module ####################################################################### # Class methods which are written by hand in libxml.c but the Python-level # code is still automatically generated (so they are not in skip_function()). if name[
0:
12] ==
"xmlXPathWrap":
if name ==
"xmlFreeParserCtxt":
if name ==
"xmlCleanupParser":
if name ==
"xmlFreeTextReader":
# if name[0:11] == "xmlXPathNew": # the next function is defined in libxml.c if name ==
"xmlRelaxNGFreeValidCtxt":
if name ==
"xmlFreeValidCtxt":
if name ==
"xmlSchemaFreeValidCtxt":
# Those are skipped because the Const version is used of the bindings if name ==
"xmlTextReaderBaseUri":
if name ==
"xmlTextReaderLocalName":
if name ==
"xmlTextReaderName":
if name ==
"xmlTextReaderNamespaceUri":
if name ==
"xmlTextReaderPrefix":
if name ==
"xmlTextReaderXmlLang":
if name ==
"xmlTextReaderValue":
if name ==
"xmlOutputBufferClose":
# handled by by the superclass if name ==
"xmlOutputBufferFlush":
# handled by by the superclass if name ==
"xmlErrMemory":
if name ==
"xmlValidBuildContentModel":
if name ==
"xmlValidateElementDecl":
if name ==
"xmlValidateAttributeDecl":
print "failed to get function %s infos" # Don't delete the function entry in the caller. if arg[
1][
0:
6] ==
"const ":
" %s = (%s) Py%s_Get(pyobj_%s);\n" % (
arg[
0],
if file ==
"python_accessor":
if args[
1][
1] ==
"char *" or args[
1][
1] ==
"xmlChar *":
c_call =
"\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % (
c_call =
c_call +
" %s->%s = (%s)xmlStrdup((const xmlChar *)%s);\n" % (
args[
0][
0],
ret_convert =
" Py_INCREF(Py_None);\n return(Py_None);\n" if file ==
"python_accessor" and ret[
2] !=
None:
ret_convert =
" py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
ret_convert =
" py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c)
export.
write(
" { (char *)\"%s\", libxml_%s, METH_VARARGS, NULL },\n" %
# Those have been manually generated if file ==
"python_accessor" and ret[
0] !=
"void" and ret[
2]
is None:
# Those have been manually generated output.
write(
"\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
py_types[
'pythonObject'] = (
'O',
"pythonObject",
"pythonObject",
"pythonObject")
print "Generated %d wrapper functions, %d failed, %d skipped\n" % (
nb_wrap,
print "Missing type converters: " ####################################################################### # This part writes part of the Python front-end classes based on # mapping rules between types and classes and also based on function # renaming to get consistent function names at the Python level ####################################################################### # The type automatically remapped to generated classes "xmlNodePtr": (
"._o",
"xmlNode(_obj=%s)",
"xmlNode"),
"xmlNode *": (
"._o",
"xmlNode(_obj=%s)",
"xmlNode"),
"xmlDocPtr": (
"._o",
"xmlDoc(_obj=%s)",
"xmlDoc"),
"xmlDocPtr *": (
"._o",
"xmlDoc(_obj=%s)",
"xmlDoc"),
"htmlDocPtr": (
"._o",
"xmlDoc(_obj=%s)",
"xmlDoc"),
"htmlxmlDocPtr *": (
"._o",
"xmlDoc(_obj=%s)",
"xmlDoc"),
"xmlAttrPtr": (
"._o",
"xmlAttr(_obj=%s)",
"xmlAttr"),
"xmlAttr *": (
"._o",
"xmlAttr(_obj=%s)",
"xmlAttr"),
"xmlNsPtr": (
"._o",
"xmlNs(_obj=%s)",
"xmlNs"),
"xmlNs *": (
"._o",
"xmlNs(_obj=%s)",
"xmlNs"),
"xmlDtdPtr": (
"._o",
"xmlDtd(_obj=%s)",
"xmlDtd"),
"xmlDtd *": (
"._o",
"xmlDtd(_obj=%s)",
"xmlDtd"),
"xmlEntityPtr": (
"._o",
"xmlEntity(_obj=%s)",
"xmlEntity"),
"xmlEntity *": (
"._o",
"xmlEntity(_obj=%s)",
"xmlEntity"),
"xmlElementPtr": (
"._o",
"xmlElement(_obj=%s)",
"xmlElement"),
"xmlElement *": (
"._o",
"xmlElement(_obj=%s)",
"xmlElement"),
"xmlAttributePtr": (
"._o",
"xmlAttribute(_obj=%s)",
"xmlAttribute"),
"xmlAttribute *": (
"._o",
"xmlAttribute(_obj=%s)",
"xmlAttribute"),
"xmlXPathContextPtr": (
"._o",
"xpathContext(_obj=%s)",
"xpathContext"),
"xmlXPathContext *": (
"._o",
"xpathContext(_obj=%s)",
"xpathContext"),
"xmlXPathParserContext *": (
"._o",
"xpathParserContext(_obj=%s)",
"xpathParserContext"),
"xmlXPathParserContextPtr": (
"._o",
"xpathParserContext(_obj=%s)",
"xpathParserContext"),
"xmlParserCtxtPtr": (
"._o",
"parserCtxt(_obj=%s)",
"parserCtxt"),
"xmlParserCtxt *": (
"._o",
"parserCtxt(_obj=%s)",
"parserCtxt"),
"htmlParserCtxtPtr": (
"._o",
"parserCtxt(_obj=%s)",
"parserCtxt"),
"htmlParserCtxt *": (
"._o",
"parserCtxt(_obj=%s)",
"parserCtxt"),
"xmlValidCtxtPtr": (
"._o",
"ValidCtxt(_obj=%s)",
"ValidCtxt"),
"xmlCatalogPtr": (
"._o",
"catalog(_obj=%s)",
"catalog"),
"xmlURIPtr": (
"._o",
"URI(_obj=%s)",
"URI"),
"xmlErrorPtr": (
"._o",
"Error(_obj=%s)",
"Error"),
"xmlOutputBufferPtr": (
"._o",
"outputBuffer(_obj=%s)",
"outputBuffer"),
"xmlParserInputBufferPtr": (
"._o",
"inputBuffer(_obj=%s)",
"inputBuffer"),
"xmlRegexpPtr": (
"._o",
"xmlReg(_obj=%s)",
"xmlReg"),
"xmlTextReaderLocatorPtr": (
"._o",
"xmlTextReaderLocator(_obj=%s)",
"xmlTextReaderLocator"),
"xmlTextReaderPtr": (
"._o",
"xmlTextReader(_obj=%s)",
"xmlTextReader"),
'xmlRelaxNGPtr': (
'._o',
"relaxNgSchema(_obj=%s)",
"relaxNgSchema"),
'xmlRelaxNGParserCtxtPtr': (
'._o',
"relaxNgParserCtxt(_obj=%s)",
"relaxNgParserCtxt"),
'xmlRelaxNGValidCtxtPtr': (
'._o',
"relaxNgValidCtxt(_obj=%s)",
"relaxNgValidCtxt"),
'xmlSchemaPtr': (
"._o",
"Schema(_obj=%s)",
"Schema"),
'xmlSchemaParserCtxtPtr': (
"._o",
"SchemaParserCtxt(_obj=%s)",
"SchemaParserCtxt"),
'xmlSchemaValidCtxtPtr': (
"._o",
"SchemaValidCtxt(_obj=%s)",
"SchemaValidCtxt"),
"xmlXPathObjectPtr":
"xpathObjectRet(%s)",
"xmlElement" :
"xmlNode",
"xmlAttribute" :
"xmlNode",
"outputBuffer":
"ioWriteWrapper",
"inputBuffer":
"ioReadWrapper",
"parserCtxt":
"parserCtxtCore",
"xmlTextReader":
"xmlTextReaderCore",
"ValidCtxt":
"ValidCtxtCore",
"SchemaValidCtxt":
"SchemaValidCtxtCore",
"relaxNgValidCtxt":
"relaxNgValidCtxtCore",
"parserCtxt":
"xmlFreeParserCtxt",
"catalog":
"xmlFreeCatalog",
# "outputBuffer": "xmlOutputBufferClose", "inputBuffer":
"xmlFreeParserInputBuffer",
"xmlReg":
"xmlRegFreeRegexp",
"xmlTextReader":
"xmlFreeTextReader",
"relaxNgSchema":
"xmlRelaxNGFree",
"relaxNgParserCtxt":
"xmlRelaxNGFreeParserCtxt",
"relaxNgValidCtxt":
"xmlRelaxNGFreeValidCtxt",
"Schema":
"xmlSchemaFree",
"SchemaParserCtxt":
"xmlSchemaFreeParserCtxt",
"SchemaValidCtxt":
"xmlSchemaFreeValidCtxt",
"ValidCtxt":
"xmlFreeValidCtxt",
"xmlDocSetRootElement":
1,
"xmlTextReader": [(
'inputBuffer',
'input')],
"relaxNgValidCtxt": [(
'relaxNgSchema',
'schema')],
"SchemaValidCtxt": [(
'Schema',
'schema')],
elif name[
0:
12] ==
"xmlParserGet" and file ==
"python_accessor":
elif name[
0:
12] ==
"xmlParserSet" and file ==
"python_accessor":
elif name[
0:
10] ==
"xmlNodeGet" and file ==
"python_accessor":
elif name[
0:
9] ==
"xmlURIGet" and file ==
"python_accessor":
elif name[
0:
9] ==
"xmlURISet" and file ==
"python_accessor":
elif name[
0:
11] ==
"xmlErrorGet" and file ==
"python_accessor":
elif name[
0:
17] ==
"xmlXPathParserGet" and file ==
"python_accessor":
elif name[
0:
11] ==
"xmlXPathGet" and file ==
"python_accessor":
elif name[
0:
11] ==
"xmlXPathSet" and file ==
"python_accessor":
elif name[
0:
15] ==
"xmlOutputBuffer" and file !=
"python":
elif name[
0:
20] ==
"xmlParserInputBuffer" and file !=
"python":
elif name[
0:
9] ==
"xmlRegexp" and file ==
"xmlregexp":
elif name[
0:
6] ==
"xmlReg" and file ==
"xmlregexp":
elif name[
0:
20] ==
"xmlTextReaderLocator" and file ==
"xmlreader":
elif name[
0:
18] ==
"xmlTextReaderConst" and file ==
"xmlreader":
elif name[
0:
13] ==
"xmlTextReader" and file ==
"xmlreader":
elif name[
0:
12] ==
"xmlReaderNew" and file ==
"xmlreader":
elif name[
0:
11] ==
"xmlACatalog":
elif name[
0:
7] ==
"libxml_":
elif name[
0:
6] ==
"xmlGet":
elif func[
0:
4] ==
"xPtr":
elif func[
0:
8] ==
"xInclude":
elif func[
0:
4] ==
"uTF8":
if file1 ==
"python_accessor":
if file2 ==
"python_accessor":
# Build the list of C types to look for ordered to start and file !=
"python_accessor":
and file !=
"python_accessor":
if name[
0:
8] ==
"xmlXPath":
if name[
0:
6] ==
"xmlStr":
if name[
0:
10] ==
"xmlCharStr":
txt.
write(
" Generated Classes for libxml2-python\n\n")
txt.
write(
"#\n# Global functions of the module\n#\n\n")
" if ret is None:raise uriError('%s() failed')\n" " if ret is None:raise xpathError('%s() failed')\n" " if ret is None:raise parserError('%s() failed')\n" " if ret is None:raise treeError('%s() failed')\n" txt.
write(
"\n\n#\n# Set of classes of the module\n#\n\n")
classes.
write(
" return \"%s\" %% (self.name, long(pos_id (self)))\n\n" % (
# Do not provide as method the destructors for the class if file ==
"python_accessor":
" if ret is None:return None\n");
" if ret is None:raise uriError('%s() failed')\n" " if ret is None:raise xpathError('%s() failed')\n" " if ret is None:raise parserError('%s() failed')\n" " if ret is None:raise treeError('%s() failed')\n" # generate the returned class wrapper for the object # Sometime one need to keep references of the source # class in the returned class object. # See reference_keepers for the list " if ret is None:return None");
" if ret is None:raise uriError('%s() failed')\n" " if ret is None:raise xpathError('%s() failed')\n" " if ret is None:raise parserError('%s() failed')\n" " if ret is None:raise treeError('%s() failed')\n" # Generate enum constants