Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # generate python wrappers from the XML API description |
| 4 | # |
| 5 | |
| 6 | functions = {} |
Daniel Veillard | 4f4a27f | 2004-01-14 23:50:34 +0000 | [diff] [blame] | 7 | enums = {} # { enumType: { enumConstant: enumValue } } |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 8 | |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 9 | import os |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 10 | import sys |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 11 | import string |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 12 | |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 13 | if __name__ == "__main__": |
| 14 | # launched as a script |
| 15 | srcPref = os.path.dirname(sys.argv[0]) |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 16 | else: |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 17 | # imported |
| 18 | srcPref = os.path.dirname(__file__) |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 19 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 20 | ####################################################################### |
| 21 | # |
| 22 | # That part if purely the API acquisition phase from the |
| 23 | # XML API description |
| 24 | # |
| 25 | ####################################################################### |
| 26 | import os |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 27 | import xmllib |
| 28 | try: |
| 29 | import sgmlop |
| 30 | except ImportError: |
| 31 | sgmlop = None # accelerator not available |
| 32 | |
| 33 | debug = 0 |
| 34 | |
| 35 | if sgmlop: |
| 36 | class FastParser: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 37 | """sgmlop based XML parser. this is typically 15x faster |
| 38 | than SlowParser...""" |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 39 | |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 40 | def __init__(self, target): |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 41 | |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 42 | # setup callbacks |
| 43 | self.finish_starttag = target.start |
| 44 | self.finish_endtag = target.end |
| 45 | self.handle_data = target.data |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 46 | |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 47 | # activate parser |
| 48 | self.parser = sgmlop.XMLParser() |
| 49 | self.parser.register(self) |
| 50 | self.feed = self.parser.feed |
| 51 | self.entity = { |
| 52 | "amp": "&", "gt": ">", "lt": "<", |
| 53 | "apos": "'", "quot": '"' |
| 54 | } |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 55 | |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 56 | def close(self): |
| 57 | try: |
| 58 | self.parser.close() |
| 59 | finally: |
| 60 | self.parser = self.feed = None # nuke circular reference |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 61 | |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 62 | def handle_entityref(self, entity): |
| 63 | # <string> entity |
| 64 | try: |
| 65 | self.handle_data(self.entity[entity]) |
| 66 | except KeyError: |
| 67 | self.handle_data("&%s;" % entity) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 68 | |
| 69 | else: |
| 70 | FastParser = None |
| 71 | |
| 72 | |
| 73 | class SlowParser(xmllib.XMLParser): |
| 74 | """slow but safe standard parser, based on the XML parser in |
| 75 | Python's standard library.""" |
| 76 | |
| 77 | def __init__(self, target): |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 78 | self.unknown_starttag = target.start |
| 79 | self.handle_data = target.data |
| 80 | self.unknown_endtag = target.end |
| 81 | xmllib.XMLParser.__init__(self) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 82 | |
| 83 | def getparser(target = None): |
| 84 | # get the fastest available parser, and attach it to an |
| 85 | # unmarshalling object. return both objects. |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 86 | if target is None: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 87 | target = docParser() |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 88 | if FastParser: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 89 | return FastParser(target), target |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 90 | return SlowParser(target), target |
| 91 | |
| 92 | class docParser: |
| 93 | def __init__(self): |
| 94 | self._methodname = None |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 95 | self._data = [] |
| 96 | self.in_function = 0 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 97 | |
| 98 | def close(self): |
| 99 | if debug: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 100 | print "close" |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 101 | |
| 102 | def getmethodname(self): |
| 103 | return self._methodname |
| 104 | |
| 105 | def data(self, text): |
| 106 | if debug: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 107 | print "data %s" % text |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 108 | self._data.append(text) |
| 109 | |
| 110 | def start(self, tag, attrs): |
| 111 | if debug: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 112 | print "start %s, %s" % (tag, attrs) |
| 113 | if tag == 'function': |
| 114 | self._data = [] |
| 115 | self.in_function = 1 |
| 116 | self.function = None |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 117 | self.function_cond = None |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 118 | self.function_args = [] |
| 119 | self.function_descr = None |
| 120 | self.function_return = None |
| 121 | self.function_file = None |
| 122 | if attrs.has_key('name'): |
| 123 | self.function = attrs['name'] |
| 124 | if attrs.has_key('file'): |
| 125 | self.function_file = attrs['file'] |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 126 | elif tag == 'cond': |
| 127 | self._data = [] |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 128 | elif tag == 'info': |
| 129 | self._data = [] |
| 130 | elif tag == 'arg': |
| 131 | if self.in_function == 1: |
| 132 | self.function_arg_name = None |
| 133 | self.function_arg_type = None |
| 134 | self.function_arg_info = None |
| 135 | if attrs.has_key('name'): |
| 136 | self.function_arg_name = attrs['name'] |
| 137 | if attrs.has_key('type'): |
| 138 | self.function_arg_type = attrs['type'] |
| 139 | if attrs.has_key('info'): |
| 140 | self.function_arg_info = attrs['info'] |
| 141 | elif tag == 'return': |
| 142 | if self.in_function == 1: |
| 143 | self.function_return_type = None |
| 144 | self.function_return_info = None |
| 145 | self.function_return_field = None |
| 146 | if attrs.has_key('type'): |
| 147 | self.function_return_type = attrs['type'] |
| 148 | if attrs.has_key('info'): |
| 149 | self.function_return_info = attrs['info'] |
| 150 | if attrs.has_key('field'): |
| 151 | self.function_return_field = attrs['field'] |
Daniel Veillard | 4f4a27f | 2004-01-14 23:50:34 +0000 | [diff] [blame] | 152 | elif tag == 'enum': |
| 153 | enum(attrs['type'],attrs['name'],attrs['value']) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 154 | |
| 155 | def end(self, tag): |
| 156 | if debug: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 157 | print "end %s" % tag |
| 158 | if tag == 'function': |
| 159 | if self.function != None: |
| 160 | function(self.function, self.function_descr, |
| 161 | self.function_return, self.function_args, |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 162 | self.function_file, self.function_cond) |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 163 | self.in_function = 0 |
| 164 | elif tag == 'arg': |
| 165 | if self.in_function == 1: |
| 166 | self.function_args.append([self.function_arg_name, |
| 167 | self.function_arg_type, |
| 168 | self.function_arg_info]) |
| 169 | elif tag == 'return': |
| 170 | if self.in_function == 1: |
| 171 | self.function_return = [self.function_return_type, |
| 172 | self.function_return_info, |
| 173 | self.function_return_field] |
| 174 | elif tag == 'info': |
| 175 | str = '' |
| 176 | for c in self._data: |
| 177 | str = str + c |
| 178 | if self.in_function == 1: |
| 179 | self.function_descr = str |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 180 | elif tag == 'cond': |
| 181 | str = '' |
| 182 | for c in self._data: |
| 183 | str = str + c |
| 184 | if self.in_function == 1: |
| 185 | self.function_cond = str |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 186 | |
| 187 | |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 188 | def function(name, desc, ret, args, file, cond): |
| 189 | functions[name] = (desc, ret, args, file, cond) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 190 | |
Daniel Veillard | 4f4a27f | 2004-01-14 23:50:34 +0000 | [diff] [blame] | 191 | def enum(type, name, value): |
| 192 | if not enums.has_key(type): |
| 193 | enums[type] = {} |
| 194 | enums[type][name] = value |
| 195 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 196 | ####################################################################### |
| 197 | # |
| 198 | # Some filtering rukes to drop functions/types which should not |
| 199 | # be exposed as-is on the Python interface |
| 200 | # |
| 201 | ####################################################################### |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 202 | |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 203 | skipped_modules = { |
| 204 | 'xmlmemory': None, |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 205 | 'DOCBparser': None, |
| 206 | 'SAX': None, |
| 207 | 'hash': None, |
| 208 | 'list': None, |
| 209 | 'threads': None, |
Daniel Veillard | ff12c49 | 2003-01-23 16:42:55 +0000 | [diff] [blame] | 210 | # 'xpointer': None, |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 211 | } |
| 212 | skipped_types = { |
| 213 | 'int *': "usually a return type", |
| 214 | 'xmlSAXHandlerPtr': "not the proper interface for SAX", |
| 215 | 'htmlSAXHandlerPtr': "not the proper interface for SAX", |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 216 | 'xmlRMutexPtr': "thread specific, skipped", |
| 217 | 'xmlMutexPtr': "thread specific, skipped", |
| 218 | 'xmlGlobalStatePtr': "thread specific, skipped", |
| 219 | 'xmlListPtr': "internal representation not suitable for python", |
| 220 | 'xmlBufferPtr': "internal representation not suitable for python", |
| 221 | 'FILE *': None, |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 222 | } |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 223 | |
| 224 | ####################################################################### |
| 225 | # |
| 226 | # Table of remapping to/from the python type or class to the C |
| 227 | # counterpart. |
| 228 | # |
| 229 | ####################################################################### |
| 230 | |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 231 | py_types = { |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 232 | 'void': (None, None, None, None), |
| 233 | 'int': ('i', None, "int", "int"), |
| 234 | 'long': ('i', None, "int", "int"), |
| 235 | 'double': ('d', None, "double", "double"), |
| 236 | 'unsigned int': ('i', None, "int", "int"), |
| 237 | 'xmlChar': ('c', None, "int", "int"), |
Daniel Veillard | 253aa2c | 2002-02-02 09:17:16 +0000 | [diff] [blame] | 238 | 'unsigned char *': ('z', None, "charPtr", "char *"), |
| 239 | 'char *': ('z', None, "charPtr", "char *"), |
Daniel Veillard | c575b99 | 2002-02-08 13:28:40 +0000 | [diff] [blame] | 240 | 'const char *': ('z', None, "charPtrConst", "const char *"), |
Daniel Veillard | 253aa2c | 2002-02-02 09:17:16 +0000 | [diff] [blame] | 241 | 'xmlChar *': ('z', None, "xmlCharPtr", "xmlChar *"), |
Daniel Veillard | c575b99 | 2002-02-08 13:28:40 +0000 | [diff] [blame] | 242 | 'const xmlChar *': ('z', None, "xmlCharPtrConst", "const xmlChar *"), |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 243 | 'xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 244 | 'const xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 245 | 'xmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 246 | 'const xmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 247 | 'xmlDtdPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 248 | 'const xmlDtdPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 249 | 'xmlDtd *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 250 | 'const xmlDtd *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 251 | 'xmlAttrPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 252 | 'const xmlAttrPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 253 | 'xmlAttr *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 254 | 'const xmlAttr *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 255 | 'xmlEntityPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 256 | 'const xmlEntityPtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 257 | 'xmlEntity *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 258 | 'const xmlEntity *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 259 | 'xmlElementPtr': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"), |
| 260 | 'const xmlElementPtr': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"), |
| 261 | 'xmlElement *': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"), |
| 262 | 'const xmlElement *': ('O', "xmlElement", "xmlElementPtr", "xmlElementPtr"), |
| 263 | 'xmlAttributePtr': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"), |
| 264 | 'const xmlAttributePtr': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"), |
| 265 | 'xmlAttribute *': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"), |
| 266 | 'const xmlAttribute *': ('O', "xmlAttribute", "xmlAttributePtr", "xmlAttributePtr"), |
| 267 | 'xmlNsPtr': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"), |
| 268 | 'const xmlNsPtr': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"), |
| 269 | 'xmlNs *': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"), |
| 270 | 'const xmlNs *': ('O', "xmlNode", "xmlNsPtr", "xmlNsPtr"), |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 271 | 'xmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 272 | 'const xmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 273 | 'xmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 274 | 'const xmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 275 | 'htmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 276 | 'const htmlDocPtr': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 277 | 'htmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 278 | 'const htmlDoc *': ('O', "xmlNode", "xmlDocPtr", "xmlDocPtr"), |
| 279 | 'htmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 280 | 'const htmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 281 | 'htmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
| 282 | 'const htmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"), |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 283 | 'xmlXPathContextPtr': ('O', "xmlXPathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"), |
| 284 | 'xmlXPathContext *': ('O', "xpathContext", "xmlXPathContextPtr", "xmlXPathContextPtr"), |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 285 | 'xmlXPathParserContextPtr': ('O', "xmlXPathParserContext", "xmlXPathParserContextPtr", "xmlXPathParserContextPtr"), |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 286 | 'xmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"), |
| 287 | 'xmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"), |
| 288 | 'htmlParserCtxtPtr': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"), |
| 289 | 'htmlParserCtxt *': ('O', "parserCtxt", "xmlParserCtxtPtr", "xmlParserCtxtPtr"), |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 290 | 'xmlValidCtxtPtr': ('O', "ValidCtxt", "xmlValidCtxtPtr", "xmlValidCtxtPtr"), |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 291 | 'xmlCatalogPtr': ('O', "catalog", "xmlCatalogPtr", "xmlCatalogPtr"), |
| 292 | 'FILE *': ('O', "File", "FILEPtr", "FILE *"), |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 293 | 'xmlURIPtr': ('O', "URI", "xmlURIPtr", "xmlURIPtr"), |
Daniel Veillard | 46da464 | 2004-01-06 22:54:57 +0000 | [diff] [blame] | 294 | 'xmlErrorPtr': ('O', "Error", "xmlErrorPtr", "xmlErrorPtr"), |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 295 | 'xmlOutputBufferPtr': ('O', "outputBuffer", "xmlOutputBufferPtr", "xmlOutputBufferPtr"), |
| 296 | 'xmlParserInputBufferPtr': ('O', "inputBuffer", "xmlParserInputBufferPtr", "xmlParserInputBufferPtr"), |
Daniel Veillard | bd9afb5 | 2002-09-25 22:25:35 +0000 | [diff] [blame] | 297 | 'xmlRegexpPtr': ('O', "xmlReg", "xmlRegexpPtr", "xmlRegexpPtr"), |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 298 | 'xmlTextReaderLocatorPtr': ('O', "xmlTextReaderLocator", "xmlTextReaderLocatorPtr", "xmlTextReaderLocatorPtr"), |
Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 299 | 'xmlTextReaderPtr': ('O', "xmlTextReader", "xmlTextReaderPtr", "xmlTextReaderPtr"), |
Daniel Veillard | 591b4be | 2003-02-09 23:33:36 +0000 | [diff] [blame] | 300 | 'xmlRelaxNGPtr': ('O', "relaxNgSchema", "xmlRelaxNGPtr", "xmlRelaxNGPtr"), |
| 301 | 'xmlRelaxNGParserCtxtPtr': ('O', "relaxNgParserCtxt", "xmlRelaxNGParserCtxtPtr", "xmlRelaxNGParserCtxtPtr"), |
| 302 | 'xmlRelaxNGValidCtxtPtr': ('O', "relaxNgValidCtxt", "xmlRelaxNGValidCtxtPtr", "xmlRelaxNGValidCtxtPtr"), |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 303 | 'xmlSchemaPtr': ('O', "Schema", "xmlSchemaPtr", "xmlSchemaPtr"), |
| 304 | 'xmlSchemaParserCtxtPtr': ('O', "SchemaParserCtxt", "xmlSchemaParserCtxtPtr", "xmlSchemaParserCtxtPtr"), |
| 305 | 'xmlSchemaValidCtxtPtr': ('O', "SchemaValidCtxt", "xmlSchemaValidCtxtPtr", "xmlSchemaValidCtxtPtr"), |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | py_return_types = { |
| 309 | 'xmlXPathObjectPtr': ('O', "foo", "xmlXPathObjectPtr", "xmlXPathObjectPtr"), |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | unknown_types = {} |
| 313 | |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 314 | foreign_encoding_args = ( |
William M. Brack | ff34911 | 2004-12-24 08:39:13 +0000 | [diff] [blame] | 315 | 'htmlCreateMemoryParserCtxt', |
| 316 | 'htmlCtxtReadMemory', |
| 317 | 'htmlParseChunk', |
| 318 | 'htmlReadMemory', |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 319 | 'xmlCreateMemoryParserCtxt', |
William M. Brack | ff34911 | 2004-12-24 08:39:13 +0000 | [diff] [blame] | 320 | 'xmlCtxtReadMemory', |
| 321 | 'xmlCtxtResetPush', |
| 322 | 'xmlParseChunk', |
| 323 | 'xmlParseMemory', |
| 324 | 'xmlReadMemory', |
| 325 | 'xmlRecoverMemory', |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 326 | ) |
| 327 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 328 | ####################################################################### |
| 329 | # |
| 330 | # This part writes the C <-> Python stubs libxml2-py.[ch] and |
| 331 | # the table libxml2-export.c to add when registrering the Python module |
| 332 | # |
| 333 | ####################################################################### |
| 334 | |
Daniel Veillard | 263ec86 | 2004-10-04 10:26:54 +0000 | [diff] [blame] | 335 | # Class methods which are written by hand in libxml.c but the Python-level |
| 336 | # code is still automatically generated (so they are not in skip_function()). |
| 337 | skip_impl = ( |
| 338 | 'xmlSaveFileTo', |
| 339 | 'xmlSaveFormatFileTo', |
| 340 | ) |
| 341 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 342 | def skip_function(name): |
| 343 | if name[0:12] == "xmlXPathWrap": |
| 344 | return 1 |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 345 | if name == "xmlFreeParserCtxt": |
| 346 | return 1 |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 347 | if name == "xmlCleanupParser": |
| 348 | return 1 |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 349 | if name == "xmlFreeTextReader": |
| 350 | return 1 |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 351 | # if name[0:11] == "xmlXPathNew": |
| 352 | # return 1 |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 353 | # the next function is defined in libxml.c |
| 354 | if name == "xmlRelaxNGFreeValidCtxt": |
| 355 | return 1 |
Daniel Veillard | 25c90c5 | 2005-03-02 10:47:41 +0000 | [diff] [blame] | 356 | if name == "xmlFreeValidCtxt": |
| 357 | return 1 |
Daniel Veillard | bb8502c | 2005-03-30 07:40:35 +0000 | [diff] [blame] | 358 | if name == "xmlSchemaFreeValidCtxt": |
| 359 | return 1 |
| 360 | |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 361 | # |
| 362 | # Those are skipped because the Const version is used of the bindings |
| 363 | # instead. |
| 364 | # |
| 365 | if name == "xmlTextReaderBaseUri": |
| 366 | return 1 |
| 367 | if name == "xmlTextReaderLocalName": |
| 368 | return 1 |
| 369 | if name == "xmlTextReaderName": |
| 370 | return 1 |
| 371 | if name == "xmlTextReaderNamespaceUri": |
| 372 | return 1 |
| 373 | if name == "xmlTextReaderPrefix": |
| 374 | return 1 |
| 375 | if name == "xmlTextReaderXmlLang": |
| 376 | return 1 |
| 377 | if name == "xmlTextReaderValue": |
| 378 | return 1 |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 379 | if name == "xmlOutputBufferClose": # handled by by the superclass |
| 380 | return 1 |
| 381 | if name == "xmlOutputBufferFlush": # handled by by the superclass |
| 382 | return 1 |
William M. Brack | f7eb794 | 2003-12-31 07:59:17 +0000 | [diff] [blame] | 383 | if name == "xmlErrMemory": |
| 384 | return 1 |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 385 | |
| 386 | if name == "xmlValidBuildContentModel": |
| 387 | return 1 |
| 388 | if name == "xmlValidateElementDecl": |
| 389 | return 1 |
| 390 | if name == "xmlValidateAttributeDecl": |
| 391 | return 1 |
| 392 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 393 | return 0 |
| 394 | |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 395 | def print_function_wrapper(name, output, export, include): |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 396 | global py_types |
| 397 | global unknown_types |
| 398 | global functions |
| 399 | global skipped_modules |
| 400 | |
| 401 | try: |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 402 | (desc, ret, args, file, cond) = functions[name] |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 403 | except: |
| 404 | print "failed to get function %s infos" |
| 405 | return |
| 406 | |
| 407 | if skipped_modules.has_key(file): |
| 408 | return 0 |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 409 | if skip_function(name) == 1: |
| 410 | return 0 |
Daniel Veillard | 263ec86 | 2004-10-04 10:26:54 +0000 | [diff] [blame] | 411 | if name in skip_impl: |
| 412 | # Don't delete the function entry in the caller. |
| 413 | return 1 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 414 | |
| 415 | c_call = ""; |
| 416 | format="" |
| 417 | format_args="" |
| 418 | c_args="" |
| 419 | c_return="" |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 420 | c_convert="" |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 421 | num_bufs=0 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 422 | for arg in args: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 423 | # This should be correct |
| 424 | if arg[1][0:6] == "const ": |
| 425 | arg[1] = arg[1][6:] |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 426 | c_args = c_args + " %s %s;\n" % (arg[1], arg[0]) |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 427 | if py_types.has_key(arg[1]): |
| 428 | (f, t, n, c) = py_types[arg[1]] |
William M. Brack | ff34911 | 2004-12-24 08:39:13 +0000 | [diff] [blame] | 429 | if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0): |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 430 | f = 't#' |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 431 | if f != None: |
| 432 | format = format + f |
| 433 | if t != None: |
| 434 | format_args = format_args + ", &pyobj_%s" % (arg[0]) |
| 435 | c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0]) |
| 436 | c_convert = c_convert + \ |
| 437 | " %s = (%s) Py%s_Get(pyobj_%s);\n" % (arg[0], |
| 438 | arg[1], t, arg[0]); |
| 439 | else: |
| 440 | format_args = format_args + ", &%s" % (arg[0]) |
William M. Brack | 106cad6 | 2004-12-23 15:56:12 +0000 | [diff] [blame] | 441 | if f == 't#': |
| 442 | format_args = format_args + ", &py_buffsize%d" % num_bufs |
| 443 | c_args = c_args + " int py_buffsize%d;\n" % num_bufs |
| 444 | num_bufs = num_bufs + 1 |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 445 | if c_call != "": |
| 446 | c_call = c_call + ", "; |
| 447 | c_call = c_call + "%s" % (arg[0]) |
| 448 | else: |
| 449 | if skipped_types.has_key(arg[1]): |
| 450 | return 0 |
| 451 | if unknown_types.has_key(arg[1]): |
| 452 | lst = unknown_types[arg[1]] |
| 453 | lst.append(name) |
| 454 | else: |
| 455 | unknown_types[arg[1]] = [name] |
| 456 | return -1 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 457 | if format != "": |
| 458 | format = format + ":%s" % (name) |
| 459 | |
| 460 | if ret[0] == 'void': |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 461 | if file == "python_accessor": |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 462 | if args[1][1] == "char *" or args[1][1] == "xmlChar *": |
| 463 | c_call = "\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % ( |
| 464 | args[0][0], args[1][0], args[0][0], args[1][0]) |
William M. Brack | a71a8ef | 2003-08-06 04:43:55 +0000 | [diff] [blame] | 465 | c_call = c_call + " %s->%s = (%s)xmlStrdup((const xmlChar *)%s);\n" % (args[0][0], |
| 466 | args[1][0], args[1][1], args[1][0]) |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 467 | else: |
| 468 | c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0], |
| 469 | args[1][0]) |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 470 | else: |
| 471 | c_call = "\n %s(%s);\n" % (name, c_call); |
| 472 | ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n" |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 473 | elif py_types.has_key(ret[0]): |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 474 | (f, t, n, c) = py_types[ret[0]] |
| 475 | c_return = " %s c_retval;\n" % (ret[0]) |
| 476 | if file == "python_accessor" and ret[2] != None: |
| 477 | c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2]) |
| 478 | else: |
| 479 | c_call = "\n c_retval = %s(%s);\n" % (name, c_call); |
| 480 | ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c) |
| 481 | ret_convert = ret_convert + " return(py_retval);\n" |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 482 | elif py_return_types.has_key(ret[0]): |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 483 | (f, t, n, c) = py_return_types[ret[0]] |
| 484 | c_return = " %s c_retval;\n" % (ret[0]) |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 485 | c_call = "\n c_retval = %s(%s);\n" % (name, c_call); |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 486 | ret_convert = " py_retval = libxml_%sWrap((%s) c_retval);\n" % (n,c) |
| 487 | ret_convert = ret_convert + " return(py_retval);\n" |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 488 | else: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 489 | if skipped_types.has_key(ret[0]): |
| 490 | return 0 |
| 491 | if unknown_types.has_key(ret[0]): |
| 492 | lst = unknown_types[ret[0]] |
| 493 | lst.append(name) |
| 494 | else: |
| 495 | unknown_types[ret[0]] = [name] |
| 496 | return -1 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 497 | |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 498 | if cond != None and cond != "": |
| 499 | include.write("#if %s\n" % cond) |
| 500 | export.write("#if %s\n" % cond) |
| 501 | output.write("#if %s\n" % cond) |
Daniel Veillard | 42766c0 | 2002-08-22 20:52:17 +0000 | [diff] [blame] | 502 | |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 503 | include.write("PyObject * ") |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 504 | include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name)); |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 505 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 506 | export.write(" { (char *)\"%s\", libxml_%s, METH_VARARGS, NULL },\n" % |
Daniel Veillard | 5e5c2d0 | 2002-02-09 18:03:01 +0000 | [diff] [blame] | 507 | (name, name)) |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 508 | |
| 509 | if file == "python": |
| 510 | # Those have been manually generated |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 511 | if cond != None and cond != "": |
| 512 | include.write("#endif\n"); |
| 513 | export.write("#endif\n"); |
| 514 | output.write("#endif\n"); |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 515 | return 1 |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 516 | if file == "python_accessor" and ret[0] != "void" and ret[2] is None: |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 517 | # Those have been manually generated |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 518 | if cond != None and cond != "": |
| 519 | include.write("#endif\n"); |
| 520 | export.write("#endif\n"); |
| 521 | output.write("#endif\n"); |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 522 | return 1 |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 523 | |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 524 | output.write("PyObject *\n") |
William M. Brack | 6bf4d6f | 2003-11-04 23:29:16 +0000 | [diff] [blame] | 525 | output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name)) |
| 526 | output.write(" PyObject *args") |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 527 | if format == "": |
William M. Brack | 6bf4d6f | 2003-11-04 23:29:16 +0000 | [diff] [blame] | 528 | output.write(" ATTRIBUTE_UNUSED") |
| 529 | output.write(") {\n") |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 530 | if ret[0] != 'void': |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 531 | output.write(" PyObject *py_retval;\n") |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 532 | if c_return != "": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 533 | output.write(c_return) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 534 | if c_args != "": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 535 | output.write(c_args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 536 | if format != "": |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 537 | output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" % |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 538 | (format, format_args)) |
| 539 | output.write(" return(NULL);\n") |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 540 | if c_convert != "": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 541 | output.write(c_convert) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 542 | |
| 543 | output.write(c_call) |
| 544 | output.write(ret_convert) |
| 545 | output.write("}\n\n") |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 546 | if cond != None and cond != "": |
| 547 | include.write("#endif /* %s */\n" % cond) |
| 548 | export.write("#endif /* %s */\n" % cond) |
| 549 | output.write("#endif /* %s */\n" % cond) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 550 | return 1 |
| 551 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 552 | def buildStubs(): |
| 553 | global py_types |
| 554 | global py_return_types |
| 555 | global unknown_types |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 556 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 557 | try: |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 558 | f = open(os.path.join(srcPref,"libxml2-api.xml")) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 559 | data = f.read() |
| 560 | (parser, target) = getparser() |
| 561 | parser.feed(data) |
| 562 | parser.close() |
| 563 | except IOError, msg: |
| 564 | try: |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 565 | f = open(os.path.join(srcPref,"..","doc","libxml2-api.xml")) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 566 | data = f.read() |
| 567 | (parser, target) = getparser() |
| 568 | parser.feed(data) |
| 569 | parser.close() |
| 570 | except IOError, msg: |
| 571 | print file, ":", msg |
| 572 | sys.exit(1) |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 573 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 574 | n = len(functions.keys()) |
| 575 | print "Found %d functions in libxml2-api.xml" % (n) |
| 576 | |
| 577 | py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject") |
| 578 | try: |
Daniel Veillard | 2fc6df9 | 2005-01-30 18:42:55 +0000 | [diff] [blame] | 579 | f = open(os.path.join(srcPref,"libxml2-python-api.xml")) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 580 | data = f.read() |
| 581 | (parser, target) = getparser() |
| 582 | parser.feed(data) |
| 583 | parser.close() |
| 584 | except IOError, msg: |
| 585 | print file, ":", msg |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 586 | |
| 587 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 588 | print "Found %d functions in libxml2-python-api.xml" % ( |
| 589 | len(functions.keys()) - n) |
| 590 | nb_wrap = 0 |
| 591 | failed = 0 |
| 592 | skipped = 0 |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 593 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 594 | include = open("libxml2-py.h", "w") |
| 595 | include.write("/* Generated */\n\n") |
| 596 | export = open("libxml2-export.c", "w") |
| 597 | export.write("/* Generated */\n\n") |
| 598 | wrapper = open("libxml2-py.c", "w") |
| 599 | wrapper.write("/* Generated */\n\n") |
| 600 | wrapper.write("#include <Python.h>\n") |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 601 | wrapper.write("#include <libxml/xmlversion.h>\n") |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 602 | wrapper.write("#include <libxml/tree.h>\n") |
William M. Brack | a71a8ef | 2003-08-06 04:43:55 +0000 | [diff] [blame] | 603 | wrapper.write("#include <libxml/xmlschemastypes.h>\n") |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 604 | wrapper.write("#include \"libxml_wrap.h\"\n") |
| 605 | wrapper.write("#include \"libxml2-py.h\"\n\n") |
| 606 | for function in functions.keys(): |
| 607 | ret = print_function_wrapper(function, wrapper, export, include) |
| 608 | if ret < 0: |
| 609 | failed = failed + 1 |
| 610 | del functions[function] |
| 611 | if ret == 0: |
| 612 | skipped = skipped + 1 |
| 613 | del functions[function] |
| 614 | if ret == 1: |
| 615 | nb_wrap = nb_wrap + 1 |
| 616 | include.close() |
| 617 | export.close() |
| 618 | wrapper.close() |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 619 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 620 | print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap, |
| 621 | failed, skipped); |
| 622 | print "Missing type converters: " |
| 623 | for type in unknown_types.keys(): |
| 624 | print "%s:%d " % (type, len(unknown_types[type])), |
| 625 | print |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 626 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 627 | ####################################################################### |
| 628 | # |
| 629 | # This part writes part of the Python front-end classes based on |
| 630 | # mapping rules between types and classes and also based on function |
| 631 | # renaming to get consistent function names at the Python level |
| 632 | # |
| 633 | ####################################################################### |
| 634 | |
| 635 | # |
| 636 | # The type automatically remapped to generated classes |
| 637 | # |
| 638 | classes_type = { |
| 639 | "xmlNodePtr": ("._o", "xmlNode(_obj=%s)", "xmlNode"), |
| 640 | "xmlNode *": ("._o", "xmlNode(_obj=%s)", "xmlNode"), |
| 641 | "xmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"), |
| 642 | "xmlDocPtr *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"), |
| 643 | "htmlDocPtr": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"), |
| 644 | "htmlxmlDocPtr *": ("._o", "xmlDoc(_obj=%s)", "xmlDoc"), |
| 645 | "xmlAttrPtr": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"), |
| 646 | "xmlAttr *": ("._o", "xmlAttr(_obj=%s)", "xmlAttr"), |
| 647 | "xmlNsPtr": ("._o", "xmlNs(_obj=%s)", "xmlNs"), |
| 648 | "xmlNs *": ("._o", "xmlNs(_obj=%s)", "xmlNs"), |
| 649 | "xmlDtdPtr": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"), |
| 650 | "xmlDtd *": ("._o", "xmlDtd(_obj=%s)", "xmlDtd"), |
| 651 | "xmlEntityPtr": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"), |
| 652 | "xmlEntity *": ("._o", "xmlEntity(_obj=%s)", "xmlEntity"), |
| 653 | "xmlElementPtr": ("._o", "xmlElement(_obj=%s)", "xmlElement"), |
| 654 | "xmlElement *": ("._o", "xmlElement(_obj=%s)", "xmlElement"), |
| 655 | "xmlAttributePtr": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"), |
| 656 | "xmlAttribute *": ("._o", "xmlAttribute(_obj=%s)", "xmlAttribute"), |
| 657 | "xmlXPathContextPtr": ("._o", "xpathContext(_obj=%s)", "xpathContext"), |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 658 | "xmlXPathContext *": ("._o", "xpathContext(_obj=%s)", "xpathContext"), |
| 659 | "xmlXPathParserContext *": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"), |
| 660 | "xmlXPathParserContextPtr": ("._o", "xpathParserContext(_obj=%s)", "xpathParserContext"), |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 661 | "xmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"), |
| 662 | "xmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"), |
Daniel Veillard | 3cd7240 | 2002-05-13 10:33:30 +0000 | [diff] [blame] | 663 | "htmlParserCtxtPtr": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"), |
| 664 | "htmlParserCtxt *": ("._o", "parserCtxt(_obj=%s)", "parserCtxt"), |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 665 | "xmlValidCtxtPtr": ("._o", "ValidCtxt(_obj=%s)", "ValidCtxt"), |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 666 | "xmlCatalogPtr": ("._o", "catalog(_obj=%s)", "catalog"), |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 667 | "xmlURIPtr": ("._o", "URI(_obj=%s)", "URI"), |
Daniel Veillard | 46da464 | 2004-01-06 22:54:57 +0000 | [diff] [blame] | 668 | "xmlErrorPtr": ("._o", "Error(_obj=%s)", "Error"), |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 669 | "xmlOutputBufferPtr": ("._o", "outputBuffer(_obj=%s)", "outputBuffer"), |
| 670 | "xmlParserInputBufferPtr": ("._o", "inputBuffer(_obj=%s)", "inputBuffer"), |
Daniel Veillard | bd9afb5 | 2002-09-25 22:25:35 +0000 | [diff] [blame] | 671 | "xmlRegexpPtr": ("._o", "xmlReg(_obj=%s)", "xmlReg"), |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 672 | "xmlTextReaderLocatorPtr": ("._o", "xmlTextReaderLocator(_obj=%s)", "xmlTextReaderLocator"), |
Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 673 | "xmlTextReaderPtr": ("._o", "xmlTextReader(_obj=%s)", "xmlTextReader"), |
Daniel Veillard | 591b4be | 2003-02-09 23:33:36 +0000 | [diff] [blame] | 674 | 'xmlRelaxNGPtr': ('._o', "relaxNgSchema(_obj=%s)", "relaxNgSchema"), |
| 675 | 'xmlRelaxNGParserCtxtPtr': ('._o', "relaxNgParserCtxt(_obj=%s)", "relaxNgParserCtxt"), |
| 676 | 'xmlRelaxNGValidCtxtPtr': ('._o', "relaxNgValidCtxt(_obj=%s)", "relaxNgValidCtxt"), |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 677 | 'xmlSchemaPtr': ("._o", "Schema(_obj=%s)", "Schema"), |
| 678 | 'xmlSchemaParserCtxtPtr': ("._o", "SchemaParserCtxt(_obj=%s)", "SchemaParserCtxt"), |
| 679 | 'xmlSchemaValidCtxtPtr': ("._o", "SchemaValidCtxt(_obj=%s)", "SchemaValidCtxt"), |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | converter_type = { |
| 683 | "xmlXPathObjectPtr": "xpathObjectRet(%s)", |
| 684 | } |
| 685 | |
| 686 | primary_classes = ["xmlNode", "xmlDoc"] |
| 687 | |
| 688 | classes_ancestor = { |
| 689 | "xmlNode" : "xmlCore", |
Daniel Veillard | 253aa2c | 2002-02-02 09:17:16 +0000 | [diff] [blame] | 690 | "xmlDtd" : "xmlNode", |
| 691 | "xmlDoc" : "xmlNode", |
| 692 | "xmlAttr" : "xmlNode", |
| 693 | "xmlNs" : "xmlNode", |
| 694 | "xmlEntity" : "xmlNode", |
| 695 | "xmlElement" : "xmlNode", |
| 696 | "xmlAttribute" : "xmlNode", |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 697 | "outputBuffer": "ioWriteWrapper", |
| 698 | "inputBuffer": "ioReadWrapper", |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 699 | "parserCtxt": "parserCtxtCore", |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 700 | "xmlTextReader": "xmlTextReaderCore", |
Daniel Veillard | 0e460da | 2005-03-30 22:47:10 +0000 | [diff] [blame] | 701 | "ValidCtxt": "ValidCtxtCore", |
| 702 | "SchemaValidCtxt": "SchemaValidCtxtCore", |
| 703 | "relaxNgValidCtxt": "relaxNgValidCtxtCore", |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 704 | } |
| 705 | classes_destructors = { |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 706 | "parserCtxt": "xmlFreeParserCtxt", |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 707 | "catalog": "xmlFreeCatalog", |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 708 | "URI": "xmlFreeURI", |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 709 | # "outputBuffer": "xmlOutputBufferClose", |
| 710 | "inputBuffer": "xmlFreeParserInputBuffer", |
Daniel Veillard | bd9afb5 | 2002-09-25 22:25:35 +0000 | [diff] [blame] | 711 | "xmlReg": "xmlRegFreeRegexp", |
Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 712 | "xmlTextReader": "xmlFreeTextReader", |
Daniel Veillard | 591b4be | 2003-02-09 23:33:36 +0000 | [diff] [blame] | 713 | "relaxNgSchema": "xmlRelaxNGFree", |
| 714 | "relaxNgParserCtxt": "xmlRelaxNGFreeParserCtxt", |
| 715 | "relaxNgValidCtxt": "xmlRelaxNGFreeValidCtxt", |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 716 | "Schema": "xmlSchemaFree", |
| 717 | "SchemaParserCtxt": "xmlSchemaFreeParserCtxt", |
| 718 | "SchemaValidCtxt": "xmlSchemaFreeValidCtxt", |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 719 | "ValidCtxt": "xmlFreeValidCtxt", |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 722 | functions_noexcept = { |
| 723 | "xmlHasProp": 1, |
| 724 | "xmlHasNsProp": 1, |
Daniel Veillard | 3b87b6b | 2003-01-10 15:21:50 +0000 | [diff] [blame] | 725 | "xmlDocSetRootElement": 1, |
William M. Brack | dbbcf8e | 2004-12-17 22:50:53 +0000 | [diff] [blame] | 726 | "xmlNodeGetNs": 1, |
| 727 | "xmlNodeGetNsDefs": 1, |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 730 | reference_keepers = { |
| 731 | "xmlTextReader": [('inputBuffer', 'input')], |
Daniel Veillard | 591b4be | 2003-02-09 23:33:36 +0000 | [diff] [blame] | 732 | "relaxNgValidCtxt": [('relaxNgSchema', 'schema')], |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 733 | "SchemaValidCtxt": [('Schema', 'schema')], |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 736 | function_classes = {} |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 737 | |
| 738 | function_classes["None"] = [] |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 739 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 740 | def nameFixup(name, classe, type, file): |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 741 | listname = classe + "List" |
| 742 | ll = len(listname) |
| 743 | l = len(classe) |
| 744 | if name[0:l] == listname: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 745 | func = name[l:] |
| 746 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 747 | elif name[0:12] == "xmlParserGet" and file == "python_accessor": |
| 748 | func = name[12:] |
| 749 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 750 | elif name[0:12] == "xmlParserSet" and file == "python_accessor": |
| 751 | func = name[12:] |
| 752 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 753 | elif name[0:10] == "xmlNodeGet" and file == "python_accessor": |
| 754 | func = name[10:] |
| 755 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 756 | elif name[0:9] == "xmlURIGet" and file == "python_accessor": |
| 757 | func = name[9:] |
| 758 | func = string.lower(func[0:1]) + func[1:] |
| 759 | elif name[0:9] == "xmlURISet" and file == "python_accessor": |
| 760 | func = name[6:] |
| 761 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 46da464 | 2004-01-06 22:54:57 +0000 | [diff] [blame] | 762 | elif name[0:11] == "xmlErrorGet" and file == "python_accessor": |
| 763 | func = name[11:] |
| 764 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | c575b99 | 2002-02-08 13:28:40 +0000 | [diff] [blame] | 765 | elif name[0:17] == "xmlXPathParserGet" and file == "python_accessor": |
| 766 | func = name[17:] |
| 767 | func = string.lower(func[0:1]) + func[1:] |
| 768 | elif name[0:11] == "xmlXPathGet" and file == "python_accessor": |
| 769 | func = name[11:] |
| 770 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 771 | elif name[0:11] == "xmlXPathSet" and file == "python_accessor": |
| 772 | func = name[8:] |
| 773 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 774 | elif name[0:15] == "xmlOutputBuffer" and file != "python": |
| 775 | func = name[15:] |
| 776 | func = string.lower(func[0:1]) + func[1:] |
| 777 | elif name[0:20] == "xmlParserInputBuffer" and file != "python": |
| 778 | func = name[20:] |
| 779 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | d4cb1e8 | 2002-09-26 09:34:23 +0000 | [diff] [blame] | 780 | elif name[0:9] == "xmlRegexp" and file == "xmlregexp": |
Daniel Veillard | bd9afb5 | 2002-09-25 22:25:35 +0000 | [diff] [blame] | 781 | func = "regexp" + name[9:] |
Daniel Veillard | d4cb1e8 | 2002-09-26 09:34:23 +0000 | [diff] [blame] | 782 | elif name[0:6] == "xmlReg" and file == "xmlregexp": |
Daniel Veillard | bd9afb5 | 2002-09-25 22:25:35 +0000 | [diff] [blame] | 783 | func = "regexp" + name[6:] |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 784 | elif name[0:20] == "xmlTextReaderLocator" and file == "xmlreader": |
| 785 | func = name[20:] |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 786 | elif name[0:18] == "xmlTextReaderConst" and file == "xmlreader": |
| 787 | func = name[18:] |
Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 788 | elif name[0:13] == "xmlTextReader" and file == "xmlreader": |
| 789 | func = name[13:] |
Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 790 | elif name[0:12] == "xmlReaderNew" and file == "xmlreader": |
| 791 | func = name[9:] |
Daniel Veillard | 7db3871 | 2002-02-07 16:39:11 +0000 | [diff] [blame] | 792 | elif name[0:11] == "xmlACatalog": |
| 793 | func = name[11:] |
| 794 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 795 | elif name[0:l] == classe: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 796 | func = name[l:] |
| 797 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 9589d45 | 2002-02-02 10:28:17 +0000 | [diff] [blame] | 798 | elif name[0:7] == "libxml_": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 799 | func = name[7:] |
| 800 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 801 | elif name[0:6] == "xmlGet": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 802 | func = name[6:] |
| 803 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 804 | elif name[0:3] == "xml": |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 805 | func = name[3:] |
| 806 | func = string.lower(func[0:1]) + func[1:] |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 807 | else: |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 808 | func = name |
| 809 | if func[0:5] == "xPath": |
| 810 | func = "xpath" + func[5:] |
| 811 | elif func[0:4] == "xPtr": |
| 812 | func = "xpointer" + func[4:] |
| 813 | elif func[0:8] == "xInclude": |
| 814 | func = "xinclude" + func[8:] |
| 815 | elif func[0:2] == "iD": |
| 816 | func = "ID" + func[2:] |
| 817 | elif func[0:3] == "uRI": |
| 818 | func = "URI" + func[3:] |
| 819 | elif func[0:4] == "uTF8": |
| 820 | func = "UTF8" + func[4:] |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 821 | elif func[0:3] == 'sAX': |
| 822 | func = "SAX" + func[3:] |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 823 | return func |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 824 | |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 825 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 826 | def functionCompare(info1, info2): |
| 827 | (index1, func1, name1, ret1, args1, file1) = info1 |
| 828 | (index2, func2, name2, ret2, args2, file2) = info2 |
Daniel Veillard | 26f1dcc | 2002-02-03 16:53:19 +0000 | [diff] [blame] | 829 | if file1 == file2: |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 830 | if func1 < func2: |
| 831 | return -1 |
| 832 | if func1 > func2: |
| 833 | return 1 |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 834 | if file1 == "python_accessor": |
| 835 | return -1 |
| 836 | if file2 == "python_accessor": |
| 837 | return 1 |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 838 | if file1 < file2: |
| 839 | return -1 |
| 840 | if file1 > file2: |
| 841 | return 1 |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 842 | return 0 |
| 843 | |
| 844 | def writeDoc(name, args, indent, output): |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 845 | if functions[name][0] is None or functions[name][0] == "": |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 846 | return |
| 847 | val = functions[name][0] |
| 848 | val = string.replace(val, "NULL", "None"); |
| 849 | output.write(indent) |
| 850 | output.write('"""') |
| 851 | while len(val) > 60: |
| 852 | str = val[0:60] |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 853 | i = string.rfind(str, " "); |
| 854 | if i < 0: |
| 855 | i = 60 |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 856 | str = val[0:i] |
Daniel Veillard | 01a6d41 | 2002-02-11 18:42:20 +0000 | [diff] [blame] | 857 | val = val[i:] |
| 858 | output.write(str) |
| 859 | output.write('\n '); |
| 860 | output.write(indent) |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 861 | output.write(val); |
Daniel Veillard | d076a20 | 2002-11-20 13:28:31 +0000 | [diff] [blame] | 862 | output.write(' """\n') |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 863 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 864 | def buildWrappers(): |
| 865 | global ctypes |
| 866 | global py_types |
| 867 | global py_return_types |
| 868 | global unknown_types |
| 869 | global functions |
| 870 | global function_classes |
| 871 | global classes_type |
| 872 | global classes_list |
| 873 | global converter_type |
| 874 | global primary_classes |
| 875 | global converter_type |
| 876 | global classes_ancestor |
| 877 | global converter_type |
| 878 | global primary_classes |
| 879 | global classes_ancestor |
| 880 | global classes_destructors |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 881 | global functions_noexcept |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 882 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 883 | for type in classes_type.keys(): |
| 884 | function_classes[classes_type[type][2]] = [] |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 885 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 886 | # |
| 887 | # Build the list of C types to look for ordered to start |
| 888 | # with primary classes |
| 889 | # |
| 890 | ctypes = [] |
| 891 | classes_list = [] |
| 892 | ctypes_processed = {} |
| 893 | classes_processed = {} |
| 894 | for classe in primary_classes: |
| 895 | classes_list.append(classe) |
| 896 | classes_processed[classe] = () |
| 897 | for type in classes_type.keys(): |
| 898 | tinfo = classes_type[type] |
| 899 | if tinfo[2] == classe: |
| 900 | ctypes.append(type) |
| 901 | ctypes_processed[type] = () |
| 902 | for type in classes_type.keys(): |
| 903 | if ctypes_processed.has_key(type): |
| 904 | continue |
| 905 | tinfo = classes_type[type] |
| 906 | if not classes_processed.has_key(tinfo[2]): |
| 907 | classes_list.append(tinfo[2]) |
| 908 | classes_processed[tinfo[2]] = () |
| 909 | |
| 910 | ctypes.append(type) |
| 911 | ctypes_processed[type] = () |
Daniel Veillard | 36ed529 | 2002-01-30 23:49:06 +0000 | [diff] [blame] | 912 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 913 | for name in functions.keys(): |
| 914 | found = 0; |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 915 | (desc, ret, args, file, cond) = functions[name] |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 916 | for type in ctypes: |
| 917 | classe = classes_type[type][2] |
| 918 | |
| 919 | if name[0:3] == "xml" and len(args) >= 1 and args[0][1] == type: |
| 920 | found = 1 |
| 921 | func = nameFixup(name, classe, type, file) |
| 922 | info = (0, func, name, ret, args, file) |
| 923 | function_classes[classe].append(info) |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 924 | elif name[0:3] == "xml" and len(args) >= 2 and args[1][1] == type \ |
| 925 | and file != "python_accessor": |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 926 | found = 1 |
| 927 | func = nameFixup(name, classe, type, file) |
| 928 | info = (1, func, name, ret, args, file) |
| 929 | function_classes[classe].append(info) |
| 930 | elif name[0:4] == "html" and len(args) >= 1 and args[0][1] == type: |
| 931 | found = 1 |
| 932 | func = nameFixup(name, classe, type, file) |
| 933 | info = (0, func, name, ret, args, file) |
| 934 | function_classes[classe].append(info) |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 935 | elif name[0:4] == "html" and len(args) >= 2 and args[1][1] == type \ |
| 936 | and file != "python_accessor": |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 937 | found = 1 |
| 938 | func = nameFixup(name, classe, type, file) |
| 939 | info = (1, func, name, ret, args, file) |
| 940 | function_classes[classe].append(info) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 941 | if found == 1: |
| 942 | continue |
| 943 | if name[0:8] == "xmlXPath": |
| 944 | continue |
| 945 | if name[0:6] == "xmlStr": |
| 946 | continue |
| 947 | if name[0:10] == "xmlCharStr": |
| 948 | continue |
| 949 | func = nameFixup(name, "None", file, file) |
| 950 | info = (0, func, name, ret, args, file) |
| 951 | function_classes['None'].append(info) |
| 952 | |
| 953 | classes = open("libxml2class.py", "w") |
| 954 | txt = open("libxml2class.txt", "w") |
| 955 | txt.write(" Generated Classes for libxml2-python\n\n") |
| 956 | |
| 957 | txt.write("#\n# Global functions of the module\n#\n\n") |
| 958 | if function_classes.has_key("None"): |
| 959 | flist = function_classes["None"] |
| 960 | flist.sort(functionCompare) |
| 961 | oldfile = "" |
| 962 | for info in flist: |
| 963 | (index, func, name, ret, args, file) = info |
| 964 | if file != oldfile: |
| 965 | classes.write("#\n# Functions from module %s\n#\n\n" % file) |
| 966 | txt.write("\n# functions from module %s\n" % file) |
| 967 | oldfile = file |
| 968 | classes.write("def %s(" % func) |
| 969 | txt.write("%s()\n" % func); |
| 970 | n = 0 |
| 971 | for arg in args: |
| 972 | if n != 0: |
| 973 | classes.write(", ") |
| 974 | classes.write("%s" % arg[0]) |
| 975 | n = n + 1 |
| 976 | classes.write("):\n") |
| 977 | writeDoc(name, args, ' ', classes); |
| 978 | |
| 979 | for arg in args: |
| 980 | if classes_type.has_key(arg[1]): |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 981 | classes.write(" if %s is None: %s__o = None\n" % |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 982 | (arg[0], arg[0])) |
| 983 | classes.write(" else: %s__o = %s%s\n" % |
| 984 | (arg[0], arg[0], classes_type[arg[1]][0])) |
| 985 | if ret[0] != "void": |
| 986 | classes.write(" ret = "); |
| 987 | else: |
| 988 | classes.write(" "); |
| 989 | classes.write("libxml2mod.%s(" % name) |
| 990 | n = 0 |
| 991 | for arg in args: |
| 992 | if n != 0: |
| 993 | classes.write(", "); |
| 994 | classes.write("%s" % arg[0]) |
| 995 | if classes_type.has_key(arg[1]): |
| 996 | classes.write("__o"); |
| 997 | n = n + 1 |
| 998 | classes.write(")\n"); |
| 999 | if ret[0] != "void": |
| 1000 | if classes_type.has_key(ret[0]): |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1001 | # |
| 1002 | # Raise an exception |
| 1003 | # |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1004 | if functions_noexcept.has_key(name): |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1005 | classes.write(" if ret is None:return None\n"); |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1006 | elif string.find(name, "URI") >= 0: |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1007 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1008 | " if ret is None:raise uriError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1009 | % (name)) |
| 1010 | elif string.find(name, "XPath") >= 0: |
| 1011 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1012 | " if ret is None:raise xpathError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1013 | % (name)) |
| 1014 | elif string.find(name, "Parse") >= 0: |
| 1015 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1016 | " if ret is None:raise parserError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1017 | % (name)) |
| 1018 | else: |
| 1019 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1020 | " if ret is None:raise treeError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1021 | % (name)) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1022 | classes.write(" return "); |
| 1023 | classes.write(classes_type[ret[0]][1] % ("ret")); |
| 1024 | classes.write("\n"); |
| 1025 | else: |
| 1026 | classes.write(" return ret\n"); |
| 1027 | classes.write("\n"); |
| 1028 | |
| 1029 | txt.write("\n\n#\n# Set of classes of the module\n#\n\n") |
| 1030 | for classname in classes_list: |
| 1031 | if classname == "None": |
| 1032 | pass |
| 1033 | else: |
| 1034 | if classes_ancestor.has_key(classname): |
| 1035 | txt.write("\n\nClass %s(%s)\n" % (classname, |
| 1036 | classes_ancestor[classname])) |
| 1037 | classes.write("class %s(%s):\n" % (classname, |
| 1038 | classes_ancestor[classname])) |
| 1039 | classes.write(" def __init__(self, _obj=None):\n") |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 1040 | if classes_ancestor[classname] == "xmlCore" or \ |
| 1041 | classes_ancestor[classname] == "xmlNode": |
| 1042 | classes.write(" if type(_obj).__name__ != ") |
| 1043 | classes.write("'PyCObject':\n") |
| 1044 | classes.write(" raise TypeError, ") |
| 1045 | classes.write("'%s needs a PyCObject argument'\n" % \ |
| 1046 | classname) |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 1047 | if reference_keepers.has_key(classname): |
| 1048 | rlist = reference_keepers[classname] |
| 1049 | for ref in rlist: |
| 1050 | classes.write(" self.%s = None\n" % ref[1]) |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 1051 | classes.write(" self._o = _obj\n") |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1052 | classes.write(" %s.__init__(self, _obj=_obj)\n\n" % ( |
| 1053 | classes_ancestor[classname])) |
| 1054 | if classes_ancestor[classname] == "xmlCore" or \ |
| 1055 | classes_ancestor[classname] == "xmlNode": |
| 1056 | classes.write(" def __repr__(self):\n") |
Daniel Veillard | ba5e18a | 2002-03-05 09:36:43 +0000 | [diff] [blame] | 1057 | format = "<%s (%%s) object at 0x%%x>" % (classname) |
| 1058 | classes.write(" return \"%s\" %% (self.name, id (self))\n\n" % ( |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1059 | format)) |
| 1060 | else: |
| 1061 | txt.write("Class %s()\n" % (classname)) |
| 1062 | classes.write("class %s:\n" % (classname)) |
| 1063 | classes.write(" def __init__(self, _obj=None):\n") |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 1064 | if reference_keepers.has_key(classname): |
| 1065 | list = reference_keepers[classname] |
| 1066 | for ref in list: |
| 1067 | classes.write(" self.%s = None\n" % ref[1]) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1068 | classes.write(" if _obj != None:self._o = _obj;return\n") |
| 1069 | classes.write(" self._o = None\n\n"); |
Daniel Veillard | d69cc81 | 2004-07-01 09:36:26 +0000 | [diff] [blame] | 1070 | destruct=None |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1071 | if classes_destructors.has_key(classname): |
| 1072 | classes.write(" def __del__(self):\n") |
| 1073 | classes.write(" if self._o != None:\n") |
| 1074 | classes.write(" libxml2mod.%s(self._o)\n" % |
| 1075 | classes_destructors[classname]); |
| 1076 | classes.write(" self._o = None\n\n"); |
Daniel Veillard | d69cc81 | 2004-07-01 09:36:26 +0000 | [diff] [blame] | 1077 | destruct=classes_destructors[classname] |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1078 | flist = function_classes[classname] |
| 1079 | flist.sort(functionCompare) |
| 1080 | oldfile = "" |
| 1081 | for info in flist: |
| 1082 | (index, func, name, ret, args, file) = info |
Daniel Veillard | d69cc81 | 2004-07-01 09:36:26 +0000 | [diff] [blame] | 1083 | # |
| 1084 | # Do not provide as method the destructors for the class |
| 1085 | # to avoid double free |
| 1086 | # |
| 1087 | if name == destruct: |
| 1088 | continue; |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1089 | if file != oldfile: |
| 1090 | if file == "python_accessor": |
| 1091 | classes.write(" # accessors for %s\n" % (classname)) |
| 1092 | txt.write(" # accessors\n") |
| 1093 | else: |
| 1094 | classes.write(" #\n") |
| 1095 | classes.write(" # %s functions from module %s\n" % ( |
| 1096 | classname, file)) |
| 1097 | txt.write("\n # functions from module %s\n" % file) |
| 1098 | classes.write(" #\n\n") |
| 1099 | oldfile = file |
| 1100 | classes.write(" def %s(self" % func) |
| 1101 | txt.write(" %s()\n" % func); |
| 1102 | n = 0 |
| 1103 | for arg in args: |
| 1104 | if n != index: |
| 1105 | classes.write(", %s" % arg[0]) |
| 1106 | n = n + 1 |
| 1107 | classes.write("):\n") |
| 1108 | writeDoc(name, args, ' ', classes); |
| 1109 | n = 0 |
| 1110 | for arg in args: |
| 1111 | if classes_type.has_key(arg[1]): |
| 1112 | if n != index: |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1113 | classes.write(" if %s is None: %s__o = None\n" % |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1114 | (arg[0], arg[0])) |
| 1115 | classes.write(" else: %s__o = %s%s\n" % |
| 1116 | (arg[0], arg[0], classes_type[arg[1]][0])) |
| 1117 | n = n + 1 |
| 1118 | if ret[0] != "void": |
| 1119 | classes.write(" ret = "); |
| 1120 | else: |
| 1121 | classes.write(" "); |
| 1122 | classes.write("libxml2mod.%s(" % name) |
| 1123 | n = 0 |
| 1124 | for arg in args: |
| 1125 | if n != 0: |
| 1126 | classes.write(", "); |
| 1127 | if n != index: |
| 1128 | classes.write("%s" % arg[0]) |
| 1129 | if classes_type.has_key(arg[1]): |
| 1130 | classes.write("__o"); |
| 1131 | else: |
| 1132 | classes.write("self"); |
| 1133 | if classes_type.has_key(arg[1]): |
| 1134 | classes.write(classes_type[arg[1]][0]) |
| 1135 | n = n + 1 |
| 1136 | classes.write(")\n"); |
| 1137 | if ret[0] != "void": |
| 1138 | if classes_type.has_key(ret[0]): |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1139 | # |
| 1140 | # Raise an exception |
| 1141 | # |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1142 | if functions_noexcept.has_key(name): |
| 1143 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1144 | " if ret is None:return None\n"); |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1145 | elif string.find(name, "URI") >= 0: |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1146 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1147 | " if ret is None:raise uriError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1148 | % (name)) |
| 1149 | elif string.find(name, "XPath") >= 0: |
| 1150 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1151 | " if ret is None:raise xpathError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1152 | % (name)) |
| 1153 | elif string.find(name, "Parse") >= 0: |
| 1154 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1155 | " if ret is None:raise parserError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1156 | % (name)) |
| 1157 | else: |
| 1158 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1159 | " if ret is None:raise treeError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1160 | % (name)) |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 1161 | |
| 1162 | # |
| 1163 | # generate the returned class wrapper for the object |
| 1164 | # |
| 1165 | classes.write(" __tmp = "); |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1166 | classes.write(classes_type[ret[0]][1] % ("ret")); |
| 1167 | classes.write("\n"); |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 1168 | |
| 1169 | # |
| 1170 | # Sometime one need to keep references of the source |
| 1171 | # class in the returned class object. |
| 1172 | # See reference_keepers for the list |
| 1173 | # |
| 1174 | tclass = classes_type[ret[0]][2] |
| 1175 | if reference_keepers.has_key(tclass): |
| 1176 | list = reference_keepers[tclass] |
| 1177 | for pref in list: |
Daniel Veillard | febcca4 | 2003-02-16 15:44:18 +0000 | [diff] [blame] | 1178 | if pref[0] == classname: |
Daniel Veillard | dc85f28 | 2002-12-31 11:18:37 +0000 | [diff] [blame] | 1179 | classes.write(" __tmp.%s = self\n" % |
| 1180 | pref[1]) |
| 1181 | # |
| 1182 | # return the class |
| 1183 | # |
| 1184 | classes.write(" return __tmp\n"); |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1185 | elif converter_type.has_key(ret[0]): |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1186 | # |
| 1187 | # Raise an exception |
| 1188 | # |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1189 | if functions_noexcept.has_key(name): |
| 1190 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1191 | " if ret is None:return None"); |
Daniel Veillard | ef6c46f | 2002-03-07 22:21:56 +0000 | [diff] [blame] | 1192 | elif string.find(name, "URI") >= 0: |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1193 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1194 | " if ret is None:raise uriError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1195 | % (name)) |
| 1196 | elif string.find(name, "XPath") >= 0: |
| 1197 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1198 | " if ret is None:raise xpathError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1199 | % (name)) |
| 1200 | elif string.find(name, "Parse") >= 0: |
| 1201 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1202 | " if ret is None:raise parserError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1203 | % (name)) |
| 1204 | else: |
| 1205 | classes.write( |
Daniel Veillard | 6f46f6c | 2002-08-01 12:22:24 +0000 | [diff] [blame] | 1206 | " if ret is None:raise treeError('%s() failed')\n" |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1207 | % (name)) |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1208 | classes.write(" return "); |
| 1209 | classes.write(converter_type[ret[0]] % ("ret")); |
| 1210 | classes.write("\n"); |
| 1211 | else: |
| 1212 | classes.write(" return ret\n"); |
| 1213 | classes.write("\n"); |
| 1214 | |
Daniel Veillard | 4f4a27f | 2004-01-14 23:50:34 +0000 | [diff] [blame] | 1215 | # |
| 1216 | # Generate enum constants |
| 1217 | # |
| 1218 | for type,enum in enums.items(): |
| 1219 | classes.write("# %s\n" % type) |
| 1220 | items = enum.items() |
| 1221 | items.sort(lambda i1,i2: cmp(long(i1[1]),long(i2[1]))) |
| 1222 | for name,value in items: |
| 1223 | classes.write("%s = %s\n" % (name,value)) |
| 1224 | classes.write("\n"); |
| 1225 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1226 | txt.close() |
| 1227 | classes.close() |
| 1228 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 1229 | buildStubs() |
| 1230 | buildWrappers() |