libxml.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. import libxml2mod
  2. import types
  3. import sys
  4. # The root of all libxml2 errors.
  5. class libxmlError(Exception): pass
  6. #
  7. # id() is sometimes negative ...
  8. #
  9. def pos_id(o):
  10. i = id(o)
  11. if (i < 0):
  12. return (sys.maxint - i)
  13. return i
  14. #
  15. # Errors raised by the wrappers when some tree handling failed.
  16. #
  17. class treeError(libxmlError):
  18. def __init__(self, msg):
  19. self.msg = msg
  20. def __str__(self):
  21. return self.msg
  22. class parserError(libxmlError):
  23. def __init__(self, msg):
  24. self.msg = msg
  25. def __str__(self):
  26. return self.msg
  27. class uriError(libxmlError):
  28. def __init__(self, msg):
  29. self.msg = msg
  30. def __str__(self):
  31. return self.msg
  32. class xpathError(libxmlError):
  33. def __init__(self, msg):
  34. self.msg = msg
  35. def __str__(self):
  36. return self.msg
  37. class ioWrapper:
  38. def __init__(self, _obj):
  39. self.__io = _obj
  40. self._o = None
  41. def io_close(self):
  42. if self.__io == None:
  43. return(-1)
  44. self.__io.close()
  45. self.__io = None
  46. return(0)
  47. def io_flush(self):
  48. if self.__io == None:
  49. return(-1)
  50. self.__io.flush()
  51. return(0)
  52. def io_read(self, len = -1):
  53. if self.__io == None:
  54. return(-1)
  55. if len < 0:
  56. return(self.__io.read())
  57. return(self.__io.read(len))
  58. def io_write(self, str, len = -1):
  59. if self.__io == None:
  60. return(-1)
  61. if len < 0:
  62. return(self.__io.write(str))
  63. return(self.__io.write(str, len))
  64. class ioReadWrapper(ioWrapper):
  65. def __init__(self, _obj, enc = ""):
  66. ioWrapper.__init__(self, _obj)
  67. self._o = libxml2mod.xmlCreateInputBuffer(self, enc)
  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. def close(self):
  75. self.io_close()
  76. if self._o != None:
  77. libxml2mod.xmlFreeParserInputBuffer(self._o)
  78. self._o = None
  79. class ioWriteWrapper(ioWrapper):
  80. def __init__(self, _obj, enc = ""):
  81. # print "ioWriteWrapper.__init__", _obj
  82. if type(_obj) == type(''):
  83. print "write io from a string"
  84. self.o = None
  85. elif type(_obj) == types.InstanceType:
  86. print "write io from instance of %s" % (_obj.__class__)
  87. ioWrapper.__init__(self, _obj)
  88. self._o = libxml2mod.xmlCreateOutputBuffer(self, enc)
  89. else:
  90. file = libxml2mod.outputBufferGetPythonFile(_obj)
  91. if file != None:
  92. ioWrapper.__init__(self, file)
  93. else:
  94. ioWrapper.__init__(self, _obj)
  95. self._o = _obj
  96. def __del__(self):
  97. # print "__del__"
  98. self.io_close()
  99. if self._o != None:
  100. libxml2mod.xmlOutputBufferClose(self._o)
  101. self._o = None
  102. def flush(self):
  103. self.io_flush()
  104. if self._o != None:
  105. libxml2mod.xmlOutputBufferClose(self._o)
  106. self._o = None
  107. def close(self):
  108. self.io_flush()
  109. if self._o != None:
  110. libxml2mod.xmlOutputBufferClose(self._o)
  111. self._o = None
  112. #
  113. # Example of a class to handle SAX events
  114. #
  115. class SAXCallback:
  116. """Base class for SAX handlers"""
  117. def startDocument(self):
  118. """called at the start of the document"""
  119. pass
  120. def endDocument(self):
  121. """called at the end of the document"""
  122. pass
  123. def startElement(self, tag, attrs):
  124. """called at the start of every element, tag is the name of
  125. the element, attrs is a dictionary of the element's attributes"""
  126. pass
  127. def endElement(self, tag):
  128. """called at the start of every element, tag is the name of
  129. the element"""
  130. pass
  131. def characters(self, data):
  132. """called when character data have been read, data is the string
  133. containing the data, multiple consecutive characters() callback
  134. are possible."""
  135. pass
  136. def cdataBlock(self, data):
  137. """called when CDATA section have been read, data is the string
  138. containing the data, multiple consecutive cdataBlock() callback
  139. are possible."""
  140. pass
  141. def reference(self, name):
  142. """called when an entity reference has been found"""
  143. pass
  144. def ignorableWhitespace(self, data):
  145. """called when potentially ignorable white spaces have been found"""
  146. pass
  147. def processingInstruction(self, target, data):
  148. """called when a PI has been found, target contains the PI name and
  149. data is the associated data in the PI"""
  150. pass
  151. def comment(self, content):
  152. """called when a comment has been found, content contains the comment"""
  153. pass
  154. def externalSubset(self, name, externalID, systemID):
  155. """called when a DOCTYPE declaration has been found, name is the
  156. DTD name and externalID, systemID are the DTD public and system
  157. identifier for that DTd if available"""
  158. pass
  159. def internalSubset(self, name, externalID, systemID):
  160. """called when a DOCTYPE declaration has been found, name is the
  161. DTD name and externalID, systemID are the DTD public and system
  162. identifier for that DTD if available"""
  163. pass
  164. def entityDecl(self, name, type, externalID, systemID, content):
  165. """called when an ENTITY declaration has been found, name is the
  166. entity name and externalID, systemID are the entity public and
  167. system identifier for that entity if available, type indicates
  168. the entity type, and content reports it's string content"""
  169. pass
  170. def notationDecl(self, name, externalID, systemID):
  171. """called when an NOTATION declaration has been found, name is the
  172. notation name and externalID, systemID are the notation public and
  173. system identifier for that notation if available"""
  174. pass
  175. def attributeDecl(self, elem, name, type, defi, defaultValue, nameList):
  176. """called when an ATTRIBUTE definition has been found"""
  177. pass
  178. def elementDecl(self, name, type, content):
  179. """called when an ELEMENT definition has been found"""
  180. pass
  181. def entityDecl(self, name, publicId, systemID, notationName):
  182. """called when an unparsed ENTITY declaration has been found,
  183. name is the entity name and publicId,, systemID are the entity
  184. public and system identifier for that entity if available,
  185. and notationName indicate the associated NOTATION"""
  186. pass
  187. def warning(self, msg):
  188. #print msg
  189. pass
  190. def error(self, msg):
  191. raise parserError(msg)
  192. def fatalError(self, msg):
  193. raise parserError(msg)
  194. #
  195. # This class is the ancestor of all the Node classes. It provides
  196. # the basic functionalities shared by all nodes (and handle
  197. # gracefylly the exception), like name, navigation in the tree,
  198. # doc reference, content access and serializing to a string or URI
  199. #
  200. class xmlCore:
  201. def __init__(self, _obj=None):
  202. if _obj != None:
  203. self._o = _obj;
  204. return
  205. self._o = None
  206. def __eq__(self, other):
  207. if other == None:
  208. return False
  209. ret = libxml2mod.compareNodesEqual(self._o, other._o)
  210. if ret == None:
  211. return False
  212. return ret == True
  213. def __ne__(self, other):
  214. if other == None:
  215. return True
  216. ret = libxml2mod.compareNodesEqual(self._o, other._o)
  217. return not ret
  218. def __hash__(self):
  219. ret = libxml2mod.nodeHash(self._o)
  220. return ret
  221. def __str__(self):
  222. return self.serialize()
  223. def get_parent(self):
  224. ret = libxml2mod.parent(self._o)
  225. if ret == None:
  226. return None
  227. return xmlNode(_obj=ret)
  228. def get_children(self):
  229. ret = libxml2mod.children(self._o)
  230. if ret == None:
  231. return None
  232. return xmlNode(_obj=ret)
  233. def get_last(self):
  234. ret = libxml2mod.last(self._o)
  235. if ret == None:
  236. return None
  237. return xmlNode(_obj=ret)
  238. def get_next(self):
  239. ret = libxml2mod.next(self._o)
  240. if ret == None:
  241. return None
  242. return xmlNode(_obj=ret)
  243. def get_properties(self):
  244. ret = libxml2mod.properties(self._o)
  245. if ret == None:
  246. return None
  247. return xmlAttr(_obj=ret)
  248. def get_prev(self):
  249. ret = libxml2mod.prev(self._o)
  250. if ret == None:
  251. return None
  252. return xmlNode(_obj=ret)
  253. def get_content(self):
  254. return libxml2mod.xmlNodeGetContent(self._o)
  255. getContent = get_content # why is this duplicate naming needed ?
  256. def get_name(self):
  257. return libxml2mod.name(self._o)
  258. def get_type(self):
  259. return libxml2mod.type(self._o)
  260. def get_doc(self):
  261. ret = libxml2mod.doc(self._o)
  262. if ret == None:
  263. if self.type in ["document_xml", "document_html"]:
  264. return xmlDoc(_obj=self._o)
  265. else:
  266. return None
  267. return xmlDoc(_obj=ret)
  268. #
  269. # Those are common attributes to nearly all type of nodes
  270. # defined as python2 properties
  271. #
  272. import sys
  273. if float(sys.version[0:3]) < 2.2:
  274. def __getattr__(self, attr):
  275. if attr == "parent":
  276. ret = libxml2mod.parent(self._o)
  277. if ret == None:
  278. return None
  279. return xmlNode(_obj=ret)
  280. elif attr == "properties":
  281. ret = libxml2mod.properties(self._o)
  282. if ret == None:
  283. return None
  284. return xmlAttr(_obj=ret)
  285. elif attr == "children":
  286. ret = libxml2mod.children(self._o)
  287. if ret == None:
  288. return None
  289. return xmlNode(_obj=ret)
  290. elif attr == "last":
  291. ret = libxml2mod.last(self._o)
  292. if ret == None:
  293. return None
  294. return xmlNode(_obj=ret)
  295. elif attr == "next":
  296. ret = libxml2mod.next(self._o)
  297. if ret == None:
  298. return None
  299. return xmlNode(_obj=ret)
  300. elif attr == "prev":
  301. ret = libxml2mod.prev(self._o)
  302. if ret == None:
  303. return None
  304. return xmlNode(_obj=ret)
  305. elif attr == "content":
  306. return libxml2mod.xmlNodeGetContent(self._o)
  307. elif attr == "name":
  308. return libxml2mod.name(self._o)
  309. elif attr == "type":
  310. return libxml2mod.type(self._o)
  311. elif attr == "doc":
  312. ret = libxml2mod.doc(self._o)
  313. if ret == None:
  314. if self.type == "document_xml" or self.type == "document_html":
  315. return xmlDoc(_obj=self._o)
  316. else:
  317. return None
  318. return xmlDoc(_obj=ret)
  319. raise AttributeError,attr
  320. else:
  321. parent = property(get_parent, None, None, "Parent node")
  322. children = property(get_children, None, None, "First child node")
  323. last = property(get_last, None, None, "Last sibling node")
  324. next = property(get_next, None, None, "Next sibling node")
  325. prev = property(get_prev, None, None, "Previous sibling node")
  326. properties = property(get_properties, None, None, "List of properies")
  327. content = property(get_content, None, None, "Content of this node")
  328. name = property(get_name, None, None, "Node name")
  329. type = property(get_type, None, None, "Node type")
  330. doc = property(get_doc, None, None, "The document this node belongs to")
  331. #
  332. # Serialization routines, the optional arguments have the following
  333. # meaning:
  334. # encoding: string to ask saving in a specific encoding
  335. # indent: if 1 the serializer is asked to indent the output
  336. #
  337. def serialize(self, encoding = None, format = 0):
  338. return libxml2mod.serializeNode(self._o, encoding, format)
  339. def saveTo(self, file, encoding = None, format = 0):
  340. return libxml2mod.saveNodeTo(self._o, file, encoding, format)
  341. #
  342. # Canonicalization routines:
  343. #
  344. # nodes: the node set (tuple or list) to be included in the
  345. # canonized image or None if all document nodes should be
  346. # included.
  347. # exclusive: the exclusive flag (0 - non-exclusive
  348. # canonicalization; otherwise - exclusive canonicalization)
  349. # prefixes: the list of inclusive namespace prefixes (strings),
  350. # or None if there is no inclusive namespaces (only for
  351. # exclusive canonicalization, ignored otherwise)
  352. # with_comments: include comments in the result (!=0) or not
  353. # (==0)
  354. def c14nMemory(self,
  355. nodes=None,
  356. exclusive=0,
  357. prefixes=None,
  358. with_comments=0):
  359. if nodes:
  360. nodes = map(lambda n: n._o, nodes)
  361. return libxml2mod.xmlC14NDocDumpMemory(
  362. self.get_doc()._o,
  363. nodes,
  364. exclusive != 0,
  365. prefixes,
  366. with_comments != 0)
  367. def c14nSaveTo(self,
  368. file,
  369. nodes=None,
  370. exclusive=0,
  371. prefixes=None,
  372. with_comments=0):
  373. if nodes:
  374. nodes = map(lambda n: n._o, nodes)
  375. return libxml2mod.xmlC14NDocSaveTo(
  376. self.get_doc()._o,
  377. nodes,
  378. exclusive != 0,
  379. prefixes,
  380. with_comments != 0,
  381. file)
  382. #
  383. # Selecting nodes using XPath, a bit slow because the context
  384. # is allocated/freed every time but convenient.
  385. #
  386. def xpathEval(self, expr):
  387. doc = self.doc
  388. if doc == None:
  389. return None
  390. ctxt = doc.xpathNewContext()
  391. ctxt.setContextNode(self)
  392. res = ctxt.xpathEval(expr)
  393. ctxt.xpathFreeContext()
  394. return res
  395. # #
  396. # # Selecting nodes using XPath, faster because the context
  397. # # is allocated just once per xmlDoc.
  398. # #
  399. # # Removed: DV memleaks c.f. #126735
  400. # #
  401. # def xpathEval2(self, expr):
  402. # doc = self.doc
  403. # if doc == None:
  404. # return None
  405. # try:
  406. # doc._ctxt.setContextNode(self)
  407. # except:
  408. # doc._ctxt = doc.xpathNewContext()
  409. # doc._ctxt.setContextNode(self)
  410. # res = doc._ctxt.xpathEval(expr)
  411. # return res
  412. def xpathEval2(self, expr):
  413. return self.xpathEval(expr)
  414. # Remove namespaces
  415. def removeNsDef(self, href):
  416. """
  417. Remove a namespace definition from a node. If href is None,
  418. remove all of the ns definitions on that node. The removed
  419. namespaces are returned as a linked list.
  420. Note: If any child nodes referred to the removed namespaces,
  421. they will be left with dangling links. You should call
  422. renconciliateNs() to fix those pointers.
  423. Note: This method does not free memory taken by the ns
  424. definitions. You will need to free it manually with the
  425. freeNsList() method on the returns xmlNs object.
  426. """
  427. ret = libxml2mod.xmlNodeRemoveNsDef(self._o, href)
  428. if ret is None:return None
  429. __tmp = xmlNs(_obj=ret)
  430. return __tmp
  431. # support for python2 iterators
  432. def walk_depth_first(self):
  433. return xmlCoreDepthFirstItertor(self)
  434. def walk_breadth_first(self):
  435. return xmlCoreBreadthFirstItertor(self)
  436. __iter__ = walk_depth_first
  437. def free(self):
  438. try:
  439. self.doc._ctxt.xpathFreeContext()
  440. except:
  441. pass
  442. libxml2mod.xmlFreeDoc(self._o)
  443. #
  444. # implements the depth-first iterator for libxml2 DOM tree
  445. #
  446. class xmlCoreDepthFirstItertor:
  447. def __init__(self, node):
  448. self.node = node
  449. self.parents = []
  450. def __iter__(self):
  451. return self
  452. def next(self):
  453. while 1:
  454. if self.node:
  455. ret = self.node
  456. self.parents.append(self.node)
  457. self.node = self.node.children
  458. return ret
  459. try:
  460. parent = self.parents.pop()
  461. except IndexError:
  462. raise StopIteration
  463. self.node = parent.next
  464. #
  465. # implements the breadth-first iterator for libxml2 DOM tree
  466. #
  467. class xmlCoreBreadthFirstItertor:
  468. def __init__(self, node):
  469. self.node = node
  470. self.parents = []
  471. def __iter__(self):
  472. return self
  473. def next(self):
  474. while 1:
  475. if self.node:
  476. ret = self.node
  477. self.parents.append(self.node)
  478. self.node = self.node.next
  479. return ret
  480. try:
  481. parent = self.parents.pop()
  482. except IndexError:
  483. raise StopIteration
  484. self.node = parent.children
  485. #
  486. # converters to present a nicer view of the XPath returns
  487. #
  488. def nodeWrap(o):
  489. # TODO try to cast to the most appropriate node class
  490. name = libxml2mod.type(o)
  491. if name == "element" or name == "text":
  492. return xmlNode(_obj=o)
  493. if name == "attribute":
  494. return xmlAttr(_obj=o)
  495. if name[0:8] == "document":
  496. return xmlDoc(_obj=o)
  497. if name == "namespace":
  498. return xmlNs(_obj=o)
  499. if name == "elem_decl":
  500. return xmlElement(_obj=o)
  501. if name == "attribute_decl":
  502. return xmlAttribute(_obj=o)
  503. if name == "entity_decl":
  504. return xmlEntity(_obj=o)
  505. if name == "dtd":
  506. return xmlDtd(_obj=o)
  507. return xmlNode(_obj=o)
  508. def xpathObjectRet(o):
  509. otype = type(o)
  510. if otype == type([]):
  511. ret = map(xpathObjectRet, o)
  512. return ret
  513. elif otype == type(()):
  514. ret = map(xpathObjectRet, o)
  515. return tuple(ret)
  516. elif otype == type('') or otype == type(0) or otype == type(0.0):
  517. return o
  518. else:
  519. return nodeWrap(o)
  520. #
  521. # register an XPath function
  522. #
  523. def registerXPathFunction(ctxt, name, ns_uri, f):
  524. ret = libxml2mod.xmlRegisterXPathFunction(ctxt, name, ns_uri, f)
  525. #
  526. # For the xmlTextReader parser configuration
  527. #
  528. PARSER_LOADDTD=1
  529. PARSER_DEFAULTATTRS=2
  530. PARSER_VALIDATE=3
  531. PARSER_SUBST_ENTITIES=4
  532. #
  533. # For the error callback severities
  534. #
  535. PARSER_SEVERITY_VALIDITY_WARNING=1
  536. PARSER_SEVERITY_VALIDITY_ERROR=2
  537. PARSER_SEVERITY_WARNING=3
  538. PARSER_SEVERITY_ERROR=4
  539. #
  540. # register the libxml2 error handler
  541. #
  542. def registerErrorHandler(f, ctx):
  543. """Register a Python written function to for error reporting.
  544. The function is called back as f(ctx, error). """
  545. import sys
  546. if not sys.modules.has_key('libxslt'):
  547. # normal behaviour when libxslt is not imported
  548. ret = libxml2mod.xmlRegisterErrorHandler(f,ctx)
  549. else:
  550. # when libxslt is already imported, one must
  551. # use libxst's error handler instead
  552. import libxslt
  553. ret = libxslt.registerErrorHandler(f,ctx)
  554. return ret
  555. class parserCtxtCore:
  556. def __init__(self, _obj=None):
  557. if _obj != None:
  558. self._o = _obj;
  559. return
  560. self._o = None
  561. def __del__(self):
  562. if self._o != None:
  563. libxml2mod.xmlFreeParserCtxt(self._o)
  564. self._o = None
  565. def setErrorHandler(self,f,arg):
  566. """Register an error handler that will be called back as
  567. f(arg,msg,severity,reserved).
  568. @reserved is currently always None."""
  569. libxml2mod.xmlParserCtxtSetErrorHandler(self._o,f,arg)
  570. def getErrorHandler(self):
  571. """Return (f,arg) as previously registered with setErrorHandler
  572. or (None,None)."""
  573. return libxml2mod.xmlParserCtxtGetErrorHandler(self._o)
  574. def addLocalCatalog(self, uri):
  575. """Register a local catalog with the parser"""
  576. return libxml2mod.addLocalCatalog(self._o, uri)
  577. class ValidCtxtCore:
  578. def __init__(self, *args, **kw):
  579. pass
  580. def setValidityErrorHandler(self, err_func, warn_func, arg=None):
  581. """
  582. Register error and warning handlers for DTD validation.
  583. These will be called back as f(msg,arg)
  584. """
  585. libxml2mod.xmlSetValidErrors(self._o, err_func, warn_func, arg)
  586. class SchemaValidCtxtCore:
  587. def __init__(self, *args, **kw):
  588. pass
  589. def setValidityErrorHandler(self, err_func, warn_func, arg=None):
  590. """
  591. Register error and warning handlers for Schema validation.
  592. These will be called back as f(msg,arg)
  593. """
  594. libxml2mod.xmlSchemaSetValidErrors(self._o, err_func, warn_func, arg)
  595. class relaxNgValidCtxtCore:
  596. def __init__(self, *args, **kw):
  597. pass
  598. def setValidityErrorHandler(self, err_func, warn_func, arg=None):
  599. """
  600. Register error and warning handlers for RelaxNG validation.
  601. These will be called back as f(msg,arg)
  602. """
  603. libxml2mod.xmlRelaxNGSetValidErrors(self._o, err_func, warn_func, arg)
  604. def _xmlTextReaderErrorFunc((f,arg),msg,severity,locator):
  605. """Intermediate callback to wrap the locator"""
  606. return f(arg,msg,severity,xmlTextReaderLocator(locator))
  607. class xmlTextReaderCore:
  608. def __init__(self, _obj=None):
  609. self.input = None
  610. if _obj != None:self._o = _obj;return
  611. self._o = None
  612. def __del__(self):
  613. if self._o != None:
  614. libxml2mod.xmlFreeTextReader(self._o)
  615. self._o = None
  616. def SetErrorHandler(self,f,arg):
  617. """Register an error handler that will be called back as
  618. f(arg,msg,severity,locator)."""
  619. if f is None:
  620. libxml2mod.xmlTextReaderSetErrorHandler(\
  621. self._o,None,None)
  622. else:
  623. libxml2mod.xmlTextReaderSetErrorHandler(\
  624. self._o,_xmlTextReaderErrorFunc,(f,arg))
  625. def GetErrorHandler(self):
  626. """Return (f,arg) as previously registered with setErrorHandler
  627. or (None,None)."""
  628. f,arg = libxml2mod.xmlTextReaderGetErrorHandler(self._o)
  629. if f is None:
  630. return None,None
  631. else:
  632. # assert f is _xmlTextReaderErrorFunc
  633. return arg
  634. #
  635. # The cleanup now goes though a wrappe in libxml.c
  636. #
  637. def cleanupParser():
  638. libxml2mod.xmlPythonCleanupParser()
  639. # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  640. #
  641. # Everything before this line comes from libxml.py
  642. # Everything after this line is automatically generated
  643. #
  644. # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING