blob: 92c4c3cfd0c375a7f8a759b5459dfef7ed6adf14 [file] [log] [blame]
Daniel Veillard5e5c2d02002-02-09 18:03:01 +00001import libxml2mod
Daniel Veillard85bb5b02003-12-04 14:12:05 +00002import types
Daniel Veillardd2897fd2002-01-30 16:37:32 +00003
Daniel Veillard1971ee22002-01-31 20:29:19 +00004#
Daniel Veillard8d24cc12002-03-05 15:41:29 +00005# Errors raised by the wrappers when some tree handling failed.
6#
7class treeError:
8 def __init__(self, msg):
9 self.msg = msg
10 def __str__(self):
11 return self.msg
12
13class parserError:
14 def __init__(self, msg):
15 self.msg = msg
16 def __str__(self):
17 return self.msg
18
19class uriError:
20 def __init__(self, msg):
21 self.msg = msg
22 def __str__(self):
23 return self.msg
24
25class xpathError:
26 def __init__(self, msg):
27 self.msg = msg
28 def __str__(self):
29 return self.msg
30
Daniel Veillardc6d4a932002-09-12 15:00:57 +000031class ioWrapper:
32 def __init__(self, _obj):
33 self.__io = _obj
34 self._o = None
35
36 def io_close(self):
37 if self.__io == None:
William M. Brack1d75c8a2003-10-27 13:48:16 +000038 return(-1)
39 self.__io.close()
40 self.__io = None
41 return(0)
Daniel Veillardc6d4a932002-09-12 15:00:57 +000042
43 def io_flush(self):
44 if self.__io == None:
William M. Brack1d75c8a2003-10-27 13:48:16 +000045 return(-1)
46 self.__io.flush()
47 return(0)
Daniel Veillardc6d4a932002-09-12 15:00:57 +000048
49 def io_read(self, len = -1):
50 if self.__io == None:
William M. Brack1d75c8a2003-10-27 13:48:16 +000051 return(-1)
Daniel Veillardc6d4a932002-09-12 15:00:57 +000052 if len < 0:
William M. Brack1d75c8a2003-10-27 13:48:16 +000053 return(self.__io.read())
54 return(self.__io.read(len))
Daniel Veillardc6d4a932002-09-12 15:00:57 +000055
56 def io_write(self, str, len = -1):
57 if self.__io == None:
William M. Brack1d75c8a2003-10-27 13:48:16 +000058 return(-1)
Daniel Veillardc6d4a932002-09-12 15:00:57 +000059 if len < 0:
William M. Brack1d75c8a2003-10-27 13:48:16 +000060 return(self.__io.write(str))
61 return(self.__io.write(str, len))
Daniel Veillardc6d4a932002-09-12 15:00:57 +000062
63class ioReadWrapper(ioWrapper):
64 def __init__(self, _obj, enc = ""):
65 ioWrapper.__init__(self, _obj)
66 self._o = libxml2mod.xmlCreateInputBuffer(self, enc)
67
68 def __del__(self):
69 print "__del__"
70 self.io_close()
71 if self._o != None:
72 libxml2mod.xmlFreeParserInputBuffer(self._o)
73 self._o = None
74
75 def close(self):
76 self.io_close()
77 if self._o != None:
78 libxml2mod.xmlFreeParserInputBuffer(self._o)
79 self._o = None
80
81class ioWriteWrapper(ioWrapper):
82 def __init__(self, _obj, enc = ""):
Daniel Veillard85bb5b02003-12-04 14:12:05 +000083# print "ioWriteWrapper.__init__", _obj
84 if type(_obj) == type(''):
85 print "write io from a string"
86 self.o = None
87 elif type(_obj) == types.InstanceType:
88 print "write io from instance of %s" % (_obj.__class__)
89 ioWrapper.__init__(self, _obj)
90 self._o = libxml2mod.xmlCreateOutputBuffer(self, enc)
91 else:
92 file = libxml2mod.outputBufferGetPythonFile(_obj)
93 if file != None:
94 ioWrapper.__init__(self, file)
95 else:
96 ioWrapper.__init__(self, _obj)
97 self._o = _obj
Daniel Veillardc6d4a932002-09-12 15:00:57 +000098
99 def __del__(self):
Daniel Veillard85bb5b02003-12-04 14:12:05 +0000100# print "__del__"
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000101 self.io_close()
102 if self._o != None:
103 libxml2mod.xmlOutputBufferClose(self._o)
104 self._o = None
105
Daniel Veillard85bb5b02003-12-04 14:12:05 +0000106 def flush(self):
107 self.io_flush()
108 if self._o != None:
109 libxml2mod.xmlOutputBufferClose(self._o)
110 self._o = None
111
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000112 def close(self):
Daniel Veillard85bb5b02003-12-04 14:12:05 +0000113 self.io_flush()
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000114 if self._o != None:
115 libxml2mod.xmlOutputBufferClose(self._o)
116 self._o = None
117
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000118#
119# Example of a class to handle SAX events
120#
121class SAXCallback:
122 """Base class for SAX handlers"""
123 def startDocument(self):
124 """called at the start of the document"""
125 pass
126
127 def endDocument(self):
128 """called at the end of the document"""
129 pass
130
131 def startElement(self, tag, attrs):
132 """called at the start of every element, tag is the name of
William M. Brack1d75c8a2003-10-27 13:48:16 +0000133 the element, attrs is a dictionary of the element's attributes"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000134 pass
135
136 def endElement(self, tag):
137 """called at the start of every element, tag is the name of
William M. Brack1d75c8a2003-10-27 13:48:16 +0000138 the element"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000139 pass
140
141 def characters(self, data):
142 """called when character data have been read, data is the string
William M. Brack1d75c8a2003-10-27 13:48:16 +0000143 containing the data, multiple consecutive characters() callback
144 are possible."""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000145 pass
146
147 def cdataBlock(self, data):
148 """called when CDATA section have been read, data is the string
William M. Brack1d75c8a2003-10-27 13:48:16 +0000149 containing the data, multiple consecutive cdataBlock() callback
150 are possible."""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000151 pass
152
153 def reference(self, name):
154 """called when an entity reference has been found"""
155 pass
156
157 def ignorableWhitespace(self, data):
158 """called when potentially ignorable white spaces have been found"""
159 pass
160
161 def processingInstruction(self, target, data):
162 """called when a PI has been found, target contains the PI name and
William M. Brack1d75c8a2003-10-27 13:48:16 +0000163 data is the associated data in the PI"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000164 pass
165
166 def comment(self, content):
167 """called when a comment has been found, content contains the comment"""
168 pass
169
170 def externalSubset(self, name, externalID, systemID):
171 """called when a DOCTYPE declaration has been found, name is the
William M. Brack1d75c8a2003-10-27 13:48:16 +0000172 DTD name and externalID, systemID are the DTD public and system
173 identifier for that DTd if available"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000174 pass
175
176 def internalSubset(self, name, externalID, systemID):
177 """called when a DOCTYPE declaration has been found, name is the
William M. Brack1d75c8a2003-10-27 13:48:16 +0000178 DTD name and externalID, systemID are the DTD public and system
179 identifier for that DTD if available"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000180 pass
181
182 def entityDecl(self, name, type, externalID, systemID, content):
183 """called when an ENTITY declaration has been found, name is the
William M. Brack1d75c8a2003-10-27 13:48:16 +0000184 entity name and externalID, systemID are the entity public and
185 system identifier for that entity if available, type indicates
186 the entity type, and content reports it's string content"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000187 pass
188
189 def notationDecl(self, name, externalID, systemID):
190 """called when an NOTATION declaration has been found, name is the
William M. Brack1d75c8a2003-10-27 13:48:16 +0000191 notation name and externalID, systemID are the notation public and
192 system identifier for that notation if available"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000193 pass
194
195 def attributeDecl(self, elem, name, type, defi, defaultValue, nameList):
196 """called when an ATTRIBUTE definition has been found"""
William M. Brack1d75c8a2003-10-27 13:48:16 +0000197 pass
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000198
199 def elementDecl(self, name, type, content):
200 """called when an ELEMENT definition has been found"""
William M. Brack1d75c8a2003-10-27 13:48:16 +0000201 pass
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000202
203 def entityDecl(self, name, publicId, systemID, notationName):
204 """called when an unparsed ENTITY declaration has been found,
William M. Brack1d75c8a2003-10-27 13:48:16 +0000205 name is the entity name and publicId,, systemID are the entity
206 public and system identifier for that entity if available,
207 and notationName indicate the associated NOTATION"""
Daniel Veillard8d24cc12002-03-05 15:41:29 +0000208 pass
209
210 def warning(self, msg):
211 print msg
212
213 def error(self, msg):
214 raise parserError(msg)
215
216 def fatalError(self, msg):
217 raise parserError(msg)
218
219#
Daniel Veillard1971ee22002-01-31 20:29:19 +0000220# This class is the ancestor of all the Node classes. It provides
221# the basic functionalities shared by all nodes (and handle
222# gracefylly the exception), like name, navigation in the tree,
Daniel Veillard1e774382002-03-06 17:35:40 +0000223# doc reference, content access and serializing to a string or URI
Daniel Veillard1971ee22002-01-31 20:29:19 +0000224#
Daniel Veillard36ed5292002-01-30 23:49:06 +0000225class xmlCore:
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000226 def __init__(self, _obj=None):
227 if _obj != None:
Daniel Veillard01a6d412002-02-11 18:42:20 +0000228 self._o = _obj;
229 return
230 self._o = None
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000231 def get_parent(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000232 ret = libxml2mod.parent(self._o)
233 if ret == None:
234 return None
235 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000236 def get_children(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000237 ret = libxml2mod.children(self._o)
238 if ret == None:
239 return None
240 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000241 def get_last(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000242 ret = libxml2mod.last(self._o)
243 if ret == None:
244 return None
245 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000246 def get_next(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000247 ret = libxml2mod.next(self._o)
248 if ret == None:
249 return None
250 return xmlNode(_obj=ret)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000251 def get_properties(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000252 ret = libxml2mod.properties(self._o)
253 if ret == None:
254 return None
255 return xmlAttr(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000256 def get_prev(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000257 ret = libxml2mod.prev(self._o)
258 if ret == None:
259 return None
260 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000261 def get_content(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000262 return libxml2mod.xmlNodeGetContent(self._o)
Daniel Veillard51a447a2003-01-04 19:42:46 +0000263 getContent = get_content # why is this duplicate naming needed ?
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000264 def get_name(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000265 return libxml2mod.name(self._o)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000266 def get_type(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000267 return libxml2mod.type(self._o)
Daniel Veillard51a447a2003-01-04 19:42:46 +0000268 def get_doc(self):
269 ret = libxml2mod.doc(self._o)
270 if ret == None:
271 if self.type in ["document_xml", "document_html"]:
272 return xmlDoc(_obj=self._o)
273 else:
274 return None
275 return xmlDoc(_obj=ret)
276 #
277 # Those are common attributes to nearly all type of nodes
278 # defined as python2 properties
279 #
280 import sys
281 if float(sys.version[0:3]) < 2.2:
William M. Brack1d75c8a2003-10-27 13:48:16 +0000282 def __getattr__(self, attr):
283 if attr == "parent":
284 ret = libxml2mod.parent(self._o)
285 if ret == None:
286 return None
287 return xmlNode(_obj=ret)
288 elif attr == "properties":
289 ret = libxml2mod.properties(self._o)
290 if ret == None:
291 return None
292 return xmlAttr(_obj=ret)
293 elif attr == "children":
294 ret = libxml2mod.children(self._o)
295 if ret == None:
296 return None
297 return xmlNode(_obj=ret)
298 elif attr == "last":
299 ret = libxml2mod.last(self._o)
300 if ret == None:
301 return None
302 return xmlNode(_obj=ret)
303 elif attr == "next":
304 ret = libxml2mod.next(self._o)
305 if ret == None:
306 return None
307 return xmlNode(_obj=ret)
308 elif attr == "prev":
309 ret = libxml2mod.prev(self._o)
310 if ret == None:
311 return None
312 return xmlNode(_obj=ret)
313 elif attr == "content":
314 return libxml2mod.xmlNodeGetContent(self._o)
315 elif attr == "name":
316 return libxml2mod.name(self._o)
317 elif attr == "type":
318 return libxml2mod.type(self._o)
319 elif attr == "doc":
320 ret = libxml2mod.doc(self._o)
321 if ret == None:
322 if self.type == "document_xml" or self.type == "document_html":
323 return xmlDoc(_obj=self._o)
324 else:
325 return None
326 return xmlDoc(_obj=ret)
327 raise AttributeError,attr
Daniel Veillard51a447a2003-01-04 19:42:46 +0000328 else:
William M. Brack1d75c8a2003-10-27 13:48:16 +0000329 parent = property(get_parent, None, None, "Parent node")
330 children = property(get_children, None, None, "First child node")
331 last = property(get_last, None, None, "Last sibling node")
332 next = property(get_next, None, None, "Next sibling node")
333 prev = property(get_prev, None, None, "Previous sibling node")
334 properties = property(get_properties, None, None, "List of properies")
335 content = property(get_content, None, None, "Content of this node")
336 name = property(get_name, None, None, "Node name")
337 type = property(get_type, None, None, "Node type")
338 doc = property(get_doc, None, None, "The document this node belongs to")
Daniel Veillard1e774382002-03-06 17:35:40 +0000339
340 #
341 # Serialization routines, the optional arguments have the following
342 # meaning:
343 # encoding: string to ask saving in a specific encoding
Daniel Veillard51a447a2003-01-04 19:42:46 +0000344 # indent: if 1 the serializer is asked to indent the output
Daniel Veillard1e774382002-03-06 17:35:40 +0000345 #
346 def serialize(self, encoding = None, format = 0):
347 return libxml2mod.serializeNode(self._o, encoding, format)
348 def saveTo(self, file, encoding = None, format = 0):
349 return libxml2mod.saveNodeTo(self._o, file, encoding, format)
Daniel Veillard01a6d412002-02-11 18:42:20 +0000350
Daniel Veillardf742d342002-03-07 00:05:35 +0000351 #
352 # Selecting nodes using XPath, a bit slow because the context
353 # is allocated/freed every time but convenient.
354 #
355 def xpathEval(self, expr):
William M. Brack1d75c8a2003-10-27 13:48:16 +0000356 doc = self.doc
357 if doc == None:
358 return None
359 ctxt = doc.xpathNewContext()
360 ctxt.setContextNode(self)
361 res = ctxt.xpathEval(expr)
362 ctxt.xpathFreeContext()
363 return res
Daniel Veillard51a447a2003-01-04 19:42:46 +0000364
Daniel Veillardf88d8cf2003-12-08 10:25:02 +0000365# #
366# # Selecting nodes using XPath, faster because the context
367# # is allocated just once per xmlDoc.
368# #
369# # Removed: DV memleaks c.f. #126735
370# #
371# def xpathEval2(self, expr):
372# doc = self.doc
373# if doc == None:
374# return None
375# try:
376# doc._ctxt.setContextNode(self)
377# except:
378# doc._ctxt = doc.xpathNewContext()
379# doc._ctxt.setContextNode(self)
380# res = doc._ctxt.xpathEval(expr)
381# return res
Daniel Veillard51a447a2003-01-04 19:42:46 +0000382 def xpathEval2(self, expr):
Daniel Veillardf88d8cf2003-12-08 10:25:02 +0000383 return self.xpathEval(expr)
Daniel Veillard51a447a2003-01-04 19:42:46 +0000384
385 # support for python2 iterators
386 def walk_depth_first(self):
387 return xmlCoreDepthFirstItertor(self)
388 def walk_breadth_first(self):
389 return xmlCoreBreadthFirstItertor(self)
390 __iter__ = walk_depth_first
391
392 def free(self):
393 try:
394 self.doc._ctxt.xpathFreeContext()
395 except:
396 pass
Daniel Veillardf88d8cf2003-12-08 10:25:02 +0000397 libxml2mod.xmlFreeDoc(self._o)
Daniel Veillard51a447a2003-01-04 19:42:46 +0000398
399
400#
401# implements the depth-first iterator for libxml2 DOM tree
402#
403class xmlCoreDepthFirstItertor:
404 def __init__(self, node):
405 self.node = node
406 self.parents = []
407 def __iter__(self):
408 return self
409 def next(self):
410 while 1:
411 if self.node:
412 ret = self.node
413 self.parents.append(self.node)
414 self.node = self.node.children
415 return ret
416 try:
417 parent = self.parents.pop()
418 except IndexError:
419 raise StopIteration
420 self.node = parent.next
421
422#
423# implements the breadth-first iterator for libxml2 DOM tree
424#
425class xmlCoreBreadthFirstItertor:
426 def __init__(self, node):
427 self.node = node
428 self.parents = []
429 def __iter__(self):
430 return self
431 def next(self):
432 while 1:
433 if self.node:
434 ret = self.node
435 self.parents.append(self.node)
436 self.node = self.node.next
437 return ret
438 try:
439 parent = self.parents.pop()
440 except IndexError:
441 raise StopIteration
442 self.node = parent.children
443
Daniel Veillard36ed5292002-01-30 23:49:06 +0000444#
Daniel Veillard1971ee22002-01-31 20:29:19 +0000445# converters to present a nicer view of the XPath returns
446#
447def nodeWrap(o):
448 # TODO try to cast to the most appropriate node class
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000449 name = libxml2mod.name(o)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000450 if name == "element" or name == "text":
451 return xmlNode(_obj=o)
452 if name == "attribute":
453 return xmlAttr(_obj=o)
454 if name[0:8] == "document":
455 return xmlDoc(_obj=o)
456 if name[0:8] == "namespace":
457 return xmlNs(_obj=o)
458 if name == "elem_decl":
459 return xmlElement(_obj=o)
460 if name == "attribute_decl":
461 return xmlAtribute(_obj=o)
462 if name == "entity_decl":
463 return xmlEntity(_obj=o)
464 if name == "dtd":
Daniel Veillarde59494f2003-01-04 16:35:29 +0000465 return xmlDtd(_obj=o)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000466 return xmlNode(_obj=o)
467
468def xpathObjectRet(o):
469 if type(o) == type([]) or type(o) == type(()):
470 ret = map(lambda x: nodeWrap(x), o)
Daniel Veillard01a6d412002-02-11 18:42:20 +0000471 return ret
Daniel Veillard1971ee22002-01-31 20:29:19 +0000472 return o
473
474#
Daniel Veillarda7340c82002-02-01 17:56:45 +0000475# register an XPath function
476#
477def registerXPathFunction(ctxt, name, ns_uri, f):
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000478 ret = libxml2mod.xmlRegisterXPathFunction(ctxt, name, ns_uri, f)
Daniel Veillarda7340c82002-02-01 17:56:45 +0000479
480#
Daniel Veillardf25b4ca2002-12-27 15:18:35 +0000481# For the xmlTextReader parser configuration
482#
483PARSER_LOADDTD=1
484PARSER_DEFAULTATTRS=2
485PARSER_VALIDATE=3
Daniel Veillarde18fc182002-12-28 22:56:33 +0000486PARSER_SUBST_ENTITIES=4
Daniel Veillardf25b4ca2002-12-27 15:18:35 +0000487
488#
Daniel Veillard417be3a2003-01-20 21:26:34 +0000489# For the error callback severities
Daniel Veillard26f70262003-01-16 22:45:08 +0000490#
Daniel Veillard417be3a2003-01-20 21:26:34 +0000491PARSER_SEVERITY_VALIDITY_WARNING=1
492PARSER_SEVERITY_VALIDITY_ERROR=2
493PARSER_SEVERITY_WARNING=3
494PARSER_SEVERITY_ERROR=4
Daniel Veillard26f70262003-01-16 22:45:08 +0000495
496#
Daniel Veillard3e20a292003-01-10 13:14:40 +0000497# register the libxml2 error handler
Daniel Veillard36ed5292002-01-30 23:49:06 +0000498#
Daniel Veillard3e20a292003-01-10 13:14:40 +0000499def registerErrorHandler(f, ctx):
500 """Register a Python written function to for error reporting.
501 The function is called back as f(ctx, error). """
502 import sys
503 if not sys.modules.has_key('libxslt'):
504 # normal behaviour when libxslt is not imported
505 ret = libxml2mod.xmlRegisterErrorHandler(f,ctx)
506 else:
507 # when libxslt is already imported, one must
508 # use libxst's error handler instead
509 import libxslt
510 ret = libxslt.registerErrorHandler(f,ctx)
511 return ret
512
Daniel Veillarde6227e02003-01-14 11:42:39 +0000513class parserCtxtCore:
514
515 def __init__(self, _obj=None):
516 if _obj != None:
517 self._o = _obj;
518 return
519 self._o = None
520
521 def __del__(self):
522 if self._o != None:
523 libxml2mod.xmlFreeParserCtxt(self._o)
William M. Brack1d75c8a2003-10-27 13:48:16 +0000524 self._o = None
Daniel Veillarde6227e02003-01-14 11:42:39 +0000525
Daniel Veillard417be3a2003-01-20 21:26:34 +0000526 def setErrorHandler(self,f,arg):
527 """Register an error handler that will be called back as
528 f(arg,msg,severity,reserved).
529
530 @reserved is currently always None."""
531 libxml2mod.xmlParserCtxtSetErrorHandler(self._o,f,arg)
Daniel Veillarde6227e02003-01-14 11:42:39 +0000532
Daniel Veillard417be3a2003-01-20 21:26:34 +0000533 def getErrorHandler(self):
534 """Return (f,arg) as previously registered with setErrorHandler
535 or (None,None)."""
536 return libxml2mod.xmlParserCtxtGetErrorHandler(self._o)
537
Daniel Veillard54396242003-04-23 07:36:50 +0000538 def addLocalCatalog(self, uri):
539 """Register a local catalog with the parser"""
540 return libxml2mod.addLocalCatalog(self._o, uri)
541
542
Daniel Veillard417be3a2003-01-20 21:26:34 +0000543def _xmlTextReaderErrorFunc((f,arg),msg,severity,locator):
544 """Intermediate callback to wrap the locator"""
545 return f(arg,msg,severity,xmlTextReaderLocator(locator))
Daniel Veillarde6227e02003-01-14 11:42:39 +0000546
Daniel Veillard26f70262003-01-16 22:45:08 +0000547class xmlTextReaderCore:
548
549 def __init__(self, _obj=None):
550 self.input = None
551 if _obj != None:self._o = _obj;return
552 self._o = None
553
554 def __del__(self):
555 if self._o != None:
556 libxml2mod.xmlFreeTextReader(self._o)
557 self._o = None
558
Daniel Veillard417be3a2003-01-20 21:26:34 +0000559 def SetErrorHandler(self,f,arg):
Daniel Veillard26f70262003-01-16 22:45:08 +0000560 """Register an error handler that will be called back as
Daniel Veillard417be3a2003-01-20 21:26:34 +0000561 f(arg,msg,severity,locator)."""
562 if f is None:
563 libxml2mod.xmlTextReaderSetErrorHandler(\
564 self._o,None,None)
565 else:
566 libxml2mod.xmlTextReaderSetErrorHandler(\
567 self._o,_xmlTextReaderErrorFunc,(f,arg))
Daniel Veillard26f70262003-01-16 22:45:08 +0000568
Daniel Veillard417be3a2003-01-20 21:26:34 +0000569 def GetErrorHandler(self):
Daniel Veillard26f70262003-01-16 22:45:08 +0000570 """Return (f,arg) as previously registered with setErrorHandler
571 or (None,None)."""
Daniel Veillard417be3a2003-01-20 21:26:34 +0000572 f,arg = libxml2mod.xmlTextReaderGetErrorHandler(self._o)
573 if f is None:
574 return None,None
575 else:
576 # assert f is _xmlTextReaderErrorFunc
577 return arg
Daniel Veillard26f70262003-01-16 22:45:08 +0000578
Daniel Veillard3e20a292003-01-10 13:14:40 +0000579# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
580#
581# Everything before this line comes from libxml.py
582# Everything after this line is automatically generated
583#
584# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
Daniel Veillard1971ee22002-01-31 20:29:19 +0000585