3 from lxml.includes cimport xinclude
6 cdef class XIncludeError(LxmlError):
7 u"""Error during XInclude processing.
15 Create an instance and call it on an Element to run XInclude
18 cdef _ErrorLog _error_log
20 self._error_log = _ErrorLog()
24 assert self._error_log is not None, "XInclude instance not initialised"
25 return self._error_log.copy()
27 def __call__(self, _Element node not None):
28 u"__call__(self, node)"
29 # We cannot pass the XML_PARSE_NOXINCNODE option as this would free
30 # the XInclude nodes - there may still be Python references to them!
31 # Therefore, we allow XInclude nodes to be converted to
32 # XML_XINCLUDE_START nodes. XML_XINCLUDE_END nodes are added as
33 # siblings. Tree traversal will simply ignore them as they are not
34 # typed as elements. The included fragment is added between the two,
35 # i.e. as a sibling, which does not conflict with traversal.
37 _assertValidNode(node)
38 assert self._error_log is not None, "XInclude processor not initialised"
39 if node._doc._parser is not None:
40 parse_options = node._doc._parser._parse_options
41 context = node._doc._parser._getParserContext()
42 c_context = <void*>context
48 self._error_log.connect()
49 if tree.LIBXML_VERSION < 20704 or not c_context:
50 __GLOBAL_PARSER_CONTEXT.pushImpliedContext(context)
52 orig_loader = _register_document_loader()
54 result = xinclude.xmlXIncludeProcessTreeFlagsData(
55 node._c_node, parse_options, c_context)
57 result = xinclude.xmlXIncludeProcessTree(node._c_node)
58 _reset_document_loader(orig_loader)
59 if tree.LIBXML_VERSION < 20704 or not c_context:
60 __GLOBAL_PARSER_CONTEXT.popImpliedContext()
61 self._error_log.disconnect()
65 self._error_log._buildExceptionMessage(
66 u"XInclude processing failed"),