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