ZTWHHH commited on
Commit
e083556
·
verified ·
1 Parent(s): 4c2555b

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. llava_video/lib/python3.10/site-packages/lxml/ElementInclude.py +244 -0
  3. llava_video/lib/python3.10/site-packages/lxml/__init__.py +22 -0
  4. llava_video/lib/python3.10/site-packages/lxml/_elementpath.py +341 -0
  5. llava_video/lib/python3.10/site-packages/lxml/apihelpers.pxi +1793 -0
  6. llava_video/lib/python3.10/site-packages/lxml/cssselect.py +101 -0
  7. llava_video/lib/python3.10/site-packages/lxml/docloader.pxi +178 -0
  8. llava_video/lib/python3.10/site-packages/lxml/doctestcompare.py +488 -0
  9. llava_video/lib/python3.10/site-packages/lxml/dtd.pxi +479 -0
  10. llava_video/lib/python3.10/site-packages/lxml/etree.h +248 -0
  11. llava_video/lib/python3.10/site-packages/lxml/etree.pyx +0 -0
  12. llava_video/lib/python3.10/site-packages/lxml/etree_api.h +195 -0
  13. llava_video/lib/python3.10/site-packages/lxml/extensions.pxi +833 -0
  14. llava_video/lib/python3.10/site-packages/lxml/includes/__init__.pxd +0 -0
  15. llava_video/lib/python3.10/site-packages/lxml/includes/__init__.py +0 -0
  16. llava_video/lib/python3.10/site-packages/lxml/includes/c14n.pxd +25 -0
  17. llava_video/lib/python3.10/site-packages/lxml/includes/config.pxd +3 -0
  18. llava_video/lib/python3.10/site-packages/lxml/includes/dtdvalid.pxd +18 -0
  19. llava_video/lib/python3.10/site-packages/lxml/includes/etree_defs.h +379 -0
  20. llava_video/lib/python3.10/site-packages/lxml/includes/etreepublic.pxd +237 -0
  21. llava_video/lib/python3.10/site-packages/lxml/includes/htmlparser.pxd +56 -0
  22. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/SAX2.h +171 -0
  23. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/entities.h +155 -0
  24. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/parserInternals.h +663 -0
  25. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/schemasInternals.h +959 -0
  26. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xlink.h +189 -0
  27. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xmlversion.h +511 -0
  28. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xmlwriter.h +488 -0
  29. llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xpath.h +575 -0
  30. llava_video/lib/python3.10/site-packages/lxml/includes/lxml-version.h +3 -0
  31. llava_video/lib/python3.10/site-packages/lxml/includes/relaxng.pxd +64 -0
  32. llava_video/lib/python3.10/site-packages/lxml/includes/schematron.pxd +34 -0
  33. llava_video/lib/python3.10/site-packages/lxml/includes/tree.pxd +494 -0
  34. llava_video/lib/python3.10/site-packages/lxml/includes/uri.pxd +5 -0
  35. llava_video/lib/python3.10/site-packages/lxml/includes/xinclude.pxd +22 -0
  36. llava_video/lib/python3.10/site-packages/lxml/includes/xmlerror.pxd +852 -0
  37. llava_video/lib/python3.10/site-packages/lxml/includes/xmlparser.pxd +265 -0
  38. llava_video/lib/python3.10/site-packages/lxml/includes/xmlschema.pxd +35 -0
  39. llava_video/lib/python3.10/site-packages/lxml/includes/xpath.pxd +136 -0
  40. llava_video/lib/python3.10/site-packages/lxml/includes/xslt.pxd +190 -0
  41. llava_video/lib/python3.10/site-packages/lxml/iterparse.pxi +438 -0
  42. llava_video/lib/python3.10/site-packages/lxml/lxml.etree.h +248 -0
  43. llava_video/lib/python3.10/site-packages/lxml/lxml.etree_api.h +195 -0
  44. llava_video/lib/python3.10/site-packages/lxml/nsclasses.pxi +281 -0
  45. llava_video/lib/python3.10/site-packages/lxml/objectify.pyx +2145 -0
  46. llava_video/lib/python3.10/site-packages/lxml/objectpath.pxi +332 -0
  47. llava_video/lib/python3.10/site-packages/lxml/parser.pxi +2000 -0
  48. llava_video/lib/python3.10/site-packages/lxml/parsertarget.pxi +180 -0
  49. llava_video/lib/python3.10/site-packages/lxml/proxy.pxi +619 -0
  50. llava_video/lib/python3.10/site-packages/lxml/public-api.pxi +178 -0
.gitattributes CHANGED
@@ -671,3 +671,5 @@ llava_video/lib/python3.10/site-packages/matplotlib/_path.cpython-310-x86_64-lin
671
  llava_video/lib/python3.10/site-packages/matplotlib/_image.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
672
  llava_video/lib/python3.10/site-packages/matplotlib/_tri.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
673
  llava_video/lib/python3.10/site-packages/matplotlib/backends/_tkagg.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
671
  llava_video/lib/python3.10/site-packages/matplotlib/_image.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
672
  llava_video/lib/python3.10/site-packages/matplotlib/_tri.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
673
  llava_video/lib/python3.10/site-packages/matplotlib/backends/_tkagg.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
674
+ llava_video/lib/python3.10/site-packages/matplotlib/__pycache__/widgets.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
675
+ llava_video/lib/python3.10/site-packages/matplotlib/__pycache__/colors.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
llava_video/lib/python3.10/site-packages/lxml/ElementInclude.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # ElementTree
3
+ # $Id: ElementInclude.py 1862 2004-06-18 07:31:02Z Fredrik $
4
+ #
5
+ # limited xinclude support for element trees
6
+ #
7
+ # history:
8
+ # 2003-08-15 fl created
9
+ # 2003-11-14 fl fixed default loader
10
+ #
11
+ # Copyright (c) 2003-2004 by Fredrik Lundh. All rights reserved.
12
+ #
13
+ # fredrik@pythonware.com
14
+ # http://www.pythonware.com
15
+ #
16
+ # --------------------------------------------------------------------
17
+ # The ElementTree toolkit is
18
+ #
19
+ # Copyright (c) 1999-2004 by Fredrik Lundh
20
+ #
21
+ # By obtaining, using, and/or copying this software and/or its
22
+ # associated documentation, you agree that you have read, understood,
23
+ # and will comply with the following terms and conditions:
24
+ #
25
+ # Permission to use, copy, modify, and distribute this software and
26
+ # its associated documentation for any purpose and without fee is
27
+ # hereby granted, provided that the above copyright notice appears in
28
+ # all copies, and that both that copyright notice and this permission
29
+ # notice appear in supporting documentation, and that the name of
30
+ # Secret Labs AB or the author not be used in advertising or publicity
31
+ # pertaining to distribution of the software without specific, written
32
+ # prior permission.
33
+ #
34
+ # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
35
+ # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
36
+ # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
37
+ # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
38
+ # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39
+ # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
40
+ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
41
+ # OF THIS SOFTWARE.
42
+ # --------------------------------------------------------------------
43
+
44
+ """
45
+ Limited XInclude support for the ElementTree package.
46
+
47
+ While lxml.etree has full support for XInclude (see
48
+ `etree.ElementTree.xinclude()`), this module provides a simpler, pure
49
+ Python, ElementTree compatible implementation that supports a simple
50
+ form of custom URL resolvers.
51
+ """
52
+
53
+ from lxml import etree
54
+ try:
55
+ from urlparse import urljoin
56
+ from urllib2 import urlopen
57
+ except ImportError:
58
+ # Python 3
59
+ from urllib.parse import urljoin
60
+ from urllib.request import urlopen
61
+
62
+ XINCLUDE = "{http://www.w3.org/2001/XInclude}"
63
+
64
+ XINCLUDE_INCLUDE = XINCLUDE + "include"
65
+ XINCLUDE_FALLBACK = XINCLUDE + "fallback"
66
+ XINCLUDE_ITER_TAG = XINCLUDE + "*"
67
+
68
+ # For security reasons, the inclusion depth is limited to this read-only value by default.
69
+ DEFAULT_MAX_INCLUSION_DEPTH = 6
70
+
71
+
72
+ ##
73
+ # Fatal include error.
74
+
75
+ class FatalIncludeError(etree.LxmlSyntaxError):
76
+ pass
77
+
78
+
79
+ class LimitedRecursiveIncludeError(FatalIncludeError):
80
+ pass
81
+
82
+
83
+ ##
84
+ # ET compatible default loader.
85
+ # This loader reads an included resource from disk.
86
+ #
87
+ # @param href Resource reference.
88
+ # @param parse Parse mode. Either "xml" or "text".
89
+ # @param encoding Optional text encoding.
90
+ # @return The expanded resource. If the parse mode is "xml", this
91
+ # is an ElementTree instance. If the parse mode is "text", this
92
+ # is a Unicode string. If the loader fails, it can return None
93
+ # or raise an IOError exception.
94
+ # @throws IOError If the loader fails to load the resource.
95
+
96
+ def default_loader(href, parse, encoding=None):
97
+ file = open(href, 'rb')
98
+ if parse == "xml":
99
+ data = etree.parse(file).getroot()
100
+ else:
101
+ data = file.read()
102
+ if not encoding:
103
+ encoding = 'utf-8'
104
+ data = data.decode(encoding)
105
+ file.close()
106
+ return data
107
+
108
+
109
+ ##
110
+ # Default loader used by lxml.etree - handles custom resolvers properly
111
+ #
112
+
113
+ def _lxml_default_loader(href, parse, encoding=None, parser=None):
114
+ if parse == "xml":
115
+ data = etree.parse(href, parser).getroot()
116
+ else:
117
+ if "://" in href:
118
+ f = urlopen(href)
119
+ else:
120
+ f = open(href, 'rb')
121
+ data = f.read()
122
+ f.close()
123
+ if not encoding:
124
+ encoding = 'utf-8'
125
+ data = data.decode(encoding)
126
+ return data
127
+
128
+
129
+ ##
130
+ # Wrapper for ET compatibility - drops the parser
131
+
132
+ def _wrap_et_loader(loader):
133
+ def load(href, parse, encoding=None, parser=None):
134
+ return loader(href, parse, encoding)
135
+ return load
136
+
137
+
138
+ ##
139
+ # Expand XInclude directives.
140
+ #
141
+ # @param elem Root element.
142
+ # @param loader Optional resource loader. If omitted, it defaults
143
+ # to {@link default_loader}. If given, it should be a callable
144
+ # that implements the same interface as <b>default_loader</b>.
145
+ # @param base_url The base URL of the original file, to resolve
146
+ # relative include file references.
147
+ # @param max_depth The maximum number of recursive inclusions.
148
+ # Limited to reduce the risk of malicious content explosion.
149
+ # Pass None to disable the limitation.
150
+ # @throws LimitedRecursiveIncludeError If the {@link max_depth} was exceeded.
151
+ # @throws FatalIncludeError If the function fails to include a given
152
+ # resource, or if the tree contains malformed XInclude elements.
153
+ # @throws IOError If the function fails to load a given resource.
154
+ # @returns the node or its replacement if it was an XInclude node
155
+
156
+ def include(elem, loader=None, base_url=None,
157
+ max_depth=DEFAULT_MAX_INCLUSION_DEPTH):
158
+ if max_depth is None:
159
+ max_depth = -1
160
+ elif max_depth < 0:
161
+ raise ValueError("expected non-negative depth or None for 'max_depth', got %r" % max_depth)
162
+
163
+ if base_url is None:
164
+ if hasattr(elem, 'getroot'):
165
+ tree = elem
166
+ elem = elem.getroot()
167
+ else:
168
+ tree = elem.getroottree()
169
+ if hasattr(tree, 'docinfo'):
170
+ base_url = tree.docinfo.URL
171
+ elif hasattr(elem, 'getroot'):
172
+ elem = elem.getroot()
173
+ _include(elem, loader, base_url, max_depth)
174
+
175
+
176
+ def _include(elem, loader=None, base_url=None,
177
+ max_depth=DEFAULT_MAX_INCLUSION_DEPTH, _parent_hrefs=None):
178
+ if loader is not None:
179
+ load_include = _wrap_et_loader(loader)
180
+ else:
181
+ load_include = _lxml_default_loader
182
+
183
+ if _parent_hrefs is None:
184
+ _parent_hrefs = set()
185
+
186
+ parser = elem.getroottree().parser
187
+
188
+ include_elements = list(
189
+ elem.iter(XINCLUDE_ITER_TAG))
190
+
191
+ for e in include_elements:
192
+ if e.tag == XINCLUDE_INCLUDE:
193
+ # process xinclude directive
194
+ href = urljoin(base_url, e.get("href"))
195
+ parse = e.get("parse", "xml")
196
+ parent = e.getparent()
197
+ if parse == "xml":
198
+ if href in _parent_hrefs:
199
+ raise FatalIncludeError(
200
+ "recursive include of %r detected" % href
201
+ )
202
+ if max_depth == 0:
203
+ raise LimitedRecursiveIncludeError(
204
+ "maximum xinclude depth reached when including file %s" % href)
205
+ node = load_include(href, parse, parser=parser)
206
+ if node is None:
207
+ raise FatalIncludeError(
208
+ "cannot load %r as %r" % (href, parse)
209
+ )
210
+ node = _include(node, loader, href, max_depth - 1, {href} | _parent_hrefs)
211
+ if e.tail:
212
+ node.tail = (node.tail or "") + e.tail
213
+ if parent is None:
214
+ return node # replaced the root node!
215
+ parent.replace(e, node)
216
+ elif parse == "text":
217
+ text = load_include(href, parse, encoding=e.get("encoding"))
218
+ if text is None:
219
+ raise FatalIncludeError(
220
+ "cannot load %r as %r" % (href, parse)
221
+ )
222
+ predecessor = e.getprevious()
223
+ if predecessor is not None:
224
+ predecessor.tail = (predecessor.tail or "") + text
225
+ elif parent is None:
226
+ return text # replaced the root node!
227
+ else:
228
+ parent.text = (parent.text or "") + text + (e.tail or "")
229
+ parent.remove(e)
230
+ else:
231
+ raise FatalIncludeError(
232
+ "unknown parse type in xi:include tag (%r)" % parse
233
+ )
234
+ elif e.tag == XINCLUDE_FALLBACK:
235
+ parent = e.getparent()
236
+ if parent is not None and parent.tag != XINCLUDE_INCLUDE:
237
+ raise FatalIncludeError(
238
+ "xi:fallback tag must be child of xi:include (%r)" % e.tag
239
+ )
240
+ else:
241
+ raise FatalIncludeError(
242
+ "Invalid element found in XInclude namespace (%r)" % e.tag
243
+ )
244
+ return elem
llava_video/lib/python3.10/site-packages/lxml/__init__.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # this is a package
2
+
3
+ __version__ = "5.3.1"
4
+
5
+
6
+ def get_include():
7
+ """
8
+ Returns a list of header include paths (for lxml itself, libxml2
9
+ and libxslt) needed to compile C code against lxml if it was built
10
+ with statically linked libraries.
11
+ """
12
+ import os
13
+ lxml_path = __path__[0]
14
+ include_path = os.path.join(lxml_path, 'includes')
15
+ includes = [include_path, lxml_path]
16
+
17
+ for name in os.listdir(include_path):
18
+ path = os.path.join(include_path, name)
19
+ if os.path.isdir(path):
20
+ includes.append(path)
21
+
22
+ return includes
llava_video/lib/python3.10/site-packages/lxml/_elementpath.py ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cython: language_level=2
2
+
3
+ #
4
+ # ElementTree
5
+ # $Id: ElementPath.py 3375 2008-02-13 08:05:08Z fredrik $
6
+ #
7
+ # limited xpath support for element trees
8
+ #
9
+ # history:
10
+ # 2003-05-23 fl created
11
+ # 2003-05-28 fl added support for // etc
12
+ # 2003-08-27 fl fixed parsing of periods in element names
13
+ # 2007-09-10 fl new selection engine
14
+ # 2007-09-12 fl fixed parent selector
15
+ # 2007-09-13 fl added iterfind; changed findall to return a list
16
+ # 2007-11-30 fl added namespaces support
17
+ # 2009-10-30 fl added child element value filter
18
+ #
19
+ # Copyright (c) 2003-2009 by Fredrik Lundh. All rights reserved.
20
+ #
21
+ # fredrik@pythonware.com
22
+ # http://www.pythonware.com
23
+ #
24
+ # --------------------------------------------------------------------
25
+ # The ElementTree toolkit is
26
+ #
27
+ # Copyright (c) 1999-2009 by Fredrik Lundh
28
+ #
29
+ # By obtaining, using, and/or copying this software and/or its
30
+ # associated documentation, you agree that you have read, understood,
31
+ # and will comply with the following terms and conditions:
32
+ #
33
+ # Permission to use, copy, modify, and distribute this software and
34
+ # its associated documentation for any purpose and without fee is
35
+ # hereby granted, provided that the above copyright notice appears in
36
+ # all copies, and that both that copyright notice and this permission
37
+ # notice appear in supporting documentation, and that the name of
38
+ # Secret Labs AB or the author not be used in advertising or publicity
39
+ # pertaining to distribution of the software without specific, written
40
+ # prior permission.
41
+ #
42
+ # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
43
+ # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
44
+ # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
45
+ # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
46
+ # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
47
+ # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
48
+ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
49
+ # OF THIS SOFTWARE.
50
+ # --------------------------------------------------------------------
51
+
52
+ ##
53
+ # Implementation module for XPath support. There's usually no reason
54
+ # to import this module directly; the <b>ElementTree</b> does this for
55
+ # you, if needed.
56
+ ##
57
+
58
+
59
+ import re
60
+
61
+ xpath_tokenizer_re = re.compile(
62
+ "("
63
+ "'[^']*'|\"[^\"]*\"|"
64
+ "::|"
65
+ "//?|"
66
+ r"\.\.|"
67
+ r"\(\)|"
68
+ r"[/.*:\[\]\(\)@=])|"
69
+ r"((?:\{[^}]+\})?[^/\[\]\(\)@=\s]+)|"
70
+ r"\s+"
71
+ )
72
+
73
+ def xpath_tokenizer(pattern, namespaces=None, with_prefixes=True):
74
+ # ElementTree uses '', lxml used None originally.
75
+ default_namespace = (namespaces.get(None) or namespaces.get('')) if namespaces else None
76
+ parsing_attribute = False
77
+ for token in xpath_tokenizer_re.findall(pattern):
78
+ ttype, tag = token
79
+ if tag and tag[0] != "{":
80
+ if ":" in tag and with_prefixes:
81
+ prefix, uri = tag.split(":", 1)
82
+ try:
83
+ if not namespaces:
84
+ raise KeyError
85
+ yield ttype, "{%s}%s" % (namespaces[prefix], uri)
86
+ except KeyError:
87
+ raise SyntaxError("prefix %r not found in prefix map" % prefix)
88
+ elif default_namespace and not parsing_attribute:
89
+ yield ttype, "{%s}%s" % (default_namespace, tag)
90
+ else:
91
+ yield token
92
+ parsing_attribute = False
93
+ else:
94
+ yield token
95
+ parsing_attribute = ttype == '@'
96
+
97
+
98
+ def prepare_child(next, token):
99
+ tag = token[1]
100
+ def select(result):
101
+ for elem in result:
102
+ yield from elem.iterchildren(tag)
103
+ return select
104
+
105
+ def prepare_star(next, token):
106
+ def select(result):
107
+ for elem in result:
108
+ yield from elem.iterchildren('*')
109
+ return select
110
+
111
+ def prepare_self(next, token):
112
+ def select(result):
113
+ return result
114
+ return select
115
+
116
+ def prepare_descendant(next, token):
117
+ token = next()
118
+ if token[0] == "*":
119
+ tag = "*"
120
+ elif not token[0]:
121
+ tag = token[1]
122
+ else:
123
+ raise SyntaxError("invalid descendant")
124
+ def select(result):
125
+ for elem in result:
126
+ yield from elem.iterdescendants(tag)
127
+ return select
128
+
129
+ def prepare_parent(next, token):
130
+ def select(result):
131
+ for elem in result:
132
+ parent = elem.getparent()
133
+ if parent is not None:
134
+ yield parent
135
+ return select
136
+
137
+ def prepare_predicate(next, token):
138
+ # FIXME: replace with real parser!!! refs:
139
+ # http://effbot.org/zone/simple-iterator-parser.htm
140
+ # http://javascript.crockford.com/tdop/tdop.html
141
+ signature = ''
142
+ predicate = []
143
+ while 1:
144
+ token = next()
145
+ if token[0] == "]":
146
+ break
147
+ if token == ('', ''):
148
+ # ignore whitespace
149
+ continue
150
+ if token[0] and token[0][:1] in "'\"":
151
+ token = "'", token[0][1:-1]
152
+ signature += token[0] or "-"
153
+ predicate.append(token[1])
154
+
155
+ # use signature to determine predicate type
156
+ if signature == "@-":
157
+ # [@attribute] predicate
158
+ key = predicate[1]
159
+ def select(result):
160
+ for elem in result:
161
+ if elem.get(key) is not None:
162
+ yield elem
163
+ return select
164
+ if signature == "@-='":
165
+ # [@attribute='value']
166
+ key = predicate[1]
167
+ value = predicate[-1]
168
+ def select(result):
169
+ for elem in result:
170
+ if elem.get(key) == value:
171
+ yield elem
172
+ return select
173
+ if signature == "-" and not re.match(r"-?\d+$", predicate[0]):
174
+ # [tag]
175
+ tag = predicate[0]
176
+ def select(result):
177
+ for elem in result:
178
+ for _ in elem.iterchildren(tag):
179
+ yield elem
180
+ break
181
+ return select
182
+ if signature == ".='" or (signature == "-='" and not re.match(r"-?\d+$", predicate[0])):
183
+ # [.='value'] or [tag='value']
184
+ tag = predicate[0]
185
+ value = predicate[-1]
186
+ if tag:
187
+ def select(result):
188
+ for elem in result:
189
+ for e in elem.iterchildren(tag):
190
+ if "".join(e.itertext()) == value:
191
+ yield elem
192
+ break
193
+ else:
194
+ def select(result):
195
+ for elem in result:
196
+ if "".join(elem.itertext()) == value:
197
+ yield elem
198
+ return select
199
+ if signature == "-" or signature == "-()" or signature == "-()-":
200
+ # [index] or [last()] or [last()-index]
201
+ if signature == "-":
202
+ # [index]
203
+ index = int(predicate[0]) - 1
204
+ if index < 0:
205
+ if index == -1:
206
+ raise SyntaxError(
207
+ "indices in path predicates are 1-based, not 0-based")
208
+ else:
209
+ raise SyntaxError("path index >= 1 expected")
210
+ else:
211
+ if predicate[0] != "last":
212
+ raise SyntaxError("unsupported function")
213
+ if signature == "-()-":
214
+ try:
215
+ index = int(predicate[2]) - 1
216
+ except ValueError:
217
+ raise SyntaxError("unsupported expression")
218
+ else:
219
+ index = -1
220
+ def select(result):
221
+ for elem in result:
222
+ parent = elem.getparent()
223
+ if parent is None:
224
+ continue
225
+ try:
226
+ # FIXME: what if the selector is "*" ?
227
+ elems = list(parent.iterchildren(elem.tag))
228
+ if elems[index] is elem:
229
+ yield elem
230
+ except IndexError:
231
+ pass
232
+ return select
233
+ raise SyntaxError("invalid predicate")
234
+
235
+ ops = {
236
+ "": prepare_child,
237
+ "*": prepare_star,
238
+ ".": prepare_self,
239
+ "..": prepare_parent,
240
+ "//": prepare_descendant,
241
+ "[": prepare_predicate,
242
+ }
243
+
244
+
245
+ # --------------------------------------------------------------------
246
+
247
+ _cache = {}
248
+
249
+
250
+ def _build_path_iterator(path, namespaces, with_prefixes=True):
251
+ """compile selector pattern"""
252
+ if path[-1:] == "/":
253
+ path += "*" # implicit all (FIXME: keep this?)
254
+
255
+ cache_key = (path,)
256
+ if namespaces:
257
+ # lxml originally used None for the default namespace but ElementTree uses the
258
+ # more convenient (all-strings-dict) empty string, so we support both here,
259
+ # preferring the more convenient '', as long as they aren't ambiguous.
260
+ if None in namespaces:
261
+ if '' in namespaces and namespaces[None] != namespaces['']:
262
+ raise ValueError("Ambiguous default namespace provided: %r versus %r" % (
263
+ namespaces[None], namespaces['']))
264
+ cache_key += (namespaces[None],) + tuple(sorted(
265
+ item for item in namespaces.items() if item[0] is not None))
266
+ else:
267
+ cache_key += tuple(sorted(namespaces.items()))
268
+
269
+ try:
270
+ return _cache[cache_key]
271
+ except KeyError:
272
+ pass
273
+ if len(_cache) > 100:
274
+ _cache.clear()
275
+
276
+ if path[:1] == "/":
277
+ raise SyntaxError("cannot use absolute path on element")
278
+ stream = iter(xpath_tokenizer(path, namespaces, with_prefixes=with_prefixes))
279
+ try:
280
+ _next = stream.next
281
+ except AttributeError:
282
+ # Python 3
283
+ _next = stream.__next__
284
+ try:
285
+ token = _next()
286
+ except StopIteration:
287
+ raise SyntaxError("empty path expression")
288
+ selector = []
289
+ while 1:
290
+ try:
291
+ selector.append(ops[token[0]](_next, token))
292
+ except StopIteration:
293
+ raise SyntaxError("invalid path")
294
+ try:
295
+ token = _next()
296
+ if token[0] == "/":
297
+ token = _next()
298
+ except StopIteration:
299
+ break
300
+ _cache[cache_key] = selector
301
+ return selector
302
+
303
+
304
+ ##
305
+ # Iterate over the matching nodes
306
+
307
+ def iterfind(elem, path, namespaces=None, with_prefixes=True):
308
+ selector = _build_path_iterator(path, namespaces, with_prefixes=with_prefixes)
309
+ result = iter((elem,))
310
+ for select in selector:
311
+ result = select(result)
312
+ return result
313
+
314
+
315
+ ##
316
+ # Find first matching object.
317
+
318
+ def find(elem, path, namespaces=None, with_prefixes=True):
319
+ it = iterfind(elem, path, namespaces, with_prefixes=with_prefixes)
320
+ try:
321
+ return next(it)
322
+ except StopIteration:
323
+ return None
324
+
325
+
326
+ ##
327
+ # Find all matching objects.
328
+
329
+ def findall(elem, path, namespaces=None, with_prefixes=True):
330
+ return list(iterfind(elem, path, namespaces))
331
+
332
+
333
+ ##
334
+ # Find text for first matching object.
335
+
336
+ def findtext(elem, path, default=None, namespaces=None, with_prefixes=True):
337
+ el = find(elem, path, namespaces, with_prefixes=with_prefixes)
338
+ if el is None:
339
+ return default
340
+ else:
341
+ return el.text or ''
llava_video/lib/python3.10/site-packages/lxml/apihelpers.pxi ADDED
@@ -0,0 +1,1793 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Private/public helper functions for API functions
2
+
3
+ from lxml.includes cimport uri
4
+
5
+
6
+ cdef void displayNode(xmlNode* c_node, indent) noexcept:
7
+ # to help with debugging
8
+ cdef xmlNode* c_child
9
+ try:
10
+ print(indent * ' ', <long>c_node)
11
+ c_child = c_node.children
12
+ while c_child is not NULL:
13
+ displayNode(c_child, indent + 1)
14
+ c_child = c_child.next
15
+ finally:
16
+ return # swallow any exceptions
17
+
18
+ cdef inline bint _isHtmlDocument(_Element element) except -1:
19
+ cdef xmlNode* c_node = element._c_node
20
+ return (
21
+ c_node is not NULL and c_node.doc is not NULL and
22
+ c_node.doc.properties & tree.XML_DOC_HTML != 0
23
+ )
24
+
25
+ cdef inline int _assertValidNode(_Element element) except -1:
26
+ assert element._c_node is not NULL, "invalid Element proxy at %s" % id(element)
27
+
28
+ cdef inline int _assertValidDoc(_Document doc) except -1:
29
+ assert doc._c_doc is not NULL, "invalid Document proxy at %s" % id(doc)
30
+
31
+ cdef _Document _documentOrRaise(object input):
32
+ """Call this to get the document of a _Document, _ElementTree or _Element
33
+ object, or to raise an exception if it can't be determined.
34
+
35
+ Should be used in all API functions for consistency.
36
+ """
37
+ cdef _Document doc
38
+ if isinstance(input, _ElementTree):
39
+ if (<_ElementTree>input)._context_node is not None:
40
+ doc = (<_ElementTree>input)._context_node._doc
41
+ else:
42
+ doc = None
43
+ elif isinstance(input, _Element):
44
+ doc = (<_Element>input)._doc
45
+ elif isinstance(input, _Document):
46
+ doc = <_Document>input
47
+ else:
48
+ raise TypeError, f"Invalid input object: {python._fqtypename(input).decode('utf8')}"
49
+ if doc is None:
50
+ raise ValueError, f"Input object has no document: {python._fqtypename(input).decode('utf8')}"
51
+ _assertValidDoc(doc)
52
+ return doc
53
+
54
+ cdef _Element _rootNodeOrRaise(object input):
55
+ """Call this to get the root node of a _Document, _ElementTree or
56
+ _Element object, or to raise an exception if it can't be determined.
57
+
58
+ Should be used in all API functions for consistency.
59
+ """
60
+ cdef _Element node
61
+ if isinstance(input, _ElementTree):
62
+ node = (<_ElementTree>input)._context_node
63
+ elif isinstance(input, _Element):
64
+ node = <_Element>input
65
+ elif isinstance(input, _Document):
66
+ node = (<_Document>input).getroot()
67
+ else:
68
+ raise TypeError, f"Invalid input object: {python._fqtypename(input).decode('utf8')}"
69
+ if (node is None or not node._c_node or
70
+ node._c_node.type != tree.XML_ELEMENT_NODE):
71
+ raise ValueError, f"Input object is not an XML element: {python._fqtypename(input).decode('utf8')}"
72
+ _assertValidNode(node)
73
+ return node
74
+
75
+ cdef bint _isAncestorOrSame(xmlNode* c_ancestor, xmlNode* c_node) noexcept:
76
+ while c_node:
77
+ if c_node is c_ancestor:
78
+ return True
79
+ c_node = c_node.parent
80
+ return False
81
+
82
+ cdef _Element _makeElement(tag, xmlDoc* c_doc, _Document doc,
83
+ _BaseParser parser, text, tail, attrib, nsmap,
84
+ dict extra_attrs):
85
+ """Create a new element and initialize text content, namespaces and
86
+ attributes.
87
+
88
+ This helper function will reuse as much of the existing document as
89
+ possible:
90
+
91
+ If 'parser' is None, the parser will be inherited from 'doc' or the
92
+ default parser will be used.
93
+
94
+ If 'doc' is None, 'c_doc' is used to create a new _Document and the new
95
+ element is made its root node.
96
+
97
+ If 'c_doc' is also NULL, a new xmlDoc will be created.
98
+ """
99
+ cdef xmlNode* c_node
100
+ if doc is not None:
101
+ c_doc = doc._c_doc
102
+ ns_utf, name_utf = _getNsTag(tag)
103
+ if parser is not None and parser._for_html:
104
+ _htmlTagValidOrRaise(name_utf)
105
+ if c_doc is NULL:
106
+ c_doc = _newHTMLDoc()
107
+ else:
108
+ _tagValidOrRaise(name_utf)
109
+ if c_doc is NULL:
110
+ c_doc = _newXMLDoc()
111
+ c_node = _createElement(c_doc, name_utf)
112
+ if c_node is NULL:
113
+ if doc is None and c_doc is not NULL:
114
+ tree.xmlFreeDoc(c_doc)
115
+ raise MemoryError()
116
+ try:
117
+ if doc is None:
118
+ tree.xmlDocSetRootElement(c_doc, c_node)
119
+ doc = _documentFactory(c_doc, parser)
120
+ if text is not None:
121
+ _setNodeText(c_node, text)
122
+ if tail is not None:
123
+ _setTailText(c_node, tail)
124
+ # add namespaces to node if necessary
125
+ _setNodeNamespaces(c_node, doc, ns_utf, nsmap)
126
+ _initNodeAttributes(c_node, doc, attrib, extra_attrs)
127
+ return _elementFactory(doc, c_node)
128
+ except:
129
+ # free allocated c_node/c_doc unless Python does it for us
130
+ if c_node.doc is not c_doc:
131
+ # node not yet in document => will not be freed by document
132
+ if tail is not None:
133
+ _removeText(c_node.next) # tail
134
+ tree.xmlFreeNode(c_node)
135
+ if doc is None:
136
+ # c_doc will not be freed by doc
137
+ tree.xmlFreeDoc(c_doc)
138
+ raise
139
+
140
+ cdef int _initNewElement(_Element element, bint is_html, name_utf, ns_utf,
141
+ _BaseParser parser, attrib, nsmap, dict extra_attrs) except -1:
142
+ """Initialise a new Element object.
143
+
144
+ This is used when users instantiate a Python Element subclass
145
+ directly, without it being mapped to an existing XML node.
146
+ """
147
+ cdef xmlDoc* c_doc
148
+ cdef xmlNode* c_node
149
+ cdef _Document doc
150
+ if is_html:
151
+ _htmlTagValidOrRaise(name_utf)
152
+ c_doc = _newHTMLDoc()
153
+ else:
154
+ _tagValidOrRaise(name_utf)
155
+ c_doc = _newXMLDoc()
156
+ c_node = _createElement(c_doc, name_utf)
157
+ if c_node is NULL:
158
+ if c_doc is not NULL:
159
+ tree.xmlFreeDoc(c_doc)
160
+ raise MemoryError()
161
+ tree.xmlDocSetRootElement(c_doc, c_node)
162
+ doc = _documentFactory(c_doc, parser)
163
+ # add namespaces to node if necessary
164
+ _setNodeNamespaces(c_node, doc, ns_utf, nsmap)
165
+ _initNodeAttributes(c_node, doc, attrib, extra_attrs)
166
+ _registerProxy(element, doc, c_node)
167
+ element._init()
168
+ return 0
169
+
170
+ cdef _Element _makeSubElement(_Element parent, tag, text, tail,
171
+ attrib, nsmap, dict extra_attrs):
172
+ """Create a new child element and initialize text content, namespaces and
173
+ attributes.
174
+ """
175
+ cdef xmlNode* c_node
176
+ cdef xmlDoc* c_doc
177
+ if parent is None or parent._doc is None:
178
+ return None
179
+ _assertValidNode(parent)
180
+ ns_utf, name_utf = _getNsTag(tag)
181
+ c_doc = parent._doc._c_doc
182
+
183
+ if parent._doc._parser is not None and parent._doc._parser._for_html:
184
+ _htmlTagValidOrRaise(name_utf)
185
+ else:
186
+ _tagValidOrRaise(name_utf)
187
+
188
+ c_node = _createElement(c_doc, name_utf)
189
+ if c_node is NULL:
190
+ raise MemoryError()
191
+ tree.xmlAddChild(parent._c_node, c_node)
192
+
193
+ try:
194
+ if text is not None:
195
+ _setNodeText(c_node, text)
196
+ if tail is not None:
197
+ _setTailText(c_node, tail)
198
+
199
+ # add namespaces to node if necessary
200
+ _setNodeNamespaces(c_node, parent._doc, ns_utf, nsmap)
201
+ _initNodeAttributes(c_node, parent._doc, attrib, extra_attrs)
202
+ return _elementFactory(parent._doc, c_node)
203
+ except:
204
+ # make sure we clean up in case of an error
205
+ _removeNode(parent._doc, c_node)
206
+ raise
207
+
208
+
209
+ cdef int _setNodeNamespaces(xmlNode* c_node, _Document doc,
210
+ object node_ns_utf, object nsmap) except -1:
211
+ """Lookup current namespace prefixes, then set namespace structure for
212
+ node (if 'node_ns_utf' was provided) and register new ns-prefix mappings.
213
+
214
+ 'node_ns_utf' should only be passed for a newly created node.
215
+ """
216
+ cdef xmlNs* c_ns
217
+ cdef list nsdefs
218
+
219
+ if nsmap:
220
+ for prefix, href in _iter_nsmap(nsmap):
221
+ href_utf = _utf8(href)
222
+ _uriValidOrRaise(href_utf)
223
+ c_href = _xcstr(href_utf)
224
+ if prefix is not None:
225
+ prefix_utf = _utf8(prefix)
226
+ _prefixValidOrRaise(prefix_utf)
227
+ c_prefix = _xcstr(prefix_utf)
228
+ else:
229
+ c_prefix = <const_xmlChar*>NULL
230
+ # add namespace with prefix if it is not already known
231
+ c_ns = tree.xmlSearchNs(doc._c_doc, c_node, c_prefix)
232
+ if c_ns is NULL or \
233
+ c_ns.href is NULL or \
234
+ tree.xmlStrcmp(c_ns.href, c_href) != 0:
235
+ c_ns = tree.xmlNewNs(c_node, c_href, c_prefix)
236
+ if href_utf == node_ns_utf:
237
+ tree.xmlSetNs(c_node, c_ns)
238
+ node_ns_utf = None
239
+
240
+ if node_ns_utf is not None:
241
+ _uriValidOrRaise(node_ns_utf)
242
+ doc._setNodeNs(c_node, _xcstr(node_ns_utf))
243
+ return 0
244
+
245
+
246
+ cdef dict _build_nsmap(xmlNode* c_node):
247
+ """
248
+ Namespace prefix->URI mapping known in the context of this Element.
249
+ This includes all namespace declarations of the parents.
250
+ """
251
+ cdef xmlNs* c_ns
252
+ nsmap = {}
253
+ while c_node is not NULL and c_node.type == tree.XML_ELEMENT_NODE:
254
+ c_ns = c_node.nsDef
255
+ while c_ns is not NULL:
256
+ if c_ns.prefix or c_ns.href:
257
+ prefix = funicodeOrNone(c_ns.prefix)
258
+ if prefix not in nsmap:
259
+ nsmap[prefix] = funicodeOrNone(c_ns.href)
260
+ c_ns = c_ns.next
261
+ c_node = c_node.parent
262
+ return nsmap
263
+
264
+
265
+ cdef _iter_nsmap(nsmap):
266
+ """
267
+ Create a reproducibly ordered iterable from an nsmap mapping.
268
+ Tries to preserve an existing order and sorts if it assumes no order.
269
+
270
+ The difference to _iter_attrib() is that None doesn't sort with strings
271
+ in Py3.x.
272
+ """
273
+ if isinstance(nsmap, dict):
274
+ # dicts are insertion-ordered in Py3.6+ => keep the user provided order.
275
+ return nsmap.items()
276
+ if len(nsmap) <= 1:
277
+ return nsmap.items()
278
+ # nsmap will usually be a plain unordered dict => avoid type checking overhead
279
+ if type(nsmap) is not dict and isinstance(nsmap, OrderedDict):
280
+ return nsmap.items() # keep existing order
281
+ if None not in nsmap:
282
+ return sorted(nsmap.items())
283
+
284
+ # Move the default namespace to the end. This makes sure libxml2
285
+ # prefers a prefix if the ns is defined redundantly on the same
286
+ # element. That way, users can work around a problem themselves
287
+ # where default namespace attributes on non-default namespaced
288
+ # elements serialise without prefix (i.e. into the non-default
289
+ # namespace).
290
+ default_ns = nsmap[None]
291
+ nsdefs = [(k, v) for k, v in nsmap.items() if k is not None]
292
+ nsdefs.sort()
293
+ nsdefs.append((None, default_ns))
294
+ return nsdefs
295
+
296
+
297
+ cdef _iter_attrib(attrib):
298
+ """
299
+ Create a reproducibly ordered iterable from an attrib mapping.
300
+ Tries to preserve an existing order and sorts if it assumes no order.
301
+ """
302
+ # dicts are insertion-ordered in Py3.6+ => keep the user provided order.
303
+ if isinstance(attrib, (dict, _Attrib, OrderedDict)):
304
+ return attrib.items()
305
+ # assume it's an unordered mapping of some kind
306
+ return sorted(attrib.items())
307
+
308
+
309
+ cdef _initNodeAttributes(xmlNode* c_node, _Document doc, attrib, dict extra):
310
+ """Initialise the attributes of an element node.
311
+ """
312
+ cdef bint is_html
313
+ cdef xmlNs* c_ns
314
+ if attrib is not None and not hasattr(attrib, 'items'):
315
+ raise TypeError, f"Invalid attribute dictionary: {python._fqtypename(attrib).decode('utf8')}"
316
+ if not attrib and not extra:
317
+ return # nothing to do
318
+ is_html = doc._parser._for_html
319
+ seen = set()
320
+ if extra:
321
+ for name, value in extra.items():
322
+ _addAttributeToNode(c_node, doc, is_html, name, value, seen)
323
+ if attrib:
324
+ for name, value in _iter_attrib(attrib):
325
+ _addAttributeToNode(c_node, doc, is_html, name, value, seen)
326
+
327
+
328
+ cdef int _addAttributeToNode(xmlNode* c_node, _Document doc, bint is_html,
329
+ name, value, set seen_tags) except -1:
330
+ ns_utf, name_utf = tag = _getNsTag(name)
331
+ if tag in seen_tags:
332
+ return 0
333
+ seen_tags.add(tag)
334
+ if not is_html:
335
+ _attributeValidOrRaise(name_utf)
336
+ value_utf = _utf8(value)
337
+ if ns_utf is None:
338
+ tree.xmlNewProp(c_node, _xcstr(name_utf), _xcstr(value_utf))
339
+ else:
340
+ _uriValidOrRaise(ns_utf)
341
+ c_ns = doc._findOrBuildNodeNs(c_node, _xcstr(ns_utf), NULL, 1)
342
+ tree.xmlNewNsProp(c_node, c_ns,
343
+ _xcstr(name_utf), _xcstr(value_utf))
344
+ return 0
345
+
346
+
347
+ ctypedef struct _ns_node_ref:
348
+ xmlNs* ns
349
+ xmlNode* node
350
+
351
+
352
+ cdef int _collectNsDefs(xmlNode* c_element, _ns_node_ref **_c_ns_list,
353
+ size_t *_c_ns_list_len, size_t *_c_ns_list_size) except -1:
354
+ c_ns_list = _c_ns_list[0]
355
+ cdef size_t c_ns_list_len = _c_ns_list_len[0]
356
+ cdef size_t c_ns_list_size = _c_ns_list_size[0]
357
+
358
+ c_nsdef = c_element.nsDef
359
+ while c_nsdef is not NULL:
360
+ if c_ns_list_len >= c_ns_list_size:
361
+ if c_ns_list is NULL:
362
+ c_ns_list_size = 20
363
+ else:
364
+ c_ns_list_size *= 2
365
+ c_nsref_ptr = <_ns_node_ref*> python.lxml_realloc(
366
+ c_ns_list, c_ns_list_size, sizeof(_ns_node_ref))
367
+ if c_nsref_ptr is NULL:
368
+ if c_ns_list is not NULL:
369
+ python.lxml_free(c_ns_list)
370
+ _c_ns_list[0] = NULL
371
+ raise MemoryError()
372
+ c_ns_list = c_nsref_ptr
373
+
374
+ c_ns_list[c_ns_list_len] = _ns_node_ref(c_nsdef, c_element)
375
+ c_ns_list_len += 1
376
+ c_nsdef = c_nsdef.next
377
+
378
+ _c_ns_list_size[0] = c_ns_list_size
379
+ _c_ns_list_len[0] = c_ns_list_len
380
+ _c_ns_list[0] = c_ns_list
381
+
382
+
383
+ cdef int _removeUnusedNamespaceDeclarations(xmlNode* c_element, set prefixes_to_keep) except -1:
384
+ """Remove any namespace declarations from a subtree that are not used by
385
+ any of its elements (or attributes).
386
+
387
+ If a 'prefixes_to_keep' is provided, it must be a set of prefixes.
388
+ Any corresponding namespace mappings will not be removed as part of the cleanup.
389
+ """
390
+ cdef xmlNode* c_node
391
+ cdef _ns_node_ref* c_ns_list = NULL
392
+ cdef size_t c_ns_list_size = 0
393
+ cdef size_t c_ns_list_len = 0
394
+ cdef size_t i
395
+
396
+ if c_element.parent and c_element.parent.type == tree.XML_DOCUMENT_NODE:
397
+ # include declarations on the document node
398
+ _collectNsDefs(c_element.parent, &c_ns_list, &c_ns_list_len, &c_ns_list_size)
399
+
400
+ tree.BEGIN_FOR_EACH_ELEMENT_FROM(c_element, c_element, 1)
401
+ # collect all new namespace declarations into the ns list
402
+ if c_element.nsDef:
403
+ _collectNsDefs(c_element, &c_ns_list, &c_ns_list_len, &c_ns_list_size)
404
+
405
+ # remove all namespace declarations from the list that are referenced
406
+ if c_ns_list_len and c_element.type == tree.XML_ELEMENT_NODE:
407
+ c_node = c_element
408
+ while c_node and c_ns_list_len:
409
+ if c_node.ns:
410
+ for i in range(c_ns_list_len):
411
+ if c_node.ns is c_ns_list[i].ns:
412
+ c_ns_list_len -= 1
413
+ c_ns_list[i] = c_ns_list[c_ns_list_len]
414
+ #c_ns_list[c_ns_list_len] = _ns_node_ref(NULL, NULL)
415
+ break
416
+ if c_node is c_element:
417
+ # continue with attributes
418
+ c_node = <xmlNode*>c_element.properties
419
+ else:
420
+ c_node = c_node.next
421
+ tree.END_FOR_EACH_ELEMENT_FROM(c_element)
422
+
423
+ if c_ns_list is NULL:
424
+ return 0
425
+
426
+ # free all namespace declarations that remained in the list,
427
+ # except for those we should keep explicitly
428
+ cdef xmlNs* c_nsdef
429
+ for i in range(c_ns_list_len):
430
+ if prefixes_to_keep is not None:
431
+ if c_ns_list[i].ns.prefix and c_ns_list[i].ns.prefix in prefixes_to_keep:
432
+ continue
433
+ c_node = c_ns_list[i].node
434
+ c_nsdef = c_node.nsDef
435
+ if c_nsdef is c_ns_list[i].ns:
436
+ c_node.nsDef = c_node.nsDef.next
437
+ else:
438
+ while c_nsdef.next is not c_ns_list[i].ns:
439
+ c_nsdef = c_nsdef.next
440
+ c_nsdef.next = c_nsdef.next.next
441
+ tree.xmlFreeNs(c_ns_list[i].ns)
442
+
443
+ if c_ns_list is not NULL:
444
+ python.lxml_free(c_ns_list)
445
+ return 0
446
+
447
+ cdef xmlNs* _searchNsByHref(xmlNode* c_node, const_xmlChar* c_href, bint is_attribute) noexcept:
448
+ """Search a namespace declaration that covers a node (element or
449
+ attribute).
450
+
451
+ For attributes, try to find a prefixed namespace declaration
452
+ instead of the default namespaces. This helps in supporting
453
+ round-trips for attributes on elements with a different namespace.
454
+ """
455
+ cdef xmlNs* c_ns
456
+ cdef xmlNs* c_default_ns = NULL
457
+ cdef xmlNode* c_element
458
+ if c_href is NULL or c_node is NULL or c_node.type == tree.XML_ENTITY_REF_NODE:
459
+ return NULL
460
+ if tree.xmlStrcmp(c_href, tree.XML_XML_NAMESPACE) == 0:
461
+ # no special cases here, let libxml2 handle this
462
+ return tree.xmlSearchNsByHref(c_node.doc, c_node, c_href)
463
+ if c_node.type == tree.XML_ATTRIBUTE_NODE:
464
+ is_attribute = 1
465
+ while c_node is not NULL and c_node.type != tree.XML_ELEMENT_NODE:
466
+ c_node = c_node.parent
467
+ c_element = c_node
468
+ while c_node is not NULL:
469
+ if c_node.type == tree.XML_ELEMENT_NODE:
470
+ c_ns = c_node.nsDef
471
+ while c_ns is not NULL:
472
+ if c_ns.href is not NULL and tree.xmlStrcmp(c_href, c_ns.href) == 0:
473
+ if c_ns.prefix is NULL and is_attribute:
474
+ # for attributes, continue searching a named
475
+ # prefix, but keep the first default namespace
476
+ # declaration that we found
477
+ if c_default_ns is NULL:
478
+ c_default_ns = c_ns
479
+ elif tree.xmlSearchNs(
480
+ c_element.doc, c_element, c_ns.prefix) is c_ns:
481
+ # start node is in namespace scope => found!
482
+ return c_ns
483
+ c_ns = c_ns.next
484
+ if c_node is not c_element and c_node.ns is not NULL:
485
+ # optimise: the node may have the namespace itself
486
+ c_ns = c_node.ns
487
+ if c_ns.href is not NULL and tree.xmlStrcmp(c_href, c_ns.href) == 0:
488
+ if c_ns.prefix is NULL and is_attribute:
489
+ # for attributes, continue searching a named
490
+ # prefix, but keep the first default namespace
491
+ # declaration that we found
492
+ if c_default_ns is NULL:
493
+ c_default_ns = c_ns
494
+ elif tree.xmlSearchNs(
495
+ c_element.doc, c_element, c_ns.prefix) is c_ns:
496
+ # start node is in namespace scope => found!
497
+ return c_ns
498
+ c_node = c_node.parent
499
+ # nothing found => use a matching default namespace or fail
500
+ if c_default_ns is not NULL:
501
+ if tree.xmlSearchNs(c_element.doc, c_element, NULL) is c_default_ns:
502
+ return c_default_ns
503
+ return NULL
504
+
505
+ cdef int _replaceNodeByChildren(_Document doc, xmlNode* c_node) except -1:
506
+ # NOTE: this does not deallocate the node, just unlink it!
507
+ cdef xmlNode* c_parent
508
+ cdef xmlNode* c_child
509
+ if c_node.children is NULL:
510
+ tree.xmlUnlinkNode(c_node)
511
+ return 0
512
+
513
+ c_parent = c_node.parent
514
+ # fix parent links of children
515
+ c_child = c_node.children
516
+ while c_child is not NULL:
517
+ c_child.parent = c_parent
518
+ c_child = c_child.next
519
+
520
+ # fix namespace references of children if their parent's namespace
521
+ # declarations get lost
522
+ if c_node.nsDef is not NULL:
523
+ c_child = c_node.children
524
+ while c_child is not NULL:
525
+ moveNodeToDocument(doc, doc._c_doc, c_child)
526
+ c_child = c_child.next
527
+
528
+ # fix sibling links to/from child slice
529
+ if c_node.prev is NULL:
530
+ c_parent.children = c_node.children
531
+ else:
532
+ c_node.prev.next = c_node.children
533
+ c_node.children.prev = c_node.prev
534
+ if c_node.next is NULL:
535
+ c_parent.last = c_node.last
536
+ else:
537
+ c_node.next.prev = c_node.last
538
+ c_node.last.next = c_node.next
539
+
540
+ # unlink c_node
541
+ c_node.children = c_node.last = NULL
542
+ c_node.parent = c_node.next = c_node.prev = NULL
543
+ return 0
544
+
545
+ cdef unicode _attributeValue(xmlNode* c_element, xmlAttr* c_attrib_node):
546
+ c_href = _getNs(<xmlNode*>c_attrib_node)
547
+ value = tree.xmlGetNsProp(c_element, c_attrib_node.name, c_href)
548
+ try:
549
+ result = funicode(value)
550
+ finally:
551
+ tree.xmlFree(value)
552
+ return result
553
+
554
+ cdef unicode _attributeValueFromNsName(xmlNode* c_element,
555
+ const_xmlChar* c_href, const_xmlChar* c_name):
556
+ c_result = tree.xmlGetNsProp(c_element, c_name, c_href)
557
+ if c_result is NULL:
558
+ return None
559
+ try:
560
+ result = funicode(c_result)
561
+ finally:
562
+ tree.xmlFree(c_result)
563
+ return result
564
+
565
+ cdef object _getNodeAttributeValue(xmlNode* c_node, key, default):
566
+ ns, tag = _getNsTag(key)
567
+ c_href = <const_xmlChar*>NULL if ns is None else _xcstr(ns)
568
+ c_result = tree.xmlGetNsProp(c_node, _xcstr(tag), c_href)
569
+ if c_result is NULL:
570
+ # XXX free namespace that is not in use..?
571
+ return default
572
+ try:
573
+ result = funicode(c_result)
574
+ finally:
575
+ tree.xmlFree(c_result)
576
+ return result
577
+
578
+ cdef inline object _getAttributeValue(_Element element, key, default):
579
+ return _getNodeAttributeValue(element._c_node, key, default)
580
+
581
+ cdef int _setAttributeValue(_Element element, key, value) except -1:
582
+ cdef const_xmlChar* c_value
583
+ cdef xmlNs* c_ns
584
+ ns, tag = _getNsTag(key)
585
+ is_html = element._doc._parser._for_html
586
+ if not is_html:
587
+ _attributeValidOrRaise(tag)
588
+ c_tag = _xcstr(tag)
589
+ if value is None and is_html:
590
+ c_value = NULL
591
+ else:
592
+ if isinstance(value, QName):
593
+ value = _resolveQNameText(element, value)
594
+ else:
595
+ value = _utf8(value)
596
+ c_value = _xcstr(value)
597
+ if ns is None:
598
+ c_ns = NULL
599
+ else:
600
+ c_ns = element._doc._findOrBuildNodeNs(element._c_node, _xcstr(ns), NULL, 1)
601
+ tree.xmlSetNsProp(element._c_node, c_ns, c_tag, c_value)
602
+ return 0
603
+
604
+ cdef int _delAttribute(_Element element, key) except -1:
605
+ ns, tag = _getNsTag(key)
606
+ c_href = <const_xmlChar*>NULL if ns is None else _xcstr(ns)
607
+ if _delAttributeFromNsName(element._c_node, c_href, _xcstr(tag)):
608
+ raise KeyError, key
609
+ return 0
610
+
611
+ cdef int _delAttributeFromNsName(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name) noexcept:
612
+ c_attr = tree.xmlHasNsProp(c_node, c_name, c_href)
613
+ if c_attr is NULL:
614
+ # XXX free namespace that is not in use..?
615
+ return -1
616
+ tree.xmlRemoveProp(c_attr)
617
+ return 0
618
+
619
+ cdef list _collectAttributes(xmlNode* c_node, int collecttype):
620
+ """Collect all attributes of a node in a list. Depending on collecttype,
621
+ it collects either the name (1), the value (2) or the name-value tuples.
622
+ """
623
+ cdef Py_ssize_t count
624
+ c_attr = c_node.properties
625
+ count = 0
626
+ while c_attr is not NULL:
627
+ if c_attr.type == tree.XML_ATTRIBUTE_NODE:
628
+ count += 1
629
+ c_attr = c_attr.next
630
+
631
+ if not count:
632
+ return []
633
+
634
+ attributes = [None] * count
635
+ c_attr = c_node.properties
636
+ count = 0
637
+ while c_attr is not NULL:
638
+ if c_attr.type == tree.XML_ATTRIBUTE_NODE:
639
+ if collecttype == 1:
640
+ item = _namespacedName(<xmlNode*>c_attr)
641
+ elif collecttype == 2:
642
+ item = _attributeValue(c_node, c_attr)
643
+ else:
644
+ item = (_namespacedName(<xmlNode*>c_attr),
645
+ _attributeValue(c_node, c_attr))
646
+ attributes[count] = item
647
+ count += 1
648
+ c_attr = c_attr.next
649
+ return attributes
650
+
651
+ cdef object __RE_XML_ENCODING = re.compile(
652
+ r'^(<\?xml[^>]+)\s+encoding\s*=\s*["\'][^"\']*["\'](\s*\?>|)', re.U)
653
+
654
+ cdef object __REPLACE_XML_ENCODING = __RE_XML_ENCODING.sub
655
+ cdef object __HAS_XML_ENCODING = __RE_XML_ENCODING.match
656
+
657
+ cdef object _stripEncodingDeclaration(object xml_string):
658
+ # this is a hack to remove the XML encoding declaration from unicode
659
+ return __REPLACE_XML_ENCODING(r'\g<1>\g<2>', xml_string)
660
+
661
+ cdef bint _hasEncodingDeclaration(object xml_string) except -1:
662
+ # check if a (unicode) string has an XML encoding declaration
663
+ return __HAS_XML_ENCODING(xml_string) is not None
664
+
665
+ cdef inline bint _hasText(xmlNode* c_node) noexcept:
666
+ return c_node is not NULL and _textNodeOrSkip(c_node.children) is not NULL
667
+
668
+ cdef inline bint _hasTail(xmlNode* c_node) noexcept:
669
+ return c_node is not NULL and _textNodeOrSkip(c_node.next) is not NULL
670
+
671
+ cdef inline bint _hasNonWhitespaceTail(xmlNode* c_node) except -1:
672
+ return _hasNonWhitespaceText(c_node, tail=True)
673
+
674
+ cdef bint _hasNonWhitespaceText(xmlNode* c_node, bint tail=False) except -1:
675
+ c_text_node = c_node and _textNodeOrSkip(c_node.next if tail else c_node.children)
676
+ if c_text_node is NULL:
677
+ return False
678
+ while c_text_node is not NULL:
679
+ if c_text_node.content[0] != c'\0' and not _collectText(c_text_node).isspace():
680
+ return True
681
+ c_text_node = _textNodeOrSkip(c_text_node.next)
682
+ return False
683
+
684
+ cdef unicode _collectText(xmlNode* c_node):
685
+ """Collect all text nodes and return them as a unicode string.
686
+
687
+ Start collecting at c_node.
688
+
689
+ If there was no text to collect, return None
690
+ """
691
+ cdef Py_ssize_t scount
692
+ cdef xmlChar* c_text
693
+ cdef xmlNode* c_node_cur
694
+ # check for multiple text nodes
695
+ scount = 0
696
+ c_text = NULL
697
+ c_node_cur = c_node = _textNodeOrSkip(c_node)
698
+ while c_node_cur is not NULL:
699
+ if c_node_cur.content[0] != c'\0':
700
+ c_text = c_node_cur.content
701
+ scount += 1
702
+ c_node_cur = _textNodeOrSkip(c_node_cur.next)
703
+
704
+ # handle two most common cases first
705
+ if c_text is NULL:
706
+ return '' if scount > 0 else None
707
+ if scount == 1:
708
+ return funicode(c_text)
709
+
710
+ # the rest is not performance critical anymore
711
+ result = b''
712
+ while c_node is not NULL:
713
+ result += <unsigned char*>c_node.content
714
+ c_node = _textNodeOrSkip(c_node.next)
715
+ return funicode(<const_xmlChar*><unsigned char*>result)
716
+
717
+ cdef void _removeText(xmlNode* c_node) noexcept:
718
+ """Remove all text nodes.
719
+
720
+ Start removing at c_node.
721
+ """
722
+ cdef xmlNode* c_next
723
+ c_node = _textNodeOrSkip(c_node)
724
+ while c_node is not NULL:
725
+ c_next = _textNodeOrSkip(c_node.next)
726
+ tree.xmlUnlinkNode(c_node)
727
+ tree.xmlFreeNode(c_node)
728
+ c_node = c_next
729
+
730
+ cdef xmlNode* _createTextNode(xmlDoc* doc, value) except NULL:
731
+ cdef xmlNode* c_text_node
732
+ if isinstance(value, CDATA):
733
+ c_text_node = tree.xmlNewCDataBlock(
734
+ doc, _xcstr((<CDATA>value)._utf8_data),
735
+ python.PyBytes_GET_SIZE((<CDATA>value)._utf8_data))
736
+ else:
737
+ text = _utf8(value)
738
+ c_text_node = tree.xmlNewDocText(doc, _xcstr(text))
739
+ if not c_text_node:
740
+ raise MemoryError()
741
+ return c_text_node
742
+
743
+ cdef int _setNodeText(xmlNode* c_node, value) except -1:
744
+ # remove all text nodes at the start first
745
+ _removeText(c_node.children)
746
+ if value is None:
747
+ return 0
748
+ # now add new text node with value at start
749
+ c_text_node = _createTextNode(c_node.doc, value)
750
+ if c_node.children is NULL:
751
+ tree.xmlAddChild(c_node, c_text_node)
752
+ else:
753
+ tree.xmlAddPrevSibling(c_node.children, c_text_node)
754
+ return 0
755
+
756
+ cdef int _setTailText(xmlNode* c_node, value) except -1:
757
+ # remove all text nodes at the start first
758
+ _removeText(c_node.next)
759
+ if value is None:
760
+ return 0
761
+ # now append new text node with value
762
+ c_text_node = _createTextNode(c_node.doc, value)
763
+ tree.xmlAddNextSibling(c_node, c_text_node)
764
+ return 0
765
+
766
+ cdef bytes _resolveQNameText(_Element element, value):
767
+ cdef xmlNs* c_ns
768
+ ns, tag = _getNsTag(value)
769
+ if ns is None:
770
+ return tag
771
+ else:
772
+ c_ns = element._doc._findOrBuildNodeNs(
773
+ element._c_node, _xcstr(ns), NULL, 0)
774
+ return python.PyBytes_FromFormat('%s:%s', c_ns.prefix, _cstr(tag))
775
+
776
+ cdef inline bint _hasChild(xmlNode* c_node) noexcept:
777
+ return c_node is not NULL and _findChildForwards(c_node, 0) is not NULL
778
+
779
+ cdef inline Py_ssize_t _countElements(xmlNode* c_node) noexcept:
780
+ "Counts the elements within the following siblings and the node itself."
781
+ cdef Py_ssize_t count
782
+ count = 0
783
+ while c_node is not NULL:
784
+ if _isElement(c_node):
785
+ count += 1
786
+ c_node = c_node.next
787
+ return count
788
+
789
+ cdef int _findChildSlice(
790
+ slice sliceobject, xmlNode* c_parent,
791
+ xmlNode** c_start_node, Py_ssize_t* c_step, Py_ssize_t* c_length) except -1:
792
+ """Resolve a children slice.
793
+
794
+ Returns the start node, step size and the slice length in the
795
+ pointer arguments.
796
+ """
797
+ cdef Py_ssize_t start = 0, stop = 0, childcount
798
+ childcount = _countElements(c_parent.children)
799
+ if childcount == 0:
800
+ c_start_node[0] = NULL
801
+ c_length[0] = 0
802
+ if sliceobject.step is None:
803
+ c_step[0] = 1
804
+ else:
805
+ python._PyEval_SliceIndex(sliceobject.step, c_step)
806
+ return 0
807
+ python.PySlice_GetIndicesEx(
808
+ sliceobject, childcount, &start, &stop, c_step, c_length)
809
+ if start > childcount // 2:
810
+ c_start_node[0] = _findChildBackwards(c_parent, childcount - start - 1)
811
+ else:
812
+ c_start_node[0] = _findChild(c_parent, start)
813
+ return 0
814
+
815
+ cdef bint _isFullSlice(slice sliceobject) except -1:
816
+ """Conservative guess if this slice is a full slice as in ``s[:]``.
817
+ """
818
+ cdef Py_ssize_t step = 0
819
+ if sliceobject is None:
820
+ return 0
821
+ if sliceobject.start is None and \
822
+ sliceobject.stop is None:
823
+ if sliceobject.step is None:
824
+ return 1
825
+ python._PyEval_SliceIndex(sliceobject.step, &step)
826
+ if step == 1:
827
+ return 1
828
+ return 0
829
+ return 0
830
+
831
+ cdef _collectChildren(_Element element):
832
+ cdef xmlNode* c_node
833
+ cdef list result = []
834
+ c_node = element._c_node.children
835
+ if c_node is not NULL:
836
+ if not _isElement(c_node):
837
+ c_node = _nextElement(c_node)
838
+ while c_node is not NULL:
839
+ result.append(_elementFactory(element._doc, c_node))
840
+ c_node = _nextElement(c_node)
841
+ return result
842
+
843
+ cdef inline xmlNode* _findChild(xmlNode* c_node, Py_ssize_t index) noexcept:
844
+ if index < 0:
845
+ return _findChildBackwards(c_node, -index - 1)
846
+ else:
847
+ return _findChildForwards(c_node, index)
848
+
849
+ cdef inline xmlNode* _findChildForwards(xmlNode* c_node, Py_ssize_t index) noexcept:
850
+ """Return child element of c_node with index, or return NULL if not found.
851
+ """
852
+ cdef xmlNode* c_child
853
+ cdef Py_ssize_t c
854
+ c_child = c_node.children
855
+ c = 0
856
+ while c_child is not NULL:
857
+ if _isElement(c_child):
858
+ if c == index:
859
+ return c_child
860
+ c += 1
861
+ c_child = c_child.next
862
+ return NULL
863
+
864
+ cdef inline xmlNode* _findChildBackwards(xmlNode* c_node, Py_ssize_t index) noexcept:
865
+ """Return child element of c_node with index, or return NULL if not found.
866
+ Search from the end.
867
+ """
868
+ cdef xmlNode* c_child
869
+ cdef Py_ssize_t c
870
+ c_child = c_node.last
871
+ c = 0
872
+ while c_child is not NULL:
873
+ if _isElement(c_child):
874
+ if c == index:
875
+ return c_child
876
+ c += 1
877
+ c_child = c_child.prev
878
+ return NULL
879
+
880
+ cdef inline xmlNode* _textNodeOrSkip(xmlNode* c_node) noexcept nogil:
881
+ """Return the node if it's a text node. Skip over ignorable nodes in a
882
+ series of text nodes. Return NULL if a non-ignorable node is found.
883
+
884
+ This is used to skip over XInclude nodes when collecting adjacent text
885
+ nodes.
886
+ """
887
+ while c_node is not NULL:
888
+ if c_node.type == tree.XML_TEXT_NODE or \
889
+ c_node.type == tree.XML_CDATA_SECTION_NODE:
890
+ return c_node
891
+ elif c_node.type == tree.XML_XINCLUDE_START or \
892
+ c_node.type == tree.XML_XINCLUDE_END:
893
+ c_node = c_node.next
894
+ else:
895
+ return NULL
896
+ return NULL
897
+
898
+ cdef inline xmlNode* _nextElement(xmlNode* c_node) noexcept:
899
+ """Given a node, find the next sibling that is an element.
900
+ """
901
+ if c_node is NULL:
902
+ return NULL
903
+ c_node = c_node.next
904
+ while c_node is not NULL:
905
+ if _isElement(c_node):
906
+ return c_node
907
+ c_node = c_node.next
908
+ return NULL
909
+
910
+ cdef inline xmlNode* _previousElement(xmlNode* c_node) noexcept:
911
+ """Given a node, find the next sibling that is an element.
912
+ """
913
+ if c_node is NULL:
914
+ return NULL
915
+ c_node = c_node.prev
916
+ while c_node is not NULL:
917
+ if _isElement(c_node):
918
+ return c_node
919
+ c_node = c_node.prev
920
+ return NULL
921
+
922
+ cdef inline xmlNode* _parentElement(xmlNode* c_node) noexcept:
923
+ "Given a node, find the parent element."
924
+ if c_node is NULL or not _isElement(c_node):
925
+ return NULL
926
+ c_node = c_node.parent
927
+ if c_node is NULL or not _isElement(c_node):
928
+ return NULL
929
+ return c_node
930
+
931
+ cdef inline bint _tagMatches(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name) noexcept:
932
+ """Tests if the node matches namespace URI and tag name.
933
+
934
+ A node matches if it matches both c_href and c_name.
935
+
936
+ A node matches c_href if any of the following is true:
937
+ * c_href is NULL
938
+ * its namespace is NULL and c_href is the empty string
939
+ * its namespace string equals the c_href string
940
+
941
+ A node matches c_name if any of the following is true:
942
+ * c_name is NULL
943
+ * its name string equals the c_name string
944
+ """
945
+ if c_node is NULL:
946
+ return 0
947
+ if c_node.type != tree.XML_ELEMENT_NODE:
948
+ # not an element, only succeed if we match everything
949
+ return c_name is NULL and c_href is NULL
950
+ if c_name is NULL:
951
+ if c_href is NULL:
952
+ # always match
953
+ return 1
954
+ else:
955
+ c_node_href = _getNs(c_node)
956
+ if c_node_href is NULL:
957
+ return c_href[0] == c'\0'
958
+ else:
959
+ return tree.xmlStrcmp(c_node_href, c_href) == 0
960
+ elif c_href is NULL:
961
+ if _getNs(c_node) is not NULL:
962
+ return 0
963
+ return c_node.name == c_name or tree.xmlStrcmp(c_node.name, c_name) == 0
964
+ elif c_node.name == c_name or tree.xmlStrcmp(c_node.name, c_name) == 0:
965
+ c_node_href = _getNs(c_node)
966
+ if c_node_href is NULL:
967
+ return c_href[0] == c'\0'
968
+ else:
969
+ return tree.xmlStrcmp(c_node_href, c_href) == 0
970
+ else:
971
+ return 0
972
+
973
+ cdef inline bint _tagMatchesExactly(xmlNode* c_node, qname* c_qname) noexcept:
974
+ """Tests if the node matches namespace URI and tag name.
975
+
976
+ This differs from _tagMatches() in that it does not consider a
977
+ NULL value in qname.href a wildcard, and that it expects the c_name
978
+ to be taken from the doc dict, i.e. it only compares the names by
979
+ address.
980
+
981
+ A node matches if it matches both href and c_name of the qname.
982
+
983
+ A node matches c_href if any of the following is true:
984
+ * its namespace is NULL and c_href is the empty string
985
+ * its namespace string equals the c_href string
986
+
987
+ A node matches c_name if any of the following is true:
988
+ * c_name is NULL
989
+ * its name string points to the same address (!) as c_name
990
+ """
991
+ return _nsTagMatchesExactly(_getNs(c_node), c_node.name, c_qname)
992
+
993
+ cdef inline bint _nsTagMatchesExactly(const_xmlChar* c_node_href,
994
+ const_xmlChar* c_node_name,
995
+ qname* c_qname) noexcept:
996
+ """Tests if name and namespace URI match those of c_qname.
997
+
998
+ This differs from _tagMatches() in that it does not consider a
999
+ NULL value in qname.href a wildcard, and that it expects the c_name
1000
+ to be taken from the doc dict, i.e. it only compares the names by
1001
+ address.
1002
+
1003
+ A node matches if it matches both href and c_name of the qname.
1004
+
1005
+ A node matches c_href if any of the following is true:
1006
+ * its namespace is NULL and c_href is the empty string
1007
+ * its namespace string equals the c_href string
1008
+
1009
+ A node matches c_name if any of the following is true:
1010
+ * c_name is NULL
1011
+ * its name string points to the same address (!) as c_name
1012
+ """
1013
+ cdef char* c_href
1014
+ if c_qname.c_name is not NULL and c_qname.c_name is not c_node_name:
1015
+ return 0
1016
+ if c_qname.href is NULL:
1017
+ return 1
1018
+ c_href = python.__cstr(c_qname.href)
1019
+ if c_href[0] == b'\0':
1020
+ return c_node_href is NULL or c_node_href[0] == b'\0'
1021
+ elif c_node_href is NULL:
1022
+ return 0
1023
+ else:
1024
+ return tree.xmlStrcmp(<const_xmlChar*>c_href, c_node_href) == 0
1025
+
1026
+ cdef Py_ssize_t _mapTagsToQnameMatchArray(xmlDoc* c_doc, list ns_tags,
1027
+ qname* c_ns_tags, bint force_into_dict) except -1:
1028
+ """Map a sequence of (name, namespace) pairs to a qname array for efficient
1029
+ matching with _tagMatchesExactly() above.
1030
+
1031
+ Note that each qname struct in the array owns its href byte string object
1032
+ if it is not NULL.
1033
+ """
1034
+ cdef Py_ssize_t count = 0, i
1035
+ cdef bytes ns, tag
1036
+ for ns, tag in ns_tags:
1037
+ if tag is None:
1038
+ c_tag = <const_xmlChar*>NULL
1039
+ elif force_into_dict:
1040
+ c_tag = tree.xmlDictLookup(c_doc.dict, _xcstr(tag), len(tag))
1041
+ if c_tag is NULL:
1042
+ # clean up before raising the error
1043
+ for i in xrange(count):
1044
+ cpython.ref.Py_XDECREF(c_ns_tags[i].href)
1045
+ raise MemoryError()
1046
+ else:
1047
+ c_tag = tree.xmlDictExists(c_doc.dict, _xcstr(tag), len(tag))
1048
+ if c_tag is NULL:
1049
+ # not in the dict => not in the document
1050
+ continue
1051
+ c_ns_tags[count].c_name = c_tag
1052
+ if ns is None:
1053
+ c_ns_tags[count].href = NULL
1054
+ else:
1055
+ cpython.ref.Py_INCREF(ns) # keep an owned reference!
1056
+ c_ns_tags[count].href = <python.PyObject*>ns
1057
+ count += 1
1058
+ return count
1059
+
1060
+ cdef int _removeNode(_Document doc, xmlNode* c_node) except -1:
1061
+ """Unlink and free a node and subnodes if possible. Otherwise, make sure
1062
+ it's self-contained.
1063
+ """
1064
+ cdef xmlNode* c_next
1065
+ c_next = c_node.next
1066
+ tree.xmlUnlinkNode(c_node)
1067
+ _moveTail(c_next, c_node)
1068
+ if not attemptDeallocation(c_node):
1069
+ # make namespaces absolute
1070
+ moveNodeToDocument(doc, c_node.doc, c_node)
1071
+ return 0
1072
+
1073
+ cdef int _removeSiblings(xmlNode* c_element, tree.xmlElementType node_type, bint with_tail) except -1:
1074
+ cdef xmlNode* c_node
1075
+ cdef xmlNode* c_next
1076
+ c_node = c_element.next
1077
+ while c_node is not NULL:
1078
+ c_next = _nextElement(c_node)
1079
+ if c_node.type == node_type:
1080
+ if with_tail:
1081
+ _removeText(c_node.next)
1082
+ tree.xmlUnlinkNode(c_node)
1083
+ attemptDeallocation(c_node)
1084
+ c_node = c_next
1085
+ c_node = c_element.prev
1086
+ while c_node is not NULL:
1087
+ c_next = _previousElement(c_node)
1088
+ if c_node.type == node_type:
1089
+ if with_tail:
1090
+ _removeText(c_node.next)
1091
+ tree.xmlUnlinkNode(c_node)
1092
+ attemptDeallocation(c_node)
1093
+ c_node = c_next
1094
+ return 0
1095
+
1096
+ cdef void _moveTail(xmlNode* c_tail, xmlNode* c_target) noexcept:
1097
+ cdef xmlNode* c_next
1098
+ # tail support: look for any text nodes trailing this node and
1099
+ # move them too
1100
+ c_tail = _textNodeOrSkip(c_tail)
1101
+ while c_tail is not NULL:
1102
+ c_next = _textNodeOrSkip(c_tail.next)
1103
+ c_target = tree.xmlAddNextSibling(c_target, c_tail)
1104
+ c_tail = c_next
1105
+
1106
+ cdef int _copyTail(xmlNode* c_tail, xmlNode* c_target) except -1:
1107
+ cdef xmlNode* c_new_tail
1108
+ # tail copying support: look for any text nodes trailing this node and
1109
+ # copy it to the target node
1110
+ c_tail = _textNodeOrSkip(c_tail)
1111
+ while c_tail is not NULL:
1112
+ if c_target.doc is not c_tail.doc:
1113
+ c_new_tail = tree.xmlDocCopyNode(c_tail, c_target.doc, 0)
1114
+ else:
1115
+ c_new_tail = tree.xmlCopyNode(c_tail, 0)
1116
+ if c_new_tail is NULL:
1117
+ raise MemoryError()
1118
+ c_target = tree.xmlAddNextSibling(c_target, c_new_tail)
1119
+ c_tail = _textNodeOrSkip(c_tail.next)
1120
+ return 0
1121
+
1122
+ cdef int _copyNonElementSiblings(xmlNode* c_node, xmlNode* c_target) except -1:
1123
+ cdef xmlNode* c_copy
1124
+ cdef xmlNode* c_sibling = c_node
1125
+ while c_sibling.prev != NULL and \
1126
+ (c_sibling.prev.type == tree.XML_PI_NODE or
1127
+ c_sibling.prev.type == tree.XML_COMMENT_NODE or
1128
+ c_sibling.prev.type == tree.XML_DTD_NODE):
1129
+ c_sibling = c_sibling.prev
1130
+ while c_sibling != c_node:
1131
+ if c_sibling.type == tree.XML_DTD_NODE:
1132
+ c_copy = <xmlNode*>_copyDtd(<tree.xmlDtd*>c_sibling)
1133
+ if c_sibling == <xmlNode*>c_node.doc.intSubset:
1134
+ c_target.doc.intSubset = <tree.xmlDtd*>c_copy
1135
+ else: # c_sibling == c_node.doc.extSubset
1136
+ c_target.doc.extSubset = <tree.xmlDtd*>c_copy
1137
+ else:
1138
+ c_copy = tree.xmlDocCopyNode(c_sibling, c_target.doc, 1)
1139
+ if c_copy is NULL:
1140
+ raise MemoryError()
1141
+ tree.xmlAddPrevSibling(c_target, c_copy)
1142
+ c_sibling = c_sibling.next
1143
+ while c_sibling.next != NULL and \
1144
+ (c_sibling.next.type == tree.XML_PI_NODE or
1145
+ c_sibling.next.type == tree.XML_COMMENT_NODE):
1146
+ c_sibling = c_sibling.next
1147
+ c_copy = tree.xmlDocCopyNode(c_sibling, c_target.doc, 1)
1148
+ if c_copy is NULL:
1149
+ raise MemoryError()
1150
+ tree.xmlAddNextSibling(c_target, c_copy)
1151
+
1152
+ cdef int _deleteSlice(_Document doc, xmlNode* c_node,
1153
+ Py_ssize_t count, Py_ssize_t step) except -1:
1154
+ """Delete slice, ``count`` items starting with ``c_node`` with a step
1155
+ width of ``step``.
1156
+ """
1157
+ cdef xmlNode* c_next
1158
+ cdef Py_ssize_t c, i
1159
+ cdef _node_to_node_function next_element
1160
+ if c_node is NULL:
1161
+ return 0
1162
+ if step > 0:
1163
+ next_element = _nextElement
1164
+ else:
1165
+ step = -step
1166
+ next_element = _previousElement
1167
+ # now start deleting nodes
1168
+ c = 0
1169
+ c_next = c_node
1170
+ while c_node is not NULL and c < count:
1171
+ for i in range(step):
1172
+ c_next = next_element(c_next)
1173
+ if c_next is NULL:
1174
+ break
1175
+ _removeNode(doc, c_node)
1176
+ c += 1
1177
+ c_node = c_next
1178
+ return 0
1179
+
1180
+ cdef int _replaceSlice(_Element parent, xmlNode* c_node,
1181
+ Py_ssize_t slicelength, Py_ssize_t step,
1182
+ bint left_to_right, elements) except -1:
1183
+ """Replace the slice of ``count`` elements starting at ``c_node`` with
1184
+ positive step width ``step`` by the Elements in ``elements``. The
1185
+ direction is given by the boolean argument ``left_to_right``.
1186
+
1187
+ ``c_node`` may be NULL to indicate the end of the children list.
1188
+ """
1189
+ cdef xmlNode* c_orig_neighbour
1190
+ cdef xmlNode* c_next
1191
+ cdef xmlDoc* c_source_doc
1192
+ cdef _Element element
1193
+ cdef Py_ssize_t seqlength, i, c
1194
+ cdef _node_to_node_function next_element
1195
+ assert step > 0
1196
+ if left_to_right:
1197
+ next_element = _nextElement
1198
+ else:
1199
+ next_element = _previousElement
1200
+
1201
+ if not isinstance(elements, (list, tuple)):
1202
+ elements = list(elements)
1203
+
1204
+ if step != 1 or not left_to_right:
1205
+ # *replacing* children stepwise with list => check size!
1206
+ seqlength = len(elements)
1207
+ if seqlength != slicelength:
1208
+ raise ValueError, f"attempt to assign sequence of size {seqlength} " \
1209
+ f"to extended slice of size {slicelength}"
1210
+
1211
+ if c_node is NULL:
1212
+ # no children yet => add all elements straight away
1213
+ if left_to_right:
1214
+ for element in elements:
1215
+ assert element is not None, "Node must not be None"
1216
+ _appendChild(parent, element)
1217
+ else:
1218
+ for element in elements:
1219
+ assert element is not None, "Node must not be None"
1220
+ _prependChild(parent, element)
1221
+ return 0
1222
+
1223
+ # remove the elements first as some might be re-added
1224
+ if left_to_right:
1225
+ # L->R, remember left neighbour
1226
+ c_orig_neighbour = _previousElement(c_node)
1227
+ else:
1228
+ # R->L, remember right neighbour
1229
+ c_orig_neighbour = _nextElement(c_node)
1230
+
1231
+ # We remove the original slice elements one by one. Since we hold
1232
+ # a Python reference to all elements that we will insert, it is
1233
+ # safe to let _removeNode() try (and fail) to free them even if
1234
+ # the element itself or one of its descendents will be reinserted.
1235
+ c = 0
1236
+ c_next = c_node
1237
+ while c_node is not NULL and c < slicelength:
1238
+ for i in range(step):
1239
+ c_next = next_element(c_next)
1240
+ if c_next is NULL:
1241
+ break
1242
+ _removeNode(parent._doc, c_node)
1243
+ c += 1
1244
+ c_node = c_next
1245
+
1246
+ # make sure each element is inserted only once
1247
+ elements = iter(elements)
1248
+
1249
+ # find the first node right of the new insertion point
1250
+ if left_to_right:
1251
+ if c_orig_neighbour is not NULL:
1252
+ c_node = next_element(c_orig_neighbour)
1253
+ else:
1254
+ # before the first element
1255
+ c_node = _findChildForwards(parent._c_node, 0)
1256
+ elif c_orig_neighbour is NULL:
1257
+ # at the end, but reversed stepping
1258
+ # append one element and go to the next insertion point
1259
+ for element in elements:
1260
+ assert element is not None, "Node must not be None"
1261
+ _appendChild(parent, element)
1262
+ c_node = element._c_node
1263
+ if slicelength > 0:
1264
+ slicelength -= 1
1265
+ for i in range(1, step):
1266
+ c_node = next_element(c_node)
1267
+ if c_node is NULL:
1268
+ break
1269
+ break
1270
+ else:
1271
+ c_node = c_orig_neighbour
1272
+
1273
+ if left_to_right:
1274
+ # adjust step size after removing slice as we are not stepping
1275
+ # over the newly inserted elements
1276
+ step -= 1
1277
+
1278
+ # now insert elements where we removed them
1279
+ if c_node is not NULL:
1280
+ for element in elements:
1281
+ assert element is not None, "Node must not be None"
1282
+ _assertValidNode(element)
1283
+ # move element and tail over
1284
+ c_source_doc = element._c_node.doc
1285
+ c_next = element._c_node.next
1286
+ tree.xmlAddPrevSibling(c_node, element._c_node)
1287
+ _moveTail(c_next, element._c_node)
1288
+
1289
+ # integrate element into new document
1290
+ moveNodeToDocument(parent._doc, c_source_doc, element._c_node)
1291
+
1292
+ # stop at the end of the slice
1293
+ if slicelength > 0:
1294
+ slicelength -= 1
1295
+ for i in range(step):
1296
+ c_node = next_element(c_node)
1297
+ if c_node is NULL:
1298
+ break
1299
+ if c_node is NULL:
1300
+ break
1301
+ else:
1302
+ # everything inserted
1303
+ return 0
1304
+
1305
+ # append the remaining elements at the respective end
1306
+ if left_to_right:
1307
+ for element in elements:
1308
+ assert element is not None, "Node must not be None"
1309
+ _assertValidNode(element)
1310
+ _appendChild(parent, element)
1311
+ else:
1312
+ for element in elements:
1313
+ assert element is not None, "Node must not be None"
1314
+ _assertValidNode(element)
1315
+ _prependChild(parent, element)
1316
+
1317
+ return 0
1318
+
1319
+
1320
+ cdef int _linkChild(xmlNode* c_parent, xmlNode* c_node) except -1:
1321
+ """Adaptation of 'xmlAddChild()' that deep-fix the document links iteratively.
1322
+ """
1323
+ assert _isElement(c_node)
1324
+ c_node.parent = c_parent
1325
+ if c_parent.children is NULL:
1326
+ c_parent.children = c_parent.last = c_node
1327
+ else:
1328
+ c_node.prev = c_parent.last
1329
+ c_parent.last.next = c_node
1330
+ c_parent.last = c_node
1331
+
1332
+ _setTreeDoc(c_node, c_parent.doc)
1333
+ return 0
1334
+
1335
+
1336
+ cdef int _appendChild(_Element parent, _Element child) except -1:
1337
+ """Append a new child to a parent element.
1338
+ """
1339
+ c_node = child._c_node
1340
+ c_source_doc = c_node.doc
1341
+ # prevent cycles
1342
+ if _isAncestorOrSame(c_node, parent._c_node):
1343
+ raise ValueError("cannot append parent to itself")
1344
+ # store possible text node
1345
+ c_next = c_node.next
1346
+ # move node itself
1347
+ tree.xmlUnlinkNode(c_node)
1348
+ # do not call xmlAddChild() here since it would deep-traverse the tree
1349
+ _linkChild(parent._c_node, c_node)
1350
+ _moveTail(c_next, c_node)
1351
+ # uh oh, elements may be pointing to different doc when
1352
+ # parent element has moved; change them too..
1353
+ moveNodeToDocument(parent._doc, c_source_doc, c_node)
1354
+ return 0
1355
+
1356
+ cdef int _prependChild(_Element parent, _Element child) except -1:
1357
+ """Prepend a new child to a parent element.
1358
+ """
1359
+ c_node = child._c_node
1360
+ c_source_doc = c_node.doc
1361
+ # prevent cycles
1362
+ if _isAncestorOrSame(c_node, parent._c_node):
1363
+ raise ValueError("cannot append parent to itself")
1364
+ # store possible text node
1365
+ c_next = c_node.next
1366
+ # move node itself
1367
+ c_child = _findChildForwards(parent._c_node, 0)
1368
+ if c_child is NULL:
1369
+ tree.xmlUnlinkNode(c_node)
1370
+ # do not call xmlAddChild() here since it would deep-traverse the tree
1371
+ _linkChild(parent._c_node, c_node)
1372
+ else:
1373
+ tree.xmlAddPrevSibling(c_child, c_node)
1374
+ _moveTail(c_next, c_node)
1375
+ # uh oh, elements may be pointing to different doc when
1376
+ # parent element has moved; change them too..
1377
+ moveNodeToDocument(parent._doc, c_source_doc, c_node)
1378
+ return 0
1379
+
1380
+ cdef int _appendSibling(_Element element, _Element sibling) except -1:
1381
+ """Add a new sibling behind an element.
1382
+ """
1383
+ return _addSibling(element, sibling, as_next=True)
1384
+
1385
+ cdef int _prependSibling(_Element element, _Element sibling) except -1:
1386
+ """Add a new sibling before an element.
1387
+ """
1388
+ return _addSibling(element, sibling, as_next=False)
1389
+
1390
+ cdef int _addSibling(_Element element, _Element sibling, bint as_next) except -1:
1391
+ c_node = sibling._c_node
1392
+ c_source_doc = c_node.doc
1393
+ # prevent cycles
1394
+ if _isAncestorOrSame(c_node, element._c_node):
1395
+ if element._c_node is c_node:
1396
+ return 0 # nothing to do
1397
+ raise ValueError("cannot add ancestor as sibling, please break cycle first")
1398
+ # store possible text node
1399
+ c_next = c_node.next
1400
+ # move node itself
1401
+ if as_next:
1402
+ # must insert after any tail text
1403
+ c_next_node = _nextElement(element._c_node)
1404
+ if c_next_node is NULL:
1405
+ c_next_node = element._c_node
1406
+ while c_next_node.next:
1407
+ c_next_node = c_next_node.next
1408
+ tree.xmlAddNextSibling(c_next_node, c_node)
1409
+ else:
1410
+ tree.xmlAddPrevSibling(c_next_node, c_node)
1411
+ else:
1412
+ tree.xmlAddPrevSibling(element._c_node, c_node)
1413
+ _moveTail(c_next, c_node)
1414
+ # uh oh, elements may be pointing to different doc when
1415
+ # parent element has moved; change them too..
1416
+ moveNodeToDocument(element._doc, c_source_doc, c_node)
1417
+ return 0
1418
+
1419
+ cdef inline bint isutf8(const_xmlChar* s) noexcept:
1420
+ cdef xmlChar c = s[0]
1421
+ while c != c'\0':
1422
+ if c & 0x80:
1423
+ return True
1424
+ s += 1
1425
+ c = s[0]
1426
+ return False
1427
+
1428
+ cdef bint isutf8l(const_xmlChar* s, size_t length) noexcept:
1429
+ """
1430
+ Search for non-ASCII characters in the string, knowing its length in advance.
1431
+ """
1432
+ cdef unsigned int i
1433
+ cdef unsigned long non_ascii_mask
1434
+ cdef const unsigned long *lptr = <const unsigned long*> s
1435
+
1436
+ cdef const unsigned long *end = lptr + length // sizeof(unsigned long)
1437
+ if length >= sizeof(non_ascii_mask):
1438
+ # Build constant 0x80808080... mask (and let the C compiler fold it).
1439
+ non_ascii_mask = 0
1440
+ for i in range(sizeof(non_ascii_mask) // 2):
1441
+ non_ascii_mask = (non_ascii_mask << 16) | 0x8080
1442
+
1443
+ # Advance to long-aligned character before we start reading longs.
1444
+ while (<size_t>s) % sizeof(unsigned long) and s < <const_xmlChar *>end:
1445
+ if s[0] & 0x80:
1446
+ return True
1447
+ s += 1
1448
+
1449
+ # Read one long at a time
1450
+ lptr = <const unsigned long*> s
1451
+ while lptr < end:
1452
+ if lptr[0] & non_ascii_mask:
1453
+ return True
1454
+ lptr += 1
1455
+ s = <const_xmlChar *>lptr
1456
+
1457
+ while s < (<const_xmlChar *>end + length % sizeof(unsigned long)):
1458
+ if s[0] & 0x80:
1459
+ return True
1460
+ s += 1
1461
+
1462
+ return False
1463
+
1464
+ cdef int _is_valid_xml_ascii(bytes pystring) except -1:
1465
+ """Check if a string is XML ascii content."""
1466
+ cdef signed char ch
1467
+ # When ch is a *signed* char, non-ascii characters are negative integers
1468
+ # and xmlIsChar_ch does not accept them.
1469
+ for ch in pystring:
1470
+ if not tree.xmlIsChar_ch(ch):
1471
+ return 0
1472
+ return 1
1473
+
1474
+ cdef bint _is_valid_xml_utf8(bytes pystring) except -1:
1475
+ """Check if a string is like valid UTF-8 XML content."""
1476
+ cdef const_xmlChar* s = _xcstr(pystring)
1477
+ cdef const_xmlChar* c_end = s + len(pystring)
1478
+ cdef unsigned long next3 = 0
1479
+ if s < c_end - 2:
1480
+ next3 = (s[0] << 8) | (s[1])
1481
+
1482
+ while s < c_end - 2:
1483
+ next3 = 0x00ffffff & ((next3 << 8) | s[2])
1484
+ if s[0] & 0x80:
1485
+ # 0xefbfbe and 0xefbfbf are utf-8 encodings of
1486
+ # forbidden characters \ufffe and \uffff
1487
+ if next3 == 0x00efbfbe or next3 == 0x00efbfbf:
1488
+ return 0
1489
+ # 0xeda080 and 0xedbfbf are utf-8 encodings of
1490
+ # \ud800 and \udfff. Anything between them (inclusive)
1491
+ # is forbidden, because they are surrogate blocks in utf-16.
1492
+ if 0x00eda080 <= next3 <= 0x00edbfbf:
1493
+ return 0
1494
+ elif not tree.xmlIsChar_ch(s[0]):
1495
+ return 0 # invalid ascii char
1496
+ s += 1
1497
+
1498
+ while s < c_end:
1499
+ if not s[0] & 0x80 and not tree.xmlIsChar_ch(s[0]):
1500
+ return 0 # invalid ascii char
1501
+ s += 1
1502
+
1503
+ return 1
1504
+
1505
+ cdef inline unicode funicodeOrNone(const_xmlChar* s):
1506
+ return funicode(s) if s is not NULL else None
1507
+
1508
+ cdef inline unicode funicodeOrEmpty(const_xmlChar* s):
1509
+ return funicode(s) if s is not NULL else ''
1510
+
1511
+ cdef unicode funicode(const_xmlChar* s):
1512
+ return s.decode('UTF-8')
1513
+
1514
+ cdef bytes _utf8(object s):
1515
+ """Test if a string is valid user input and encode it to UTF-8.
1516
+ Reject all bytes/unicode input that contains non-XML characters.
1517
+ Reject all bytes input that contains non-ASCII characters.
1518
+ """
1519
+ cdef int valid
1520
+ cdef bytes utf8_string
1521
+ if isinstance(s, unicode):
1522
+ utf8_string = (<unicode>s).encode('utf8')
1523
+ valid = _is_valid_xml_utf8(utf8_string)
1524
+ elif isinstance(s, (bytes, bytearray)):
1525
+ utf8_string = s if type(s) is bytes else bytes(s)
1526
+ valid = _is_valid_xml_ascii(utf8_string)
1527
+ else:
1528
+ raise TypeError("Argument must be bytes or unicode, got '%.200s'" % type(s).__name__)
1529
+ if not valid:
1530
+ raise ValueError(
1531
+ "All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters")
1532
+ return utf8_string
1533
+
1534
+
1535
+ cdef bytes _utf8orNone(object s):
1536
+ return _utf8(s) if s is not None else None
1537
+
1538
+
1539
+ cdef enum:
1540
+ NO_FILE_PATH = 0
1541
+ ABS_UNIX_FILE_PATH = 1
1542
+ ABS_WIN_FILE_PATH = 2
1543
+ REL_FILE_PATH = 3
1544
+
1545
+
1546
+ cdef bint _isFilePath(const_xmlChar* c_path) noexcept:
1547
+ "simple heuristic to see if a path is a filename"
1548
+ cdef xmlChar c
1549
+ # test if it looks like an absolute Unix path or a Windows network path
1550
+ if c_path[0] == c'/':
1551
+ return ABS_UNIX_FILE_PATH
1552
+
1553
+ # test if it looks like an absolute Windows path or URL
1554
+ if c'a' <= c_path[0] <= c'z' or c'A' <= c_path[0] <= c'Z':
1555
+ c_path += 1
1556
+ if c_path[0] == c':' and c_path[1] in b'\0\\':
1557
+ return ABS_WIN_FILE_PATH # C: or C:\...
1558
+
1559
+ # test if it looks like a URL with scheme://
1560
+ while c'a' <= c_path[0] <= c'z' or c'A' <= c_path[0] <= c'Z':
1561
+ c_path += 1
1562
+ if c_path[0] == c':' and c_path[1] == c'/' and c_path[2] == c'/':
1563
+ return NO_FILE_PATH
1564
+
1565
+ # assume it's a relative path
1566
+ return REL_FILE_PATH
1567
+
1568
+
1569
+ cdef object _getFSPathOrObject(object obj):
1570
+ """
1571
+ Get the __fspath__ attribute of an object if it exists.
1572
+ Otherwise, the original object is returned.
1573
+ """
1574
+ if _isString(obj):
1575
+ return obj
1576
+ try:
1577
+ return python.PyOS_FSPath(obj)
1578
+ except TypeError:
1579
+ return obj
1580
+
1581
+
1582
+ cdef object _encodeFilename(object filename):
1583
+ """Make sure a filename is 8-bit encoded (or None).
1584
+ """
1585
+ if filename is None:
1586
+ return None
1587
+ elif isinstance(filename, bytes):
1588
+ return filename
1589
+ elif isinstance(filename, unicode):
1590
+ filename8 = (<unicode>filename).encode('utf8')
1591
+ if _isFilePath(<unsigned char*>filename8):
1592
+ try:
1593
+ return python.PyUnicode_AsEncodedString(
1594
+ filename, _C_FILENAME_ENCODING, NULL)
1595
+ except UnicodeEncodeError:
1596
+ pass
1597
+ return filename8
1598
+ else:
1599
+ raise TypeError("Argument must be string or unicode.")
1600
+
1601
+ cdef object _decodeFilename(const_xmlChar* c_path):
1602
+ """Make the filename a unicode string if we are in Py3.
1603
+ """
1604
+ return _decodeFilenameWithLength(c_path, tree.xmlStrlen(c_path))
1605
+
1606
+ cdef object _decodeFilenameWithLength(const_xmlChar* c_path, size_t c_len):
1607
+ """Make the filename a unicode string if we are in Py3.
1608
+ """
1609
+ if _isFilePath(c_path):
1610
+ try:
1611
+ return python.PyUnicode_Decode(
1612
+ <const_char*>c_path, c_len, _C_FILENAME_ENCODING, NULL)
1613
+ except UnicodeDecodeError:
1614
+ pass
1615
+ try:
1616
+ return (<unsigned char*>c_path)[:c_len].decode('UTF-8')
1617
+ except UnicodeDecodeError:
1618
+ # this is a stupid fallback, but it might still work...
1619
+ return (<unsigned char*>c_path)[:c_len].decode('latin-1', 'replace')
1620
+
1621
+ cdef object _encodeFilenameUTF8(object filename):
1622
+ """Recode filename as UTF-8. Tries ASCII, local filesystem encoding and
1623
+ UTF-8 as source encoding.
1624
+ """
1625
+ cdef char* c_filename
1626
+ if filename is None:
1627
+ return None
1628
+ elif isinstance(filename, bytes):
1629
+ if not isutf8l(<bytes>filename, len(<bytes>filename)):
1630
+ # plain ASCII!
1631
+ return filename
1632
+ c_filename = _cstr(<bytes>filename)
1633
+ try:
1634
+ # try to decode with default encoding
1635
+ filename = python.PyUnicode_Decode(
1636
+ c_filename, len(<bytes>filename),
1637
+ _C_FILENAME_ENCODING, NULL)
1638
+ except UnicodeDecodeError as decode_exc:
1639
+ try:
1640
+ # try if it's proper UTF-8
1641
+ (<bytes>filename).decode('utf8')
1642
+ return filename
1643
+ except UnicodeDecodeError:
1644
+ raise decode_exc # otherwise re-raise original exception
1645
+ if isinstance(filename, unicode):
1646
+ return (<unicode>filename).encode('utf8')
1647
+ else:
1648
+ raise TypeError("Argument must be string or unicode.")
1649
+
1650
+ cdef tuple _getNsTag(tag):
1651
+ """Given a tag, find namespace URI and tag name.
1652
+ Return None for NS uri if no namespace URI provided.
1653
+ """
1654
+ return __getNsTag(tag, 0)
1655
+
1656
+ cdef tuple _getNsTagWithEmptyNs(tag):
1657
+ """Given a tag, find namespace URI and tag name. Return None for NS uri
1658
+ if no namespace URI provided, or the empty string if namespace
1659
+ part is '{}'.
1660
+ """
1661
+ return __getNsTag(tag, 1)
1662
+
1663
+ cdef tuple __getNsTag(tag, bint empty_ns):
1664
+ cdef char* c_tag
1665
+ cdef char* c_ns_end
1666
+ cdef Py_ssize_t taglen
1667
+ cdef Py_ssize_t nslen
1668
+ cdef bytes ns = None
1669
+ # _isString() is much faster than isinstance()
1670
+ if not _isString(tag) and isinstance(tag, QName):
1671
+ tag = (<QName>tag).text
1672
+ tag = _utf8(tag)
1673
+ c_tag = _cstr(tag)
1674
+ if c_tag[0] == c'{':
1675
+ c_tag += 1
1676
+ c_ns_end = cstring_h.strchr(c_tag, c'}')
1677
+ if c_ns_end is NULL:
1678
+ raise ValueError, "Invalid tag name"
1679
+ nslen = c_ns_end - c_tag
1680
+ taglen = python.PyBytes_GET_SIZE(tag) - nslen - 2
1681
+ if taglen == 0:
1682
+ raise ValueError, "Empty tag name"
1683
+ if nslen > 0:
1684
+ ns = <bytes>c_tag[:nslen]
1685
+ elif empty_ns:
1686
+ ns = b''
1687
+ tag = <bytes>c_ns_end[1:taglen+1]
1688
+ elif python.PyBytes_GET_SIZE(tag) == 0:
1689
+ raise ValueError, "Empty tag name"
1690
+ return ns, tag
1691
+
1692
+ cdef inline int _pyXmlNameIsValid(name_utf8):
1693
+ return _xmlNameIsValid(_xcstr(name_utf8)) and b':' not in name_utf8
1694
+
1695
+ cdef inline int _pyHtmlNameIsValid(name_utf8):
1696
+ return _htmlNameIsValid(_xcstr(name_utf8))
1697
+
1698
+ cdef inline int _xmlNameIsValid(const_xmlChar* c_name) noexcept:
1699
+ return tree.xmlValidateNameValue(c_name)
1700
+
1701
+ cdef int _htmlNameIsValid(const_xmlChar* c_name) noexcept:
1702
+ if c_name is NULL or c_name[0] == c'\0':
1703
+ return 0
1704
+ while c_name[0] != c'\0':
1705
+ if c_name[0] in b'&<>/"\'\t\n\x0B\x0C\r ':
1706
+ return 0
1707
+ c_name += 1
1708
+ return 1
1709
+
1710
+ cdef bint _characterReferenceIsValid(const_xmlChar* c_name) noexcept:
1711
+ cdef bint is_hex
1712
+ if c_name[0] == c'x':
1713
+ c_name += 1
1714
+ is_hex = 1
1715
+ else:
1716
+ is_hex = 0
1717
+ if c_name[0] == c'\0':
1718
+ return 0
1719
+ while c_name[0] != c'\0':
1720
+ if c_name[0] < c'0' or c_name[0] > c'9':
1721
+ if not is_hex:
1722
+ return 0
1723
+ if not (c'a' <= c_name[0] <= c'f'):
1724
+ if not (c'A' <= c_name[0] <= c'F'):
1725
+ return 0
1726
+ c_name += 1
1727
+ return 1
1728
+
1729
+ cdef int _tagValidOrRaise(tag_utf) except -1:
1730
+ if not _pyXmlNameIsValid(tag_utf):
1731
+ raise ValueError(f"Invalid tag name {(<bytes>tag_utf).decode('utf8')!r}")
1732
+ return 0
1733
+
1734
+ cdef int _htmlTagValidOrRaise(tag_utf) except -1:
1735
+ if not _pyHtmlNameIsValid(tag_utf):
1736
+ raise ValueError(f"Invalid HTML tag name {(<bytes>tag_utf).decode('utf8')!r}")
1737
+ return 0
1738
+
1739
+ cdef int _attributeValidOrRaise(name_utf) except -1:
1740
+ if not _pyXmlNameIsValid(name_utf):
1741
+ raise ValueError(f"Invalid attribute name {(<bytes>name_utf).decode('utf8')!r}")
1742
+ return 0
1743
+
1744
+ cdef int _prefixValidOrRaise(tag_utf) except -1:
1745
+ if not _pyXmlNameIsValid(tag_utf):
1746
+ raise ValueError(f"Invalid namespace prefix {(<bytes>tag_utf).decode('utf8')!r}")
1747
+ return 0
1748
+
1749
+ cdef int _uriValidOrRaise(uri_utf) except -1:
1750
+ cdef uri.xmlURI* c_uri = uri.xmlParseURI(_cstr(uri_utf))
1751
+ if c_uri is NULL:
1752
+ raise ValueError(f"Invalid namespace URI {(<bytes>uri_utf).decode('utf8')!r}")
1753
+ uri.xmlFreeURI(c_uri)
1754
+ return 0
1755
+
1756
+ cdef inline unicode _namespacedName(xmlNode* c_node):
1757
+ return _namespacedNameFromNsName(_getNs(c_node), c_node.name)
1758
+
1759
+
1760
+ cdef unicode _namespacedNameFromNsName(const_xmlChar* c_href, const_xmlChar* c_name):
1761
+ name = funicode(c_name)
1762
+ if c_href is NULL:
1763
+ return name
1764
+ href = funicode(c_href)
1765
+ return f"{{{href}}}{name}"
1766
+
1767
+
1768
+ cdef _getFilenameForFile(source):
1769
+ """Given a Python File or Gzip object, give filename back.
1770
+
1771
+ Returns None if not a file object.
1772
+ """
1773
+ # urllib2 provides a geturl() method
1774
+ try:
1775
+ return source.geturl()
1776
+ except:
1777
+ pass
1778
+ # file instances have a name attribute
1779
+ try:
1780
+ filename = source.name
1781
+ if _isString(filename):
1782
+ return os_path_abspath(filename)
1783
+ except:
1784
+ pass
1785
+ # gzip file instances have a filename attribute (before Py3k)
1786
+ try:
1787
+ filename = source.filename
1788
+ if _isString(filename):
1789
+ return os_path_abspath(filename)
1790
+ except:
1791
+ pass
1792
+ # can't determine filename
1793
+ return None
llava_video/lib/python3.10/site-packages/lxml/cssselect.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """CSS Selectors based on XPath.
2
+
3
+ This module supports selecting XML/HTML tags based on CSS selectors.
4
+ See the `CSSSelector` class for details.
5
+
6
+ This is a thin wrapper around cssselect 0.7 or later.
7
+ """
8
+
9
+
10
+ from . import etree
11
+ try:
12
+ import cssselect as external_cssselect
13
+ except ImportError:
14
+ raise ImportError(
15
+ 'cssselect does not seem to be installed. '
16
+ 'See https://pypi.org/project/cssselect/')
17
+
18
+
19
+ SelectorSyntaxError = external_cssselect.SelectorSyntaxError
20
+ ExpressionError = external_cssselect.ExpressionError
21
+ SelectorError = external_cssselect.SelectorError
22
+
23
+
24
+ __all__ = ['SelectorSyntaxError', 'ExpressionError', 'SelectorError',
25
+ 'CSSSelector']
26
+
27
+
28
+ class LxmlTranslator(external_cssselect.GenericTranslator):
29
+ """
30
+ A custom CSS selector to XPath translator with lxml-specific extensions.
31
+ """
32
+ def xpath_contains_function(self, xpath, function):
33
+ # Defined there, removed in later drafts:
34
+ # http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors
35
+ if function.argument_types() not in (['STRING'], ['IDENT']):
36
+ raise ExpressionError(
37
+ "Expected a single string or ident for :contains(), got %r"
38
+ % function.arguments)
39
+ value = function.arguments[0].value
40
+ return xpath.add_condition(
41
+ 'contains(__lxml_internal_css:lower-case(string(.)), %s)'
42
+ % self.xpath_literal(value.lower()))
43
+
44
+
45
+ class LxmlHTMLTranslator(LxmlTranslator, external_cssselect.HTMLTranslator):
46
+ """
47
+ lxml extensions + HTML support.
48
+ """
49
+
50
+
51
+ def _make_lower_case(context, s):
52
+ return s.lower()
53
+
54
+ ns = etree.FunctionNamespace('http://codespeak.net/lxml/css/')
55
+ ns.prefix = '__lxml_internal_css'
56
+ ns['lower-case'] = _make_lower_case
57
+
58
+
59
+ class CSSSelector(etree.XPath):
60
+ """A CSS selector.
61
+
62
+ Usage::
63
+
64
+ >>> from lxml import etree, cssselect
65
+ >>> select = cssselect.CSSSelector("a tag > child")
66
+
67
+ >>> root = etree.XML("<a><b><c/><tag><child>TEXT</child></tag></b></a>")
68
+ >>> [ el.tag for el in select(root) ]
69
+ ['child']
70
+
71
+ To use CSS namespaces, you need to pass a prefix-to-namespace
72
+ mapping as ``namespaces`` keyword argument::
73
+
74
+ >>> rdfns = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
75
+ >>> select_ns = cssselect.CSSSelector('root > rdf|Description',
76
+ ... namespaces={'rdf': rdfns})
77
+
78
+ >>> rdf = etree.XML((
79
+ ... '<root xmlns:rdf="%s">'
80
+ ... '<rdf:Description>blah</rdf:Description>'
81
+ ... '</root>') % rdfns)
82
+ >>> [(el.tag, el.text) for el in select_ns(rdf)]
83
+ [('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description', 'blah')]
84
+
85
+ """
86
+ def __init__(self, css, namespaces=None, translator='xml'):
87
+ if translator == 'xml':
88
+ translator = LxmlTranslator()
89
+ elif translator == 'html':
90
+ translator = LxmlHTMLTranslator()
91
+ elif translator == 'xhtml':
92
+ translator = LxmlHTMLTranslator(xhtml=True)
93
+ path = translator.css_to_xpath(css)
94
+ super().__init__(path, namespaces=namespaces)
95
+ self.css = css
96
+
97
+ def __repr__(self):
98
+ return '<%s %x for %r>' % (
99
+ self.__class__.__name__,
100
+ abs(id(self)),
101
+ self.css)
llava_video/lib/python3.10/site-packages/lxml/docloader.pxi ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Custom resolver API
2
+
3
+ ctypedef enum _InputDocumentDataType:
4
+ PARSER_DATA_INVALID
5
+ PARSER_DATA_EMPTY
6
+ PARSER_DATA_STRING
7
+ PARSER_DATA_FILENAME
8
+ PARSER_DATA_FILE
9
+
10
+ @cython.final
11
+ @cython.internal
12
+ cdef class _InputDocument:
13
+ cdef _InputDocumentDataType _type
14
+ cdef bytes _data_bytes
15
+ cdef object _filename
16
+ cdef object _file
17
+ cdef bint _close_file
18
+
19
+ def __cinit__(self):
20
+ self._type = PARSER_DATA_INVALID
21
+
22
+
23
+ cdef class Resolver:
24
+ "This is the base class of all resolvers."
25
+ def resolve(self, system_url, public_id, context):
26
+ """resolve(self, system_url, public_id, context)
27
+
28
+ Override this method to resolve an external source by
29
+ ``system_url`` and ``public_id``. The third argument is an
30
+ opaque context object.
31
+
32
+ Return the result of one of the ``resolve_*()`` methods.
33
+ """
34
+ return None
35
+
36
+ def resolve_empty(self, context):
37
+ """resolve_empty(self, context)
38
+
39
+ Return an empty input document.
40
+
41
+ Pass context as parameter.
42
+ """
43
+ cdef _InputDocument doc_ref
44
+ doc_ref = _InputDocument()
45
+ doc_ref._type = PARSER_DATA_EMPTY
46
+ return doc_ref
47
+
48
+ def resolve_string(self, string, context, *, base_url=None):
49
+ """resolve_string(self, string, context, base_url=None)
50
+
51
+ Return a parsable string as input document.
52
+
53
+ Pass data string and context as parameters. You can pass the
54
+ source URL or filename through the ``base_url`` keyword
55
+ argument.
56
+ """
57
+ cdef _InputDocument doc_ref
58
+ if isinstance(string, unicode):
59
+ string = (<unicode>string).encode('utf8')
60
+ elif not isinstance(string, bytes):
61
+ raise TypeError, "argument must be a byte string or unicode string"
62
+ doc_ref = _InputDocument()
63
+ doc_ref._type = PARSER_DATA_STRING
64
+ doc_ref._data_bytes = string
65
+ if base_url is not None:
66
+ doc_ref._filename = _encodeFilename(base_url)
67
+ return doc_ref
68
+
69
+ def resolve_filename(self, filename, context):
70
+ """resolve_filename(self, filename, context)
71
+
72
+ Return the name of a parsable file as input document.
73
+
74
+ Pass filename and context as parameters. You can also pass a
75
+ URL with an HTTP, FTP or file target.
76
+ """
77
+ cdef _InputDocument doc_ref
78
+ doc_ref = _InputDocument()
79
+ doc_ref._type = PARSER_DATA_FILENAME
80
+ doc_ref._filename = _encodeFilename(filename)
81
+ return doc_ref
82
+
83
+ def resolve_file(self, f, context, *, base_url=None, bint close=True):
84
+ """resolve_file(self, f, context, base_url=None, close=True)
85
+
86
+ Return an open file-like object as input document.
87
+
88
+ Pass open file and context as parameters. You can pass the
89
+ base URL or filename of the file through the ``base_url``
90
+ keyword argument. If the ``close`` flag is True (the
91
+ default), the file will be closed after reading.
92
+
93
+ Note that using ``.resolve_filename()`` is more efficient,
94
+ especially in threaded environments.
95
+ """
96
+ cdef _InputDocument doc_ref
97
+ try:
98
+ f.read
99
+ except AttributeError:
100
+ raise TypeError, "Argument is not a file-like object"
101
+ doc_ref = _InputDocument()
102
+ doc_ref._type = PARSER_DATA_FILE
103
+ if base_url is not None:
104
+ doc_ref._filename = _encodeFilename(base_url)
105
+ else:
106
+ doc_ref._filename = _getFilenameForFile(f)
107
+ doc_ref._close_file = close
108
+ doc_ref._file = f
109
+ return doc_ref
110
+
111
+ @cython.final
112
+ @cython.internal
113
+ cdef class _ResolverRegistry:
114
+ cdef object _resolvers
115
+ cdef Resolver _default_resolver
116
+ def __cinit__(self, Resolver default_resolver=None):
117
+ self._resolvers = set()
118
+ self._default_resolver = default_resolver
119
+
120
+ def add(self, Resolver resolver not None):
121
+ """add(self, resolver)
122
+
123
+ Register a resolver.
124
+
125
+ For each requested entity, the 'resolve' method of the resolver will
126
+ be called and the result will be passed to the parser. If this method
127
+ returns None, the request will be delegated to other resolvers or the
128
+ default resolver. The resolvers will be tested in an arbitrary order
129
+ until the first match is found.
130
+ """
131
+ self._resolvers.add(resolver)
132
+
133
+ def remove(self, resolver):
134
+ "remove(self, resolver)"
135
+ self._resolvers.discard(resolver)
136
+
137
+ cdef _ResolverRegistry _copy(self):
138
+ cdef _ResolverRegistry registry
139
+ registry = _ResolverRegistry(self._default_resolver)
140
+ registry._resolvers = self._resolvers.copy()
141
+ return registry
142
+
143
+ def copy(self):
144
+ "copy(self)"
145
+ return self._copy()
146
+
147
+ def resolve(self, system_url, public_id, context):
148
+ "resolve(self, system_url, public_id, context)"
149
+ for resolver in self._resolvers:
150
+ result = resolver.resolve(system_url, public_id, context)
151
+ if result is not None:
152
+ return result
153
+ if self._default_resolver is None:
154
+ return None
155
+ return self._default_resolver.resolve(system_url, public_id, context)
156
+
157
+ def __repr__(self):
158
+ return repr(self._resolvers)
159
+
160
+
161
+ @cython.internal
162
+ cdef class _ResolverContext(_ExceptionContext):
163
+ cdef _ResolverRegistry _resolvers
164
+ cdef _TempStore _storage
165
+
166
+ cdef int clear(self) except -1:
167
+ _ExceptionContext.clear(self)
168
+ self._storage.clear()
169
+ return 0
170
+
171
+
172
+ cdef _initResolverContext(_ResolverContext context,
173
+ _ResolverRegistry resolvers):
174
+ if resolvers is None:
175
+ context._resolvers = _ResolverRegistry()
176
+ else:
177
+ context._resolvers = resolvers
178
+ context._storage = _TempStore()
llava_video/lib/python3.10/site-packages/lxml/doctestcompare.py ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ lxml-based doctest output comparison.
3
+
4
+ Note: normally, you should just import the `lxml.usedoctest` and
5
+ `lxml.html.usedoctest` modules from within a doctest, instead of this
6
+ one::
7
+
8
+ >>> import lxml.usedoctest # for XML output
9
+
10
+ >>> import lxml.html.usedoctest # for HTML output
11
+
12
+ To use this module directly, you must call ``lxmldoctest.install()``,
13
+ which will cause doctest to use this in all subsequent calls.
14
+
15
+ This changes the way output is checked and comparisons are made for
16
+ XML or HTML-like content.
17
+
18
+ XML or HTML content is noticed because the example starts with ``<``
19
+ (it's HTML if it starts with ``<html``). You can also use the
20
+ ``PARSE_HTML`` and ``PARSE_XML`` flags to force parsing.
21
+
22
+ Some rough wildcard-like things are allowed. Whitespace is generally
23
+ ignored (except in attributes). In text (attributes and text in the
24
+ body) you can use ``...`` as a wildcard. In an example it also
25
+ matches any trailing tags in the element, though it does not match
26
+ leading tags. You may create a tag ``<any>`` or include an ``any``
27
+ attribute in the tag. An ``any`` tag matches any tag, while the
28
+ attribute matches any and all attributes.
29
+
30
+ When a match fails, the reformatted example and gotten text is
31
+ displayed (indented), and a rough diff-like output is given. Anything
32
+ marked with ``+`` is in the output but wasn't supposed to be, and
33
+ similarly ``-`` means its in the example but wasn't in the output.
34
+
35
+ You can disable parsing on one line with ``# doctest:+NOPARSE_MARKUP``
36
+ """
37
+
38
+ from lxml import etree
39
+ import sys
40
+ import re
41
+ import doctest
42
+ try:
43
+ from html import escape as html_escape
44
+ except ImportError:
45
+ from cgi import escape as html_escape
46
+
47
+ __all__ = ['PARSE_HTML', 'PARSE_XML', 'NOPARSE_MARKUP', 'LXMLOutputChecker',
48
+ 'LHTMLOutputChecker', 'install', 'temp_install']
49
+
50
+ PARSE_HTML = doctest.register_optionflag('PARSE_HTML')
51
+ PARSE_XML = doctest.register_optionflag('PARSE_XML')
52
+ NOPARSE_MARKUP = doctest.register_optionflag('NOPARSE_MARKUP')
53
+
54
+ OutputChecker = doctest.OutputChecker
55
+
56
+ def strip(v):
57
+ if v is None:
58
+ return None
59
+ else:
60
+ return v.strip()
61
+
62
+ def norm_whitespace(v):
63
+ return _norm_whitespace_re.sub(' ', v)
64
+
65
+ _html_parser = etree.HTMLParser(recover=False, remove_blank_text=True)
66
+
67
+ def html_fromstring(html):
68
+ return etree.fromstring(html, _html_parser)
69
+
70
+ # We use this to distinguish repr()s from elements:
71
+ _repr_re = re.compile(r'^<[^>]+ (at|object) ')
72
+ _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
73
+
74
+ class LXMLOutputChecker(OutputChecker):
75
+
76
+ empty_tags = (
77
+ 'param', 'img', 'area', 'br', 'basefont', 'input',
78
+ 'base', 'meta', 'link', 'col')
79
+
80
+ def get_default_parser(self):
81
+ return etree.XML
82
+
83
+ def check_output(self, want, got, optionflags):
84
+ alt_self = getattr(self, '_temp_override_self', None)
85
+ if alt_self is not None:
86
+ super_method = self._temp_call_super_check_output
87
+ self = alt_self
88
+ else:
89
+ super_method = OutputChecker.check_output
90
+ parser = self.get_parser(want, got, optionflags)
91
+ if not parser:
92
+ return super_method(
93
+ self, want, got, optionflags)
94
+ try:
95
+ want_doc = parser(want)
96
+ except etree.XMLSyntaxError:
97
+ return False
98
+ try:
99
+ got_doc = parser(got)
100
+ except etree.XMLSyntaxError:
101
+ return False
102
+ return self.compare_docs(want_doc, got_doc)
103
+
104
+ def get_parser(self, want, got, optionflags):
105
+ parser = None
106
+ if NOPARSE_MARKUP & optionflags:
107
+ return None
108
+ if PARSE_HTML & optionflags:
109
+ parser = html_fromstring
110
+ elif PARSE_XML & optionflags:
111
+ parser = etree.XML
112
+ elif (want.strip().lower().startswith('<html')
113
+ and got.strip().startswith('<html')):
114
+ parser = html_fromstring
115
+ elif (self._looks_like_markup(want)
116
+ and self._looks_like_markup(got)):
117
+ parser = self.get_default_parser()
118
+ return parser
119
+
120
+ def _looks_like_markup(self, s):
121
+ s = s.strip()
122
+ return (s.startswith('<')
123
+ and not _repr_re.search(s))
124
+
125
+ def compare_docs(self, want, got):
126
+ if not self.tag_compare(want.tag, got.tag):
127
+ return False
128
+ if not self.text_compare(want.text, got.text, True):
129
+ return False
130
+ if not self.text_compare(want.tail, got.tail, True):
131
+ return False
132
+ if 'any' not in want.attrib:
133
+ want_keys = sorted(want.attrib.keys())
134
+ got_keys = sorted(got.attrib.keys())
135
+ if want_keys != got_keys:
136
+ return False
137
+ for key in want_keys:
138
+ if not self.text_compare(want.attrib[key], got.attrib[key], False):
139
+ return False
140
+ if want.text != '...' or len(want):
141
+ want_children = list(want)
142
+ got_children = list(got)
143
+ while want_children or got_children:
144
+ if not want_children or not got_children:
145
+ return False
146
+ want_first = want_children.pop(0)
147
+ got_first = got_children.pop(0)
148
+ if not self.compare_docs(want_first, got_first):
149
+ return False
150
+ if not got_children and want_first.tail == '...':
151
+ break
152
+ return True
153
+
154
+ def text_compare(self, want, got, strip):
155
+ want = want or ''
156
+ got = got or ''
157
+ if strip:
158
+ want = norm_whitespace(want).strip()
159
+ got = norm_whitespace(got).strip()
160
+ want = '^%s$' % re.escape(want)
161
+ want = want.replace(r'\.\.\.', '.*')
162
+ if re.search(want, got):
163
+ return True
164
+ else:
165
+ return False
166
+
167
+ def tag_compare(self, want, got):
168
+ if want == 'any':
169
+ return True
170
+ if (not isinstance(want, (str, bytes))
171
+ or not isinstance(got, (str, bytes))):
172
+ return want == got
173
+ want = want or ''
174
+ got = got or ''
175
+ if want.startswith('{...}'):
176
+ # Ellipsis on the namespace
177
+ return want.split('}')[-1] == got.split('}')[-1]
178
+ else:
179
+ return want == got
180
+
181
+ def output_difference(self, example, got, optionflags):
182
+ want = example.want
183
+ parser = self.get_parser(want, got, optionflags)
184
+ errors = []
185
+ if parser is not None:
186
+ try:
187
+ want_doc = parser(want)
188
+ except etree.XMLSyntaxError:
189
+ e = sys.exc_info()[1]
190
+ errors.append('In example: %s' % e)
191
+ try:
192
+ got_doc = parser(got)
193
+ except etree.XMLSyntaxError:
194
+ e = sys.exc_info()[1]
195
+ errors.append('In actual output: %s' % e)
196
+ if parser is None or errors:
197
+ value = OutputChecker.output_difference(
198
+ self, example, got, optionflags)
199
+ if errors:
200
+ errors.append(value)
201
+ return '\n'.join(errors)
202
+ else:
203
+ return value
204
+ html = parser is html_fromstring
205
+ diff_parts = ['Expected:',
206
+ self.format_doc(want_doc, html, 2),
207
+ 'Got:',
208
+ self.format_doc(got_doc, html, 2),
209
+ 'Diff:',
210
+ self.collect_diff(want_doc, got_doc, html, 2)]
211
+ return '\n'.join(diff_parts)
212
+
213
+ def html_empty_tag(self, el, html=True):
214
+ if not html:
215
+ return False
216
+ if el.tag not in self.empty_tags:
217
+ return False
218
+ if el.text or len(el):
219
+ # This shouldn't happen (contents in an empty tag)
220
+ return False
221
+ return True
222
+
223
+ def format_doc(self, doc, html, indent, prefix=''):
224
+ parts = []
225
+ if not len(doc):
226
+ # No children...
227
+ parts.append(' '*indent)
228
+ parts.append(prefix)
229
+ parts.append(self.format_tag(doc))
230
+ if not self.html_empty_tag(doc, html):
231
+ if strip(doc.text):
232
+ parts.append(self.format_text(doc.text))
233
+ parts.append(self.format_end_tag(doc))
234
+ if strip(doc.tail):
235
+ parts.append(self.format_text(doc.tail))
236
+ parts.append('\n')
237
+ return ''.join(parts)
238
+ parts.append(' '*indent)
239
+ parts.append(prefix)
240
+ parts.append(self.format_tag(doc))
241
+ if not self.html_empty_tag(doc, html):
242
+ parts.append('\n')
243
+ if strip(doc.text):
244
+ parts.append(' '*indent)
245
+ parts.append(self.format_text(doc.text))
246
+ parts.append('\n')
247
+ for el in doc:
248
+ parts.append(self.format_doc(el, html, indent+2))
249
+ parts.append(' '*indent)
250
+ parts.append(self.format_end_tag(doc))
251
+ parts.append('\n')
252
+ if strip(doc.tail):
253
+ parts.append(' '*indent)
254
+ parts.append(self.format_text(doc.tail))
255
+ parts.append('\n')
256
+ return ''.join(parts)
257
+
258
+ def format_text(self, text, strip=True):
259
+ if text is None:
260
+ return ''
261
+ if strip:
262
+ text = text.strip()
263
+ return html_escape(text, 1)
264
+
265
+ def format_tag(self, el):
266
+ attrs = []
267
+ if isinstance(el, etree.CommentBase):
268
+ # FIXME: probably PIs should be handled specially too?
269
+ return '<!--'
270
+ for name, value in sorted(el.attrib.items()):
271
+ attrs.append('%s="%s"' % (name, self.format_text(value, False)))
272
+ if not attrs:
273
+ return '<%s>' % el.tag
274
+ return '<%s %s>' % (el.tag, ' '.join(attrs))
275
+
276
+ def format_end_tag(self, el):
277
+ if isinstance(el, etree.CommentBase):
278
+ # FIXME: probably PIs should be handled specially too?
279
+ return '-->'
280
+ return '</%s>' % el.tag
281
+
282
+ def collect_diff(self, want, got, html, indent):
283
+ parts = []
284
+ if not len(want) and not len(got):
285
+ parts.append(' '*indent)
286
+ parts.append(self.collect_diff_tag(want, got))
287
+ if not self.html_empty_tag(got, html):
288
+ parts.append(self.collect_diff_text(want.text, got.text))
289
+ parts.append(self.collect_diff_end_tag(want, got))
290
+ parts.append(self.collect_diff_text(want.tail, got.tail))
291
+ parts.append('\n')
292
+ return ''.join(parts)
293
+ parts.append(' '*indent)
294
+ parts.append(self.collect_diff_tag(want, got))
295
+ parts.append('\n')
296
+ if strip(want.text) or strip(got.text):
297
+ parts.append(' '*indent)
298
+ parts.append(self.collect_diff_text(want.text, got.text))
299
+ parts.append('\n')
300
+ want_children = list(want)
301
+ got_children = list(got)
302
+ while want_children or got_children:
303
+ if not want_children:
304
+ parts.append(self.format_doc(got_children.pop(0), html, indent+2, '+'))
305
+ continue
306
+ if not got_children:
307
+ parts.append(self.format_doc(want_children.pop(0), html, indent+2, '-'))
308
+ continue
309
+ parts.append(self.collect_diff(
310
+ want_children.pop(0), got_children.pop(0), html, indent+2))
311
+ parts.append(' '*indent)
312
+ parts.append(self.collect_diff_end_tag(want, got))
313
+ parts.append('\n')
314
+ if strip(want.tail) or strip(got.tail):
315
+ parts.append(' '*indent)
316
+ parts.append(self.collect_diff_text(want.tail, got.tail))
317
+ parts.append('\n')
318
+ return ''.join(parts)
319
+
320
+ def collect_diff_tag(self, want, got):
321
+ if not self.tag_compare(want.tag, got.tag):
322
+ tag = '%s (got: %s)' % (want.tag, got.tag)
323
+ else:
324
+ tag = got.tag
325
+ attrs = []
326
+ any = want.tag == 'any' or 'any' in want.attrib
327
+ for name, value in sorted(got.attrib.items()):
328
+ if name not in want.attrib and not any:
329
+ attrs.append('+%s="%s"' % (name, self.format_text(value, False)))
330
+ else:
331
+ if name in want.attrib:
332
+ text = self.collect_diff_text(want.attrib[name], value, False)
333
+ else:
334
+ text = self.format_text(value, False)
335
+ attrs.append('%s="%s"' % (name, text))
336
+ if not any:
337
+ for name, value in sorted(want.attrib.items()):
338
+ if name in got.attrib:
339
+ continue
340
+ attrs.append('-%s="%s"' % (name, self.format_text(value, False)))
341
+ if attrs:
342
+ tag = '<%s %s>' % (tag, ' '.join(attrs))
343
+ else:
344
+ tag = '<%s>' % tag
345
+ return tag
346
+
347
+ def collect_diff_end_tag(self, want, got):
348
+ if want.tag != got.tag:
349
+ tag = '%s (got: %s)' % (want.tag, got.tag)
350
+ else:
351
+ tag = got.tag
352
+ return '</%s>' % tag
353
+
354
+ def collect_diff_text(self, want, got, strip=True):
355
+ if self.text_compare(want, got, strip):
356
+ if not got:
357
+ return ''
358
+ return self.format_text(got, strip)
359
+ text = '%s (got: %s)' % (want, got)
360
+ return self.format_text(text, strip)
361
+
362
+ class LHTMLOutputChecker(LXMLOutputChecker):
363
+ def get_default_parser(self):
364
+ return html_fromstring
365
+
366
+ def install(html=False):
367
+ """
368
+ Install doctestcompare for all future doctests.
369
+
370
+ If html is true, then by default the HTML parser will be used;
371
+ otherwise the XML parser is used.
372
+ """
373
+ if html:
374
+ doctest.OutputChecker = LHTMLOutputChecker
375
+ else:
376
+ doctest.OutputChecker = LXMLOutputChecker
377
+
378
+ def temp_install(html=False, del_module=None):
379
+ """
380
+ Use this *inside* a doctest to enable this checker for this
381
+ doctest only.
382
+
383
+ If html is true, then by default the HTML parser will be used;
384
+ otherwise the XML parser is used.
385
+ """
386
+ if html:
387
+ Checker = LHTMLOutputChecker
388
+ else:
389
+ Checker = LXMLOutputChecker
390
+ frame = _find_doctest_frame()
391
+ dt_self = frame.f_locals['self']
392
+ checker = Checker()
393
+ old_checker = dt_self._checker
394
+ dt_self._checker = checker
395
+ # The unfortunate thing is that there is a local variable 'check'
396
+ # in the function that runs the doctests, that is a bound method
397
+ # into the output checker. We have to update that. We can't
398
+ # modify the frame, so we have to modify the object in place. The
399
+ # only way to do this is to actually change the func_code
400
+ # attribute of the method. We change it, and then wait for
401
+ # __record_outcome to be run, which signals the end of the __run
402
+ # method, at which point we restore the previous check_output
403
+ # implementation.
404
+ check_func = frame.f_locals['check'].__func__
405
+ checker_check_func = checker.check_output.__func__
406
+ # Because we can't patch up func_globals, this is the only global
407
+ # in check_output that we care about:
408
+ doctest.etree = etree
409
+ _RestoreChecker(dt_self, old_checker, checker,
410
+ check_func, checker_check_func,
411
+ del_module)
412
+
413
+ class _RestoreChecker:
414
+ def __init__(self, dt_self, old_checker, new_checker, check_func, clone_func,
415
+ del_module):
416
+ self.dt_self = dt_self
417
+ self.checker = old_checker
418
+ self.checker._temp_call_super_check_output = self.call_super
419
+ self.checker._temp_override_self = new_checker
420
+ self.check_func = check_func
421
+ self.clone_func = clone_func
422
+ self.del_module = del_module
423
+ self.install_clone()
424
+ self.install_dt_self()
425
+ def install_clone(self):
426
+ self.func_code = self.check_func.__code__
427
+ self.func_globals = self.check_func.__globals__
428
+ self.check_func.__code__ = self.clone_func.__code__
429
+ def uninstall_clone(self):
430
+ self.check_func.__code__ = self.func_code
431
+ def install_dt_self(self):
432
+ self.prev_func = self.dt_self._DocTestRunner__record_outcome
433
+ self.dt_self._DocTestRunner__record_outcome = self
434
+ def uninstall_dt_self(self):
435
+ self.dt_self._DocTestRunner__record_outcome = self.prev_func
436
+ def uninstall_module(self):
437
+ if self.del_module:
438
+ import sys
439
+ del sys.modules[self.del_module]
440
+ if '.' in self.del_module:
441
+ package, module = self.del_module.rsplit('.', 1)
442
+ package_mod = sys.modules[package]
443
+ delattr(package_mod, module)
444
+ def __call__(self, *args, **kw):
445
+ self.uninstall_clone()
446
+ self.uninstall_dt_self()
447
+ del self.checker._temp_override_self
448
+ del self.checker._temp_call_super_check_output
449
+ result = self.prev_func(*args, **kw)
450
+ self.uninstall_module()
451
+ return result
452
+ def call_super(self, *args, **kw):
453
+ self.uninstall_clone()
454
+ try:
455
+ return self.check_func(*args, **kw)
456
+ finally:
457
+ self.install_clone()
458
+
459
+ def _find_doctest_frame():
460
+ import sys
461
+ frame = sys._getframe(1)
462
+ while frame:
463
+ l = frame.f_locals
464
+ if 'BOOM' in l:
465
+ # Sign of doctest
466
+ return frame
467
+ frame = frame.f_back
468
+ raise LookupError(
469
+ "Could not find doctest (only use this function *inside* a doctest)")
470
+
471
+ __test__ = {
472
+ 'basic': '''
473
+ >>> temp_install()
474
+ >>> print """<xml a="1" b="2">stuff</xml>"""
475
+ <xml b="2" a="1">...</xml>
476
+ >>> print """<xml xmlns="http://example.com"><tag attr="bar" /></xml>"""
477
+ <xml xmlns="...">
478
+ <tag attr="..." />
479
+ </xml>
480
+ >>> print """<xml>blahblahblah<foo /></xml>""" # doctest: +NOPARSE_MARKUP, +ELLIPSIS
481
+ <xml>...foo /></xml>
482
+ '''}
483
+
484
+ if __name__ == '__main__':
485
+ import doctest
486
+ doctest.testmod()
487
+
488
+
llava_video/lib/python3.10/site-packages/lxml/dtd.pxi ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # support for DTD validation
2
+ from lxml.includes cimport dtdvalid
3
+
4
+ cdef class DTDError(LxmlError):
5
+ """Base class for DTD errors.
6
+ """
7
+
8
+ cdef class DTDParseError(DTDError):
9
+ """Error while parsing a DTD.
10
+ """
11
+
12
+ cdef class DTDValidateError(DTDError):
13
+ """Error while validating an XML document with a DTD.
14
+ """
15
+
16
+
17
+ cdef inline int _assertValidDTDNode(node, void *c_node) except -1:
18
+ assert c_node is not NULL, "invalid DTD proxy at %s" % id(node)
19
+
20
+
21
+ @cython.final
22
+ @cython.internal
23
+ @cython.freelist(8)
24
+ cdef class _DTDElementContentDecl:
25
+ cdef DTD _dtd
26
+ cdef tree.xmlElementContent* _c_node
27
+
28
+ def __repr__(self):
29
+ return "<%s.%s object name=%r type=%r occur=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.type, self.occur, id(self))
30
+
31
+ @property
32
+ def name(self):
33
+ _assertValidDTDNode(self, self._c_node)
34
+ return funicodeOrNone(self._c_node.name)
35
+
36
+ @property
37
+ def type(self):
38
+ _assertValidDTDNode(self, self._c_node)
39
+ cdef int type = self._c_node.type
40
+ if type == tree.XML_ELEMENT_CONTENT_PCDATA:
41
+ return "pcdata"
42
+ elif type == tree.XML_ELEMENT_CONTENT_ELEMENT:
43
+ return "element"
44
+ elif type == tree.XML_ELEMENT_CONTENT_SEQ:
45
+ return "seq"
46
+ elif type == tree.XML_ELEMENT_CONTENT_OR:
47
+ return "or"
48
+ else:
49
+ return None
50
+
51
+ @property
52
+ def occur(self):
53
+ _assertValidDTDNode(self, self._c_node)
54
+ cdef int occur = self._c_node.ocur
55
+ if occur == tree.XML_ELEMENT_CONTENT_ONCE:
56
+ return "once"
57
+ elif occur == tree.XML_ELEMENT_CONTENT_OPT:
58
+ return "opt"
59
+ elif occur == tree.XML_ELEMENT_CONTENT_MULT:
60
+ return "mult"
61
+ elif occur == tree.XML_ELEMENT_CONTENT_PLUS:
62
+ return "plus"
63
+ else:
64
+ return None
65
+
66
+ @property
67
+ def left(self):
68
+ _assertValidDTDNode(self, self._c_node)
69
+ c1 = self._c_node.c1
70
+ if c1:
71
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
72
+ node._dtd = self._dtd
73
+ node._c_node = <tree.xmlElementContent*>c1
74
+ return node
75
+ else:
76
+ return None
77
+
78
+ @property
79
+ def right(self):
80
+ _assertValidDTDNode(self, self._c_node)
81
+ c2 = self._c_node.c2
82
+ if c2:
83
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
84
+ node._dtd = self._dtd
85
+ node._c_node = <tree.xmlElementContent*>c2
86
+ return node
87
+ else:
88
+ return None
89
+
90
+
91
+ @cython.final
92
+ @cython.internal
93
+ @cython.freelist(8)
94
+ cdef class _DTDAttributeDecl:
95
+ cdef DTD _dtd
96
+ cdef tree.xmlAttribute* _c_node
97
+
98
+ def __repr__(self):
99
+ return "<%s.%s object name=%r elemname=%r prefix=%r type=%r default=%r default_value=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.elemname, self.prefix, self.type, self.default, self.default_value, id(self))
100
+
101
+ @property
102
+ def name(self):
103
+ _assertValidDTDNode(self, self._c_node)
104
+ return funicodeOrNone(self._c_node.name)
105
+
106
+ @property
107
+ def elemname(self):
108
+ _assertValidDTDNode(self, self._c_node)
109
+ return funicodeOrNone(self._c_node.elem)
110
+
111
+ @property
112
+ def prefix(self):
113
+ _assertValidDTDNode(self, self._c_node)
114
+ return funicodeOrNone(self._c_node.prefix)
115
+
116
+ @property
117
+ def type(self):
118
+ _assertValidDTDNode(self, self._c_node)
119
+ cdef int type = self._c_node.atype
120
+ if type == tree.XML_ATTRIBUTE_CDATA:
121
+ return "cdata"
122
+ elif type == tree.XML_ATTRIBUTE_ID:
123
+ return "id"
124
+ elif type == tree.XML_ATTRIBUTE_IDREF:
125
+ return "idref"
126
+ elif type == tree.XML_ATTRIBUTE_IDREFS:
127
+ return "idrefs"
128
+ elif type == tree.XML_ATTRIBUTE_ENTITY:
129
+ return "entity"
130
+ elif type == tree.XML_ATTRIBUTE_ENTITIES:
131
+ return "entities"
132
+ elif type == tree.XML_ATTRIBUTE_NMTOKEN:
133
+ return "nmtoken"
134
+ elif type == tree.XML_ATTRIBUTE_NMTOKENS:
135
+ return "nmtokens"
136
+ elif type == tree.XML_ATTRIBUTE_ENUMERATION:
137
+ return "enumeration"
138
+ elif type == tree.XML_ATTRIBUTE_NOTATION:
139
+ return "notation"
140
+ else:
141
+ return None
142
+
143
+ @property
144
+ def default(self):
145
+ _assertValidDTDNode(self, self._c_node)
146
+ cdef int default = self._c_node.def_
147
+ if default == tree.XML_ATTRIBUTE_NONE:
148
+ return "none"
149
+ elif default == tree.XML_ATTRIBUTE_REQUIRED:
150
+ return "required"
151
+ elif default == tree.XML_ATTRIBUTE_IMPLIED:
152
+ return "implied"
153
+ elif default == tree.XML_ATTRIBUTE_FIXED:
154
+ return "fixed"
155
+ else:
156
+ return None
157
+
158
+ @property
159
+ def default_value(self):
160
+ _assertValidDTDNode(self, self._c_node)
161
+ return funicodeOrNone(self._c_node.defaultValue)
162
+
163
+ def itervalues(self):
164
+ _assertValidDTDNode(self, self._c_node)
165
+ cdef tree.xmlEnumeration *c_node = self._c_node.tree
166
+ while c_node is not NULL:
167
+ yield funicode(c_node.name)
168
+ c_node = c_node.next
169
+
170
+ def values(self):
171
+ return list(self.itervalues())
172
+
173
+
174
+ @cython.final
175
+ @cython.internal
176
+ @cython.freelist(8)
177
+ cdef class _DTDElementDecl:
178
+ cdef DTD _dtd
179
+ cdef tree.xmlElement* _c_node
180
+
181
+ def __repr__(self):
182
+ return "<%s.%s object name=%r prefix=%r type=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, self.prefix, self.type, id(self))
183
+
184
+ @property
185
+ def name(self):
186
+ _assertValidDTDNode(self, self._c_node)
187
+ return funicodeOrNone(self._c_node.name)
188
+
189
+ @property
190
+ def prefix(self):
191
+ _assertValidDTDNode(self, self._c_node)
192
+ return funicodeOrNone(self._c_node.prefix)
193
+
194
+ @property
195
+ def type(self):
196
+ _assertValidDTDNode(self, self._c_node)
197
+ cdef int type = self._c_node.etype
198
+ if type == tree.XML_ELEMENT_TYPE_UNDEFINED:
199
+ return "undefined"
200
+ elif type == tree.XML_ELEMENT_TYPE_EMPTY:
201
+ return "empty"
202
+ elif type == tree.XML_ELEMENT_TYPE_ANY:
203
+ return "any"
204
+ elif type == tree.XML_ELEMENT_TYPE_MIXED:
205
+ return "mixed"
206
+ elif type == tree.XML_ELEMENT_TYPE_ELEMENT:
207
+ return "element"
208
+ else:
209
+ return None
210
+
211
+ @property
212
+ def content(self):
213
+ _assertValidDTDNode(self, self._c_node)
214
+ cdef tree.xmlElementContent *content = self._c_node.content
215
+ if content:
216
+ node = <_DTDElementContentDecl>_DTDElementContentDecl.__new__(_DTDElementContentDecl)
217
+ node._dtd = self._dtd
218
+ node._c_node = content
219
+ return node
220
+ else:
221
+ return None
222
+
223
+ def iterattributes(self):
224
+ _assertValidDTDNode(self, self._c_node)
225
+ cdef tree.xmlAttribute *c_node = self._c_node.attributes
226
+ while c_node:
227
+ node = <_DTDAttributeDecl>_DTDAttributeDecl.__new__(_DTDAttributeDecl)
228
+ node._dtd = self._dtd
229
+ node._c_node = c_node
230
+ yield node
231
+ c_node = c_node.nexth
232
+
233
+ def attributes(self):
234
+ return list(self.iterattributes())
235
+
236
+
237
+ @cython.final
238
+ @cython.internal
239
+ @cython.freelist(8)
240
+ cdef class _DTDEntityDecl:
241
+ cdef DTD _dtd
242
+ cdef tree.xmlEntity* _c_node
243
+ def __repr__(self):
244
+ return "<%s.%s object name=%r at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self))
245
+
246
+ @property
247
+ def name(self):
248
+ _assertValidDTDNode(self, self._c_node)
249
+ return funicodeOrNone(self._c_node.name)
250
+
251
+ @property
252
+ def orig(self):
253
+ _assertValidDTDNode(self, self._c_node)
254
+ return funicodeOrNone(self._c_node.orig)
255
+
256
+ @property
257
+ def content(self):
258
+ _assertValidDTDNode(self, self._c_node)
259
+ return funicodeOrNone(self._c_node.content)
260
+
261
+ @property
262
+ def system_url(self):
263
+ _assertValidDTDNode(self, self._c_node)
264
+ return funicodeOrNone(self._c_node.SystemID)
265
+
266
+
267
+ ################################################################################
268
+ # DTD
269
+
270
+ cdef class DTD(_Validator):
271
+ """DTD(self, file=None, external_id=None)
272
+ A DTD validator.
273
+
274
+ Can load from filesystem directly given a filename or file-like object.
275
+ Alternatively, pass the keyword parameter ``external_id`` to load from a
276
+ catalog.
277
+ """
278
+ cdef tree.xmlDtd* _c_dtd
279
+ def __init__(self, file=None, *, external_id=None):
280
+ _Validator.__init__(self)
281
+ if file is not None:
282
+ file = _getFSPathOrObject(file)
283
+ if _isString(file):
284
+ file = _encodeFilename(file)
285
+ with self._error_log:
286
+ orig_loader = _register_document_loader()
287
+ self._c_dtd = xmlparser.xmlParseDTD(NULL, _xcstr(file))
288
+ _reset_document_loader(orig_loader)
289
+ elif hasattr(file, 'read'):
290
+ orig_loader = _register_document_loader()
291
+ self._c_dtd = _parseDtdFromFilelike(file)
292
+ _reset_document_loader(orig_loader)
293
+ else:
294
+ raise DTDParseError, "file must be a filename, file-like or path-like object"
295
+ elif external_id is not None:
296
+ external_id_utf = _utf8(external_id)
297
+ with self._error_log:
298
+ orig_loader = _register_document_loader()
299
+ self._c_dtd = xmlparser.xmlParseDTD(<const_xmlChar*>external_id_utf, NULL)
300
+ _reset_document_loader(orig_loader)
301
+ else:
302
+ raise DTDParseError, "either filename or external ID required"
303
+
304
+ if self._c_dtd is NULL:
305
+ raise DTDParseError(
306
+ self._error_log._buildExceptionMessage("error parsing DTD"),
307
+ self._error_log)
308
+
309
+ @property
310
+ def name(self):
311
+ if self._c_dtd is NULL:
312
+ return None
313
+ return funicodeOrNone(self._c_dtd.name)
314
+
315
+ @property
316
+ def external_id(self):
317
+ if self._c_dtd is NULL:
318
+ return None
319
+ return funicodeOrNone(self._c_dtd.ExternalID)
320
+
321
+ @property
322
+ def system_url(self):
323
+ if self._c_dtd is NULL:
324
+ return None
325
+ return funicodeOrNone(self._c_dtd.SystemID)
326
+
327
+ def iterelements(self):
328
+ cdef tree.xmlNode *c_node = self._c_dtd.children if self._c_dtd is not NULL else NULL
329
+ while c_node is not NULL:
330
+ if c_node.type == tree.XML_ELEMENT_DECL:
331
+ node = _DTDElementDecl()
332
+ node._dtd = self
333
+ node._c_node = <tree.xmlElement*>c_node
334
+ yield node
335
+ c_node = c_node.next
336
+
337
+ def elements(self):
338
+ return list(self.iterelements())
339
+
340
+ def iterentities(self):
341
+ cdef tree.xmlNode *c_node = self._c_dtd.children if self._c_dtd is not NULL else NULL
342
+ while c_node is not NULL:
343
+ if c_node.type == tree.XML_ENTITY_DECL:
344
+ node = _DTDEntityDecl()
345
+ node._dtd = self
346
+ node._c_node = <tree.xmlEntity*>c_node
347
+ yield node
348
+ c_node = c_node.next
349
+
350
+ def entities(self):
351
+ return list(self.iterentities())
352
+
353
+ def __dealloc__(self):
354
+ tree.xmlFreeDtd(self._c_dtd)
355
+
356
+ def __call__(self, etree):
357
+ """__call__(self, etree)
358
+
359
+ Validate doc using the DTD.
360
+
361
+ Returns true if the document is valid, false if not.
362
+ """
363
+ cdef _Document doc
364
+ cdef _Element root_node
365
+ cdef xmlDoc* c_doc
366
+ cdef dtdvalid.xmlValidCtxt* valid_ctxt
367
+ cdef int ret = -1
368
+
369
+ assert self._c_dtd is not NULL, "DTD not initialised"
370
+ doc = _documentOrRaise(etree)
371
+ root_node = _rootNodeOrRaise(etree)
372
+
373
+ valid_ctxt = dtdvalid.xmlNewValidCtxt()
374
+ if valid_ctxt is NULL:
375
+ raise DTDError("Failed to create validation context")
376
+
377
+ # work around error reporting bug in libxml2 <= 2.9.1 (and later?)
378
+ # https://bugzilla.gnome.org/show_bug.cgi?id=724903
379
+ valid_ctxt.error = <dtdvalid.xmlValidityErrorFunc>_nullGenericErrorFunc
380
+ valid_ctxt.userData = NULL
381
+
382
+ try:
383
+ with self._error_log:
384
+ c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
385
+ ret = dtdvalid.xmlValidateDtd(valid_ctxt, c_doc, self._c_dtd)
386
+ _destroyFakeDoc(doc._c_doc, c_doc)
387
+ finally:
388
+ dtdvalid.xmlFreeValidCtxt(valid_ctxt)
389
+
390
+ if ret == -1:
391
+ raise DTDValidateError("Internal error in DTD validation",
392
+ self._error_log)
393
+ return ret == 1
394
+
395
+
396
+ cdef tree.xmlDtd* _parseDtdFromFilelike(file) except NULL:
397
+ cdef _ExceptionContext exc_context
398
+ cdef _FileReaderContext dtd_parser
399
+ cdef _ErrorLog error_log
400
+ cdef tree.xmlDtd* c_dtd = NULL
401
+ exc_context = _ExceptionContext()
402
+ dtd_parser = _FileReaderContext(file, exc_context, None)
403
+ error_log = _ErrorLog()
404
+
405
+ with error_log:
406
+ c_dtd = dtd_parser._readDtd()
407
+
408
+ exc_context._raise_if_stored()
409
+ if c_dtd is NULL:
410
+ raise DTDParseError("error parsing DTD", error_log)
411
+ return c_dtd
412
+
413
+ cdef DTD _dtdFactory(tree.xmlDtd* c_dtd):
414
+ # do not run through DTD.__init__()!
415
+ cdef DTD dtd
416
+ if c_dtd is NULL:
417
+ return None
418
+ dtd = DTD.__new__(DTD)
419
+ dtd._c_dtd = _copyDtd(c_dtd)
420
+ _Validator.__init__(dtd)
421
+ return dtd
422
+
423
+
424
+ cdef tree.xmlDtd* _copyDtd(tree.xmlDtd* c_orig_dtd) except NULL:
425
+ """
426
+ Copy a DTD. libxml2 (currently) fails to set up the element->attributes
427
+ links when copying DTDs, so we have to rebuild them here.
428
+ """
429
+ c_dtd = tree.xmlCopyDtd(c_orig_dtd)
430
+ if not c_dtd:
431
+ raise MemoryError
432
+ cdef tree.xmlNode* c_node = c_dtd.children
433
+ while c_node:
434
+ if c_node.type == tree.XML_ATTRIBUTE_DECL:
435
+ _linkDtdAttribute(c_dtd, <tree.xmlAttribute*>c_node)
436
+ c_node = c_node.next
437
+ return c_dtd
438
+
439
+
440
+ cdef void _linkDtdAttribute(tree.xmlDtd* c_dtd, tree.xmlAttribute* c_attr) noexcept:
441
+ """
442
+ Create the link to the DTD attribute declaration from the corresponding
443
+ element declaration.
444
+ """
445
+ c_elem = dtdvalid.xmlGetDtdElementDesc(c_dtd, c_attr.elem)
446
+ if not c_elem:
447
+ # no such element? something is wrong with the DTD ...
448
+ return
449
+ c_pos = c_elem.attributes
450
+ if not c_pos:
451
+ c_elem.attributes = c_attr
452
+ c_attr.nexth = NULL
453
+ return
454
+ # libxml2 keeps namespace declarations first, and we need to make
455
+ # sure we don't re-insert attributes that are already there
456
+ if _isDtdNsDecl(c_attr):
457
+ if not _isDtdNsDecl(c_pos):
458
+ c_elem.attributes = c_attr
459
+ c_attr.nexth = c_pos
460
+ return
461
+ while c_pos != c_attr and c_pos.nexth and _isDtdNsDecl(c_pos.nexth):
462
+ c_pos = c_pos.nexth
463
+ else:
464
+ # append at end
465
+ while c_pos != c_attr and c_pos.nexth:
466
+ c_pos = c_pos.nexth
467
+ if c_pos == c_attr:
468
+ return
469
+ c_attr.nexth = c_pos.nexth
470
+ c_pos.nexth = c_attr
471
+
472
+
473
+ cdef bint _isDtdNsDecl(tree.xmlAttribute* c_attr) noexcept:
474
+ if cstring_h.strcmp(<const_char*>c_attr.name, "xmlns") == 0:
475
+ return True
476
+ if (c_attr.prefix is not NULL and
477
+ cstring_h.strcmp(<const_char*>c_attr.prefix, "xmlns") == 0):
478
+ return True
479
+ return False
llava_video/lib/python3.10/site-packages/lxml/etree.h ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.11 */
2
+
3
+ #ifndef __PYX_HAVE__lxml__etree
4
+ #define __PYX_HAVE__lxml__etree
5
+
6
+ #include "Python.h"
7
+ struct LxmlDocument;
8
+ struct LxmlElement;
9
+ struct LxmlElementTree;
10
+ struct LxmlElementTagMatcher;
11
+ struct LxmlElementIterator;
12
+ struct LxmlElementBase;
13
+ struct LxmlElementClassLookup;
14
+ struct LxmlFallbackElementClassLookup;
15
+
16
+ /* "lxml/etree.pyx":355
17
+ *
18
+ * # type of a function that steps from node to node
19
+ * ctypedef public xmlNode* (*_node_to_node_function)(xmlNode*) # <<<<<<<<<<<<<<
20
+ *
21
+ *
22
+ */
23
+ typedef xmlNode *(*_node_to_node_function)(xmlNode *);
24
+
25
+ /* "lxml/etree.pyx":371
26
+ * @cython.final
27
+ * @cython.freelist(8)
28
+ * cdef public class _Document [ type LxmlDocumentType, object LxmlDocument ]: # <<<<<<<<<<<<<<
29
+ * """Internal base class to reference a libxml document.
30
+ *
31
+ */
32
+ struct LxmlDocument {
33
+ PyObject_HEAD
34
+ struct __pyx_vtabstruct_4lxml_5etree__Document *__pyx_vtab;
35
+ int _ns_counter;
36
+ PyObject *_prefix_tail;
37
+ xmlDoc *_c_doc;
38
+ struct __pyx_obj_4lxml_5etree__BaseParser *_parser;
39
+ };
40
+
41
+ /* "lxml/etree.pyx":720
42
+ *
43
+ * @cython.no_gc_clear
44
+ * cdef public class _Element [ type LxmlElementType, object LxmlElement ]: # <<<<<<<<<<<<<<
45
+ * """Element class.
46
+ *
47
+ */
48
+ struct LxmlElement {
49
+ PyObject_HEAD
50
+ struct LxmlDocument *_doc;
51
+ xmlNode *_c_node;
52
+ PyObject *_tag;
53
+ };
54
+
55
+ /* "lxml/etree.pyx":1895
56
+ *
57
+ *
58
+ * cdef public class _ElementTree [ type LxmlElementTreeType, # <<<<<<<<<<<<<<
59
+ * object LxmlElementTree ]:
60
+ * cdef _Document _doc
61
+ */
62
+ struct LxmlElementTree {
63
+ PyObject_HEAD
64
+ struct __pyx_vtabstruct_4lxml_5etree__ElementTree *__pyx_vtab;
65
+ struct LxmlDocument *_doc;
66
+ struct LxmlElement *_context_node;
67
+ };
68
+
69
+ /* "lxml/etree.pyx":2669
70
+ *
71
+ *
72
+ * cdef public class _ElementTagMatcher [ object LxmlElementTagMatcher, # <<<<<<<<<<<<<<
73
+ * type LxmlElementTagMatcherType ]:
74
+ * """
75
+ */
76
+ struct LxmlElementTagMatcher {
77
+ PyObject_HEAD
78
+ struct __pyx_vtabstruct_4lxml_5etree__ElementTagMatcher *__pyx_vtab;
79
+ PyObject *_pystrings;
80
+ int _node_type;
81
+ char *_href;
82
+ char *_name;
83
+ };
84
+
85
+ /* "lxml/etree.pyx":2700
86
+ * self._name = NULL
87
+ *
88
+ * cdef public class _ElementIterator(_ElementTagMatcher) [ # <<<<<<<<<<<<<<
89
+ * object LxmlElementIterator, type LxmlElementIteratorType ]:
90
+ * """
91
+ */
92
+ struct LxmlElementIterator {
93
+ struct LxmlElementTagMatcher __pyx_base;
94
+ struct LxmlElement *_node;
95
+ _node_to_node_function _next_element;
96
+ };
97
+
98
+ /* "src/lxml/classlookup.pxi":6
99
+ * # Custom Element classes
100
+ *
101
+ * cdef public class ElementBase(_Element) [ type LxmlElementBaseType, # <<<<<<<<<<<<<<
102
+ * object LxmlElementBase ]:
103
+ * """ElementBase(*children, attrib=None, nsmap=None, **_extra)
104
+ */
105
+ struct LxmlElementBase {
106
+ struct LxmlElement __pyx_base;
107
+ };
108
+
109
+ /* "src/lxml/classlookup.pxi":210
110
+ * # Element class lookup
111
+ *
112
+ * ctypedef public object (*_element_class_lookup_function)(object, _Document, xmlNode*) # <<<<<<<<<<<<<<
113
+ *
114
+ * # class to store element class lookup functions
115
+ */
116
+ typedef PyObject *(*_element_class_lookup_function)(PyObject *, struct LxmlDocument *, xmlNode *);
117
+
118
+ /* "src/lxml/classlookup.pxi":213
119
+ *
120
+ * # class to store element class lookup functions
121
+ * cdef public class ElementClassLookup [ type LxmlElementClassLookupType, # <<<<<<<<<<<<<<
122
+ * object LxmlElementClassLookup ]:
123
+ * """ElementClassLookup(self)
124
+ */
125
+ struct LxmlElementClassLookup {
126
+ PyObject_HEAD
127
+ _element_class_lookup_function _lookup_function;
128
+ };
129
+
130
+ /* "src/lxml/classlookup.pxi":221
131
+ *
132
+ *
133
+ * cdef public class FallbackElementClassLookup(ElementClassLookup) \ # <<<<<<<<<<<<<<
134
+ * [ type LxmlFallbackElementClassLookupType,
135
+ * object LxmlFallbackElementClassLookup ]:
136
+ */
137
+ struct LxmlFallbackElementClassLookup {
138
+ struct LxmlElementClassLookup __pyx_base;
139
+ struct __pyx_vtabstruct_4lxml_5etree_FallbackElementClassLookup *__pyx_vtab;
140
+ struct LxmlElementClassLookup *fallback;
141
+ _element_class_lookup_function _fallback_function;
142
+ };
143
+
144
+ #ifndef __PYX_HAVE_API__lxml__etree
145
+
146
+ #ifdef CYTHON_EXTERN_C
147
+ #undef __PYX_EXTERN_C
148
+ #define __PYX_EXTERN_C CYTHON_EXTERN_C
149
+ #elif defined(__PYX_EXTERN_C)
150
+ #ifdef _MSC_VER
151
+ #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
152
+ #else
153
+ #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
154
+ #endif
155
+ #else
156
+ #ifdef __cplusplus
157
+ #define __PYX_EXTERN_C extern "C"
158
+ #else
159
+ #define __PYX_EXTERN_C extern
160
+ #endif
161
+ #endif
162
+
163
+ #ifndef DL_IMPORT
164
+ #define DL_IMPORT(_T) _T
165
+ #endif
166
+
167
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlDocumentType;
168
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementType;
169
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementTreeType;
170
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementTagMatcherType;
171
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementIteratorType;
172
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementBaseType;
173
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementClassLookupType;
174
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlFallbackElementClassLookupType;
175
+
176
+ __PYX_EXTERN_C struct LxmlElement *deepcopyNodeToDocument(struct LxmlDocument *, xmlNode *);
177
+ __PYX_EXTERN_C struct LxmlElementTree *elementTreeFactory(struct LxmlElement *);
178
+ __PYX_EXTERN_C struct LxmlElementTree *newElementTree(struct LxmlElement *, PyObject *);
179
+ __PYX_EXTERN_C struct LxmlElementTree *adoptExternalDocument(xmlDoc *, PyObject *, int);
180
+ __PYX_EXTERN_C struct LxmlElement *elementFactory(struct LxmlDocument *, xmlNode *);
181
+ __PYX_EXTERN_C struct LxmlElement *makeElement(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *);
182
+ __PYX_EXTERN_C struct LxmlElement *makeSubElement(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *);
183
+ __PYX_EXTERN_C void setElementClassLookupFunction(_element_class_lookup_function, PyObject *);
184
+ __PYX_EXTERN_C PyObject *lookupDefaultElementClass(PyObject *, PyObject *, xmlNode *);
185
+ __PYX_EXTERN_C PyObject *lookupNamespaceElementClass(PyObject *, PyObject *, xmlNode *);
186
+ __PYX_EXTERN_C PyObject *callLookupFallback(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *);
187
+ __PYX_EXTERN_C int tagMatches(xmlNode *, const xmlChar *, const xmlChar *);
188
+ __PYX_EXTERN_C struct LxmlDocument *documentOrRaise(PyObject *);
189
+ __PYX_EXTERN_C struct LxmlElement *rootNodeOrRaise(PyObject *);
190
+ __PYX_EXTERN_C int hasText(xmlNode *);
191
+ __PYX_EXTERN_C int hasTail(xmlNode *);
192
+ __PYX_EXTERN_C PyObject *textOf(xmlNode *);
193
+ __PYX_EXTERN_C PyObject *tailOf(xmlNode *);
194
+ __PYX_EXTERN_C int setNodeText(xmlNode *, PyObject *);
195
+ __PYX_EXTERN_C int setTailText(xmlNode *, PyObject *);
196
+ __PYX_EXTERN_C PyObject *attributeValue(xmlNode *, xmlAttr *);
197
+ __PYX_EXTERN_C PyObject *attributeValueFromNsName(xmlNode *, const xmlChar *, const xmlChar *);
198
+ __PYX_EXTERN_C PyObject *getAttributeValue(struct LxmlElement *, PyObject *, PyObject *);
199
+ __PYX_EXTERN_C PyObject *iterattributes(struct LxmlElement *, int);
200
+ __PYX_EXTERN_C PyObject *collectAttributes(xmlNode *, int);
201
+ __PYX_EXTERN_C int setAttributeValue(struct LxmlElement *, PyObject *, PyObject *);
202
+ __PYX_EXTERN_C int delAttribute(struct LxmlElement *, PyObject *);
203
+ __PYX_EXTERN_C int delAttributeFromNsName(xmlNode *, const xmlChar *, const xmlChar *);
204
+ __PYX_EXTERN_C int hasChild(xmlNode *);
205
+ __PYX_EXTERN_C xmlNode *findChild(xmlNode *, Py_ssize_t);
206
+ __PYX_EXTERN_C xmlNode *findChildForwards(xmlNode *, Py_ssize_t);
207
+ __PYX_EXTERN_C xmlNode *findChildBackwards(xmlNode *, Py_ssize_t);
208
+ __PYX_EXTERN_C xmlNode *nextElement(xmlNode *);
209
+ __PYX_EXTERN_C xmlNode *previousElement(xmlNode *);
210
+ __PYX_EXTERN_C void appendChild(struct LxmlElement *, struct LxmlElement *);
211
+ __PYX_EXTERN_C int appendChildToElement(struct LxmlElement *, struct LxmlElement *);
212
+ __PYX_EXTERN_C PyObject *pyunicode(const xmlChar *);
213
+ __PYX_EXTERN_C PyObject *utf8(PyObject *);
214
+ __PYX_EXTERN_C PyObject *getNsTag(PyObject *);
215
+ __PYX_EXTERN_C PyObject *getNsTagWithEmptyNs(PyObject *);
216
+ __PYX_EXTERN_C PyObject *namespacedName(xmlNode *);
217
+ __PYX_EXTERN_C PyObject *namespacedNameFromNsName(const xmlChar *, const xmlChar *);
218
+ __PYX_EXTERN_C void iteratorStoreNext(struct LxmlElementIterator *, struct LxmlElement *);
219
+ __PYX_EXTERN_C void initTagMatch(struct LxmlElementTagMatcher *, PyObject *);
220
+ __PYX_EXTERN_C xmlNs *findOrBuildNodeNsPrefix(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *);
221
+
222
+ #endif /* !__PYX_HAVE_API__lxml__etree */
223
+
224
+ /* WARNING: the interface of the module init function changed in CPython 3.5. */
225
+ /* It now returns a PyModuleDef instance instead of a PyModule instance. */
226
+
227
+ #if PY_MAJOR_VERSION < 3
228
+ PyMODINIT_FUNC initetree(void);
229
+ #else
230
+ /* WARNING: Use PyImport_AppendInittab("etree", PyInit_etree) instead of calling PyInit_etree directly from Python 3.5 */
231
+ PyMODINIT_FUNC PyInit_etree(void);
232
+
233
+ #if PY_VERSION_HEX >= 0x03050000 && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 201402L))
234
+ #if defined(__cplusplus) && __cplusplus >= 201402L
235
+ [[deprecated("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly.")]] inline
236
+ #elif defined(__GNUC__) || defined(__clang__)
237
+ __attribute__ ((__deprecated__("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly."), __unused__)) __inline__
238
+ #elif defined(_MSC_VER)
239
+ __declspec(deprecated("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly.")) __inline
240
+ #endif
241
+ static PyObject* __PYX_WARN_IF_PyInit_etree_INIT_CALLED(PyObject* res) {
242
+ return res;
243
+ }
244
+ #define PyInit_etree() __PYX_WARN_IF_PyInit_etree_INIT_CALLED(PyInit_etree())
245
+ #endif
246
+ #endif
247
+
248
+ #endif /* !__PYX_HAVE__lxml__etree */
llava_video/lib/python3.10/site-packages/lxml/etree.pyx ADDED
The diff for this file is too large to render. See raw diff
 
llava_video/lib/python3.10/site-packages/lxml/etree_api.h ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.11 */
2
+
3
+ #ifndef __PYX_HAVE_API__lxml__etree
4
+ #define __PYX_HAVE_API__lxml__etree
5
+ #ifdef __MINGW64__
6
+ #define MS_WIN64
7
+ #endif
8
+ #include "Python.h"
9
+ #include "etree.h"
10
+
11
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_deepcopyNodeToDocument)(struct LxmlDocument *, xmlNode *) = 0;
12
+ #define deepcopyNodeToDocument __pyx_api_f_4lxml_5etree_deepcopyNodeToDocument
13
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_elementTreeFactory)(struct LxmlElement *) = 0;
14
+ #define elementTreeFactory __pyx_api_f_4lxml_5etree_elementTreeFactory
15
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_newElementTree)(struct LxmlElement *, PyObject *) = 0;
16
+ #define newElementTree __pyx_api_f_4lxml_5etree_newElementTree
17
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_adoptExternalDocument)(xmlDoc *, PyObject *, int) = 0;
18
+ #define adoptExternalDocument __pyx_api_f_4lxml_5etree_adoptExternalDocument
19
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_elementFactory)(struct LxmlDocument *, xmlNode *) = 0;
20
+ #define elementFactory __pyx_api_f_4lxml_5etree_elementFactory
21
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_makeElement)(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *) = 0;
22
+ #define makeElement __pyx_api_f_4lxml_5etree_makeElement
23
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_makeSubElement)(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *) = 0;
24
+ #define makeSubElement __pyx_api_f_4lxml_5etree_makeSubElement
25
+ static void (*__pyx_api_f_4lxml_5etree_setElementClassLookupFunction)(_element_class_lookup_function, PyObject *) = 0;
26
+ #define setElementClassLookupFunction __pyx_api_f_4lxml_5etree_setElementClassLookupFunction
27
+ static PyObject *(*__pyx_api_f_4lxml_5etree_lookupDefaultElementClass)(PyObject *, PyObject *, xmlNode *) = 0;
28
+ #define lookupDefaultElementClass __pyx_api_f_4lxml_5etree_lookupDefaultElementClass
29
+ static PyObject *(*__pyx_api_f_4lxml_5etree_lookupNamespaceElementClass)(PyObject *, PyObject *, xmlNode *) = 0;
30
+ #define lookupNamespaceElementClass __pyx_api_f_4lxml_5etree_lookupNamespaceElementClass
31
+ static PyObject *(*__pyx_api_f_4lxml_5etree_callLookupFallback)(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *) = 0;
32
+ #define callLookupFallback __pyx_api_f_4lxml_5etree_callLookupFallback
33
+ static int (*__pyx_api_f_4lxml_5etree_tagMatches)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
34
+ #define tagMatches __pyx_api_f_4lxml_5etree_tagMatches
35
+ static struct LxmlDocument *(*__pyx_api_f_4lxml_5etree_documentOrRaise)(PyObject *) = 0;
36
+ #define documentOrRaise __pyx_api_f_4lxml_5etree_documentOrRaise
37
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_rootNodeOrRaise)(PyObject *) = 0;
38
+ #define rootNodeOrRaise __pyx_api_f_4lxml_5etree_rootNodeOrRaise
39
+ static int (*__pyx_api_f_4lxml_5etree_hasText)(xmlNode *) = 0;
40
+ #define hasText __pyx_api_f_4lxml_5etree_hasText
41
+ static int (*__pyx_api_f_4lxml_5etree_hasTail)(xmlNode *) = 0;
42
+ #define hasTail __pyx_api_f_4lxml_5etree_hasTail
43
+ static PyObject *(*__pyx_api_f_4lxml_5etree_textOf)(xmlNode *) = 0;
44
+ #define textOf __pyx_api_f_4lxml_5etree_textOf
45
+ static PyObject *(*__pyx_api_f_4lxml_5etree_tailOf)(xmlNode *) = 0;
46
+ #define tailOf __pyx_api_f_4lxml_5etree_tailOf
47
+ static int (*__pyx_api_f_4lxml_5etree_setNodeText)(xmlNode *, PyObject *) = 0;
48
+ #define setNodeText __pyx_api_f_4lxml_5etree_setNodeText
49
+ static int (*__pyx_api_f_4lxml_5etree_setTailText)(xmlNode *, PyObject *) = 0;
50
+ #define setTailText __pyx_api_f_4lxml_5etree_setTailText
51
+ static PyObject *(*__pyx_api_f_4lxml_5etree_attributeValue)(xmlNode *, xmlAttr *) = 0;
52
+ #define attributeValue __pyx_api_f_4lxml_5etree_attributeValue
53
+ static PyObject *(*__pyx_api_f_4lxml_5etree_attributeValueFromNsName)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
54
+ #define attributeValueFromNsName __pyx_api_f_4lxml_5etree_attributeValueFromNsName
55
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getAttributeValue)(struct LxmlElement *, PyObject *, PyObject *) = 0;
56
+ #define getAttributeValue __pyx_api_f_4lxml_5etree_getAttributeValue
57
+ static PyObject *(*__pyx_api_f_4lxml_5etree_iterattributes)(struct LxmlElement *, int) = 0;
58
+ #define iterattributes __pyx_api_f_4lxml_5etree_iterattributes
59
+ static PyObject *(*__pyx_api_f_4lxml_5etree_collectAttributes)(xmlNode *, int) = 0;
60
+ #define collectAttributes __pyx_api_f_4lxml_5etree_collectAttributes
61
+ static int (*__pyx_api_f_4lxml_5etree_setAttributeValue)(struct LxmlElement *, PyObject *, PyObject *) = 0;
62
+ #define setAttributeValue __pyx_api_f_4lxml_5etree_setAttributeValue
63
+ static int (*__pyx_api_f_4lxml_5etree_delAttribute)(struct LxmlElement *, PyObject *) = 0;
64
+ #define delAttribute __pyx_api_f_4lxml_5etree_delAttribute
65
+ static int (*__pyx_api_f_4lxml_5etree_delAttributeFromNsName)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
66
+ #define delAttributeFromNsName __pyx_api_f_4lxml_5etree_delAttributeFromNsName
67
+ static int (*__pyx_api_f_4lxml_5etree_hasChild)(xmlNode *) = 0;
68
+ #define hasChild __pyx_api_f_4lxml_5etree_hasChild
69
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChild)(xmlNode *, Py_ssize_t) = 0;
70
+ #define findChild __pyx_api_f_4lxml_5etree_findChild
71
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChildForwards)(xmlNode *, Py_ssize_t) = 0;
72
+ #define findChildForwards __pyx_api_f_4lxml_5etree_findChildForwards
73
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChildBackwards)(xmlNode *, Py_ssize_t) = 0;
74
+ #define findChildBackwards __pyx_api_f_4lxml_5etree_findChildBackwards
75
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_nextElement)(xmlNode *) = 0;
76
+ #define nextElement __pyx_api_f_4lxml_5etree_nextElement
77
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_previousElement)(xmlNode *) = 0;
78
+ #define previousElement __pyx_api_f_4lxml_5etree_previousElement
79
+ static void (*__pyx_api_f_4lxml_5etree_appendChild)(struct LxmlElement *, struct LxmlElement *) = 0;
80
+ #define appendChild __pyx_api_f_4lxml_5etree_appendChild
81
+ static int (*__pyx_api_f_4lxml_5etree_appendChildToElement)(struct LxmlElement *, struct LxmlElement *) = 0;
82
+ #define appendChildToElement __pyx_api_f_4lxml_5etree_appendChildToElement
83
+ static PyObject *(*__pyx_api_f_4lxml_5etree_pyunicode)(const xmlChar *) = 0;
84
+ #define pyunicode __pyx_api_f_4lxml_5etree_pyunicode
85
+ static PyObject *(*__pyx_api_f_4lxml_5etree_utf8)(PyObject *) = 0;
86
+ #define utf8 __pyx_api_f_4lxml_5etree_utf8
87
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getNsTag)(PyObject *) = 0;
88
+ #define getNsTag __pyx_api_f_4lxml_5etree_getNsTag
89
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs)(PyObject *) = 0;
90
+ #define getNsTagWithEmptyNs __pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs
91
+ static PyObject *(*__pyx_api_f_4lxml_5etree_namespacedName)(xmlNode *) = 0;
92
+ #define namespacedName __pyx_api_f_4lxml_5etree_namespacedName
93
+ static PyObject *(*__pyx_api_f_4lxml_5etree_namespacedNameFromNsName)(const xmlChar *, const xmlChar *) = 0;
94
+ #define namespacedNameFromNsName __pyx_api_f_4lxml_5etree_namespacedNameFromNsName
95
+ static void (*__pyx_api_f_4lxml_5etree_iteratorStoreNext)(struct LxmlElementIterator *, struct LxmlElement *) = 0;
96
+ #define iteratorStoreNext __pyx_api_f_4lxml_5etree_iteratorStoreNext
97
+ static void (*__pyx_api_f_4lxml_5etree_initTagMatch)(struct LxmlElementTagMatcher *, PyObject *) = 0;
98
+ #define initTagMatch __pyx_api_f_4lxml_5etree_initTagMatch
99
+ static xmlNs *(*__pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix)(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *) = 0;
100
+ #define findOrBuildNodeNsPrefix __pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix
101
+ #ifndef __PYX_HAVE_RT_ImportFunction_3_0_11
102
+ #define __PYX_HAVE_RT_ImportFunction_3_0_11
103
+ static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
104
+ PyObject *d = 0;
105
+ PyObject *cobj = 0;
106
+ union {
107
+ void (*fp)(void);
108
+ void *p;
109
+ } tmp;
110
+ d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
111
+ if (!d)
112
+ goto bad;
113
+ cobj = PyDict_GetItemString(d, funcname);
114
+ if (!cobj) {
115
+ PyErr_Format(PyExc_ImportError,
116
+ "%.200s does not export expected C function %.200s",
117
+ PyModule_GetName(module), funcname);
118
+ goto bad;
119
+ }
120
+ if (!PyCapsule_IsValid(cobj, sig)) {
121
+ PyErr_Format(PyExc_TypeError,
122
+ "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
123
+ PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
124
+ goto bad;
125
+ }
126
+ tmp.p = PyCapsule_GetPointer(cobj, sig);
127
+ *f = tmp.fp;
128
+ if (!(*f))
129
+ goto bad;
130
+ Py_DECREF(d);
131
+ return 0;
132
+ bad:
133
+ Py_XDECREF(d);
134
+ return -1;
135
+ }
136
+ #endif
137
+
138
+
139
+ static int import_lxml__etree(void) {
140
+ PyObject *module = 0;
141
+ module = PyImport_ImportModule("lxml.etree");
142
+ if (!module) goto bad;
143
+ if (__Pyx_ImportFunction_3_0_11(module, "deepcopyNodeToDocument", (void (**)(void))&__pyx_api_f_4lxml_5etree_deepcopyNodeToDocument, "struct LxmlElement *(struct LxmlDocument *, xmlNode *)") < 0) goto bad;
144
+ if (__Pyx_ImportFunction_3_0_11(module, "elementTreeFactory", (void (**)(void))&__pyx_api_f_4lxml_5etree_elementTreeFactory, "struct LxmlElementTree *(struct LxmlElement *)") < 0) goto bad;
145
+ if (__Pyx_ImportFunction_3_0_11(module, "newElementTree", (void (**)(void))&__pyx_api_f_4lxml_5etree_newElementTree, "struct LxmlElementTree *(struct LxmlElement *, PyObject *)") < 0) goto bad;
146
+ if (__Pyx_ImportFunction_3_0_11(module, "adoptExternalDocument", (void (**)(void))&__pyx_api_f_4lxml_5etree_adoptExternalDocument, "struct LxmlElementTree *(xmlDoc *, PyObject *, int)") < 0) goto bad;
147
+ if (__Pyx_ImportFunction_3_0_11(module, "elementFactory", (void (**)(void))&__pyx_api_f_4lxml_5etree_elementFactory, "struct LxmlElement *(struct LxmlDocument *, xmlNode *)") < 0) goto bad;
148
+ if (__Pyx_ImportFunction_3_0_11(module, "makeElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_makeElement, "struct LxmlElement *(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *)") < 0) goto bad;
149
+ if (__Pyx_ImportFunction_3_0_11(module, "makeSubElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_makeSubElement, "struct LxmlElement *(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *)") < 0) goto bad;
150
+ if (__Pyx_ImportFunction_3_0_11(module, "setElementClassLookupFunction", (void (**)(void))&__pyx_api_f_4lxml_5etree_setElementClassLookupFunction, "void (_element_class_lookup_function, PyObject *)") < 0) goto bad;
151
+ if (__Pyx_ImportFunction_3_0_11(module, "lookupDefaultElementClass", (void (**)(void))&__pyx_api_f_4lxml_5etree_lookupDefaultElementClass, "PyObject *(PyObject *, PyObject *, xmlNode *)") < 0) goto bad;
152
+ if (__Pyx_ImportFunction_3_0_11(module, "lookupNamespaceElementClass", (void (**)(void))&__pyx_api_f_4lxml_5etree_lookupNamespaceElementClass, "PyObject *(PyObject *, PyObject *, xmlNode *)") < 0) goto bad;
153
+ if (__Pyx_ImportFunction_3_0_11(module, "callLookupFallback", (void (**)(void))&__pyx_api_f_4lxml_5etree_callLookupFallback, "PyObject *(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *)") < 0) goto bad;
154
+ if (__Pyx_ImportFunction_3_0_11(module, "tagMatches", (void (**)(void))&__pyx_api_f_4lxml_5etree_tagMatches, "int (xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
155
+ if (__Pyx_ImportFunction_3_0_11(module, "documentOrRaise", (void (**)(void))&__pyx_api_f_4lxml_5etree_documentOrRaise, "struct LxmlDocument *(PyObject *)") < 0) goto bad;
156
+ if (__Pyx_ImportFunction_3_0_11(module, "rootNodeOrRaise", (void (**)(void))&__pyx_api_f_4lxml_5etree_rootNodeOrRaise, "struct LxmlElement *(PyObject *)") < 0) goto bad;
157
+ if (__Pyx_ImportFunction_3_0_11(module, "hasText", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasText, "int (xmlNode *)") < 0) goto bad;
158
+ if (__Pyx_ImportFunction_3_0_11(module, "hasTail", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasTail, "int (xmlNode *)") < 0) goto bad;
159
+ if (__Pyx_ImportFunction_3_0_11(module, "textOf", (void (**)(void))&__pyx_api_f_4lxml_5etree_textOf, "PyObject *(xmlNode *)") < 0) goto bad;
160
+ if (__Pyx_ImportFunction_3_0_11(module, "tailOf", (void (**)(void))&__pyx_api_f_4lxml_5etree_tailOf, "PyObject *(xmlNode *)") < 0) goto bad;
161
+ if (__Pyx_ImportFunction_3_0_11(module, "setNodeText", (void (**)(void))&__pyx_api_f_4lxml_5etree_setNodeText, "int (xmlNode *, PyObject *)") < 0) goto bad;
162
+ if (__Pyx_ImportFunction_3_0_11(module, "setTailText", (void (**)(void))&__pyx_api_f_4lxml_5etree_setTailText, "int (xmlNode *, PyObject *)") < 0) goto bad;
163
+ if (__Pyx_ImportFunction_3_0_11(module, "attributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_attributeValue, "PyObject *(xmlNode *, xmlAttr *)") < 0) goto bad;
164
+ if (__Pyx_ImportFunction_3_0_11(module, "attributeValueFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_attributeValueFromNsName, "PyObject *(xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
165
+ if (__Pyx_ImportFunction_3_0_11(module, "getAttributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_getAttributeValue, "PyObject *(struct LxmlElement *, PyObject *, PyObject *)") < 0) goto bad;
166
+ if (__Pyx_ImportFunction_3_0_11(module, "iterattributes", (void (**)(void))&__pyx_api_f_4lxml_5etree_iterattributes, "PyObject *(struct LxmlElement *, int)") < 0) goto bad;
167
+ if (__Pyx_ImportFunction_3_0_11(module, "collectAttributes", (void (**)(void))&__pyx_api_f_4lxml_5etree_collectAttributes, "PyObject *(xmlNode *, int)") < 0) goto bad;
168
+ if (__Pyx_ImportFunction_3_0_11(module, "setAttributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_setAttributeValue, "int (struct LxmlElement *, PyObject *, PyObject *)") < 0) goto bad;
169
+ if (__Pyx_ImportFunction_3_0_11(module, "delAttribute", (void (**)(void))&__pyx_api_f_4lxml_5etree_delAttribute, "int (struct LxmlElement *, PyObject *)") < 0) goto bad;
170
+ if (__Pyx_ImportFunction_3_0_11(module, "delAttributeFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_delAttributeFromNsName, "int (xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
171
+ if (__Pyx_ImportFunction_3_0_11(module, "hasChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasChild, "int (xmlNode *)") < 0) goto bad;
172
+ if (__Pyx_ImportFunction_3_0_11(module, "findChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChild, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
173
+ if (__Pyx_ImportFunction_3_0_11(module, "findChildForwards", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChildForwards, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
174
+ if (__Pyx_ImportFunction_3_0_11(module, "findChildBackwards", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChildBackwards, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
175
+ if (__Pyx_ImportFunction_3_0_11(module, "nextElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_nextElement, "xmlNode *(xmlNode *)") < 0) goto bad;
176
+ if (__Pyx_ImportFunction_3_0_11(module, "previousElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_previousElement, "xmlNode *(xmlNode *)") < 0) goto bad;
177
+ if (__Pyx_ImportFunction_3_0_11(module, "appendChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_appendChild, "void (struct LxmlElement *, struct LxmlElement *)") < 0) goto bad;
178
+ if (__Pyx_ImportFunction_3_0_11(module, "appendChildToElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_appendChildToElement, "int (struct LxmlElement *, struct LxmlElement *)") < 0) goto bad;
179
+ if (__Pyx_ImportFunction_3_0_11(module, "pyunicode", (void (**)(void))&__pyx_api_f_4lxml_5etree_pyunicode, "PyObject *(const xmlChar *)") < 0) goto bad;
180
+ if (__Pyx_ImportFunction_3_0_11(module, "utf8", (void (**)(void))&__pyx_api_f_4lxml_5etree_utf8, "PyObject *(PyObject *)") < 0) goto bad;
181
+ if (__Pyx_ImportFunction_3_0_11(module, "getNsTag", (void (**)(void))&__pyx_api_f_4lxml_5etree_getNsTag, "PyObject *(PyObject *)") < 0) goto bad;
182
+ if (__Pyx_ImportFunction_3_0_11(module, "getNsTagWithEmptyNs", (void (**)(void))&__pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs, "PyObject *(PyObject *)") < 0) goto bad;
183
+ if (__Pyx_ImportFunction_3_0_11(module, "namespacedName", (void (**)(void))&__pyx_api_f_4lxml_5etree_namespacedName, "PyObject *(xmlNode *)") < 0) goto bad;
184
+ if (__Pyx_ImportFunction_3_0_11(module, "namespacedNameFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_namespacedNameFromNsName, "PyObject *(const xmlChar *, const xmlChar *)") < 0) goto bad;
185
+ if (__Pyx_ImportFunction_3_0_11(module, "iteratorStoreNext", (void (**)(void))&__pyx_api_f_4lxml_5etree_iteratorStoreNext, "void (struct LxmlElementIterator *, struct LxmlElement *)") < 0) goto bad;
186
+ if (__Pyx_ImportFunction_3_0_11(module, "initTagMatch", (void (**)(void))&__pyx_api_f_4lxml_5etree_initTagMatch, "void (struct LxmlElementTagMatcher *, PyObject *)") < 0) goto bad;
187
+ if (__Pyx_ImportFunction_3_0_11(module, "findOrBuildNodeNsPrefix", (void (**)(void))&__pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix, "xmlNs *(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
188
+ Py_DECREF(module); module = 0;
189
+ return 0;
190
+ bad:
191
+ Py_XDECREF(module);
192
+ return -1;
193
+ }
194
+
195
+ #endif /* !__PYX_HAVE_API__lxml__etree */
llava_video/lib/python3.10/site-packages/lxml/extensions.pxi ADDED
@@ -0,0 +1,833 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # support for extension functions in XPath and XSLT
2
+
3
+ cdef class XPathError(LxmlError):
4
+ """Base class of all XPath errors.
5
+ """
6
+
7
+ cdef class XPathEvalError(XPathError):
8
+ """Error during XPath evaluation.
9
+ """
10
+
11
+ cdef class XPathFunctionError(XPathEvalError):
12
+ """Internal error looking up an XPath extension function.
13
+ """
14
+
15
+ cdef class XPathResultError(XPathEvalError):
16
+ """Error handling an XPath result.
17
+ """
18
+
19
+
20
+ # forward declarations
21
+
22
+ ctypedef int (*_register_function)(void* ctxt, name_utf, ns_uri_utf)
23
+ cdef class _ExsltRegExp
24
+
25
+ ################################################################################
26
+ # Base class for XSLT and XPath evaluation contexts: functions, namespaces, ...
27
+
28
+ @cython.internal
29
+ cdef class _BaseContext:
30
+ cdef xpath.xmlXPathContext* _xpathCtxt
31
+ cdef _Document _doc
32
+ cdef dict _extensions
33
+ cdef list _namespaces
34
+ cdef list _global_namespaces
35
+ cdef dict _utf_refs
36
+ cdef dict _function_cache
37
+ cdef dict _eval_context_dict
38
+ cdef bint _build_smart_strings
39
+ # for exception handling and temporary reference keeping:
40
+ cdef _TempStore _temp_refs
41
+ cdef set _temp_documents
42
+ cdef _ExceptionContext _exc
43
+ cdef _ErrorLog _error_log
44
+
45
+ def __cinit__(self):
46
+ self._xpathCtxt = NULL
47
+
48
+ def __init__(self, namespaces, extensions, error_log, enable_regexp,
49
+ build_smart_strings):
50
+ cdef _ExsltRegExp _regexp
51
+ cdef dict new_extensions
52
+ cdef list ns
53
+ self._utf_refs = {}
54
+ self._global_namespaces = []
55
+ self._function_cache = {}
56
+ self._eval_context_dict = None
57
+ self._error_log = error_log
58
+
59
+ if extensions is not None:
60
+ # convert extensions to UTF-8
61
+ if isinstance(extensions, dict):
62
+ extensions = (extensions,)
63
+ # format: [ {(ns, name):function} ] -> {(ns_utf, name_utf):function}
64
+ new_extensions = {}
65
+ for extension in extensions:
66
+ for (ns_uri, name), function in extension.items():
67
+ if name is None:
68
+ raise ValueError, "extensions must have non empty names"
69
+ ns_utf = self._to_utf(ns_uri)
70
+ name_utf = self._to_utf(name)
71
+ new_extensions[(ns_utf, name_utf)] = function
72
+ extensions = new_extensions or None
73
+
74
+ if namespaces is not None:
75
+ if isinstance(namespaces, dict):
76
+ namespaces = namespaces.items()
77
+ if namespaces:
78
+ ns = []
79
+ for prefix, ns_uri in namespaces:
80
+ if prefix is None or not prefix:
81
+ raise TypeError, \
82
+ "empty namespace prefix is not supported in XPath"
83
+ if ns_uri is None or not ns_uri:
84
+ raise TypeError, \
85
+ "setting default namespace is not supported in XPath"
86
+ prefix_utf = self._to_utf(prefix)
87
+ ns_uri_utf = self._to_utf(ns_uri)
88
+ ns.append( (prefix_utf, ns_uri_utf) )
89
+ namespaces = ns
90
+ else:
91
+ namespaces = None
92
+
93
+ self._doc = None
94
+ self._exc = _ExceptionContext()
95
+ self._extensions = extensions
96
+ self._namespaces = namespaces
97
+ self._temp_refs = _TempStore()
98
+ self._temp_documents = set()
99
+ self._build_smart_strings = build_smart_strings
100
+
101
+ if enable_regexp:
102
+ _regexp = _ExsltRegExp()
103
+ _regexp._register_in_context(self)
104
+
105
+ cdef _BaseContext _copy(self):
106
+ cdef _BaseContext context
107
+ if self._namespaces is not None:
108
+ namespaces = self._namespaces[:]
109
+ else:
110
+ namespaces = None
111
+ context = self.__class__(namespaces, None, self._error_log, False,
112
+ self._build_smart_strings)
113
+ if self._extensions is not None:
114
+ context._extensions = self._extensions.copy()
115
+ return context
116
+
117
+ cdef bytes _to_utf(self, s):
118
+ "Convert to UTF-8 and keep a reference to the encoded string"
119
+ cdef python.PyObject* dict_result
120
+ if s is None:
121
+ return None
122
+ dict_result = python.PyDict_GetItem(self._utf_refs, s)
123
+ if dict_result is not NULL:
124
+ return <bytes>dict_result
125
+ utf = _utf8(s)
126
+ self._utf_refs[s] = utf
127
+ if python.IS_PYPY:
128
+ # use C level refs, PyPy refs are not enough!
129
+ python.Py_INCREF(utf)
130
+ return utf
131
+
132
+ cdef void _set_xpath_context(self, xpath.xmlXPathContext* xpathCtxt) noexcept:
133
+ self._xpathCtxt = xpathCtxt
134
+ xpathCtxt.userData = <void*>self
135
+ # Need a cast here because older libxml2 releases do not use 'const' in the functype.
136
+ xpathCtxt.error = <xmlerror.xmlStructuredErrorFunc> _receiveXPathError
137
+
138
+ @cython.final
139
+ cdef _register_context(self, _Document doc):
140
+ self._doc = doc
141
+ self._exc.clear()
142
+
143
+ @cython.final
144
+ cdef _cleanup_context(self):
145
+ #xpath.xmlXPathRegisteredNsCleanup(self._xpathCtxt)
146
+ #self.unregisterGlobalNamespaces()
147
+ if python.IS_PYPY:
148
+ # clean up double refs in PyPy (see "_to_utf()" method)
149
+ for ref in self._utf_refs.itervalues():
150
+ python.Py_DECREF(ref)
151
+ self._utf_refs.clear()
152
+ self._eval_context_dict = None
153
+ self._doc = None
154
+
155
+ @cython.final
156
+ cdef _release_context(self):
157
+ if self._xpathCtxt is not NULL:
158
+ self._xpathCtxt.userData = NULL
159
+ self._xpathCtxt = NULL
160
+
161
+ # namespaces (internal UTF-8 methods with leading '_')
162
+
163
+ cdef addNamespace(self, prefix, ns_uri):
164
+ cdef list namespaces
165
+ if prefix is None:
166
+ raise TypeError, "empty prefix is not supported in XPath"
167
+ prefix_utf = self._to_utf(prefix)
168
+ ns_uri_utf = self._to_utf(ns_uri)
169
+ new_item = (prefix_utf, ns_uri_utf)
170
+ if self._namespaces is None:
171
+ self._namespaces = [new_item]
172
+ else:
173
+ namespaces = []
174
+ for item in self._namespaces:
175
+ if item[0] == prefix_utf:
176
+ item = new_item
177
+ new_item = None
178
+ namespaces.append(item)
179
+ if new_item is not None:
180
+ namespaces.append(new_item)
181
+ self._namespaces = namespaces
182
+ if self._xpathCtxt is not NULL:
183
+ xpath.xmlXPathRegisterNs(
184
+ self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
185
+
186
+ cdef registerNamespace(self, prefix, ns_uri):
187
+ if prefix is None:
188
+ raise TypeError, "empty prefix is not supported in XPath"
189
+ prefix_utf = self._to_utf(prefix)
190
+ ns_uri_utf = self._to_utf(ns_uri)
191
+ self._global_namespaces.append(prefix_utf)
192
+ xpath.xmlXPathRegisterNs(self._xpathCtxt,
193
+ _xcstr(prefix_utf), _xcstr(ns_uri_utf))
194
+
195
+ cdef registerLocalNamespaces(self):
196
+ if self._namespaces is None:
197
+ return
198
+ for prefix_utf, ns_uri_utf in self._namespaces:
199
+ xpath.xmlXPathRegisterNs(
200
+ self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
201
+
202
+ cdef registerGlobalNamespaces(self):
203
+ cdef list ns_prefixes = _find_all_extension_prefixes()
204
+ if python.PyList_GET_SIZE(ns_prefixes) > 0:
205
+ for prefix_utf, ns_uri_utf in ns_prefixes:
206
+ self._global_namespaces.append(prefix_utf)
207
+ xpath.xmlXPathRegisterNs(
208
+ self._xpathCtxt, _xcstr(prefix_utf), _xcstr(ns_uri_utf))
209
+
210
+ cdef unregisterGlobalNamespaces(self):
211
+ if python.PyList_GET_SIZE(self._global_namespaces) > 0:
212
+ for prefix_utf in self._global_namespaces:
213
+ xpath.xmlXPathRegisterNs(self._xpathCtxt,
214
+ _xcstr(prefix_utf), NULL)
215
+ del self._global_namespaces[:]
216
+
217
+ cdef void _unregisterNamespace(self, prefix_utf) noexcept:
218
+ xpath.xmlXPathRegisterNs(self._xpathCtxt,
219
+ _xcstr(prefix_utf), NULL)
220
+
221
+ # extension functions
222
+
223
+ cdef int _addLocalExtensionFunction(self, ns_utf, name_utf, function) except -1:
224
+ if self._extensions is None:
225
+ self._extensions = {}
226
+ self._extensions[(ns_utf, name_utf)] = function
227
+ return 0
228
+
229
+ cdef registerGlobalFunctions(self, void* ctxt,
230
+ _register_function reg_func):
231
+ cdef python.PyObject* dict_result
232
+ cdef dict d
233
+ for ns_utf, ns_functions in __FUNCTION_NAMESPACE_REGISTRIES.iteritems():
234
+ dict_result = python.PyDict_GetItem(
235
+ self._function_cache, ns_utf)
236
+ if dict_result is not NULL:
237
+ d = <dict>dict_result
238
+ else:
239
+ d = {}
240
+ self._function_cache[ns_utf] = d
241
+ for name_utf, function in ns_functions.iteritems():
242
+ d[name_utf] = function
243
+ reg_func(ctxt, name_utf, ns_utf)
244
+
245
+ cdef registerLocalFunctions(self, void* ctxt,
246
+ _register_function reg_func):
247
+ cdef python.PyObject* dict_result
248
+ cdef dict d
249
+ if self._extensions is None:
250
+ return # done
251
+ last_ns = None
252
+ d = None
253
+ for (ns_utf, name_utf), function in self._extensions.iteritems():
254
+ if ns_utf is not last_ns or d is None:
255
+ last_ns = ns_utf
256
+ dict_result = python.PyDict_GetItem(
257
+ self._function_cache, ns_utf)
258
+ if dict_result is not NULL:
259
+ d = <dict>dict_result
260
+ else:
261
+ d = {}
262
+ self._function_cache[ns_utf] = d
263
+ d[name_utf] = function
264
+ reg_func(ctxt, name_utf, ns_utf)
265
+
266
+ cdef unregisterAllFunctions(self, void* ctxt,
267
+ _register_function unreg_func):
268
+ for ns_utf, functions in self._function_cache.iteritems():
269
+ for name_utf in functions:
270
+ unreg_func(ctxt, name_utf, ns_utf)
271
+
272
+ cdef unregisterGlobalFunctions(self, void* ctxt,
273
+ _register_function unreg_func):
274
+ for ns_utf, functions in self._function_cache.items():
275
+ for name_utf in functions:
276
+ if self._extensions is None or \
277
+ (ns_utf, name_utf) not in self._extensions:
278
+ unreg_func(ctxt, name_utf, ns_utf)
279
+
280
+ @cython.final
281
+ cdef _find_cached_function(self, const_xmlChar* c_ns_uri, const_xmlChar* c_name):
282
+ """Lookup an extension function in the cache and return it.
283
+
284
+ Parameters: c_ns_uri may be NULL, c_name must not be NULL
285
+ """
286
+ cdef python.PyObject* c_dict
287
+ cdef python.PyObject* dict_result
288
+ c_dict = python.PyDict_GetItem(
289
+ self._function_cache, None if c_ns_uri is NULL else c_ns_uri)
290
+ if c_dict is not NULL:
291
+ dict_result = python.PyDict_GetItem(
292
+ <object>c_dict, <unsigned char*>c_name)
293
+ if dict_result is not NULL:
294
+ return <object>dict_result
295
+ return None
296
+
297
+ # Python access to the XPath context for extension functions
298
+
299
+ @property
300
+ def context_node(self):
301
+ cdef xmlNode* c_node
302
+ if self._xpathCtxt is NULL:
303
+ raise XPathError, \
304
+ "XPath context is only usable during the evaluation"
305
+ c_node = self._xpathCtxt.node
306
+ if c_node is NULL:
307
+ raise XPathError, "no context node"
308
+ if c_node.doc != self._xpathCtxt.doc:
309
+ raise XPathError, \
310
+ "document-external context nodes are not supported"
311
+ if self._doc is None:
312
+ raise XPathError, "document context is missing"
313
+ return _elementFactory(self._doc, c_node)
314
+
315
+ @property
316
+ def eval_context(self):
317
+ if self._eval_context_dict is None:
318
+ self._eval_context_dict = {}
319
+ return self._eval_context_dict
320
+
321
+ # Python reference keeping during XPath function evaluation
322
+
323
+ @cython.final
324
+ cdef _release_temp_refs(self):
325
+ "Free temporarily referenced objects from this context."
326
+ self._temp_refs.clear()
327
+ self._temp_documents.clear()
328
+
329
+ @cython.final
330
+ cdef _hold(self, obj):
331
+ """A way to temporarily hold references to nodes in the evaluator.
332
+
333
+ This is needed because otherwise nodes created in XPath extension
334
+ functions would be reference counted too soon, during the XPath
335
+ evaluation. This is most important in the case of exceptions.
336
+ """
337
+ cdef _Element element
338
+ if isinstance(obj, _Element):
339
+ self._temp_refs.add(obj)
340
+ self._temp_documents.add((<_Element>obj)._doc)
341
+ return
342
+ elif _isString(obj) or not python.PySequence_Check(obj):
343
+ return
344
+ for o in obj:
345
+ if isinstance(o, _Element):
346
+ #print "Holding element:", <int>element._c_node
347
+ self._temp_refs.add(o)
348
+ #print "Holding document:", <int>element._doc._c_doc
349
+ self._temp_documents.add((<_Element>o)._doc)
350
+
351
+ @cython.final
352
+ cdef _Document _findDocumentForNode(self, xmlNode* c_node):
353
+ """If an XPath expression returns an element from a different
354
+ document than the current context document, we call this to
355
+ see if it was possibly created by an extension and is a known
356
+ document instance.
357
+ """
358
+ cdef _Document doc
359
+ for doc in self._temp_documents:
360
+ if doc is not None and doc._c_doc is c_node.doc:
361
+ return doc
362
+ return None
363
+
364
+
365
+ # libxml2 keeps these error messages in a static array in its code
366
+ # and doesn't give us access to them ...
367
+
368
+ cdef tuple LIBXML2_XPATH_ERROR_MESSAGES = (
369
+ b"Ok",
370
+ b"Number encoding",
371
+ b"Unfinished literal",
372
+ b"Start of literal",
373
+ b"Expected $ for variable reference",
374
+ b"Undefined variable",
375
+ b"Invalid predicate",
376
+ b"Invalid expression",
377
+ b"Missing closing curly brace",
378
+ b"Unregistered function",
379
+ b"Invalid operand",
380
+ b"Invalid type",
381
+ b"Invalid number of arguments",
382
+ b"Invalid context size",
383
+ b"Invalid context position",
384
+ b"Memory allocation error",
385
+ b"Syntax error",
386
+ b"Resource error",
387
+ b"Sub resource error",
388
+ b"Undefined namespace prefix",
389
+ b"Encoding error",
390
+ b"Char out of XML range",
391
+ b"Invalid or incomplete context",
392
+ b"Stack usage error",
393
+ b"Forbidden variable\n",
394
+ b"?? Unknown error ??\n",
395
+ )
396
+
397
+ cdef void _forwardXPathError(void* c_ctxt, const xmlerror.xmlError* c_error) noexcept with gil:
398
+ cdef xmlerror.xmlError error
399
+ cdef int xpath_code
400
+ if c_error.message is not NULL:
401
+ error.message = c_error.message
402
+ else:
403
+ xpath_code = c_error.code - xmlerror.XML_XPATH_EXPRESSION_OK
404
+ if 0 <= xpath_code < len(LIBXML2_XPATH_ERROR_MESSAGES):
405
+ error.message = _cstr(LIBXML2_XPATH_ERROR_MESSAGES[xpath_code])
406
+ else:
407
+ error.message = b"unknown error"
408
+ error.domain = c_error.domain
409
+ error.code = c_error.code
410
+ error.level = c_error.level
411
+ error.line = c_error.line
412
+ error.int2 = c_error.int1 # column
413
+ error.file = c_error.file
414
+ error.node = NULL
415
+
416
+ (<_BaseContext>c_ctxt)._error_log._receive(&error)
417
+
418
+ cdef void _receiveXPathError(void* c_context, const xmlerror.xmlError* error) noexcept nogil:
419
+ if not __DEBUG:
420
+ return
421
+ if c_context is NULL:
422
+ _forwardError(NULL, error)
423
+ else:
424
+ _forwardXPathError(c_context, error)
425
+
426
+
427
+ def Extension(module, function_mapping=None, *, ns=None):
428
+ """Extension(module, function_mapping=None, ns=None)
429
+
430
+ Build a dictionary of extension functions from the functions
431
+ defined in a module or the methods of an object.
432
+
433
+ As second argument, you can pass an additional mapping of
434
+ attribute names to XPath function names, or a list of function
435
+ names that should be taken.
436
+
437
+ The ``ns`` keyword argument accepts a namespace URI for the XPath
438
+ functions.
439
+ """
440
+ cdef dict functions = {}
441
+ if isinstance(function_mapping, dict):
442
+ for function_name, xpath_name in function_mapping.items():
443
+ functions[(ns, xpath_name)] = getattr(module, function_name)
444
+ else:
445
+ if function_mapping is None:
446
+ function_mapping = [ name for name in dir(module)
447
+ if not name.startswith('_') ]
448
+ for function_name in function_mapping:
449
+ functions[(ns, function_name)] = getattr(module, function_name)
450
+ return functions
451
+
452
+ ################################################################################
453
+ # EXSLT regexp implementation
454
+
455
+ @cython.final
456
+ @cython.internal
457
+ cdef class _ExsltRegExp:
458
+ cdef dict _compile_map
459
+ def __cinit__(self):
460
+ self._compile_map = {}
461
+
462
+ cdef _make_string(self, value):
463
+ if _isString(value):
464
+ return value
465
+ elif isinstance(value, list):
466
+ # node set: take recursive text concatenation of first element
467
+ if python.PyList_GET_SIZE(value) == 0:
468
+ return ''
469
+ firstnode = value[0]
470
+ if _isString(firstnode):
471
+ return firstnode
472
+ elif isinstance(firstnode, _Element):
473
+ c_text = tree.xmlNodeGetContent((<_Element>firstnode)._c_node)
474
+ if c_text is NULL:
475
+ raise MemoryError()
476
+ try:
477
+ return funicode(c_text)
478
+ finally:
479
+ tree.xmlFree(c_text)
480
+ else:
481
+ return unicode(firstnode)
482
+ else:
483
+ return unicode(value)
484
+
485
+ cdef _compile(self, rexp, ignore_case):
486
+ cdef python.PyObject* c_result
487
+ rexp = self._make_string(rexp)
488
+ key = (rexp, ignore_case)
489
+ c_result = python.PyDict_GetItem(self._compile_map, key)
490
+ if c_result is not NULL:
491
+ return <object>c_result
492
+ py_flags = re.UNICODE
493
+ if ignore_case:
494
+ py_flags = py_flags | re.IGNORECASE
495
+ rexp_compiled = re.compile(rexp, py_flags)
496
+ self._compile_map[key] = rexp_compiled
497
+ return rexp_compiled
498
+
499
+ def test(self, ctxt, s, rexp, flags=''):
500
+ flags = self._make_string(flags)
501
+ s = self._make_string(s)
502
+ rexpc = self._compile(rexp, 'i' in flags)
503
+ if rexpc.search(s) is None:
504
+ return False
505
+ else:
506
+ return True
507
+
508
+ def match(self, ctxt, s, rexp, flags=''):
509
+ cdef list result_list
510
+ flags = self._make_string(flags)
511
+ s = self._make_string(s)
512
+ rexpc = self._compile(rexp, 'i' in flags)
513
+ if 'g' in flags:
514
+ results = rexpc.findall(s)
515
+ if not results:
516
+ return ()
517
+ else:
518
+ result = rexpc.search(s)
519
+ if not result:
520
+ return ()
521
+ results = [ result.group() ]
522
+ results.extend( result.groups('') )
523
+ result_list = []
524
+ root = Element('matches')
525
+ for s_match in results:
526
+ if python.PyTuple_CheckExact(s_match):
527
+ s_match = ''.join(s_match)
528
+ elem = SubElement(root, 'match')
529
+ elem.text = s_match
530
+ result_list.append(elem)
531
+ return result_list
532
+
533
+ def replace(self, ctxt, s, rexp, flags, replacement):
534
+ replacement = self._make_string(replacement)
535
+ flags = self._make_string(flags)
536
+ s = self._make_string(s)
537
+ rexpc = self._compile(rexp, 'i' in flags)
538
+ count: object = 0 if 'g' in flags else 1
539
+ return rexpc.sub(replacement, s, count)
540
+
541
+ cdef _register_in_context(self, _BaseContext context):
542
+ ns = b"http://exslt.org/regular-expressions"
543
+ context._addLocalExtensionFunction(ns, b"test", self.test)
544
+ context._addLocalExtensionFunction(ns, b"match", self.match)
545
+ context._addLocalExtensionFunction(ns, b"replace", self.replace)
546
+
547
+
548
+ ################################################################################
549
+ # helper functions
550
+
551
+ cdef xpath.xmlXPathObject* _wrapXPathObject(object obj, _Document doc,
552
+ _BaseContext context) except NULL:
553
+ cdef xpath.xmlNodeSet* resultSet
554
+ cdef _Element fake_node = None
555
+ cdef xmlNode* c_node
556
+
557
+ if isinstance(obj, unicode):
558
+ obj = _utf8(obj)
559
+ if isinstance(obj, bytes):
560
+ # libxml2 copies the string value
561
+ return xpath.xmlXPathNewCString(_cstr(obj))
562
+ if isinstance(obj, bool):
563
+ return xpath.xmlXPathNewBoolean(obj)
564
+ if python.PyNumber_Check(obj):
565
+ return xpath.xmlXPathNewFloat(obj)
566
+ if obj is None:
567
+ resultSet = xpath.xmlXPathNodeSetCreate(NULL)
568
+ elif isinstance(obj, _Element):
569
+ resultSet = xpath.xmlXPathNodeSetCreate((<_Element>obj)._c_node)
570
+ elif python.PySequence_Check(obj):
571
+ resultSet = xpath.xmlXPathNodeSetCreate(NULL)
572
+ try:
573
+ for value in obj:
574
+ if isinstance(value, _Element):
575
+ if context is not None:
576
+ context._hold(value)
577
+ xpath.xmlXPathNodeSetAdd(resultSet, (<_Element>value)._c_node)
578
+ else:
579
+ if context is None or doc is None:
580
+ raise XPathResultError, \
581
+ f"Non-Element values not supported at this point - got {value!r}"
582
+ # support strings by appending text nodes to an Element
583
+ if isinstance(value, unicode):
584
+ value = _utf8(value)
585
+ if isinstance(value, bytes):
586
+ if fake_node is None:
587
+ fake_node = _makeElement("text-root", NULL, doc, None,
588
+ None, None, None, None, None)
589
+ context._hold(fake_node)
590
+ else:
591
+ # append a comment node to keep the text nodes separate
592
+ c_node = tree.xmlNewDocComment(doc._c_doc, <unsigned char*>"")
593
+ if c_node is NULL:
594
+ raise MemoryError()
595
+ tree.xmlAddChild(fake_node._c_node, c_node)
596
+ context._hold(value)
597
+ c_node = tree.xmlNewDocText(doc._c_doc, _xcstr(value))
598
+ if c_node is NULL:
599
+ raise MemoryError()
600
+ tree.xmlAddChild(fake_node._c_node, c_node)
601
+ xpath.xmlXPathNodeSetAdd(resultSet, c_node)
602
+ else:
603
+ raise XPathResultError, \
604
+ f"This is not a supported node-set result: {value!r}"
605
+ except:
606
+ xpath.xmlXPathFreeNodeSet(resultSet)
607
+ raise
608
+ else:
609
+ raise XPathResultError, f"Unknown return type: {python._fqtypename(obj).decode('utf8')}"
610
+ return xpath.xmlXPathWrapNodeSet(resultSet)
611
+
612
+ cdef object _unwrapXPathObject(xpath.xmlXPathObject* xpathObj,
613
+ _Document doc, _BaseContext context):
614
+ if xpathObj.type == xpath.XPATH_UNDEFINED:
615
+ raise XPathResultError, "Undefined xpath result"
616
+ elif xpathObj.type == xpath.XPATH_NODESET:
617
+ return _createNodeSetResult(xpathObj, doc, context)
618
+ elif xpathObj.type == xpath.XPATH_BOOLEAN:
619
+ return xpathObj.boolval
620
+ elif xpathObj.type == xpath.XPATH_NUMBER:
621
+ return xpathObj.floatval
622
+ elif xpathObj.type == xpath.XPATH_STRING:
623
+ stringval = funicode(xpathObj.stringval)
624
+ if context._build_smart_strings:
625
+ stringval = _elementStringResultFactory(
626
+ stringval, None, None, False)
627
+ return stringval
628
+ elif xpathObj.type == xpath.XPATH_POINT:
629
+ raise NotImplementedError, "XPATH_POINT"
630
+ elif xpathObj.type == xpath.XPATH_RANGE:
631
+ raise NotImplementedError, "XPATH_RANGE"
632
+ elif xpathObj.type == xpath.XPATH_LOCATIONSET:
633
+ raise NotImplementedError, "XPATH_LOCATIONSET"
634
+ elif xpathObj.type == xpath.XPATH_USERS:
635
+ raise NotImplementedError, "XPATH_USERS"
636
+ elif xpathObj.type == xpath.XPATH_XSLT_TREE:
637
+ return _createNodeSetResult(xpathObj, doc, context)
638
+ else:
639
+ raise XPathResultError, f"Unknown xpath result {xpathObj.type}"
640
+
641
+ cdef object _createNodeSetResult(xpath.xmlXPathObject* xpathObj, _Document doc,
642
+ _BaseContext context):
643
+ cdef xmlNode* c_node
644
+ cdef int i
645
+ cdef list result
646
+ result = []
647
+ if xpathObj.nodesetval is NULL:
648
+ return result
649
+ for i in range(xpathObj.nodesetval.nodeNr):
650
+ c_node = xpathObj.nodesetval.nodeTab[i]
651
+ _unpackNodeSetEntry(result, c_node, doc, context,
652
+ xpathObj.type == xpath.XPATH_XSLT_TREE)
653
+ return result
654
+
655
+ cdef _unpackNodeSetEntry(list results, xmlNode* c_node, _Document doc,
656
+ _BaseContext context, bint is_fragment):
657
+ cdef xmlNode* c_child
658
+ if _isElement(c_node):
659
+ if c_node.doc != doc._c_doc and c_node.doc._private is NULL:
660
+ # XXX: works, but maybe not always the right thing to do?
661
+ # XPath: only runs when extensions create or copy trees
662
+ # -> we store Python refs to these, so that is OK
663
+ # XSLT: can it leak when merging trees from multiple sources?
664
+ c_node = tree.xmlDocCopyNode(c_node, doc._c_doc, 1)
665
+ # FIXME: call _instantiateElementFromXPath() instead?
666
+ results.append(
667
+ _fakeDocElementFactory(doc, c_node))
668
+ elif c_node.type == tree.XML_TEXT_NODE or \
669
+ c_node.type == tree.XML_CDATA_SECTION_NODE or \
670
+ c_node.type == tree.XML_ATTRIBUTE_NODE:
671
+ results.append(
672
+ _buildElementStringResult(doc, c_node, context))
673
+ elif c_node.type == tree.XML_NAMESPACE_DECL:
674
+ results.append( (funicodeOrNone((<xmlNs*>c_node).prefix),
675
+ funicodeOrNone((<xmlNs*>c_node).href)) )
676
+ elif c_node.type == tree.XML_DOCUMENT_NODE or \
677
+ c_node.type == tree.XML_HTML_DOCUMENT_NODE:
678
+ # ignored for everything but result tree fragments
679
+ if is_fragment:
680
+ c_child = c_node.children
681
+ while c_child is not NULL:
682
+ _unpackNodeSetEntry(results, c_child, doc, context, 0)
683
+ c_child = c_child.next
684
+ elif c_node.type == tree.XML_XINCLUDE_START or \
685
+ c_node.type == tree.XML_XINCLUDE_END:
686
+ pass
687
+ else:
688
+ raise NotImplementedError, \
689
+ f"Not yet implemented result node type: {c_node.type}"
690
+
691
+ cdef void _freeXPathObject(xpath.xmlXPathObject* xpathObj) noexcept:
692
+ """Free the XPath object, but *never* free the *content* of node sets.
693
+ Python dealloc will do that for us.
694
+ """
695
+ if xpathObj.nodesetval is not NULL:
696
+ xpath.xmlXPathFreeNodeSet(xpathObj.nodesetval)
697
+ xpathObj.nodesetval = NULL
698
+ xpath.xmlXPathFreeObject(xpathObj)
699
+
700
+ cdef _Element _instantiateElementFromXPath(xmlNode* c_node, _Document doc,
701
+ _BaseContext context):
702
+ # NOTE: this may copy the element - only call this when it can't leak
703
+ if c_node.doc != doc._c_doc and c_node.doc._private is NULL:
704
+ # not from the context document and not from a fake document
705
+ # either => may still be from a known document, e.g. one
706
+ # created by an extension function
707
+ node_doc = context._findDocumentForNode(c_node)
708
+ if node_doc is None:
709
+ # not from a known document at all! => can only make a
710
+ # safety copy here
711
+ c_node = tree.xmlDocCopyNode(c_node, doc._c_doc, 1)
712
+ else:
713
+ doc = node_doc
714
+ return _fakeDocElementFactory(doc, c_node)
715
+
716
+ ################################################################################
717
+ # special str/unicode subclasses
718
+
719
+ @cython.final
720
+ cdef class _ElementUnicodeResult(unicode):
721
+ cdef _Element _parent
722
+ cdef readonly object attrname
723
+ cdef readonly bint is_tail
724
+
725
+ def getparent(self):
726
+ return self._parent
727
+
728
+ @property
729
+ def is_text(self):
730
+ return self._parent is not None and not (self.is_tail or self.attrname is not None)
731
+
732
+ @property
733
+ def is_attribute(self):
734
+ return self.attrname is not None
735
+
736
+ cdef object _elementStringResultFactory(string_value, _Element parent,
737
+ attrname, bint is_tail):
738
+ result = _ElementUnicodeResult(string_value)
739
+ result._parent = parent
740
+ result.is_tail = is_tail
741
+ result.attrname = attrname
742
+ return result
743
+
744
+ cdef object _buildElementStringResult(_Document doc, xmlNode* c_node,
745
+ _BaseContext context):
746
+ cdef _Element parent = None
747
+ cdef object attrname = None
748
+ cdef xmlNode* c_element
749
+ cdef bint is_tail
750
+
751
+ if c_node.type == tree.XML_ATTRIBUTE_NODE:
752
+ attrname = _namespacedName(c_node)
753
+ is_tail = 0
754
+ s = tree.xmlNodeGetContent(c_node)
755
+ try:
756
+ value = funicode(s)
757
+ finally:
758
+ tree.xmlFree(s)
759
+ c_element = NULL
760
+ else:
761
+ #assert c_node.type == tree.XML_TEXT_NODE or c_node.type == tree.XML_CDATA_SECTION_NODE, "invalid node type"
762
+ # may be tail text or normal text
763
+ value = funicode(c_node.content)
764
+ c_element = _previousElement(c_node)
765
+ is_tail = c_element is not NULL
766
+
767
+ if not context._build_smart_strings:
768
+ return value
769
+
770
+ if c_element is NULL:
771
+ # non-tail text or attribute text
772
+ c_element = c_node.parent
773
+ while c_element is not NULL and not _isElement(c_element):
774
+ c_element = c_element.parent
775
+
776
+ if c_element is not NULL:
777
+ parent = _instantiateElementFromXPath(c_element, doc, context)
778
+
779
+ return _elementStringResultFactory(
780
+ value, parent, attrname, is_tail)
781
+
782
+ ################################################################################
783
+ # callbacks for XPath/XSLT extension functions
784
+
785
+ cdef void _extension_function_call(_BaseContext context, function,
786
+ xpath.xmlXPathParserContext* ctxt, int nargs) noexcept:
787
+ cdef _Document doc
788
+ cdef xpath.xmlXPathObject* obj
789
+ cdef list args
790
+ cdef int i
791
+ doc = context._doc
792
+ try:
793
+ args = []
794
+ for i in range(nargs):
795
+ obj = xpath.valuePop(ctxt)
796
+ o = _unwrapXPathObject(obj, doc, context)
797
+ _freeXPathObject(obj)
798
+ args.append(o)
799
+ args.reverse()
800
+
801
+ res = function(context, *args)
802
+ # wrap result for XPath consumption
803
+ obj = _wrapXPathObject(res, doc, context)
804
+ # prevent Python from deallocating elements handed to libxml2
805
+ context._hold(res)
806
+ xpath.valuePush(ctxt, obj)
807
+ except:
808
+ xpath.xmlXPathErr(ctxt, xpath.XPATH_EXPR_ERROR)
809
+ context._exc._store_raised()
810
+ finally:
811
+ return # swallow any further exceptions
812
+
813
+ # lookup the function by name and call it
814
+
815
+ cdef void _xpath_function_call(xpath.xmlXPathParserContext* ctxt,
816
+ int nargs) noexcept with gil:
817
+ cdef _BaseContext context
818
+ cdef xpath.xmlXPathContext* rctxt = ctxt.context
819
+ context = <_BaseContext> rctxt.userData
820
+ try:
821
+ function = context._find_cached_function(rctxt.functionURI, rctxt.function)
822
+ if function is not None:
823
+ _extension_function_call(context, function, ctxt, nargs)
824
+ else:
825
+ xpath.xmlXPathErr(ctxt, xpath.XPATH_UNKNOWN_FUNC_ERROR)
826
+ context._exc._store_exception(XPathFunctionError(
827
+ f"XPath function '{_namespacedNameFromNsName(rctxt.functionURI, rctxt.function)}' not found"))
828
+ except:
829
+ # may not be the right error, but we need to tell libxml2 *something*
830
+ xpath.xmlXPathErr(ctxt, xpath.XPATH_UNKNOWN_FUNC_ERROR)
831
+ context._exc._store_raised()
832
+ finally:
833
+ return # swallow any further exceptions
llava_video/lib/python3.10/site-packages/lxml/includes/__init__.pxd ADDED
File without changes
llava_video/lib/python3.10/site-packages/lxml/includes/__init__.py ADDED
File without changes
llava_video/lib/python3.10/site-packages/lxml/includes/c14n.pxd ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes.tree cimport xmlDoc, xmlOutputBuffer, xmlChar
2
+ from lxml.includes.xpath cimport xmlNodeSet
3
+
4
+ cdef extern from "libxml/c14n.h" nogil:
5
+ cdef int xmlC14NDocDumpMemory(xmlDoc* doc,
6
+ xmlNodeSet* nodes,
7
+ int exclusive,
8
+ xmlChar** inclusive_ns_prefixes,
9
+ int with_comments,
10
+ xmlChar** doc_txt_ptr)
11
+
12
+ cdef int xmlC14NDocSave(xmlDoc* doc,
13
+ xmlNodeSet* nodes,
14
+ int exclusive,
15
+ xmlChar** inclusive_ns_prefixes,
16
+ int with_comments,
17
+ char* filename,
18
+ int compression)
19
+
20
+ cdef int xmlC14NDocSaveTo(xmlDoc* doc,
21
+ xmlNodeSet* nodes,
22
+ int exclusive,
23
+ xmlChar** inclusive_ns_prefixes,
24
+ int with_comments,
25
+ xmlOutputBuffer* buffer)
llava_video/lib/python3.10/site-packages/lxml/includes/config.pxd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ cdef extern from "etree_defs.h":
2
+ cdef bint ENABLE_THREADING
3
+ cdef bint ENABLE_SCHEMATRON
llava_video/lib/python3.10/site-packages/lxml/includes/dtdvalid.pxd ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes cimport tree
2
+ from lxml.includes.tree cimport xmlDoc, xmlDtd
3
+
4
+ cdef extern from "libxml/valid.h" nogil:
5
+ ctypedef void (*xmlValidityErrorFunc)(void * ctx, const char * msg, ...) noexcept
6
+ ctypedef void (*xmlValidityWarningFunc)(void * ctx, const char * msg, ...) noexcept
7
+
8
+ ctypedef struct xmlValidCtxt:
9
+ void *userData
10
+ xmlValidityErrorFunc error
11
+ xmlValidityWarningFunc warning
12
+
13
+ cdef xmlValidCtxt* xmlNewValidCtxt()
14
+ cdef void xmlFreeValidCtxt(xmlValidCtxt* cur)
15
+
16
+ cdef int xmlValidateDtd(xmlValidCtxt* ctxt, xmlDoc* doc, xmlDtd* dtd)
17
+ cdef tree.xmlElement* xmlGetDtdElementDesc(
18
+ xmlDtd* dtd, tree.const_xmlChar* name)
llava_video/lib/python3.10/site-packages/lxml/includes/etree_defs.h ADDED
@@ -0,0 +1,379 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HAS_ETREE_DEFS_H
2
+ #define HAS_ETREE_DEFS_H
3
+
4
+ /* quick check for Python/libxml2/libxslt devel setup */
5
+ #include "Python.h"
6
+ #ifndef PY_VERSION_HEX
7
+ # error the development package of Python (header files etc.) is not installed correctly
8
+ #elif PY_VERSION_HEX < 0x03060000
9
+ # error this version of lxml requires Python 3.6 or later
10
+ #endif
11
+
12
+ #include "libxml/xmlversion.h"
13
+ #ifndef LIBXML_VERSION
14
+ # error the development package of libxml2 (header files etc.) is not installed correctly
15
+ #elif LIBXML_VERSION < 20700
16
+ # error minimum required version of libxml2 is 2.7.0
17
+ #endif
18
+
19
+ #include "libxslt/xsltconfig.h"
20
+ #ifndef LIBXSLT_VERSION
21
+ # error the development package of libxslt (header files etc.) is not installed correctly
22
+ #elif LIBXSLT_VERSION < 10123
23
+ # error minimum required version of libxslt is 1.1.23
24
+ #endif
25
+
26
+
27
+ /* v_arg functions */
28
+ #define va_int(ap) va_arg(ap, int)
29
+ #define va_charptr(ap) va_arg(ap, char *)
30
+
31
+ #ifdef PYPY_VERSION
32
+ # define IS_PYPY 1
33
+ #else
34
+ # define IS_PYPY 0
35
+ #endif
36
+
37
+ /* unused */
38
+ #define IS_PYTHON2 0
39
+ #define IS_PYTHON3 1
40
+ #undef LXML_UNICODE_STRINGS
41
+ #define LXML_UNICODE_STRINGS 1
42
+
43
+ #if !IS_PYPY
44
+ # define PyWeakref_LockObject(obj) (NULL)
45
+ #endif
46
+
47
+ /* Threading is not currently supported by PyPy */
48
+ #if IS_PYPY
49
+ # ifndef WITHOUT_THREADING
50
+ # define WITHOUT_THREADING
51
+ # endif
52
+ #endif
53
+
54
+ #if IS_PYPY
55
+ # ifndef PyUnicode_FromFormat
56
+ # define PyUnicode_FromFormat PyString_FromFormat
57
+ # endif
58
+ # if !defined(PyBytes_FromFormat)
59
+ # ifdef PyString_FromFormat
60
+ # define PyBytes_FromFormat PyString_FromFormat
61
+ # else
62
+ #include <stdarg.h>
63
+ static PyObject* PyBytes_FromFormat(const char* format, ...) {
64
+ PyObject *string;
65
+ va_list vargs;
66
+ #ifdef HAVE_STDARG_PROTOTYPES
67
+ va_start(vargs, format);
68
+ #else
69
+ va_start(vargs);
70
+ #endif
71
+ string = PyUnicode_FromFormatV(format, vargs);
72
+ va_end(vargs);
73
+ if (string && PyUnicode_Check(string)) {
74
+ PyObject *bstring = PyUnicode_AsUTF8String(string);
75
+ Py_DECREF(string);
76
+ string = bstring;
77
+ }
78
+ if (string && !PyBytes_CheckExact(string)) {
79
+ Py_DECREF(string);
80
+ string = NULL;
81
+ PyErr_SetString(PyExc_TypeError, "String formatting and encoding failed to return bytes object");
82
+ }
83
+ return string;
84
+ }
85
+ # endif
86
+ # endif
87
+ #endif
88
+
89
+ #if PY_VERSION_HEX >= 0x030B00A1
90
+ /* Python 3.12 doesn't have wstr Unicode strings any more. */
91
+ #undef PyUnicode_GET_DATA_SIZE
92
+ #define PyUnicode_GET_DATA_SIZE(ustr) (0)
93
+ #undef PyUnicode_AS_DATA
94
+ #define PyUnicode_AS_DATA(ustr) (NULL)
95
+ #undef PyUnicode_IS_READY
96
+ #define PyUnicode_IS_READY(ustr) (1)
97
+ #endif
98
+
99
+ #ifdef WITHOUT_THREADING
100
+ # undef PyEval_SaveThread
101
+ # define PyEval_SaveThread() (NULL)
102
+ # undef PyEval_RestoreThread
103
+ # define PyEval_RestoreThread(state) if (state); else {}
104
+ # undef PyGILState_Ensure
105
+ # define PyGILState_Ensure() (PyGILState_UNLOCKED)
106
+ # undef PyGILState_Release
107
+ # define PyGILState_Release(state) if (state); else {}
108
+ # undef Py_UNBLOCK_THREADS
109
+ # define Py_UNBLOCK_THREADS _save = NULL;
110
+ # undef Py_BLOCK_THREADS
111
+ # define Py_BLOCK_THREADS if (_save); else {}
112
+ #endif
113
+
114
+ #ifdef WITHOUT_THREADING
115
+ # define ENABLE_THREADING 0
116
+ #else
117
+ # define ENABLE_THREADING 1
118
+ #endif
119
+
120
+ #if LIBXML_VERSION < 20704
121
+ /* FIXME: hack to make new error reporting compile in old libxml2 versions */
122
+ # define xmlStructuredErrorContext NULL
123
+ # define xmlXIncludeProcessTreeFlagsData(n,o,d) xmlXIncludeProcessTreeFlags(n,o)
124
+ #endif
125
+
126
+ /* schematron was added in libxml2 2.6.21 */
127
+ #ifdef LIBXML_SCHEMATRON_ENABLED
128
+ # define ENABLE_SCHEMATRON 1
129
+ #else
130
+ # define ENABLE_SCHEMATRON 0
131
+ # define XML_SCHEMATRON_OUT_QUIET 0
132
+ # define XML_SCHEMATRON_OUT_XML 0
133
+ # define XML_SCHEMATRON_OUT_ERROR 0
134
+ typedef void xmlSchematron;
135
+ typedef void xmlSchematronParserCtxt;
136
+ typedef void xmlSchematronValidCtxt;
137
+ # define xmlSchematronNewDocParserCtxt(doc) NULL
138
+ # define xmlSchematronNewParserCtxt(file) NULL
139
+ # define xmlSchematronParse(ctxt) NULL
140
+ # define xmlSchematronFreeParserCtxt(ctxt)
141
+ # define xmlSchematronFree(schema)
142
+ # define xmlSchematronNewValidCtxt(schema, options) NULL
143
+ # define xmlSchematronValidateDoc(ctxt, doc) 0
144
+ # define xmlSchematronFreeValidCtxt(ctxt)
145
+ # define xmlSchematronSetValidStructuredErrors(ctxt, errorfunc, data)
146
+ #endif
147
+
148
+ #if LIBXML_VERSION < 20708
149
+ # define HTML_PARSE_NODEFDTD 4
150
+ #endif
151
+ #if LIBXML_VERSION < 20900
152
+ # define XML_PARSE_BIG_LINES 4194304
153
+ #endif
154
+
155
+ #include "libxml/tree.h"
156
+ #ifndef LIBXML2_NEW_BUFFER
157
+ typedef xmlBuffer xmlBuf;
158
+ # define xmlBufContent(buf) xmlBufferContent(buf)
159
+ # define xmlBufUse(buf) xmlBufferLength(buf)
160
+ #endif
161
+
162
+ /* libexslt 1.1.25+ support EXSLT functions in XPath */
163
+ #if LIBXSLT_VERSION < 10125
164
+ #define exsltDateXpathCtxtRegister(ctxt, prefix)
165
+ #define exsltSetsXpathCtxtRegister(ctxt, prefix)
166
+ #define exsltMathXpathCtxtRegister(ctxt, prefix)
167
+ #define exsltStrXpathCtxtRegister(ctxt, prefix)
168
+ #endif
169
+
170
+ #define LXML_GET_XSLT_ENCODING(result_var, style) XSLT_GET_IMPORT_PTR(result_var, style, encoding)
171
+
172
+ /* work around MSDEV 6.0 */
173
+ #if (_MSC_VER == 1200) && (WINVER < 0x0500)
174
+ long _ftol( double ); //defined by VC6 C libs
175
+ long _ftol2( double dblSource ) { return _ftol( dblSource ); }
176
+ #endif
177
+
178
+ #ifdef __GNUC__
179
+ /* Test for GCC > 2.95 */
180
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
181
+ #define unlikely_condition(x) __builtin_expect((x), 0)
182
+ #else /* __GNUC__ > 2 ... */
183
+ #define unlikely_condition(x) (x)
184
+ #endif /* __GNUC__ > 2 ... */
185
+ #else /* __GNUC__ */
186
+ #define unlikely_condition(x) (x)
187
+ #endif /* __GNUC__ */
188
+
189
+ #ifndef Py_TYPE
190
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
191
+ #endif
192
+
193
+ #define PY_NEW(T) \
194
+ (((PyTypeObject*)(T))->tp_new( \
195
+ (PyTypeObject*)(T), __pyx_empty_tuple, NULL))
196
+
197
+ #define _fqtypename(o) ((Py_TYPE(o))->tp_name)
198
+
199
+ #define lxml_malloc(count, item_size) \
200
+ (unlikely_condition((size_t)(count) > (size_t) (PY_SSIZE_T_MAX / item_size)) ? NULL : \
201
+ (PyMem_Malloc((count) * item_size)))
202
+
203
+ #define lxml_realloc(mem, count, item_size) \
204
+ (unlikely_condition((size_t)(count) > (size_t) (PY_SSIZE_T_MAX / item_size)) ? NULL : \
205
+ (PyMem_Realloc(mem, (count) * item_size)))
206
+
207
+ #define lxml_free(mem) PyMem_Free(mem)
208
+
209
+ #define _isString(obj) (PyUnicode_Check(obj) || PyBytes_Check(obj))
210
+
211
+ #define _isElement(c_node) \
212
+ (((c_node)->type == XML_ELEMENT_NODE) || \
213
+ ((c_node)->type == XML_COMMENT_NODE) || \
214
+ ((c_node)->type == XML_ENTITY_REF_NODE) || \
215
+ ((c_node)->type == XML_PI_NODE))
216
+
217
+ #define _isElementOrXInclude(c_node) \
218
+ (_isElement(c_node) || \
219
+ ((c_node)->type == XML_XINCLUDE_START) || \
220
+ ((c_node)->type == XML_XINCLUDE_END))
221
+
222
+ #define _getNs(c_node) \
223
+ (((c_node)->ns == 0) ? 0 : ((c_node)->ns->href))
224
+
225
+
226
+ #include "string.h"
227
+ static void* lxml_unpack_xmldoc_capsule(PyObject* capsule, int* is_owned) {
228
+ xmlDoc *c_doc;
229
+ void *context;
230
+ *is_owned = 0;
231
+ if (unlikely_condition(!PyCapsule_IsValid(capsule, (const char*)"libxml2:xmlDoc"))) {
232
+ PyErr_SetString(
233
+ PyExc_TypeError,
234
+ "Not a valid capsule. The capsule argument must be a capsule object with name libxml2:xmlDoc");
235
+ return NULL;
236
+ }
237
+ c_doc = (xmlDoc*) PyCapsule_GetPointer(capsule, (const char*)"libxml2:xmlDoc");
238
+ if (unlikely_condition(!c_doc)) return NULL;
239
+
240
+ if (unlikely_condition(c_doc->type != XML_DOCUMENT_NODE && c_doc->type != XML_HTML_DOCUMENT_NODE)) {
241
+ PyErr_Format(
242
+ PyExc_ValueError,
243
+ "Illegal document provided: expected XML or HTML, found %d", (int)c_doc->type);
244
+ return NULL;
245
+ }
246
+
247
+ context = PyCapsule_GetContext(capsule);
248
+ if (unlikely_condition(!context && PyErr_Occurred())) return NULL;
249
+ if (context && strcmp((const char*) context, "destructor:xmlFreeDoc") == 0) {
250
+ /* take ownership by setting destructor to NULL */
251
+ if (PyCapsule_SetDestructor(capsule, NULL) == 0) {
252
+ /* ownership transferred => invalidate capsule by clearing its name */
253
+ if (unlikely_condition(PyCapsule_SetName(capsule, NULL))) {
254
+ /* this should never happen since everything above succeeded */
255
+ xmlFreeDoc(c_doc);
256
+ return NULL;
257
+ }
258
+ *is_owned = 1;
259
+ }
260
+ }
261
+ return c_doc;
262
+ }
263
+
264
+ /* Macro pair implementation of a depth first tree walker
265
+ *
266
+ * Calls the code block between the BEGIN and END macros for all elements
267
+ * below c_tree_top (exclusively), starting at c_node (inclusively iff
268
+ * 'inclusive' is 1). The _ELEMENT_ variants will only stop on nodes
269
+ * that match _isElement(), the normal variant will stop on every node
270
+ * except text nodes.
271
+ *
272
+ * To traverse the node and all of its children and siblings in Pyrex, call
273
+ * cdef xmlNode* some_node
274
+ * BEGIN_FOR_EACH_ELEMENT_FROM(some_node.parent, some_node, 1)
275
+ * # do something with some_node
276
+ * END_FOR_EACH_ELEMENT_FROM(some_node)
277
+ *
278
+ * To traverse only the children and siblings of a node, call
279
+ * cdef xmlNode* some_node
280
+ * BEGIN_FOR_EACH_ELEMENT_FROM(some_node.parent, some_node, 0)
281
+ * # do something with some_node
282
+ * END_FOR_EACH_ELEMENT_FROM(some_node)
283
+ *
284
+ * To traverse only the children, do:
285
+ * cdef xmlNode* some_node
286
+ * some_node = parent_node.children
287
+ * BEGIN_FOR_EACH_ELEMENT_FROM(parent_node, some_node, 1)
288
+ * # do something with some_node
289
+ * END_FOR_EACH_ELEMENT_FROM(some_node)
290
+ *
291
+ * NOTE: 'some_node' MUST be a plain 'xmlNode*' !
292
+ *
293
+ * NOTE: parent modification during the walk can divert the iterator, but
294
+ * should not segfault !
295
+ */
296
+
297
+ #define _LX__ELEMENT_MATCH(c_node, only_elements) \
298
+ ((only_elements) ? (_isElement(c_node)) : 1)
299
+
300
+ #define _LX__ADVANCE_TO_NEXT(c_node, only_elements) \
301
+ while ((c_node != 0) && (!_LX__ELEMENT_MATCH(c_node, only_elements))) \
302
+ c_node = c_node->next;
303
+
304
+ #define _LX__TRAVERSE_TO_NEXT(c_stop_node, c_node, only_elements) \
305
+ { \
306
+ /* walk through children first */ \
307
+ xmlNode* _lx__next = c_node->children; \
308
+ if (_lx__next != 0) { \
309
+ if (c_node->type == XML_ENTITY_REF_NODE || c_node->type == XML_DTD_NODE) { \
310
+ _lx__next = 0; \
311
+ } else { \
312
+ _LX__ADVANCE_TO_NEXT(_lx__next, only_elements) \
313
+ } \
314
+ } \
315
+ if ((_lx__next == 0) && (c_node != c_stop_node)) { \
316
+ /* try siblings */ \
317
+ _lx__next = c_node->next; \
318
+ _LX__ADVANCE_TO_NEXT(_lx__next, only_elements) \
319
+ /* back off through parents */ \
320
+ while (_lx__next == 0) { \
321
+ c_node = c_node->parent; \
322
+ if (c_node == 0) \
323
+ break; \
324
+ if (c_node == c_stop_node) \
325
+ break; \
326
+ if ((only_elements) && !_isElement(c_node)) \
327
+ break; \
328
+ /* we already traversed the parents -> siblings */ \
329
+ _lx__next = c_node->next; \
330
+ _LX__ADVANCE_TO_NEXT(_lx__next, only_elements) \
331
+ } \
332
+ } \
333
+ c_node = _lx__next; \
334
+ }
335
+
336
+ #define _LX__BEGIN_FOR_EACH_FROM(c_tree_top, c_node, inclusive, only_elements) \
337
+ { \
338
+ if (c_node != 0) { \
339
+ const xmlNode* _lx__tree_top = (c_tree_top); \
340
+ const int _lx__only_elements = (only_elements); \
341
+ /* make sure we start at an element */ \
342
+ if (!_LX__ELEMENT_MATCH(c_node, _lx__only_elements)) { \
343
+ /* we skip the node, so 'inclusive' is irrelevant */ \
344
+ if (c_node == _lx__tree_top) \
345
+ c_node = 0; /* nothing to traverse */ \
346
+ else { \
347
+ c_node = c_node->next; \
348
+ _LX__ADVANCE_TO_NEXT(c_node, _lx__only_elements) \
349
+ } \
350
+ } else if (! (inclusive)) { \
351
+ /* skip the first node */ \
352
+ _LX__TRAVERSE_TO_NEXT(_lx__tree_top, c_node, _lx__only_elements) \
353
+ } \
354
+ \
355
+ /* now run the user code on the elements we find */ \
356
+ while (c_node != 0) { \
357
+ /* here goes the code to be run for each element */
358
+
359
+ #define _LX__END_FOR_EACH_FROM(c_node) \
360
+ _LX__TRAVERSE_TO_NEXT(_lx__tree_top, c_node, _lx__only_elements) \
361
+ } \
362
+ } \
363
+ }
364
+
365
+
366
+ #define BEGIN_FOR_EACH_ELEMENT_FROM(c_tree_top, c_node, inclusive) \
367
+ _LX__BEGIN_FOR_EACH_FROM(c_tree_top, c_node, inclusive, 1)
368
+
369
+ #define END_FOR_EACH_ELEMENT_FROM(c_node) \
370
+ _LX__END_FOR_EACH_FROM(c_node)
371
+
372
+ #define BEGIN_FOR_EACH_FROM(c_tree_top, c_node, inclusive) \
373
+ _LX__BEGIN_FOR_EACH_FROM(c_tree_top, c_node, inclusive, 0)
374
+
375
+ #define END_FOR_EACH_FROM(c_node) \
376
+ _LX__END_FOR_EACH_FROM(c_node)
377
+
378
+
379
+ #endif /* HAS_ETREE_DEFS_H */
llava_video/lib/python3.10/site-packages/lxml/includes/etreepublic.pxd ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # public Cython/C interface to lxml.etree
2
+
3
+ from lxml.includes cimport tree
4
+ from lxml.includes.tree cimport const_xmlChar
5
+
6
+ cdef extern from "lxml-version.h":
7
+ cdef char* LXML_VERSION_STRING
8
+
9
+ cdef extern from "etree_defs.h":
10
+ # test if c_node is considered an Element (i.e. Element, Comment, etc.)
11
+ cdef bint _isElement(tree.xmlNode* c_node) noexcept nogil
12
+
13
+ # return the namespace URI of the node or NULL
14
+ cdef const_xmlChar* _getNs(tree.xmlNode* node) noexcept nogil
15
+
16
+ # pair of macros for tree traversal
17
+ cdef void BEGIN_FOR_EACH_ELEMENT_FROM(tree.xmlNode* tree_top,
18
+ tree.xmlNode* start_node,
19
+ int start_node_inclusive) noexcept nogil
20
+ cdef void END_FOR_EACH_ELEMENT_FROM(tree.xmlNode* start_node) noexcept nogil
21
+
22
+ cdef extern from "etree_api.h":
23
+
24
+ # first function to call!
25
+ cdef int import_lxml__etree() except -1
26
+
27
+ ##########################################################################
28
+ # public ElementTree API classes
29
+
30
+ cdef class lxml.etree._Document [ object LxmlDocument ]:
31
+ cdef tree.xmlDoc* _c_doc
32
+
33
+ cdef class lxml.etree._Element [ object LxmlElement ]:
34
+ cdef _Document _doc
35
+ cdef tree.xmlNode* _c_node
36
+
37
+ cdef class lxml.etree.ElementBase(_Element) [ object LxmlElementBase ]:
38
+ pass
39
+
40
+ cdef class lxml.etree._ElementTree [ object LxmlElementTree ]:
41
+ cdef _Document _doc
42
+ cdef _Element _context_node
43
+
44
+ cdef class lxml.etree.ElementClassLookup [ object LxmlElementClassLookup ]:
45
+ cdef object (*_lookup_function)(object, _Document, tree.xmlNode*)
46
+
47
+ cdef class lxml.etree.FallbackElementClassLookup(ElementClassLookup) \
48
+ [ object LxmlFallbackElementClassLookup ]:
49
+ cdef ElementClassLookup fallback
50
+ cdef object (*_fallback_function)(object, _Document, tree.xmlNode*)
51
+
52
+ ##########################################################################
53
+ # creating Element objects
54
+
55
+ # create an Element for a C-node in the Document
56
+ cdef _Element elementFactory(_Document doc, tree.xmlNode* c_node)
57
+
58
+ # create an ElementTree for an Element
59
+ cdef _ElementTree elementTreeFactory(_Element context_node)
60
+
61
+ # create an ElementTree subclass for an Element
62
+ cdef _ElementTree newElementTree(_Element context_node, object subclass)
63
+
64
+ # create an ElementTree from an external document
65
+ cdef _ElementTree adoptExternalDocument(tree.xmlDoc* c_doc, parser, bint is_owned)
66
+
67
+ # create a new Element for an existing or new document (doc = None)
68
+ # builds Python object after setting text, tail, namespaces and attributes
69
+ cdef _Element makeElement(tag, _Document doc, parser,
70
+ text, tail, attrib, nsmap)
71
+
72
+ # create a new SubElement for an existing parent
73
+ # builds Python object after setting text, tail, namespaces and attributes
74
+ cdef _Element makeSubElement(_Element parent, tag, text, tail,
75
+ attrib, nsmap)
76
+
77
+ # deep copy a node to include it in the Document
78
+ cdef _Element deepcopyNodeToDocument(_Document doc, tree.xmlNode* c_root)
79
+
80
+ # set the internal lookup function for Element/Comment/PI classes
81
+ # use setElementClassLookupFunction(NULL, None) to reset it
82
+ # note that the lookup function *must always* return an _Element subclass!
83
+ cdef void setElementClassLookupFunction(
84
+ object (*function)(object, _Document, tree.xmlNode*), object state)
85
+
86
+ # lookup function that always returns the default Element class
87
+ # note that the first argument is expected to be None!
88
+ cdef object lookupDefaultElementClass(_1, _Document _2,
89
+ tree.xmlNode* c_node)
90
+
91
+ # lookup function for namespace/tag specific Element classes
92
+ # note that the first argument is expected to be None!
93
+ cdef object lookupNamespaceElementClass(_1, _Document _2,
94
+ tree.xmlNode* c_node)
95
+
96
+ # call the fallback lookup function of a FallbackElementClassLookup
97
+ cdef object callLookupFallback(FallbackElementClassLookup lookup,
98
+ _Document doc, tree.xmlNode* c_node)
99
+
100
+ ##########################################################################
101
+ # XML attribute access
102
+
103
+ # return an attribute value for a C attribute on a C element node
104
+ cdef unicode attributeValue(tree.xmlNode* c_element,
105
+ tree.xmlAttr* c_attrib_node)
106
+
107
+ # return the value of the attribute with 'ns' and 'name' (or None)
108
+ cdef unicode attributeValueFromNsName(tree.xmlNode* c_element,
109
+ const_xmlChar* c_ns, const_xmlChar* c_name)
110
+
111
+ # return the value of attribute "{ns}name", or the default value
112
+ cdef object getAttributeValue(_Element element, key, default)
113
+
114
+ # return an iterator over attribute names (1), values (2) or items (3)
115
+ # attributes must not be removed during iteration!
116
+ cdef object iterattributes(_Element element, int keysvalues)
117
+
118
+ # return the list of all attribute names (1), values (2) or items (3)
119
+ cdef list collectAttributes(tree.xmlNode* c_element, int keysvalues)
120
+
121
+ # set an attribute value on an element
122
+ # on failure, sets an exception and returns -1
123
+ cdef int setAttributeValue(_Element element, key, value) except -1
124
+
125
+ # delete an attribute
126
+ # on failure, sets an exception and returns -1
127
+ cdef int delAttribute(_Element element, key) except -1
128
+
129
+ # delete an attribute based on name and namespace URI
130
+ # returns -1 if the attribute was not found (no exception)
131
+ cdef int delAttributeFromNsName(tree.xmlNode* c_element,
132
+ const_xmlChar* c_href, const_xmlChar* c_name) noexcept
133
+
134
+ ##########################################################################
135
+ # XML node helper functions
136
+
137
+ # check if the element has at least one child
138
+ cdef bint hasChild(tree.xmlNode* c_node) noexcept nogil
139
+
140
+ # find child element number 'index' (supports negative indexes)
141
+ cdef tree.xmlNode* findChild(tree.xmlNode* c_node,
142
+ Py_ssize_t index) noexcept nogil
143
+
144
+ # find child element number 'index' starting at first one
145
+ cdef tree.xmlNode* findChildForwards(tree.xmlNode* c_node,
146
+ Py_ssize_t index) nogil
147
+
148
+ # find child element number 'index' starting at last one
149
+ cdef tree.xmlNode* findChildBackwards(tree.xmlNode* c_node,
150
+ Py_ssize_t index) nogil
151
+
152
+ # return next/previous sibling element of the node
153
+ cdef tree.xmlNode* nextElement(tree.xmlNode* c_node) nogil
154
+ cdef tree.xmlNode* previousElement(tree.xmlNode* c_node) nogil
155
+
156
+ ##########################################################################
157
+ # iterators (DEPRECATED API, don't use in new code!)
158
+
159
+ cdef class lxml.etree._ElementTagMatcher [ object LxmlElementTagMatcher ]:
160
+ cdef char* _href
161
+ cdef char* _name
162
+
163
+ # store "{ns}tag" (or None) filter for this matcher or element iterator
164
+ # ** unless _href *and* _name are set up 'by hand', this function *must*
165
+ # ** be called when subclassing the iterator below!
166
+ cdef void initTagMatch(_ElementTagMatcher matcher, tag)
167
+
168
+ cdef class lxml.etree._ElementIterator(_ElementTagMatcher) [
169
+ object LxmlElementIterator ]:
170
+ cdef _Element _node
171
+ cdef tree.xmlNode* (*_next_element)(tree.xmlNode*)
172
+
173
+ # store the initial node of the iterator if it matches the required tag
174
+ # or its next matching sibling if not
175
+ cdef void iteratorStoreNext(_ElementIterator iterator, _Element node)
176
+
177
+ ##########################################################################
178
+ # other helper functions
179
+
180
+ # check if a C node matches a tag name and namespace
181
+ # (NULL allowed for each => always matches)
182
+ cdef int tagMatches(tree.xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name)
183
+
184
+ # convert a UTF-8 char* to a Python unicode string
185
+ cdef unicode pyunicode(const_xmlChar* s)
186
+
187
+ # convert the string to UTF-8 using the normal lxml.etree semantics
188
+ cdef bytes utf8(object s)
189
+
190
+ # split a tag into a (URI, name) tuple, return None as URI for '{}tag'
191
+ cdef tuple getNsTag(object tag)
192
+
193
+ # split a tag into a (URI, name) tuple, return b'' as URI for '{}tag'
194
+ cdef tuple getNsTagWithEmptyNs(object tag)
195
+
196
+ # get the "{ns}tag" string for a C node
197
+ cdef unicode namespacedName(tree.xmlNode* c_node)
198
+
199
+ # get the "{ns}tag" string for a href/tagname pair (c_ns may be NULL)
200
+ cdef unicode namespacedNameFromNsName(const_xmlChar* c_ns, const_xmlChar* c_tag)
201
+
202
+ # check if the node has a text value (which may be '')
203
+ cdef bint hasText(tree.xmlNode* c_node) nogil
204
+
205
+ # check if the node has a tail value (which may be '')
206
+ cdef bint hasTail(tree.xmlNode* c_node) nogil
207
+
208
+ # get the text content of an element (or None)
209
+ cdef unicode textOf(tree.xmlNode* c_node)
210
+
211
+ # get the tail content of an element (or None)
212
+ cdef unicode tailOf(tree.xmlNode* c_node)
213
+
214
+ # set the text value of an element
215
+ cdef int setNodeText(tree.xmlNode* c_node, text) except -1
216
+
217
+ # set the tail text value of an element
218
+ cdef int setTailText(tree.xmlNode* c_node, text) except -1
219
+
220
+ # append an element to the children of a parent element
221
+ # deprecated: don't use, does not propagate exceptions!
222
+ # use appendChildToElement() instead
223
+ cdef void appendChild(_Element parent, _Element child)
224
+
225
+ # added in lxml 3.3 as a safe replacement for appendChild()
226
+ # return -1 for exception, 0 for ok
227
+ cdef int appendChildToElement(_Element parent, _Element child) except -1
228
+
229
+ # recursively lookup a namespace in element or ancestors, or create it
230
+ cdef tree.xmlNs* findOrBuildNodeNsPrefix(
231
+ _Document doc, tree.xmlNode* c_node, const_xmlChar* href, const_xmlChar* prefix)
232
+
233
+ # find the Document of an Element, ElementTree or Document (itself!)
234
+ cdef _Document documentOrRaise(object input)
235
+
236
+ # find the root Element of an Element (itself!), ElementTree or Document
237
+ cdef _Element rootNodeOrRaise(object input)
llava_video/lib/python3.10/site-packages/lxml/includes/htmlparser.pxd ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from libc.string cimport const_char
2
+
3
+ from lxml.includes.tree cimport xmlDoc
4
+ from lxml.includes.tree cimport xmlInputReadCallback, xmlInputCloseCallback
5
+ from lxml.includes.xmlparser cimport xmlParserCtxt, xmlSAXHandler, xmlSAXHandlerV1
6
+
7
+ cdef extern from "libxml/HTMLparser.h" nogil:
8
+ ctypedef enum htmlParserOption:
9
+ HTML_PARSE_NOERROR # suppress error reports
10
+ HTML_PARSE_NOWARNING # suppress warning reports
11
+ HTML_PARSE_PEDANTIC # pedantic error reporting
12
+ HTML_PARSE_NOBLANKS # remove blank nodes
13
+ HTML_PARSE_NONET # Forbid network access
14
+ # libxml2 2.6.21+ only:
15
+ HTML_PARSE_RECOVER # Relaxed parsing
16
+ HTML_PARSE_COMPACT # compact small text nodes
17
+ # libxml2 2.7.7+ only:
18
+ HTML_PARSE_NOIMPLIED # Do not add implied html/body... elements
19
+ # libxml2 2.7.8+ only:
20
+ HTML_PARSE_NODEFDTD # do not default a doctype if not found
21
+ # libxml2 2.8.0+ only:
22
+ XML_PARSE_IGNORE_ENC # ignore internal document encoding hint
23
+
24
+ xmlSAXHandlerV1 htmlDefaultSAXHandler
25
+
26
+ cdef xmlParserCtxt* htmlCreateMemoryParserCtxt(
27
+ char* buffer, int size)
28
+ cdef xmlParserCtxt* htmlCreateFileParserCtxt(
29
+ char* filename, char* encoding)
30
+ cdef xmlParserCtxt* htmlCreatePushParserCtxt(xmlSAXHandler* sax,
31
+ void* user_data,
32
+ char* chunk, int size,
33
+ char* filename, int enc)
34
+ cdef void htmlFreeParserCtxt(xmlParserCtxt* ctxt)
35
+ cdef void htmlCtxtReset(xmlParserCtxt* ctxt)
36
+ cdef int htmlCtxtUseOptions(xmlParserCtxt* ctxt, int options)
37
+ cdef int htmlParseDocument(xmlParserCtxt* ctxt)
38
+ cdef int htmlParseChunk(xmlParserCtxt* ctxt,
39
+ char* chunk, int size, int terminate)
40
+
41
+ cdef xmlDoc* htmlCtxtReadFile(xmlParserCtxt* ctxt,
42
+ char* filename, const_char* encoding,
43
+ int options)
44
+ cdef xmlDoc* htmlCtxtReadDoc(xmlParserCtxt* ctxt,
45
+ char* buffer, char* URL, const_char* encoding,
46
+ int options)
47
+ cdef xmlDoc* htmlCtxtReadIO(xmlParserCtxt* ctxt,
48
+ xmlInputReadCallback ioread,
49
+ xmlInputCloseCallback ioclose,
50
+ void* ioctx,
51
+ char* URL, const_char* encoding,
52
+ int options)
53
+ cdef xmlDoc* htmlCtxtReadMemory(xmlParserCtxt* ctxt,
54
+ char* buffer, int size,
55
+ char* filename, const_char* encoding,
56
+ int options)
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/SAX2.h ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: SAX2 parser interface used to build the DOM tree
3
+ * Description: those are the default SAX2 interfaces used by
4
+ * the library when building DOM tree.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+
12
+ #ifndef __XML_SAX2_H__
13
+ #define __XML_SAX2_H__
14
+
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/parser.h>
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+ XMLPUBFUN const xmlChar *
22
+ xmlSAX2GetPublicId (void *ctx);
23
+ XMLPUBFUN const xmlChar *
24
+ xmlSAX2GetSystemId (void *ctx);
25
+ XMLPUBFUN void
26
+ xmlSAX2SetDocumentLocator (void *ctx,
27
+ xmlSAXLocatorPtr loc);
28
+
29
+ XMLPUBFUN int
30
+ xmlSAX2GetLineNumber (void *ctx);
31
+ XMLPUBFUN int
32
+ xmlSAX2GetColumnNumber (void *ctx);
33
+
34
+ XMLPUBFUN int
35
+ xmlSAX2IsStandalone (void *ctx);
36
+ XMLPUBFUN int
37
+ xmlSAX2HasInternalSubset (void *ctx);
38
+ XMLPUBFUN int
39
+ xmlSAX2HasExternalSubset (void *ctx);
40
+
41
+ XMLPUBFUN void
42
+ xmlSAX2InternalSubset (void *ctx,
43
+ const xmlChar *name,
44
+ const xmlChar *ExternalID,
45
+ const xmlChar *SystemID);
46
+ XMLPUBFUN void
47
+ xmlSAX2ExternalSubset (void *ctx,
48
+ const xmlChar *name,
49
+ const xmlChar *ExternalID,
50
+ const xmlChar *SystemID);
51
+ XMLPUBFUN xmlEntityPtr
52
+ xmlSAX2GetEntity (void *ctx,
53
+ const xmlChar *name);
54
+ XMLPUBFUN xmlEntityPtr
55
+ xmlSAX2GetParameterEntity (void *ctx,
56
+ const xmlChar *name);
57
+ XMLPUBFUN xmlParserInputPtr
58
+ xmlSAX2ResolveEntity (void *ctx,
59
+ const xmlChar *publicId,
60
+ const xmlChar *systemId);
61
+
62
+ XMLPUBFUN void
63
+ xmlSAX2EntityDecl (void *ctx,
64
+ const xmlChar *name,
65
+ int type,
66
+ const xmlChar *publicId,
67
+ const xmlChar *systemId,
68
+ xmlChar *content);
69
+ XMLPUBFUN void
70
+ xmlSAX2AttributeDecl (void *ctx,
71
+ const xmlChar *elem,
72
+ const xmlChar *fullname,
73
+ int type,
74
+ int def,
75
+ const xmlChar *defaultValue,
76
+ xmlEnumerationPtr tree);
77
+ XMLPUBFUN void
78
+ xmlSAX2ElementDecl (void *ctx,
79
+ const xmlChar *name,
80
+ int type,
81
+ xmlElementContentPtr content);
82
+ XMLPUBFUN void
83
+ xmlSAX2NotationDecl (void *ctx,
84
+ const xmlChar *name,
85
+ const xmlChar *publicId,
86
+ const xmlChar *systemId);
87
+ XMLPUBFUN void
88
+ xmlSAX2UnparsedEntityDecl (void *ctx,
89
+ const xmlChar *name,
90
+ const xmlChar *publicId,
91
+ const xmlChar *systemId,
92
+ const xmlChar *notationName);
93
+
94
+ XMLPUBFUN void
95
+ xmlSAX2StartDocument (void *ctx);
96
+ XMLPUBFUN void
97
+ xmlSAX2EndDocument (void *ctx);
98
+ #if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || \
99
+ defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_LEGACY_ENABLED)
100
+ XMLPUBFUN void
101
+ xmlSAX2StartElement (void *ctx,
102
+ const xmlChar *fullname,
103
+ const xmlChar **atts);
104
+ XMLPUBFUN void
105
+ xmlSAX2EndElement (void *ctx,
106
+ const xmlChar *name);
107
+ #endif /* LIBXML_SAX1_ENABLED or LIBXML_HTML_ENABLED or LIBXML_LEGACY_ENABLED */
108
+ XMLPUBFUN void
109
+ xmlSAX2StartElementNs (void *ctx,
110
+ const xmlChar *localname,
111
+ const xmlChar *prefix,
112
+ const xmlChar *URI,
113
+ int nb_namespaces,
114
+ const xmlChar **namespaces,
115
+ int nb_attributes,
116
+ int nb_defaulted,
117
+ const xmlChar **attributes);
118
+ XMLPUBFUN void
119
+ xmlSAX2EndElementNs (void *ctx,
120
+ const xmlChar *localname,
121
+ const xmlChar *prefix,
122
+ const xmlChar *URI);
123
+ XMLPUBFUN void
124
+ xmlSAX2Reference (void *ctx,
125
+ const xmlChar *name);
126
+ XMLPUBFUN void
127
+ xmlSAX2Characters (void *ctx,
128
+ const xmlChar *ch,
129
+ int len);
130
+ XMLPUBFUN void
131
+ xmlSAX2IgnorableWhitespace (void *ctx,
132
+ const xmlChar *ch,
133
+ int len);
134
+ XMLPUBFUN void
135
+ xmlSAX2ProcessingInstruction (void *ctx,
136
+ const xmlChar *target,
137
+ const xmlChar *data);
138
+ XMLPUBFUN void
139
+ xmlSAX2Comment (void *ctx,
140
+ const xmlChar *value);
141
+ XMLPUBFUN void
142
+ xmlSAX2CDataBlock (void *ctx,
143
+ const xmlChar *value,
144
+ int len);
145
+
146
+ #ifdef LIBXML_SAX1_ENABLED
147
+ XML_DEPRECATED
148
+ XMLPUBFUN int
149
+ xmlSAXDefaultVersion (int version);
150
+ #endif /* LIBXML_SAX1_ENABLED */
151
+
152
+ XMLPUBFUN int
153
+ xmlSAXVersion (xmlSAXHandler *hdlr,
154
+ int version);
155
+ XMLPUBFUN void
156
+ xmlSAX2InitDefaultSAXHandler (xmlSAXHandler *hdlr,
157
+ int warning);
158
+ #ifdef LIBXML_HTML_ENABLED
159
+ XMLPUBFUN void
160
+ xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr);
161
+ XML_DEPRECATED
162
+ XMLPUBFUN void
163
+ htmlDefaultSAXHandlerInit (void);
164
+ #endif
165
+ XML_DEPRECATED
166
+ XMLPUBFUN void
167
+ xmlDefaultSAXHandlerInit (void);
168
+ #ifdef __cplusplus
169
+ }
170
+ #endif
171
+ #endif /* __XML_SAX2_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/entities.h ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: interface for the XML entities handling
3
+ * Description: this module provides some of the entity API needed
4
+ * for the parser and applications.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __XML_ENTITIES_H__
12
+ #define __XML_ENTITIES_H__
13
+
14
+ #include <libxml/xmlversion.h>
15
+ #define XML_TREE_INTERNALS
16
+ #include <libxml/tree.h>
17
+ #undef XML_TREE_INTERNALS
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ /*
24
+ * The different valid entity types.
25
+ */
26
+ typedef enum {
27
+ XML_INTERNAL_GENERAL_ENTITY = 1,
28
+ XML_EXTERNAL_GENERAL_PARSED_ENTITY = 2,
29
+ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY = 3,
30
+ XML_INTERNAL_PARAMETER_ENTITY = 4,
31
+ XML_EXTERNAL_PARAMETER_ENTITY = 5,
32
+ XML_INTERNAL_PREDEFINED_ENTITY = 6
33
+ } xmlEntityType;
34
+
35
+ /*
36
+ * An unit of storage for an entity, contains the string, the value
37
+ * and the linkind data needed for the linking in the hash table.
38
+ */
39
+
40
+ struct _xmlEntity {
41
+ void *_private; /* application data */
42
+ xmlElementType type; /* XML_ENTITY_DECL, must be second ! */
43
+ const xmlChar *name; /* Entity name */
44
+ struct _xmlNode *children; /* First child link */
45
+ struct _xmlNode *last; /* Last child link */
46
+ struct _xmlDtd *parent; /* -> DTD */
47
+ struct _xmlNode *next; /* next sibling link */
48
+ struct _xmlNode *prev; /* previous sibling link */
49
+ struct _xmlDoc *doc; /* the containing document */
50
+
51
+ xmlChar *orig; /* content without ref substitution */
52
+ xmlChar *content; /* content or ndata if unparsed */
53
+ int length; /* the content length */
54
+ xmlEntityType etype; /* The entity type */
55
+ const xmlChar *ExternalID; /* External identifier for PUBLIC */
56
+ const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
57
+
58
+ struct _xmlEntity *nexte; /* unused */
59
+ const xmlChar *URI; /* the full URI as computed */
60
+ int owner; /* does the entity own the childrens */
61
+ int flags; /* various flags */
62
+ unsigned long expandedSize; /* expanded size */
63
+ };
64
+
65
+ /*
66
+ * All entities are stored in an hash table.
67
+ * There is 2 separate hash tables for global and parameter entities.
68
+ */
69
+
70
+ typedef struct _xmlHashTable xmlEntitiesTable;
71
+ typedef xmlEntitiesTable *xmlEntitiesTablePtr;
72
+
73
+ /*
74
+ * External functions:
75
+ */
76
+
77
+ #ifdef LIBXML_LEGACY_ENABLED
78
+ XML_DEPRECATED
79
+ XMLPUBFUN void
80
+ xmlInitializePredefinedEntities (void);
81
+ #endif /* LIBXML_LEGACY_ENABLED */
82
+
83
+ XMLPUBFUN xmlEntityPtr
84
+ xmlNewEntity (xmlDocPtr doc,
85
+ const xmlChar *name,
86
+ int type,
87
+ const xmlChar *ExternalID,
88
+ const xmlChar *SystemID,
89
+ const xmlChar *content);
90
+ XMLPUBFUN void
91
+ xmlFreeEntity (xmlEntityPtr entity);
92
+ XMLPUBFUN xmlEntityPtr
93
+ xmlAddDocEntity (xmlDocPtr doc,
94
+ const xmlChar *name,
95
+ int type,
96
+ const xmlChar *ExternalID,
97
+ const xmlChar *SystemID,
98
+ const xmlChar *content);
99
+ XMLPUBFUN xmlEntityPtr
100
+ xmlAddDtdEntity (xmlDocPtr doc,
101
+ const xmlChar *name,
102
+ int type,
103
+ const xmlChar *ExternalID,
104
+ const xmlChar *SystemID,
105
+ const xmlChar *content);
106
+ XMLPUBFUN xmlEntityPtr
107
+ xmlGetPredefinedEntity (const xmlChar *name);
108
+ XMLPUBFUN xmlEntityPtr
109
+ xmlGetDocEntity (const xmlDoc *doc,
110
+ const xmlChar *name);
111
+ XMLPUBFUN xmlEntityPtr
112
+ xmlGetDtdEntity (xmlDocPtr doc,
113
+ const xmlChar *name);
114
+ XMLPUBFUN xmlEntityPtr
115
+ xmlGetParameterEntity (xmlDocPtr doc,
116
+ const xmlChar *name);
117
+ #ifdef LIBXML_LEGACY_ENABLED
118
+ XML_DEPRECATED
119
+ XMLPUBFUN const xmlChar *
120
+ xmlEncodeEntities (xmlDocPtr doc,
121
+ const xmlChar *input);
122
+ #endif /* LIBXML_LEGACY_ENABLED */
123
+ XMLPUBFUN xmlChar *
124
+ xmlEncodeEntitiesReentrant(xmlDocPtr doc,
125
+ const xmlChar *input);
126
+ XMLPUBFUN xmlChar *
127
+ xmlEncodeSpecialChars (const xmlDoc *doc,
128
+ const xmlChar *input);
129
+ XMLPUBFUN xmlEntitiesTablePtr
130
+ xmlCreateEntitiesTable (void);
131
+ #ifdef LIBXML_TREE_ENABLED
132
+ XMLPUBFUN xmlEntitiesTablePtr
133
+ xmlCopyEntitiesTable (xmlEntitiesTablePtr table);
134
+ #endif /* LIBXML_TREE_ENABLED */
135
+ XMLPUBFUN void
136
+ xmlFreeEntitiesTable (xmlEntitiesTablePtr table);
137
+ #ifdef LIBXML_OUTPUT_ENABLED
138
+ XMLPUBFUN void
139
+ xmlDumpEntitiesTable (xmlBufferPtr buf,
140
+ xmlEntitiesTablePtr table);
141
+ XMLPUBFUN void
142
+ xmlDumpEntityDecl (xmlBufferPtr buf,
143
+ xmlEntityPtr ent);
144
+ #endif /* LIBXML_OUTPUT_ENABLED */
145
+ #ifdef LIBXML_LEGACY_ENABLED
146
+ XMLPUBFUN void
147
+ xmlCleanupPredefinedEntities(void);
148
+ #endif /* LIBXML_LEGACY_ENABLED */
149
+
150
+
151
+ #ifdef __cplusplus
152
+ }
153
+ #endif
154
+
155
+ # endif /* __XML_ENTITIES_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/parserInternals.h ADDED
@@ -0,0 +1,663 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: internals routines and limits exported by the parser.
3
+ * Description: this module exports a number of internal parsing routines
4
+ * they are not really all intended for applications but
5
+ * can prove useful doing low level processing.
6
+ *
7
+ * Copy: See Copyright for the status of this software.
8
+ *
9
+ * Author: Daniel Veillard
10
+ */
11
+
12
+ #ifndef __XML_PARSER_INTERNALS_H__
13
+ #define __XML_PARSER_INTERNALS_H__
14
+
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/parser.h>
17
+ #include <libxml/HTMLparser.h>
18
+ #include <libxml/chvalid.h>
19
+ #include <libxml/SAX2.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /**
26
+ * xmlParserMaxDepth:
27
+ *
28
+ * arbitrary depth limit for the XML documents that we allow to
29
+ * process. This is not a limitation of the parser but a safety
30
+ * boundary feature, use XML_PARSE_HUGE option to override it.
31
+ */
32
+ XMLPUBVAR unsigned int xmlParserMaxDepth;
33
+
34
+ /**
35
+ * XML_MAX_TEXT_LENGTH:
36
+ *
37
+ * Maximum size allowed for a single text node when building a tree.
38
+ * This is not a limitation of the parser but a safety boundary feature,
39
+ * use XML_PARSE_HUGE option to override it.
40
+ * Introduced in 2.9.0
41
+ */
42
+ #define XML_MAX_TEXT_LENGTH 10000000
43
+
44
+ /**
45
+ * XML_MAX_HUGE_LENGTH:
46
+ *
47
+ * Maximum size allowed when XML_PARSE_HUGE is set.
48
+ */
49
+ #define XML_MAX_HUGE_LENGTH 1000000000
50
+
51
+ /**
52
+ * XML_MAX_NAME_LENGTH:
53
+ *
54
+ * Maximum size allowed for a markup identifier.
55
+ * This is not a limitation of the parser but a safety boundary feature,
56
+ * use XML_PARSE_HUGE option to override it.
57
+ * Note that with the use of parsing dictionaries overriding the limit
58
+ * may result in more runtime memory usage in face of "unfriendly' content
59
+ * Introduced in 2.9.0
60
+ */
61
+ #define XML_MAX_NAME_LENGTH 50000
62
+
63
+ /**
64
+ * XML_MAX_DICTIONARY_LIMIT:
65
+ *
66
+ * Maximum size allowed by the parser for a dictionary by default
67
+ * This is not a limitation of the parser but a safety boundary feature,
68
+ * use XML_PARSE_HUGE option to override it.
69
+ * Introduced in 2.9.0
70
+ */
71
+ #define XML_MAX_DICTIONARY_LIMIT 10000000
72
+
73
+ /**
74
+ * XML_MAX_LOOKUP_LIMIT:
75
+ *
76
+ * Maximum size allowed by the parser for ahead lookup
77
+ * This is an upper boundary enforced by the parser to avoid bad
78
+ * behaviour on "unfriendly' content
79
+ * Introduced in 2.9.0
80
+ */
81
+ #define XML_MAX_LOOKUP_LIMIT 10000000
82
+
83
+ /**
84
+ * XML_MAX_NAMELEN:
85
+ *
86
+ * Identifiers can be longer, but this will be more costly
87
+ * at runtime.
88
+ */
89
+ #define XML_MAX_NAMELEN 100
90
+
91
+ /**
92
+ * INPUT_CHUNK:
93
+ *
94
+ * The parser tries to always have that amount of input ready.
95
+ * One of the point is providing context when reporting errors.
96
+ */
97
+ #define INPUT_CHUNK 250
98
+
99
+ /************************************************************************
100
+ * *
101
+ * UNICODE version of the macros. *
102
+ * *
103
+ ************************************************************************/
104
+ /**
105
+ * IS_BYTE_CHAR:
106
+ * @c: an byte value (int)
107
+ *
108
+ * Macro to check the following production in the XML spec:
109
+ *
110
+ * [2] Char ::= #x9 | #xA | #xD | [#x20...]
111
+ * any byte character in the accepted range
112
+ */
113
+ #define IS_BYTE_CHAR(c) xmlIsChar_ch(c)
114
+
115
+ /**
116
+ * IS_CHAR:
117
+ * @c: an UNICODE value (int)
118
+ *
119
+ * Macro to check the following production in the XML spec:
120
+ *
121
+ * [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
122
+ * | [#x10000-#x10FFFF]
123
+ * any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
124
+ */
125
+ #define IS_CHAR(c) xmlIsCharQ(c)
126
+
127
+ /**
128
+ * IS_CHAR_CH:
129
+ * @c: an xmlChar (usually an unsigned char)
130
+ *
131
+ * Behaves like IS_CHAR on single-byte value
132
+ */
133
+ #define IS_CHAR_CH(c) xmlIsChar_ch(c)
134
+
135
+ /**
136
+ * IS_BLANK:
137
+ * @c: an UNICODE value (int)
138
+ *
139
+ * Macro to check the following production in the XML spec:
140
+ *
141
+ * [3] S ::= (#x20 | #x9 | #xD | #xA)+
142
+ */
143
+ #define IS_BLANK(c) xmlIsBlankQ(c)
144
+
145
+ /**
146
+ * IS_BLANK_CH:
147
+ * @c: an xmlChar value (normally unsigned char)
148
+ *
149
+ * Behaviour same as IS_BLANK
150
+ */
151
+ #define IS_BLANK_CH(c) xmlIsBlank_ch(c)
152
+
153
+ /**
154
+ * IS_BASECHAR:
155
+ * @c: an UNICODE value (int)
156
+ *
157
+ * Macro to check the following production in the XML spec:
158
+ *
159
+ * [85] BaseChar ::= ... long list see REC ...
160
+ */
161
+ #define IS_BASECHAR(c) xmlIsBaseCharQ(c)
162
+
163
+ /**
164
+ * IS_DIGIT:
165
+ * @c: an UNICODE value (int)
166
+ *
167
+ * Macro to check the following production in the XML spec:
168
+ *
169
+ * [88] Digit ::= ... long list see REC ...
170
+ */
171
+ #define IS_DIGIT(c) xmlIsDigitQ(c)
172
+
173
+ /**
174
+ * IS_DIGIT_CH:
175
+ * @c: an xmlChar value (usually an unsigned char)
176
+ *
177
+ * Behaves like IS_DIGIT but with a single byte argument
178
+ */
179
+ #define IS_DIGIT_CH(c) xmlIsDigit_ch(c)
180
+
181
+ /**
182
+ * IS_COMBINING:
183
+ * @c: an UNICODE value (int)
184
+ *
185
+ * Macro to check the following production in the XML spec:
186
+ *
187
+ * [87] CombiningChar ::= ... long list see REC ...
188
+ */
189
+ #define IS_COMBINING(c) xmlIsCombiningQ(c)
190
+
191
+ /**
192
+ * IS_COMBINING_CH:
193
+ * @c: an xmlChar (usually an unsigned char)
194
+ *
195
+ * Always false (all combining chars > 0xff)
196
+ */
197
+ #define IS_COMBINING_CH(c) 0
198
+
199
+ /**
200
+ * IS_EXTENDER:
201
+ * @c: an UNICODE value (int)
202
+ *
203
+ * Macro to check the following production in the XML spec:
204
+ *
205
+ *
206
+ * [89] Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 |
207
+ * #x0E46 | #x0EC6 | #x3005 | [#x3031-#x3035] |
208
+ * [#x309D-#x309E] | [#x30FC-#x30FE]
209
+ */
210
+ #define IS_EXTENDER(c) xmlIsExtenderQ(c)
211
+
212
+ /**
213
+ * IS_EXTENDER_CH:
214
+ * @c: an xmlChar value (usually an unsigned char)
215
+ *
216
+ * Behaves like IS_EXTENDER but with a single-byte argument
217
+ */
218
+ #define IS_EXTENDER_CH(c) xmlIsExtender_ch(c)
219
+
220
+ /**
221
+ * IS_IDEOGRAPHIC:
222
+ * @c: an UNICODE value (int)
223
+ *
224
+ * Macro to check the following production in the XML spec:
225
+ *
226
+ *
227
+ * [86] Ideographic ::= [#x4E00-#x9FA5] | #x3007 | [#x3021-#x3029]
228
+ */
229
+ #define IS_IDEOGRAPHIC(c) xmlIsIdeographicQ(c)
230
+
231
+ /**
232
+ * IS_LETTER:
233
+ * @c: an UNICODE value (int)
234
+ *
235
+ * Macro to check the following production in the XML spec:
236
+ *
237
+ *
238
+ * [84] Letter ::= BaseChar | Ideographic
239
+ */
240
+ #define IS_LETTER(c) (IS_BASECHAR(c) || IS_IDEOGRAPHIC(c))
241
+
242
+ /**
243
+ * IS_LETTER_CH:
244
+ * @c: an xmlChar value (normally unsigned char)
245
+ *
246
+ * Macro behaves like IS_LETTER, but only check base chars
247
+ *
248
+ */
249
+ #define IS_LETTER_CH(c) xmlIsBaseChar_ch(c)
250
+
251
+ /**
252
+ * IS_ASCII_LETTER:
253
+ * @c: an xmlChar value
254
+ *
255
+ * Macro to check [a-zA-Z]
256
+ *
257
+ */
258
+ #define IS_ASCII_LETTER(c) (((0x41 <= (c)) && ((c) <= 0x5a)) || \
259
+ ((0x61 <= (c)) && ((c) <= 0x7a)))
260
+
261
+ /**
262
+ * IS_ASCII_DIGIT:
263
+ * @c: an xmlChar value
264
+ *
265
+ * Macro to check [0-9]
266
+ *
267
+ */
268
+ #define IS_ASCII_DIGIT(c) ((0x30 <= (c)) && ((c) <= 0x39))
269
+
270
+ /**
271
+ * IS_PUBIDCHAR:
272
+ * @c: an UNICODE value (int)
273
+ *
274
+ * Macro to check the following production in the XML spec:
275
+ *
276
+ *
277
+ * [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
278
+ */
279
+ #define IS_PUBIDCHAR(c) xmlIsPubidCharQ(c)
280
+
281
+ /**
282
+ * IS_PUBIDCHAR_CH:
283
+ * @c: an xmlChar value (normally unsigned char)
284
+ *
285
+ * Same as IS_PUBIDCHAR but for single-byte value
286
+ */
287
+ #define IS_PUBIDCHAR_CH(c) xmlIsPubidChar_ch(c)
288
+
289
+ /**
290
+ * Global variables used for predefined strings.
291
+ */
292
+ XMLPUBVAR const xmlChar xmlStringText[];
293
+ XMLPUBVAR const xmlChar xmlStringTextNoenc[];
294
+ XMLPUBVAR const xmlChar xmlStringComment[];
295
+
296
+ /*
297
+ * Function to finish the work of the macros where needed.
298
+ */
299
+ XMLPUBFUN int xmlIsLetter (int c);
300
+
301
+ /**
302
+ * Parser context.
303
+ */
304
+ XMLPUBFUN xmlParserCtxtPtr
305
+ xmlCreateFileParserCtxt (const char *filename);
306
+ XMLPUBFUN xmlParserCtxtPtr
307
+ xmlCreateURLParserCtxt (const char *filename,
308
+ int options);
309
+ XMLPUBFUN xmlParserCtxtPtr
310
+ xmlCreateMemoryParserCtxt(const char *buffer,
311
+ int size);
312
+ XMLPUBFUN xmlParserCtxtPtr
313
+ xmlCreateEntityParserCtxt(const xmlChar *URL,
314
+ const xmlChar *ID,
315
+ const xmlChar *base);
316
+ XMLPUBFUN int
317
+ xmlSwitchEncoding (xmlParserCtxtPtr ctxt,
318
+ xmlCharEncoding enc);
319
+ XMLPUBFUN int
320
+ xmlSwitchToEncoding (xmlParserCtxtPtr ctxt,
321
+ xmlCharEncodingHandlerPtr handler);
322
+ XML_DEPRECATED
323
+ XMLPUBFUN int
324
+ xmlSwitchInputEncoding (xmlParserCtxtPtr ctxt,
325
+ xmlParserInputPtr input,
326
+ xmlCharEncodingHandlerPtr handler);
327
+
328
+ /**
329
+ * Input Streams.
330
+ */
331
+ XMLPUBFUN xmlParserInputPtr
332
+ xmlNewStringInputStream (xmlParserCtxtPtr ctxt,
333
+ const xmlChar *buffer);
334
+ XML_DEPRECATED
335
+ XMLPUBFUN xmlParserInputPtr
336
+ xmlNewEntityInputStream (xmlParserCtxtPtr ctxt,
337
+ xmlEntityPtr entity);
338
+ XMLPUBFUN int
339
+ xmlPushInput (xmlParserCtxtPtr ctxt,
340
+ xmlParserInputPtr input);
341
+ XMLPUBFUN xmlChar
342
+ xmlPopInput (xmlParserCtxtPtr ctxt);
343
+ XMLPUBFUN void
344
+ xmlFreeInputStream (xmlParserInputPtr input);
345
+ XMLPUBFUN xmlParserInputPtr
346
+ xmlNewInputFromFile (xmlParserCtxtPtr ctxt,
347
+ const char *filename);
348
+ XMLPUBFUN xmlParserInputPtr
349
+ xmlNewInputStream (xmlParserCtxtPtr ctxt);
350
+
351
+ /**
352
+ * Namespaces.
353
+ */
354
+ XMLPUBFUN xmlChar *
355
+ xmlSplitQName (xmlParserCtxtPtr ctxt,
356
+ const xmlChar *name,
357
+ xmlChar **prefix);
358
+
359
+ /**
360
+ * Generic production rules.
361
+ */
362
+ XML_DEPRECATED
363
+ XMLPUBFUN const xmlChar *
364
+ xmlParseName (xmlParserCtxtPtr ctxt);
365
+ XML_DEPRECATED
366
+ XMLPUBFUN xmlChar *
367
+ xmlParseNmtoken (xmlParserCtxtPtr ctxt);
368
+ XML_DEPRECATED
369
+ XMLPUBFUN xmlChar *
370
+ xmlParseEntityValue (xmlParserCtxtPtr ctxt,
371
+ xmlChar **orig);
372
+ XML_DEPRECATED
373
+ XMLPUBFUN xmlChar *
374
+ xmlParseAttValue (xmlParserCtxtPtr ctxt);
375
+ XML_DEPRECATED
376
+ XMLPUBFUN xmlChar *
377
+ xmlParseSystemLiteral (xmlParserCtxtPtr ctxt);
378
+ XML_DEPRECATED
379
+ XMLPUBFUN xmlChar *
380
+ xmlParsePubidLiteral (xmlParserCtxtPtr ctxt);
381
+ XML_DEPRECATED
382
+ XMLPUBFUN void
383
+ xmlParseCharData (xmlParserCtxtPtr ctxt,
384
+ int cdata);
385
+ XML_DEPRECATED
386
+ XMLPUBFUN xmlChar *
387
+ xmlParseExternalID (xmlParserCtxtPtr ctxt,
388
+ xmlChar **publicID,
389
+ int strict);
390
+ XML_DEPRECATED
391
+ XMLPUBFUN void
392
+ xmlParseComment (xmlParserCtxtPtr ctxt);
393
+ XML_DEPRECATED
394
+ XMLPUBFUN const xmlChar *
395
+ xmlParsePITarget (xmlParserCtxtPtr ctxt);
396
+ XML_DEPRECATED
397
+ XMLPUBFUN void
398
+ xmlParsePI (xmlParserCtxtPtr ctxt);
399
+ XML_DEPRECATED
400
+ XMLPUBFUN void
401
+ xmlParseNotationDecl (xmlParserCtxtPtr ctxt);
402
+ XML_DEPRECATED
403
+ XMLPUBFUN void
404
+ xmlParseEntityDecl (xmlParserCtxtPtr ctxt);
405
+ XML_DEPRECATED
406
+ XMLPUBFUN int
407
+ xmlParseDefaultDecl (xmlParserCtxtPtr ctxt,
408
+ xmlChar **value);
409
+ XML_DEPRECATED
410
+ XMLPUBFUN xmlEnumerationPtr
411
+ xmlParseNotationType (xmlParserCtxtPtr ctxt);
412
+ XML_DEPRECATED
413
+ XMLPUBFUN xmlEnumerationPtr
414
+ xmlParseEnumerationType (xmlParserCtxtPtr ctxt);
415
+ XML_DEPRECATED
416
+ XMLPUBFUN int
417
+ xmlParseEnumeratedType (xmlParserCtxtPtr ctxt,
418
+ xmlEnumerationPtr *tree);
419
+ XML_DEPRECATED
420
+ XMLPUBFUN int
421
+ xmlParseAttributeType (xmlParserCtxtPtr ctxt,
422
+ xmlEnumerationPtr *tree);
423
+ XML_DEPRECATED
424
+ XMLPUBFUN void
425
+ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt);
426
+ XML_DEPRECATED
427
+ XMLPUBFUN xmlElementContentPtr
428
+ xmlParseElementMixedContentDecl
429
+ (xmlParserCtxtPtr ctxt,
430
+ int inputchk);
431
+ XML_DEPRECATED
432
+ XMLPUBFUN xmlElementContentPtr
433
+ xmlParseElementChildrenContentDecl
434
+ (xmlParserCtxtPtr ctxt,
435
+ int inputchk);
436
+ XML_DEPRECATED
437
+ XMLPUBFUN int
438
+ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt,
439
+ const xmlChar *name,
440
+ xmlElementContentPtr *result);
441
+ XML_DEPRECATED
442
+ XMLPUBFUN int
443
+ xmlParseElementDecl (xmlParserCtxtPtr ctxt);
444
+ XML_DEPRECATED
445
+ XMLPUBFUN void
446
+ xmlParseMarkupDecl (xmlParserCtxtPtr ctxt);
447
+ XML_DEPRECATED
448
+ XMLPUBFUN int
449
+ xmlParseCharRef (xmlParserCtxtPtr ctxt);
450
+ XML_DEPRECATED
451
+ XMLPUBFUN xmlEntityPtr
452
+ xmlParseEntityRef (xmlParserCtxtPtr ctxt);
453
+ XML_DEPRECATED
454
+ XMLPUBFUN void
455
+ xmlParseReference (xmlParserCtxtPtr ctxt);
456
+ XML_DEPRECATED
457
+ XMLPUBFUN void
458
+ xmlParsePEReference (xmlParserCtxtPtr ctxt);
459
+ XML_DEPRECATED
460
+ XMLPUBFUN void
461
+ xmlParseDocTypeDecl (xmlParserCtxtPtr ctxt);
462
+ #ifdef LIBXML_SAX1_ENABLED
463
+ XML_DEPRECATED
464
+ XMLPUBFUN const xmlChar *
465
+ xmlParseAttribute (xmlParserCtxtPtr ctxt,
466
+ xmlChar **value);
467
+ XML_DEPRECATED
468
+ XMLPUBFUN const xmlChar *
469
+ xmlParseStartTag (xmlParserCtxtPtr ctxt);
470
+ XML_DEPRECATED
471
+ XMLPUBFUN void
472
+ xmlParseEndTag (xmlParserCtxtPtr ctxt);
473
+ #endif /* LIBXML_SAX1_ENABLED */
474
+ XML_DEPRECATED
475
+ XMLPUBFUN void
476
+ xmlParseCDSect (xmlParserCtxtPtr ctxt);
477
+ XMLPUBFUN void
478
+ xmlParseContent (xmlParserCtxtPtr ctxt);
479
+ XML_DEPRECATED
480
+ XMLPUBFUN void
481
+ xmlParseElement (xmlParserCtxtPtr ctxt);
482
+ XML_DEPRECATED
483
+ XMLPUBFUN xmlChar *
484
+ xmlParseVersionNum (xmlParserCtxtPtr ctxt);
485
+ XML_DEPRECATED
486
+ XMLPUBFUN xmlChar *
487
+ xmlParseVersionInfo (xmlParserCtxtPtr ctxt);
488
+ XML_DEPRECATED
489
+ XMLPUBFUN xmlChar *
490
+ xmlParseEncName (xmlParserCtxtPtr ctxt);
491
+ XML_DEPRECATED
492
+ XMLPUBFUN const xmlChar *
493
+ xmlParseEncodingDecl (xmlParserCtxtPtr ctxt);
494
+ XML_DEPRECATED
495
+ XMLPUBFUN int
496
+ xmlParseSDDecl (xmlParserCtxtPtr ctxt);
497
+ XML_DEPRECATED
498
+ XMLPUBFUN void
499
+ xmlParseXMLDecl (xmlParserCtxtPtr ctxt);
500
+ XML_DEPRECATED
501
+ XMLPUBFUN void
502
+ xmlParseTextDecl (xmlParserCtxtPtr ctxt);
503
+ XML_DEPRECATED
504
+ XMLPUBFUN void
505
+ xmlParseMisc (xmlParserCtxtPtr ctxt);
506
+ XMLPUBFUN void
507
+ xmlParseExternalSubset (xmlParserCtxtPtr ctxt,
508
+ const xmlChar *ExternalID,
509
+ const xmlChar *SystemID);
510
+ /**
511
+ * XML_SUBSTITUTE_NONE:
512
+ *
513
+ * If no entities need to be substituted.
514
+ */
515
+ #define XML_SUBSTITUTE_NONE 0
516
+ /**
517
+ * XML_SUBSTITUTE_REF:
518
+ *
519
+ * Whether general entities need to be substituted.
520
+ */
521
+ #define XML_SUBSTITUTE_REF 1
522
+ /**
523
+ * XML_SUBSTITUTE_PEREF:
524
+ *
525
+ * Whether parameter entities need to be substituted.
526
+ */
527
+ #define XML_SUBSTITUTE_PEREF 2
528
+ /**
529
+ * XML_SUBSTITUTE_BOTH:
530
+ *
531
+ * Both general and parameter entities need to be substituted.
532
+ */
533
+ #define XML_SUBSTITUTE_BOTH 3
534
+
535
+ XML_DEPRECATED
536
+ XMLPUBFUN xmlChar *
537
+ xmlStringDecodeEntities (xmlParserCtxtPtr ctxt,
538
+ const xmlChar *str,
539
+ int what,
540
+ xmlChar end,
541
+ xmlChar end2,
542
+ xmlChar end3);
543
+ XML_DEPRECATED
544
+ XMLPUBFUN xmlChar *
545
+ xmlStringLenDecodeEntities (xmlParserCtxtPtr ctxt,
546
+ const xmlChar *str,
547
+ int len,
548
+ int what,
549
+ xmlChar end,
550
+ xmlChar end2,
551
+ xmlChar end3);
552
+
553
+ /*
554
+ * Generated by MACROS on top of parser.c c.f. PUSH_AND_POP.
555
+ */
556
+ XML_DEPRECATED
557
+ XMLPUBFUN int nodePush (xmlParserCtxtPtr ctxt,
558
+ xmlNodePtr value);
559
+ XML_DEPRECATED
560
+ XMLPUBFUN xmlNodePtr nodePop (xmlParserCtxtPtr ctxt);
561
+ XMLPUBFUN int inputPush (xmlParserCtxtPtr ctxt,
562
+ xmlParserInputPtr value);
563
+ XMLPUBFUN xmlParserInputPtr inputPop (xmlParserCtxtPtr ctxt);
564
+ XML_DEPRECATED
565
+ XMLPUBFUN const xmlChar * namePop (xmlParserCtxtPtr ctxt);
566
+ XML_DEPRECATED
567
+ XMLPUBFUN int namePush (xmlParserCtxtPtr ctxt,
568
+ const xmlChar *value);
569
+
570
+ /*
571
+ * other commodities shared between parser.c and parserInternals.
572
+ */
573
+ XML_DEPRECATED
574
+ XMLPUBFUN int xmlSkipBlankChars (xmlParserCtxtPtr ctxt);
575
+ XML_DEPRECATED
576
+ XMLPUBFUN int xmlStringCurrentChar (xmlParserCtxtPtr ctxt,
577
+ const xmlChar *cur,
578
+ int *len);
579
+ XML_DEPRECATED
580
+ XMLPUBFUN void xmlParserHandlePEReference(xmlParserCtxtPtr ctxt);
581
+ XML_DEPRECATED
582
+ XMLPUBFUN int xmlCheckLanguageID (const xmlChar *lang);
583
+
584
+ /*
585
+ * Really core function shared with HTML parser.
586
+ */
587
+ XML_DEPRECATED
588
+ XMLPUBFUN int xmlCurrentChar (xmlParserCtxtPtr ctxt,
589
+ int *len);
590
+ XMLPUBFUN int xmlCopyCharMultiByte (xmlChar *out,
591
+ int val);
592
+ XMLPUBFUN int xmlCopyChar (int len,
593
+ xmlChar *out,
594
+ int val);
595
+ XML_DEPRECATED
596
+ XMLPUBFUN void xmlNextChar (xmlParserCtxtPtr ctxt);
597
+ XML_DEPRECATED
598
+ XMLPUBFUN void xmlParserInputShrink (xmlParserInputPtr in);
599
+
600
+ /*
601
+ * Specific function to keep track of entities references
602
+ * and used by the XSLT debugger.
603
+ */
604
+ #ifdef LIBXML_LEGACY_ENABLED
605
+ /**
606
+ * xmlEntityReferenceFunc:
607
+ * @ent: the entity
608
+ * @firstNode: the fist node in the chunk
609
+ * @lastNode: the last nod in the chunk
610
+ *
611
+ * Callback function used when one needs to be able to track back the
612
+ * provenance of a chunk of nodes inherited from an entity replacement.
613
+ */
614
+ typedef void (*xmlEntityReferenceFunc) (xmlEntityPtr ent,
615
+ xmlNodePtr firstNode,
616
+ xmlNodePtr lastNode);
617
+
618
+ XML_DEPRECATED
619
+ XMLPUBFUN void xmlSetEntityReferenceFunc (xmlEntityReferenceFunc func);
620
+
621
+ XML_DEPRECATED
622
+ XMLPUBFUN xmlChar *
623
+ xmlParseQuotedString (xmlParserCtxtPtr ctxt);
624
+ XML_DEPRECATED
625
+ XMLPUBFUN void
626
+ xmlParseNamespace (xmlParserCtxtPtr ctxt);
627
+ XML_DEPRECATED
628
+ XMLPUBFUN xmlChar *
629
+ xmlNamespaceParseNSDef (xmlParserCtxtPtr ctxt);
630
+ XML_DEPRECATED
631
+ XMLPUBFUN xmlChar *
632
+ xmlScanName (xmlParserCtxtPtr ctxt);
633
+ XML_DEPRECATED
634
+ XMLPUBFUN xmlChar *
635
+ xmlNamespaceParseNCName (xmlParserCtxtPtr ctxt);
636
+ XML_DEPRECATED
637
+ XMLPUBFUN void xmlParserHandleReference(xmlParserCtxtPtr ctxt);
638
+ XML_DEPRECATED
639
+ XMLPUBFUN xmlChar *
640
+ xmlNamespaceParseQName (xmlParserCtxtPtr ctxt,
641
+ xmlChar **prefix);
642
+ /**
643
+ * Entities
644
+ */
645
+ XML_DEPRECATED
646
+ XMLPUBFUN xmlChar *
647
+ xmlDecodeEntities (xmlParserCtxtPtr ctxt,
648
+ int len,
649
+ int what,
650
+ xmlChar end,
651
+ xmlChar end2,
652
+ xmlChar end3);
653
+ XML_DEPRECATED
654
+ XMLPUBFUN void
655
+ xmlHandleEntity (xmlParserCtxtPtr ctxt,
656
+ xmlEntityPtr entity);
657
+
658
+ #endif /* LIBXML_LEGACY_ENABLED */
659
+
660
+ #ifdef __cplusplus
661
+ }
662
+ #endif
663
+ #endif /* __XML_PARSER_INTERNALS_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/schemasInternals.h ADDED
@@ -0,0 +1,959 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: internal interfaces for XML Schemas
3
+ * Description: internal interfaces for the XML Schemas handling
4
+ * and schema validity checking
5
+ * The Schemas development is a Work In Progress.
6
+ * Some of those interfaces are not guaranteed to be API or ABI stable !
7
+ *
8
+ * Copy: See Copyright for the status of this software.
9
+ *
10
+ * Author: Daniel Veillard
11
+ */
12
+
13
+
14
+ #ifndef __XML_SCHEMA_INTERNALS_H__
15
+ #define __XML_SCHEMA_INTERNALS_H__
16
+
17
+ #include <libxml/xmlversion.h>
18
+
19
+ #ifdef LIBXML_SCHEMAS_ENABLED
20
+
21
+ #include <libxml/xmlregexp.h>
22
+ #include <libxml/hash.h>
23
+ #include <libxml/dict.h>
24
+ #include <libxml/tree.h>
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ typedef enum {
31
+ XML_SCHEMAS_UNKNOWN = 0,
32
+ XML_SCHEMAS_STRING = 1,
33
+ XML_SCHEMAS_NORMSTRING = 2,
34
+ XML_SCHEMAS_DECIMAL = 3,
35
+ XML_SCHEMAS_TIME = 4,
36
+ XML_SCHEMAS_GDAY = 5,
37
+ XML_SCHEMAS_GMONTH = 6,
38
+ XML_SCHEMAS_GMONTHDAY = 7,
39
+ XML_SCHEMAS_GYEAR = 8,
40
+ XML_SCHEMAS_GYEARMONTH = 9,
41
+ XML_SCHEMAS_DATE = 10,
42
+ XML_SCHEMAS_DATETIME = 11,
43
+ XML_SCHEMAS_DURATION = 12,
44
+ XML_SCHEMAS_FLOAT = 13,
45
+ XML_SCHEMAS_DOUBLE = 14,
46
+ XML_SCHEMAS_BOOLEAN = 15,
47
+ XML_SCHEMAS_TOKEN = 16,
48
+ XML_SCHEMAS_LANGUAGE = 17,
49
+ XML_SCHEMAS_NMTOKEN = 18,
50
+ XML_SCHEMAS_NMTOKENS = 19,
51
+ XML_SCHEMAS_NAME = 20,
52
+ XML_SCHEMAS_QNAME = 21,
53
+ XML_SCHEMAS_NCNAME = 22,
54
+ XML_SCHEMAS_ID = 23,
55
+ XML_SCHEMAS_IDREF = 24,
56
+ XML_SCHEMAS_IDREFS = 25,
57
+ XML_SCHEMAS_ENTITY = 26,
58
+ XML_SCHEMAS_ENTITIES = 27,
59
+ XML_SCHEMAS_NOTATION = 28,
60
+ XML_SCHEMAS_ANYURI = 29,
61
+ XML_SCHEMAS_INTEGER = 30,
62
+ XML_SCHEMAS_NPINTEGER = 31,
63
+ XML_SCHEMAS_NINTEGER = 32,
64
+ XML_SCHEMAS_NNINTEGER = 33,
65
+ XML_SCHEMAS_PINTEGER = 34,
66
+ XML_SCHEMAS_INT = 35,
67
+ XML_SCHEMAS_UINT = 36,
68
+ XML_SCHEMAS_LONG = 37,
69
+ XML_SCHEMAS_ULONG = 38,
70
+ XML_SCHEMAS_SHORT = 39,
71
+ XML_SCHEMAS_USHORT = 40,
72
+ XML_SCHEMAS_BYTE = 41,
73
+ XML_SCHEMAS_UBYTE = 42,
74
+ XML_SCHEMAS_HEXBINARY = 43,
75
+ XML_SCHEMAS_BASE64BINARY = 44,
76
+ XML_SCHEMAS_ANYTYPE = 45,
77
+ XML_SCHEMAS_ANYSIMPLETYPE = 46
78
+ } xmlSchemaValType;
79
+
80
+ /*
81
+ * XML Schemas defines multiple type of types.
82
+ */
83
+ typedef enum {
84
+ XML_SCHEMA_TYPE_BASIC = 1, /* A built-in datatype */
85
+ XML_SCHEMA_TYPE_ANY,
86
+ XML_SCHEMA_TYPE_FACET,
87
+ XML_SCHEMA_TYPE_SIMPLE,
88
+ XML_SCHEMA_TYPE_COMPLEX,
89
+ XML_SCHEMA_TYPE_SEQUENCE = 6,
90
+ XML_SCHEMA_TYPE_CHOICE,
91
+ XML_SCHEMA_TYPE_ALL,
92
+ XML_SCHEMA_TYPE_SIMPLE_CONTENT,
93
+ XML_SCHEMA_TYPE_COMPLEX_CONTENT,
94
+ XML_SCHEMA_TYPE_UR,
95
+ XML_SCHEMA_TYPE_RESTRICTION,
96
+ XML_SCHEMA_TYPE_EXTENSION,
97
+ XML_SCHEMA_TYPE_ELEMENT,
98
+ XML_SCHEMA_TYPE_ATTRIBUTE,
99
+ XML_SCHEMA_TYPE_ATTRIBUTEGROUP,
100
+ XML_SCHEMA_TYPE_GROUP,
101
+ XML_SCHEMA_TYPE_NOTATION,
102
+ XML_SCHEMA_TYPE_LIST,
103
+ XML_SCHEMA_TYPE_UNION,
104
+ XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
105
+ XML_SCHEMA_TYPE_IDC_UNIQUE,
106
+ XML_SCHEMA_TYPE_IDC_KEY,
107
+ XML_SCHEMA_TYPE_IDC_KEYREF,
108
+ XML_SCHEMA_TYPE_PARTICLE = 25,
109
+ XML_SCHEMA_TYPE_ATTRIBUTE_USE,
110
+ XML_SCHEMA_FACET_MININCLUSIVE = 1000,
111
+ XML_SCHEMA_FACET_MINEXCLUSIVE,
112
+ XML_SCHEMA_FACET_MAXINCLUSIVE,
113
+ XML_SCHEMA_FACET_MAXEXCLUSIVE,
114
+ XML_SCHEMA_FACET_TOTALDIGITS,
115
+ XML_SCHEMA_FACET_FRACTIONDIGITS,
116
+ XML_SCHEMA_FACET_PATTERN,
117
+ XML_SCHEMA_FACET_ENUMERATION,
118
+ XML_SCHEMA_FACET_WHITESPACE,
119
+ XML_SCHEMA_FACET_LENGTH,
120
+ XML_SCHEMA_FACET_MAXLENGTH,
121
+ XML_SCHEMA_FACET_MINLENGTH,
122
+ XML_SCHEMA_EXTRA_QNAMEREF = 2000,
123
+ XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
124
+ } xmlSchemaTypeType;
125
+
126
+ typedef enum {
127
+ XML_SCHEMA_CONTENT_UNKNOWN = 0,
128
+ XML_SCHEMA_CONTENT_EMPTY = 1,
129
+ XML_SCHEMA_CONTENT_ELEMENTS,
130
+ XML_SCHEMA_CONTENT_MIXED,
131
+ XML_SCHEMA_CONTENT_SIMPLE,
132
+ XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS, /* Obsolete */
133
+ XML_SCHEMA_CONTENT_BASIC,
134
+ XML_SCHEMA_CONTENT_ANY
135
+ } xmlSchemaContentType;
136
+
137
+ typedef struct _xmlSchemaVal xmlSchemaVal;
138
+ typedef xmlSchemaVal *xmlSchemaValPtr;
139
+
140
+ typedef struct _xmlSchemaType xmlSchemaType;
141
+ typedef xmlSchemaType *xmlSchemaTypePtr;
142
+
143
+ typedef struct _xmlSchemaFacet xmlSchemaFacet;
144
+ typedef xmlSchemaFacet *xmlSchemaFacetPtr;
145
+
146
+ /**
147
+ * Annotation
148
+ */
149
+ typedef struct _xmlSchemaAnnot xmlSchemaAnnot;
150
+ typedef xmlSchemaAnnot *xmlSchemaAnnotPtr;
151
+ struct _xmlSchemaAnnot {
152
+ struct _xmlSchemaAnnot *next;
153
+ xmlNodePtr content; /* the annotation */
154
+ };
155
+
156
+ /**
157
+ * XML_SCHEMAS_ANYATTR_SKIP:
158
+ *
159
+ * Skip unknown attribute from validation
160
+ * Obsolete, not used anymore.
161
+ */
162
+ #define XML_SCHEMAS_ANYATTR_SKIP 1
163
+ /**
164
+ * XML_SCHEMAS_ANYATTR_LAX:
165
+ *
166
+ * Ignore validation non definition on attributes
167
+ * Obsolete, not used anymore.
168
+ */
169
+ #define XML_SCHEMAS_ANYATTR_LAX 2
170
+ /**
171
+ * XML_SCHEMAS_ANYATTR_STRICT:
172
+ *
173
+ * Apply strict validation rules on attributes
174
+ * Obsolete, not used anymore.
175
+ */
176
+ #define XML_SCHEMAS_ANYATTR_STRICT 3
177
+ /**
178
+ * XML_SCHEMAS_ANY_SKIP:
179
+ *
180
+ * Skip unknown attribute from validation
181
+ */
182
+ #define XML_SCHEMAS_ANY_SKIP 1
183
+ /**
184
+ * XML_SCHEMAS_ANY_LAX:
185
+ *
186
+ * Used by wildcards.
187
+ * Validate if type found, don't worry if not found
188
+ */
189
+ #define XML_SCHEMAS_ANY_LAX 2
190
+ /**
191
+ * XML_SCHEMAS_ANY_STRICT:
192
+ *
193
+ * Used by wildcards.
194
+ * Apply strict validation rules
195
+ */
196
+ #define XML_SCHEMAS_ANY_STRICT 3
197
+ /**
198
+ * XML_SCHEMAS_ATTR_USE_PROHIBITED:
199
+ *
200
+ * Used by wildcards.
201
+ * The attribute is prohibited.
202
+ */
203
+ #define XML_SCHEMAS_ATTR_USE_PROHIBITED 0
204
+ /**
205
+ * XML_SCHEMAS_ATTR_USE_REQUIRED:
206
+ *
207
+ * The attribute is required.
208
+ */
209
+ #define XML_SCHEMAS_ATTR_USE_REQUIRED 1
210
+ /**
211
+ * XML_SCHEMAS_ATTR_USE_OPTIONAL:
212
+ *
213
+ * The attribute is optional.
214
+ */
215
+ #define XML_SCHEMAS_ATTR_USE_OPTIONAL 2
216
+ /**
217
+ * XML_SCHEMAS_ATTR_GLOBAL:
218
+ *
219
+ * allow elements in no namespace
220
+ */
221
+ #define XML_SCHEMAS_ATTR_GLOBAL 1 << 0
222
+ /**
223
+ * XML_SCHEMAS_ATTR_NSDEFAULT:
224
+ *
225
+ * allow elements in no namespace
226
+ */
227
+ #define XML_SCHEMAS_ATTR_NSDEFAULT 1 << 7
228
+ /**
229
+ * XML_SCHEMAS_ATTR_INTERNAL_RESOLVED:
230
+ *
231
+ * this is set when the "type" and "ref" references
232
+ * have been resolved.
233
+ */
234
+ #define XML_SCHEMAS_ATTR_INTERNAL_RESOLVED 1 << 8
235
+ /**
236
+ * XML_SCHEMAS_ATTR_FIXED:
237
+ *
238
+ * the attribute has a fixed value
239
+ */
240
+ #define XML_SCHEMAS_ATTR_FIXED 1 << 9
241
+
242
+ /**
243
+ * xmlSchemaAttribute:
244
+ * An attribute definition.
245
+ */
246
+
247
+ typedef struct _xmlSchemaAttribute xmlSchemaAttribute;
248
+ typedef xmlSchemaAttribute *xmlSchemaAttributePtr;
249
+ struct _xmlSchemaAttribute {
250
+ xmlSchemaTypeType type;
251
+ struct _xmlSchemaAttribute *next; /* the next attribute (not used?) */
252
+ const xmlChar *name; /* the name of the declaration */
253
+ const xmlChar *id; /* Deprecated; not used */
254
+ const xmlChar *ref; /* Deprecated; not used */
255
+ const xmlChar *refNs; /* Deprecated; not used */
256
+ const xmlChar *typeName; /* the local name of the type definition */
257
+ const xmlChar *typeNs; /* the ns URI of the type definition */
258
+ xmlSchemaAnnotPtr annot;
259
+
260
+ xmlSchemaTypePtr base; /* Deprecated; not used */
261
+ int occurs; /* Deprecated; not used */
262
+ const xmlChar *defValue; /* The initial value of the value constraint */
263
+ xmlSchemaTypePtr subtypes; /* the type definition */
264
+ xmlNodePtr node;
265
+ const xmlChar *targetNamespace;
266
+ int flags;
267
+ const xmlChar *refPrefix; /* Deprecated; not used */
268
+ xmlSchemaValPtr defVal; /* The compiled value constraint */
269
+ xmlSchemaAttributePtr refDecl; /* Deprecated; not used */
270
+ };
271
+
272
+ /**
273
+ * xmlSchemaAttributeLink:
274
+ * Used to build a list of attribute uses on complexType definitions.
275
+ * WARNING: Deprecated; not used.
276
+ */
277
+ typedef struct _xmlSchemaAttributeLink xmlSchemaAttributeLink;
278
+ typedef xmlSchemaAttributeLink *xmlSchemaAttributeLinkPtr;
279
+ struct _xmlSchemaAttributeLink {
280
+ struct _xmlSchemaAttributeLink *next;/* the next attribute link ... */
281
+ struct _xmlSchemaAttribute *attr;/* the linked attribute */
282
+ };
283
+
284
+ /**
285
+ * XML_SCHEMAS_WILDCARD_COMPLETE:
286
+ *
287
+ * If the wildcard is complete.
288
+ */
289
+ #define XML_SCHEMAS_WILDCARD_COMPLETE 1 << 0
290
+
291
+ /**
292
+ * xmlSchemaCharValueLink:
293
+ * Used to build a list of namespaces on wildcards.
294
+ */
295
+ typedef struct _xmlSchemaWildcardNs xmlSchemaWildcardNs;
296
+ typedef xmlSchemaWildcardNs *xmlSchemaWildcardNsPtr;
297
+ struct _xmlSchemaWildcardNs {
298
+ struct _xmlSchemaWildcardNs *next;/* the next constraint link ... */
299
+ const xmlChar *value;/* the value */
300
+ };
301
+
302
+ /**
303
+ * xmlSchemaWildcard.
304
+ * A wildcard.
305
+ */
306
+ typedef struct _xmlSchemaWildcard xmlSchemaWildcard;
307
+ typedef xmlSchemaWildcard *xmlSchemaWildcardPtr;
308
+ struct _xmlSchemaWildcard {
309
+ xmlSchemaTypeType type; /* The kind of type */
310
+ const xmlChar *id; /* Deprecated; not used */
311
+ xmlSchemaAnnotPtr annot;
312
+ xmlNodePtr node;
313
+ int minOccurs; /* Deprecated; not used */
314
+ int maxOccurs; /* Deprecated; not used */
315
+ int processContents;
316
+ int any; /* Indicates if the ns constraint is of ##any */
317
+ xmlSchemaWildcardNsPtr nsSet; /* The list of allowed namespaces */
318
+ xmlSchemaWildcardNsPtr negNsSet; /* The negated namespace */
319
+ int flags;
320
+ };
321
+
322
+ /**
323
+ * XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED:
324
+ *
325
+ * The attribute wildcard has been built.
326
+ */
327
+ #define XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED 1 << 0
328
+ /**
329
+ * XML_SCHEMAS_ATTRGROUP_GLOBAL:
330
+ *
331
+ * The attribute group has been defined.
332
+ */
333
+ #define XML_SCHEMAS_ATTRGROUP_GLOBAL 1 << 1
334
+ /**
335
+ * XML_SCHEMAS_ATTRGROUP_MARKED:
336
+ *
337
+ * Marks the attr group as marked; used for circular checks.
338
+ */
339
+ #define XML_SCHEMAS_ATTRGROUP_MARKED 1 << 2
340
+
341
+ /**
342
+ * XML_SCHEMAS_ATTRGROUP_REDEFINED:
343
+ *
344
+ * The attr group was redefined.
345
+ */
346
+ #define XML_SCHEMAS_ATTRGROUP_REDEFINED 1 << 3
347
+ /**
348
+ * XML_SCHEMAS_ATTRGROUP_HAS_REFS:
349
+ *
350
+ * Whether this attr. group contains attr. group references.
351
+ */
352
+ #define XML_SCHEMAS_ATTRGROUP_HAS_REFS 1 << 4
353
+
354
+ /**
355
+ * An attribute group definition.
356
+ *
357
+ * xmlSchemaAttribute and xmlSchemaAttributeGroup start of structures
358
+ * must be kept similar
359
+ */
360
+ typedef struct _xmlSchemaAttributeGroup xmlSchemaAttributeGroup;
361
+ typedef xmlSchemaAttributeGroup *xmlSchemaAttributeGroupPtr;
362
+ struct _xmlSchemaAttributeGroup {
363
+ xmlSchemaTypeType type; /* The kind of type */
364
+ struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */
365
+ const xmlChar *name;
366
+ const xmlChar *id;
367
+ const xmlChar *ref; /* Deprecated; not used */
368
+ const xmlChar *refNs; /* Deprecated; not used */
369
+ xmlSchemaAnnotPtr annot;
370
+
371
+ xmlSchemaAttributePtr attributes; /* Deprecated; not used */
372
+ xmlNodePtr node;
373
+ int flags;
374
+ xmlSchemaWildcardPtr attributeWildcard;
375
+ const xmlChar *refPrefix; /* Deprecated; not used */
376
+ xmlSchemaAttributeGroupPtr refItem; /* Deprecated; not used */
377
+ const xmlChar *targetNamespace;
378
+ void *attrUses;
379
+ };
380
+
381
+ /**
382
+ * xmlSchemaTypeLink:
383
+ * Used to build a list of types (e.g. member types of
384
+ * simpleType with variety "union").
385
+ */
386
+ typedef struct _xmlSchemaTypeLink xmlSchemaTypeLink;
387
+ typedef xmlSchemaTypeLink *xmlSchemaTypeLinkPtr;
388
+ struct _xmlSchemaTypeLink {
389
+ struct _xmlSchemaTypeLink *next;/* the next type link ... */
390
+ xmlSchemaTypePtr type;/* the linked type */
391
+ };
392
+
393
+ /**
394
+ * xmlSchemaFacetLink:
395
+ * Used to build a list of facets.
396
+ */
397
+ typedef struct _xmlSchemaFacetLink xmlSchemaFacetLink;
398
+ typedef xmlSchemaFacetLink *xmlSchemaFacetLinkPtr;
399
+ struct _xmlSchemaFacetLink {
400
+ struct _xmlSchemaFacetLink *next;/* the next facet link ... */
401
+ xmlSchemaFacetPtr facet;/* the linked facet */
402
+ };
403
+
404
+ /**
405
+ * XML_SCHEMAS_TYPE_MIXED:
406
+ *
407
+ * the element content type is mixed
408
+ */
409
+ #define XML_SCHEMAS_TYPE_MIXED 1 << 0
410
+ /**
411
+ * XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION:
412
+ *
413
+ * the simple or complex type has a derivation method of "extension".
414
+ */
415
+ #define XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION 1 << 1
416
+ /**
417
+ * XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION:
418
+ *
419
+ * the simple or complex type has a derivation method of "restriction".
420
+ */
421
+ #define XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION 1 << 2
422
+ /**
423
+ * XML_SCHEMAS_TYPE_GLOBAL:
424
+ *
425
+ * the type is global
426
+ */
427
+ #define XML_SCHEMAS_TYPE_GLOBAL 1 << 3
428
+ /**
429
+ * XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD:
430
+ *
431
+ * the complexType owns an attribute wildcard, i.e.
432
+ * it can be freed by the complexType
433
+ */
434
+ #define XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD 1 << 4 /* Obsolete. */
435
+ /**
436
+ * XML_SCHEMAS_TYPE_VARIETY_ABSENT:
437
+ *
438
+ * the simpleType has a variety of "absent".
439
+ * TODO: Actually not necessary :-/, since if
440
+ * none of the variety flags occur then it's
441
+ * automatically absent.
442
+ */
443
+ #define XML_SCHEMAS_TYPE_VARIETY_ABSENT 1 << 5
444
+ /**
445
+ * XML_SCHEMAS_TYPE_VARIETY_LIST:
446
+ *
447
+ * the simpleType has a variety of "list".
448
+ */
449
+ #define XML_SCHEMAS_TYPE_VARIETY_LIST 1 << 6
450
+ /**
451
+ * XML_SCHEMAS_TYPE_VARIETY_UNION:
452
+ *
453
+ * the simpleType has a variety of "union".
454
+ */
455
+ #define XML_SCHEMAS_TYPE_VARIETY_UNION 1 << 7
456
+ /**
457
+ * XML_SCHEMAS_TYPE_VARIETY_ATOMIC:
458
+ *
459
+ * the simpleType has a variety of "union".
460
+ */
461
+ #define XML_SCHEMAS_TYPE_VARIETY_ATOMIC 1 << 8
462
+ /**
463
+ * XML_SCHEMAS_TYPE_FINAL_EXTENSION:
464
+ *
465
+ * the complexType has a final of "extension".
466
+ */
467
+ #define XML_SCHEMAS_TYPE_FINAL_EXTENSION 1 << 9
468
+ /**
469
+ * XML_SCHEMAS_TYPE_FINAL_RESTRICTION:
470
+ *
471
+ * the simpleType/complexType has a final of "restriction".
472
+ */
473
+ #define XML_SCHEMAS_TYPE_FINAL_RESTRICTION 1 << 10
474
+ /**
475
+ * XML_SCHEMAS_TYPE_FINAL_LIST:
476
+ *
477
+ * the simpleType has a final of "list".
478
+ */
479
+ #define XML_SCHEMAS_TYPE_FINAL_LIST 1 << 11
480
+ /**
481
+ * XML_SCHEMAS_TYPE_FINAL_UNION:
482
+ *
483
+ * the simpleType has a final of "union".
484
+ */
485
+ #define XML_SCHEMAS_TYPE_FINAL_UNION 1 << 12
486
+ /**
487
+ * XML_SCHEMAS_TYPE_FINAL_DEFAULT:
488
+ *
489
+ * the simpleType has a final of "default".
490
+ */
491
+ #define XML_SCHEMAS_TYPE_FINAL_DEFAULT 1 << 13
492
+ /**
493
+ * XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE:
494
+ *
495
+ * Marks the item as a builtin primitive.
496
+ */
497
+ #define XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE 1 << 14
498
+ /**
499
+ * XML_SCHEMAS_TYPE_MARKED:
500
+ *
501
+ * Marks the item as marked; used for circular checks.
502
+ */
503
+ #define XML_SCHEMAS_TYPE_MARKED 1 << 16
504
+ /**
505
+ * XML_SCHEMAS_TYPE_BLOCK_DEFAULT:
506
+ *
507
+ * the complexType did not specify 'block' so use the default of the
508
+ * <schema> item.
509
+ */
510
+ #define XML_SCHEMAS_TYPE_BLOCK_DEFAULT 1 << 17
511
+ /**
512
+ * XML_SCHEMAS_TYPE_BLOCK_EXTENSION:
513
+ *
514
+ * the complexType has a 'block' of "extension".
515
+ */
516
+ #define XML_SCHEMAS_TYPE_BLOCK_EXTENSION 1 << 18
517
+ /**
518
+ * XML_SCHEMAS_TYPE_BLOCK_RESTRICTION:
519
+ *
520
+ * the complexType has a 'block' of "restriction".
521
+ */
522
+ #define XML_SCHEMAS_TYPE_BLOCK_RESTRICTION 1 << 19
523
+ /**
524
+ * XML_SCHEMAS_TYPE_ABSTRACT:
525
+ *
526
+ * the simple/complexType is abstract.
527
+ */
528
+ #define XML_SCHEMAS_TYPE_ABSTRACT 1 << 20
529
+ /**
530
+ * XML_SCHEMAS_TYPE_FACETSNEEDVALUE:
531
+ *
532
+ * indicates if the facets need a computed value
533
+ */
534
+ #define XML_SCHEMAS_TYPE_FACETSNEEDVALUE 1 << 21
535
+ /**
536
+ * XML_SCHEMAS_TYPE_INTERNAL_RESOLVED:
537
+ *
538
+ * indicates that the type was typefixed
539
+ */
540
+ #define XML_SCHEMAS_TYPE_INTERNAL_RESOLVED 1 << 22
541
+ /**
542
+ * XML_SCHEMAS_TYPE_INTERNAL_INVALID:
543
+ *
544
+ * indicates that the type is invalid
545
+ */
546
+ #define XML_SCHEMAS_TYPE_INTERNAL_INVALID 1 << 23
547
+ /**
548
+ * XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE:
549
+ *
550
+ * a whitespace-facet value of "preserve"
551
+ */
552
+ #define XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE 1 << 24
553
+ /**
554
+ * XML_SCHEMAS_TYPE_WHITESPACE_REPLACE:
555
+ *
556
+ * a whitespace-facet value of "replace"
557
+ */
558
+ #define XML_SCHEMAS_TYPE_WHITESPACE_REPLACE 1 << 25
559
+ /**
560
+ * XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE:
561
+ *
562
+ * a whitespace-facet value of "collapse"
563
+ */
564
+ #define XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE 1 << 26
565
+ /**
566
+ * XML_SCHEMAS_TYPE_HAS_FACETS:
567
+ *
568
+ * has facets
569
+ */
570
+ #define XML_SCHEMAS_TYPE_HAS_FACETS 1 << 27
571
+ /**
572
+ * XML_SCHEMAS_TYPE_NORMVALUENEEDED:
573
+ *
574
+ * indicates if the facets (pattern) need a normalized value
575
+ */
576
+ #define XML_SCHEMAS_TYPE_NORMVALUENEEDED 1 << 28
577
+
578
+ /**
579
+ * XML_SCHEMAS_TYPE_FIXUP_1:
580
+ *
581
+ * First stage of fixup was done.
582
+ */
583
+ #define XML_SCHEMAS_TYPE_FIXUP_1 1 << 29
584
+
585
+ /**
586
+ * XML_SCHEMAS_TYPE_REDEFINED:
587
+ *
588
+ * The type was redefined.
589
+ */
590
+ #define XML_SCHEMAS_TYPE_REDEFINED 1 << 30
591
+ /**
592
+ * XML_SCHEMAS_TYPE_REDEFINING:
593
+ *
594
+ * The type redefines an other type.
595
+ */
596
+ /* #define XML_SCHEMAS_TYPE_REDEFINING 1 << 31 */
597
+
598
+ /**
599
+ * _xmlSchemaType:
600
+ *
601
+ * Schemas type definition.
602
+ */
603
+ struct _xmlSchemaType {
604
+ xmlSchemaTypeType type; /* The kind of type */
605
+ struct _xmlSchemaType *next; /* the next type if in a sequence ... */
606
+ const xmlChar *name;
607
+ const xmlChar *id ; /* Deprecated; not used */
608
+ const xmlChar *ref; /* Deprecated; not used */
609
+ const xmlChar *refNs; /* Deprecated; not used */
610
+ xmlSchemaAnnotPtr annot;
611
+ xmlSchemaTypePtr subtypes;
612
+ xmlSchemaAttributePtr attributes; /* Deprecated; not used */
613
+ xmlNodePtr node;
614
+ int minOccurs; /* Deprecated; not used */
615
+ int maxOccurs; /* Deprecated; not used */
616
+
617
+ int flags;
618
+ xmlSchemaContentType contentType;
619
+ const xmlChar *base; /* Base type's local name */
620
+ const xmlChar *baseNs; /* Base type's target namespace */
621
+ xmlSchemaTypePtr baseType; /* The base type component */
622
+ xmlSchemaFacetPtr facets; /* Local facets */
623
+ struct _xmlSchemaType *redef; /* Deprecated; not used */
624
+ int recurse; /* Obsolete */
625
+ xmlSchemaAttributeLinkPtr *attributeUses; /* Deprecated; not used */
626
+ xmlSchemaWildcardPtr attributeWildcard;
627
+ int builtInType; /* Type of built-in types. */
628
+ xmlSchemaTypeLinkPtr memberTypes; /* member-types if a union type. */
629
+ xmlSchemaFacetLinkPtr facetSet; /* All facets (incl. inherited) */
630
+ const xmlChar *refPrefix; /* Deprecated; not used */
631
+ xmlSchemaTypePtr contentTypeDef; /* Used for the simple content of complex types.
632
+ Could we use @subtypes for this? */
633
+ xmlRegexpPtr contModel; /* Holds the automaton of the content model */
634
+ const xmlChar *targetNamespace;
635
+ void *attrUses;
636
+ };
637
+
638
+ /*
639
+ * xmlSchemaElement:
640
+ * An element definition.
641
+ *
642
+ * xmlSchemaType, xmlSchemaFacet and xmlSchemaElement start of
643
+ * structures must be kept similar
644
+ */
645
+ /**
646
+ * XML_SCHEMAS_ELEM_NILLABLE:
647
+ *
648
+ * the element is nillable
649
+ */
650
+ #define XML_SCHEMAS_ELEM_NILLABLE 1 << 0
651
+ /**
652
+ * XML_SCHEMAS_ELEM_GLOBAL:
653
+ *
654
+ * the element is global
655
+ */
656
+ #define XML_SCHEMAS_ELEM_GLOBAL 1 << 1
657
+ /**
658
+ * XML_SCHEMAS_ELEM_DEFAULT:
659
+ *
660
+ * the element has a default value
661
+ */
662
+ #define XML_SCHEMAS_ELEM_DEFAULT 1 << 2
663
+ /**
664
+ * XML_SCHEMAS_ELEM_FIXED:
665
+ *
666
+ * the element has a fixed value
667
+ */
668
+ #define XML_SCHEMAS_ELEM_FIXED 1 << 3
669
+ /**
670
+ * XML_SCHEMAS_ELEM_ABSTRACT:
671
+ *
672
+ * the element is abstract
673
+ */
674
+ #define XML_SCHEMAS_ELEM_ABSTRACT 1 << 4
675
+ /**
676
+ * XML_SCHEMAS_ELEM_TOPLEVEL:
677
+ *
678
+ * the element is top level
679
+ * obsolete: use XML_SCHEMAS_ELEM_GLOBAL instead
680
+ */
681
+ #define XML_SCHEMAS_ELEM_TOPLEVEL 1 << 5
682
+ /**
683
+ * XML_SCHEMAS_ELEM_REF:
684
+ *
685
+ * the element is a reference to a type
686
+ */
687
+ #define XML_SCHEMAS_ELEM_REF 1 << 6
688
+ /**
689
+ * XML_SCHEMAS_ELEM_NSDEFAULT:
690
+ *
691
+ * allow elements in no namespace
692
+ * Obsolete, not used anymore.
693
+ */
694
+ #define XML_SCHEMAS_ELEM_NSDEFAULT 1 << 7
695
+ /**
696
+ * XML_SCHEMAS_ELEM_INTERNAL_RESOLVED:
697
+ *
698
+ * this is set when "type", "ref", "substitutionGroup"
699
+ * references have been resolved.
700
+ */
701
+ #define XML_SCHEMAS_ELEM_INTERNAL_RESOLVED 1 << 8
702
+ /**
703
+ * XML_SCHEMAS_ELEM_CIRCULAR:
704
+ *
705
+ * a helper flag for the search of circular references.
706
+ */
707
+ #define XML_SCHEMAS_ELEM_CIRCULAR 1 << 9
708
+ /**
709
+ * XML_SCHEMAS_ELEM_BLOCK_ABSENT:
710
+ *
711
+ * the "block" attribute is absent
712
+ */
713
+ #define XML_SCHEMAS_ELEM_BLOCK_ABSENT 1 << 10
714
+ /**
715
+ * XML_SCHEMAS_ELEM_BLOCK_EXTENSION:
716
+ *
717
+ * disallowed substitutions are absent
718
+ */
719
+ #define XML_SCHEMAS_ELEM_BLOCK_EXTENSION 1 << 11
720
+ /**
721
+ * XML_SCHEMAS_ELEM_BLOCK_RESTRICTION:
722
+ *
723
+ * disallowed substitutions: "restriction"
724
+ */
725
+ #define XML_SCHEMAS_ELEM_BLOCK_RESTRICTION 1 << 12
726
+ /**
727
+ * XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION:
728
+ *
729
+ * disallowed substitutions: "substitution"
730
+ */
731
+ #define XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION 1 << 13
732
+ /**
733
+ * XML_SCHEMAS_ELEM_FINAL_ABSENT:
734
+ *
735
+ * substitution group exclusions are absent
736
+ */
737
+ #define XML_SCHEMAS_ELEM_FINAL_ABSENT 1 << 14
738
+ /**
739
+ * XML_SCHEMAS_ELEM_FINAL_EXTENSION:
740
+ *
741
+ * substitution group exclusions: "extension"
742
+ */
743
+ #define XML_SCHEMAS_ELEM_FINAL_EXTENSION 1 << 15
744
+ /**
745
+ * XML_SCHEMAS_ELEM_FINAL_RESTRICTION:
746
+ *
747
+ * substitution group exclusions: "restriction"
748
+ */
749
+ #define XML_SCHEMAS_ELEM_FINAL_RESTRICTION 1 << 16
750
+ /**
751
+ * XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD:
752
+ *
753
+ * the declaration is a substitution group head
754
+ */
755
+ #define XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD 1 << 17
756
+ /**
757
+ * XML_SCHEMAS_ELEM_INTERNAL_CHECKED:
758
+ *
759
+ * this is set when the elem decl has been checked against
760
+ * all constraints
761
+ */
762
+ #define XML_SCHEMAS_ELEM_INTERNAL_CHECKED 1 << 18
763
+
764
+ typedef struct _xmlSchemaElement xmlSchemaElement;
765
+ typedef xmlSchemaElement *xmlSchemaElementPtr;
766
+ struct _xmlSchemaElement {
767
+ xmlSchemaTypeType type; /* The kind of type */
768
+ struct _xmlSchemaType *next; /* Not used? */
769
+ const xmlChar *name;
770
+ const xmlChar *id; /* Deprecated; not used */
771
+ const xmlChar *ref; /* Deprecated; not used */
772
+ const xmlChar *refNs; /* Deprecated; not used */
773
+ xmlSchemaAnnotPtr annot;
774
+ xmlSchemaTypePtr subtypes; /* the type definition */
775
+ xmlSchemaAttributePtr attributes;
776
+ xmlNodePtr node;
777
+ int minOccurs; /* Deprecated; not used */
778
+ int maxOccurs; /* Deprecated; not used */
779
+
780
+ int flags;
781
+ const xmlChar *targetNamespace;
782
+ const xmlChar *namedType;
783
+ const xmlChar *namedTypeNs;
784
+ const xmlChar *substGroup;
785
+ const xmlChar *substGroupNs;
786
+ const xmlChar *scope;
787
+ const xmlChar *value; /* The original value of the value constraint. */
788
+ struct _xmlSchemaElement *refDecl; /* This will now be used for the
789
+ substitution group affiliation */
790
+ xmlRegexpPtr contModel; /* Obsolete for WXS, maybe used for RelaxNG */
791
+ xmlSchemaContentType contentType;
792
+ const xmlChar *refPrefix; /* Deprecated; not used */
793
+ xmlSchemaValPtr defVal; /* The compiled value constraint. */
794
+ void *idcs; /* The identity-constraint defs */
795
+ };
796
+
797
+ /*
798
+ * XML_SCHEMAS_FACET_UNKNOWN:
799
+ *
800
+ * unknown facet handling
801
+ */
802
+ #define XML_SCHEMAS_FACET_UNKNOWN 0
803
+ /*
804
+ * XML_SCHEMAS_FACET_PRESERVE:
805
+ *
806
+ * preserve the type of the facet
807
+ */
808
+ #define XML_SCHEMAS_FACET_PRESERVE 1
809
+ /*
810
+ * XML_SCHEMAS_FACET_REPLACE:
811
+ *
812
+ * replace the type of the facet
813
+ */
814
+ #define XML_SCHEMAS_FACET_REPLACE 2
815
+ /*
816
+ * XML_SCHEMAS_FACET_COLLAPSE:
817
+ *
818
+ * collapse the types of the facet
819
+ */
820
+ #define XML_SCHEMAS_FACET_COLLAPSE 3
821
+ /**
822
+ * A facet definition.
823
+ */
824
+ struct _xmlSchemaFacet {
825
+ xmlSchemaTypeType type; /* The kind of type */
826
+ struct _xmlSchemaFacet *next;/* the next type if in a sequence ... */
827
+ const xmlChar *value; /* The original value */
828
+ const xmlChar *id; /* Obsolete */
829
+ xmlSchemaAnnotPtr annot;
830
+ xmlNodePtr node;
831
+ int fixed; /* XML_SCHEMAS_FACET_PRESERVE, etc. */
832
+ int whitespace;
833
+ xmlSchemaValPtr val; /* The compiled value */
834
+ xmlRegexpPtr regexp; /* The regex for patterns */
835
+ };
836
+
837
+ /**
838
+ * A notation definition.
839
+ */
840
+ typedef struct _xmlSchemaNotation xmlSchemaNotation;
841
+ typedef xmlSchemaNotation *xmlSchemaNotationPtr;
842
+ struct _xmlSchemaNotation {
843
+ xmlSchemaTypeType type; /* The kind of type */
844
+ const xmlChar *name;
845
+ xmlSchemaAnnotPtr annot;
846
+ const xmlChar *identifier;
847
+ const xmlChar *targetNamespace;
848
+ };
849
+
850
+ /*
851
+ * TODO: Actually all those flags used for the schema should sit
852
+ * on the schema parser context, since they are used only
853
+ * during parsing an XML schema document, and not available
854
+ * on the component level as per spec.
855
+ */
856
+ /**
857
+ * XML_SCHEMAS_QUALIF_ELEM:
858
+ *
859
+ * Reflects elementFormDefault == qualified in
860
+ * an XML schema document.
861
+ */
862
+ #define XML_SCHEMAS_QUALIF_ELEM 1 << 0
863
+ /**
864
+ * XML_SCHEMAS_QUALIF_ATTR:
865
+ *
866
+ * Reflects attributeFormDefault == qualified in
867
+ * an XML schema document.
868
+ */
869
+ #define XML_SCHEMAS_QUALIF_ATTR 1 << 1
870
+ /**
871
+ * XML_SCHEMAS_FINAL_DEFAULT_EXTENSION:
872
+ *
873
+ * the schema has "extension" in the set of finalDefault.
874
+ */
875
+ #define XML_SCHEMAS_FINAL_DEFAULT_EXTENSION 1 << 2
876
+ /**
877
+ * XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION:
878
+ *
879
+ * the schema has "restriction" in the set of finalDefault.
880
+ */
881
+ #define XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION 1 << 3
882
+ /**
883
+ * XML_SCHEMAS_FINAL_DEFAULT_LIST:
884
+ *
885
+ * the schema has "list" in the set of finalDefault.
886
+ */
887
+ #define XML_SCHEMAS_FINAL_DEFAULT_LIST 1 << 4
888
+ /**
889
+ * XML_SCHEMAS_FINAL_DEFAULT_UNION:
890
+ *
891
+ * the schema has "union" in the set of finalDefault.
892
+ */
893
+ #define XML_SCHEMAS_FINAL_DEFAULT_UNION 1 << 5
894
+ /**
895
+ * XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION:
896
+ *
897
+ * the schema has "extension" in the set of blockDefault.
898
+ */
899
+ #define XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION 1 << 6
900
+ /**
901
+ * XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION:
902
+ *
903
+ * the schema has "restriction" in the set of blockDefault.
904
+ */
905
+ #define XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION 1 << 7
906
+ /**
907
+ * XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION:
908
+ *
909
+ * the schema has "substitution" in the set of blockDefault.
910
+ */
911
+ #define XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION 1 << 8
912
+ /**
913
+ * XML_SCHEMAS_INCLUDING_CONVERT_NS:
914
+ *
915
+ * the schema is currently including an other schema with
916
+ * no target namespace.
917
+ */
918
+ #define XML_SCHEMAS_INCLUDING_CONVERT_NS 1 << 9
919
+ /**
920
+ * _xmlSchema:
921
+ *
922
+ * A Schemas definition
923
+ */
924
+ struct _xmlSchema {
925
+ const xmlChar *name; /* schema name */
926
+ const xmlChar *targetNamespace; /* the target namespace */
927
+ const xmlChar *version;
928
+ const xmlChar *id; /* Obsolete */
929
+ xmlDocPtr doc;
930
+ xmlSchemaAnnotPtr annot;
931
+ int flags;
932
+
933
+ xmlHashTablePtr typeDecl;
934
+ xmlHashTablePtr attrDecl;
935
+ xmlHashTablePtr attrgrpDecl;
936
+ xmlHashTablePtr elemDecl;
937
+ xmlHashTablePtr notaDecl;
938
+
939
+ xmlHashTablePtr schemasImports;
940
+
941
+ void *_private; /* unused by the library for users or bindings */
942
+ xmlHashTablePtr groupDecl;
943
+ xmlDictPtr dict;
944
+ void *includes; /* the includes, this is opaque for now */
945
+ int preserve; /* whether to free the document */
946
+ int counter; /* used to give anonymous components unique names */
947
+ xmlHashTablePtr idcDef; /* All identity-constraint defs. */
948
+ void *volatiles; /* Obsolete */
949
+ };
950
+
951
+ XMLPUBFUN void xmlSchemaFreeType (xmlSchemaTypePtr type);
952
+ XMLPUBFUN void xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard);
953
+
954
+ #ifdef __cplusplus
955
+ }
956
+ #endif
957
+
958
+ #endif /* LIBXML_SCHEMAS_ENABLED */
959
+ #endif /* __XML_SCHEMA_INTERNALS_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xlink.h ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: unfinished XLink detection module
3
+ * Description: unfinished XLink detection module
4
+ *
5
+ * Copy: See Copyright for the status of this software.
6
+ *
7
+ * Author: Daniel Veillard
8
+ */
9
+
10
+ #ifndef __XML_XLINK_H__
11
+ #define __XML_XLINK_H__
12
+
13
+ #include <libxml/xmlversion.h>
14
+ #include <libxml/tree.h>
15
+
16
+ #ifdef LIBXML_XPTR_ENABLED
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ /**
23
+ * Various defines for the various Link properties.
24
+ *
25
+ * NOTE: the link detection layer will try to resolve QName expansion
26
+ * of namespaces. If "foo" is the prefix for "http://foo.com/"
27
+ * then the link detection layer will expand role="foo:myrole"
28
+ * to "http://foo.com/:myrole".
29
+ * NOTE: the link detection layer will expand URI-References found on
30
+ * href attributes by using the base mechanism if found.
31
+ */
32
+ typedef xmlChar *xlinkHRef;
33
+ typedef xmlChar *xlinkRole;
34
+ typedef xmlChar *xlinkTitle;
35
+
36
+ typedef enum {
37
+ XLINK_TYPE_NONE = 0,
38
+ XLINK_TYPE_SIMPLE,
39
+ XLINK_TYPE_EXTENDED,
40
+ XLINK_TYPE_EXTENDED_SET
41
+ } xlinkType;
42
+
43
+ typedef enum {
44
+ XLINK_SHOW_NONE = 0,
45
+ XLINK_SHOW_NEW,
46
+ XLINK_SHOW_EMBED,
47
+ XLINK_SHOW_REPLACE
48
+ } xlinkShow;
49
+
50
+ typedef enum {
51
+ XLINK_ACTUATE_NONE = 0,
52
+ XLINK_ACTUATE_AUTO,
53
+ XLINK_ACTUATE_ONREQUEST
54
+ } xlinkActuate;
55
+
56
+ /**
57
+ * xlinkNodeDetectFunc:
58
+ * @ctx: user data pointer
59
+ * @node: the node to check
60
+ *
61
+ * This is the prototype for the link detection routine.
62
+ * It calls the default link detection callbacks upon link detection.
63
+ */
64
+ typedef void (*xlinkNodeDetectFunc) (void *ctx, xmlNodePtr node);
65
+
66
+ /*
67
+ * The link detection module interact with the upper layers using
68
+ * a set of callback registered at parsing time.
69
+ */
70
+
71
+ /**
72
+ * xlinkSimpleLinkFunk:
73
+ * @ctx: user data pointer
74
+ * @node: the node carrying the link
75
+ * @href: the target of the link
76
+ * @role: the role string
77
+ * @title: the link title
78
+ *
79
+ * This is the prototype for a simple link detection callback.
80
+ */
81
+ typedef void
82
+ (*xlinkSimpleLinkFunk) (void *ctx,
83
+ xmlNodePtr node,
84
+ const xlinkHRef href,
85
+ const xlinkRole role,
86
+ const xlinkTitle title);
87
+
88
+ /**
89
+ * xlinkExtendedLinkFunk:
90
+ * @ctx: user data pointer
91
+ * @node: the node carrying the link
92
+ * @nbLocators: the number of locators detected on the link
93
+ * @hrefs: pointer to the array of locator hrefs
94
+ * @roles: pointer to the array of locator roles
95
+ * @nbArcs: the number of arcs detected on the link
96
+ * @from: pointer to the array of source roles found on the arcs
97
+ * @to: pointer to the array of target roles found on the arcs
98
+ * @show: array of values for the show attributes found on the arcs
99
+ * @actuate: array of values for the actuate attributes found on the arcs
100
+ * @nbTitles: the number of titles detected on the link
101
+ * @title: array of titles detected on the link
102
+ * @langs: array of xml:lang values for the titles
103
+ *
104
+ * This is the prototype for a extended link detection callback.
105
+ */
106
+ typedef void
107
+ (*xlinkExtendedLinkFunk)(void *ctx,
108
+ xmlNodePtr node,
109
+ int nbLocators,
110
+ const xlinkHRef *hrefs,
111
+ const xlinkRole *roles,
112
+ int nbArcs,
113
+ const xlinkRole *from,
114
+ const xlinkRole *to,
115
+ xlinkShow *show,
116
+ xlinkActuate *actuate,
117
+ int nbTitles,
118
+ const xlinkTitle *titles,
119
+ const xmlChar **langs);
120
+
121
+ /**
122
+ * xlinkExtendedLinkSetFunk:
123
+ * @ctx: user data pointer
124
+ * @node: the node carrying the link
125
+ * @nbLocators: the number of locators detected on the link
126
+ * @hrefs: pointer to the array of locator hrefs
127
+ * @roles: pointer to the array of locator roles
128
+ * @nbTitles: the number of titles detected on the link
129
+ * @title: array of titles detected on the link
130
+ * @langs: array of xml:lang values for the titles
131
+ *
132
+ * This is the prototype for a extended link set detection callback.
133
+ */
134
+ typedef void
135
+ (*xlinkExtendedLinkSetFunk) (void *ctx,
136
+ xmlNodePtr node,
137
+ int nbLocators,
138
+ const xlinkHRef *hrefs,
139
+ const xlinkRole *roles,
140
+ int nbTitles,
141
+ const xlinkTitle *titles,
142
+ const xmlChar **langs);
143
+
144
+ /**
145
+ * This is the structure containing a set of Links detection callbacks.
146
+ *
147
+ * There is no default xlink callbacks, if one want to get link
148
+ * recognition activated, those call backs must be provided before parsing.
149
+ */
150
+ typedef struct _xlinkHandler xlinkHandler;
151
+ typedef xlinkHandler *xlinkHandlerPtr;
152
+ struct _xlinkHandler {
153
+ xlinkSimpleLinkFunk simple;
154
+ xlinkExtendedLinkFunk extended;
155
+ xlinkExtendedLinkSetFunk set;
156
+ };
157
+
158
+ /*
159
+ * The default detection routine, can be overridden, they call the default
160
+ * detection callbacks.
161
+ */
162
+
163
+ XMLPUBFUN xlinkNodeDetectFunc
164
+ xlinkGetDefaultDetect (void);
165
+ XMLPUBFUN void
166
+ xlinkSetDefaultDetect (xlinkNodeDetectFunc func);
167
+
168
+ /*
169
+ * Routines to set/get the default handlers.
170
+ */
171
+ XMLPUBFUN xlinkHandlerPtr
172
+ xlinkGetDefaultHandler (void);
173
+ XMLPUBFUN void
174
+ xlinkSetDefaultHandler (xlinkHandlerPtr handler);
175
+
176
+ /*
177
+ * Link detection module itself.
178
+ */
179
+ XMLPUBFUN xlinkType
180
+ xlinkIsLink (xmlDocPtr doc,
181
+ xmlNodePtr node);
182
+
183
+ #ifdef __cplusplus
184
+ }
185
+ #endif
186
+
187
+ #endif /* LIBXML_XPTR_ENABLED */
188
+
189
+ #endif /* __XML_XLINK_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xmlversion.h ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: compile-time version information
3
+ * Description: compile-time version information for the XML library
4
+ *
5
+ * Copy: See Copyright for the status of this software.
6
+ *
7
+ * Author: Daniel Veillard
8
+ */
9
+
10
+ #ifndef __XML_VERSION_H__
11
+ #define __XML_VERSION_H__
12
+
13
+ #include <libxml/xmlexports.h>
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ /*
20
+ * use those to be sure nothing nasty will happen if
21
+ * your library and includes mismatch
22
+ */
23
+ #ifndef LIBXML2_COMPILING_MSCCDEF
24
+ XMLPUBFUN void xmlCheckVersion(int version);
25
+ #endif /* LIBXML2_COMPILING_MSCCDEF */
26
+
27
+ /**
28
+ * LIBXML_DOTTED_VERSION:
29
+ *
30
+ * the version string like "1.2.3"
31
+ */
32
+ #define LIBXML_DOTTED_VERSION "2.12.9"
33
+
34
+ /**
35
+ * LIBXML_VERSION:
36
+ *
37
+ * the version number: 1.2.3 value is 10203
38
+ */
39
+ #define LIBXML_VERSION 21209
40
+
41
+ /**
42
+ * LIBXML_VERSION_STRING:
43
+ *
44
+ * the version number string, 1.2.3 value is "10203"
45
+ */
46
+ #define LIBXML_VERSION_STRING "21209"
47
+
48
+ /**
49
+ * LIBXML_VERSION_EXTRA:
50
+ *
51
+ * extra version information, used to show a git commit description
52
+ */
53
+ #define LIBXML_VERSION_EXTRA ""
54
+
55
+ /**
56
+ * LIBXML_TEST_VERSION:
57
+ *
58
+ * Macro to check that the libxml version in use is compatible with
59
+ * the version the software has been compiled against
60
+ */
61
+ #define LIBXML_TEST_VERSION xmlCheckVersion(21209);
62
+
63
+ #ifndef VMS
64
+ #if 0
65
+ /**
66
+ * WITH_TRIO:
67
+ *
68
+ * defined if the trio support need to be configured in
69
+ */
70
+ #define WITH_TRIO
71
+ #else
72
+ /**
73
+ * WITHOUT_TRIO:
74
+ *
75
+ * defined if the trio support should not be configured in
76
+ */
77
+ #define WITHOUT_TRIO
78
+ #endif
79
+ #else /* VMS */
80
+ /**
81
+ * WITH_TRIO:
82
+ *
83
+ * defined if the trio support need to be configured in
84
+ */
85
+ #define WITH_TRIO 1
86
+ #endif /* VMS */
87
+
88
+ /**
89
+ * LIBXML_THREAD_ENABLED:
90
+ *
91
+ * Whether the thread support is configured in
92
+ */
93
+ #if 1
94
+ #define LIBXML_THREAD_ENABLED
95
+ #endif
96
+
97
+ /**
98
+ * LIBXML_THREAD_ALLOC_ENABLED:
99
+ *
100
+ * Whether the allocation hooks are per-thread
101
+ */
102
+ #if 0
103
+ #define LIBXML_THREAD_ALLOC_ENABLED
104
+ #endif
105
+
106
+ /**
107
+ * LIBXML_TREE_ENABLED:
108
+ *
109
+ * Whether the DOM like tree manipulation API support is configured in
110
+ */
111
+ #if 1
112
+ #define LIBXML_TREE_ENABLED
113
+ #endif
114
+
115
+ /**
116
+ * LIBXML_OUTPUT_ENABLED:
117
+ *
118
+ * Whether the serialization/saving support is configured in
119
+ */
120
+ #if 1
121
+ #define LIBXML_OUTPUT_ENABLED
122
+ #endif
123
+
124
+ /**
125
+ * LIBXML_PUSH_ENABLED:
126
+ *
127
+ * Whether the push parsing interfaces are configured in
128
+ */
129
+ #if 1
130
+ #define LIBXML_PUSH_ENABLED
131
+ #endif
132
+
133
+ /**
134
+ * LIBXML_READER_ENABLED:
135
+ *
136
+ * Whether the xmlReader parsing interface is configured in
137
+ */
138
+ #if 1
139
+ #define LIBXML_READER_ENABLED
140
+ #endif
141
+
142
+ /**
143
+ * LIBXML_PATTERN_ENABLED:
144
+ *
145
+ * Whether the xmlPattern node selection interface is configured in
146
+ */
147
+ #if 1
148
+ #define LIBXML_PATTERN_ENABLED
149
+ #endif
150
+
151
+ /**
152
+ * LIBXML_WRITER_ENABLED:
153
+ *
154
+ * Whether the xmlWriter saving interface is configured in
155
+ */
156
+ #if 1
157
+ #define LIBXML_WRITER_ENABLED
158
+ #endif
159
+
160
+ /**
161
+ * LIBXML_SAX1_ENABLED:
162
+ *
163
+ * Whether the older SAX1 interface is configured in
164
+ */
165
+ #if 1
166
+ #define LIBXML_SAX1_ENABLED
167
+ #endif
168
+
169
+ /**
170
+ * LIBXML_FTP_ENABLED:
171
+ *
172
+ * Whether the FTP support is configured in
173
+ */
174
+ #if 0
175
+ #define LIBXML_FTP_ENABLED
176
+ #endif
177
+
178
+ /**
179
+ * LIBXML_HTTP_ENABLED:
180
+ *
181
+ * Whether the HTTP support is configured in
182
+ */
183
+ #if 1
184
+ #define LIBXML_HTTP_ENABLED
185
+ #endif
186
+
187
+ /**
188
+ * LIBXML_VALID_ENABLED:
189
+ *
190
+ * Whether the DTD validation support is configured in
191
+ */
192
+ #if 1
193
+ #define LIBXML_VALID_ENABLED
194
+ #endif
195
+
196
+ /**
197
+ * LIBXML_HTML_ENABLED:
198
+ *
199
+ * Whether the HTML support is configured in
200
+ */
201
+ #if 1
202
+ #define LIBXML_HTML_ENABLED
203
+ #endif
204
+
205
+ /**
206
+ * LIBXML_LEGACY_ENABLED:
207
+ *
208
+ * Whether the deprecated APIs are compiled in for compatibility
209
+ */
210
+ #if 0
211
+ #define LIBXML_LEGACY_ENABLED
212
+ #endif
213
+
214
+ /**
215
+ * LIBXML_C14N_ENABLED:
216
+ *
217
+ * Whether the Canonicalization support is configured in
218
+ */
219
+ #if 1
220
+ #define LIBXML_C14N_ENABLED
221
+ #endif
222
+
223
+ /**
224
+ * LIBXML_CATALOG_ENABLED:
225
+ *
226
+ * Whether the Catalog support is configured in
227
+ */
228
+ #if 1
229
+ #define LIBXML_CATALOG_ENABLED
230
+ #endif
231
+
232
+ /**
233
+ * LIBXML_XPATH_ENABLED:
234
+ *
235
+ * Whether XPath is configured in
236
+ */
237
+ #if 1
238
+ #define LIBXML_XPATH_ENABLED
239
+ #endif
240
+
241
+ /**
242
+ * LIBXML_XPTR_ENABLED:
243
+ *
244
+ * Whether XPointer is configured in
245
+ */
246
+ #if 1
247
+ #define LIBXML_XPTR_ENABLED
248
+ #endif
249
+
250
+ /**
251
+ * LIBXML_XPTR_LOCS_ENABLED:
252
+ *
253
+ * Whether support for XPointer locations is configured in
254
+ */
255
+ #if 0
256
+ #define LIBXML_XPTR_LOCS_ENABLED
257
+ #endif
258
+
259
+ /**
260
+ * LIBXML_XINCLUDE_ENABLED:
261
+ *
262
+ * Whether XInclude is configured in
263
+ */
264
+ #if 1
265
+ #define LIBXML_XINCLUDE_ENABLED
266
+ #endif
267
+
268
+ /**
269
+ * LIBXML_ICONV_ENABLED:
270
+ *
271
+ * Whether iconv support is available
272
+ */
273
+ #if 1
274
+ #define LIBXML_ICONV_ENABLED
275
+ #endif
276
+
277
+ /**
278
+ * LIBXML_ICU_ENABLED:
279
+ *
280
+ * Whether icu support is available
281
+ */
282
+ #if 0
283
+ #define LIBXML_ICU_ENABLED
284
+ #endif
285
+
286
+ /**
287
+ * LIBXML_ISO8859X_ENABLED:
288
+ *
289
+ * Whether ISO-8859-* support is made available in case iconv is not
290
+ */
291
+ #if 1
292
+ #define LIBXML_ISO8859X_ENABLED
293
+ #endif
294
+
295
+ /**
296
+ * LIBXML_DEBUG_ENABLED:
297
+ *
298
+ * Whether Debugging module is configured in
299
+ */
300
+ #if 1
301
+ #define LIBXML_DEBUG_ENABLED
302
+ #endif
303
+
304
+ /**
305
+ * DEBUG_MEMORY_LOCATION:
306
+ *
307
+ * Whether the memory debugging is configured in
308
+ */
309
+ #if 0
310
+ #define DEBUG_MEMORY_LOCATION
311
+ #endif
312
+
313
+ /**
314
+ * LIBXML_DEBUG_RUNTIME:
315
+ *
316
+ * Removed
317
+ */
318
+ #if 0
319
+ #define LIBXML_DEBUG_RUNTIME
320
+ #endif
321
+
322
+ /**
323
+ * LIBXML_UNICODE_ENABLED:
324
+ *
325
+ * Whether the Unicode related interfaces are compiled in
326
+ */
327
+ #if 1
328
+ #define LIBXML_UNICODE_ENABLED
329
+ #endif
330
+
331
+ /**
332
+ * LIBXML_REGEXP_ENABLED:
333
+ *
334
+ * Whether the regular expressions interfaces are compiled in
335
+ */
336
+ #if 1
337
+ #define LIBXML_REGEXP_ENABLED
338
+ #endif
339
+
340
+ /**
341
+ * LIBXML_AUTOMATA_ENABLED:
342
+ *
343
+ * Whether the automata interfaces are compiled in
344
+ */
345
+ #if 1
346
+ #define LIBXML_AUTOMATA_ENABLED
347
+ #endif
348
+
349
+ /**
350
+ * LIBXML_EXPR_ENABLED:
351
+ *
352
+ * Whether the formal expressions interfaces are compiled in
353
+ *
354
+ * This code is unused and disabled unconditionally for now.
355
+ */
356
+ #if 0
357
+ #define LIBXML_EXPR_ENABLED
358
+ #endif
359
+
360
+ /**
361
+ * LIBXML_SCHEMAS_ENABLED:
362
+ *
363
+ * Whether the Schemas validation interfaces are compiled in
364
+ */
365
+ #if 1
366
+ #define LIBXML_SCHEMAS_ENABLED
367
+ #endif
368
+
369
+ /**
370
+ * LIBXML_SCHEMATRON_ENABLED:
371
+ *
372
+ * Whether the Schematron validation interfaces are compiled in
373
+ */
374
+ #if 1
375
+ #define LIBXML_SCHEMATRON_ENABLED
376
+ #endif
377
+
378
+ /**
379
+ * LIBXML_MODULES_ENABLED:
380
+ *
381
+ * Whether the module interfaces are compiled in
382
+ */
383
+ #if 1
384
+ #define LIBXML_MODULES_ENABLED
385
+ /**
386
+ * LIBXML_MODULE_EXTENSION:
387
+ *
388
+ * the string suffix used by dynamic modules (usually shared libraries)
389
+ */
390
+ #define LIBXML_MODULE_EXTENSION ".so"
391
+ #endif
392
+
393
+ /**
394
+ * LIBXML_ZLIB_ENABLED:
395
+ *
396
+ * Whether the Zlib support is compiled in
397
+ */
398
+ #if 1
399
+ #define LIBXML_ZLIB_ENABLED
400
+ #endif
401
+
402
+ /**
403
+ * LIBXML_LZMA_ENABLED:
404
+ *
405
+ * Whether the Lzma support is compiled in
406
+ */
407
+ #if 0
408
+ #define LIBXML_LZMA_ENABLED
409
+ #endif
410
+
411
+ #ifdef __GNUC__
412
+ /** DOC_DISABLE */
413
+
414
+ #ifndef ATTRIBUTE_UNUSED
415
+ # if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
416
+ # define ATTRIBUTE_UNUSED __attribute__((unused))
417
+ # else
418
+ # define ATTRIBUTE_UNUSED
419
+ # endif
420
+ #endif
421
+
422
+ #ifndef LIBXML_ATTR_ALLOC_SIZE
423
+ # if (!defined(__clang__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))
424
+ # define LIBXML_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
425
+ # else
426
+ # define LIBXML_ATTR_ALLOC_SIZE(x)
427
+ # endif
428
+ #else
429
+ # define LIBXML_ATTR_ALLOC_SIZE(x)
430
+ #endif
431
+
432
+ #ifndef LIBXML_ATTR_FORMAT
433
+ # if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
434
+ # define LIBXML_ATTR_FORMAT(fmt,args) __attribute__((__format__(__printf__,fmt,args)))
435
+ # else
436
+ # define LIBXML_ATTR_FORMAT(fmt,args)
437
+ # endif
438
+ #else
439
+ # define LIBXML_ATTR_FORMAT(fmt,args)
440
+ #endif
441
+
442
+ #ifndef XML_DEPRECATED
443
+ # if defined (IN_LIBXML) || (__GNUC__ * 100 + __GNUC_MINOR__ < 301)
444
+ # define XML_DEPRECATED
445
+ /* Available since at least GCC 3.1 */
446
+ # else
447
+ # define XML_DEPRECATED __attribute__((deprecated))
448
+ # endif
449
+ #endif
450
+
451
+ #if defined(__clang__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
452
+ #if defined(__clang__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 800)
453
+ #define XML_IGNORE_FPTR_CAST_WARNINGS \
454
+ _Pragma("GCC diagnostic push") \
455
+ _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
456
+ _Pragma("GCC diagnostic ignored \"-Wcast-function-type\"")
457
+ #else
458
+ #define XML_IGNORE_FPTR_CAST_WARNINGS \
459
+ _Pragma("GCC diagnostic push") \
460
+ _Pragma("GCC diagnostic ignored \"-Wpedantic\"")
461
+ #endif
462
+ #define XML_POP_WARNINGS \
463
+ _Pragma("GCC diagnostic pop")
464
+ #else
465
+ #define XML_IGNORE_FPTR_CAST_WARNINGS
466
+ #define XML_POP_WARNINGS
467
+ #endif
468
+
469
+ #else /* ! __GNUC__ */
470
+ #define ATTRIBUTE_UNUSED
471
+ #define LIBXML_ATTR_ALLOC_SIZE(x)
472
+ #define LIBXML_ATTR_FORMAT(fmt,args)
473
+ #ifndef XML_DEPRECATED
474
+ # if defined (IN_LIBXML) || !defined (_MSC_VER)
475
+ # define XML_DEPRECATED
476
+ /* Available since Visual Studio 2005 */
477
+ # elif defined (_MSC_VER) && (_MSC_VER >= 1400)
478
+ # define XML_DEPRECATED __declspec(deprecated)
479
+ # endif
480
+ #endif
481
+ #if defined (_MSC_VER) && (_MSC_VER >= 1400)
482
+ # define XML_IGNORE_FPTR_CAST_WARNINGS __pragma(warning(push))
483
+ #else
484
+ # define XML_IGNORE_FPTR_CAST_WARNINGS
485
+ #endif
486
+ #ifndef XML_POP_WARNINGS
487
+ # if defined (_MSC_VER) && (_MSC_VER >= 1400)
488
+ # define XML_POP_WARNINGS __pragma(warning(pop))
489
+ # else
490
+ # define XML_POP_WARNINGS
491
+ # endif
492
+ #endif
493
+ #endif /* __GNUC__ */
494
+
495
+ #define XML_NO_ATTR
496
+
497
+ #ifdef LIBXML_THREAD_ENABLED
498
+ #define XML_DECLARE_GLOBAL(name, type, attrs) \
499
+ attrs XMLPUBFUN type *__##name(void);
500
+ #define XML_GLOBAL_MACRO(name) (*__##name())
501
+ #else
502
+ #define XML_DECLARE_GLOBAL(name, type, attrs) \
503
+ attrs XMLPUBVAR type name;
504
+ #endif
505
+
506
+ #ifdef __cplusplus
507
+ }
508
+ #endif /* __cplusplus */
509
+ #endif
510
+
511
+
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xmlwriter.h ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: text writing API for XML
3
+ * Description: text writing API for XML
4
+ *
5
+ * Copy: See Copyright for the status of this software.
6
+ *
7
+ * Author: Alfred Mickautsch <alfred@mickautsch.de>
8
+ */
9
+
10
+ #ifndef __XML_XMLWRITER_H__
11
+ #define __XML_XMLWRITER_H__
12
+
13
+ #include <libxml/xmlversion.h>
14
+
15
+ #ifdef LIBXML_WRITER_ENABLED
16
+
17
+ #include <stdarg.h>
18
+ #include <libxml/xmlIO.h>
19
+ #include <libxml/list.h>
20
+ #include <libxml/xmlstring.h>
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ typedef struct _xmlTextWriter xmlTextWriter;
27
+ typedef xmlTextWriter *xmlTextWriterPtr;
28
+
29
+ /*
30
+ * Constructors & Destructor
31
+ */
32
+ XMLPUBFUN xmlTextWriterPtr
33
+ xmlNewTextWriter(xmlOutputBufferPtr out);
34
+ XMLPUBFUN xmlTextWriterPtr
35
+ xmlNewTextWriterFilename(const char *uri, int compression);
36
+ XMLPUBFUN xmlTextWriterPtr
37
+ xmlNewTextWriterMemory(xmlBufferPtr buf, int compression);
38
+ XMLPUBFUN xmlTextWriterPtr
39
+ xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt, int compression);
40
+ XMLPUBFUN xmlTextWriterPtr
41
+ xmlNewTextWriterDoc(xmlDocPtr * doc, int compression);
42
+ XMLPUBFUN xmlTextWriterPtr
43
+ xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node,
44
+ int compression);
45
+ XMLPUBFUN void xmlFreeTextWriter(xmlTextWriterPtr writer);
46
+
47
+ /*
48
+ * Functions
49
+ */
50
+
51
+
52
+ /*
53
+ * Document
54
+ */
55
+ XMLPUBFUN int
56
+ xmlTextWriterStartDocument(xmlTextWriterPtr writer,
57
+ const char *version,
58
+ const char *encoding,
59
+ const char *standalone);
60
+ XMLPUBFUN int xmlTextWriterEndDocument(xmlTextWriterPtr
61
+ writer);
62
+
63
+ /*
64
+ * Comments
65
+ */
66
+ XMLPUBFUN int xmlTextWriterStartComment(xmlTextWriterPtr
67
+ writer);
68
+ XMLPUBFUN int xmlTextWriterEndComment(xmlTextWriterPtr writer);
69
+ XMLPUBFUN int
70
+ xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
71
+ const char *format, ...)
72
+ LIBXML_ATTR_FORMAT(2,3);
73
+ XMLPUBFUN int
74
+ xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
75
+ const char *format,
76
+ va_list argptr)
77
+ LIBXML_ATTR_FORMAT(2,0);
78
+ XMLPUBFUN int xmlTextWriterWriteComment(xmlTextWriterPtr
79
+ writer,
80
+ const xmlChar *
81
+ content);
82
+
83
+ /*
84
+ * Elements
85
+ */
86
+ XMLPUBFUN int
87
+ xmlTextWriterStartElement(xmlTextWriterPtr writer,
88
+ const xmlChar * name);
89
+ XMLPUBFUN int xmlTextWriterStartElementNS(xmlTextWriterPtr
90
+ writer,
91
+ const xmlChar *
92
+ prefix,
93
+ const xmlChar * name,
94
+ const xmlChar *
95
+ namespaceURI);
96
+ XMLPUBFUN int xmlTextWriterEndElement(xmlTextWriterPtr writer);
97
+ XMLPUBFUN int xmlTextWriterFullEndElement(xmlTextWriterPtr
98
+ writer);
99
+
100
+ /*
101
+ * Elements conveniency functions
102
+ */
103
+ XMLPUBFUN int
104
+ xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
105
+ const xmlChar * name,
106
+ const char *format, ...)
107
+ LIBXML_ATTR_FORMAT(3,4);
108
+ XMLPUBFUN int
109
+ xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
110
+ const xmlChar * name,
111
+ const char *format,
112
+ va_list argptr)
113
+ LIBXML_ATTR_FORMAT(3,0);
114
+ XMLPUBFUN int xmlTextWriterWriteElement(xmlTextWriterPtr
115
+ writer,
116
+ const xmlChar * name,
117
+ const xmlChar *
118
+ content);
119
+ XMLPUBFUN int
120
+ xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer,
121
+ const xmlChar * prefix,
122
+ const xmlChar * name,
123
+ const xmlChar * namespaceURI,
124
+ const char *format, ...)
125
+ LIBXML_ATTR_FORMAT(5,6);
126
+ XMLPUBFUN int
127
+ xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
128
+ const xmlChar * prefix,
129
+ const xmlChar * name,
130
+ const xmlChar * namespaceURI,
131
+ const char *format,
132
+ va_list argptr)
133
+ LIBXML_ATTR_FORMAT(5,0);
134
+ XMLPUBFUN int xmlTextWriterWriteElementNS(xmlTextWriterPtr
135
+ writer,
136
+ const xmlChar *
137
+ prefix,
138
+ const xmlChar * name,
139
+ const xmlChar *
140
+ namespaceURI,
141
+ const xmlChar *
142
+ content);
143
+
144
+ /*
145
+ * Text
146
+ */
147
+ XMLPUBFUN int
148
+ xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer,
149
+ const char *format, ...)
150
+ LIBXML_ATTR_FORMAT(2,3);
151
+ XMLPUBFUN int
152
+ xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer,
153
+ const char *format, va_list argptr)
154
+ LIBXML_ATTR_FORMAT(2,0);
155
+ XMLPUBFUN int
156
+ xmlTextWriterWriteRawLen(xmlTextWriterPtr writer,
157
+ const xmlChar * content, int len);
158
+ XMLPUBFUN int
159
+ xmlTextWriterWriteRaw(xmlTextWriterPtr writer,
160
+ const xmlChar * content);
161
+ XMLPUBFUN int xmlTextWriterWriteFormatString(xmlTextWriterPtr
162
+ writer,
163
+ const char
164
+ *format, ...)
165
+ LIBXML_ATTR_FORMAT(2,3);
166
+ XMLPUBFUN int xmlTextWriterWriteVFormatString(xmlTextWriterPtr
167
+ writer,
168
+ const char
169
+ *format,
170
+ va_list argptr)
171
+ LIBXML_ATTR_FORMAT(2,0);
172
+ XMLPUBFUN int xmlTextWriterWriteString(xmlTextWriterPtr writer,
173
+ const xmlChar *
174
+ content);
175
+ XMLPUBFUN int xmlTextWriterWriteBase64(xmlTextWriterPtr writer,
176
+ const char *data,
177
+ int start, int len);
178
+ XMLPUBFUN int xmlTextWriterWriteBinHex(xmlTextWriterPtr writer,
179
+ const char *data,
180
+ int start, int len);
181
+
182
+ /*
183
+ * Attributes
184
+ */
185
+ XMLPUBFUN int
186
+ xmlTextWriterStartAttribute(xmlTextWriterPtr writer,
187
+ const xmlChar * name);
188
+ XMLPUBFUN int xmlTextWriterStartAttributeNS(xmlTextWriterPtr
189
+ writer,
190
+ const xmlChar *
191
+ prefix,
192
+ const xmlChar *
193
+ name,
194
+ const xmlChar *
195
+ namespaceURI);
196
+ XMLPUBFUN int xmlTextWriterEndAttribute(xmlTextWriterPtr
197
+ writer);
198
+
199
+ /*
200
+ * Attributes conveniency functions
201
+ */
202
+ XMLPUBFUN int
203
+ xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
204
+ const xmlChar * name,
205
+ const char *format, ...)
206
+ LIBXML_ATTR_FORMAT(3,4);
207
+ XMLPUBFUN int
208
+ xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
209
+ const xmlChar * name,
210
+ const char *format,
211
+ va_list argptr)
212
+ LIBXML_ATTR_FORMAT(3,0);
213
+ XMLPUBFUN int xmlTextWriterWriteAttribute(xmlTextWriterPtr
214
+ writer,
215
+ const xmlChar * name,
216
+ const xmlChar *
217
+ content);
218
+ XMLPUBFUN int
219
+ xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer,
220
+ const xmlChar * prefix,
221
+ const xmlChar * name,
222
+ const xmlChar * namespaceURI,
223
+ const char *format, ...)
224
+ LIBXML_ATTR_FORMAT(5,6);
225
+ XMLPUBFUN int
226
+ xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
227
+ const xmlChar * prefix,
228
+ const xmlChar * name,
229
+ const xmlChar * namespaceURI,
230
+ const char *format,
231
+ va_list argptr)
232
+ LIBXML_ATTR_FORMAT(5,0);
233
+ XMLPUBFUN int xmlTextWriterWriteAttributeNS(xmlTextWriterPtr
234
+ writer,
235
+ const xmlChar *
236
+ prefix,
237
+ const xmlChar *
238
+ name,
239
+ const xmlChar *
240
+ namespaceURI,
241
+ const xmlChar *
242
+ content);
243
+
244
+ /*
245
+ * PI's
246
+ */
247
+ XMLPUBFUN int
248
+ xmlTextWriterStartPI(xmlTextWriterPtr writer,
249
+ const xmlChar * target);
250
+ XMLPUBFUN int xmlTextWriterEndPI(xmlTextWriterPtr writer);
251
+
252
+ /*
253
+ * PI conveniency functions
254
+ */
255
+ XMLPUBFUN int
256
+ xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer,
257
+ const xmlChar * target,
258
+ const char *format, ...)
259
+ LIBXML_ATTR_FORMAT(3,4);
260
+ XMLPUBFUN int
261
+ xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
262
+ const xmlChar * target,
263
+ const char *format, va_list argptr)
264
+ LIBXML_ATTR_FORMAT(3,0);
265
+ XMLPUBFUN int
266
+ xmlTextWriterWritePI(xmlTextWriterPtr writer,
267
+ const xmlChar * target,
268
+ const xmlChar * content);
269
+
270
+ /**
271
+ * xmlTextWriterWriteProcessingInstruction:
272
+ *
273
+ * This macro maps to xmlTextWriterWritePI
274
+ */
275
+ #define xmlTextWriterWriteProcessingInstruction xmlTextWriterWritePI
276
+
277
+ /*
278
+ * CDATA
279
+ */
280
+ XMLPUBFUN int xmlTextWriterStartCDATA(xmlTextWriterPtr writer);
281
+ XMLPUBFUN int xmlTextWriterEndCDATA(xmlTextWriterPtr writer);
282
+
283
+ /*
284
+ * CDATA conveniency functions
285
+ */
286
+ XMLPUBFUN int
287
+ xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer,
288
+ const char *format, ...)
289
+ LIBXML_ATTR_FORMAT(2,3);
290
+ XMLPUBFUN int
291
+ xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer,
292
+ const char *format, va_list argptr)
293
+ LIBXML_ATTR_FORMAT(2,0);
294
+ XMLPUBFUN int
295
+ xmlTextWriterWriteCDATA(xmlTextWriterPtr writer,
296
+ const xmlChar * content);
297
+
298
+ /*
299
+ * DTD
300
+ */
301
+ XMLPUBFUN int
302
+ xmlTextWriterStartDTD(xmlTextWriterPtr writer,
303
+ const xmlChar * name,
304
+ const xmlChar * pubid,
305
+ const xmlChar * sysid);
306
+ XMLPUBFUN int xmlTextWriterEndDTD(xmlTextWriterPtr writer);
307
+
308
+ /*
309
+ * DTD conveniency functions
310
+ */
311
+ XMLPUBFUN int
312
+ xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer,
313
+ const xmlChar * name,
314
+ const xmlChar * pubid,
315
+ const xmlChar * sysid,
316
+ const char *format, ...)
317
+ LIBXML_ATTR_FORMAT(5,6);
318
+ XMLPUBFUN int
319
+ xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
320
+ const xmlChar * name,
321
+ const xmlChar * pubid,
322
+ const xmlChar * sysid,
323
+ const char *format, va_list argptr)
324
+ LIBXML_ATTR_FORMAT(5,0);
325
+ XMLPUBFUN int
326
+ xmlTextWriterWriteDTD(xmlTextWriterPtr writer,
327
+ const xmlChar * name,
328
+ const xmlChar * pubid,
329
+ const xmlChar * sysid,
330
+ const xmlChar * subset);
331
+
332
+ /**
333
+ * xmlTextWriterWriteDocType:
334
+ *
335
+ * this macro maps to xmlTextWriterWriteDTD
336
+ */
337
+ #define xmlTextWriterWriteDocType xmlTextWriterWriteDTD
338
+
339
+ /*
340
+ * DTD element definition
341
+ */
342
+ XMLPUBFUN int
343
+ xmlTextWriterStartDTDElement(xmlTextWriterPtr writer,
344
+ const xmlChar * name);
345
+ XMLPUBFUN int xmlTextWriterEndDTDElement(xmlTextWriterPtr
346
+ writer);
347
+
348
+ /*
349
+ * DTD element definition conveniency functions
350
+ */
351
+ XMLPUBFUN int
352
+ xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
353
+ const xmlChar * name,
354
+ const char *format, ...)
355
+ LIBXML_ATTR_FORMAT(3,4);
356
+ XMLPUBFUN int
357
+ xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
358
+ const xmlChar * name,
359
+ const char *format,
360
+ va_list argptr)
361
+ LIBXML_ATTR_FORMAT(3,0);
362
+ XMLPUBFUN int xmlTextWriterWriteDTDElement(xmlTextWriterPtr
363
+ writer,
364
+ const xmlChar *
365
+ name,
366
+ const xmlChar *
367
+ content);
368
+
369
+ /*
370
+ * DTD attribute list definition
371
+ */
372
+ XMLPUBFUN int
373
+ xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer,
374
+ const xmlChar * name);
375
+ XMLPUBFUN int xmlTextWriterEndDTDAttlist(xmlTextWriterPtr
376
+ writer);
377
+
378
+ /*
379
+ * DTD attribute list definition conveniency functions
380
+ */
381
+ XMLPUBFUN int
382
+ xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
383
+ const xmlChar * name,
384
+ const char *format, ...)
385
+ LIBXML_ATTR_FORMAT(3,4);
386
+ XMLPUBFUN int
387
+ xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
388
+ const xmlChar * name,
389
+ const char *format,
390
+ va_list argptr)
391
+ LIBXML_ATTR_FORMAT(3,0);
392
+ XMLPUBFUN int xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr
393
+ writer,
394
+ const xmlChar *
395
+ name,
396
+ const xmlChar *
397
+ content);
398
+
399
+ /*
400
+ * DTD entity definition
401
+ */
402
+ XMLPUBFUN int
403
+ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
404
+ int pe, const xmlChar * name);
405
+ XMLPUBFUN int xmlTextWriterEndDTDEntity(xmlTextWriterPtr
406
+ writer);
407
+
408
+ /*
409
+ * DTD entity definition conveniency functions
410
+ */
411
+ XMLPUBFUN int
412
+ xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
413
+ int pe,
414
+ const xmlChar * name,
415
+ const char *format, ...)
416
+ LIBXML_ATTR_FORMAT(4,5);
417
+ XMLPUBFUN int
418
+ xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
419
+ int pe,
420
+ const xmlChar * name,
421
+ const char *format,
422
+ va_list argptr)
423
+ LIBXML_ATTR_FORMAT(4,0);
424
+ XMLPUBFUN int
425
+ xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
426
+ int pe,
427
+ const xmlChar * name,
428
+ const xmlChar * content);
429
+ XMLPUBFUN int
430
+ xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer,
431
+ int pe,
432
+ const xmlChar * name,
433
+ const xmlChar * pubid,
434
+ const xmlChar * sysid,
435
+ const xmlChar * ndataid);
436
+ XMLPUBFUN int
437
+ xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr
438
+ writer,
439
+ const xmlChar * pubid,
440
+ const xmlChar * sysid,
441
+ const xmlChar *
442
+ ndataid);
443
+ XMLPUBFUN int xmlTextWriterWriteDTDEntity(xmlTextWriterPtr
444
+ writer, int pe,
445
+ const xmlChar * name,
446
+ const xmlChar *
447
+ pubid,
448
+ const xmlChar *
449
+ sysid,
450
+ const xmlChar *
451
+ ndataid,
452
+ const xmlChar *
453
+ content);
454
+
455
+ /*
456
+ * DTD notation definition
457
+ */
458
+ XMLPUBFUN int
459
+ xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer,
460
+ const xmlChar * name,
461
+ const xmlChar * pubid,
462
+ const xmlChar * sysid);
463
+
464
+ /*
465
+ * Indentation
466
+ */
467
+ XMLPUBFUN int
468
+ xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent);
469
+ XMLPUBFUN int
470
+ xmlTextWriterSetIndentString(xmlTextWriterPtr writer,
471
+ const xmlChar * str);
472
+
473
+ XMLPUBFUN int
474
+ xmlTextWriterSetQuoteChar(xmlTextWriterPtr writer, xmlChar quotechar);
475
+
476
+
477
+ /*
478
+ * misc
479
+ */
480
+ XMLPUBFUN int xmlTextWriterFlush(xmlTextWriterPtr writer);
481
+
482
+ #ifdef __cplusplus
483
+ }
484
+ #endif
485
+
486
+ #endif /* LIBXML_WRITER_ENABLED */
487
+
488
+ #endif /* __XML_XMLWRITER_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/libxml/xpath.h ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: XML Path Language implementation
3
+ * Description: API for the XML Path Language implementation
4
+ *
5
+ * XML Path Language implementation
6
+ * XPath is a language for addressing parts of an XML document,
7
+ * designed to be used by both XSLT and XPointer
8
+ * http://www.w3.org/TR/xpath
9
+ *
10
+ * Implements
11
+ * W3C Recommendation 16 November 1999
12
+ * http://www.w3.org/TR/1999/REC-xpath-19991116
13
+ *
14
+ * Copy: See Copyright for the status of this software.
15
+ *
16
+ * Author: Daniel Veillard
17
+ */
18
+
19
+ #ifndef __XML_XPATH_H__
20
+ #define __XML_XPATH_H__
21
+
22
+ #include <libxml/xmlversion.h>
23
+
24
+ #ifdef LIBXML_XPATH_ENABLED
25
+
26
+ #include <libxml/xmlerror.h>
27
+ #include <libxml/tree.h>
28
+ #include <libxml/hash.h>
29
+ #endif /* LIBXML_XPATH_ENABLED */
30
+
31
+ #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
32
+ #ifdef __cplusplus
33
+ extern "C" {
34
+ #endif
35
+ #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */
36
+
37
+ #ifdef LIBXML_XPATH_ENABLED
38
+
39
+ typedef struct _xmlXPathContext xmlXPathContext;
40
+ typedef xmlXPathContext *xmlXPathContextPtr;
41
+ typedef struct _xmlXPathParserContext xmlXPathParserContext;
42
+ typedef xmlXPathParserContext *xmlXPathParserContextPtr;
43
+
44
+ /**
45
+ * The set of XPath error codes.
46
+ */
47
+
48
+ typedef enum {
49
+ XPATH_EXPRESSION_OK = 0,
50
+ XPATH_NUMBER_ERROR,
51
+ XPATH_UNFINISHED_LITERAL_ERROR,
52
+ XPATH_START_LITERAL_ERROR,
53
+ XPATH_VARIABLE_REF_ERROR,
54
+ XPATH_UNDEF_VARIABLE_ERROR,
55
+ XPATH_INVALID_PREDICATE_ERROR,
56
+ XPATH_EXPR_ERROR,
57
+ XPATH_UNCLOSED_ERROR,
58
+ XPATH_UNKNOWN_FUNC_ERROR,
59
+ XPATH_INVALID_OPERAND,
60
+ XPATH_INVALID_TYPE,
61
+ XPATH_INVALID_ARITY,
62
+ XPATH_INVALID_CTXT_SIZE,
63
+ XPATH_INVALID_CTXT_POSITION,
64
+ XPATH_MEMORY_ERROR,
65
+ XPTR_SYNTAX_ERROR,
66
+ XPTR_RESOURCE_ERROR,
67
+ XPTR_SUB_RESOURCE_ERROR,
68
+ XPATH_UNDEF_PREFIX_ERROR,
69
+ XPATH_ENCODING_ERROR,
70
+ XPATH_INVALID_CHAR_ERROR,
71
+ XPATH_INVALID_CTXT,
72
+ XPATH_STACK_ERROR,
73
+ XPATH_FORBID_VARIABLE_ERROR,
74
+ XPATH_OP_LIMIT_EXCEEDED,
75
+ XPATH_RECURSION_LIMIT_EXCEEDED
76
+ } xmlXPathError;
77
+
78
+ /*
79
+ * A node-set (an unordered collection of nodes without duplicates).
80
+ */
81
+ typedef struct _xmlNodeSet xmlNodeSet;
82
+ typedef xmlNodeSet *xmlNodeSetPtr;
83
+ struct _xmlNodeSet {
84
+ int nodeNr; /* number of nodes in the set */
85
+ int nodeMax; /* size of the array as allocated */
86
+ xmlNodePtr *nodeTab; /* array of nodes in no particular order */
87
+ /* @@ with_ns to check whether namespace nodes should be looked at @@ */
88
+ };
89
+
90
+ /*
91
+ * An expression is evaluated to yield an object, which
92
+ * has one of the following four basic types:
93
+ * - node-set
94
+ * - boolean
95
+ * - number
96
+ * - string
97
+ *
98
+ * @@ XPointer will add more types !
99
+ */
100
+
101
+ typedef enum {
102
+ XPATH_UNDEFINED = 0,
103
+ XPATH_NODESET = 1,
104
+ XPATH_BOOLEAN = 2,
105
+ XPATH_NUMBER = 3,
106
+ XPATH_STRING = 4,
107
+ #ifdef LIBXML_XPTR_LOCS_ENABLED
108
+ XPATH_POINT = 5,
109
+ XPATH_RANGE = 6,
110
+ XPATH_LOCATIONSET = 7,
111
+ #endif
112
+ XPATH_USERS = 8,
113
+ XPATH_XSLT_TREE = 9 /* An XSLT value tree, non modifiable */
114
+ } xmlXPathObjectType;
115
+
116
+ #ifndef LIBXML_XPTR_LOCS_ENABLED
117
+ /** DOC_DISABLE */
118
+ #define XPATH_POINT 5
119
+ #define XPATH_RANGE 6
120
+ #define XPATH_LOCATIONSET 7
121
+ /** DOC_ENABLE */
122
+ #endif
123
+
124
+ typedef struct _xmlXPathObject xmlXPathObject;
125
+ typedef xmlXPathObject *xmlXPathObjectPtr;
126
+ struct _xmlXPathObject {
127
+ xmlXPathObjectType type;
128
+ xmlNodeSetPtr nodesetval;
129
+ int boolval;
130
+ double floatval;
131
+ xmlChar *stringval;
132
+ void *user;
133
+ int index;
134
+ void *user2;
135
+ int index2;
136
+ };
137
+
138
+ /**
139
+ * xmlXPathConvertFunc:
140
+ * @obj: an XPath object
141
+ * @type: the number of the target type
142
+ *
143
+ * A conversion function is associated to a type and used to cast
144
+ * the new type to primitive values.
145
+ *
146
+ * Returns -1 in case of error, 0 otherwise
147
+ */
148
+ typedef int (*xmlXPathConvertFunc) (xmlXPathObjectPtr obj, int type);
149
+
150
+ /*
151
+ * Extra type: a name and a conversion function.
152
+ */
153
+
154
+ typedef struct _xmlXPathType xmlXPathType;
155
+ typedef xmlXPathType *xmlXPathTypePtr;
156
+ struct _xmlXPathType {
157
+ const xmlChar *name; /* the type name */
158
+ xmlXPathConvertFunc func; /* the conversion function */
159
+ };
160
+
161
+ /*
162
+ * Extra variable: a name and a value.
163
+ */
164
+
165
+ typedef struct _xmlXPathVariable xmlXPathVariable;
166
+ typedef xmlXPathVariable *xmlXPathVariablePtr;
167
+ struct _xmlXPathVariable {
168
+ const xmlChar *name; /* the variable name */
169
+ xmlXPathObjectPtr value; /* the value */
170
+ };
171
+
172
+ /**
173
+ * xmlXPathEvalFunc:
174
+ * @ctxt: an XPath parser context
175
+ * @nargs: the number of arguments passed to the function
176
+ *
177
+ * An XPath evaluation function, the parameters are on the XPath context stack.
178
+ */
179
+
180
+ typedef void (*xmlXPathEvalFunc)(xmlXPathParserContextPtr ctxt,
181
+ int nargs);
182
+
183
+ /*
184
+ * Extra function: a name and a evaluation function.
185
+ */
186
+
187
+ typedef struct _xmlXPathFunct xmlXPathFunct;
188
+ typedef xmlXPathFunct *xmlXPathFuncPtr;
189
+ struct _xmlXPathFunct {
190
+ const xmlChar *name; /* the function name */
191
+ xmlXPathEvalFunc func; /* the evaluation function */
192
+ };
193
+
194
+ /**
195
+ * xmlXPathAxisFunc:
196
+ * @ctxt: the XPath interpreter context
197
+ * @cur: the previous node being explored on that axis
198
+ *
199
+ * An axis traversal function. To traverse an axis, the engine calls
200
+ * the first time with cur == NULL and repeat until the function returns
201
+ * NULL indicating the end of the axis traversal.
202
+ *
203
+ * Returns the next node in that axis or NULL if at the end of the axis.
204
+ */
205
+
206
+ typedef xmlXPathObjectPtr (*xmlXPathAxisFunc) (xmlXPathParserContextPtr ctxt,
207
+ xmlXPathObjectPtr cur);
208
+
209
+ /*
210
+ * Extra axis: a name and an axis function.
211
+ */
212
+
213
+ typedef struct _xmlXPathAxis xmlXPathAxis;
214
+ typedef xmlXPathAxis *xmlXPathAxisPtr;
215
+ struct _xmlXPathAxis {
216
+ const xmlChar *name; /* the axis name */
217
+ xmlXPathAxisFunc func; /* the search function */
218
+ };
219
+
220
+ /**
221
+ * xmlXPathFunction:
222
+ * @ctxt: the XPath interprestation context
223
+ * @nargs: the number of arguments
224
+ *
225
+ * An XPath function.
226
+ * The arguments (if any) are popped out from the context stack
227
+ * and the result is pushed on the stack.
228
+ */
229
+
230
+ typedef void (*xmlXPathFunction) (xmlXPathParserContextPtr ctxt, int nargs);
231
+
232
+ /*
233
+ * Function and Variable Lookup.
234
+ */
235
+
236
+ /**
237
+ * xmlXPathVariableLookupFunc:
238
+ * @ctxt: an XPath context
239
+ * @name: name of the variable
240
+ * @ns_uri: the namespace name hosting this variable
241
+ *
242
+ * Prototype for callbacks used to plug variable lookup in the XPath
243
+ * engine.
244
+ *
245
+ * Returns the XPath object value or NULL if not found.
246
+ */
247
+ typedef xmlXPathObjectPtr (*xmlXPathVariableLookupFunc) (void *ctxt,
248
+ const xmlChar *name,
249
+ const xmlChar *ns_uri);
250
+
251
+ /**
252
+ * xmlXPathFuncLookupFunc:
253
+ * @ctxt: an XPath context
254
+ * @name: name of the function
255
+ * @ns_uri: the namespace name hosting this function
256
+ *
257
+ * Prototype for callbacks used to plug function lookup in the XPath
258
+ * engine.
259
+ *
260
+ * Returns the XPath function or NULL if not found.
261
+ */
262
+ typedef xmlXPathFunction (*xmlXPathFuncLookupFunc) (void *ctxt,
263
+ const xmlChar *name,
264
+ const xmlChar *ns_uri);
265
+
266
+ /**
267
+ * xmlXPathFlags:
268
+ * Flags for XPath engine compilation and runtime
269
+ */
270
+ /**
271
+ * XML_XPATH_CHECKNS:
272
+ *
273
+ * check namespaces at compilation
274
+ */
275
+ #define XML_XPATH_CHECKNS (1<<0)
276
+ /**
277
+ * XML_XPATH_NOVAR:
278
+ *
279
+ * forbid variables in expression
280
+ */
281
+ #define XML_XPATH_NOVAR (1<<1)
282
+
283
+ /**
284
+ * xmlXPathContext:
285
+ *
286
+ * Expression evaluation occurs with respect to a context.
287
+ * he context consists of:
288
+ * - a node (the context node)
289
+ * - a node list (the context node list)
290
+ * - a set of variable bindings
291
+ * - a function library
292
+ * - the set of namespace declarations in scope for the expression
293
+ * Following the switch to hash tables, this need to be trimmed up at
294
+ * the next binary incompatible release.
295
+ * The node may be modified when the context is passed to libxml2
296
+ * for an XPath evaluation so you may need to initialize it again
297
+ * before the next call.
298
+ */
299
+
300
+ struct _xmlXPathContext {
301
+ xmlDocPtr doc; /* The current document */
302
+ xmlNodePtr node; /* The current node */
303
+
304
+ int nb_variables_unused; /* unused (hash table) */
305
+ int max_variables_unused; /* unused (hash table) */
306
+ xmlHashTablePtr varHash; /* Hash table of defined variables */
307
+
308
+ int nb_types; /* number of defined types */
309
+ int max_types; /* max number of types */
310
+ xmlXPathTypePtr types; /* Array of defined types */
311
+
312
+ int nb_funcs_unused; /* unused (hash table) */
313
+ int max_funcs_unused; /* unused (hash table) */
314
+ xmlHashTablePtr funcHash; /* Hash table of defined funcs */
315
+
316
+ int nb_axis; /* number of defined axis */
317
+ int max_axis; /* max number of axis */
318
+ xmlXPathAxisPtr axis; /* Array of defined axis */
319
+
320
+ /* the namespace nodes of the context node */
321
+ xmlNsPtr *namespaces; /* Array of namespaces */
322
+ int nsNr; /* number of namespace in scope */
323
+ void *user; /* function to free */
324
+
325
+ /* extra variables */
326
+ int contextSize; /* the context size */
327
+ int proximityPosition; /* the proximity position */
328
+
329
+ /* extra stuff for XPointer */
330
+ int xptr; /* is this an XPointer context? */
331
+ xmlNodePtr here; /* for here() */
332
+ xmlNodePtr origin; /* for origin() */
333
+
334
+ /* the set of namespace declarations in scope for the expression */
335
+ xmlHashTablePtr nsHash; /* The namespaces hash table */
336
+ xmlXPathVariableLookupFunc varLookupFunc;/* variable lookup func */
337
+ void *varLookupData; /* variable lookup data */
338
+
339
+ /* Possibility to link in an extra item */
340
+ void *extra; /* needed for XSLT */
341
+
342
+ /* The function name and URI when calling a function */
343
+ const xmlChar *function;
344
+ const xmlChar *functionURI;
345
+
346
+ /* function lookup function and data */
347
+ xmlXPathFuncLookupFunc funcLookupFunc;/* function lookup func */
348
+ void *funcLookupData; /* function lookup data */
349
+
350
+ /* temporary namespace lists kept for walking the namespace axis */
351
+ xmlNsPtr *tmpNsList; /* Array of namespaces */
352
+ int tmpNsNr; /* number of namespaces in scope */
353
+
354
+ /* error reporting mechanism */
355
+ void *userData; /* user specific data block */
356
+ xmlStructuredErrorFunc error; /* the callback in case of errors */
357
+ xmlError lastError; /* the last error */
358
+ xmlNodePtr debugNode; /* the source node XSLT */
359
+
360
+ /* dictionary */
361
+ xmlDictPtr dict; /* dictionary if any */
362
+
363
+ int flags; /* flags to control compilation */
364
+
365
+ /* Cache for reusal of XPath objects */
366
+ void *cache;
367
+
368
+ /* Resource limits */
369
+ unsigned long opLimit;
370
+ unsigned long opCount;
371
+ int depth;
372
+ };
373
+
374
+ /*
375
+ * The structure of a compiled expression form is not public.
376
+ */
377
+
378
+ typedef struct _xmlXPathCompExpr xmlXPathCompExpr;
379
+ typedef xmlXPathCompExpr *xmlXPathCompExprPtr;
380
+
381
+ /**
382
+ * xmlXPathParserContext:
383
+ *
384
+ * An XPath parser context. It contains pure parsing information,
385
+ * an xmlXPathContext, and the stack of objects.
386
+ */
387
+ struct _xmlXPathParserContext {
388
+ const xmlChar *cur; /* the current char being parsed */
389
+ const xmlChar *base; /* the full expression */
390
+
391
+ int error; /* error code */
392
+
393
+ xmlXPathContextPtr context; /* the evaluation context */
394
+ xmlXPathObjectPtr value; /* the current value */
395
+ int valueNr; /* number of values stacked */
396
+ int valueMax; /* max number of values stacked */
397
+ xmlXPathObjectPtr *valueTab; /* stack of values */
398
+
399
+ xmlXPathCompExprPtr comp; /* the precompiled expression */
400
+ int xptr; /* it this an XPointer expression */
401
+ xmlNodePtr ancestor; /* used for walking preceding axis */
402
+
403
+ int valueFrame; /* always zero for compatibility */
404
+ };
405
+
406
+ /************************************************************************
407
+ * *
408
+ * Public API *
409
+ * *
410
+ ************************************************************************/
411
+
412
+ /**
413
+ * Objects and Nodesets handling
414
+ */
415
+
416
+ XMLPUBVAR double xmlXPathNAN;
417
+ XMLPUBVAR double xmlXPathPINF;
418
+ XMLPUBVAR double xmlXPathNINF;
419
+
420
+ /* These macros may later turn into functions */
421
+ /**
422
+ * xmlXPathNodeSetGetLength:
423
+ * @ns: a node-set
424
+ *
425
+ * Implement a functionality similar to the DOM NodeList.length.
426
+ *
427
+ * Returns the number of nodes in the node-set.
428
+ */
429
+ #define xmlXPathNodeSetGetLength(ns) ((ns) ? (ns)->nodeNr : 0)
430
+ /**
431
+ * xmlXPathNodeSetItem:
432
+ * @ns: a node-set
433
+ * @index: index of a node in the set
434
+ *
435
+ * Implements a functionality similar to the DOM NodeList.item().
436
+ *
437
+ * Returns the xmlNodePtr at the given @index in @ns or NULL if
438
+ * @index is out of range (0 to length-1)
439
+ */
440
+ #define xmlXPathNodeSetItem(ns, index) \
441
+ ((((ns) != NULL) && \
442
+ ((index) >= 0) && ((index) < (ns)->nodeNr)) ? \
443
+ (ns)->nodeTab[(index)] \
444
+ : NULL)
445
+ /**
446
+ * xmlXPathNodeSetIsEmpty:
447
+ * @ns: a node-set
448
+ *
449
+ * Checks whether @ns is empty or not.
450
+ *
451
+ * Returns %TRUE if @ns is an empty node-set.
452
+ */
453
+ #define xmlXPathNodeSetIsEmpty(ns) \
454
+ (((ns) == NULL) || ((ns)->nodeNr == 0) || ((ns)->nodeTab == NULL))
455
+
456
+
457
+ XMLPUBFUN void
458
+ xmlXPathFreeObject (xmlXPathObjectPtr obj);
459
+ XMLPUBFUN xmlNodeSetPtr
460
+ xmlXPathNodeSetCreate (xmlNodePtr val);
461
+ XMLPUBFUN void
462
+ xmlXPathFreeNodeSetList (xmlXPathObjectPtr obj);
463
+ XMLPUBFUN void
464
+ xmlXPathFreeNodeSet (xmlNodeSetPtr obj);
465
+ XMLPUBFUN xmlXPathObjectPtr
466
+ xmlXPathObjectCopy (xmlXPathObjectPtr val);
467
+ XMLPUBFUN int
468
+ xmlXPathCmpNodes (xmlNodePtr node1,
469
+ xmlNodePtr node2);
470
+ /**
471
+ * Conversion functions to basic types.
472
+ */
473
+ XMLPUBFUN int
474
+ xmlXPathCastNumberToBoolean (double val);
475
+ XMLPUBFUN int
476
+ xmlXPathCastStringToBoolean (const xmlChar * val);
477
+ XMLPUBFUN int
478
+ xmlXPathCastNodeSetToBoolean(xmlNodeSetPtr ns);
479
+ XMLPUBFUN int
480
+ xmlXPathCastToBoolean (xmlXPathObjectPtr val);
481
+
482
+ XMLPUBFUN double
483
+ xmlXPathCastBooleanToNumber (int val);
484
+ XMLPUBFUN double
485
+ xmlXPathCastStringToNumber (const xmlChar * val);
486
+ XMLPUBFUN double
487
+ xmlXPathCastNodeToNumber (xmlNodePtr node);
488
+ XMLPUBFUN double
489
+ xmlXPathCastNodeSetToNumber (xmlNodeSetPtr ns);
490
+ XMLPUBFUN double
491
+ xmlXPathCastToNumber (xmlXPathObjectPtr val);
492
+
493
+ XMLPUBFUN xmlChar *
494
+ xmlXPathCastBooleanToString (int val);
495
+ XMLPUBFUN xmlChar *
496
+ xmlXPathCastNumberToString (double val);
497
+ XMLPUBFUN xmlChar *
498
+ xmlXPathCastNodeToString (xmlNodePtr node);
499
+ XMLPUBFUN xmlChar *
500
+ xmlXPathCastNodeSetToString (xmlNodeSetPtr ns);
501
+ XMLPUBFUN xmlChar *
502
+ xmlXPathCastToString (xmlXPathObjectPtr val);
503
+
504
+ XMLPUBFUN xmlXPathObjectPtr
505
+ xmlXPathConvertBoolean (xmlXPathObjectPtr val);
506
+ XMLPUBFUN xmlXPathObjectPtr
507
+ xmlXPathConvertNumber (xmlXPathObjectPtr val);
508
+ XMLPUBFUN xmlXPathObjectPtr
509
+ xmlXPathConvertString (xmlXPathObjectPtr val);
510
+
511
+ /**
512
+ * Context handling.
513
+ */
514
+ XMLPUBFUN xmlXPathContextPtr
515
+ xmlXPathNewContext (xmlDocPtr doc);
516
+ XMLPUBFUN void
517
+ xmlXPathFreeContext (xmlXPathContextPtr ctxt);
518
+ XMLPUBFUN int
519
+ xmlXPathContextSetCache(xmlXPathContextPtr ctxt,
520
+ int active,
521
+ int value,
522
+ int options);
523
+ /**
524
+ * Evaluation functions.
525
+ */
526
+ XMLPUBFUN long
527
+ xmlXPathOrderDocElems (xmlDocPtr doc);
528
+ XMLPUBFUN int
529
+ xmlXPathSetContextNode (xmlNodePtr node,
530
+ xmlXPathContextPtr ctx);
531
+ XMLPUBFUN xmlXPathObjectPtr
532
+ xmlXPathNodeEval (xmlNodePtr node,
533
+ const xmlChar *str,
534
+ xmlXPathContextPtr ctx);
535
+ XMLPUBFUN xmlXPathObjectPtr
536
+ xmlXPathEval (const xmlChar *str,
537
+ xmlXPathContextPtr ctx);
538
+ XMLPUBFUN xmlXPathObjectPtr
539
+ xmlXPathEvalExpression (const xmlChar *str,
540
+ xmlXPathContextPtr ctxt);
541
+ XMLPUBFUN int
542
+ xmlXPathEvalPredicate (xmlXPathContextPtr ctxt,
543
+ xmlXPathObjectPtr res);
544
+ /**
545
+ * Separate compilation/evaluation entry points.
546
+ */
547
+ XMLPUBFUN xmlXPathCompExprPtr
548
+ xmlXPathCompile (const xmlChar *str);
549
+ XMLPUBFUN xmlXPathCompExprPtr
550
+ xmlXPathCtxtCompile (xmlXPathContextPtr ctxt,
551
+ const xmlChar *str);
552
+ XMLPUBFUN xmlXPathObjectPtr
553
+ xmlXPathCompiledEval (xmlXPathCompExprPtr comp,
554
+ xmlXPathContextPtr ctx);
555
+ XMLPUBFUN int
556
+ xmlXPathCompiledEvalToBoolean(xmlXPathCompExprPtr comp,
557
+ xmlXPathContextPtr ctxt);
558
+ XMLPUBFUN void
559
+ xmlXPathFreeCompExpr (xmlXPathCompExprPtr comp);
560
+ #endif /* LIBXML_XPATH_ENABLED */
561
+ #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
562
+ XML_DEPRECATED
563
+ XMLPUBFUN void
564
+ xmlXPathInit (void);
565
+ XMLPUBFUN int
566
+ xmlXPathIsNaN (double val);
567
+ XMLPUBFUN int
568
+ xmlXPathIsInf (double val);
569
+
570
+ #ifdef __cplusplus
571
+ }
572
+ #endif
573
+
574
+ #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED*/
575
+ #endif /* ! __XML_XPATH_H__ */
llava_video/lib/python3.10/site-packages/lxml/includes/lxml-version.h ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #ifndef LXML_VERSION_STRING
2
+ #define LXML_VERSION_STRING "5.3.1"
3
+ #endif
llava_video/lib/python3.10/site-packages/lxml/includes/relaxng.pxd ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes.tree cimport xmlDoc
2
+ from lxml.includes.xmlerror cimport xmlStructuredErrorFunc
3
+
4
+ cdef extern from "libxml/relaxng.h" nogil:
5
+ ctypedef struct xmlRelaxNG
6
+ ctypedef struct xmlRelaxNGParserCtxt
7
+
8
+ ctypedef struct xmlRelaxNGValidCtxt
9
+
10
+ ctypedef enum xmlRelaxNGValidErr:
11
+ XML_RELAXNG_OK = 0
12
+ XML_RELAXNG_ERR_MEMORY = 1
13
+ XML_RELAXNG_ERR_TYPE = 2
14
+ XML_RELAXNG_ERR_TYPEVAL = 3
15
+ XML_RELAXNG_ERR_DUPID = 4
16
+ XML_RELAXNG_ERR_TYPECMP = 5
17
+ XML_RELAXNG_ERR_NOSTATE = 6
18
+ XML_RELAXNG_ERR_NODEFINE = 7
19
+ XML_RELAXNG_ERR_LISTEXTRA = 8
20
+ XML_RELAXNG_ERR_LISTEMPTY = 9
21
+ XML_RELAXNG_ERR_INTERNODATA = 10
22
+ XML_RELAXNG_ERR_INTERSEQ = 11
23
+ XML_RELAXNG_ERR_INTEREXTRA = 12
24
+ XML_RELAXNG_ERR_ELEMNAME = 13
25
+ XML_RELAXNG_ERR_ATTRNAME = 14
26
+ XML_RELAXNG_ERR_ELEMNONS = 15
27
+ XML_RELAXNG_ERR_ATTRNONS = 16
28
+ XML_RELAXNG_ERR_ELEMWRONGNS = 17
29
+ XML_RELAXNG_ERR_ATTRWRONGNS = 18
30
+ XML_RELAXNG_ERR_ELEMEXTRANS = 19
31
+ XML_RELAXNG_ERR_ATTREXTRANS = 20
32
+ XML_RELAXNG_ERR_ELEMNOTEMPTY = 21
33
+ XML_RELAXNG_ERR_NOELEM = 22
34
+ XML_RELAXNG_ERR_NOTELEM = 23
35
+ XML_RELAXNG_ERR_ATTRVALID = 24
36
+ XML_RELAXNG_ERR_CONTENTVALID = 25
37
+ XML_RELAXNG_ERR_EXTRACONTENT = 26
38
+ XML_RELAXNG_ERR_INVALIDATTR = 27
39
+ XML_RELAXNG_ERR_DATAELEM = 28
40
+ XML_RELAXNG_ERR_VALELEM = 29
41
+ XML_RELAXNG_ERR_LISTELEM = 30
42
+ XML_RELAXNG_ERR_DATATYPE = 31
43
+ XML_RELAXNG_ERR_VALUE = 32
44
+ XML_RELAXNG_ERR_LIST = 33
45
+ XML_RELAXNG_ERR_NOGRAMMAR = 34
46
+ XML_RELAXNG_ERR_EXTRADATA = 35
47
+ XML_RELAXNG_ERR_LACKDATA = 36
48
+ XML_RELAXNG_ERR_INTERNAL = 37
49
+ XML_RELAXNG_ERR_ELEMWRONG = 38
50
+ XML_RELAXNG_ERR_TEXTWRONG = 39
51
+
52
+ cdef xmlRelaxNGValidCtxt* xmlRelaxNGNewValidCtxt(xmlRelaxNG* schema)
53
+ cdef int xmlRelaxNGValidateDoc(xmlRelaxNGValidCtxt* ctxt, xmlDoc* doc)
54
+ cdef xmlRelaxNG* xmlRelaxNGParse(xmlRelaxNGParserCtxt* ctxt)
55
+ cdef xmlRelaxNGParserCtxt* xmlRelaxNGNewParserCtxt(char* URL)
56
+ cdef xmlRelaxNGParserCtxt* xmlRelaxNGNewDocParserCtxt(xmlDoc* doc)
57
+ cdef void xmlRelaxNGFree(xmlRelaxNG* schema)
58
+ cdef void xmlRelaxNGFreeParserCtxt(xmlRelaxNGParserCtxt* ctxt)
59
+ cdef void xmlRelaxNGFreeValidCtxt(xmlRelaxNGValidCtxt* ctxt)
60
+
61
+ cdef void xmlRelaxNGSetValidStructuredErrors(
62
+ xmlRelaxNGValidCtxt* ctxt, xmlStructuredErrorFunc serror, void *ctx)
63
+ cdef void xmlRelaxNGSetParserStructuredErrors(
64
+ xmlRelaxNGParserCtxt* ctxt, xmlStructuredErrorFunc serror, void *ctx)
llava_video/lib/python3.10/site-packages/lxml/includes/schematron.pxd ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes cimport xmlerror
2
+ from lxml.includes.tree cimport xmlDoc
3
+
4
+ cdef extern from "libxml/schematron.h" nogil:
5
+ ctypedef struct xmlSchematron
6
+ ctypedef struct xmlSchematronParserCtxt
7
+ ctypedef struct xmlSchematronValidCtxt
8
+
9
+ ctypedef enum xmlSchematronValidOptions:
10
+ XML_SCHEMATRON_OUT_QUIET = 1 # quiet no report
11
+ XML_SCHEMATRON_OUT_TEXT = 2 # build a textual report
12
+ XML_SCHEMATRON_OUT_XML = 4 # output SVRL
13
+ XML_SCHEMATRON_OUT_ERROR = 8 # output via xmlStructuredErrorFunc
14
+ XML_SCHEMATRON_OUT_FILE = 256 # output to a file descriptor
15
+ XML_SCHEMATRON_OUT_BUFFER = 512 # output to a buffer
16
+ XML_SCHEMATRON_OUT_IO = 1024 # output to I/O mechanism
17
+
18
+ cdef xmlSchematronParserCtxt* xmlSchematronNewDocParserCtxt(
19
+ xmlDoc* doc)
20
+ cdef xmlSchematronParserCtxt* xmlSchematronNewParserCtxt(
21
+ char* filename) nogil
22
+ cdef xmlSchematronValidCtxt* xmlSchematronNewValidCtxt(
23
+ xmlSchematron* schema, int options)
24
+
25
+ cdef xmlSchematron* xmlSchematronParse(xmlSchematronParserCtxt* ctxt)
26
+ cdef int xmlSchematronValidateDoc(xmlSchematronValidCtxt* ctxt,
27
+ xmlDoc* instance)
28
+
29
+ cdef void xmlSchematronFreeParserCtxt(xmlSchematronParserCtxt* ctxt)
30
+ cdef void xmlSchematronFreeValidCtxt(xmlSchematronValidCtxt* ctxt)
31
+ cdef void xmlSchematronFree(xmlSchematron* schema)
32
+ cdef void xmlSchematronSetValidStructuredErrors(
33
+ xmlSchematronValidCtxt* ctxt,
34
+ xmlerror.xmlStructuredErrorFunc error_func, void *data)
llava_video/lib/python3.10/site-packages/lxml/includes/tree.pxd ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from libc cimport stdio
2
+ from libc.string cimport const_char, const_uchar
3
+
4
+ cdef extern from "lxml-version.h":
5
+ # deprecated declaration, use etreepublic.pxd instead
6
+ cdef char* LXML_VERSION_STRING
7
+
8
+ cdef extern from "libxml/xmlversion.h":
9
+ cdef const_char* xmlParserVersion
10
+ cdef int LIBXML_VERSION
11
+
12
+ cdef extern from "libxml/xmlstring.h" nogil:
13
+ ctypedef unsigned char xmlChar
14
+ ctypedef const xmlChar const_xmlChar "const xmlChar"
15
+ cdef int xmlStrlen(const_xmlChar* str)
16
+ cdef xmlChar* xmlStrdup(const_xmlChar* cur)
17
+ cdef int xmlStrncmp(const_xmlChar* str1, const_xmlChar* str2, int length)
18
+ cdef int xmlStrcmp(const_xmlChar* str1, const_xmlChar* str2)
19
+ cdef int xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2)
20
+ cdef const_xmlChar* xmlStrstr(const_xmlChar* str1, const_xmlChar* str2)
21
+ cdef const_xmlChar* xmlStrchr(const_xmlChar* str1, xmlChar ch)
22
+ cdef const_xmlChar* _xcstr "(const xmlChar*)PyBytes_AS_STRING" (object s)
23
+
24
+ cdef extern from "libxml/encoding.h" nogil:
25
+ ctypedef enum xmlCharEncoding:
26
+ XML_CHAR_ENCODING_ERROR = -1 # No char encoding detected
27
+ XML_CHAR_ENCODING_NONE = 0 # No char encoding detected
28
+ XML_CHAR_ENCODING_UTF8 = 1 # UTF-8
29
+ XML_CHAR_ENCODING_UTF16LE = 2 # UTF-16 little endian
30
+ XML_CHAR_ENCODING_UTF16BE = 3 # UTF-16 big endian
31
+ XML_CHAR_ENCODING_UCS4LE = 4 # UCS-4 little endian
32
+ XML_CHAR_ENCODING_UCS4BE = 5 # UCS-4 big endian
33
+ XML_CHAR_ENCODING_EBCDIC = 6 # EBCDIC uh!
34
+ XML_CHAR_ENCODING_UCS4_2143 = 7 # UCS-4 unusual ordering
35
+ XML_CHAR_ENCODING_UCS4_3412 = 8 # UCS-4 unusual ordering
36
+ XML_CHAR_ENCODING_UCS2 = 9 # UCS-2
37
+ XML_CHAR_ENCODING_8859_1 = 10 # ISO-8859-1 ISO Latin 1
38
+ XML_CHAR_ENCODING_8859_2 = 11 # ISO-8859-2 ISO Latin 2
39
+ XML_CHAR_ENCODING_8859_3 = 12 # ISO-8859-3
40
+ XML_CHAR_ENCODING_8859_4 = 13 # ISO-8859-4
41
+ XML_CHAR_ENCODING_8859_5 = 14 # ISO-8859-5
42
+ XML_CHAR_ENCODING_8859_6 = 15 # ISO-8859-6
43
+ XML_CHAR_ENCODING_8859_7 = 16 # ISO-8859-7
44
+ XML_CHAR_ENCODING_8859_8 = 17 # ISO-8859-8
45
+ XML_CHAR_ENCODING_8859_9 = 18 # ISO-8859-9
46
+ XML_CHAR_ENCODING_2022_JP = 19 # ISO-2022-JP
47
+ XML_CHAR_ENCODING_SHIFT_JIS = 20 # Shift_JIS
48
+ XML_CHAR_ENCODING_EUC_JP = 21 # EUC-JP
49
+ XML_CHAR_ENCODING_ASCII = 22 # pure ASCII
50
+
51
+ ctypedef struct xmlCharEncodingHandler:
52
+ char* name
53
+
54
+ cdef xmlCharEncodingHandler* xmlFindCharEncodingHandler(char* name)
55
+ cdef xmlCharEncodingHandler* xmlGetCharEncodingHandler(
56
+ xmlCharEncoding enc)
57
+ cdef int xmlCharEncCloseFunc(xmlCharEncodingHandler* handler)
58
+ cdef xmlCharEncoding xmlDetectCharEncoding(const_xmlChar* text, int len)
59
+ cdef const_char* xmlGetCharEncodingName(xmlCharEncoding enc)
60
+ cdef xmlCharEncoding xmlParseCharEncoding(char* name)
61
+ ctypedef int (*xmlCharEncodingOutputFunc)(
62
+ unsigned char *out_buf, int *outlen, const_uchar *in_buf, int *inlen)
63
+
64
+ cdef extern from "libxml/chvalid.h" nogil:
65
+ cdef int xmlIsChar_ch(char c)
66
+ cdef int xmlIsCharQ(int ch)
67
+
68
+ cdef extern from "libxml/hash.h":
69
+ ctypedef struct xmlHashTable
70
+ ctypedef void (*xmlHashScanner)(void* payload, void* data, const_xmlChar* name) noexcept # may require GIL!
71
+ void xmlHashScan(xmlHashTable* table, xmlHashScanner f, void* data) nogil
72
+ void* xmlHashLookup(xmlHashTable* table, const_xmlChar* name) nogil
73
+ ctypedef void (*xmlHashDeallocator)(void *payload, xmlChar *name) noexcept
74
+ cdef xmlHashTable* xmlHashCreate(int size) nogil
75
+ cdef xmlHashTable* xmlHashCreateDict(int size, xmlDict *dict) nogil
76
+ cdef int xmlHashSize(xmlHashTable* table) nogil
77
+ cdef void xmlHashFree(xmlHashTable* table, xmlHashDeallocator f) nogil
78
+
79
+ cdef extern from * nogil: # actually "libxml/dict.h"
80
+ # libxml/dict.h appears to be broken to include in C
81
+ ctypedef struct xmlDict
82
+ cdef const_xmlChar* xmlDictLookup(xmlDict* dict, const_xmlChar* name, int len)
83
+ cdef const_xmlChar* xmlDictExists(xmlDict* dict, const_xmlChar* name, int len)
84
+ cdef int xmlDictOwns(xmlDict* dict, const_xmlChar* name)
85
+ cdef size_t xmlDictSize(xmlDict* dict)
86
+
87
+ cdef extern from "libxml/tree.h" nogil:
88
+ ctypedef struct xmlDoc
89
+ ctypedef struct xmlAttr
90
+ ctypedef struct xmlNotationTable
91
+
92
+ ctypedef enum xmlElementType:
93
+ XML_ELEMENT_NODE= 1
94
+ XML_ATTRIBUTE_NODE= 2
95
+ XML_TEXT_NODE= 3
96
+ XML_CDATA_SECTION_NODE= 4
97
+ XML_ENTITY_REF_NODE= 5
98
+ XML_ENTITY_NODE= 6
99
+ XML_PI_NODE= 7
100
+ XML_COMMENT_NODE= 8
101
+ XML_DOCUMENT_NODE= 9
102
+ XML_DOCUMENT_TYPE_NODE= 10
103
+ XML_DOCUMENT_FRAG_NODE= 11
104
+ XML_NOTATION_NODE= 12
105
+ XML_HTML_DOCUMENT_NODE= 13
106
+ XML_DTD_NODE= 14
107
+ XML_ELEMENT_DECL= 15
108
+ XML_ATTRIBUTE_DECL= 16
109
+ XML_ENTITY_DECL= 17
110
+ XML_NAMESPACE_DECL= 18
111
+ XML_XINCLUDE_START= 19
112
+ XML_XINCLUDE_END= 20
113
+
114
+ ctypedef enum xmlElementTypeVal:
115
+ XML_ELEMENT_TYPE_UNDEFINED= 0
116
+ XML_ELEMENT_TYPE_EMPTY= 1
117
+ XML_ELEMENT_TYPE_ANY= 2
118
+ XML_ELEMENT_TYPE_MIXED= 3
119
+ XML_ELEMENT_TYPE_ELEMENT= 4
120
+
121
+ ctypedef enum xmlElementContentType:
122
+ XML_ELEMENT_CONTENT_PCDATA= 1
123
+ XML_ELEMENT_CONTENT_ELEMENT= 2
124
+ XML_ELEMENT_CONTENT_SEQ= 3
125
+ XML_ELEMENT_CONTENT_OR= 4
126
+
127
+ ctypedef enum xmlElementContentOccur:
128
+ XML_ELEMENT_CONTENT_ONCE= 1
129
+ XML_ELEMENT_CONTENT_OPT= 2
130
+ XML_ELEMENT_CONTENT_MULT= 3
131
+ XML_ELEMENT_CONTENT_PLUS= 4
132
+
133
+ ctypedef enum xmlAttributeType:
134
+ XML_ATTRIBUTE_CDATA = 1
135
+ XML_ATTRIBUTE_ID= 2
136
+ XML_ATTRIBUTE_IDREF= 3
137
+ XML_ATTRIBUTE_IDREFS= 4
138
+ XML_ATTRIBUTE_ENTITY= 5
139
+ XML_ATTRIBUTE_ENTITIES= 6
140
+ XML_ATTRIBUTE_NMTOKEN= 7
141
+ XML_ATTRIBUTE_NMTOKENS= 8
142
+ XML_ATTRIBUTE_ENUMERATION= 9
143
+ XML_ATTRIBUTE_NOTATION= 10
144
+
145
+ ctypedef enum xmlAttributeDefault:
146
+ XML_ATTRIBUTE_NONE= 1
147
+ XML_ATTRIBUTE_REQUIRED= 2
148
+ XML_ATTRIBUTE_IMPLIED= 3
149
+ XML_ATTRIBUTE_FIXED= 4
150
+
151
+ ctypedef enum xmlEntityType:
152
+ XML_INTERNAL_GENERAL_ENTITY= 1
153
+ XML_EXTERNAL_GENERAL_PARSED_ENTITY= 2
154
+ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY= 3
155
+ XML_INTERNAL_PARAMETER_ENTITY= 4
156
+ XML_EXTERNAL_PARAMETER_ENTITY= 5
157
+ XML_INTERNAL_PREDEFINED_ENTITY= 6
158
+
159
+ ctypedef enum xmlDocProperties:
160
+ XML_DOC_WELLFORMED = 1 # /* document is XML well formed */
161
+ XML_DOC_NSVALID = 2 # /* document is Namespace valid */
162
+ XML_DOC_OLD10 = 4 # /* parsed with old XML-1.0 parser */
163
+ XML_DOC_DTDVALID = 8 # /* DTD validation was successful */
164
+ XML_DOC_XINCLUDE = 16 # /* XInclude substitution was done */
165
+ XML_DOC_USERBUILT = 32 # /* Document was built using the API
166
+ # and not by parsing an instance */
167
+ XML_DOC_INTERNAL = 64 # /* built for internal processing */
168
+ XML_DOC_HTML = 128 # /* parsed or built HTML document */
169
+
170
+ ctypedef struct xmlNs:
171
+ const_xmlChar* href
172
+ const_xmlChar* prefix
173
+ xmlNs* next
174
+
175
+ ctypedef struct xmlNode:
176
+ void* _private
177
+ xmlElementType type
178
+ const_xmlChar* name
179
+ xmlNode* children
180
+ xmlNode* last
181
+ xmlNode* parent
182
+ xmlNode* next
183
+ xmlNode* prev
184
+ xmlDoc* doc
185
+ xmlChar* content
186
+ xmlAttr* properties
187
+ xmlNs* ns
188
+ xmlNs* nsDef
189
+ unsigned short line
190
+
191
+ ctypedef struct xmlElementContent:
192
+ xmlElementContentType type
193
+ xmlElementContentOccur ocur
194
+ const_xmlChar *name
195
+ xmlElementContent *c1
196
+ xmlElementContent *c2
197
+ xmlElementContent *parent
198
+ const_xmlChar *prefix
199
+
200
+ ctypedef struct xmlEnumeration:
201
+ xmlEnumeration *next
202
+ const_xmlChar *name
203
+
204
+ ctypedef struct xmlAttribute:
205
+ void* _private
206
+ xmlElementType type
207
+ const_xmlChar* name
208
+ xmlNode* children
209
+ xmlNode* last
210
+ xmlDtd* parent
211
+ xmlNode* next
212
+ xmlNode* prev
213
+ xmlDoc* doc
214
+ xmlAttribute* nexth
215
+ xmlAttributeType atype
216
+ xmlAttributeDefault def_ "def"
217
+ const_xmlChar* defaultValue
218
+ xmlEnumeration* tree
219
+ const_xmlChar* prefix
220
+ const_xmlChar* elem
221
+
222
+ ctypedef struct xmlElement:
223
+ void* _private
224
+ xmlElementType type
225
+ const_xmlChar* name
226
+ xmlNode* children
227
+ xmlNode* last
228
+ xmlNode* parent
229
+ xmlNode* next
230
+ xmlNode* prev
231
+ xmlDoc* doc
232
+ xmlElementTypeVal etype
233
+ xmlElementContent* content
234
+ xmlAttribute* attributes
235
+ const_xmlChar* prefix
236
+ void *contModel
237
+
238
+ ctypedef struct xmlEntity:
239
+ void* _private
240
+ xmlElementType type
241
+ const_xmlChar* name
242
+ xmlNode* children
243
+ xmlNode* last
244
+ xmlDtd* parent
245
+ xmlNode* next
246
+ xmlNode* prev
247
+ xmlDoc* doc
248
+ xmlChar* orig
249
+ xmlChar* content
250
+ int length
251
+ xmlEntityType etype
252
+ const_xmlChar* ExternalID
253
+ const_xmlChar* SystemID
254
+ xmlEntity* nexte
255
+ const_xmlChar* URI
256
+ int owner
257
+ int checked
258
+
259
+ ctypedef struct xmlDtd:
260
+ const_xmlChar* name
261
+ const_xmlChar* ExternalID
262
+ const_xmlChar* SystemID
263
+ void* notations
264
+ void* entities
265
+ void* pentities
266
+ void* attributes
267
+ void* elements
268
+ xmlNode* children
269
+ xmlNode* last
270
+ xmlDoc* doc
271
+
272
+ ctypedef struct xmlDoc:
273
+ xmlElementType type
274
+ char* name
275
+ xmlNode* children
276
+ xmlNode* last
277
+ xmlNode* parent
278
+ xmlNode* next
279
+ xmlNode* prev
280
+ xmlDoc* doc
281
+ xmlDict* dict
282
+ xmlHashTable* ids
283
+ int standalone
284
+ const_xmlChar* version
285
+ const_xmlChar* encoding
286
+ const_xmlChar* URL
287
+ void* _private
288
+ xmlDtd* intSubset
289
+ xmlDtd* extSubset
290
+ int properties
291
+
292
+ ctypedef struct xmlAttr:
293
+ void* _private
294
+ xmlElementType type
295
+ const_xmlChar* name
296
+ xmlNode* children
297
+ xmlNode* last
298
+ xmlNode* parent
299
+ xmlAttr* next
300
+ xmlAttr* prev
301
+ xmlDoc* doc
302
+ xmlNs* ns
303
+ xmlAttributeType atype
304
+
305
+ ctypedef struct xmlID:
306
+ const_xmlChar* value
307
+ const_xmlChar* name
308
+ xmlAttr* attr
309
+ xmlDoc* doc
310
+
311
+ ctypedef struct xmlBuffer
312
+
313
+ ctypedef struct xmlBuf # new in libxml2 2.9
314
+
315
+ ctypedef struct xmlOutputBuffer:
316
+ xmlBuf* buffer
317
+ xmlBuf* conv
318
+ int error
319
+
320
+ const_xmlChar* XML_XML_NAMESPACE
321
+
322
+ cdef void xmlFreeDoc(xmlDoc* cur)
323
+ cdef void xmlFreeDtd(xmlDtd* cur)
324
+ cdef void xmlFreeNode(xmlNode* cur)
325
+ cdef void xmlFreeNsList(xmlNs* ns)
326
+ cdef void xmlFreeNs(xmlNs* ns)
327
+ cdef void xmlFree(void* buf)
328
+
329
+ cdef xmlNode* xmlNewNode(xmlNs* ns, const_xmlChar* name)
330
+ cdef xmlNode* xmlNewDocText(xmlDoc* doc, const_xmlChar* content)
331
+ cdef xmlNode* xmlNewDocComment(xmlDoc* doc, const_xmlChar* content)
332
+ cdef xmlNode* xmlNewDocPI(xmlDoc* doc, const_xmlChar* name, const_xmlChar* content)
333
+ cdef xmlNode* xmlNewReference(xmlDoc* doc, const_xmlChar* name)
334
+ cdef xmlNode* xmlNewCDataBlock(xmlDoc* doc, const_xmlChar* text, int len)
335
+ cdef xmlNs* xmlNewNs(xmlNode* node, const_xmlChar* href, const_xmlChar* prefix)
336
+ cdef xmlNode* xmlAddChild(xmlNode* parent, xmlNode* cur)
337
+ cdef xmlNode* xmlReplaceNode(xmlNode* old, xmlNode* cur)
338
+ cdef xmlNode* xmlAddPrevSibling(xmlNode* cur, xmlNode* elem)
339
+ cdef xmlNode* xmlAddNextSibling(xmlNode* cur, xmlNode* elem)
340
+ cdef xmlNode* xmlNewDocNode(xmlDoc* doc, xmlNs* ns,
341
+ const_xmlChar* name, const_xmlChar* content)
342
+ cdef xmlDoc* xmlNewDoc(const_xmlChar* version)
343
+ cdef xmlAttr* xmlNewProp(xmlNode* node, const_xmlChar* name, const_xmlChar* value)
344
+ cdef xmlAttr* xmlNewNsProp(xmlNode* node, xmlNs* ns,
345
+ const_xmlChar* name, const_xmlChar* value)
346
+ cdef xmlChar* xmlGetNoNsProp(xmlNode* node, const_xmlChar* name)
347
+ cdef xmlChar* xmlGetNsProp(xmlNode* node, const_xmlChar* name, const_xmlChar* nameSpace)
348
+ cdef void xmlSetNs(xmlNode* node, xmlNs* ns)
349
+ cdef xmlAttr* xmlSetProp(xmlNode* node, const_xmlChar* name, const_xmlChar* value)
350
+ cdef xmlAttr* xmlSetNsProp(xmlNode* node, xmlNs* ns,
351
+ const_xmlChar* name, const_xmlChar* value)
352
+ cdef int xmlRemoveID(xmlDoc* doc, xmlAttr* cur)
353
+ cdef int xmlRemoveProp(xmlAttr* cur)
354
+ cdef void xmlFreePropList(xmlAttr* cur)
355
+ cdef xmlChar* xmlGetNodePath(xmlNode* node)
356
+ cdef void xmlDocDumpMemory(xmlDoc* cur, char** mem, int* size)
357
+ cdef void xmlDocDumpMemoryEnc(xmlDoc* cur, char** mem, int* size,
358
+ char* encoding)
359
+ cdef int xmlSaveFileTo(xmlOutputBuffer* out, xmlDoc* cur,
360
+ char* encoding)
361
+
362
+ cdef void xmlUnlinkNode(xmlNode* cur)
363
+ cdef xmlNode* xmlDocSetRootElement(xmlDoc* doc, xmlNode* root)
364
+ cdef xmlNode* xmlDocGetRootElement(xmlDoc* doc)
365
+ cdef void xmlSetTreeDoc(xmlNode* tree, xmlDoc* doc)
366
+ cdef xmlAttr* xmlHasProp(xmlNode* node, const_xmlChar* name)
367
+ cdef xmlAttr* xmlHasNsProp(xmlNode* node, const_xmlChar* name, const_xmlChar* nameSpace)
368
+ cdef xmlChar* xmlNodeGetContent(xmlNode* cur)
369
+ cdef int xmlNodeBufGetContent(xmlBuffer* buffer, xmlNode* cur)
370
+ cdef xmlNs* xmlSearchNs(xmlDoc* doc, xmlNode* node, const_xmlChar* prefix)
371
+ cdef xmlNs* xmlSearchNsByHref(xmlDoc* doc, xmlNode* node, const_xmlChar* href)
372
+ cdef int xmlIsBlankNode(xmlNode* node)
373
+ cdef long xmlGetLineNo(xmlNode* node)
374
+ cdef void xmlElemDump(stdio.FILE* f, xmlDoc* doc, xmlNode* cur)
375
+ cdef void xmlNodeDumpOutput(xmlOutputBuffer* buf,
376
+ xmlDoc* doc, xmlNode* cur, int level,
377
+ int format, const_char* encoding)
378
+ cdef void xmlBufAttrSerializeTxtContent(xmlOutputBuffer *buf, xmlDoc *doc,
379
+ xmlAttr *attr, const_xmlChar *string)
380
+ cdef void xmlNodeSetName(xmlNode* cur, const_xmlChar* name)
381
+ cdef void xmlNodeSetContent(xmlNode* cur, const_xmlChar* content)
382
+ cdef xmlDtd* xmlCopyDtd(xmlDtd* dtd)
383
+ cdef xmlDoc* xmlCopyDoc(xmlDoc* doc, int recursive)
384
+ cdef xmlNode* xmlCopyNode(xmlNode* node, int extended)
385
+ cdef xmlNode* xmlDocCopyNode(xmlNode* node, xmlDoc* doc, int extended)
386
+ cdef int xmlReconciliateNs(xmlDoc* doc, xmlNode* tree)
387
+ cdef xmlNs* xmlNewReconciliedNs(xmlDoc* doc, xmlNode* tree, xmlNs* ns)
388
+ cdef xmlBuffer* xmlBufferCreate()
389
+ cdef void xmlBufferWriteChar(xmlBuffer* buf, char* string)
390
+ cdef void xmlBufferFree(xmlBuffer* buf)
391
+ cdef const_xmlChar* xmlBufferContent(xmlBuffer* buf)
392
+ cdef int xmlBufferLength(xmlBuffer* buf)
393
+ cdef const_xmlChar* xmlBufContent(xmlBuf* buf) # new in libxml2 2.9
394
+ cdef size_t xmlBufUse(xmlBuf* buf) # new in libxml2 2.9
395
+ cdef int xmlKeepBlanksDefault(int val)
396
+ cdef xmlChar* xmlNodeGetBase(xmlDoc* doc, xmlNode* node)
397
+ cdef xmlDtd* xmlCreateIntSubset(xmlDoc* doc, const_xmlChar* name,
398
+ const_xmlChar* ExternalID, const_xmlChar* SystemID)
399
+ cdef void xmlNodeSetBase(xmlNode* node, const_xmlChar* uri)
400
+ cdef int xmlValidateNCName(const_xmlChar* value, int space)
401
+
402
+ cdef extern from "libxml/uri.h" nogil:
403
+ cdef const_xmlChar* xmlBuildURI(const_xmlChar* href, const_xmlChar* base)
404
+
405
+ cdef extern from "libxml/HTMLtree.h" nogil:
406
+ cdef void htmlNodeDumpFormatOutput(xmlOutputBuffer* buf,
407
+ xmlDoc* doc, xmlNode* cur,
408
+ char* encoding, int format)
409
+ cdef xmlDoc* htmlNewDoc(const_xmlChar* uri, const_xmlChar* externalID)
410
+
411
+ cdef extern from "libxml/valid.h" nogil:
412
+ cdef xmlAttr* xmlGetID(xmlDoc* doc, const_xmlChar* ID)
413
+ cdef void xmlDumpNotationTable(xmlBuffer* buffer,
414
+ xmlNotationTable* table)
415
+ cdef int xmlValidateNameValue(const_xmlChar* value)
416
+
417
+ cdef extern from "libxml/xmlIO.h":
418
+ cdef int xmlOutputBufferWrite(xmlOutputBuffer* out,
419
+ int len, const_char* str) nogil
420
+ cdef int xmlOutputBufferWriteString(xmlOutputBuffer* out, const_char* str) nogil
421
+ cdef int xmlOutputBufferWriteEscape(xmlOutputBuffer* out,
422
+ const_xmlChar* str,
423
+ xmlCharEncodingOutputFunc escapefunc) nogil
424
+ cdef int xmlOutputBufferFlush(xmlOutputBuffer* out) nogil
425
+ cdef int xmlOutputBufferClose(xmlOutputBuffer* out) nogil
426
+
427
+ ctypedef int (*xmlInputReadCallback)(void* context,
428
+ char* buffer, int len) noexcept nogil
429
+ ctypedef int (*xmlInputCloseCallback)(void* context) noexcept nogil
430
+
431
+ ctypedef int (*xmlOutputWriteCallback)(void* context,
432
+ char* buffer, int len) noexcept
433
+ ctypedef int (*xmlOutputCloseCallback)(void* context) noexcept
434
+
435
+ cdef xmlOutputBuffer* xmlAllocOutputBuffer(
436
+ xmlCharEncodingHandler* encoder) nogil
437
+ cdef xmlOutputBuffer* xmlOutputBufferCreateIO(
438
+ xmlOutputWriteCallback iowrite,
439
+ xmlOutputCloseCallback ioclose,
440
+ void * ioctx,
441
+ xmlCharEncodingHandler* encoder) nogil
442
+ cdef xmlOutputBuffer* xmlOutputBufferCreateFile(
443
+ stdio.FILE* file, xmlCharEncodingHandler* encoder) nogil
444
+ cdef xmlOutputBuffer* xmlOutputBufferCreateFilename(
445
+ char* URI, xmlCharEncodingHandler* encoder, int compression) nogil
446
+
447
+ cdef extern from "libxml/xmlsave.h" nogil:
448
+ ctypedef struct xmlSaveCtxt
449
+
450
+ ctypedef enum xmlSaveOption:
451
+ XML_SAVE_FORMAT = 1 # format save output (2.6.17)
452
+ XML_SAVE_NO_DECL = 2 # drop the xml declaration (2.6.21)
453
+ XML_SAVE_NO_EMPTY = 4 # no empty tags (2.6.22)
454
+ XML_SAVE_NO_XHTML = 8 # disable XHTML1 specific rules (2.6.22)
455
+ XML_SAVE_XHTML = 16 # force XHTML1 specific rules (2.7.2)
456
+ XML_SAVE_AS_XML = 32 # force XML serialization on HTML doc (2.7.2)
457
+ XML_SAVE_AS_HTML = 64 # force HTML serialization on XML doc (2.7.2)
458
+
459
+ cdef xmlSaveCtxt* xmlSaveToFilename(char* filename, char* encoding,
460
+ int options)
461
+ cdef xmlSaveCtxt* xmlSaveToBuffer(xmlBuffer* buffer, char* encoding,
462
+ int options) # libxml2 2.6.23
463
+ cdef long xmlSaveDoc(xmlSaveCtxt* ctxt, xmlDoc* doc)
464
+ cdef long xmlSaveTree(xmlSaveCtxt* ctxt, xmlNode* node)
465
+ cdef int xmlSaveClose(xmlSaveCtxt* ctxt)
466
+ cdef int xmlSaveFlush(xmlSaveCtxt* ctxt)
467
+ cdef int xmlSaveSetAttrEscape(xmlSaveCtxt* ctxt, void* escape_func)
468
+ cdef int xmlSaveSetEscape(xmlSaveCtxt* ctxt, void* escape_func)
469
+
470
+ cdef extern from "libxml/globals.h" nogil:
471
+ cdef int xmlThrDefKeepBlanksDefaultValue(int onoff)
472
+ cdef int xmlThrDefLineNumbersDefaultValue(int onoff)
473
+ cdef int xmlThrDefIndentTreeOutput(int onoff)
474
+
475
+ cdef extern from "libxml/xmlmemory.h" nogil:
476
+ cdef void* xmlMalloc(size_t size)
477
+ cdef int xmlMemBlocks()
478
+ cdef int xmlMemUsed()
479
+ cdef void xmlMemDisplay(stdio.FILE* file)
480
+ cdef void xmlMemDisplayLast(stdio.FILE* file, long num_bytes)
481
+ cdef void xmlMemShow(stdio.FILE* file, int count)
482
+
483
+ cdef extern from "etree_defs.h" nogil:
484
+ cdef bint _isElement(xmlNode* node)
485
+ cdef bint _isElementOrXInclude(xmlNode* node)
486
+ cdef const_xmlChar* _getNs(xmlNode* node)
487
+ cdef void BEGIN_FOR_EACH_ELEMENT_FROM(xmlNode* tree_top,
488
+ xmlNode* start_node,
489
+ bint inclusive)
490
+ cdef void END_FOR_EACH_ELEMENT_FROM(xmlNode* start_node)
491
+ cdef void BEGIN_FOR_EACH_FROM(xmlNode* tree_top,
492
+ xmlNode* start_node,
493
+ bint inclusive)
494
+ cdef void END_FOR_EACH_FROM(xmlNode* start_node)
llava_video/lib/python3.10/site-packages/lxml/includes/uri.pxd ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ cdef extern from "libxml/uri.h" nogil:
2
+ ctypedef struct xmlURI
3
+
4
+ cdef xmlURI* xmlParseURI(char* str)
5
+ cdef void xmlFreeURI(xmlURI* uri)
llava_video/lib/python3.10/site-packages/lxml/includes/xinclude.pxd ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes.tree cimport xmlDoc, xmlNode
2
+
3
+ cdef extern from "libxml/xinclude.h" nogil:
4
+
5
+ ctypedef struct xmlXIncludeCtxt
6
+
7
+ cdef int xmlXIncludeProcess(xmlDoc* doc)
8
+ cdef int xmlXIncludeProcessFlags(xmlDoc* doc, int parser_opts)
9
+ cdef int xmlXIncludeProcessTree(xmlNode* doc)
10
+ cdef int xmlXIncludeProcessTreeFlags(xmlNode* doc, int parser_opts)
11
+
12
+ # libxml2 >= 2.7.4
13
+ cdef int xmlXIncludeProcessTreeFlagsData(
14
+ xmlNode* doc, int parser_opts, void* data)
15
+
16
+ cdef xmlXIncludeCtxt* xmlXIncludeNewContext(xmlDoc* doc)
17
+ cdef int xmlXIncludeProcessNode(xmlXIncludeCtxt* ctxt, xmlNode* node)
18
+ cdef int xmlXIncludeSetFlags(xmlXIncludeCtxt* ctxt, int flags)
19
+
20
+ # libxml2 >= 2.6.27
21
+ cdef int xmlXIncludeProcessFlagsData(
22
+ xmlDoc* doc, int flags, void* data)
llava_video/lib/python3.10/site-packages/lxml/includes/xmlerror.pxd ADDED
@@ -0,0 +1,852 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # --- BEGIN: GENERATED CONSTANTS ---
3
+
4
+ # This section is generated by the script 'update-error-constants.py'.
5
+
6
+ cdef extern from "libxml/xmlerror.h":
7
+ ctypedef enum xmlErrorLevel:
8
+ XML_ERR_NONE = 0
9
+ XML_ERR_WARNING = 1 # A simple warning
10
+ XML_ERR_ERROR = 2 # A recoverable error
11
+ XML_ERR_FATAL = 3 # A fatal error
12
+
13
+ ctypedef enum xmlErrorDomain:
14
+ XML_FROM_NONE = 0
15
+ XML_FROM_PARSER = 1 # The XML parser
16
+ XML_FROM_TREE = 2 # The tree module
17
+ XML_FROM_NAMESPACE = 3 # The XML Namespace module
18
+ XML_FROM_DTD = 4 # The XML DTD validation with parser contex
19
+ XML_FROM_HTML = 5 # The HTML parser
20
+ XML_FROM_MEMORY = 6 # The memory allocator
21
+ XML_FROM_OUTPUT = 7 # The serialization code
22
+ XML_FROM_IO = 8 # The Input/Output stack
23
+ XML_FROM_FTP = 9 # The FTP module
24
+ XML_FROM_HTTP = 10 # The HTTP module
25
+ XML_FROM_XINCLUDE = 11 # The XInclude processing
26
+ XML_FROM_XPATH = 12 # The XPath module
27
+ XML_FROM_XPOINTER = 13 # The XPointer module
28
+ XML_FROM_REGEXP = 14 # The regular expressions module
29
+ XML_FROM_DATATYPE = 15 # The W3C XML Schemas Datatype module
30
+ XML_FROM_SCHEMASP = 16 # The W3C XML Schemas parser module
31
+ XML_FROM_SCHEMASV = 17 # The W3C XML Schemas validation module
32
+ XML_FROM_RELAXNGP = 18 # The Relax-NG parser module
33
+ XML_FROM_RELAXNGV = 19 # The Relax-NG validator module
34
+ XML_FROM_CATALOG = 20 # The Catalog module
35
+ XML_FROM_C14N = 21 # The Canonicalization module
36
+ XML_FROM_XSLT = 22 # The XSLT engine from libxslt
37
+ XML_FROM_VALID = 23 # The XML DTD validation with valid context
38
+ XML_FROM_CHECK = 24 # The error checking module
39
+ XML_FROM_WRITER = 25 # The xmlwriter module
40
+ XML_FROM_MODULE = 26 # The dynamically loaded module modul
41
+ XML_FROM_I18N = 27 # The module handling character conversion
42
+ XML_FROM_SCHEMATRONV = 28 # The Schematron validator module
43
+ XML_FROM_BUFFER = 29 # The buffers module
44
+ XML_FROM_URI = 30 # The URI module
45
+
46
+ ctypedef enum xmlParserErrors:
47
+ XML_ERR_OK = 0
48
+ XML_ERR_INTERNAL_ERROR = 1
49
+ XML_ERR_NO_MEMORY = 2
50
+ XML_ERR_DOCUMENT_START = 3
51
+ XML_ERR_DOCUMENT_EMPTY = 4
52
+ XML_ERR_DOCUMENT_END = 5
53
+ XML_ERR_INVALID_HEX_CHARREF = 6
54
+ XML_ERR_INVALID_DEC_CHARREF = 7
55
+ XML_ERR_INVALID_CHARREF = 8
56
+ XML_ERR_INVALID_CHAR = 9
57
+ XML_ERR_CHARREF_AT_EOF = 10
58
+ XML_ERR_CHARREF_IN_PROLOG = 11
59
+ XML_ERR_CHARREF_IN_EPILOG = 12
60
+ XML_ERR_CHARREF_IN_DTD = 13
61
+ XML_ERR_ENTITYREF_AT_EOF = 14
62
+ XML_ERR_ENTITYREF_IN_PROLOG = 15
63
+ XML_ERR_ENTITYREF_IN_EPILOG = 16
64
+ XML_ERR_ENTITYREF_IN_DTD = 17
65
+ XML_ERR_PEREF_AT_EOF = 18
66
+ XML_ERR_PEREF_IN_PROLOG = 19
67
+ XML_ERR_PEREF_IN_EPILOG = 20
68
+ XML_ERR_PEREF_IN_INT_SUBSET = 21
69
+ XML_ERR_ENTITYREF_NO_NAME = 22
70
+ XML_ERR_ENTITYREF_SEMICOL_MISSING = 23
71
+ XML_ERR_PEREF_NO_NAME = 24
72
+ XML_ERR_PEREF_SEMICOL_MISSING = 25
73
+ XML_ERR_UNDECLARED_ENTITY = 26
74
+ XML_WAR_UNDECLARED_ENTITY = 27
75
+ XML_ERR_UNPARSED_ENTITY = 28
76
+ XML_ERR_ENTITY_IS_EXTERNAL = 29
77
+ XML_ERR_ENTITY_IS_PARAMETER = 30
78
+ XML_ERR_UNKNOWN_ENCODING = 31
79
+ XML_ERR_UNSUPPORTED_ENCODING = 32
80
+ XML_ERR_STRING_NOT_STARTED = 33
81
+ XML_ERR_STRING_NOT_CLOSED = 34
82
+ XML_ERR_NS_DECL_ERROR = 35
83
+ XML_ERR_ENTITY_NOT_STARTED = 36
84
+ XML_ERR_ENTITY_NOT_FINISHED = 37
85
+ XML_ERR_LT_IN_ATTRIBUTE = 38
86
+ XML_ERR_ATTRIBUTE_NOT_STARTED = 39
87
+ XML_ERR_ATTRIBUTE_NOT_FINISHED = 40
88
+ XML_ERR_ATTRIBUTE_WITHOUT_VALUE = 41
89
+ XML_ERR_ATTRIBUTE_REDEFINED = 42
90
+ XML_ERR_LITERAL_NOT_STARTED = 43
91
+ XML_ERR_LITERAL_NOT_FINISHED = 44
92
+ XML_ERR_COMMENT_NOT_FINISHED = 45
93
+ XML_ERR_PI_NOT_STARTED = 46
94
+ XML_ERR_PI_NOT_FINISHED = 47
95
+ XML_ERR_NOTATION_NOT_STARTED = 48
96
+ XML_ERR_NOTATION_NOT_FINISHED = 49
97
+ XML_ERR_ATTLIST_NOT_STARTED = 50
98
+ XML_ERR_ATTLIST_NOT_FINISHED = 51
99
+ XML_ERR_MIXED_NOT_STARTED = 52
100
+ XML_ERR_MIXED_NOT_FINISHED = 53
101
+ XML_ERR_ELEMCONTENT_NOT_STARTED = 54
102
+ XML_ERR_ELEMCONTENT_NOT_FINISHED = 55
103
+ XML_ERR_XMLDECL_NOT_STARTED = 56
104
+ XML_ERR_XMLDECL_NOT_FINISHED = 57
105
+ XML_ERR_CONDSEC_NOT_STARTED = 58
106
+ XML_ERR_CONDSEC_NOT_FINISHED = 59
107
+ XML_ERR_EXT_SUBSET_NOT_FINISHED = 60
108
+ XML_ERR_DOCTYPE_NOT_FINISHED = 61
109
+ XML_ERR_MISPLACED_CDATA_END = 62
110
+ XML_ERR_CDATA_NOT_FINISHED = 63
111
+ XML_ERR_RESERVED_XML_NAME = 64
112
+ XML_ERR_SPACE_REQUIRED = 65
113
+ XML_ERR_SEPARATOR_REQUIRED = 66
114
+ XML_ERR_NMTOKEN_REQUIRED = 67
115
+ XML_ERR_NAME_REQUIRED = 68
116
+ XML_ERR_PCDATA_REQUIRED = 69
117
+ XML_ERR_URI_REQUIRED = 70
118
+ XML_ERR_PUBID_REQUIRED = 71
119
+ XML_ERR_LT_REQUIRED = 72
120
+ XML_ERR_GT_REQUIRED = 73
121
+ XML_ERR_LTSLASH_REQUIRED = 74
122
+ XML_ERR_EQUAL_REQUIRED = 75
123
+ XML_ERR_TAG_NAME_MISMATCH = 76
124
+ XML_ERR_TAG_NOT_FINISHED = 77
125
+ XML_ERR_STANDALONE_VALUE = 78
126
+ XML_ERR_ENCODING_NAME = 79
127
+ XML_ERR_HYPHEN_IN_COMMENT = 80
128
+ XML_ERR_INVALID_ENCODING = 81
129
+ XML_ERR_EXT_ENTITY_STANDALONE = 82
130
+ XML_ERR_CONDSEC_INVALID = 83
131
+ XML_ERR_VALUE_REQUIRED = 84
132
+ XML_ERR_NOT_WELL_BALANCED = 85
133
+ XML_ERR_EXTRA_CONTENT = 86
134
+ XML_ERR_ENTITY_CHAR_ERROR = 87
135
+ XML_ERR_ENTITY_PE_INTERNAL = 88
136
+ XML_ERR_ENTITY_LOOP = 89
137
+ XML_ERR_ENTITY_BOUNDARY = 90
138
+ XML_ERR_INVALID_URI = 91
139
+ XML_ERR_URI_FRAGMENT = 92
140
+ XML_WAR_CATALOG_PI = 93
141
+ XML_ERR_NO_DTD = 94
142
+ XML_ERR_CONDSEC_INVALID_KEYWORD = 95
143
+ XML_ERR_VERSION_MISSING = 96
144
+ XML_WAR_UNKNOWN_VERSION = 97
145
+ XML_WAR_LANG_VALUE = 98
146
+ XML_WAR_NS_URI = 99
147
+ XML_WAR_NS_URI_RELATIVE = 100
148
+ XML_ERR_MISSING_ENCODING = 101
149
+ XML_WAR_SPACE_VALUE = 102
150
+ XML_ERR_NOT_STANDALONE = 103
151
+ XML_ERR_ENTITY_PROCESSING = 104
152
+ XML_ERR_NOTATION_PROCESSING = 105
153
+ XML_WAR_NS_COLUMN = 106
154
+ XML_WAR_ENTITY_REDEFINED = 107
155
+ XML_ERR_UNKNOWN_VERSION = 108
156
+ XML_ERR_VERSION_MISMATCH = 109
157
+ XML_ERR_NAME_TOO_LONG = 110
158
+ XML_ERR_USER_STOP = 111
159
+ XML_ERR_COMMENT_ABRUPTLY_ENDED = 112
160
+ XML_NS_ERR_XML_NAMESPACE = 200
161
+ XML_NS_ERR_UNDEFINED_NAMESPACE = 201
162
+ XML_NS_ERR_QNAME = 202
163
+ XML_NS_ERR_ATTRIBUTE_REDEFINED = 203
164
+ XML_NS_ERR_EMPTY = 204
165
+ XML_NS_ERR_COLON = 205
166
+ XML_DTD_ATTRIBUTE_DEFAULT = 500
167
+ XML_DTD_ATTRIBUTE_REDEFINED = 501
168
+ XML_DTD_ATTRIBUTE_VALUE = 502
169
+ XML_DTD_CONTENT_ERROR = 503
170
+ XML_DTD_CONTENT_MODEL = 504
171
+ XML_DTD_CONTENT_NOT_DETERMINIST = 505
172
+ XML_DTD_DIFFERENT_PREFIX = 506
173
+ XML_DTD_ELEM_DEFAULT_NAMESPACE = 507
174
+ XML_DTD_ELEM_NAMESPACE = 508
175
+ XML_DTD_ELEM_REDEFINED = 509
176
+ XML_DTD_EMPTY_NOTATION = 510
177
+ XML_DTD_ENTITY_TYPE = 511
178
+ XML_DTD_ID_FIXED = 512
179
+ XML_DTD_ID_REDEFINED = 513
180
+ XML_DTD_ID_SUBSET = 514
181
+ XML_DTD_INVALID_CHILD = 515
182
+ XML_DTD_INVALID_DEFAULT = 516
183
+ XML_DTD_LOAD_ERROR = 517
184
+ XML_DTD_MISSING_ATTRIBUTE = 518
185
+ XML_DTD_MIXED_CORRUPT = 519
186
+ XML_DTD_MULTIPLE_ID = 520
187
+ XML_DTD_NO_DOC = 521
188
+ XML_DTD_NO_DTD = 522
189
+ XML_DTD_NO_ELEM_NAME = 523
190
+ XML_DTD_NO_PREFIX = 524
191
+ XML_DTD_NO_ROOT = 525
192
+ XML_DTD_NOTATION_REDEFINED = 526
193
+ XML_DTD_NOTATION_VALUE = 527
194
+ XML_DTD_NOT_EMPTY = 528
195
+ XML_DTD_NOT_PCDATA = 529
196
+ XML_DTD_NOT_STANDALONE = 530
197
+ XML_DTD_ROOT_NAME = 531
198
+ XML_DTD_STANDALONE_WHITE_SPACE = 532
199
+ XML_DTD_UNKNOWN_ATTRIBUTE = 533
200
+ XML_DTD_UNKNOWN_ELEM = 534
201
+ XML_DTD_UNKNOWN_ENTITY = 535
202
+ XML_DTD_UNKNOWN_ID = 536
203
+ XML_DTD_UNKNOWN_NOTATION = 537
204
+ XML_DTD_STANDALONE_DEFAULTED = 538
205
+ XML_DTD_XMLID_VALUE = 539
206
+ XML_DTD_XMLID_TYPE = 540
207
+ XML_DTD_DUP_TOKEN = 541
208
+ XML_HTML_STRUCURE_ERROR = 800
209
+ XML_HTML_UNKNOWN_TAG = 801
210
+ XML_RNGP_ANYNAME_ATTR_ANCESTOR = 1000
211
+ XML_RNGP_ATTR_CONFLICT = 1001
212
+ XML_RNGP_ATTRIBUTE_CHILDREN = 1002
213
+ XML_RNGP_ATTRIBUTE_CONTENT = 1003
214
+ XML_RNGP_ATTRIBUTE_EMPTY = 1004
215
+ XML_RNGP_ATTRIBUTE_NOOP = 1005
216
+ XML_RNGP_CHOICE_CONTENT = 1006
217
+ XML_RNGP_CHOICE_EMPTY = 1007
218
+ XML_RNGP_CREATE_FAILURE = 1008
219
+ XML_RNGP_DATA_CONTENT = 1009
220
+ XML_RNGP_DEF_CHOICE_AND_INTERLEAVE = 1010
221
+ XML_RNGP_DEFINE_CREATE_FAILED = 1011
222
+ XML_RNGP_DEFINE_EMPTY = 1012
223
+ XML_RNGP_DEFINE_MISSING = 1013
224
+ XML_RNGP_DEFINE_NAME_MISSING = 1014
225
+ XML_RNGP_ELEM_CONTENT_EMPTY = 1015
226
+ XML_RNGP_ELEM_CONTENT_ERROR = 1016
227
+ XML_RNGP_ELEMENT_EMPTY = 1017
228
+ XML_RNGP_ELEMENT_CONTENT = 1018
229
+ XML_RNGP_ELEMENT_NAME = 1019
230
+ XML_RNGP_ELEMENT_NO_CONTENT = 1020
231
+ XML_RNGP_ELEM_TEXT_CONFLICT = 1021
232
+ XML_RNGP_EMPTY = 1022
233
+ XML_RNGP_EMPTY_CONSTRUCT = 1023
234
+ XML_RNGP_EMPTY_CONTENT = 1024
235
+ XML_RNGP_EMPTY_NOT_EMPTY = 1025
236
+ XML_RNGP_ERROR_TYPE_LIB = 1026
237
+ XML_RNGP_EXCEPT_EMPTY = 1027
238
+ XML_RNGP_EXCEPT_MISSING = 1028
239
+ XML_RNGP_EXCEPT_MULTIPLE = 1029
240
+ XML_RNGP_EXCEPT_NO_CONTENT = 1030
241
+ XML_RNGP_EXTERNALREF_EMTPY = 1031
242
+ XML_RNGP_EXTERNAL_REF_FAILURE = 1032
243
+ XML_RNGP_EXTERNALREF_RECURSE = 1033
244
+ XML_RNGP_FORBIDDEN_ATTRIBUTE = 1034
245
+ XML_RNGP_FOREIGN_ELEMENT = 1035
246
+ XML_RNGP_GRAMMAR_CONTENT = 1036
247
+ XML_RNGP_GRAMMAR_EMPTY = 1037
248
+ XML_RNGP_GRAMMAR_MISSING = 1038
249
+ XML_RNGP_GRAMMAR_NO_START = 1039
250
+ XML_RNGP_GROUP_ATTR_CONFLICT = 1040
251
+ XML_RNGP_HREF_ERROR = 1041
252
+ XML_RNGP_INCLUDE_EMPTY = 1042
253
+ XML_RNGP_INCLUDE_FAILURE = 1043
254
+ XML_RNGP_INCLUDE_RECURSE = 1044
255
+ XML_RNGP_INTERLEAVE_ADD = 1045
256
+ XML_RNGP_INTERLEAVE_CREATE_FAILED = 1046
257
+ XML_RNGP_INTERLEAVE_EMPTY = 1047
258
+ XML_RNGP_INTERLEAVE_NO_CONTENT = 1048
259
+ XML_RNGP_INVALID_DEFINE_NAME = 1049
260
+ XML_RNGP_INVALID_URI = 1050
261
+ XML_RNGP_INVALID_VALUE = 1051
262
+ XML_RNGP_MISSING_HREF = 1052
263
+ XML_RNGP_NAME_MISSING = 1053
264
+ XML_RNGP_NEED_COMBINE = 1054
265
+ XML_RNGP_NOTALLOWED_NOT_EMPTY = 1055
266
+ XML_RNGP_NSNAME_ATTR_ANCESTOR = 1056
267
+ XML_RNGP_NSNAME_NO_NS = 1057
268
+ XML_RNGP_PARAM_FORBIDDEN = 1058
269
+ XML_RNGP_PARAM_NAME_MISSING = 1059
270
+ XML_RNGP_PARENTREF_CREATE_FAILED = 1060
271
+ XML_RNGP_PARENTREF_NAME_INVALID = 1061
272
+ XML_RNGP_PARENTREF_NO_NAME = 1062
273
+ XML_RNGP_PARENTREF_NO_PARENT = 1063
274
+ XML_RNGP_PARENTREF_NOT_EMPTY = 1064
275
+ XML_RNGP_PARSE_ERROR = 1065
276
+ XML_RNGP_PAT_ANYNAME_EXCEPT_ANYNAME = 1066
277
+ XML_RNGP_PAT_ATTR_ATTR = 1067
278
+ XML_RNGP_PAT_ATTR_ELEM = 1068
279
+ XML_RNGP_PAT_DATA_EXCEPT_ATTR = 1069
280
+ XML_RNGP_PAT_DATA_EXCEPT_ELEM = 1070
281
+ XML_RNGP_PAT_DATA_EXCEPT_EMPTY = 1071
282
+ XML_RNGP_PAT_DATA_EXCEPT_GROUP = 1072
283
+ XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE = 1073
284
+ XML_RNGP_PAT_DATA_EXCEPT_LIST = 1074
285
+ XML_RNGP_PAT_DATA_EXCEPT_ONEMORE = 1075
286
+ XML_RNGP_PAT_DATA_EXCEPT_REF = 1076
287
+ XML_RNGP_PAT_DATA_EXCEPT_TEXT = 1077
288
+ XML_RNGP_PAT_LIST_ATTR = 1078
289
+ XML_RNGP_PAT_LIST_ELEM = 1079
290
+ XML_RNGP_PAT_LIST_INTERLEAVE = 1080
291
+ XML_RNGP_PAT_LIST_LIST = 1081
292
+ XML_RNGP_PAT_LIST_REF = 1082
293
+ XML_RNGP_PAT_LIST_TEXT = 1083
294
+ XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME = 1084
295
+ XML_RNGP_PAT_NSNAME_EXCEPT_NSNAME = 1085
296
+ XML_RNGP_PAT_ONEMORE_GROUP_ATTR = 1086
297
+ XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR = 1087
298
+ XML_RNGP_PAT_START_ATTR = 1088
299
+ XML_RNGP_PAT_START_DATA = 1089
300
+ XML_RNGP_PAT_START_EMPTY = 1090
301
+ XML_RNGP_PAT_START_GROUP = 1091
302
+ XML_RNGP_PAT_START_INTERLEAVE = 1092
303
+ XML_RNGP_PAT_START_LIST = 1093
304
+ XML_RNGP_PAT_START_ONEMORE = 1094
305
+ XML_RNGP_PAT_START_TEXT = 1095
306
+ XML_RNGP_PAT_START_VALUE = 1096
307
+ XML_RNGP_PREFIX_UNDEFINED = 1097
308
+ XML_RNGP_REF_CREATE_FAILED = 1098
309
+ XML_RNGP_REF_CYCLE = 1099
310
+ XML_RNGP_REF_NAME_INVALID = 1100
311
+ XML_RNGP_REF_NO_DEF = 1101
312
+ XML_RNGP_REF_NO_NAME = 1102
313
+ XML_RNGP_REF_NOT_EMPTY = 1103
314
+ XML_RNGP_START_CHOICE_AND_INTERLEAVE = 1104
315
+ XML_RNGP_START_CONTENT = 1105
316
+ XML_RNGP_START_EMPTY = 1106
317
+ XML_RNGP_START_MISSING = 1107
318
+ XML_RNGP_TEXT_EXPECTED = 1108
319
+ XML_RNGP_TEXT_HAS_CHILD = 1109
320
+ XML_RNGP_TYPE_MISSING = 1110
321
+ XML_RNGP_TYPE_NOT_FOUND = 1111
322
+ XML_RNGP_TYPE_VALUE = 1112
323
+ XML_RNGP_UNKNOWN_ATTRIBUTE = 1113
324
+ XML_RNGP_UNKNOWN_COMBINE = 1114
325
+ XML_RNGP_UNKNOWN_CONSTRUCT = 1115
326
+ XML_RNGP_UNKNOWN_TYPE_LIB = 1116
327
+ XML_RNGP_URI_FRAGMENT = 1117
328
+ XML_RNGP_URI_NOT_ABSOLUTE = 1118
329
+ XML_RNGP_VALUE_EMPTY = 1119
330
+ XML_RNGP_VALUE_NO_CONTENT = 1120
331
+ XML_RNGP_XMLNS_NAME = 1121
332
+ XML_RNGP_XML_NS = 1122
333
+ XML_XPATH_EXPRESSION_OK = 1200
334
+ XML_XPATH_NUMBER_ERROR = 1201
335
+ XML_XPATH_UNFINISHED_LITERAL_ERROR = 1202
336
+ XML_XPATH_START_LITERAL_ERROR = 1203
337
+ XML_XPATH_VARIABLE_REF_ERROR = 1204
338
+ XML_XPATH_UNDEF_VARIABLE_ERROR = 1205
339
+ XML_XPATH_INVALID_PREDICATE_ERROR = 1206
340
+ XML_XPATH_EXPR_ERROR = 1207
341
+ XML_XPATH_UNCLOSED_ERROR = 1208
342
+ XML_XPATH_UNKNOWN_FUNC_ERROR = 1209
343
+ XML_XPATH_INVALID_OPERAND = 1210
344
+ XML_XPATH_INVALID_TYPE = 1211
345
+ XML_XPATH_INVALID_ARITY = 1212
346
+ XML_XPATH_INVALID_CTXT_SIZE = 1213
347
+ XML_XPATH_INVALID_CTXT_POSITION = 1214
348
+ XML_XPATH_MEMORY_ERROR = 1215
349
+ XML_XPTR_SYNTAX_ERROR = 1216
350
+ XML_XPTR_RESOURCE_ERROR = 1217
351
+ XML_XPTR_SUB_RESOURCE_ERROR = 1218
352
+ XML_XPATH_UNDEF_PREFIX_ERROR = 1219
353
+ XML_XPATH_ENCODING_ERROR = 1220
354
+ XML_XPATH_INVALID_CHAR_ERROR = 1221
355
+ XML_TREE_INVALID_HEX = 1300
356
+ XML_TREE_INVALID_DEC = 1301
357
+ XML_TREE_UNTERMINATED_ENTITY = 1302
358
+ XML_TREE_NOT_UTF8 = 1303
359
+ XML_SAVE_NOT_UTF8 = 1400
360
+ XML_SAVE_CHAR_INVALID = 1401
361
+ XML_SAVE_NO_DOCTYPE = 1402
362
+ XML_SAVE_UNKNOWN_ENCODING = 1403
363
+ XML_REGEXP_COMPILE_ERROR = 1450
364
+ XML_IO_UNKNOWN = 1500
365
+ XML_IO_EACCES = 1501
366
+ XML_IO_EAGAIN = 1502
367
+ XML_IO_EBADF = 1503
368
+ XML_IO_EBADMSG = 1504
369
+ XML_IO_EBUSY = 1505
370
+ XML_IO_ECANCELED = 1506
371
+ XML_IO_ECHILD = 1507
372
+ XML_IO_EDEADLK = 1508
373
+ XML_IO_EDOM = 1509
374
+ XML_IO_EEXIST = 1510
375
+ XML_IO_EFAULT = 1511
376
+ XML_IO_EFBIG = 1512
377
+ XML_IO_EINPROGRESS = 1513
378
+ XML_IO_EINTR = 1514
379
+ XML_IO_EINVAL = 1515
380
+ XML_IO_EIO = 1516
381
+ XML_IO_EISDIR = 1517
382
+ XML_IO_EMFILE = 1518
383
+ XML_IO_EMLINK = 1519
384
+ XML_IO_EMSGSIZE = 1520
385
+ XML_IO_ENAMETOOLONG = 1521
386
+ XML_IO_ENFILE = 1522
387
+ XML_IO_ENODEV = 1523
388
+ XML_IO_ENOENT = 1524
389
+ XML_IO_ENOEXEC = 1525
390
+ XML_IO_ENOLCK = 1526
391
+ XML_IO_ENOMEM = 1527
392
+ XML_IO_ENOSPC = 1528
393
+ XML_IO_ENOSYS = 1529
394
+ XML_IO_ENOTDIR = 1530
395
+ XML_IO_ENOTEMPTY = 1531
396
+ XML_IO_ENOTSUP = 1532
397
+ XML_IO_ENOTTY = 1533
398
+ XML_IO_ENXIO = 1534
399
+ XML_IO_EPERM = 1535
400
+ XML_IO_EPIPE = 1536
401
+ XML_IO_ERANGE = 1537
402
+ XML_IO_EROFS = 1538
403
+ XML_IO_ESPIPE = 1539
404
+ XML_IO_ESRCH = 1540
405
+ XML_IO_ETIMEDOUT = 1541
406
+ XML_IO_EXDEV = 1542
407
+ XML_IO_NETWORK_ATTEMPT = 1543
408
+ XML_IO_ENCODER = 1544
409
+ XML_IO_FLUSH = 1545
410
+ XML_IO_WRITE = 1546
411
+ XML_IO_NO_INPUT = 1547
412
+ XML_IO_BUFFER_FULL = 1548
413
+ XML_IO_LOAD_ERROR = 1549
414
+ XML_IO_ENOTSOCK = 1550
415
+ XML_IO_EISCONN = 1551
416
+ XML_IO_ECONNREFUSED = 1552
417
+ XML_IO_ENETUNREACH = 1553
418
+ XML_IO_EADDRINUSE = 1554
419
+ XML_IO_EALREADY = 1555
420
+ XML_IO_EAFNOSUPPORT = 1556
421
+ XML_XINCLUDE_RECURSION = 1600
422
+ XML_XINCLUDE_PARSE_VALUE = 1601
423
+ XML_XINCLUDE_ENTITY_DEF_MISMATCH = 1602
424
+ XML_XINCLUDE_NO_HREF = 1603
425
+ XML_XINCLUDE_NO_FALLBACK = 1604
426
+ XML_XINCLUDE_HREF_URI = 1605
427
+ XML_XINCLUDE_TEXT_FRAGMENT = 1606
428
+ XML_XINCLUDE_TEXT_DOCUMENT = 1607
429
+ XML_XINCLUDE_INVALID_CHAR = 1608
430
+ XML_XINCLUDE_BUILD_FAILED = 1609
431
+ XML_XINCLUDE_UNKNOWN_ENCODING = 1610
432
+ XML_XINCLUDE_MULTIPLE_ROOT = 1611
433
+ XML_XINCLUDE_XPTR_FAILED = 1612
434
+ XML_XINCLUDE_XPTR_RESULT = 1613
435
+ XML_XINCLUDE_INCLUDE_IN_INCLUDE = 1614
436
+ XML_XINCLUDE_FALLBACKS_IN_INCLUDE = 1615
437
+ XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE = 1616
438
+ XML_XINCLUDE_DEPRECATED_NS = 1617
439
+ XML_XINCLUDE_FRAGMENT_ID = 1618
440
+ XML_CATALOG_MISSING_ATTR = 1650
441
+ XML_CATALOG_ENTRY_BROKEN = 1651
442
+ XML_CATALOG_PREFER_VALUE = 1652
443
+ XML_CATALOG_NOT_CATALOG = 1653
444
+ XML_CATALOG_RECURSION = 1654
445
+ XML_SCHEMAP_PREFIX_UNDEFINED = 1700
446
+ XML_SCHEMAP_ATTRFORMDEFAULT_VALUE = 1701
447
+ XML_SCHEMAP_ATTRGRP_NONAME_NOREF = 1702
448
+ XML_SCHEMAP_ATTR_NONAME_NOREF = 1703
449
+ XML_SCHEMAP_COMPLEXTYPE_NONAME_NOREF = 1704
450
+ XML_SCHEMAP_ELEMFORMDEFAULT_VALUE = 1705
451
+ XML_SCHEMAP_ELEM_NONAME_NOREF = 1706
452
+ XML_SCHEMAP_EXTENSION_NO_BASE = 1707
453
+ XML_SCHEMAP_FACET_NO_VALUE = 1708
454
+ XML_SCHEMAP_FAILED_BUILD_IMPORT = 1709
455
+ XML_SCHEMAP_GROUP_NONAME_NOREF = 1710
456
+ XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI = 1711
457
+ XML_SCHEMAP_IMPORT_REDEFINE_NSNAME = 1712
458
+ XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI = 1713
459
+ XML_SCHEMAP_INVALID_BOOLEAN = 1714
460
+ XML_SCHEMAP_INVALID_ENUM = 1715
461
+ XML_SCHEMAP_INVALID_FACET = 1716
462
+ XML_SCHEMAP_INVALID_FACET_VALUE = 1717
463
+ XML_SCHEMAP_INVALID_MAXOCCURS = 1718
464
+ XML_SCHEMAP_INVALID_MINOCCURS = 1719
465
+ XML_SCHEMAP_INVALID_REF_AND_SUBTYPE = 1720
466
+ XML_SCHEMAP_INVALID_WHITE_SPACE = 1721
467
+ XML_SCHEMAP_NOATTR_NOREF = 1722
468
+ XML_SCHEMAP_NOTATION_NO_NAME = 1723
469
+ XML_SCHEMAP_NOTYPE_NOREF = 1724
470
+ XML_SCHEMAP_REF_AND_SUBTYPE = 1725
471
+ XML_SCHEMAP_RESTRICTION_NONAME_NOREF = 1726
472
+ XML_SCHEMAP_SIMPLETYPE_NONAME = 1727
473
+ XML_SCHEMAP_TYPE_AND_SUBTYPE = 1728
474
+ XML_SCHEMAP_UNKNOWN_ALL_CHILD = 1729
475
+ XML_SCHEMAP_UNKNOWN_ANYATTRIBUTE_CHILD = 1730
476
+ XML_SCHEMAP_UNKNOWN_ATTR_CHILD = 1731
477
+ XML_SCHEMAP_UNKNOWN_ATTRGRP_CHILD = 1732
478
+ XML_SCHEMAP_UNKNOWN_ATTRIBUTE_GROUP = 1733
479
+ XML_SCHEMAP_UNKNOWN_BASE_TYPE = 1734
480
+ XML_SCHEMAP_UNKNOWN_CHOICE_CHILD = 1735
481
+ XML_SCHEMAP_UNKNOWN_COMPLEXCONTENT_CHILD = 1736
482
+ XML_SCHEMAP_UNKNOWN_COMPLEXTYPE_CHILD = 1737
483
+ XML_SCHEMAP_UNKNOWN_ELEM_CHILD = 1738
484
+ XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD = 1739
485
+ XML_SCHEMAP_UNKNOWN_FACET_CHILD = 1740
486
+ XML_SCHEMAP_UNKNOWN_FACET_TYPE = 1741
487
+ XML_SCHEMAP_UNKNOWN_GROUP_CHILD = 1742
488
+ XML_SCHEMAP_UNKNOWN_IMPORT_CHILD = 1743
489
+ XML_SCHEMAP_UNKNOWN_LIST_CHILD = 1744
490
+ XML_SCHEMAP_UNKNOWN_NOTATION_CHILD = 1745
491
+ XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD = 1746
492
+ XML_SCHEMAP_UNKNOWN_REF = 1747
493
+ XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD = 1748
494
+ XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD = 1749
495
+ XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD = 1750
496
+ XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD = 1751
497
+ XML_SCHEMAP_UNKNOWN_SIMPLETYPE_CHILD = 1752
498
+ XML_SCHEMAP_UNKNOWN_TYPE = 1753
499
+ XML_SCHEMAP_UNKNOWN_UNION_CHILD = 1754
500
+ XML_SCHEMAP_ELEM_DEFAULT_FIXED = 1755
501
+ XML_SCHEMAP_REGEXP_INVALID = 1756
502
+ XML_SCHEMAP_FAILED_LOAD = 1757
503
+ XML_SCHEMAP_NOTHING_TO_PARSE = 1758
504
+ XML_SCHEMAP_NOROOT = 1759
505
+ XML_SCHEMAP_REDEFINED_GROUP = 1760
506
+ XML_SCHEMAP_REDEFINED_TYPE = 1761
507
+ XML_SCHEMAP_REDEFINED_ELEMENT = 1762
508
+ XML_SCHEMAP_REDEFINED_ATTRGROUP = 1763
509
+ XML_SCHEMAP_REDEFINED_ATTR = 1764
510
+ XML_SCHEMAP_REDEFINED_NOTATION = 1765
511
+ XML_SCHEMAP_FAILED_PARSE = 1766
512
+ XML_SCHEMAP_UNKNOWN_PREFIX = 1767
513
+ XML_SCHEMAP_DEF_AND_PREFIX = 1768
514
+ XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD = 1769
515
+ XML_SCHEMAP_INCLUDE_SCHEMA_NOT_URI = 1770
516
+ XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI = 1771
517
+ XML_SCHEMAP_NOT_SCHEMA = 1772
518
+ XML_SCHEMAP_UNKNOWN_MEMBER_TYPE = 1773
519
+ XML_SCHEMAP_INVALID_ATTR_USE = 1774
520
+ XML_SCHEMAP_RECURSIVE = 1775
521
+ XML_SCHEMAP_SUPERNUMEROUS_LIST_ITEM_TYPE = 1776
522
+ XML_SCHEMAP_INVALID_ATTR_COMBINATION = 1777
523
+ XML_SCHEMAP_INVALID_ATTR_INLINE_COMBINATION = 1778
524
+ XML_SCHEMAP_MISSING_SIMPLETYPE_CHILD = 1779
525
+ XML_SCHEMAP_INVALID_ATTR_NAME = 1780
526
+ XML_SCHEMAP_REF_AND_CONTENT = 1781
527
+ XML_SCHEMAP_CT_PROPS_CORRECT_1 = 1782
528
+ XML_SCHEMAP_CT_PROPS_CORRECT_2 = 1783
529
+ XML_SCHEMAP_CT_PROPS_CORRECT_3 = 1784
530
+ XML_SCHEMAP_CT_PROPS_CORRECT_4 = 1785
531
+ XML_SCHEMAP_CT_PROPS_CORRECT_5 = 1786
532
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1 = 1787
533
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1 = 1788
534
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2 = 1789
535
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2 = 1790
536
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3 = 1791
537
+ XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER = 1792
538
+ XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE = 1793
539
+ XML_SCHEMAP_UNION_NOT_EXPRESSIBLE = 1794
540
+ XML_SCHEMAP_SRC_IMPORT_3_1 = 1795
541
+ XML_SCHEMAP_SRC_IMPORT_3_2 = 1796
542
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1 = 1797
543
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2 = 1798
544
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3 = 1799
545
+ XML_SCHEMAP_COS_CT_EXTENDS_1_3 = 1800
546
+ XML_SCHEMAV_NOROOT = 1801
547
+ XML_SCHEMAV_UNDECLAREDELEM = 1802
548
+ XML_SCHEMAV_NOTTOPLEVEL = 1803
549
+ XML_SCHEMAV_MISSING = 1804
550
+ XML_SCHEMAV_WRONGELEM = 1805
551
+ XML_SCHEMAV_NOTYPE = 1806
552
+ XML_SCHEMAV_NOROLLBACK = 1807
553
+ XML_SCHEMAV_ISABSTRACT = 1808
554
+ XML_SCHEMAV_NOTEMPTY = 1809
555
+ XML_SCHEMAV_ELEMCONT = 1810
556
+ XML_SCHEMAV_HAVEDEFAULT = 1811
557
+ XML_SCHEMAV_NOTNILLABLE = 1812
558
+ XML_SCHEMAV_EXTRACONTENT = 1813
559
+ XML_SCHEMAV_INVALIDATTR = 1814
560
+ XML_SCHEMAV_INVALIDELEM = 1815
561
+ XML_SCHEMAV_NOTDETERMINIST = 1816
562
+ XML_SCHEMAV_CONSTRUCT = 1817
563
+ XML_SCHEMAV_INTERNAL = 1818
564
+ XML_SCHEMAV_NOTSIMPLE = 1819
565
+ XML_SCHEMAV_ATTRUNKNOWN = 1820
566
+ XML_SCHEMAV_ATTRINVALID = 1821
567
+ XML_SCHEMAV_VALUE = 1822
568
+ XML_SCHEMAV_FACET = 1823
569
+ XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1 = 1824
570
+ XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2 = 1825
571
+ XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3 = 1826
572
+ XML_SCHEMAV_CVC_TYPE_3_1_1 = 1827
573
+ XML_SCHEMAV_CVC_TYPE_3_1_2 = 1828
574
+ XML_SCHEMAV_CVC_FACET_VALID = 1829
575
+ XML_SCHEMAV_CVC_LENGTH_VALID = 1830
576
+ XML_SCHEMAV_CVC_MINLENGTH_VALID = 1831
577
+ XML_SCHEMAV_CVC_MAXLENGTH_VALID = 1832
578
+ XML_SCHEMAV_CVC_MININCLUSIVE_VALID = 1833
579
+ XML_SCHEMAV_CVC_MAXINCLUSIVE_VALID = 1834
580
+ XML_SCHEMAV_CVC_MINEXCLUSIVE_VALID = 1835
581
+ XML_SCHEMAV_CVC_MAXEXCLUSIVE_VALID = 1836
582
+ XML_SCHEMAV_CVC_TOTALDIGITS_VALID = 1837
583
+ XML_SCHEMAV_CVC_FRACTIONDIGITS_VALID = 1838
584
+ XML_SCHEMAV_CVC_PATTERN_VALID = 1839
585
+ XML_SCHEMAV_CVC_ENUMERATION_VALID = 1840
586
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1 = 1841
587
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2 = 1842
588
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3 = 1843
589
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_2_4 = 1844
590
+ XML_SCHEMAV_CVC_ELT_1 = 1845
591
+ XML_SCHEMAV_CVC_ELT_2 = 1846
592
+ XML_SCHEMAV_CVC_ELT_3_1 = 1847
593
+ XML_SCHEMAV_CVC_ELT_3_2_1 = 1848
594
+ XML_SCHEMAV_CVC_ELT_3_2_2 = 1849
595
+ XML_SCHEMAV_CVC_ELT_4_1 = 1850
596
+ XML_SCHEMAV_CVC_ELT_4_2 = 1851
597
+ XML_SCHEMAV_CVC_ELT_4_3 = 1852
598
+ XML_SCHEMAV_CVC_ELT_5_1_1 = 1853
599
+ XML_SCHEMAV_CVC_ELT_5_1_2 = 1854
600
+ XML_SCHEMAV_CVC_ELT_5_2_1 = 1855
601
+ XML_SCHEMAV_CVC_ELT_5_2_2_1 = 1856
602
+ XML_SCHEMAV_CVC_ELT_5_2_2_2_1 = 1857
603
+ XML_SCHEMAV_CVC_ELT_5_2_2_2_2 = 1858
604
+ XML_SCHEMAV_CVC_ELT_6 = 1859
605
+ XML_SCHEMAV_CVC_ELT_7 = 1860
606
+ XML_SCHEMAV_CVC_ATTRIBUTE_1 = 1861
607
+ XML_SCHEMAV_CVC_ATTRIBUTE_2 = 1862
608
+ XML_SCHEMAV_CVC_ATTRIBUTE_3 = 1863
609
+ XML_SCHEMAV_CVC_ATTRIBUTE_4 = 1864
610
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_3_1 = 1865
611
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1 = 1866
612
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2 = 1867
613
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_4 = 1868
614
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_5_1 = 1869
615
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_5_2 = 1870
616
+ XML_SCHEMAV_ELEMENT_CONTENT = 1871
617
+ XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING = 1872
618
+ XML_SCHEMAV_CVC_COMPLEX_TYPE_1 = 1873
619
+ XML_SCHEMAV_CVC_AU = 1874
620
+ XML_SCHEMAV_CVC_TYPE_1 = 1875
621
+ XML_SCHEMAV_CVC_TYPE_2 = 1876
622
+ XML_SCHEMAV_CVC_IDC = 1877
623
+ XML_SCHEMAV_CVC_WILDCARD = 1878
624
+ XML_SCHEMAV_MISC = 1879
625
+ XML_XPTR_UNKNOWN_SCHEME = 1900
626
+ XML_XPTR_CHILDSEQ_START = 1901
627
+ XML_XPTR_EVAL_FAILED = 1902
628
+ XML_XPTR_EXTRA_OBJECTS = 1903
629
+ XML_C14N_CREATE_CTXT = 1950
630
+ XML_C14N_REQUIRES_UTF8 = 1951
631
+ XML_C14N_CREATE_STACK = 1952
632
+ XML_C14N_INVALID_NODE = 1953
633
+ XML_C14N_UNKNOW_NODE = 1954
634
+ XML_C14N_RELATIVE_NAMESPACE = 1955
635
+ XML_FTP_PASV_ANSWER = 2000
636
+ XML_FTP_EPSV_ANSWER = 2001
637
+ XML_FTP_ACCNT = 2002
638
+ XML_FTP_URL_SYNTAX = 2003
639
+ XML_HTTP_URL_SYNTAX = 2020
640
+ XML_HTTP_USE_IP = 2021
641
+ XML_HTTP_UNKNOWN_HOST = 2022
642
+ XML_SCHEMAP_SRC_SIMPLE_TYPE_1 = 3000
643
+ XML_SCHEMAP_SRC_SIMPLE_TYPE_2 = 3001
644
+ XML_SCHEMAP_SRC_SIMPLE_TYPE_3 = 3002
645
+ XML_SCHEMAP_SRC_SIMPLE_TYPE_4 = 3003
646
+ XML_SCHEMAP_SRC_RESOLVE = 3004
647
+ XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE = 3005
648
+ XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE = 3006
649
+ XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES = 3007
650
+ XML_SCHEMAP_ST_PROPS_CORRECT_1 = 3008
651
+ XML_SCHEMAP_ST_PROPS_CORRECT_2 = 3009
652
+ XML_SCHEMAP_ST_PROPS_CORRECT_3 = 3010
653
+ XML_SCHEMAP_COS_ST_RESTRICTS_1_1 = 3011
654
+ XML_SCHEMAP_COS_ST_RESTRICTS_1_2 = 3012
655
+ XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1 = 3013
656
+ XML_SCHEMAP_COS_ST_RESTRICTS_1_3_2 = 3014
657
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_1 = 3015
658
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1 = 3016
659
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2 = 3017
660
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1 = 3018
661
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2 = 3019
662
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3 = 3020
663
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4 = 3021
664
+ XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_5 = 3022
665
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_1 = 3023
666
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1 = 3024
667
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2 = 3025
668
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2 = 3026
669
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1 = 3027
670
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3 = 3028
671
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4 = 3029
672
+ XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_5 = 3030
673
+ XML_SCHEMAP_COS_ST_DERIVED_OK_2_1 = 3031
674
+ XML_SCHEMAP_COS_ST_DERIVED_OK_2_2 = 3032
675
+ XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED = 3033
676
+ XML_SCHEMAP_S4S_ELEM_MISSING = 3034
677
+ XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED = 3035
678
+ XML_SCHEMAP_S4S_ATTR_MISSING = 3036
679
+ XML_SCHEMAP_S4S_ATTR_INVALID_VALUE = 3037
680
+ XML_SCHEMAP_SRC_ELEMENT_1 = 3038
681
+ XML_SCHEMAP_SRC_ELEMENT_2_1 = 3039
682
+ XML_SCHEMAP_SRC_ELEMENT_2_2 = 3040
683
+ XML_SCHEMAP_SRC_ELEMENT_3 = 3041
684
+ XML_SCHEMAP_P_PROPS_CORRECT_1 = 3042
685
+ XML_SCHEMAP_P_PROPS_CORRECT_2_1 = 3043
686
+ XML_SCHEMAP_P_PROPS_CORRECT_2_2 = 3044
687
+ XML_SCHEMAP_E_PROPS_CORRECT_2 = 3045
688
+ XML_SCHEMAP_E_PROPS_CORRECT_3 = 3046
689
+ XML_SCHEMAP_E_PROPS_CORRECT_4 = 3047
690
+ XML_SCHEMAP_E_PROPS_CORRECT_5 = 3048
691
+ XML_SCHEMAP_E_PROPS_CORRECT_6 = 3049
692
+ XML_SCHEMAP_SRC_INCLUDE = 3050
693
+ XML_SCHEMAP_SRC_ATTRIBUTE_1 = 3051
694
+ XML_SCHEMAP_SRC_ATTRIBUTE_2 = 3052
695
+ XML_SCHEMAP_SRC_ATTRIBUTE_3_1 = 3053
696
+ XML_SCHEMAP_SRC_ATTRIBUTE_3_2 = 3054
697
+ XML_SCHEMAP_SRC_ATTRIBUTE_4 = 3055
698
+ XML_SCHEMAP_NO_XMLNS = 3056
699
+ XML_SCHEMAP_NO_XSI = 3057
700
+ XML_SCHEMAP_COS_VALID_DEFAULT_1 = 3058
701
+ XML_SCHEMAP_COS_VALID_DEFAULT_2_1 = 3059
702
+ XML_SCHEMAP_COS_VALID_DEFAULT_2_2_1 = 3060
703
+ XML_SCHEMAP_COS_VALID_DEFAULT_2_2_2 = 3061
704
+ XML_SCHEMAP_CVC_SIMPLE_TYPE = 3062
705
+ XML_SCHEMAP_COS_CT_EXTENDS_1_1 = 3063
706
+ XML_SCHEMAP_SRC_IMPORT_1_1 = 3064
707
+ XML_SCHEMAP_SRC_IMPORT_1_2 = 3065
708
+ XML_SCHEMAP_SRC_IMPORT_2 = 3066
709
+ XML_SCHEMAP_SRC_IMPORT_2_1 = 3067
710
+ XML_SCHEMAP_SRC_IMPORT_2_2 = 3068
711
+ XML_SCHEMAP_INTERNAL = 3069 # 3069 non-W3C
712
+ XML_SCHEMAP_NOT_DETERMINISTIC = 3070 # 3070 non-W3C
713
+ XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_1 = 3071
714
+ XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_2 = 3072
715
+ XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3 = 3073
716
+ XML_SCHEMAP_MG_PROPS_CORRECT_1 = 3074
717
+ XML_SCHEMAP_MG_PROPS_CORRECT_2 = 3075
718
+ XML_SCHEMAP_SRC_CT_1 = 3076
719
+ XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3 = 3077
720
+ XML_SCHEMAP_AU_PROPS_CORRECT_2 = 3078
721
+ XML_SCHEMAP_A_PROPS_CORRECT_2 = 3079
722
+ XML_SCHEMAP_C_PROPS_CORRECT = 3080
723
+ XML_SCHEMAP_SRC_REDEFINE = 3081
724
+ XML_SCHEMAP_SRC_IMPORT = 3082
725
+ XML_SCHEMAP_WARN_SKIP_SCHEMA = 3083
726
+ XML_SCHEMAP_WARN_UNLOCATED_SCHEMA = 3084
727
+ XML_SCHEMAP_WARN_ATTR_REDECL_PROH = 3085
728
+ XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH = 3086 # 3085
729
+ XML_SCHEMAP_AG_PROPS_CORRECT = 3087 # 3086
730
+ XML_SCHEMAP_COS_CT_EXTENDS_1_2 = 3088 # 3087
731
+ XML_SCHEMAP_AU_PROPS_CORRECT = 3089 # 3088
732
+ XML_SCHEMAP_A_PROPS_CORRECT_3 = 3090 # 3089
733
+ XML_SCHEMAP_COS_ALL_LIMITED = 3091 # 3090
734
+ XML_SCHEMATRONV_ASSERT = 4000
735
+ XML_SCHEMATRONV_REPORT = 4001
736
+ XML_MODULE_OPEN = 4900
737
+ XML_MODULE_CLOSE = 4901
738
+ XML_CHECK_FOUND_ELEMENT = 5000
739
+ XML_CHECK_FOUND_ATTRIBUTE = 5001
740
+ XML_CHECK_FOUND_TEXT = 5002
741
+ XML_CHECK_FOUND_CDATA = 5003
742
+ XML_CHECK_FOUND_ENTITYREF = 5004
743
+ XML_CHECK_FOUND_ENTITY = 5005
744
+ XML_CHECK_FOUND_PI = 5006
745
+ XML_CHECK_FOUND_COMMENT = 5007
746
+ XML_CHECK_FOUND_DOCTYPE = 5008
747
+ XML_CHECK_FOUND_FRAGMENT = 5009
748
+ XML_CHECK_FOUND_NOTATION = 5010
749
+ XML_CHECK_UNKNOWN_NODE = 5011
750
+ XML_CHECK_ENTITY_TYPE = 5012
751
+ XML_CHECK_NO_PARENT = 5013
752
+ XML_CHECK_NO_DOC = 5014
753
+ XML_CHECK_NO_NAME = 5015
754
+ XML_CHECK_NO_ELEM = 5016
755
+ XML_CHECK_WRONG_DOC = 5017
756
+ XML_CHECK_NO_PREV = 5018
757
+ XML_CHECK_WRONG_PREV = 5019
758
+ XML_CHECK_NO_NEXT = 5020
759
+ XML_CHECK_WRONG_NEXT = 5021
760
+ XML_CHECK_NOT_DTD = 5022
761
+ XML_CHECK_NOT_ATTR = 5023
762
+ XML_CHECK_NOT_ATTR_DECL = 5024
763
+ XML_CHECK_NOT_ELEM_DECL = 5025
764
+ XML_CHECK_NOT_ENTITY_DECL = 5026
765
+ XML_CHECK_NOT_NS_DECL = 5027
766
+ XML_CHECK_NO_HREF = 5028
767
+ XML_CHECK_WRONG_PARENT = 5029
768
+ XML_CHECK_NS_SCOPE = 5030
769
+ XML_CHECK_NS_ANCESTOR = 5031
770
+ XML_CHECK_NOT_UTF8 = 5032
771
+ XML_CHECK_NO_DICT = 5033
772
+ XML_CHECK_NOT_NCNAME = 5034
773
+ XML_CHECK_OUTSIDE_DICT = 5035
774
+ XML_CHECK_WRONG_NAME = 5036
775
+ XML_CHECK_NAME_NOT_NULL = 5037
776
+ XML_I18N_NO_NAME = 6000
777
+ XML_I18N_NO_HANDLER = 6001
778
+ XML_I18N_EXCESS_HANDLER = 6002
779
+ XML_I18N_CONV_FAILED = 6003
780
+ XML_I18N_NO_OUTPUT = 6004
781
+ XML_BUF_OVERFLOW = 7000
782
+
783
+ ctypedef enum xmlRelaxNGValidErr:
784
+ XML_RELAXNG_OK = 0
785
+ XML_RELAXNG_ERR_MEMORY = 1
786
+ XML_RELAXNG_ERR_TYPE = 2
787
+ XML_RELAXNG_ERR_TYPEVAL = 3
788
+ XML_RELAXNG_ERR_DUPID = 4
789
+ XML_RELAXNG_ERR_TYPECMP = 5
790
+ XML_RELAXNG_ERR_NOSTATE = 6
791
+ XML_RELAXNG_ERR_NODEFINE = 7
792
+ XML_RELAXNG_ERR_LISTEXTRA = 8
793
+ XML_RELAXNG_ERR_LISTEMPTY = 9
794
+ XML_RELAXNG_ERR_INTERNODATA = 10
795
+ XML_RELAXNG_ERR_INTERSEQ = 11
796
+ XML_RELAXNG_ERR_INTEREXTRA = 12
797
+ XML_RELAXNG_ERR_ELEMNAME = 13
798
+ XML_RELAXNG_ERR_ATTRNAME = 14
799
+ XML_RELAXNG_ERR_ELEMNONS = 15
800
+ XML_RELAXNG_ERR_ATTRNONS = 16
801
+ XML_RELAXNG_ERR_ELEMWRONGNS = 17
802
+ XML_RELAXNG_ERR_ATTRWRONGNS = 18
803
+ XML_RELAXNG_ERR_ELEMEXTRANS = 19
804
+ XML_RELAXNG_ERR_ATTREXTRANS = 20
805
+ XML_RELAXNG_ERR_ELEMNOTEMPTY = 21
806
+ XML_RELAXNG_ERR_NOELEM = 22
807
+ XML_RELAXNG_ERR_NOTELEM = 23
808
+ XML_RELAXNG_ERR_ATTRVALID = 24
809
+ XML_RELAXNG_ERR_CONTENTVALID = 25
810
+ XML_RELAXNG_ERR_EXTRACONTENT = 26
811
+ XML_RELAXNG_ERR_INVALIDATTR = 27
812
+ XML_RELAXNG_ERR_DATAELEM = 28
813
+ XML_RELAXNG_ERR_VALELEM = 29
814
+ XML_RELAXNG_ERR_LISTELEM = 30
815
+ XML_RELAXNG_ERR_DATATYPE = 31
816
+ XML_RELAXNG_ERR_VALUE = 32
817
+ XML_RELAXNG_ERR_LIST = 33
818
+ XML_RELAXNG_ERR_NOGRAMMAR = 34
819
+ XML_RELAXNG_ERR_EXTRADATA = 35
820
+ XML_RELAXNG_ERR_LACKDATA = 36
821
+ XML_RELAXNG_ERR_INTERNAL = 37
822
+ XML_RELAXNG_ERR_ELEMWRONG = 38
823
+ XML_RELAXNG_ERR_TEXTWRONG = 39
824
+ # --- END: GENERATED CONSTANTS ---
825
+
826
+ cdef extern from "libxml/xmlerror.h" nogil:
827
+ ctypedef struct xmlError:
828
+ int domain
829
+ int code
830
+ char* message
831
+ xmlErrorLevel level
832
+ char* file
833
+ char* str1
834
+ char* str2
835
+ char* str3
836
+ int line
837
+ int int1
838
+ int int2
839
+ void* node
840
+
841
+ ctypedef void (*xmlGenericErrorFunc)(void* ctxt, char* msg, ...) noexcept
842
+ ctypedef void (*xmlStructuredErrorFunc)(void* userData,
843
+ const xmlError* error) noexcept
844
+
845
+ cdef void xmlSetGenericErrorFunc(
846
+ void* ctxt, xmlGenericErrorFunc func)
847
+ cdef void xmlSetStructuredErrorFunc(
848
+ void* ctxt, xmlStructuredErrorFunc func)
849
+
850
+ cdef extern from "libxml/globals.h" nogil:
851
+ cdef xmlStructuredErrorFunc xmlStructuredError
852
+ cdef void* xmlStructuredErrorContext
llava_video/lib/python3.10/site-packages/lxml/includes/xmlparser.pxd ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from libc.string cimport const_char
2
+
3
+ from lxml.includes.tree cimport (
4
+ xmlDoc, xmlNode, xmlEntity, xmlDict, xmlDtd, xmlChar, const_xmlChar)
5
+ from lxml.includes.tree cimport xmlInputReadCallback, xmlInputCloseCallback
6
+ from lxml.includes.xmlerror cimport xmlError, xmlStructuredErrorFunc, xmlErrorLevel
7
+
8
+
9
+ cdef extern from "libxml/parser.h" nogil:
10
+ ctypedef void (*startElementNsSAX2Func)(void* ctx,
11
+ const_xmlChar* localname,
12
+ const_xmlChar* prefix,
13
+ const_xmlChar* URI,
14
+ int nb_namespaces,
15
+ const_xmlChar** namespaces,
16
+ int nb_attributes,
17
+ int nb_defaulted,
18
+ const_xmlChar** attributes) noexcept
19
+
20
+ ctypedef void (*endElementNsSAX2Func)(void* ctx,
21
+ const_xmlChar* localname,
22
+ const_xmlChar* prefix,
23
+ const_xmlChar* URI) noexcept
24
+
25
+ ctypedef void (*startElementSAXFunc)(void* ctx, const_xmlChar* name, const_xmlChar** atts) noexcept
26
+
27
+ ctypedef void (*endElementSAXFunc)(void* ctx, const_xmlChar* name) noexcept
28
+
29
+ ctypedef void (*charactersSAXFunc)(void* ctx, const_xmlChar* ch, int len) noexcept
30
+
31
+ ctypedef void (*cdataBlockSAXFunc)(void* ctx, const_xmlChar* value, int len) noexcept
32
+
33
+ ctypedef void (*commentSAXFunc)(void* ctx, const_xmlChar* value) noexcept
34
+
35
+ ctypedef void (*processingInstructionSAXFunc)(void* ctx,
36
+ const_xmlChar* target,
37
+ const_xmlChar* data) noexcept
38
+
39
+ ctypedef void (*internalSubsetSAXFunc)(void* ctx,
40
+ const_xmlChar* name,
41
+ const_xmlChar* externalID,
42
+ const_xmlChar* systemID) noexcept
43
+
44
+ ctypedef void (*endDocumentSAXFunc)(void* ctx) noexcept
45
+
46
+ ctypedef void (*startDocumentSAXFunc)(void* ctx) noexcept
47
+
48
+ ctypedef void (*referenceSAXFunc)(void * ctx, const_xmlChar* name) noexcept
49
+
50
+ ctypedef xmlEntity* (*getEntitySAXFunc)(void* ctx, const_xmlChar* name) noexcept
51
+
52
+ cdef int XML_SAX2_MAGIC
53
+
54
+ cdef extern from "libxml/tree.h" nogil:
55
+ ctypedef struct xmlParserInput:
56
+ int line
57
+ int col
58
+ int length
59
+ const_xmlChar* base
60
+ const_xmlChar* cur
61
+ const_xmlChar* end
62
+ const_char *filename
63
+
64
+ ctypedef struct xmlParserInputBuffer:
65
+ void* context
66
+ xmlInputReadCallback readcallback
67
+ xmlInputCloseCallback closecallback
68
+
69
+ ctypedef struct xmlSAXHandlerV1:
70
+ # same as xmlSAXHandler, but without namespaces
71
+ pass
72
+
73
+ ctypedef struct xmlSAXHandler:
74
+ internalSubsetSAXFunc internalSubset
75
+ startElementNsSAX2Func startElementNs
76
+ endElementNsSAX2Func endElementNs
77
+ startElementSAXFunc startElement
78
+ endElementSAXFunc endElement
79
+ charactersSAXFunc characters
80
+ cdataBlockSAXFunc cdataBlock
81
+ referenceSAXFunc reference
82
+ getEntitySAXFunc getEntity
83
+ commentSAXFunc comment
84
+ processingInstructionSAXFunc processingInstruction
85
+ startDocumentSAXFunc startDocument
86
+ endDocumentSAXFunc endDocument
87
+ int initialized
88
+ xmlStructuredErrorFunc serror
89
+ void* _private
90
+
91
+
92
+ cdef extern from "libxml/SAX2.h" nogil:
93
+ cdef void xmlSAX2StartDocument(void* ctxt)
94
+
95
+
96
+ cdef extern from "libxml/xmlIO.h" nogil:
97
+ cdef xmlParserInputBuffer* xmlAllocParserInputBuffer(int enc)
98
+
99
+
100
+ cdef extern from "libxml/parser.h" nogil:
101
+
102
+ cdef xmlDict* xmlDictCreate()
103
+ cdef xmlDict* xmlDictCreateSub(xmlDict* subdict)
104
+ cdef void xmlDictFree(xmlDict* sub)
105
+ cdef int xmlDictReference(xmlDict* dict)
106
+
107
+ cdef int XML_COMPLETE_ATTRS # SAX option for adding DTD default attributes
108
+ cdef int XML_SKIP_IDS # SAX option for not building an XML ID dict
109
+
110
+ ctypedef enum xmlParserInputState:
111
+ XML_PARSER_EOF = -1 # nothing is to be parsed
112
+ XML_PARSER_START = 0 # nothing has been parsed
113
+ XML_PARSER_MISC = 1 # Misc* before int subset
114
+ XML_PARSER_PI = 2 # Within a processing instruction
115
+ XML_PARSER_DTD = 3 # within some DTD content
116
+ XML_PARSER_PROLOG = 4 # Misc* after internal subset
117
+ XML_PARSER_COMMENT = 5 # within a comment
118
+ XML_PARSER_START_TAG = 6 # within a start tag
119
+ XML_PARSER_CONTENT = 7 # within the content
120
+ XML_PARSER_CDATA_SECTION = 8 # within a CDATA section
121
+ XML_PARSER_END_TAG = 9 # within a closing tag
122
+ XML_PARSER_ENTITY_DECL = 10 # within an entity declaration
123
+ XML_PARSER_ENTITY_VALUE = 11 # within an entity value in a decl
124
+ XML_PARSER_ATTRIBUTE_VALUE = 12 # within an attribute value
125
+ XML_PARSER_SYSTEM_LITERAL = 13 # within a SYSTEM value
126
+ XML_PARSER_EPILOG = 14 # the Misc* after the last end tag
127
+ XML_PARSER_IGNORE = 15 # within an IGNORED section
128
+ XML_PARSER_PUBLIC_LITERAL = 16 # within a PUBLIC value
129
+
130
+
131
+ ctypedef struct xmlParserCtxt:
132
+ xmlDoc* myDoc
133
+ xmlDict* dict
134
+ int dictNames
135
+ void* _private
136
+ bint wellFormed
137
+ bint recovery
138
+ int options
139
+ bint disableSAX
140
+ int errNo
141
+ xmlParserInputState instate
142
+ bint replaceEntities
143
+ int loadsubset # != 0 if enabled, int value == why
144
+ bint validate
145
+ xmlError lastError
146
+ xmlNode* node
147
+ xmlSAXHandler* sax
148
+ void* userData
149
+ int* spaceTab
150
+ int spaceMax
151
+ int nsNr
152
+ bint html
153
+ bint progressive
154
+ int inSubset
155
+ int charset
156
+ xmlParserInput* input
157
+ int inputNr
158
+ xmlParserInput* inputTab[]
159
+
160
+ ctypedef enum xmlParserOption:
161
+ XML_PARSE_RECOVER = 1 # recover on errors
162
+ XML_PARSE_NOENT = 2 # substitute entities
163
+ XML_PARSE_DTDLOAD = 4 # load the external subset
164
+ XML_PARSE_DTDATTR = 8 # default DTD attributes
165
+ XML_PARSE_DTDVALID = 16 # validate with the DTD
166
+ XML_PARSE_NOERROR = 32 # suppress error reports
167
+ XML_PARSE_NOWARNING = 64 # suppress warning reports
168
+ XML_PARSE_PEDANTIC = 128 # pedantic error reporting
169
+ XML_PARSE_NOBLANKS = 256 # remove blank nodes
170
+ XML_PARSE_SAX1 = 512 # use the SAX1 interface internally
171
+ XML_PARSE_XINCLUDE = 1024 # Implement XInclude substitution
172
+ XML_PARSE_NONET = 2048 # Forbid network access
173
+ XML_PARSE_NODICT = 4096 # Do not reuse the context dictionary
174
+ XML_PARSE_NSCLEAN = 8192 # remove redundant namespaces declarations
175
+ XML_PARSE_NOCDATA = 16384 # merge CDATA as text nodes
176
+ XML_PARSE_NOXINCNODE = 32768 # do not generate XINCLUDE START/END nodes
177
+ # libxml2 2.6.21+ only:
178
+ XML_PARSE_COMPACT = 65536 # compact small text nodes
179
+ # libxml2 2.7.0+ only:
180
+ XML_PARSE_OLD10 = 131072 # parse using XML-1.0 before update 5
181
+ XML_PARSE_NOBASEFIX = 262144 # do not fixup XINCLUDE xml:base uris
182
+ XML_PARSE_HUGE = 524288 # relax any hardcoded limit from the parser
183
+ # libxml2 2.7.3+ only:
184
+ XML_PARSE_OLDSAX = 1048576 # parse using SAX2 interface before 2.7.0
185
+ # libxml2 2.8.0+ only:
186
+ XML_PARSE_IGNORE_ENC = 2097152 # ignore internal document encoding hint
187
+ # libxml2 2.9.0+ only:
188
+ XML_PARSE_BIG_LINES = 4194304 # Store big lines numbers in text PSVI field
189
+
190
+ cdef void xmlInitParser()
191
+ cdef void xmlCleanupParser()
192
+
193
+ cdef int xmlLineNumbersDefault(int onoff)
194
+ cdef xmlParserCtxt* xmlNewParserCtxt()
195
+ cdef xmlParserInput* xmlNewIOInputStream(xmlParserCtxt* ctxt,
196
+ xmlParserInputBuffer* input,
197
+ int enc)
198
+ cdef int xmlCtxtUseOptions(xmlParserCtxt* ctxt, int options)
199
+ cdef void xmlFreeParserCtxt(xmlParserCtxt* ctxt)
200
+ cdef void xmlCtxtReset(xmlParserCtxt* ctxt)
201
+ cdef void xmlClearParserCtxt(xmlParserCtxt* ctxt)
202
+ cdef int xmlParseChunk(xmlParserCtxt* ctxt,
203
+ char* chunk, int size, int terminate)
204
+ cdef xmlDoc* xmlCtxtReadDoc(xmlParserCtxt* ctxt,
205
+ char* cur, char* URL, char* encoding,
206
+ int options)
207
+ cdef xmlDoc* xmlCtxtReadFile(xmlParserCtxt* ctxt,
208
+ char* filename, char* encoding,
209
+ int options)
210
+ cdef xmlDoc* xmlCtxtReadIO(xmlParserCtxt* ctxt,
211
+ xmlInputReadCallback ioread,
212
+ xmlInputCloseCallback ioclose,
213
+ void* ioctx,
214
+ char* URL, char* encoding,
215
+ int options)
216
+ cdef xmlDoc* xmlCtxtReadMemory(xmlParserCtxt* ctxt,
217
+ char* buffer, int size,
218
+ char* filename, const_char* encoding,
219
+ int options)
220
+
221
+ cdef void xmlErrParser(xmlParserCtxt* ctxt, xmlNode* node,
222
+ int domain, int code, xmlErrorLevel level,
223
+ const xmlChar *str1, const xmlChar *str2, const xmlChar *str3,
224
+ int int1, const char *msg, ...)
225
+
226
+
227
+ # iterparse:
228
+
229
+ cdef xmlParserCtxt* xmlCreatePushParserCtxt(xmlSAXHandler* sax,
230
+ void* user_data,
231
+ char* chunk,
232
+ int size,
233
+ char* filename)
234
+
235
+ cdef int xmlCtxtResetPush(xmlParserCtxt* ctxt,
236
+ char* chunk,
237
+ int size,
238
+ char* filename,
239
+ char* encoding)
240
+
241
+ # entity loaders:
242
+
243
+ ctypedef xmlParserInput* (*xmlExternalEntityLoader)(
244
+ const_char * URL, const_char * ID, xmlParserCtxt* context) noexcept
245
+ cdef xmlExternalEntityLoader xmlGetExternalEntityLoader()
246
+ cdef void xmlSetExternalEntityLoader(xmlExternalEntityLoader f)
247
+
248
+ cdef xmlEntity* xmlSAX2GetEntity(void* ctxt, const_xmlChar* name) noexcept
249
+
250
+ # DTDs:
251
+
252
+ cdef xmlDtd* xmlParseDTD(const_xmlChar* ExternalID, const_xmlChar* SystemID)
253
+ cdef xmlDtd* xmlIOParseDTD(xmlSAXHandler* sax,
254
+ xmlParserInputBuffer* input,
255
+ int enc)
256
+
257
+
258
+ cdef extern from "libxml/parserInternals.h" nogil:
259
+ cdef xmlParserInput* xmlNewInputStream(xmlParserCtxt* ctxt)
260
+ cdef xmlParserInput* xmlNewStringInputStream(xmlParserCtxt* ctxt,
261
+ char* buffer)
262
+ cdef xmlParserInput* xmlNewInputFromFile(xmlParserCtxt* ctxt,
263
+ char* filename)
264
+ cdef void xmlFreeInputStream(xmlParserInput* input)
265
+ cdef int xmlSwitchEncoding(xmlParserCtxt* ctxt, int enc)
llava_video/lib/python3.10/site-packages/lxml/includes/xmlschema.pxd ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes.tree cimport xmlDoc
2
+ from lxml.includes.xmlparser cimport xmlSAXHandler
3
+ from lxml.includes.xmlerror cimport xmlStructuredErrorFunc
4
+
5
+ cdef extern from "libxml/xmlschemas.h" nogil:
6
+ ctypedef struct xmlSchema
7
+ ctypedef struct xmlSchemaParserCtxt
8
+
9
+ ctypedef struct xmlSchemaSAXPlugStruct
10
+ ctypedef struct xmlSchemaValidCtxt
11
+
12
+ ctypedef enum xmlSchemaValidOption:
13
+ XML_SCHEMA_VAL_VC_I_CREATE = 1
14
+
15
+ cdef xmlSchemaValidCtxt* xmlSchemaNewValidCtxt(xmlSchema* schema) nogil
16
+ cdef void xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxt* ctxt,
17
+ xmlStructuredErrorFunc serror, void *ctx)
18
+ cdef void xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxt* ctxt,
19
+ xmlStructuredErrorFunc serror, void *ctx)
20
+
21
+ cdef int xmlSchemaValidateDoc(xmlSchemaValidCtxt* ctxt, xmlDoc* doc) nogil
22
+ cdef xmlSchema* xmlSchemaParse(xmlSchemaParserCtxt* ctxt) nogil
23
+ cdef xmlSchemaParserCtxt* xmlSchemaNewParserCtxt(char* URL) nogil
24
+ cdef xmlSchemaParserCtxt* xmlSchemaNewDocParserCtxt(xmlDoc* doc) nogil
25
+ cdef void xmlSchemaFree(xmlSchema* schema) nogil
26
+ cdef void xmlSchemaFreeParserCtxt(xmlSchemaParserCtxt* ctxt) nogil
27
+ cdef void xmlSchemaFreeValidCtxt(xmlSchemaValidCtxt* ctxt) nogil
28
+ cdef int xmlSchemaSetValidOptions(xmlSchemaValidCtxt* ctxt,
29
+ int options) nogil
30
+
31
+ cdef xmlSchemaSAXPlugStruct* xmlSchemaSAXPlug(xmlSchemaValidCtxt* ctxt,
32
+ xmlSAXHandler** sax,
33
+ void** data) nogil
34
+ cdef int xmlSchemaSAXUnplug(xmlSchemaSAXPlugStruct* sax_plug)
35
+ cdef int xmlSchemaIsValid(xmlSchemaValidCtxt* ctxt)
llava_video/lib/python3.10/site-packages/lxml/includes/xpath.pxd ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes cimport tree
2
+ from lxml.includes cimport xmlerror
3
+
4
+ from libc.string cimport const_char
5
+ from lxml.includes.tree cimport xmlChar, const_xmlChar
6
+
7
+
8
+ cdef extern from "libxml/xpath.h" nogil:
9
+ ctypedef enum xmlXPathObjectType:
10
+ XPATH_UNDEFINED = 0
11
+ XPATH_NODESET = 1
12
+ XPATH_BOOLEAN = 2
13
+ XPATH_NUMBER = 3
14
+ XPATH_STRING = 4
15
+ XPATH_POINT = 5
16
+ XPATH_RANGE = 6
17
+ XPATH_LOCATIONSET = 7
18
+ XPATH_USERS = 8
19
+ XPATH_XSLT_TREE = 9
20
+
21
+ ctypedef enum xmlXPathError:
22
+ XPATH_EXPRESSION_OK = 0
23
+ XPATH_NUMBER_ERROR = 1
24
+ XPATH_UNFINISHED_LITERAL_ERROR = 2
25
+ XPATH_START_LITERAL_ERROR = 3
26
+ XPATH_VARIABLE_REF_ERROR = 4
27
+ XPATH_UNDEF_VARIABLE_ERROR = 5
28
+ XPATH_INVALID_PREDICATE_ERROR = 6
29
+ XPATH_EXPR_ERROR = 7
30
+ XPATH_UNCLOSED_ERROR = 8
31
+ XPATH_UNKNOWN_FUNC_ERROR = 9
32
+ XPATH_INVALID_OPERAND = 10
33
+ XPATH_INVALID_TYPE = 11
34
+ XPATH_INVALID_ARITY = 12
35
+ XPATH_INVALID_CTXT_SIZE = 13
36
+ XPATH_INVALID_CTXT_POSITION = 14
37
+ XPATH_MEMORY_ERROR = 15
38
+ XPTR_SYNTAX_ERROR = 16
39
+ XPTR_RESOURCE_ERROR = 17
40
+ XPTR_SUB_RESOURCE_ERROR = 18
41
+ XPATH_UNDEF_PREFIX_ERROR = 19
42
+ XPATH_ENCODING_ERROR = 20
43
+ XPATH_INVALID_CHAR_ERROR = 21
44
+ XPATH_INVALID_CTXT = 22
45
+
46
+ ctypedef struct xmlNodeSet:
47
+ int nodeNr
48
+ int nodeMax
49
+ tree.xmlNode** nodeTab
50
+
51
+ ctypedef struct xmlXPathObject:
52
+ xmlXPathObjectType type
53
+ xmlNodeSet* nodesetval
54
+ bint boolval
55
+ double floatval
56
+ xmlChar* stringval
57
+
58
+ ctypedef struct xmlXPathContext:
59
+ tree.xmlDoc* doc
60
+ tree.xmlNode* node
61
+ tree.xmlDict* dict
62
+ tree.xmlHashTable* nsHash
63
+ const_xmlChar* function
64
+ const_xmlChar* functionURI
65
+ xmlerror.xmlStructuredErrorFunc error
66
+ xmlerror.xmlError lastError
67
+ void* userData
68
+
69
+ ctypedef struct xmlXPathParserContext:
70
+ xmlXPathContext* context
71
+ xmlXPathObject* value
72
+ tree.xmlNode* ancestor
73
+ int error
74
+
75
+ ctypedef struct xmlXPathCompExpr
76
+
77
+ ctypedef void (*xmlXPathFunction)(xmlXPathParserContext* ctxt, int nargs)
78
+ ctypedef xmlXPathFunction (*xmlXPathFuncLookupFunc)(void* ctxt,
79
+ const_xmlChar* name,
80
+ const_xmlChar* ns_uri)
81
+
82
+ cdef xmlXPathContext* xmlXPathNewContext(tree.xmlDoc* doc)
83
+ cdef xmlXPathObject* xmlXPathEvalExpression(const_xmlChar* str,
84
+ xmlXPathContext* ctxt)
85
+ cdef xmlXPathObject* xmlXPathCompiledEval(xmlXPathCompExpr* comp,
86
+ xmlXPathContext* ctxt)
87
+ cdef xmlXPathCompExpr* xmlXPathCompile(const_xmlChar* str)
88
+ cdef xmlXPathCompExpr* xmlXPathCtxtCompile(xmlXPathContext* ctxt,
89
+ const_xmlChar* str)
90
+ cdef void xmlXPathFreeContext(xmlXPathContext* ctxt)
91
+ cdef void xmlXPathFreeCompExpr(xmlXPathCompExpr* comp)
92
+ cdef void xmlXPathFreeObject(xmlXPathObject* obj)
93
+ cdef int xmlXPathRegisterNs(xmlXPathContext* ctxt,
94
+ const_xmlChar* prefix, const_xmlChar* ns_uri)
95
+
96
+ cdef xmlNodeSet* xmlXPathNodeSetCreate(tree.xmlNode* val)
97
+ cdef void xmlXPathFreeNodeSet(xmlNodeSet* val)
98
+
99
+
100
+ cdef extern from "libxml/xpathInternals.h" nogil:
101
+ cdef int xmlXPathRegisterFunc(xmlXPathContext* ctxt,
102
+ const_xmlChar* name,
103
+ xmlXPathFunction f)
104
+ cdef int xmlXPathRegisterFuncNS(xmlXPathContext* ctxt,
105
+ const_xmlChar* name,
106
+ const_xmlChar* ns_uri,
107
+ xmlXPathFunction f)
108
+ cdef void xmlXPathRegisterFuncLookup(xmlXPathContext *ctxt,
109
+ xmlXPathFuncLookupFunc f,
110
+ void *funcCtxt)
111
+ cdef int xmlXPathRegisterVariable(xmlXPathContext *ctxt,
112
+ const_xmlChar* name,
113
+ xmlXPathObject* value)
114
+ cdef int xmlXPathRegisterVariableNS(xmlXPathContext *ctxt,
115
+ const_xmlChar* name,
116
+ const_xmlChar* ns_uri,
117
+ xmlXPathObject* value)
118
+ cdef void xmlXPathRegisteredVariablesCleanup(xmlXPathContext *ctxt)
119
+ cdef void xmlXPathRegisteredNsCleanup(xmlXPathContext *ctxt)
120
+ cdef xmlXPathObject* valuePop (xmlXPathParserContext *ctxt)
121
+ cdef int valuePush(xmlXPathParserContext* ctxt, xmlXPathObject *value)
122
+
123
+ cdef xmlXPathObject* xmlXPathNewCString(const_char *val)
124
+ cdef xmlXPathObject* xmlXPathWrapCString(const_char * val)
125
+ cdef xmlXPathObject* xmlXPathNewString(const_xmlChar *val)
126
+ cdef xmlXPathObject* xmlXPathWrapString(const_xmlChar * val)
127
+ cdef xmlXPathObject* xmlXPathNewFloat(double val)
128
+ cdef xmlXPathObject* xmlXPathNewBoolean(int val)
129
+ cdef xmlXPathObject* xmlXPathNewNodeSet(tree.xmlNode* val)
130
+ cdef xmlXPathObject* xmlXPathNewValueTree(tree.xmlNode* val)
131
+ cdef void xmlXPathNodeSetAdd(xmlNodeSet* cur,
132
+ tree.xmlNode* val)
133
+ cdef void xmlXPathNodeSetAddUnique(xmlNodeSet* cur,
134
+ tree.xmlNode* val)
135
+ cdef xmlXPathObject* xmlXPathWrapNodeSet(xmlNodeSet* val)
136
+ cdef void xmlXPathErr(xmlXPathParserContext* ctxt, int error)
llava_video/lib/python3.10/site-packages/lxml/includes/xslt.pxd ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.includes.tree cimport xmlDoc, xmlNode, xmlDict, xmlChar, const_xmlChar, xmlOutputBuffer
2
+ from lxml.includes.xmlerror cimport xmlGenericErrorFunc
3
+ from lxml.includes.xpath cimport xmlXPathContext, xmlXPathFunction
4
+
5
+ from libc.string cimport const_char
6
+
7
+ cdef extern from "libxslt/xslt.h":
8
+ cdef int xsltLibxsltVersion
9
+ cdef int xsltMaxDepth
10
+
11
+ cdef extern from "libxslt/xsltconfig.h":
12
+ cdef int LIBXSLT_VERSION
13
+
14
+ cdef extern from "libxslt/xsltInternals.h" nogil:
15
+ ctypedef enum xsltTransformState:
16
+ XSLT_STATE_OK # 0
17
+ XSLT_STATE_ERROR # 1
18
+ XSLT_STATE_STOPPED # 2
19
+
20
+ ctypedef struct xsltDocument:
21
+ xmlDoc* doc
22
+
23
+ ctypedef struct xsltStylesheet:
24
+ xmlChar* encoding
25
+ xmlDoc* doc
26
+ int errors
27
+
28
+ ctypedef struct xsltTransformContext:
29
+ xsltStylesheet* style
30
+ xmlXPathContext* xpathCtxt
31
+ xsltDocument* document
32
+ void* _private
33
+ xmlDict* dict
34
+ int profile
35
+ xmlNode* node
36
+ xmlDoc* output
37
+ xmlNode* insert
38
+ xmlNode* inst
39
+ xsltTransformState state
40
+
41
+ ctypedef struct xsltStackElem
42
+
43
+ ctypedef struct xsltTemplate
44
+
45
+ cdef xsltStylesheet* xsltParseStylesheetDoc(xmlDoc* doc)
46
+ cdef void xsltFreeStylesheet(xsltStylesheet* sheet)
47
+
48
+ cdef extern from "libxslt/imports.h" nogil:
49
+ # actually defined in "etree_defs.h"
50
+ cdef void LXML_GET_XSLT_ENCODING(const_xmlChar* result_var, xsltStylesheet* style)
51
+
52
+ cdef extern from "libxslt/extensions.h" nogil:
53
+ ctypedef void (*xsltTransformFunction)(xsltTransformContext* ctxt,
54
+ xmlNode* context_node,
55
+ xmlNode* inst,
56
+ void* precomp_unused) noexcept
57
+
58
+ cdef int xsltRegisterExtFunction(xsltTransformContext* ctxt,
59
+ const_xmlChar* name,
60
+ const_xmlChar* URI,
61
+ xmlXPathFunction function)
62
+ cdef int xsltRegisterExtModuleFunction(const_xmlChar* name, const_xmlChar* URI,
63
+ xmlXPathFunction function)
64
+ cdef int xsltUnregisterExtModuleFunction(const_xmlChar* name, const_xmlChar* URI)
65
+ cdef xmlXPathFunction xsltExtModuleFunctionLookup(
66
+ const_xmlChar* name, const_xmlChar* URI)
67
+ cdef int xsltRegisterExtPrefix(xsltStylesheet* style,
68
+ const_xmlChar* prefix, const_xmlChar* URI)
69
+ cdef int xsltRegisterExtElement(xsltTransformContext* ctxt,
70
+ const_xmlChar* name, const_xmlChar* URI,
71
+ xsltTransformFunction function)
72
+
73
+ cdef extern from "libxslt/documents.h" nogil:
74
+ ctypedef enum xsltLoadType:
75
+ XSLT_LOAD_START
76
+ XSLT_LOAD_STYLESHEET
77
+ XSLT_LOAD_DOCUMENT
78
+
79
+ ctypedef xmlDoc* (*xsltDocLoaderFunc)(const_xmlChar* URI, xmlDict* dict,
80
+ int options,
81
+ void* ctxt,
82
+ xsltLoadType type) noexcept
83
+ cdef xsltDocLoaderFunc xsltDocDefaultLoader
84
+ cdef void xsltSetLoaderFunc(xsltDocLoaderFunc f)
85
+
86
+ cdef extern from "libxslt/transform.h" nogil:
87
+ cdef xmlDoc* xsltApplyStylesheet(xsltStylesheet* style, xmlDoc* doc,
88
+ const_char** params)
89
+ cdef xmlDoc* xsltApplyStylesheetUser(xsltStylesheet* style, xmlDoc* doc,
90
+ const_char** params, const_char* output,
91
+ void* profile,
92
+ xsltTransformContext* context)
93
+ cdef void xsltProcessOneNode(xsltTransformContext* ctxt,
94
+ xmlNode* contextNode,
95
+ xsltStackElem* params)
96
+ cdef xsltTransformContext* xsltNewTransformContext(xsltStylesheet* style,
97
+ xmlDoc* doc)
98
+ cdef void xsltFreeTransformContext(xsltTransformContext* context)
99
+ cdef void xsltApplyOneTemplate(xsltTransformContext* ctxt,
100
+ xmlNode* contextNode, xmlNode* list,
101
+ xsltTemplate* templ,
102
+ xsltStackElem* params)
103
+
104
+
105
+ cdef extern from "libxslt/xsltutils.h" nogil:
106
+ cdef int xsltSaveResultToString(xmlChar** doc_txt_ptr,
107
+ int* doc_txt_len,
108
+ xmlDoc* result,
109
+ xsltStylesheet* style)
110
+ cdef int xsltSaveResultToFilename(const_char *URL,
111
+ xmlDoc* result,
112
+ xsltStylesheet* style,
113
+ int compression)
114
+ cdef int xsltSaveResultTo(xmlOutputBuffer* buf,
115
+ xmlDoc* result,
116
+ xsltStylesheet* style)
117
+ cdef xmlGenericErrorFunc xsltGenericError
118
+ cdef void *xsltGenericErrorContext
119
+ cdef void xsltSetGenericErrorFunc(
120
+ void* ctxt, void (*handler)(void* ctxt, char* msg, ...) nogil)
121
+ cdef void xsltSetTransformErrorFunc(
122
+ xsltTransformContext*, void* ctxt,
123
+ void (*handler)(void* ctxt, char* msg, ...) nogil)
124
+ cdef void xsltTransformError(xsltTransformContext* ctxt,
125
+ xsltStylesheet* style,
126
+ xmlNode* node, char* msg, ...)
127
+ cdef void xsltSetCtxtParseOptions(
128
+ xsltTransformContext* ctxt, int options)
129
+
130
+
131
+ cdef extern from "libxslt/security.h" nogil:
132
+ ctypedef struct xsltSecurityPrefs
133
+ ctypedef enum xsltSecurityOption:
134
+ XSLT_SECPREF_READ_FILE = 1
135
+ XSLT_SECPREF_WRITE_FILE = 2
136
+ XSLT_SECPREF_CREATE_DIRECTORY = 3
137
+ XSLT_SECPREF_READ_NETWORK = 4
138
+ XSLT_SECPREF_WRITE_NETWORK = 5
139
+
140
+ ctypedef int (*xsltSecurityCheck)(xsltSecurityPrefs* sec,
141
+ xsltTransformContext* ctxt,
142
+ char* value) noexcept
143
+
144
+ cdef xsltSecurityPrefs* xsltNewSecurityPrefs()
145
+ cdef void xsltFreeSecurityPrefs(xsltSecurityPrefs* sec)
146
+ cdef int xsltSecurityForbid(xsltSecurityPrefs* sec,
147
+ xsltTransformContext* ctxt,
148
+ char* value)
149
+ cdef int xsltSecurityAllow(xsltSecurityPrefs* sec,
150
+ xsltTransformContext* ctxt,
151
+ char* value)
152
+ cdef int xsltSetSecurityPrefs(xsltSecurityPrefs* sec,
153
+ xsltSecurityOption option,
154
+ xsltSecurityCheck func)
155
+ cdef xsltSecurityCheck xsltGetSecurityPrefs(
156
+ xsltSecurityPrefs* sec,
157
+ xsltSecurityOption option)
158
+ cdef int xsltSetCtxtSecurityPrefs(xsltSecurityPrefs* sec,
159
+ xsltTransformContext* ctxt)
160
+ cdef xmlDoc* xsltGetProfileInformation(xsltTransformContext* ctxt)
161
+
162
+ cdef extern from "libxslt/variables.h" nogil:
163
+ cdef int xsltQuoteUserParams(xsltTransformContext* ctxt,
164
+ const_char** params)
165
+ cdef int xsltQuoteOneUserParam(xsltTransformContext* ctxt,
166
+ const_xmlChar* name,
167
+ const_xmlChar* value)
168
+
169
+ cdef extern from "libxslt/extra.h" nogil:
170
+ const_xmlChar* XSLT_LIBXSLT_NAMESPACE
171
+ const_xmlChar* XSLT_XALAN_NAMESPACE
172
+ const_xmlChar* XSLT_SAXON_NAMESPACE
173
+ const_xmlChar* XSLT_XT_NAMESPACE
174
+
175
+ cdef xmlXPathFunction xsltFunctionNodeSet
176
+ cdef void xsltRegisterAllExtras()
177
+
178
+ cdef extern from "libexslt/exslt.h" nogil:
179
+ cdef void exsltRegisterAll()
180
+
181
+ # libexslt 1.1.25+
182
+ const_xmlChar* EXSLT_DATE_NAMESPACE
183
+ const_xmlChar* EXSLT_SETS_NAMESPACE
184
+ const_xmlChar* EXSLT_MATH_NAMESPACE
185
+ const_xmlChar* EXSLT_STRINGS_NAMESPACE
186
+
187
+ cdef int exsltDateXpathCtxtRegister(xmlXPathContext* ctxt, const_xmlChar* prefix)
188
+ cdef int exsltSetsXpathCtxtRegister(xmlXPathContext* ctxt, const_xmlChar* prefix)
189
+ cdef int exsltMathXpathCtxtRegister(xmlXPathContext* ctxt, const_xmlChar* prefix)
190
+ cdef int exsltStrXpathCtxtRegister(xmlXPathContext* ctxt, const_xmlChar* prefix)
llava_video/lib/python3.10/site-packages/lxml/iterparse.pxi ADDED
@@ -0,0 +1,438 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # iterparse -- event-driven parsing
2
+
3
+ DEF __ITERPARSE_CHUNK_SIZE = 32768
4
+
5
+ cdef class iterparse:
6
+ """iterparse(self, source, events=("end",), tag=None, \
7
+ attribute_defaults=False, dtd_validation=False, \
8
+ load_dtd=False, no_network=True, remove_blank_text=False, \
9
+ remove_comments=False, remove_pis=False, encoding=None, \
10
+ html=False, recover=None, huge_tree=False, schema=None)
11
+
12
+ Incremental parser.
13
+
14
+ Parses XML into a tree and generates tuples (event, element) in a
15
+ SAX-like fashion. ``event`` is any of 'start', 'end', 'start-ns',
16
+ 'end-ns'.
17
+
18
+ For 'start' and 'end', ``element`` is the Element that the parser just
19
+ found opening or closing. For 'start-ns', it is a tuple (prefix, URI) of
20
+ a new namespace declaration. For 'end-ns', it is simply None. Note that
21
+ all start and end events are guaranteed to be properly nested.
22
+
23
+ The keyword argument ``events`` specifies a sequence of event type names
24
+ that should be generated. By default, only 'end' events will be
25
+ generated.
26
+
27
+ The additional ``tag`` argument restricts the 'start' and 'end' events to
28
+ those elements that match the given tag. The ``tag`` argument can also be
29
+ a sequence of tags to allow matching more than one tag. By default,
30
+ events are generated for all elements. Note that the 'start-ns' and
31
+ 'end-ns' events are not impacted by this restriction.
32
+
33
+ The other keyword arguments in the constructor are mainly based on the
34
+ libxml2 parser configuration. A DTD will also be loaded if validation or
35
+ attribute default values are requested.
36
+
37
+ Available boolean keyword arguments:
38
+ - attribute_defaults: read default attributes from DTD
39
+ - dtd_validation: validate (if DTD is available)
40
+ - load_dtd: use DTD for parsing
41
+ - no_network: prevent network access for related files
42
+ - remove_blank_text: discard blank text nodes
43
+ - remove_comments: discard comments
44
+ - remove_pis: discard processing instructions
45
+ - strip_cdata: replace CDATA sections by normal text content (default:
46
+ True for XML, ignored otherwise)
47
+ - compact: safe memory for short text content (default: True)
48
+ - resolve_entities: replace entities by their text value (default: True)
49
+ - huge_tree: disable security restrictions and support very deep trees
50
+ and very long text content (only affects libxml2 2.7+)
51
+ - html: parse input as HTML (default: XML)
52
+ - recover: try hard to parse through broken input (default: True for HTML,
53
+ False otherwise)
54
+
55
+ Other keyword arguments:
56
+ - encoding: override the document encoding
57
+ - schema: an XMLSchema to validate against
58
+ """
59
+ cdef _FeedParser _parser
60
+ cdef object _tag
61
+ cdef object _events
62
+ cdef readonly object root
63
+ cdef object _source
64
+ cdef object _filename
65
+ cdef object _error
66
+ cdef bint _close_source_after_read
67
+
68
+ def __init__(self, source, events=("end",), *, tag=None,
69
+ attribute_defaults=False, dtd_validation=False,
70
+ load_dtd=False, no_network=True, remove_blank_text=False,
71
+ compact=True, resolve_entities=True, remove_comments=False,
72
+ remove_pis=False, strip_cdata=True, encoding=None,
73
+ html=False, recover=None, huge_tree=False, collect_ids=True,
74
+ XMLSchema schema=None):
75
+ if not hasattr(source, 'read'):
76
+ source = _getFSPathOrObject(source)
77
+ self._filename = source
78
+ self._source = open(source, 'rb')
79
+ self._close_source_after_read = True
80
+ else:
81
+ self._filename = _getFilenameForFile(source)
82
+ self._source = source
83
+ self._close_source_after_read = False
84
+
85
+ if recover is None:
86
+ recover = html
87
+
88
+ if html:
89
+ # make sure we're not looking for namespaces
90
+ events = [event for event in events
91
+ if event not in ('start-ns', 'end-ns')]
92
+ parser = HTMLPullParser(
93
+ events,
94
+ tag=tag,
95
+ recover=recover,
96
+ base_url=self._filename,
97
+ encoding=encoding,
98
+ remove_blank_text=remove_blank_text,
99
+ remove_comments=remove_comments,
100
+ remove_pis=remove_pis,
101
+ no_network=no_network,
102
+ target=None, # TODO
103
+ schema=schema,
104
+ compact=compact)
105
+ else:
106
+ parser = XMLPullParser(
107
+ events,
108
+ tag=tag,
109
+ recover=recover,
110
+ base_url=self._filename,
111
+ encoding=encoding,
112
+ attribute_defaults=attribute_defaults,
113
+ dtd_validation=dtd_validation,
114
+ load_dtd=load_dtd,
115
+ no_network=no_network,
116
+ schema=schema,
117
+ huge_tree=huge_tree,
118
+ remove_blank_text=remove_blank_text,
119
+ resolve_entities=resolve_entities,
120
+ remove_comments=remove_comments,
121
+ remove_pis=remove_pis,
122
+ strip_cdata=strip_cdata,
123
+ collect_ids=True,
124
+ target=None, # TODO
125
+ compact=compact)
126
+
127
+ self._events = parser.read_events()
128
+ self._parser = parser
129
+
130
+ @property
131
+ def error_log(self):
132
+ """The error log of the last (or current) parser run.
133
+ """
134
+ return self._parser.feed_error_log
135
+
136
+ @property
137
+ def resolvers(self):
138
+ """The custom resolver registry of the last (or current) parser run.
139
+ """
140
+ return self._parser.resolvers
141
+
142
+ @property
143
+ def version(self):
144
+ """The version of the underlying XML parser."""
145
+ return self._parser.version
146
+
147
+ def set_element_class_lookup(self, ElementClassLookup lookup = None):
148
+ """set_element_class_lookup(self, lookup = None)
149
+
150
+ Set a lookup scheme for element classes generated from this parser.
151
+
152
+ Reset it by passing None or nothing.
153
+ """
154
+ self._parser.set_element_class_lookup(lookup)
155
+
156
+ def makeelement(self, _tag, attrib=None, nsmap=None, **_extra):
157
+ """makeelement(self, _tag, attrib=None, nsmap=None, **_extra)
158
+
159
+ Creates a new element associated with this parser.
160
+ """
161
+ self._parser.makeelement(
162
+ _tag, attrib=None, nsmap=None, **_extra)
163
+
164
+ @cython.final
165
+ cdef _close_source(self):
166
+ if self._source is None:
167
+ return
168
+ if not self._close_source_after_read:
169
+ self._source = None
170
+ return
171
+ try:
172
+ close = self._source.close
173
+ except AttributeError:
174
+ close = None
175
+ finally:
176
+ self._source = None
177
+ if close is not None:
178
+ close()
179
+
180
+ def __iter__(self):
181
+ return self
182
+
183
+ def __next__(self):
184
+ try:
185
+ return next(self._events)
186
+ except StopIteration:
187
+ pass
188
+ context = <_SaxParserContext>self._parser._getPushParserContext()
189
+ if self._source is not None:
190
+ done = False
191
+ while not done:
192
+ try:
193
+ done = self._read_more_events(context)
194
+ return next(self._events)
195
+ except StopIteration:
196
+ pass # no events yet
197
+ except Exception as e:
198
+ self._error = e
199
+ self._close_source()
200
+ try:
201
+ return next(self._events)
202
+ except StopIteration:
203
+ break
204
+ # nothing left to read or return
205
+ if self._error is not None:
206
+ error = self._error
207
+ self._error = None
208
+ raise error
209
+ if (context._validator is not None
210
+ and not context._validator.isvalid()):
211
+ _raiseParseError(context._c_ctxt, self._filename,
212
+ context._error_log)
213
+ # no errors => all done
214
+ raise StopIteration
215
+
216
+ @cython.final
217
+ cdef bint _read_more_events(self, _SaxParserContext context) except -123:
218
+ data = self._source.read(__ITERPARSE_CHUNK_SIZE)
219
+ if not isinstance(data, bytes):
220
+ self._close_source()
221
+ raise TypeError("reading file objects must return bytes objects")
222
+ if not data:
223
+ try:
224
+ self.root = self._parser.close()
225
+ finally:
226
+ self._close_source()
227
+ return True
228
+ self._parser.feed(data)
229
+ return False
230
+
231
+
232
+ cdef enum _IterwalkSkipStates:
233
+ IWSKIP_NEXT_IS_START
234
+ IWSKIP_SKIP_NEXT
235
+ IWSKIP_CAN_SKIP
236
+ IWSKIP_CANNOT_SKIP
237
+
238
+
239
+ cdef class iterwalk:
240
+ """iterwalk(self, element_or_tree, events=("end",), tag=None)
241
+
242
+ A tree walker that generates events from an existing tree as if it
243
+ was parsing XML data with ``iterparse()``.
244
+
245
+ Just as for ``iterparse()``, the ``tag`` argument can be a single tag or a
246
+ sequence of tags.
247
+
248
+ After receiving a 'start' or 'start-ns' event, the children and
249
+ descendants of the current element can be excluded from iteration
250
+ by calling the ``skip_subtree()`` method.
251
+ """
252
+ cdef _MultiTagMatcher _matcher
253
+ cdef list _node_stack
254
+ cdef list _events
255
+ cdef object _pop_event
256
+ cdef object _include_siblings
257
+ cdef int _index
258
+ cdef int _event_filter
259
+ cdef _IterwalkSkipStates _skip_state
260
+
261
+ def __init__(self, element_or_tree, events=("end",), tag=None):
262
+ cdef _Element root
263
+ cdef int ns_count
264
+ root = _rootNodeOrRaise(element_or_tree)
265
+ self._event_filter = _buildParseEventFilter(events)
266
+ if tag is None or tag == '*':
267
+ self._matcher = None
268
+ else:
269
+ self._matcher = _MultiTagMatcher.__new__(_MultiTagMatcher, tag)
270
+ self._node_stack = []
271
+ self._events = []
272
+ self._pop_event = self._events.pop
273
+ self._skip_state = IWSKIP_CANNOT_SKIP # ignore all skip requests by default
274
+
275
+ if self._event_filter:
276
+ self._index = 0
277
+ if self._matcher is not None and self._event_filter & PARSE_EVENT_FILTER_START:
278
+ self._matcher.cacheTags(root._doc)
279
+
280
+ # When processing an ElementTree, add events for the preceding comments/PIs.
281
+ if self._event_filter & (PARSE_EVENT_FILTER_COMMENT | PARSE_EVENT_FILTER_PI):
282
+ if isinstance(element_or_tree, _ElementTree):
283
+ self._include_siblings = root
284
+ for elem in list(root.itersiblings(preceding=True))[::-1]:
285
+ if self._event_filter & PARSE_EVENT_FILTER_COMMENT and elem.tag is Comment:
286
+ self._events.append(('comment', elem))
287
+ elif self._event_filter & PARSE_EVENT_FILTER_PI and elem.tag is PI:
288
+ self._events.append(('pi', elem))
289
+
290
+ ns_count = self._start_node(root)
291
+ self._node_stack.append( (root, ns_count) )
292
+ else:
293
+ self._index = -1
294
+
295
+ def __iter__(self):
296
+ return self
297
+
298
+ def __next__(self):
299
+ cdef xmlNode* c_child
300
+ cdef _Element node
301
+ cdef _Element next_node
302
+ cdef int ns_count = 0
303
+ if self._events:
304
+ return self._next_event()
305
+ if self._matcher is not None and self._index >= 0:
306
+ node = self._node_stack[self._index][0]
307
+ self._matcher.cacheTags(node._doc)
308
+
309
+ # find next node
310
+ while self._index >= 0:
311
+ node = self._node_stack[self._index][0]
312
+
313
+ if self._skip_state == IWSKIP_SKIP_NEXT:
314
+ c_child = NULL
315
+ else:
316
+ c_child = self._process_non_elements(
317
+ node._doc, _findChildForwards(node._c_node, 0))
318
+ self._skip_state = IWSKIP_CANNOT_SKIP
319
+
320
+ while c_child is NULL:
321
+ # back off through parents
322
+ self._index -= 1
323
+ node = self._end_node()
324
+ if self._index < 0:
325
+ break
326
+ c_child = self._process_non_elements(
327
+ node._doc, _nextElement(node._c_node))
328
+
329
+ if c_child is not NULL:
330
+ next_node = _elementFactory(node._doc, c_child)
331
+ if self._event_filter & (PARSE_EVENT_FILTER_START |
332
+ PARSE_EVENT_FILTER_START_NS):
333
+ ns_count = self._start_node(next_node)
334
+ elif self._event_filter & PARSE_EVENT_FILTER_END_NS:
335
+ ns_count = _countNsDefs(next_node._c_node)
336
+ self._node_stack.append( (next_node, ns_count) )
337
+ self._index += 1
338
+ if self._events:
339
+ return self._next_event()
340
+
341
+ if self._include_siblings is not None:
342
+ node, self._include_siblings = self._include_siblings, None
343
+ self._process_non_elements(node._doc, _nextElement(node._c_node))
344
+ if self._events:
345
+ return self._next_event()
346
+
347
+ raise StopIteration
348
+
349
+ @cython.final
350
+ cdef xmlNode* _process_non_elements(self, _Document doc, xmlNode* c_node):
351
+ while c_node is not NULL and c_node.type != tree.XML_ELEMENT_NODE:
352
+ if c_node.type == tree.XML_COMMENT_NODE:
353
+ if self._event_filter & PARSE_EVENT_FILTER_COMMENT:
354
+ self._events.append(
355
+ ("comment", _elementFactory(doc, c_node)))
356
+ c_node = _nextElement(c_node)
357
+ elif c_node.type == tree.XML_PI_NODE:
358
+ if self._event_filter & PARSE_EVENT_FILTER_PI:
359
+ self._events.append(
360
+ ("pi", _elementFactory(doc, c_node)))
361
+ c_node = _nextElement(c_node)
362
+ else:
363
+ break
364
+ return c_node
365
+
366
+ @cython.final
367
+ cdef _next_event(self):
368
+ if self._skip_state == IWSKIP_NEXT_IS_START:
369
+ if self._events[0][0] in ('start', 'start-ns'):
370
+ self._skip_state = IWSKIP_CAN_SKIP
371
+ return self._pop_event(0)
372
+
373
+ def skip_subtree(self):
374
+ """Prevent descending into the current subtree.
375
+ Instead, the next returned event will be the 'end' event of the current element
376
+ (if included), ignoring any children or descendants.
377
+
378
+ This has no effect right after an 'end' or 'end-ns' event.
379
+ """
380
+ if self._skip_state == IWSKIP_CAN_SKIP:
381
+ self._skip_state = IWSKIP_SKIP_NEXT
382
+
383
+ @cython.final
384
+ cdef int _start_node(self, _Element node) except -1:
385
+ cdef int ns_count
386
+ if self._event_filter & PARSE_EVENT_FILTER_START_NS:
387
+ ns_count = _appendStartNsEvents(node._c_node, self._events)
388
+ if self._events:
389
+ self._skip_state = IWSKIP_NEXT_IS_START
390
+ elif self._event_filter & PARSE_EVENT_FILTER_END_NS:
391
+ ns_count = _countNsDefs(node._c_node)
392
+ else:
393
+ ns_count = 0
394
+ if self._event_filter & PARSE_EVENT_FILTER_START:
395
+ if self._matcher is None or self._matcher.matches(node._c_node):
396
+ self._events.append( ("start", node) )
397
+ self._skip_state = IWSKIP_NEXT_IS_START
398
+ return ns_count
399
+
400
+ @cython.final
401
+ cdef _Element _end_node(self):
402
+ cdef _Element node
403
+ cdef int i, ns_count
404
+ node, ns_count = self._node_stack.pop()
405
+ if self._event_filter & PARSE_EVENT_FILTER_END:
406
+ if self._matcher is None or self._matcher.matches(node._c_node):
407
+ self._events.append( ("end", node) )
408
+ if self._event_filter & PARSE_EVENT_FILTER_END_NS and ns_count:
409
+ event = ("end-ns", None)
410
+ for i in range(ns_count):
411
+ self._events.append(event)
412
+ return node
413
+
414
+
415
+ cdef int _countNsDefs(xmlNode* c_node) noexcept:
416
+ cdef xmlNs* c_ns
417
+ cdef int count
418
+ count = 0
419
+ c_ns = c_node.nsDef
420
+ while c_ns is not NULL:
421
+ count += (c_ns.href is not NULL)
422
+ c_ns = c_ns.next
423
+ return count
424
+
425
+
426
+ cdef int _appendStartNsEvents(xmlNode* c_node, list event_list) except -1:
427
+ cdef xmlNs* c_ns
428
+ cdef int count
429
+ count = 0
430
+ c_ns = c_node.nsDef
431
+ while c_ns is not NULL:
432
+ if c_ns.href:
433
+ ns_tuple = (funicodeOrEmpty(c_ns.prefix),
434
+ funicode(c_ns.href))
435
+ event_list.append( ("start-ns", ns_tuple) )
436
+ count += 1
437
+ c_ns = c_ns.next
438
+ return count
llava_video/lib/python3.10/site-packages/lxml/lxml.etree.h ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.11 */
2
+
3
+ #ifndef __PYX_HAVE__lxml__etree
4
+ #define __PYX_HAVE__lxml__etree
5
+
6
+ #include "Python.h"
7
+ struct LxmlDocument;
8
+ struct LxmlElement;
9
+ struct LxmlElementTree;
10
+ struct LxmlElementTagMatcher;
11
+ struct LxmlElementIterator;
12
+ struct LxmlElementBase;
13
+ struct LxmlElementClassLookup;
14
+ struct LxmlFallbackElementClassLookup;
15
+
16
+ /* "lxml/etree.pyx":355
17
+ *
18
+ * # type of a function that steps from node to node
19
+ * ctypedef public xmlNode* (*_node_to_node_function)(xmlNode*) # <<<<<<<<<<<<<<
20
+ *
21
+ *
22
+ */
23
+ typedef xmlNode *(*_node_to_node_function)(xmlNode *);
24
+
25
+ /* "lxml/etree.pyx":371
26
+ * @cython.final
27
+ * @cython.freelist(8)
28
+ * cdef public class _Document [ type LxmlDocumentType, object LxmlDocument ]: # <<<<<<<<<<<<<<
29
+ * """Internal base class to reference a libxml document.
30
+ *
31
+ */
32
+ struct LxmlDocument {
33
+ PyObject_HEAD
34
+ struct __pyx_vtabstruct_4lxml_5etree__Document *__pyx_vtab;
35
+ int _ns_counter;
36
+ PyObject *_prefix_tail;
37
+ xmlDoc *_c_doc;
38
+ struct __pyx_obj_4lxml_5etree__BaseParser *_parser;
39
+ };
40
+
41
+ /* "lxml/etree.pyx":720
42
+ *
43
+ * @cython.no_gc_clear
44
+ * cdef public class _Element [ type LxmlElementType, object LxmlElement ]: # <<<<<<<<<<<<<<
45
+ * """Element class.
46
+ *
47
+ */
48
+ struct LxmlElement {
49
+ PyObject_HEAD
50
+ struct LxmlDocument *_doc;
51
+ xmlNode *_c_node;
52
+ PyObject *_tag;
53
+ };
54
+
55
+ /* "lxml/etree.pyx":1895
56
+ *
57
+ *
58
+ * cdef public class _ElementTree [ type LxmlElementTreeType, # <<<<<<<<<<<<<<
59
+ * object LxmlElementTree ]:
60
+ * cdef _Document _doc
61
+ */
62
+ struct LxmlElementTree {
63
+ PyObject_HEAD
64
+ struct __pyx_vtabstruct_4lxml_5etree__ElementTree *__pyx_vtab;
65
+ struct LxmlDocument *_doc;
66
+ struct LxmlElement *_context_node;
67
+ };
68
+
69
+ /* "lxml/etree.pyx":2669
70
+ *
71
+ *
72
+ * cdef public class _ElementTagMatcher [ object LxmlElementTagMatcher, # <<<<<<<<<<<<<<
73
+ * type LxmlElementTagMatcherType ]:
74
+ * """
75
+ */
76
+ struct LxmlElementTagMatcher {
77
+ PyObject_HEAD
78
+ struct __pyx_vtabstruct_4lxml_5etree__ElementTagMatcher *__pyx_vtab;
79
+ PyObject *_pystrings;
80
+ int _node_type;
81
+ char *_href;
82
+ char *_name;
83
+ };
84
+
85
+ /* "lxml/etree.pyx":2700
86
+ * self._name = NULL
87
+ *
88
+ * cdef public class _ElementIterator(_ElementTagMatcher) [ # <<<<<<<<<<<<<<
89
+ * object LxmlElementIterator, type LxmlElementIteratorType ]:
90
+ * """
91
+ */
92
+ struct LxmlElementIterator {
93
+ struct LxmlElementTagMatcher __pyx_base;
94
+ struct LxmlElement *_node;
95
+ _node_to_node_function _next_element;
96
+ };
97
+
98
+ /* "src/lxml/classlookup.pxi":6
99
+ * # Custom Element classes
100
+ *
101
+ * cdef public class ElementBase(_Element) [ type LxmlElementBaseType, # <<<<<<<<<<<<<<
102
+ * object LxmlElementBase ]:
103
+ * """ElementBase(*children, attrib=None, nsmap=None, **_extra)
104
+ */
105
+ struct LxmlElementBase {
106
+ struct LxmlElement __pyx_base;
107
+ };
108
+
109
+ /* "src/lxml/classlookup.pxi":210
110
+ * # Element class lookup
111
+ *
112
+ * ctypedef public object (*_element_class_lookup_function)(object, _Document, xmlNode*) # <<<<<<<<<<<<<<
113
+ *
114
+ * # class to store element class lookup functions
115
+ */
116
+ typedef PyObject *(*_element_class_lookup_function)(PyObject *, struct LxmlDocument *, xmlNode *);
117
+
118
+ /* "src/lxml/classlookup.pxi":213
119
+ *
120
+ * # class to store element class lookup functions
121
+ * cdef public class ElementClassLookup [ type LxmlElementClassLookupType, # <<<<<<<<<<<<<<
122
+ * object LxmlElementClassLookup ]:
123
+ * """ElementClassLookup(self)
124
+ */
125
+ struct LxmlElementClassLookup {
126
+ PyObject_HEAD
127
+ _element_class_lookup_function _lookup_function;
128
+ };
129
+
130
+ /* "src/lxml/classlookup.pxi":221
131
+ *
132
+ *
133
+ * cdef public class FallbackElementClassLookup(ElementClassLookup) \ # <<<<<<<<<<<<<<
134
+ * [ type LxmlFallbackElementClassLookupType,
135
+ * object LxmlFallbackElementClassLookup ]:
136
+ */
137
+ struct LxmlFallbackElementClassLookup {
138
+ struct LxmlElementClassLookup __pyx_base;
139
+ struct __pyx_vtabstruct_4lxml_5etree_FallbackElementClassLookup *__pyx_vtab;
140
+ struct LxmlElementClassLookup *fallback;
141
+ _element_class_lookup_function _fallback_function;
142
+ };
143
+
144
+ #ifndef __PYX_HAVE_API__lxml__etree
145
+
146
+ #ifdef CYTHON_EXTERN_C
147
+ #undef __PYX_EXTERN_C
148
+ #define __PYX_EXTERN_C CYTHON_EXTERN_C
149
+ #elif defined(__PYX_EXTERN_C)
150
+ #ifdef _MSC_VER
151
+ #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
152
+ #else
153
+ #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
154
+ #endif
155
+ #else
156
+ #ifdef __cplusplus
157
+ #define __PYX_EXTERN_C extern "C"
158
+ #else
159
+ #define __PYX_EXTERN_C extern
160
+ #endif
161
+ #endif
162
+
163
+ #ifndef DL_IMPORT
164
+ #define DL_IMPORT(_T) _T
165
+ #endif
166
+
167
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlDocumentType;
168
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementType;
169
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementTreeType;
170
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementTagMatcherType;
171
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementIteratorType;
172
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementBaseType;
173
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlElementClassLookupType;
174
+ __PYX_EXTERN_C DL_IMPORT(PyTypeObject) LxmlFallbackElementClassLookupType;
175
+
176
+ __PYX_EXTERN_C struct LxmlElement *deepcopyNodeToDocument(struct LxmlDocument *, xmlNode *);
177
+ __PYX_EXTERN_C struct LxmlElementTree *elementTreeFactory(struct LxmlElement *);
178
+ __PYX_EXTERN_C struct LxmlElementTree *newElementTree(struct LxmlElement *, PyObject *);
179
+ __PYX_EXTERN_C struct LxmlElementTree *adoptExternalDocument(xmlDoc *, PyObject *, int);
180
+ __PYX_EXTERN_C struct LxmlElement *elementFactory(struct LxmlDocument *, xmlNode *);
181
+ __PYX_EXTERN_C struct LxmlElement *makeElement(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *);
182
+ __PYX_EXTERN_C struct LxmlElement *makeSubElement(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *);
183
+ __PYX_EXTERN_C void setElementClassLookupFunction(_element_class_lookup_function, PyObject *);
184
+ __PYX_EXTERN_C PyObject *lookupDefaultElementClass(PyObject *, PyObject *, xmlNode *);
185
+ __PYX_EXTERN_C PyObject *lookupNamespaceElementClass(PyObject *, PyObject *, xmlNode *);
186
+ __PYX_EXTERN_C PyObject *callLookupFallback(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *);
187
+ __PYX_EXTERN_C int tagMatches(xmlNode *, const xmlChar *, const xmlChar *);
188
+ __PYX_EXTERN_C struct LxmlDocument *documentOrRaise(PyObject *);
189
+ __PYX_EXTERN_C struct LxmlElement *rootNodeOrRaise(PyObject *);
190
+ __PYX_EXTERN_C int hasText(xmlNode *);
191
+ __PYX_EXTERN_C int hasTail(xmlNode *);
192
+ __PYX_EXTERN_C PyObject *textOf(xmlNode *);
193
+ __PYX_EXTERN_C PyObject *tailOf(xmlNode *);
194
+ __PYX_EXTERN_C int setNodeText(xmlNode *, PyObject *);
195
+ __PYX_EXTERN_C int setTailText(xmlNode *, PyObject *);
196
+ __PYX_EXTERN_C PyObject *attributeValue(xmlNode *, xmlAttr *);
197
+ __PYX_EXTERN_C PyObject *attributeValueFromNsName(xmlNode *, const xmlChar *, const xmlChar *);
198
+ __PYX_EXTERN_C PyObject *getAttributeValue(struct LxmlElement *, PyObject *, PyObject *);
199
+ __PYX_EXTERN_C PyObject *iterattributes(struct LxmlElement *, int);
200
+ __PYX_EXTERN_C PyObject *collectAttributes(xmlNode *, int);
201
+ __PYX_EXTERN_C int setAttributeValue(struct LxmlElement *, PyObject *, PyObject *);
202
+ __PYX_EXTERN_C int delAttribute(struct LxmlElement *, PyObject *);
203
+ __PYX_EXTERN_C int delAttributeFromNsName(xmlNode *, const xmlChar *, const xmlChar *);
204
+ __PYX_EXTERN_C int hasChild(xmlNode *);
205
+ __PYX_EXTERN_C xmlNode *findChild(xmlNode *, Py_ssize_t);
206
+ __PYX_EXTERN_C xmlNode *findChildForwards(xmlNode *, Py_ssize_t);
207
+ __PYX_EXTERN_C xmlNode *findChildBackwards(xmlNode *, Py_ssize_t);
208
+ __PYX_EXTERN_C xmlNode *nextElement(xmlNode *);
209
+ __PYX_EXTERN_C xmlNode *previousElement(xmlNode *);
210
+ __PYX_EXTERN_C void appendChild(struct LxmlElement *, struct LxmlElement *);
211
+ __PYX_EXTERN_C int appendChildToElement(struct LxmlElement *, struct LxmlElement *);
212
+ __PYX_EXTERN_C PyObject *pyunicode(const xmlChar *);
213
+ __PYX_EXTERN_C PyObject *utf8(PyObject *);
214
+ __PYX_EXTERN_C PyObject *getNsTag(PyObject *);
215
+ __PYX_EXTERN_C PyObject *getNsTagWithEmptyNs(PyObject *);
216
+ __PYX_EXTERN_C PyObject *namespacedName(xmlNode *);
217
+ __PYX_EXTERN_C PyObject *namespacedNameFromNsName(const xmlChar *, const xmlChar *);
218
+ __PYX_EXTERN_C void iteratorStoreNext(struct LxmlElementIterator *, struct LxmlElement *);
219
+ __PYX_EXTERN_C void initTagMatch(struct LxmlElementTagMatcher *, PyObject *);
220
+ __PYX_EXTERN_C xmlNs *findOrBuildNodeNsPrefix(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *);
221
+
222
+ #endif /* !__PYX_HAVE_API__lxml__etree */
223
+
224
+ /* WARNING: the interface of the module init function changed in CPython 3.5. */
225
+ /* It now returns a PyModuleDef instance instead of a PyModule instance. */
226
+
227
+ #if PY_MAJOR_VERSION < 3
228
+ PyMODINIT_FUNC initetree(void);
229
+ #else
230
+ /* WARNING: Use PyImport_AppendInittab("etree", PyInit_etree) instead of calling PyInit_etree directly from Python 3.5 */
231
+ PyMODINIT_FUNC PyInit_etree(void);
232
+
233
+ #if PY_VERSION_HEX >= 0x03050000 && (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 201402L))
234
+ #if defined(__cplusplus) && __cplusplus >= 201402L
235
+ [[deprecated("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly.")]] inline
236
+ #elif defined(__GNUC__) || defined(__clang__)
237
+ __attribute__ ((__deprecated__("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly."), __unused__)) __inline__
238
+ #elif defined(_MSC_VER)
239
+ __declspec(deprecated("Use PyImport_AppendInittab(\"etree\", PyInit_etree) instead of calling PyInit_etree directly.")) __inline
240
+ #endif
241
+ static PyObject* __PYX_WARN_IF_PyInit_etree_INIT_CALLED(PyObject* res) {
242
+ return res;
243
+ }
244
+ #define PyInit_etree() __PYX_WARN_IF_PyInit_etree_INIT_CALLED(PyInit_etree())
245
+ #endif
246
+ #endif
247
+
248
+ #endif /* !__PYX_HAVE__lxml__etree */
llava_video/lib/python3.10/site-packages/lxml/lxml.etree_api.h ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Generated by Cython 3.0.11 */
2
+
3
+ #ifndef __PYX_HAVE_API__lxml__etree
4
+ #define __PYX_HAVE_API__lxml__etree
5
+ #ifdef __MINGW64__
6
+ #define MS_WIN64
7
+ #endif
8
+ #include "Python.h"
9
+ #include "lxml.etree.h"
10
+
11
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_deepcopyNodeToDocument)(struct LxmlDocument *, xmlNode *) = 0;
12
+ #define deepcopyNodeToDocument __pyx_api_f_4lxml_5etree_deepcopyNodeToDocument
13
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_elementTreeFactory)(struct LxmlElement *) = 0;
14
+ #define elementTreeFactory __pyx_api_f_4lxml_5etree_elementTreeFactory
15
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_newElementTree)(struct LxmlElement *, PyObject *) = 0;
16
+ #define newElementTree __pyx_api_f_4lxml_5etree_newElementTree
17
+ static struct LxmlElementTree *(*__pyx_api_f_4lxml_5etree_adoptExternalDocument)(xmlDoc *, PyObject *, int) = 0;
18
+ #define adoptExternalDocument __pyx_api_f_4lxml_5etree_adoptExternalDocument
19
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_elementFactory)(struct LxmlDocument *, xmlNode *) = 0;
20
+ #define elementFactory __pyx_api_f_4lxml_5etree_elementFactory
21
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_makeElement)(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *) = 0;
22
+ #define makeElement __pyx_api_f_4lxml_5etree_makeElement
23
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_makeSubElement)(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *) = 0;
24
+ #define makeSubElement __pyx_api_f_4lxml_5etree_makeSubElement
25
+ static void (*__pyx_api_f_4lxml_5etree_setElementClassLookupFunction)(_element_class_lookup_function, PyObject *) = 0;
26
+ #define setElementClassLookupFunction __pyx_api_f_4lxml_5etree_setElementClassLookupFunction
27
+ static PyObject *(*__pyx_api_f_4lxml_5etree_lookupDefaultElementClass)(PyObject *, PyObject *, xmlNode *) = 0;
28
+ #define lookupDefaultElementClass __pyx_api_f_4lxml_5etree_lookupDefaultElementClass
29
+ static PyObject *(*__pyx_api_f_4lxml_5etree_lookupNamespaceElementClass)(PyObject *, PyObject *, xmlNode *) = 0;
30
+ #define lookupNamespaceElementClass __pyx_api_f_4lxml_5etree_lookupNamespaceElementClass
31
+ static PyObject *(*__pyx_api_f_4lxml_5etree_callLookupFallback)(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *) = 0;
32
+ #define callLookupFallback __pyx_api_f_4lxml_5etree_callLookupFallback
33
+ static int (*__pyx_api_f_4lxml_5etree_tagMatches)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
34
+ #define tagMatches __pyx_api_f_4lxml_5etree_tagMatches
35
+ static struct LxmlDocument *(*__pyx_api_f_4lxml_5etree_documentOrRaise)(PyObject *) = 0;
36
+ #define documentOrRaise __pyx_api_f_4lxml_5etree_documentOrRaise
37
+ static struct LxmlElement *(*__pyx_api_f_4lxml_5etree_rootNodeOrRaise)(PyObject *) = 0;
38
+ #define rootNodeOrRaise __pyx_api_f_4lxml_5etree_rootNodeOrRaise
39
+ static int (*__pyx_api_f_4lxml_5etree_hasText)(xmlNode *) = 0;
40
+ #define hasText __pyx_api_f_4lxml_5etree_hasText
41
+ static int (*__pyx_api_f_4lxml_5etree_hasTail)(xmlNode *) = 0;
42
+ #define hasTail __pyx_api_f_4lxml_5etree_hasTail
43
+ static PyObject *(*__pyx_api_f_4lxml_5etree_textOf)(xmlNode *) = 0;
44
+ #define textOf __pyx_api_f_4lxml_5etree_textOf
45
+ static PyObject *(*__pyx_api_f_4lxml_5etree_tailOf)(xmlNode *) = 0;
46
+ #define tailOf __pyx_api_f_4lxml_5etree_tailOf
47
+ static int (*__pyx_api_f_4lxml_5etree_setNodeText)(xmlNode *, PyObject *) = 0;
48
+ #define setNodeText __pyx_api_f_4lxml_5etree_setNodeText
49
+ static int (*__pyx_api_f_4lxml_5etree_setTailText)(xmlNode *, PyObject *) = 0;
50
+ #define setTailText __pyx_api_f_4lxml_5etree_setTailText
51
+ static PyObject *(*__pyx_api_f_4lxml_5etree_attributeValue)(xmlNode *, xmlAttr *) = 0;
52
+ #define attributeValue __pyx_api_f_4lxml_5etree_attributeValue
53
+ static PyObject *(*__pyx_api_f_4lxml_5etree_attributeValueFromNsName)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
54
+ #define attributeValueFromNsName __pyx_api_f_4lxml_5etree_attributeValueFromNsName
55
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getAttributeValue)(struct LxmlElement *, PyObject *, PyObject *) = 0;
56
+ #define getAttributeValue __pyx_api_f_4lxml_5etree_getAttributeValue
57
+ static PyObject *(*__pyx_api_f_4lxml_5etree_iterattributes)(struct LxmlElement *, int) = 0;
58
+ #define iterattributes __pyx_api_f_4lxml_5etree_iterattributes
59
+ static PyObject *(*__pyx_api_f_4lxml_5etree_collectAttributes)(xmlNode *, int) = 0;
60
+ #define collectAttributes __pyx_api_f_4lxml_5etree_collectAttributes
61
+ static int (*__pyx_api_f_4lxml_5etree_setAttributeValue)(struct LxmlElement *, PyObject *, PyObject *) = 0;
62
+ #define setAttributeValue __pyx_api_f_4lxml_5etree_setAttributeValue
63
+ static int (*__pyx_api_f_4lxml_5etree_delAttribute)(struct LxmlElement *, PyObject *) = 0;
64
+ #define delAttribute __pyx_api_f_4lxml_5etree_delAttribute
65
+ static int (*__pyx_api_f_4lxml_5etree_delAttributeFromNsName)(xmlNode *, const xmlChar *, const xmlChar *) = 0;
66
+ #define delAttributeFromNsName __pyx_api_f_4lxml_5etree_delAttributeFromNsName
67
+ static int (*__pyx_api_f_4lxml_5etree_hasChild)(xmlNode *) = 0;
68
+ #define hasChild __pyx_api_f_4lxml_5etree_hasChild
69
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChild)(xmlNode *, Py_ssize_t) = 0;
70
+ #define findChild __pyx_api_f_4lxml_5etree_findChild
71
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChildForwards)(xmlNode *, Py_ssize_t) = 0;
72
+ #define findChildForwards __pyx_api_f_4lxml_5etree_findChildForwards
73
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_findChildBackwards)(xmlNode *, Py_ssize_t) = 0;
74
+ #define findChildBackwards __pyx_api_f_4lxml_5etree_findChildBackwards
75
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_nextElement)(xmlNode *) = 0;
76
+ #define nextElement __pyx_api_f_4lxml_5etree_nextElement
77
+ static xmlNode *(*__pyx_api_f_4lxml_5etree_previousElement)(xmlNode *) = 0;
78
+ #define previousElement __pyx_api_f_4lxml_5etree_previousElement
79
+ static void (*__pyx_api_f_4lxml_5etree_appendChild)(struct LxmlElement *, struct LxmlElement *) = 0;
80
+ #define appendChild __pyx_api_f_4lxml_5etree_appendChild
81
+ static int (*__pyx_api_f_4lxml_5etree_appendChildToElement)(struct LxmlElement *, struct LxmlElement *) = 0;
82
+ #define appendChildToElement __pyx_api_f_4lxml_5etree_appendChildToElement
83
+ static PyObject *(*__pyx_api_f_4lxml_5etree_pyunicode)(const xmlChar *) = 0;
84
+ #define pyunicode __pyx_api_f_4lxml_5etree_pyunicode
85
+ static PyObject *(*__pyx_api_f_4lxml_5etree_utf8)(PyObject *) = 0;
86
+ #define utf8 __pyx_api_f_4lxml_5etree_utf8
87
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getNsTag)(PyObject *) = 0;
88
+ #define getNsTag __pyx_api_f_4lxml_5etree_getNsTag
89
+ static PyObject *(*__pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs)(PyObject *) = 0;
90
+ #define getNsTagWithEmptyNs __pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs
91
+ static PyObject *(*__pyx_api_f_4lxml_5etree_namespacedName)(xmlNode *) = 0;
92
+ #define namespacedName __pyx_api_f_4lxml_5etree_namespacedName
93
+ static PyObject *(*__pyx_api_f_4lxml_5etree_namespacedNameFromNsName)(const xmlChar *, const xmlChar *) = 0;
94
+ #define namespacedNameFromNsName __pyx_api_f_4lxml_5etree_namespacedNameFromNsName
95
+ static void (*__pyx_api_f_4lxml_5etree_iteratorStoreNext)(struct LxmlElementIterator *, struct LxmlElement *) = 0;
96
+ #define iteratorStoreNext __pyx_api_f_4lxml_5etree_iteratorStoreNext
97
+ static void (*__pyx_api_f_4lxml_5etree_initTagMatch)(struct LxmlElementTagMatcher *, PyObject *) = 0;
98
+ #define initTagMatch __pyx_api_f_4lxml_5etree_initTagMatch
99
+ static xmlNs *(*__pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix)(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *) = 0;
100
+ #define findOrBuildNodeNsPrefix __pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix
101
+ #ifndef __PYX_HAVE_RT_ImportFunction_3_0_11
102
+ #define __PYX_HAVE_RT_ImportFunction_3_0_11
103
+ static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
104
+ PyObject *d = 0;
105
+ PyObject *cobj = 0;
106
+ union {
107
+ void (*fp)(void);
108
+ void *p;
109
+ } tmp;
110
+ d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
111
+ if (!d)
112
+ goto bad;
113
+ cobj = PyDict_GetItemString(d, funcname);
114
+ if (!cobj) {
115
+ PyErr_Format(PyExc_ImportError,
116
+ "%.200s does not export expected C function %.200s",
117
+ PyModule_GetName(module), funcname);
118
+ goto bad;
119
+ }
120
+ if (!PyCapsule_IsValid(cobj, sig)) {
121
+ PyErr_Format(PyExc_TypeError,
122
+ "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
123
+ PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
124
+ goto bad;
125
+ }
126
+ tmp.p = PyCapsule_GetPointer(cobj, sig);
127
+ *f = tmp.fp;
128
+ if (!(*f))
129
+ goto bad;
130
+ Py_DECREF(d);
131
+ return 0;
132
+ bad:
133
+ Py_XDECREF(d);
134
+ return -1;
135
+ }
136
+ #endif
137
+
138
+
139
+ static int import_lxml__etree(void) {
140
+ PyObject *module = 0;
141
+ module = PyImport_ImportModule("lxml.etree");
142
+ if (!module) goto bad;
143
+ if (__Pyx_ImportFunction_3_0_11(module, "deepcopyNodeToDocument", (void (**)(void))&__pyx_api_f_4lxml_5etree_deepcopyNodeToDocument, "struct LxmlElement *(struct LxmlDocument *, xmlNode *)") < 0) goto bad;
144
+ if (__Pyx_ImportFunction_3_0_11(module, "elementTreeFactory", (void (**)(void))&__pyx_api_f_4lxml_5etree_elementTreeFactory, "struct LxmlElementTree *(struct LxmlElement *)") < 0) goto bad;
145
+ if (__Pyx_ImportFunction_3_0_11(module, "newElementTree", (void (**)(void))&__pyx_api_f_4lxml_5etree_newElementTree, "struct LxmlElementTree *(struct LxmlElement *, PyObject *)") < 0) goto bad;
146
+ if (__Pyx_ImportFunction_3_0_11(module, "adoptExternalDocument", (void (**)(void))&__pyx_api_f_4lxml_5etree_adoptExternalDocument, "struct LxmlElementTree *(xmlDoc *, PyObject *, int)") < 0) goto bad;
147
+ if (__Pyx_ImportFunction_3_0_11(module, "elementFactory", (void (**)(void))&__pyx_api_f_4lxml_5etree_elementFactory, "struct LxmlElement *(struct LxmlDocument *, xmlNode *)") < 0) goto bad;
148
+ if (__Pyx_ImportFunction_3_0_11(module, "makeElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_makeElement, "struct LxmlElement *(PyObject *, struct LxmlDocument *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *)") < 0) goto bad;
149
+ if (__Pyx_ImportFunction_3_0_11(module, "makeSubElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_makeSubElement, "struct LxmlElement *(struct LxmlElement *, PyObject *, PyObject *, PyObject *, PyObject *, PyObject *)") < 0) goto bad;
150
+ if (__Pyx_ImportFunction_3_0_11(module, "setElementClassLookupFunction", (void (**)(void))&__pyx_api_f_4lxml_5etree_setElementClassLookupFunction, "void (_element_class_lookup_function, PyObject *)") < 0) goto bad;
151
+ if (__Pyx_ImportFunction_3_0_11(module, "lookupDefaultElementClass", (void (**)(void))&__pyx_api_f_4lxml_5etree_lookupDefaultElementClass, "PyObject *(PyObject *, PyObject *, xmlNode *)") < 0) goto bad;
152
+ if (__Pyx_ImportFunction_3_0_11(module, "lookupNamespaceElementClass", (void (**)(void))&__pyx_api_f_4lxml_5etree_lookupNamespaceElementClass, "PyObject *(PyObject *, PyObject *, xmlNode *)") < 0) goto bad;
153
+ if (__Pyx_ImportFunction_3_0_11(module, "callLookupFallback", (void (**)(void))&__pyx_api_f_4lxml_5etree_callLookupFallback, "PyObject *(struct LxmlFallbackElementClassLookup *, struct LxmlDocument *, xmlNode *)") < 0) goto bad;
154
+ if (__Pyx_ImportFunction_3_0_11(module, "tagMatches", (void (**)(void))&__pyx_api_f_4lxml_5etree_tagMatches, "int (xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
155
+ if (__Pyx_ImportFunction_3_0_11(module, "documentOrRaise", (void (**)(void))&__pyx_api_f_4lxml_5etree_documentOrRaise, "struct LxmlDocument *(PyObject *)") < 0) goto bad;
156
+ if (__Pyx_ImportFunction_3_0_11(module, "rootNodeOrRaise", (void (**)(void))&__pyx_api_f_4lxml_5etree_rootNodeOrRaise, "struct LxmlElement *(PyObject *)") < 0) goto bad;
157
+ if (__Pyx_ImportFunction_3_0_11(module, "hasText", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasText, "int (xmlNode *)") < 0) goto bad;
158
+ if (__Pyx_ImportFunction_3_0_11(module, "hasTail", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasTail, "int (xmlNode *)") < 0) goto bad;
159
+ if (__Pyx_ImportFunction_3_0_11(module, "textOf", (void (**)(void))&__pyx_api_f_4lxml_5etree_textOf, "PyObject *(xmlNode *)") < 0) goto bad;
160
+ if (__Pyx_ImportFunction_3_0_11(module, "tailOf", (void (**)(void))&__pyx_api_f_4lxml_5etree_tailOf, "PyObject *(xmlNode *)") < 0) goto bad;
161
+ if (__Pyx_ImportFunction_3_0_11(module, "setNodeText", (void (**)(void))&__pyx_api_f_4lxml_5etree_setNodeText, "int (xmlNode *, PyObject *)") < 0) goto bad;
162
+ if (__Pyx_ImportFunction_3_0_11(module, "setTailText", (void (**)(void))&__pyx_api_f_4lxml_5etree_setTailText, "int (xmlNode *, PyObject *)") < 0) goto bad;
163
+ if (__Pyx_ImportFunction_3_0_11(module, "attributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_attributeValue, "PyObject *(xmlNode *, xmlAttr *)") < 0) goto bad;
164
+ if (__Pyx_ImportFunction_3_0_11(module, "attributeValueFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_attributeValueFromNsName, "PyObject *(xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
165
+ if (__Pyx_ImportFunction_3_0_11(module, "getAttributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_getAttributeValue, "PyObject *(struct LxmlElement *, PyObject *, PyObject *)") < 0) goto bad;
166
+ if (__Pyx_ImportFunction_3_0_11(module, "iterattributes", (void (**)(void))&__pyx_api_f_4lxml_5etree_iterattributes, "PyObject *(struct LxmlElement *, int)") < 0) goto bad;
167
+ if (__Pyx_ImportFunction_3_0_11(module, "collectAttributes", (void (**)(void))&__pyx_api_f_4lxml_5etree_collectAttributes, "PyObject *(xmlNode *, int)") < 0) goto bad;
168
+ if (__Pyx_ImportFunction_3_0_11(module, "setAttributeValue", (void (**)(void))&__pyx_api_f_4lxml_5etree_setAttributeValue, "int (struct LxmlElement *, PyObject *, PyObject *)") < 0) goto bad;
169
+ if (__Pyx_ImportFunction_3_0_11(module, "delAttribute", (void (**)(void))&__pyx_api_f_4lxml_5etree_delAttribute, "int (struct LxmlElement *, PyObject *)") < 0) goto bad;
170
+ if (__Pyx_ImportFunction_3_0_11(module, "delAttributeFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_delAttributeFromNsName, "int (xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
171
+ if (__Pyx_ImportFunction_3_0_11(module, "hasChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_hasChild, "int (xmlNode *)") < 0) goto bad;
172
+ if (__Pyx_ImportFunction_3_0_11(module, "findChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChild, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
173
+ if (__Pyx_ImportFunction_3_0_11(module, "findChildForwards", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChildForwards, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
174
+ if (__Pyx_ImportFunction_3_0_11(module, "findChildBackwards", (void (**)(void))&__pyx_api_f_4lxml_5etree_findChildBackwards, "xmlNode *(xmlNode *, Py_ssize_t)") < 0) goto bad;
175
+ if (__Pyx_ImportFunction_3_0_11(module, "nextElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_nextElement, "xmlNode *(xmlNode *)") < 0) goto bad;
176
+ if (__Pyx_ImportFunction_3_0_11(module, "previousElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_previousElement, "xmlNode *(xmlNode *)") < 0) goto bad;
177
+ if (__Pyx_ImportFunction_3_0_11(module, "appendChild", (void (**)(void))&__pyx_api_f_4lxml_5etree_appendChild, "void (struct LxmlElement *, struct LxmlElement *)") < 0) goto bad;
178
+ if (__Pyx_ImportFunction_3_0_11(module, "appendChildToElement", (void (**)(void))&__pyx_api_f_4lxml_5etree_appendChildToElement, "int (struct LxmlElement *, struct LxmlElement *)") < 0) goto bad;
179
+ if (__Pyx_ImportFunction_3_0_11(module, "pyunicode", (void (**)(void))&__pyx_api_f_4lxml_5etree_pyunicode, "PyObject *(const xmlChar *)") < 0) goto bad;
180
+ if (__Pyx_ImportFunction_3_0_11(module, "utf8", (void (**)(void))&__pyx_api_f_4lxml_5etree_utf8, "PyObject *(PyObject *)") < 0) goto bad;
181
+ if (__Pyx_ImportFunction_3_0_11(module, "getNsTag", (void (**)(void))&__pyx_api_f_4lxml_5etree_getNsTag, "PyObject *(PyObject *)") < 0) goto bad;
182
+ if (__Pyx_ImportFunction_3_0_11(module, "getNsTagWithEmptyNs", (void (**)(void))&__pyx_api_f_4lxml_5etree_getNsTagWithEmptyNs, "PyObject *(PyObject *)") < 0) goto bad;
183
+ if (__Pyx_ImportFunction_3_0_11(module, "namespacedName", (void (**)(void))&__pyx_api_f_4lxml_5etree_namespacedName, "PyObject *(xmlNode *)") < 0) goto bad;
184
+ if (__Pyx_ImportFunction_3_0_11(module, "namespacedNameFromNsName", (void (**)(void))&__pyx_api_f_4lxml_5etree_namespacedNameFromNsName, "PyObject *(const xmlChar *, const xmlChar *)") < 0) goto bad;
185
+ if (__Pyx_ImportFunction_3_0_11(module, "iteratorStoreNext", (void (**)(void))&__pyx_api_f_4lxml_5etree_iteratorStoreNext, "void (struct LxmlElementIterator *, struct LxmlElement *)") < 0) goto bad;
186
+ if (__Pyx_ImportFunction_3_0_11(module, "initTagMatch", (void (**)(void))&__pyx_api_f_4lxml_5etree_initTagMatch, "void (struct LxmlElementTagMatcher *, PyObject *)") < 0) goto bad;
187
+ if (__Pyx_ImportFunction_3_0_11(module, "findOrBuildNodeNsPrefix", (void (**)(void))&__pyx_api_f_4lxml_5etree_findOrBuildNodeNsPrefix, "xmlNs *(struct LxmlDocument *, xmlNode *, const xmlChar *, const xmlChar *)") < 0) goto bad;
188
+ Py_DECREF(module); module = 0;
189
+ return 0;
190
+ bad:
191
+ Py_XDECREF(module);
192
+ return -1;
193
+ }
194
+
195
+ #endif /* !__PYX_HAVE_API__lxml__etree */
llava_video/lib/python3.10/site-packages/lxml/nsclasses.pxi ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # module-level API for namespace implementations
2
+
3
+ cdef class LxmlRegistryError(LxmlError):
4
+ """Base class of lxml registry errors.
5
+ """
6
+
7
+ cdef class NamespaceRegistryError(LxmlRegistryError):
8
+ """Error registering a namespace extension.
9
+ """
10
+
11
+
12
+ @cython.internal
13
+ cdef class _NamespaceRegistry:
14
+ "Dictionary-like namespace registry"
15
+ cdef object _ns_uri
16
+ cdef bytes _ns_uri_utf
17
+ cdef dict _entries
18
+ cdef char* _c_ns_uri_utf
19
+ def __cinit__(self, ns_uri):
20
+ self._ns_uri = ns_uri
21
+ if ns_uri is None:
22
+ self._ns_uri_utf = None
23
+ self._c_ns_uri_utf = NULL
24
+ else:
25
+ self._ns_uri_utf = _utf8(ns_uri)
26
+ self._c_ns_uri_utf = _cstr(self._ns_uri_utf)
27
+ self._entries = {}
28
+
29
+ def update(self, class_dict_iterable):
30
+ """update(self, class_dict_iterable)
31
+
32
+ Forgivingly update the registry.
33
+
34
+ ``class_dict_iterable`` may be a dict or some other iterable
35
+ that yields (name, value) pairs.
36
+
37
+ If a value does not match the required type for this registry,
38
+ or if the name starts with '_', it will be silently discarded.
39
+ This allows registrations at the module or class level using
40
+ vars(), globals() etc."""
41
+ if hasattr(class_dict_iterable, 'items'):
42
+ class_dict_iterable = class_dict_iterable.items()
43
+ for name, item in class_dict_iterable:
44
+ if (name is None or name[:1] != '_') and callable(item):
45
+ self[name] = item
46
+
47
+ def __getitem__(self, name):
48
+ if name is not None:
49
+ name = _utf8(name)
50
+ return self._get(name)
51
+
52
+ def __delitem__(self, name):
53
+ if name is not None:
54
+ name = _utf8(name)
55
+ del self._entries[name]
56
+
57
+ cdef object _get(self, object name):
58
+ cdef python.PyObject* dict_result
59
+ dict_result = python.PyDict_GetItem(self._entries, name)
60
+ if dict_result is NULL:
61
+ raise KeyError, "Name not registered."
62
+ return <object>dict_result
63
+
64
+ cdef object _getForString(self, char* name):
65
+ cdef python.PyObject* dict_result
66
+ dict_result = python.PyDict_GetItem(self._entries, name)
67
+ if dict_result is NULL:
68
+ raise KeyError, "Name not registered."
69
+ return <object>dict_result
70
+
71
+ def __iter__(self):
72
+ return iter(self._entries)
73
+
74
+ def items(self):
75
+ return list(self._entries.items())
76
+
77
+ def iteritems(self):
78
+ return iter(self._entries.items())
79
+
80
+ def clear(self):
81
+ self._entries.clear()
82
+
83
+ def __call__(self, obj):
84
+ # Usage as decorator:
85
+ # ns = lookup.get_namespace("...")
86
+ # @ns('abc')
87
+ # class element(ElementBase): pass
88
+ #
89
+ # @ns
90
+ # class elementname(ElementBase): pass
91
+
92
+ if obj is None or python._isString(obj):
93
+ # @ns(None) or @ns('tag')
94
+ return partial(self.__deco, obj)
95
+ # plain @ns decorator
96
+ self[obj.__name__] = obj
97
+ return obj
98
+
99
+ def __deco(self, name, obj):
100
+ self[name] = obj
101
+ return obj
102
+
103
+
104
+ @cython.final
105
+ @cython.internal
106
+ cdef class _ClassNamespaceRegistry(_NamespaceRegistry):
107
+ "Dictionary-like registry for namespace implementation classes"
108
+ def __setitem__(self, name, item):
109
+ if not isinstance(item, type) or not issubclass(item, ElementBase):
110
+ raise NamespaceRegistryError, \
111
+ "Registered element classes must be subtypes of ElementBase"
112
+ if name is not None:
113
+ name = _utf8(name)
114
+ self._entries[name] = item
115
+
116
+ def __repr__(self):
117
+ return "Namespace(%r)" % self._ns_uri
118
+
119
+
120
+ cdef class ElementNamespaceClassLookup(FallbackElementClassLookup):
121
+ """ElementNamespaceClassLookup(self, fallback=None)
122
+
123
+ Element class lookup scheme that searches the Element class in the
124
+ Namespace registry.
125
+
126
+ Usage:
127
+
128
+ >>> lookup = ElementNamespaceClassLookup()
129
+ >>> ns_elements = lookup.get_namespace("http://schema.org/Movie")
130
+
131
+ >>> @ns_elements
132
+ ... class movie(ElementBase):
133
+ ... "Element implementation for 'movie' tag (using class name) in schema namespace."
134
+
135
+ >>> @ns_elements("movie")
136
+ ... class MovieElement(ElementBase):
137
+ ... "Element implementation for 'movie' tag (explicit tag name) in schema namespace."
138
+ """
139
+ cdef dict _namespace_registries
140
+ def __cinit__(self):
141
+ self._namespace_registries = {}
142
+
143
+ def __init__(self, ElementClassLookup fallback=None):
144
+ FallbackElementClassLookup.__init__(self, fallback)
145
+ self._lookup_function = _find_nselement_class
146
+
147
+ def get_namespace(self, ns_uri):
148
+ """get_namespace(self, ns_uri)
149
+
150
+ Retrieve the namespace object associated with the given URI.
151
+ Pass None for the empty namespace.
152
+
153
+ Creates a new namespace object if it does not yet exist."""
154
+ if ns_uri:
155
+ ns_utf = _utf8(ns_uri)
156
+ else:
157
+ ns_utf = None
158
+ try:
159
+ return self._namespace_registries[ns_utf]
160
+ except KeyError:
161
+ registry = self._namespace_registries[ns_utf] = \
162
+ _ClassNamespaceRegistry(ns_uri)
163
+ return registry
164
+
165
+ cdef object _find_nselement_class(state, _Document doc, xmlNode* c_node):
166
+ cdef python.PyObject* dict_result
167
+ cdef ElementNamespaceClassLookup lookup
168
+ cdef _NamespaceRegistry registry
169
+ if state is None:
170
+ return _lookupDefaultElementClass(None, doc, c_node)
171
+
172
+ lookup = <ElementNamespaceClassLookup>state
173
+ if c_node.type != tree.XML_ELEMENT_NODE:
174
+ return _callLookupFallback(lookup, doc, c_node)
175
+
176
+ c_namespace_utf = _getNs(c_node)
177
+ if c_namespace_utf is not NULL:
178
+ dict_result = python.PyDict_GetItem(
179
+ lookup._namespace_registries, <unsigned char*>c_namespace_utf)
180
+ else:
181
+ dict_result = python.PyDict_GetItem(
182
+ lookup._namespace_registries, None)
183
+ if dict_result is not NULL:
184
+ registry = <_NamespaceRegistry>dict_result
185
+ classes = registry._entries
186
+
187
+ if c_node.name is not NULL:
188
+ dict_result = python.PyDict_GetItem(
189
+ classes, <unsigned char*>c_node.name)
190
+ else:
191
+ dict_result = NULL
192
+
193
+ if dict_result is NULL:
194
+ dict_result = python.PyDict_GetItem(classes, None)
195
+
196
+ if dict_result is not NULL:
197
+ return <object>dict_result
198
+ return _callLookupFallback(lookup, doc, c_node)
199
+
200
+
201
+ ################################################################################
202
+ # XPath extension functions
203
+
204
+ cdef dict __FUNCTION_NAMESPACE_REGISTRIES
205
+ __FUNCTION_NAMESPACE_REGISTRIES = {}
206
+
207
+ def FunctionNamespace(ns_uri):
208
+ """FunctionNamespace(ns_uri)
209
+
210
+ Retrieve the function namespace object associated with the given
211
+ URI.
212
+
213
+ Creates a new one if it does not yet exist. A function namespace
214
+ can only be used to register extension functions.
215
+
216
+ Usage:
217
+
218
+ >>> ns_functions = FunctionNamespace("http://schema.org/Movie")
219
+
220
+ >>> @ns_functions # uses function name
221
+ ... def add2(x):
222
+ ... return x + 2
223
+
224
+ >>> @ns_functions("add3") # uses explicit name
225
+ ... def add_three(x):
226
+ ... return x + 3
227
+ """
228
+ ns_utf = _utf8(ns_uri) if ns_uri else None
229
+ try:
230
+ return __FUNCTION_NAMESPACE_REGISTRIES[ns_utf]
231
+ except KeyError:
232
+ registry = __FUNCTION_NAMESPACE_REGISTRIES[ns_utf] = \
233
+ _XPathFunctionNamespaceRegistry(ns_uri)
234
+ return registry
235
+
236
+ @cython.internal
237
+ cdef class _FunctionNamespaceRegistry(_NamespaceRegistry):
238
+ def __setitem__(self, name, item):
239
+ if not callable(item):
240
+ raise NamespaceRegistryError, \
241
+ "Registered functions must be callable."
242
+ if not name:
243
+ raise ValueError, \
244
+ "extensions must have non empty names"
245
+ self._entries[_utf8(name)] = item
246
+
247
+ def __repr__(self):
248
+ return "FunctionNamespace(%r)" % self._ns_uri
249
+
250
+ @cython.final
251
+ @cython.internal
252
+ cdef class _XPathFunctionNamespaceRegistry(_FunctionNamespaceRegistry):
253
+ cdef object _prefix
254
+ cdef bytes _prefix_utf
255
+
256
+ property prefix:
257
+ "Namespace prefix for extension functions."
258
+ def __del__(self):
259
+ self._prefix = None # no prefix configured
260
+ self._prefix_utf = None
261
+ def __get__(self):
262
+ if self._prefix is None:
263
+ return ''
264
+ else:
265
+ return self._prefix
266
+ def __set__(self, prefix):
267
+ if prefix == '':
268
+ prefix = None # empty prefix
269
+ self._prefix_utf = _utf8(prefix) if prefix is not None else None
270
+ self._prefix = prefix
271
+
272
+ cdef list _find_all_extension_prefixes():
273
+ "Internal lookup function to find all function prefixes for XSLT/XPath."
274
+ cdef _XPathFunctionNamespaceRegistry registry
275
+ cdef list ns_prefixes = []
276
+ for registry in __FUNCTION_NAMESPACE_REGISTRIES.itervalues():
277
+ if registry._prefix_utf is not None:
278
+ if registry._ns_uri_utf is not None:
279
+ ns_prefixes.append(
280
+ (registry._prefix_utf, registry._ns_uri_utf))
281
+ return ns_prefixes
llava_video/lib/python3.10/site-packages/lxml/objectify.pyx ADDED
@@ -0,0 +1,2145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cython: binding=True
2
+ # cython: auto_pickle=False
3
+ # cython: language_level=3
4
+
5
+ """
6
+ The ``lxml.objectify`` module implements a Python object API for XML.
7
+ It is based on `lxml.etree`.
8
+ """
9
+
10
+ cimport cython
11
+
12
+ from lxml.includes.etreepublic cimport _Document, _Element, ElementBase, ElementClassLookup
13
+ from lxml.includes.etreepublic cimport elementFactory, import_lxml__etree, textOf, pyunicode
14
+ from lxml.includes.tree cimport const_xmlChar, _xcstr
15
+ from lxml cimport python
16
+ from lxml.includes cimport tree
17
+
18
+ cimport lxml.includes.etreepublic as cetree
19
+ cimport libc.string as cstring_h # not to be confused with stdlib 'string'
20
+ from libc.string cimport const_char
21
+
22
+ __all__ = ['BoolElement', 'DataElement', 'E', 'Element', 'ElementMaker',
23
+ 'FloatElement', 'IntElement', 'NoneElement',
24
+ 'NumberElement', 'ObjectPath', 'ObjectifiedDataElement',
25
+ 'ObjectifiedElement', 'ObjectifyElementClassLookup',
26
+ 'PYTYPE_ATTRIBUTE', 'PyType', 'StringElement', 'SubElement',
27
+ 'XML', 'annotate', 'deannotate', 'dump', 'enable_recursive_str',
28
+ 'fromstring', 'getRegisteredTypes', 'makeparser', 'parse',
29
+ 'pyannotate', 'pytypename', 'set_default_parser',
30
+ 'set_pytype_attribute_tag', 'xsiannotate']
31
+
32
+ cdef object etree
33
+ from lxml import etree
34
+ # initialize C-API of lxml.etree
35
+ import_lxml__etree()
36
+
37
+ __version__ = etree.__version__
38
+
39
+ cdef object _float_is_inf, _float_is_nan
40
+ from math import isinf as _float_is_inf, isnan as _float_is_nan
41
+
42
+ cdef object re
43
+ import re
44
+
45
+ cdef tuple IGNORABLE_ERRORS = (ValueError, TypeError)
46
+ cdef object is_special_method = re.compile('__.*__$').match
47
+
48
+
49
+ cdef object _typename(object t):
50
+ cdef const_char* c_name
51
+ c_name = python._fqtypename(t)
52
+ s = cstring_h.strrchr(c_name, c'.')
53
+ if s is not NULL:
54
+ c_name = s + 1
55
+ return pyunicode(<const_xmlChar*>c_name)
56
+
57
+
58
+ # namespace/name for "pytype" hint attribute
59
+ cdef object PYTYPE_NAMESPACE
60
+ cdef bytes PYTYPE_NAMESPACE_UTF8
61
+ cdef const_xmlChar* _PYTYPE_NAMESPACE
62
+
63
+ cdef object PYTYPE_ATTRIBUTE_NAME
64
+ cdef bytes PYTYPE_ATTRIBUTE_NAME_UTF8
65
+ cdef const_xmlChar* _PYTYPE_ATTRIBUTE_NAME
66
+
67
+ PYTYPE_ATTRIBUTE = None
68
+
69
+ cdef unicode TREE_PYTYPE_NAME = "TREE"
70
+
71
+ cdef tuple _unicodeAndUtf8(s):
72
+ return s, python.PyUnicode_AsUTF8String(s)
73
+
74
+ def set_pytype_attribute_tag(attribute_tag=None):
75
+ """set_pytype_attribute_tag(attribute_tag=None)
76
+ Change name and namespace of the XML attribute that holds Python type
77
+ information.
78
+
79
+ Do not use this unless you know what you are doing.
80
+
81
+ Reset by calling without argument.
82
+
83
+ Default: "{http://codespeak.net/lxml/objectify/pytype}pytype"
84
+ """
85
+ global PYTYPE_ATTRIBUTE, _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME
86
+ global PYTYPE_NAMESPACE, PYTYPE_NAMESPACE_UTF8
87
+ global PYTYPE_ATTRIBUTE_NAME, PYTYPE_ATTRIBUTE_NAME_UTF8
88
+ if attribute_tag is None:
89
+ PYTYPE_NAMESPACE, PYTYPE_NAMESPACE_UTF8 = \
90
+ _unicodeAndUtf8("http://codespeak.net/lxml/objectify/pytype")
91
+ PYTYPE_ATTRIBUTE_NAME, PYTYPE_ATTRIBUTE_NAME_UTF8 = \
92
+ _unicodeAndUtf8("pytype")
93
+ else:
94
+ PYTYPE_NAMESPACE_UTF8, PYTYPE_ATTRIBUTE_NAME_UTF8 = \
95
+ cetree.getNsTag(attribute_tag)
96
+ PYTYPE_NAMESPACE = PYTYPE_NAMESPACE_UTF8.decode('utf8')
97
+ PYTYPE_ATTRIBUTE_NAME = PYTYPE_ATTRIBUTE_NAME_UTF8.decode('utf8')
98
+
99
+ _PYTYPE_NAMESPACE = PYTYPE_NAMESPACE_UTF8
100
+ _PYTYPE_ATTRIBUTE_NAME = PYTYPE_ATTRIBUTE_NAME_UTF8
101
+ PYTYPE_ATTRIBUTE = cetree.namespacedNameFromNsName(
102
+ _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME)
103
+
104
+ set_pytype_attribute_tag()
105
+
106
+
107
+ # namespaces for XML Schema
108
+ cdef object XML_SCHEMA_NS, XML_SCHEMA_NS_UTF8
109
+ XML_SCHEMA_NS, XML_SCHEMA_NS_UTF8 = \
110
+ _unicodeAndUtf8("http://www.w3.org/2001/XMLSchema")
111
+ cdef const_xmlChar* _XML_SCHEMA_NS = _xcstr(XML_SCHEMA_NS_UTF8)
112
+
113
+ cdef object XML_SCHEMA_INSTANCE_NS, XML_SCHEMA_INSTANCE_NS_UTF8
114
+ XML_SCHEMA_INSTANCE_NS, XML_SCHEMA_INSTANCE_NS_UTF8 = \
115
+ _unicodeAndUtf8("http://www.w3.org/2001/XMLSchema-instance")
116
+ cdef const_xmlChar* _XML_SCHEMA_INSTANCE_NS = _xcstr(XML_SCHEMA_INSTANCE_NS_UTF8)
117
+
118
+ cdef object XML_SCHEMA_INSTANCE_NIL_ATTR = "{%s}nil" % XML_SCHEMA_INSTANCE_NS
119
+ cdef object XML_SCHEMA_INSTANCE_TYPE_ATTR = "{%s}type" % XML_SCHEMA_INSTANCE_NS
120
+
121
+
122
+ ################################################################################
123
+ # Element class for the main API
124
+
125
+ cdef class ObjectifiedElement(ElementBase):
126
+ """Main XML Element class.
127
+
128
+ Element children are accessed as object attributes. Multiple children
129
+ with the same name are available through a list index. Example::
130
+
131
+ >>> root = XML("<root><c1><c2>0</c2><c2>1</c2></c1></root>")
132
+ >>> second_c2 = root.c1.c2[1]
133
+ >>> print(second_c2.text)
134
+ 1
135
+
136
+ Note that you cannot (and must not) instantiate this class or its
137
+ subclasses.
138
+ """
139
+ def __iter__(self):
140
+ """Iterate over self and all siblings with the same tag.
141
+ """
142
+ parent = self.getparent()
143
+ if parent is None:
144
+ return iter([self])
145
+ return etree.ElementChildIterator(parent, tag=self.tag)
146
+
147
+ def __str__(self):
148
+ if __RECURSIVE_STR:
149
+ return _dump(self, 0)
150
+ else:
151
+ return textOf(self._c_node) or ''
152
+
153
+ # pickle support for objectified Element
154
+ def __reduce__(self):
155
+ return fromstring, (etree.tostring(self),)
156
+
157
+ @property
158
+ def text(self):
159
+ return textOf(self._c_node)
160
+
161
+ @property
162
+ def __dict__(self):
163
+ """A fake implementation for __dict__ to support dir() etc.
164
+
165
+ Note that this only considers the first child with a given name.
166
+ """
167
+ cdef _Element child
168
+ cdef dict children
169
+ c_ns = tree._getNs(self._c_node)
170
+ tag = "{%s}*" % pyunicode(c_ns) if c_ns is not NULL else None
171
+ children = {}
172
+ for child in etree.ElementChildIterator(self, tag=tag):
173
+ if c_ns is NULL and tree._getNs(child._c_node) is not NULL:
174
+ continue
175
+ name = pyunicode(child._c_node.name)
176
+ if name not in children:
177
+ children[name] = child
178
+ return children
179
+
180
+ def __len__(self):
181
+ """Count self and siblings with the same tag.
182
+ """
183
+ return _countSiblings(self._c_node)
184
+
185
+ def countchildren(self):
186
+ """countchildren(self)
187
+
188
+ Return the number of children of this element, regardless of their
189
+ name.
190
+ """
191
+ # copied from etree
192
+ cdef Py_ssize_t c
193
+ cdef tree.xmlNode* c_node
194
+ c = 0
195
+ c_node = self._c_node.children
196
+ while c_node is not NULL:
197
+ if tree._isElement(c_node):
198
+ c += 1
199
+ c_node = c_node.next
200
+ return c
201
+
202
+ def getchildren(self):
203
+ """getchildren(self)
204
+
205
+ Returns a sequence of all direct children. The elements are
206
+ returned in document order.
207
+ """
208
+ cdef tree.xmlNode* c_node
209
+ result = []
210
+ c_node = self._c_node.children
211
+ while c_node is not NULL:
212
+ if tree._isElement(c_node):
213
+ result.append(cetree.elementFactory(self._doc, c_node))
214
+ c_node = c_node.next
215
+ return result
216
+
217
+ def __getattr__(self, tag):
218
+ """Return the (first) child with the given tag name. If no namespace
219
+ is provided, the child will be looked up in the same one as self.
220
+ """
221
+ return _lookupChildOrRaise(self, tag)
222
+
223
+ def __setattr__(self, tag, value):
224
+ """Set the value of the (first) child with the given tag name. If no
225
+ namespace is provided, the child will be looked up in the same one as
226
+ self.
227
+ """
228
+ cdef _Element element
229
+ # properties are looked up /after/ __setattr__, so we must emulate them
230
+ if tag == 'text' or tag == 'pyval':
231
+ # read-only !
232
+ raise TypeError, f"attribute '{tag}' of '{_typename(self)}' objects is not writable"
233
+ elif tag == 'tail':
234
+ cetree.setTailText(self._c_node, value)
235
+ return
236
+ elif tag == 'tag':
237
+ ElementBase.tag.__set__(self, value)
238
+ return
239
+ elif tag == 'base':
240
+ ElementBase.base.__set__(self, value)
241
+ return
242
+ tag = _buildChildTag(self, tag)
243
+ element = _lookupChild(self, tag)
244
+ if element is None:
245
+ _appendValue(self, tag, value)
246
+ else:
247
+ _replaceElement(element, value)
248
+
249
+ def __delattr__(self, tag):
250
+ child = _lookupChildOrRaise(self, tag)
251
+ self.remove(child)
252
+
253
+ def addattr(self, tag, value):
254
+ """addattr(self, tag, value)
255
+
256
+ Add a child value to the element.
257
+
258
+ As opposed to append(), it sets a data value, not an element.
259
+ """
260
+ _appendValue(self, _buildChildTag(self, tag), value)
261
+
262
+ def __getitem__(self, key):
263
+ """Return a sibling, counting from the first child of the parent. The
264
+ method behaves like both a dict and a sequence.
265
+
266
+ * If argument is an integer, returns the sibling at that position.
267
+
268
+ * If argument is a string, does the same as getattr(). This can be
269
+ used to provide namespaces for element lookup, or to look up
270
+ children with special names (``text`` etc.).
271
+
272
+ * If argument is a slice object, returns the matching slice.
273
+ """
274
+ cdef tree.xmlNode* c_self_node
275
+ cdef tree.xmlNode* c_parent
276
+ cdef tree.xmlNode* c_node
277
+ cdef Py_ssize_t c_index
278
+ if python._isString(key):
279
+ return _lookupChildOrRaise(self, key)
280
+ elif isinstance(key, slice):
281
+ return list(self)[key]
282
+ # normal item access
283
+ c_index = key # raises TypeError if necessary
284
+ c_self_node = self._c_node
285
+ c_parent = c_self_node.parent
286
+ if c_parent is NULL:
287
+ if c_index == 0 or c_index == -1:
288
+ return self
289
+ raise IndexError, unicode(key)
290
+ if c_index < 0:
291
+ c_node = c_parent.last
292
+ else:
293
+ c_node = c_parent.children
294
+ c_node = _findFollowingSibling(
295
+ c_node, tree._getNs(c_self_node), c_self_node.name, c_index)
296
+ if c_node is NULL:
297
+ raise IndexError, unicode(key)
298
+ return elementFactory(self._doc, c_node)
299
+
300
+ def __setitem__(self, key, value):
301
+ """Set the value of a sibling, counting from the first child of the
302
+ parent. Implements key assignment, item assignment and slice
303
+ assignment.
304
+
305
+ * If argument is an integer, sets the sibling at that position.
306
+
307
+ * If argument is a string, does the same as setattr(). This is used
308
+ to provide namespaces for element lookup.
309
+
310
+ * If argument is a sequence (list, tuple, etc.), assign the contained
311
+ items to the siblings.
312
+ """
313
+ cdef _Element element
314
+ cdef tree.xmlNode* c_node
315
+ if python._isString(key):
316
+ key = _buildChildTag(self, key)
317
+ element = _lookupChild(self, key)
318
+ if element is None:
319
+ _appendValue(self, key, value)
320
+ else:
321
+ _replaceElement(element, value)
322
+ return
323
+
324
+ if self._c_node.parent is NULL:
325
+ # the 'root[i] = ...' case
326
+ raise TypeError, "assignment to root element is invalid"
327
+
328
+ if isinstance(key, slice):
329
+ # slice assignment
330
+ _setSlice(key, self, value)
331
+ else:
332
+ # normal index assignment
333
+ if key < 0:
334
+ c_node = self._c_node.parent.last
335
+ else:
336
+ c_node = self._c_node.parent.children
337
+ c_node = _findFollowingSibling(
338
+ c_node, tree._getNs(self._c_node), self._c_node.name, key)
339
+ if c_node is NULL:
340
+ raise IndexError, unicode(key)
341
+ element = elementFactory(self._doc, c_node)
342
+ _replaceElement(element, value)
343
+
344
+ def __delitem__(self, key):
345
+ parent = self.getparent()
346
+ if parent is None:
347
+ raise TypeError, "deleting items not supported by root element"
348
+ if isinstance(key, slice):
349
+ # slice deletion
350
+ del_items = list(self)[key]
351
+ remove = parent.remove
352
+ for el in del_items:
353
+ remove(el)
354
+ else:
355
+ # normal index deletion
356
+ sibling = self.__getitem__(key)
357
+ parent.remove(sibling)
358
+
359
+ def descendantpaths(self, prefix=None):
360
+ """descendantpaths(self, prefix=None)
361
+
362
+ Returns a list of object path expressions for all descendants.
363
+ """
364
+ if prefix is not None and not python._isString(prefix):
365
+ prefix = '.'.join(prefix)
366
+ return _build_descendant_paths(self._c_node, prefix)
367
+
368
+
369
+ cdef inline bint _tagMatches(tree.xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name):
370
+ if c_node.name != c_name:
371
+ return 0
372
+ if c_href == NULL:
373
+ return 1
374
+ c_node_href = tree._getNs(c_node)
375
+ if c_node_href == NULL:
376
+ return c_href[0] == c'\0'
377
+ return tree.xmlStrcmp(c_node_href, c_href) == 0
378
+
379
+
380
+ cdef Py_ssize_t _countSiblings(tree.xmlNode* c_start_node):
381
+ cdef tree.xmlNode* c_node
382
+ cdef Py_ssize_t count
383
+ c_tag = c_start_node.name
384
+ c_href = tree._getNs(c_start_node)
385
+ count = 1
386
+ c_node = c_start_node.next
387
+ while c_node is not NULL:
388
+ if c_node.type == tree.XML_ELEMENT_NODE and \
389
+ _tagMatches(c_node, c_href, c_tag):
390
+ count += 1
391
+ c_node = c_node.next
392
+ c_node = c_start_node.prev
393
+ while c_node is not NULL:
394
+ if c_node.type == tree.XML_ELEMENT_NODE and \
395
+ _tagMatches(c_node, c_href, c_tag):
396
+ count += 1
397
+ c_node = c_node.prev
398
+ return count
399
+
400
+ cdef tree.xmlNode* _findFollowingSibling(tree.xmlNode* c_node,
401
+ const_xmlChar* href, const_xmlChar* name,
402
+ Py_ssize_t index):
403
+ cdef tree.xmlNode* (*next)(tree.xmlNode*)
404
+ if index >= 0:
405
+ next = cetree.nextElement
406
+ else:
407
+ index = -1 - index
408
+ next = cetree.previousElement
409
+ while c_node is not NULL:
410
+ if c_node.type == tree.XML_ELEMENT_NODE and \
411
+ _tagMatches(c_node, href, name):
412
+ index = index - 1
413
+ if index < 0:
414
+ return c_node
415
+ c_node = next(c_node)
416
+ return NULL
417
+
418
+ cdef object _lookupChild(_Element parent, tag):
419
+ cdef tree.xmlNode* c_result
420
+ cdef tree.xmlNode* c_node
421
+ c_node = parent._c_node
422
+ ns, tag = cetree.getNsTagWithEmptyNs(tag)
423
+ c_tag = tree.xmlDictExists(
424
+ c_node.doc.dict, _xcstr(tag), python.PyBytes_GET_SIZE(tag))
425
+ if c_tag is NULL:
426
+ return None # not in the hash map => not in the tree
427
+ if ns is None:
428
+ # either inherit ns from parent or use empty (i.e. no) namespace
429
+ c_href = tree._getNs(c_node) or <const_xmlChar*>''
430
+ else:
431
+ c_href = _xcstr(ns)
432
+ c_result = _findFollowingSibling(c_node.children, c_href, c_tag, 0)
433
+ if c_result is NULL:
434
+ return None
435
+ return elementFactory(parent._doc, c_result)
436
+
437
+ cdef object _lookupChildOrRaise(_Element parent, tag):
438
+ element = _lookupChild(parent, tag)
439
+ if element is None:
440
+ raise AttributeError, "no such child: " + _buildChildTag(parent, tag)
441
+ return element
442
+
443
+ cdef object _buildChildTag(_Element parent, tag):
444
+ ns, tag = cetree.getNsTag(tag)
445
+ c_tag = _xcstr(tag)
446
+ c_href = tree._getNs(parent._c_node) if ns is None else _xcstr(ns)
447
+ return cetree.namespacedNameFromNsName(c_href, c_tag)
448
+
449
+ cdef _replaceElement(_Element element, value):
450
+ cdef _Element new_element
451
+ if isinstance(value, _Element):
452
+ # deep copy the new element
453
+ new_element = cetree.deepcopyNodeToDocument(
454
+ element._doc, (<_Element>value)._c_node)
455
+ new_element.tag = element.tag
456
+ elif isinstance(value, (list, tuple)):
457
+ element[:] = value
458
+ return
459
+ else:
460
+ new_element = element.makeelement(element.tag)
461
+ _setElementValue(new_element, value)
462
+ element.getparent().replace(element, new_element)
463
+
464
+ cdef _appendValue(_Element parent, tag, value):
465
+ cdef _Element new_element
466
+ if isinstance(value, _Element):
467
+ # deep copy the new element
468
+ new_element = cetree.deepcopyNodeToDocument(
469
+ parent._doc, (<_Element>value)._c_node)
470
+ new_element.tag = tag
471
+ cetree.appendChildToElement(parent, new_element)
472
+ elif isinstance(value, (list, tuple)):
473
+ for item in value:
474
+ _appendValue(parent, tag, item)
475
+ else:
476
+ new_element = cetree.makeElement(
477
+ tag, parent._doc, None, None, None, None, None)
478
+ _setElementValue(new_element, value)
479
+ cetree.appendChildToElement(parent, new_element)
480
+
481
+ cdef _setElementValue(_Element element, value):
482
+ if value is None:
483
+ cetree.setAttributeValue(
484
+ element, XML_SCHEMA_INSTANCE_NIL_ATTR, "true")
485
+ elif isinstance(value, _Element):
486
+ _replaceElement(element, value)
487
+ return
488
+ else:
489
+ cetree.delAttributeFromNsName(
490
+ element._c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"nil")
491
+ if python._isString(value):
492
+ pytype_name = "str"
493
+ py_type = <PyType>_PYTYPE_DICT.get(pytype_name)
494
+ else:
495
+ pytype_name = _typename(value)
496
+ py_type = <PyType>_PYTYPE_DICT.get(pytype_name)
497
+ if py_type is not None:
498
+ value = py_type.stringify(value)
499
+ else:
500
+ value = unicode(value)
501
+ if py_type is not None:
502
+ cetree.setAttributeValue(element, PYTYPE_ATTRIBUTE, pytype_name)
503
+ else:
504
+ cetree.delAttributeFromNsName(
505
+ element._c_node, _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME)
506
+ cetree.setNodeText(element._c_node, value)
507
+
508
+ cdef _setSlice(sliceobject, _Element target, items):
509
+ cdef _Element parent
510
+ cdef tree.xmlNode* c_node
511
+ cdef Py_ssize_t c_step, c_start, pos
512
+ # collect existing slice
513
+ if (<slice>sliceobject).step is None:
514
+ c_step = 1
515
+ else:
516
+ c_step = (<slice>sliceobject).step
517
+ if c_step == 0:
518
+ raise ValueError, "Invalid slice"
519
+ cdef list del_items = target[sliceobject]
520
+
521
+ # collect new values
522
+ new_items = []
523
+ tag = target.tag
524
+ for item in items:
525
+ if isinstance(item, _Element):
526
+ # deep copy the new element
527
+ new_element = cetree.deepcopyNodeToDocument(
528
+ target._doc, (<_Element>item)._c_node)
529
+ new_element.tag = tag
530
+ else:
531
+ new_element = cetree.makeElement(
532
+ tag, target._doc, None, None, None, None, None)
533
+ _setElementValue(new_element, item)
534
+ new_items.append(new_element)
535
+
536
+ # sanity check - raise what a list would raise
537
+ if c_step != 1 and len(del_items) != len(new_items):
538
+ raise ValueError, \
539
+ f"attempt to assign sequence of size {len(new_items)} to extended slice of size {len(del_items)}"
540
+
541
+ # replace existing items
542
+ pos = 0
543
+ parent = target.getparent()
544
+ replace = parent.replace
545
+ while pos < len(new_items) and pos < len(del_items):
546
+ replace(del_items[pos], new_items[pos])
547
+ pos += 1
548
+ # remove leftover items
549
+ if pos < len(del_items):
550
+ remove = parent.remove
551
+ while pos < len(del_items):
552
+ remove(del_items[pos])
553
+ pos += 1
554
+ # append remaining new items
555
+ if pos < len(new_items):
556
+ # the sanity check above guarantees (step == 1)
557
+ if pos > 0:
558
+ item = new_items[pos-1]
559
+ else:
560
+ if (<slice>sliceobject).start > 0:
561
+ c_node = parent._c_node.children
562
+ else:
563
+ c_node = parent._c_node.last
564
+ c_node = _findFollowingSibling(
565
+ c_node, tree._getNs(target._c_node), target._c_node.name,
566
+ (<slice>sliceobject).start - 1)
567
+ if c_node is NULL:
568
+ while pos < len(new_items):
569
+ cetree.appendChildToElement(parent, new_items[pos])
570
+ pos += 1
571
+ return
572
+ item = cetree.elementFactory(parent._doc, c_node)
573
+ while pos < len(new_items):
574
+ add = item.addnext
575
+ item = new_items[pos]
576
+ add(item)
577
+ pos += 1
578
+
579
+ ################################################################################
580
+ # Data type support in subclasses
581
+
582
+ cdef class ObjectifiedDataElement(ObjectifiedElement):
583
+ """This is the base class for all data type Elements. Subclasses should
584
+ override the 'pyval' property and possibly the __str__ method.
585
+ """
586
+ @property
587
+ def pyval(self):
588
+ return textOf(self._c_node)
589
+
590
+ def __str__(self):
591
+ return textOf(self._c_node) or ''
592
+
593
+ def __repr__(self):
594
+ return textOf(self._c_node) or ''
595
+
596
+ def _setText(self, s):
597
+ """For use in subclasses only. Don't use unless you know what you are
598
+ doing.
599
+ """
600
+ cetree.setNodeText(self._c_node, s)
601
+
602
+
603
+ cdef class NumberElement(ObjectifiedDataElement):
604
+ cdef object _parse_value
605
+
606
+ def _setValueParser(self, function):
607
+ """Set the function that parses the Python value from a string.
608
+
609
+ Do not use this unless you know what you are doing.
610
+ """
611
+ self._parse_value = function
612
+
613
+ @property
614
+ def pyval(self):
615
+ return _parseNumber(self)
616
+
617
+ def __int__(self):
618
+ return int(_parseNumber(self))
619
+
620
+ def __float__(self):
621
+ return float(_parseNumber(self))
622
+
623
+ def __complex__(self):
624
+ return complex(_parseNumber(self))
625
+
626
+ def __str__(self):
627
+ return unicode(_parseNumber(self))
628
+
629
+ def __repr__(self):
630
+ return repr(_parseNumber(self))
631
+
632
+ def __oct__(self):
633
+ return oct(_parseNumber(self))
634
+
635
+ def __hex__(self):
636
+ return hex(_parseNumber(self))
637
+
638
+ def __richcmp__(self, other, int op):
639
+ return _richcmpPyvals(self, other, op)
640
+
641
+ def __hash__(self):
642
+ return hash(_parseNumber(self))
643
+
644
+ def __add__(self, other):
645
+ return _numericValueOf(self) + _numericValueOf(other)
646
+
647
+ def __radd__(self, other):
648
+ return _numericValueOf(other) + _numericValueOf(self)
649
+
650
+ def __sub__(self, other):
651
+ return _numericValueOf(self) - _numericValueOf(other)
652
+
653
+ def __rsub__(self, other):
654
+ return _numericValueOf(other) - _numericValueOf(self)
655
+
656
+ def __mul__(self, other):
657
+ return _numericValueOf(self) * _numericValueOf(other)
658
+
659
+ def __rmul__(self, other):
660
+ return _numericValueOf(other) * _numericValueOf(self)
661
+
662
+ def __div__(self, other):
663
+ return _numericValueOf(self) / _numericValueOf(other)
664
+
665
+ def __rdiv__(self, other):
666
+ return _numericValueOf(other) / _numericValueOf(self)
667
+
668
+ def __truediv__(self, other):
669
+ return _numericValueOf(self) / _numericValueOf(other)
670
+
671
+ def __rtruediv__(self, other):
672
+ return _numericValueOf(other) / _numericValueOf(self)
673
+
674
+ def __floordiv__(self, other):
675
+ return _numericValueOf(self) // _numericValueOf(other)
676
+
677
+ def __rfloordiv__(self, other):
678
+ return _numericValueOf(other) // _numericValueOf(self)
679
+
680
+ def __mod__(self, other):
681
+ return _numericValueOf(self) % _numericValueOf(other)
682
+
683
+ def __rmod__(self, other):
684
+ return _numericValueOf(other) % _numericValueOf(self)
685
+
686
+ def __divmod__(self, other):
687
+ return divmod(_numericValueOf(self), _numericValueOf(other))
688
+
689
+ def __rdivmod__(self, other):
690
+ return divmod(_numericValueOf(other), _numericValueOf(self))
691
+
692
+ def __pow__(self, other, modulo):
693
+ if modulo is None:
694
+ return _numericValueOf(self) ** _numericValueOf(other)
695
+ else:
696
+ return pow(_numericValueOf(self), _numericValueOf(other), modulo)
697
+
698
+ def __rpow__(self, other, modulo):
699
+ if modulo is None:
700
+ return _numericValueOf(other) ** _numericValueOf(self)
701
+ else:
702
+ return pow(_numericValueOf(other), _numericValueOf(self), modulo)
703
+
704
+ def __neg__(self):
705
+ return - _numericValueOf(self)
706
+
707
+ def __pos__(self):
708
+ return + _numericValueOf(self)
709
+
710
+ def __abs__(self):
711
+ return abs( _numericValueOf(self) )
712
+
713
+ def __bool__(self):
714
+ return bool(_numericValueOf(self))
715
+
716
+ def __invert__(self):
717
+ return ~ _numericValueOf(self)
718
+
719
+ def __lshift__(self, other):
720
+ return _numericValueOf(self) << _numericValueOf(other)
721
+
722
+ def __rlshift__(self, other):
723
+ return _numericValueOf(other) << _numericValueOf(self)
724
+
725
+ def __rshift__(self, other):
726
+ return _numericValueOf(self) >> _numericValueOf(other)
727
+
728
+ def __rrshift__(self, other):
729
+ return _numericValueOf(other) >> _numericValueOf(self)
730
+
731
+ def __and__(self, other):
732
+ return _numericValueOf(self) & _numericValueOf(other)
733
+
734
+ def __rand__(self, other):
735
+ return _numericValueOf(other) & _numericValueOf(self)
736
+
737
+ def __or__(self, other):
738
+ return _numericValueOf(self) | _numericValueOf(other)
739
+
740
+ def __ror__(self, other):
741
+ return _numericValueOf(other) | _numericValueOf(self)
742
+
743
+ def __xor__(self, other):
744
+ return _numericValueOf(self) ^ _numericValueOf(other)
745
+
746
+ def __rxor__(self, other):
747
+ return _numericValueOf(other) ^ _numericValueOf(self)
748
+
749
+
750
+ cdef class IntElement(NumberElement):
751
+ def _init(self):
752
+ self._parse_value = int
753
+
754
+ def __index__(self):
755
+ return int(_parseNumber(self))
756
+
757
+
758
+ cdef class FloatElement(NumberElement):
759
+ def _init(self):
760
+ self._parse_value = float
761
+
762
+
763
+ cdef class StringElement(ObjectifiedDataElement):
764
+ """String data class.
765
+
766
+ Note that this class does *not* support the sequence protocol of strings:
767
+ len(), iter(), str_attr[0], str_attr[0:1], etc. are *not* supported.
768
+ Instead, use the .text attribute to get a 'real' string.
769
+ """
770
+ @property
771
+ def pyval(self):
772
+ return textOf(self._c_node) or ''
773
+
774
+ def __repr__(self):
775
+ return repr(textOf(self._c_node) or '')
776
+
777
+ def strlen(self):
778
+ text = textOf(self._c_node)
779
+ if text is None:
780
+ return 0
781
+ else:
782
+ return len(text)
783
+
784
+ def __bool__(self):
785
+ return bool(textOf(self._c_node))
786
+
787
+ def __richcmp__(self, other, int op):
788
+ return _richcmpPyvals(self, other, op)
789
+
790
+ def __hash__(self):
791
+ return hash(textOf(self._c_node) or '')
792
+
793
+ def __add__(self, other):
794
+ text = _strValueOf(self)
795
+ other = _strValueOf(other)
796
+ return text + other
797
+
798
+ def __radd__(self, other):
799
+ text = _strValueOf(self)
800
+ other = _strValueOf(other)
801
+ return other + text
802
+
803
+ def __mul__(self, other):
804
+ if isinstance(self, StringElement):
805
+ return (textOf((<StringElement>self)._c_node) or '') * _numericValueOf(other)
806
+ elif isinstance(other, StringElement):
807
+ return _numericValueOf(self) * (textOf((<StringElement>other)._c_node) or '')
808
+ else:
809
+ return NotImplemented
810
+
811
+ def __rmul__(self, other):
812
+ return _numericValueOf(other) * (textOf((<StringElement>self)._c_node) or '')
813
+
814
+ def __mod__(self, other):
815
+ return (_strValueOf(self) or '') % other
816
+
817
+ def __int__(self):
818
+ return int(textOf(self._c_node))
819
+
820
+ def __float__(self):
821
+ return float(textOf(self._c_node))
822
+
823
+ def __complex__(self):
824
+ return complex(textOf(self._c_node))
825
+
826
+
827
+ cdef class NoneElement(ObjectifiedDataElement):
828
+ def __str__(self):
829
+ return "None"
830
+
831
+ def __repr__(self):
832
+ return "None"
833
+
834
+ def __bool__(self):
835
+ return False
836
+
837
+ def __richcmp__(self, other, int op):
838
+ if other is None or self is None:
839
+ return python.PyObject_RichCompare(None, None, op)
840
+ if isinstance(self, NoneElement):
841
+ return python.PyObject_RichCompare(None, other, op)
842
+ else:
843
+ return python.PyObject_RichCompare(self, None, op)
844
+
845
+ def __hash__(self):
846
+ return hash(None)
847
+
848
+ @property
849
+ def pyval(self):
850
+ return None
851
+
852
+
853
+ cdef class BoolElement(IntElement):
854
+ """Boolean type base on string values: 'true' or 'false'.
855
+
856
+ Note that this inherits from IntElement to mimic the behaviour of
857
+ Python's bool type.
858
+ """
859
+ def _init(self):
860
+ self._parse_value = _parseBool # wraps as Python callable
861
+
862
+ def __bool__(self):
863
+ return _parseBool(textOf(self._c_node))
864
+
865
+ def __int__(self):
866
+ return 0 + _parseBool(textOf(self._c_node))
867
+
868
+ def __float__(self):
869
+ return 0.0 + _parseBool(textOf(self._c_node))
870
+
871
+ def __richcmp__(self, other, int op):
872
+ return _richcmpPyvals(self, other, op)
873
+
874
+ def __hash__(self):
875
+ return hash(_parseBool(textOf(self._c_node)))
876
+
877
+ def __str__(self):
878
+ return unicode(_parseBool(textOf(self._c_node)))
879
+
880
+ def __repr__(self):
881
+ return repr(_parseBool(textOf(self._c_node)))
882
+
883
+ @property
884
+ def pyval(self):
885
+ return _parseBool(textOf(self._c_node))
886
+
887
+
888
+ cdef _checkBool(s):
889
+ cdef int value = -1
890
+ if s is not None:
891
+ value = __parseBoolAsInt(s)
892
+ if value == -1:
893
+ raise ValueError
894
+
895
+
896
+ cdef bint _parseBool(s) except -1:
897
+ cdef int value
898
+ if s is None:
899
+ return False
900
+ value = __parseBoolAsInt(s)
901
+ if value == -1:
902
+ raise ValueError, f"Invalid boolean value: '{s}'"
903
+ return value
904
+
905
+
906
+ cdef inline int __parseBoolAsInt(text) except -2:
907
+ if text == 'false':
908
+ return 0
909
+ elif text == 'true':
910
+ return 1
911
+ elif text == '0':
912
+ return 0
913
+ elif text == '1':
914
+ return 1
915
+ return -1
916
+
917
+
918
+ cdef object _parseNumber(NumberElement element):
919
+ return element._parse_value(textOf(element._c_node))
920
+
921
+
922
+ cdef enum NumberParserState:
923
+ NPS_SPACE_PRE = 0
924
+ NPS_SIGN = 1
925
+ NPS_DIGITS = 2
926
+ NPS_POINT_LEAD = 3
927
+ NPS_POINT = 4
928
+ NPS_FRACTION = 5
929
+ NPS_EXP = 6
930
+ NPS_EXP_SIGN = 7
931
+ NPS_DIGITS_EXP = 8
932
+ NPS_SPACE_TAIL = 9
933
+ NPS_INF1 = 20
934
+ NPS_INF2 = 21
935
+ NPS_INF3 = 22
936
+ NPS_NAN1 = 23
937
+ NPS_NAN2 = 24
938
+ NPS_NAN3 = 25
939
+ NPS_ERROR = 99
940
+
941
+
942
+ ctypedef fused bytes_unicode:
943
+ bytes
944
+ unicode
945
+
946
+
947
+ cdef _checkNumber(bytes_unicode s, bint allow_float):
948
+ cdef Py_UCS4 c
949
+ cdef NumberParserState state = NPS_SPACE_PRE
950
+
951
+ for c in s:
952
+ if c in '0123456789':
953
+ if state in (NPS_DIGITS, NPS_FRACTION, NPS_DIGITS_EXP):
954
+ pass
955
+ elif state in (NPS_SPACE_PRE, NPS_SIGN):
956
+ state = NPS_DIGITS
957
+ elif state in (NPS_POINT_LEAD, NPS_POINT):
958
+ state = NPS_FRACTION
959
+ elif state in (NPS_EXP, NPS_EXP_SIGN):
960
+ state = NPS_DIGITS_EXP
961
+ else:
962
+ state = NPS_ERROR
963
+ else:
964
+ if c == '.':
965
+ if state in (NPS_SPACE_PRE, NPS_SIGN):
966
+ state = NPS_POINT_LEAD
967
+ elif state == NPS_DIGITS:
968
+ state = NPS_POINT
969
+ else:
970
+ state = NPS_ERROR
971
+ if not allow_float:
972
+ state = NPS_ERROR
973
+ elif c in '-+':
974
+ if state == NPS_SPACE_PRE:
975
+ state = NPS_SIGN
976
+ elif state == NPS_EXP:
977
+ state = NPS_EXP_SIGN
978
+ else:
979
+ state = NPS_ERROR
980
+ elif c == 'E':
981
+ if state in (NPS_DIGITS, NPS_POINT, NPS_FRACTION):
982
+ state = NPS_EXP
983
+ else:
984
+ state = NPS_ERROR
985
+ if not allow_float:
986
+ state = NPS_ERROR
987
+ # Allow INF and NaN. XMLSchema requires case, we don't, like Python.
988
+ elif c in 'iI':
989
+ state = NPS_INF1 if allow_float and state in (NPS_SPACE_PRE, NPS_SIGN) else NPS_ERROR
990
+ elif c in 'fF':
991
+ state = NPS_INF3 if state == NPS_INF2 else NPS_ERROR
992
+ elif c in 'aA':
993
+ state = NPS_NAN2 if state == NPS_NAN1 else NPS_ERROR
994
+ elif c in 'nN':
995
+ # Python also allows [+-]NaN, so let's accept that.
996
+ if state in (NPS_SPACE_PRE, NPS_SIGN):
997
+ state = NPS_NAN1 if allow_float else NPS_ERROR
998
+ elif state == NPS_NAN2:
999
+ state = NPS_NAN3
1000
+ elif state == NPS_INF1:
1001
+ state = NPS_INF2
1002
+ else:
1003
+ state = NPS_ERROR
1004
+ # Allow spaces around text values.
1005
+ else:
1006
+ if c.isspace() if (bytes_unicode is unicode) else c in b'\x09\x0a\x0b\x0c\x0d\x20':
1007
+ if state in (NPS_SPACE_PRE, NPS_SPACE_TAIL):
1008
+ pass
1009
+ elif state in (NPS_DIGITS, NPS_POINT, NPS_FRACTION, NPS_DIGITS_EXP, NPS_INF3, NPS_NAN3):
1010
+ state = NPS_SPACE_TAIL
1011
+ else:
1012
+ state = NPS_ERROR
1013
+ else:
1014
+ state = NPS_ERROR
1015
+
1016
+ if state == NPS_ERROR:
1017
+ break
1018
+
1019
+ if state not in (NPS_DIGITS, NPS_FRACTION, NPS_POINT, NPS_DIGITS_EXP, NPS_INF3, NPS_NAN3, NPS_SPACE_TAIL):
1020
+ raise ValueError
1021
+
1022
+
1023
+ cdef _checkInt(s):
1024
+ return _checkNumber(<unicode>s, allow_float=False)
1025
+
1026
+
1027
+ cdef _checkFloat(s):
1028
+ return _checkNumber(<unicode>s, allow_float=True)
1029
+
1030
+
1031
+ cdef object _strValueOf(obj):
1032
+ if python._isString(obj):
1033
+ return obj
1034
+ if isinstance(obj, _Element):
1035
+ return textOf((<_Element>obj)._c_node) or ''
1036
+ if obj is None:
1037
+ return ''
1038
+ return unicode(obj)
1039
+
1040
+
1041
+ cdef object _numericValueOf(obj):
1042
+ if isinstance(obj, NumberElement):
1043
+ return _parseNumber(<NumberElement>obj)
1044
+ try:
1045
+ # not always numeric, but Python will raise the right exception
1046
+ return obj.pyval
1047
+ except AttributeError:
1048
+ pass
1049
+ return obj
1050
+
1051
+
1052
+ cdef _richcmpPyvals(left, right, int op):
1053
+ left = getattr(left, 'pyval', left)
1054
+ right = getattr(right, 'pyval', right)
1055
+ return python.PyObject_RichCompare(left, right, op)
1056
+
1057
+
1058
+ ################################################################################
1059
+ # Python type registry
1060
+
1061
+ cdef class PyType:
1062
+ """PyType(self, name, type_check, type_class, stringify=None)
1063
+ User defined type.
1064
+
1065
+ Named type that contains a type check function, a type class that
1066
+ inherits from ObjectifiedDataElement and an optional "stringification"
1067
+ function. The type check must take a string as argument and raise
1068
+ ValueError or TypeError if it cannot handle the string value. It may be
1069
+ None in which case it is not considered for type guessing. For registered
1070
+ named types, the 'stringify' function (or unicode() if None) is used to
1071
+ convert a Python object with type name 'name' to the string representation
1072
+ stored in the XML tree.
1073
+
1074
+ Example::
1075
+
1076
+ PyType('int', int, MyIntClass).register()
1077
+
1078
+ Note that the order in which types are registered matters. The first
1079
+ matching type will be used.
1080
+ """
1081
+ cdef readonly object name
1082
+ cdef readonly object type_check
1083
+ cdef readonly object stringify
1084
+ cdef object _type
1085
+ cdef list _schema_types
1086
+ def __init__(self, name, type_check, type_class, stringify=None):
1087
+ if isinstance(name, bytes):
1088
+ name = (<bytes>name).decode('ascii')
1089
+ elif not isinstance(name, unicode):
1090
+ raise TypeError, "Type name must be a string"
1091
+ if type_check is not None and not callable(type_check):
1092
+ raise TypeError, "Type check function must be callable (or None)"
1093
+ if name != TREE_PYTYPE_NAME and \
1094
+ not issubclass(type_class, ObjectifiedDataElement):
1095
+ raise TypeError, \
1096
+ "Data classes must inherit from ObjectifiedDataElement"
1097
+ self.name = name
1098
+ self._type = type_class
1099
+ self.type_check = type_check
1100
+ if stringify is None:
1101
+ stringify = unicode
1102
+ self.stringify = stringify
1103
+ self._schema_types = []
1104
+
1105
+ def __repr__(self):
1106
+ return "PyType(%s, %s)" % (self.name, self._type.__name__)
1107
+
1108
+ def register(self, before=None, after=None):
1109
+ """register(self, before=None, after=None)
1110
+
1111
+ Register the type.
1112
+
1113
+ The additional keyword arguments 'before' and 'after' accept a
1114
+ sequence of type names that must appear before/after the new type in
1115
+ the type list. If any of them is not currently known, it is simply
1116
+ ignored. Raises ValueError if the dependencies cannot be fulfilled.
1117
+ """
1118
+ if self.name == TREE_PYTYPE_NAME:
1119
+ raise ValueError, "Cannot register tree type"
1120
+ if self.type_check is not None:
1121
+ for item in _TYPE_CHECKS:
1122
+ if item[0] is self.type_check:
1123
+ _TYPE_CHECKS.remove(item)
1124
+ break
1125
+ entry = (self.type_check, self)
1126
+ first_pos = 0
1127
+ last_pos = -1
1128
+ if before or after:
1129
+ if before is None:
1130
+ before = ()
1131
+ elif after is None:
1132
+ after = ()
1133
+ for i, (check, pytype) in enumerate(_TYPE_CHECKS):
1134
+ if last_pos == -1 and pytype.name in before:
1135
+ last_pos = i
1136
+ if pytype.name in after:
1137
+ first_pos = i+1
1138
+ if last_pos == -1:
1139
+ _TYPE_CHECKS.append(entry)
1140
+ elif first_pos > last_pos:
1141
+ raise ValueError, "inconsistent before/after dependencies"
1142
+ else:
1143
+ _TYPE_CHECKS.insert(last_pos, entry)
1144
+
1145
+ _PYTYPE_DICT[self.name] = self
1146
+ for xs_type in self._schema_types:
1147
+ _SCHEMA_TYPE_DICT[xs_type] = self
1148
+
1149
+ def unregister(self):
1150
+ "unregister(self)"
1151
+ if _PYTYPE_DICT.get(self.name) is self:
1152
+ del _PYTYPE_DICT[self.name]
1153
+ for xs_type, pytype in list(_SCHEMA_TYPE_DICT.items()):
1154
+ if pytype is self:
1155
+ del _SCHEMA_TYPE_DICT[xs_type]
1156
+ if self.type_check is None:
1157
+ return
1158
+ try:
1159
+ _TYPE_CHECKS.remove( (self.type_check, self) )
1160
+ except ValueError:
1161
+ pass
1162
+
1163
+ property xmlSchemaTypes:
1164
+ """The list of XML Schema datatypes this Python type maps to.
1165
+
1166
+ Note that this must be set before registering the type!
1167
+ """
1168
+ def __get__(self):
1169
+ return self._schema_types
1170
+ def __set__(self, types):
1171
+ self._schema_types = list(map(unicode, types))
1172
+
1173
+
1174
+ cdef dict _PYTYPE_DICT = {}
1175
+ cdef dict _SCHEMA_TYPE_DICT = {}
1176
+ cdef list _TYPE_CHECKS = []
1177
+
1178
+ cdef unicode _xml_bool(value):
1179
+ return "true" if value else "false"
1180
+
1181
+ cdef unicode _xml_float(value):
1182
+ if _float_is_inf(value):
1183
+ if value > 0:
1184
+ return "INF"
1185
+ return "-INF"
1186
+ if _float_is_nan(value):
1187
+ return "NaN"
1188
+ return unicode(repr(value))
1189
+
1190
+ cdef _pytypename(obj):
1191
+ return "str" if python._isString(obj) else _typename(obj)
1192
+
1193
+ def pytypename(obj):
1194
+ """pytypename(obj)
1195
+
1196
+ Find the name of the corresponding PyType for a Python object.
1197
+ """
1198
+ return _pytypename(obj)
1199
+
1200
+ cdef _registerPyTypes():
1201
+ pytype = PyType('int', _checkInt, IntElement) # wraps functions for Python
1202
+ pytype.xmlSchemaTypes = ("integer", "int", "short", "byte", "unsignedShort",
1203
+ "unsignedByte", "nonPositiveInteger",
1204
+ "negativeInteger", "long", "nonNegativeInteger",
1205
+ "unsignedLong", "unsignedInt", "positiveInteger",)
1206
+ pytype.register()
1207
+
1208
+ # 'long' type just for backwards compatibility
1209
+ pytype = PyType('long', None, IntElement)
1210
+ pytype.register()
1211
+
1212
+ pytype = PyType('float', _checkFloat, FloatElement, _xml_float) # wraps functions for Python
1213
+ pytype.xmlSchemaTypes = ("double", "float")
1214
+ pytype.register()
1215
+
1216
+ pytype = PyType('bool', _checkBool, BoolElement, _xml_bool) # wraps functions for Python
1217
+ pytype.xmlSchemaTypes = ("boolean",)
1218
+ pytype.register()
1219
+
1220
+ pytype = PyType('str', None, StringElement)
1221
+ pytype.xmlSchemaTypes = ("string", "normalizedString", "token", "language",
1222
+ "Name", "NCName", "ID", "IDREF", "ENTITY",
1223
+ "NMTOKEN", )
1224
+ pytype.register()
1225
+
1226
+ # since lxml 2.0
1227
+ pytype = PyType('NoneType', None, NoneElement)
1228
+ pytype.register()
1229
+
1230
+ # backwards compatibility
1231
+ pytype = PyType('none', None, NoneElement)
1232
+ pytype.register()
1233
+
1234
+ # non-registered PyType for inner tree elements
1235
+ cdef PyType TREE_PYTYPE = PyType(TREE_PYTYPE_NAME, None, ObjectifiedElement)
1236
+
1237
+ _registerPyTypes()
1238
+
1239
+ def getRegisteredTypes():
1240
+ """getRegisteredTypes()
1241
+
1242
+ Returns a list of the currently registered PyType objects.
1243
+
1244
+ To add a new type, retrieve this list and call unregister() for all
1245
+ entries. Then add the new type at a suitable position (possibly replacing
1246
+ an existing one) and call register() for all entries.
1247
+
1248
+ This is necessary if the new type interferes with the type check functions
1249
+ of existing ones (normally only int/float/bool) and must the tried before
1250
+ other types. To add a type that is not yet parsable by the current type
1251
+ check functions, you can simply register() it, which will append it to the
1252
+ end of the type list.
1253
+ """
1254
+ cdef list types = []
1255
+ cdef set known = set()
1256
+ for check, pytype in _TYPE_CHECKS:
1257
+ name = pytype.name
1258
+ if name not in known:
1259
+ known.add(name)
1260
+ types.append(pytype)
1261
+ for pytype in _PYTYPE_DICT.values():
1262
+ name = pytype.name
1263
+ if name not in known:
1264
+ known.add(name)
1265
+ types.append(pytype)
1266
+ return types
1267
+
1268
+ cdef PyType _guessPyType(value, PyType defaulttype):
1269
+ if value is None:
1270
+ return None
1271
+ for type_check, tested_pytype in _TYPE_CHECKS:
1272
+ try:
1273
+ type_check(value)
1274
+ return <PyType>tested_pytype
1275
+ except IGNORABLE_ERRORS:
1276
+ # could not be parsed as the specified type => ignore
1277
+ pass
1278
+ return defaulttype
1279
+
1280
+ cdef object _guessElementClass(tree.xmlNode* c_node):
1281
+ value = textOf(c_node)
1282
+ if value is None:
1283
+ return None
1284
+ if value == '':
1285
+ return StringElement
1286
+
1287
+ for type_check, pytype in _TYPE_CHECKS:
1288
+ try:
1289
+ type_check(value)
1290
+ return (<PyType>pytype)._type
1291
+ except IGNORABLE_ERRORS:
1292
+ pass
1293
+ return None
1294
+
1295
+ ################################################################################
1296
+ # adapted ElementMaker supports registered PyTypes
1297
+
1298
+ @cython.final
1299
+ @cython.internal
1300
+ cdef class _ObjectifyElementMakerCaller:
1301
+ cdef object _tag
1302
+ cdef object _nsmap
1303
+ cdef object _element_factory
1304
+ cdef bint _annotate
1305
+
1306
+ def __call__(self, *children, **attrib):
1307
+ "__call__(self, *children, **attrib)"
1308
+ cdef _ObjectifyElementMakerCaller elementMaker
1309
+ cdef _Element element
1310
+ cdef _Element childElement
1311
+ cdef bint has_children
1312
+ cdef bint has_string_value
1313
+ if self._element_factory is None:
1314
+ element = _makeElement(self._tag, None, attrib, self._nsmap)
1315
+ else:
1316
+ element = self._element_factory(self._tag, attrib, self._nsmap)
1317
+
1318
+ pytype_name = None
1319
+ has_children = False
1320
+ has_string_value = False
1321
+ for child in children:
1322
+ if child is None:
1323
+ if len(children) == 1:
1324
+ cetree.setAttributeValue(
1325
+ element, XML_SCHEMA_INSTANCE_NIL_ATTR, "true")
1326
+ elif python._isString(child):
1327
+ _add_text(element, child)
1328
+ has_string_value = True
1329
+ elif isinstance(child, _Element):
1330
+ cetree.appendChildToElement(element, <_Element>child)
1331
+ has_children = True
1332
+ elif isinstance(child, _ObjectifyElementMakerCaller):
1333
+ elementMaker = <_ObjectifyElementMakerCaller>child
1334
+ if elementMaker._element_factory is None:
1335
+ cetree.makeSubElement(element, elementMaker._tag,
1336
+ None, None, None, None)
1337
+ else:
1338
+ childElement = elementMaker._element_factory(
1339
+ elementMaker._tag)
1340
+ cetree.appendChildToElement(element, childElement)
1341
+ has_children = True
1342
+ elif isinstance(child, dict):
1343
+ for name, value in child.items():
1344
+ # keyword arguments in attrib take precedence
1345
+ if name in attrib:
1346
+ continue
1347
+ pytype = _PYTYPE_DICT.get(_typename(value))
1348
+ if pytype is not None:
1349
+ value = (<PyType>pytype).stringify(value)
1350
+ elif not python._isString(value):
1351
+ value = unicode(value)
1352
+ cetree.setAttributeValue(element, name, value)
1353
+ else:
1354
+ if pytype_name is not None:
1355
+ # concatenation always makes the result a string
1356
+ has_string_value = True
1357
+ pytype_name = _typename(child)
1358
+ pytype = _PYTYPE_DICT.get(_typename(child))
1359
+ if pytype is not None:
1360
+ _add_text(element, (<PyType>pytype).stringify(child))
1361
+ else:
1362
+ has_string_value = True
1363
+ child = unicode(child)
1364
+ _add_text(element, child)
1365
+
1366
+ if self._annotate and not has_children:
1367
+ if has_string_value:
1368
+ cetree.setAttributeValue(element, PYTYPE_ATTRIBUTE, "str")
1369
+ elif pytype_name is not None:
1370
+ cetree.setAttributeValue(element, PYTYPE_ATTRIBUTE, pytype_name)
1371
+
1372
+ return element
1373
+
1374
+ cdef _add_text(_Element elem, text):
1375
+ # add text to the tree in construction, either as element text or
1376
+ # tail text, depending on the current tree state
1377
+ cdef tree.xmlNode* c_child
1378
+ c_child = cetree.findChildBackwards(elem._c_node, 0)
1379
+ if c_child is not NULL:
1380
+ old = cetree.tailOf(c_child)
1381
+ if old is not None:
1382
+ text = old + text
1383
+ cetree.setTailText(c_child, text)
1384
+ else:
1385
+ old = cetree.textOf(elem._c_node)
1386
+ if old is not None:
1387
+ text = old + text
1388
+ cetree.setNodeText(elem._c_node, text)
1389
+
1390
+ cdef class ElementMaker:
1391
+ """ElementMaker(self, namespace=None, nsmap=None, annotate=True, makeelement=None)
1392
+
1393
+ An ElementMaker that can be used for constructing trees.
1394
+
1395
+ Example::
1396
+
1397
+ >>> M = ElementMaker(annotate=False)
1398
+ >>> attributes = {'class': 'par'}
1399
+ >>> html = M.html( M.body( M.p('hello', attributes, M.br, 'objectify', style="font-weight: bold") ) )
1400
+
1401
+ >>> from lxml.etree import tostring
1402
+ >>> print(tostring(html, method='html').decode('ascii'))
1403
+ <html><body><p style="font-weight: bold" class="par">hello<br>objectify</p></body></html>
1404
+
1405
+ To create tags that are not valid Python identifiers, call the factory
1406
+ directly and pass the tag name as first argument::
1407
+
1408
+ >>> root = M('tricky-tag', 'some text')
1409
+ >>> print(root.tag)
1410
+ tricky-tag
1411
+ >>> print(root.text)
1412
+ some text
1413
+
1414
+ Note that this module has a predefined ElementMaker instance called ``E``.
1415
+ """
1416
+ cdef object _makeelement
1417
+ cdef object _namespace
1418
+ cdef object _nsmap
1419
+ cdef bint _annotate
1420
+ cdef dict _cache
1421
+ def __init__(self, *, namespace=None, nsmap=None, annotate=True,
1422
+ makeelement=None):
1423
+ if nsmap is None:
1424
+ nsmap = _DEFAULT_NSMAP if annotate else {}
1425
+ self._nsmap = nsmap
1426
+ self._namespace = None if namespace is None else "{%s}" % namespace
1427
+ self._annotate = annotate
1428
+ if makeelement is not None:
1429
+ if not callable(makeelement):
1430
+ raise TypeError(
1431
+ f"argument of 'makeelement' parameter must be callable, got {type(makeelement)}")
1432
+ self._makeelement = makeelement
1433
+ else:
1434
+ self._makeelement = None
1435
+ self._cache = {}
1436
+
1437
+ @cython.final
1438
+ cdef _build_element_maker(self, tag, bint caching):
1439
+ cdef _ObjectifyElementMakerCaller element_maker
1440
+ element_maker = _ObjectifyElementMakerCaller.__new__(_ObjectifyElementMakerCaller)
1441
+ if self._namespace is not None and tag[0] != "{":
1442
+ element_maker._tag = self._namespace + tag
1443
+ else:
1444
+ element_maker._tag = tag
1445
+ element_maker._nsmap = self._nsmap
1446
+ element_maker._annotate = self._annotate
1447
+ element_maker._element_factory = self._makeelement
1448
+ if caching:
1449
+ if len(self._cache) > 200:
1450
+ self._cache.clear()
1451
+ self._cache[tag] = element_maker
1452
+ return element_maker
1453
+
1454
+ def __getattr__(self, tag):
1455
+ element_maker = self._cache.get(tag)
1456
+ if element_maker is None:
1457
+ return self._build_element_maker(tag, caching=True)
1458
+ return element_maker
1459
+
1460
+ def __call__(self, tag, *args, **kwargs):
1461
+ element_maker = self._cache.get(tag)
1462
+ if element_maker is None:
1463
+ element_maker = self._build_element_maker(
1464
+ tag, caching=not is_special_method(tag))
1465
+ return element_maker(*args, **kwargs)
1466
+
1467
+ ################################################################################
1468
+ # Recursive element dumping
1469
+
1470
+ cdef bint __RECURSIVE_STR = 0 # default: off
1471
+
1472
+ def enable_recursive_str(on=True):
1473
+ """enable_recursive_str(on=True)
1474
+
1475
+ Enable a recursively generated tree representation for str(element),
1476
+ based on objectify.dump(element).
1477
+ """
1478
+ global __RECURSIVE_STR
1479
+ __RECURSIVE_STR = on
1480
+
1481
+ def dump(_Element element not None):
1482
+ """dump(_Element element not None)
1483
+
1484
+ Return a recursively generated string representation of an element.
1485
+ """
1486
+ return _dump(element, 0)
1487
+
1488
+ cdef object _dump(_Element element, int indent):
1489
+ indentstr = " " * indent
1490
+ if isinstance(element, ObjectifiedDataElement):
1491
+ value = repr(element)
1492
+ else:
1493
+ value = textOf(element._c_node)
1494
+ if value is not None:
1495
+ if not value.strip():
1496
+ value = None
1497
+ else:
1498
+ value = repr(value)
1499
+ result = f"{indentstr}{element.tag} = {value} [{_typename(element)}]\n"
1500
+ xsi_ns = "{%s}" % XML_SCHEMA_INSTANCE_NS
1501
+ pytype_ns = "{%s}" % PYTYPE_NAMESPACE
1502
+ for name, value in sorted(cetree.iterattributes(element, 3)):
1503
+ if '{' in name:
1504
+ if name == PYTYPE_ATTRIBUTE:
1505
+ if value == TREE_PYTYPE_NAME:
1506
+ continue
1507
+ else:
1508
+ name = name.replace(pytype_ns, 'py:')
1509
+ name = name.replace(xsi_ns, 'xsi:')
1510
+ result += f"{indentstr} * {name} = {value!r}\n"
1511
+
1512
+ indent += 1
1513
+ for child in element.iterchildren():
1514
+ result += _dump(child, indent)
1515
+ if indent == 1:
1516
+ return result[:-1] # strip last '\n'
1517
+ else:
1518
+ return result
1519
+
1520
+
1521
+ ################################################################################
1522
+ # Pickle support for objectified ElementTree
1523
+
1524
+ def __unpickleElementTree(data):
1525
+ return etree.ElementTree(fromstring(data))
1526
+
1527
+ cdef _setupPickle(elementTreeReduceFunction):
1528
+ import copyreg
1529
+ copyreg.pickle(etree._ElementTree,
1530
+ elementTreeReduceFunction, __unpickleElementTree)
1531
+
1532
+ def pickleReduceElementTree(obj):
1533
+ return __unpickleElementTree, (etree.tostring(obj),)
1534
+
1535
+ _setupPickle(pickleReduceElementTree)
1536
+ del pickleReduceElementTree
1537
+
1538
+ ################################################################################
1539
+ # Element class lookup
1540
+
1541
+ cdef class ObjectifyElementClassLookup(ElementClassLookup):
1542
+ """ObjectifyElementClassLookup(self, tree_class=None, empty_data_class=None)
1543
+ Element class lookup method that uses the objectify classes.
1544
+ """
1545
+ cdef object empty_data_class
1546
+ cdef object tree_class
1547
+ def __init__(self, tree_class=None, empty_data_class=None):
1548
+ """Lookup mechanism for objectify.
1549
+
1550
+ The default Element classes can be replaced by passing subclasses of
1551
+ ObjectifiedElement and ObjectifiedDataElement as keyword arguments.
1552
+ 'tree_class' defines inner tree classes (defaults to
1553
+ ObjectifiedElement), 'empty_data_class' defines the default class for
1554
+ empty data elements (defaults to StringElement).
1555
+ """
1556
+ self._lookup_function = _lookupElementClass
1557
+ if tree_class is None:
1558
+ tree_class = ObjectifiedElement
1559
+ self.tree_class = tree_class
1560
+ if empty_data_class is None:
1561
+ empty_data_class = StringElement
1562
+ self.empty_data_class = empty_data_class
1563
+
1564
+ cdef object _lookupElementClass(state, _Document doc, tree.xmlNode* c_node):
1565
+ cdef ObjectifyElementClassLookup lookup
1566
+ lookup = <ObjectifyElementClassLookup>state
1567
+ # if element has children => no data class
1568
+ if cetree.hasChild(c_node):
1569
+ return lookup.tree_class
1570
+
1571
+ # if element is defined as xsi:nil, return NoneElement class
1572
+ if "true" == cetree.attributeValueFromNsName(
1573
+ c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"nil"):
1574
+ return NoneElement
1575
+
1576
+ # check for Python type hint
1577
+ value = cetree.attributeValueFromNsName(
1578
+ c_node, _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME)
1579
+ if value is not None:
1580
+ if value == TREE_PYTYPE_NAME:
1581
+ return lookup.tree_class
1582
+ py_type = <PyType>_PYTYPE_DICT.get(value)
1583
+ if py_type is not None:
1584
+ return py_type._type
1585
+ # unknown 'pyval' => try to figure it out ourself, just go on
1586
+
1587
+ # check for XML Schema type hint
1588
+ value = cetree.attributeValueFromNsName(
1589
+ c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"type")
1590
+
1591
+ if value is not None:
1592
+ schema_type = <PyType>_SCHEMA_TYPE_DICT.get(value)
1593
+ if schema_type is None and ':' in value:
1594
+ prefix, value = value.split(':', 1)
1595
+ schema_type = <PyType>_SCHEMA_TYPE_DICT.get(value)
1596
+ if schema_type is not None:
1597
+ return schema_type._type
1598
+
1599
+ # otherwise determine class based on text content type
1600
+ el_class = _guessElementClass(c_node)
1601
+ if el_class is not None:
1602
+ return el_class
1603
+
1604
+ # if element is a root node => default to tree node
1605
+ if c_node.parent is NULL or not tree._isElement(c_node.parent):
1606
+ return lookup.tree_class
1607
+
1608
+ return lookup.empty_data_class
1609
+
1610
+
1611
+ ################################################################################
1612
+ # Type annotations
1613
+
1614
+ cdef PyType _check_type(tree.xmlNode* c_node, PyType pytype):
1615
+ if pytype is None:
1616
+ return None
1617
+ value = textOf(c_node)
1618
+ try:
1619
+ pytype.type_check(value)
1620
+ return pytype
1621
+ except IGNORABLE_ERRORS:
1622
+ # could not be parsed as the specified type => ignore
1623
+ pass
1624
+ return None
1625
+
1626
+ def pyannotate(element_or_tree, *, ignore_old=False, ignore_xsi=False,
1627
+ empty_pytype=None):
1628
+ """pyannotate(element_or_tree, ignore_old=False, ignore_xsi=False, empty_pytype=None)
1629
+
1630
+ Recursively annotates the elements of an XML tree with 'pytype'
1631
+ attributes.
1632
+
1633
+ If the 'ignore_old' keyword argument is True (the default), current 'pytype'
1634
+ attributes will be ignored and replaced. Otherwise, they will be checked
1635
+ and only replaced if they no longer fit the current text value.
1636
+
1637
+ Setting the keyword argument ``ignore_xsi`` to True makes the function
1638
+ additionally ignore existing ``xsi:type`` annotations. The default is to
1639
+ use them as a type hint.
1640
+
1641
+ The default annotation of empty elements can be set with the
1642
+ ``empty_pytype`` keyword argument. The default is not to annotate empty
1643
+ elements. Pass 'str', for example, to make string values the default.
1644
+ """
1645
+ cdef _Element element
1646
+ element = cetree.rootNodeOrRaise(element_or_tree)
1647
+ _annotate(element, 0, 1, ignore_xsi, ignore_old, None, empty_pytype)
1648
+
1649
+ def xsiannotate(element_or_tree, *, ignore_old=False, ignore_pytype=False,
1650
+ empty_type=None):
1651
+ """xsiannotate(element_or_tree, ignore_old=False, ignore_pytype=False, empty_type=None)
1652
+
1653
+ Recursively annotates the elements of an XML tree with 'xsi:type'
1654
+ attributes.
1655
+
1656
+ If the 'ignore_old' keyword argument is True (the default), current
1657
+ 'xsi:type' attributes will be ignored and replaced. Otherwise, they will be
1658
+ checked and only replaced if they no longer fit the current text value.
1659
+
1660
+ Note that the mapping from Python types to XSI types is usually ambiguous.
1661
+ Currently, only the first XSI type name in the corresponding PyType
1662
+ definition will be used for annotation. Thus, you should consider naming
1663
+ the widest type first if you define additional types.
1664
+
1665
+ Setting the keyword argument ``ignore_pytype`` to True makes the function
1666
+ additionally ignore existing ``pytype`` annotations. The default is to
1667
+ use them as a type hint.
1668
+
1669
+ The default annotation of empty elements can be set with the
1670
+ ``empty_type`` keyword argument. The default is not to annotate empty
1671
+ elements. Pass 'string', for example, to make string values the default.
1672
+ """
1673
+ cdef _Element element
1674
+ element = cetree.rootNodeOrRaise(element_or_tree)
1675
+ _annotate(element, 1, 0, ignore_old, ignore_pytype, empty_type, None)
1676
+
1677
+ def annotate(element_or_tree, *, ignore_old=True, ignore_xsi=False,
1678
+ empty_pytype=None, empty_type=None, annotate_xsi=0,
1679
+ annotate_pytype=1):
1680
+ """annotate(element_or_tree, ignore_old=True, ignore_xsi=False, empty_pytype=None, empty_type=None, annotate_xsi=0, annotate_pytype=1)
1681
+
1682
+ Recursively annotates the elements of an XML tree with 'xsi:type'
1683
+ and/or 'py:pytype' attributes.
1684
+
1685
+ If the 'ignore_old' keyword argument is True (the default), current
1686
+ 'py:pytype' attributes will be ignored for the type annotation. Set to False
1687
+ if you want reuse existing 'py:pytype' information (iff appropriate for the
1688
+ element text value).
1689
+
1690
+ If the 'ignore_xsi' keyword argument is False (the default), existing
1691
+ 'xsi:type' attributes will be used for the type annotation, if they fit the
1692
+ element text values.
1693
+
1694
+ Note that the mapping from Python types to XSI types is usually ambiguous.
1695
+ Currently, only the first XSI type name in the corresponding PyType
1696
+ definition will be used for annotation. Thus, you should consider naming
1697
+ the widest type first if you define additional types.
1698
+
1699
+ The default 'py:pytype' annotation of empty elements can be set with the
1700
+ ``empty_pytype`` keyword argument. Pass 'str', for example, to make
1701
+ string values the default.
1702
+
1703
+ The default 'xsi:type' annotation of empty elements can be set with the
1704
+ ``empty_type`` keyword argument. The default is not to annotate empty
1705
+ elements. Pass 'string', for example, to make string values the default.
1706
+
1707
+ The keyword arguments 'annotate_xsi' (default: 0) and 'annotate_pytype'
1708
+ (default: 1) control which kind(s) of annotation to use.
1709
+ """
1710
+ cdef _Element element
1711
+ element = cetree.rootNodeOrRaise(element_or_tree)
1712
+ _annotate(element, annotate_xsi, annotate_pytype, ignore_xsi,
1713
+ ignore_old, empty_type, empty_pytype)
1714
+
1715
+
1716
+ cdef _annotate(_Element element, bint annotate_xsi, bint annotate_pytype,
1717
+ bint ignore_xsi, bint ignore_pytype,
1718
+ empty_type_name, empty_pytype_name):
1719
+ cdef _Document doc
1720
+ cdef tree.xmlNode* c_node
1721
+ cdef PyType empty_pytype, StrType, NoneType
1722
+
1723
+ if not annotate_xsi and not annotate_pytype:
1724
+ return
1725
+
1726
+ if empty_type_name is not None:
1727
+ if isinstance(empty_type_name, bytes):
1728
+ empty_type_name = (<bytes>empty_type_name).decode("ascii")
1729
+ empty_pytype = <PyType>_SCHEMA_TYPE_DICT.get(empty_type_name)
1730
+ elif empty_pytype_name is not None:
1731
+ if isinstance(empty_pytype_name, bytes):
1732
+ empty_pytype_name = (<bytes>empty_pytype_name).decode("ascii")
1733
+ empty_pytype = <PyType>_PYTYPE_DICT.get(empty_pytype_name)
1734
+ else:
1735
+ empty_pytype = None
1736
+
1737
+ StrType = <PyType>_PYTYPE_DICT.get('str')
1738
+ NoneType = <PyType>_PYTYPE_DICT.get('NoneType')
1739
+
1740
+ doc = element._doc
1741
+ c_node = element._c_node
1742
+ tree.BEGIN_FOR_EACH_ELEMENT_FROM(c_node, c_node, 1)
1743
+ if c_node.type == tree.XML_ELEMENT_NODE:
1744
+ _annotate_element(c_node, doc, annotate_xsi, annotate_pytype,
1745
+ ignore_xsi, ignore_pytype,
1746
+ empty_type_name, empty_pytype, StrType, NoneType)
1747
+ tree.END_FOR_EACH_ELEMENT_FROM(c_node)
1748
+
1749
+ cdef int _annotate_element(tree.xmlNode* c_node, _Document doc,
1750
+ bint annotate_xsi, bint annotate_pytype,
1751
+ bint ignore_xsi, bint ignore_pytype,
1752
+ empty_type_name, PyType empty_pytype,
1753
+ PyType StrType, PyType NoneType) except -1:
1754
+ cdef tree.xmlNs* c_ns
1755
+ cdef PyType pytype = None
1756
+ typename = None
1757
+ istree = 0
1758
+
1759
+ # if element is defined as xsi:nil, represent it as None
1760
+ if cetree.attributeValueFromNsName(
1761
+ c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"nil") == "true":
1762
+ pytype = NoneType
1763
+
1764
+ if pytype is None and not ignore_xsi:
1765
+ # check that old xsi type value is valid
1766
+ typename = cetree.attributeValueFromNsName(
1767
+ c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"type")
1768
+ if typename is not None:
1769
+ pytype = <PyType>_SCHEMA_TYPE_DICT.get(typename)
1770
+ if pytype is None and ':' in typename:
1771
+ prefix, typename = typename.split(':', 1)
1772
+ pytype = <PyType>_SCHEMA_TYPE_DICT.get(typename)
1773
+ if pytype is not None and pytype is not StrType:
1774
+ # StrType does not have a typecheck but is the default
1775
+ # anyway, so just accept it if given as type
1776
+ # information
1777
+ pytype = _check_type(c_node, pytype)
1778
+ if pytype is None:
1779
+ typename = None
1780
+
1781
+ if pytype is None and not ignore_pytype:
1782
+ # check that old pytype value is valid
1783
+ old_pytypename = cetree.attributeValueFromNsName(
1784
+ c_node, _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME)
1785
+ if old_pytypename is not None:
1786
+ if old_pytypename == TREE_PYTYPE_NAME:
1787
+ if not cetree.hasChild(c_node):
1788
+ # only case where we should keep it,
1789
+ # everything else is clear enough
1790
+ pytype = TREE_PYTYPE
1791
+ else:
1792
+ if old_pytypename == 'none':
1793
+ # transition from lxml 1.x
1794
+ old_pytypename = "NoneType"
1795
+ pytype = <PyType>_PYTYPE_DICT.get(old_pytypename)
1796
+ if pytype is not None and pytype is not StrType:
1797
+ # StrType does not have a typecheck but is the
1798
+ # default anyway, so just accept it if given as
1799
+ # type information
1800
+ pytype = _check_type(c_node, pytype)
1801
+
1802
+ if pytype is None:
1803
+ # try to guess type
1804
+ if not cetree.hasChild(c_node):
1805
+ # element has no children => data class
1806
+ pytype = _guessPyType(textOf(c_node), StrType)
1807
+ else:
1808
+ istree = 1
1809
+
1810
+ if pytype is None:
1811
+ # use default type for empty elements
1812
+ if cetree.hasText(c_node):
1813
+ pytype = StrType
1814
+ else:
1815
+ pytype = empty_pytype
1816
+ if typename is None:
1817
+ typename = empty_type_name
1818
+
1819
+ if pytype is not None:
1820
+ if typename is None:
1821
+ if not istree:
1822
+ if pytype._schema_types:
1823
+ # pytype->xsi:type is a 1:n mapping
1824
+ # simply take the first
1825
+ typename = pytype._schema_types[0]
1826
+ elif typename not in pytype._schema_types:
1827
+ typename = pytype._schema_types[0]
1828
+
1829
+ if annotate_xsi:
1830
+ if typename is None or istree:
1831
+ cetree.delAttributeFromNsName(
1832
+ c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>"type")
1833
+ else:
1834
+ # update or create attribute
1835
+ typename_utf8 = cetree.utf8(typename)
1836
+ c_ns = cetree.findOrBuildNodeNsPrefix(
1837
+ doc, c_node, _XML_SCHEMA_NS, <unsigned char*>'xsd')
1838
+ if c_ns is not NULL:
1839
+ if b':' in typename_utf8:
1840
+ prefix, name = typename_utf8.split(b':', 1)
1841
+ if c_ns.prefix is NULL or c_ns.prefix[0] == c'\0':
1842
+ typename_utf8 = name
1843
+ elif tree.xmlStrcmp(_xcstr(prefix), c_ns.prefix) != 0:
1844
+ typename_utf8 = (<unsigned char*>c_ns.prefix) + b':' + name
1845
+ elif c_ns.prefix is not NULL and c_ns.prefix[0] != c'\0':
1846
+ typename_utf8 = (<unsigned char*>c_ns.prefix) + b':' + typename_utf8
1847
+ c_ns = cetree.findOrBuildNodeNsPrefix(
1848
+ doc, c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>'xsi')
1849
+ tree.xmlSetNsProp(c_node, c_ns, <unsigned char*>"type", _xcstr(typename_utf8))
1850
+
1851
+ if annotate_pytype:
1852
+ if pytype is None:
1853
+ # delete attribute if it exists
1854
+ cetree.delAttributeFromNsName(
1855
+ c_node, _PYTYPE_NAMESPACE, _PYTYPE_ATTRIBUTE_NAME)
1856
+ else:
1857
+ # update or create attribute
1858
+ c_ns = cetree.findOrBuildNodeNsPrefix(
1859
+ doc, c_node, _PYTYPE_NAMESPACE, <unsigned char*>'py')
1860
+ pytype_name = cetree.utf8(pytype.name)
1861
+ tree.xmlSetNsProp(c_node, c_ns, _PYTYPE_ATTRIBUTE_NAME,
1862
+ _xcstr(pytype_name))
1863
+ if pytype is NoneType:
1864
+ c_ns = cetree.findOrBuildNodeNsPrefix(
1865
+ doc, c_node, _XML_SCHEMA_INSTANCE_NS, <unsigned char*>'xsi')
1866
+ tree.xmlSetNsProp(c_node, c_ns, <unsigned char*>"nil", <unsigned char*>"true")
1867
+
1868
+ return 0
1869
+
1870
+ cdef object _strip_attributes = etree.strip_attributes
1871
+ cdef object _cleanup_namespaces = etree.cleanup_namespaces
1872
+
1873
+ def deannotate(element_or_tree, *, bint pytype=True, bint xsi=True,
1874
+ bint xsi_nil=False, bint cleanup_namespaces=False):
1875
+ """deannotate(element_or_tree, pytype=True, xsi=True, xsi_nil=False, cleanup_namespaces=False)
1876
+
1877
+ Recursively de-annotate the elements of an XML tree by removing 'py:pytype'
1878
+ and/or 'xsi:type' attributes and/or 'xsi:nil' attributes.
1879
+
1880
+ If the 'pytype' keyword argument is True (the default), 'py:pytype'
1881
+ attributes will be removed. If the 'xsi' keyword argument is True (the
1882
+ default), 'xsi:type' attributes will be removed.
1883
+ If the 'xsi_nil' keyword argument is True (default: False), 'xsi:nil'
1884
+ attributes will be removed.
1885
+
1886
+ Note that this does not touch the namespace declarations by
1887
+ default. If you want to remove unused namespace declarations from
1888
+ the tree, pass the option ``cleanup_namespaces=True``.
1889
+ """
1890
+ cdef list attribute_names = []
1891
+
1892
+ if pytype:
1893
+ attribute_names.append(PYTYPE_ATTRIBUTE)
1894
+ if xsi:
1895
+ attribute_names.append(XML_SCHEMA_INSTANCE_TYPE_ATTR)
1896
+ if xsi_nil:
1897
+ attribute_names.append(XML_SCHEMA_INSTANCE_NIL_ATTR)
1898
+
1899
+ _strip_attributes(element_or_tree, *attribute_names)
1900
+ if cleanup_namespaces:
1901
+ _cleanup_namespaces(element_or_tree)
1902
+
1903
+ ################################################################################
1904
+ # Module level parser setup
1905
+
1906
+ cdef object __DEFAULT_PARSER
1907
+ __DEFAULT_PARSER = etree.XMLParser(remove_blank_text=True)
1908
+ __DEFAULT_PARSER.set_element_class_lookup( ObjectifyElementClassLookup() )
1909
+
1910
+ cdef object objectify_parser
1911
+ objectify_parser = __DEFAULT_PARSER
1912
+
1913
+ def set_default_parser(new_parser = None):
1914
+ """set_default_parser(new_parser = None)
1915
+
1916
+ Replace the default parser used by objectify's Element() and
1917
+ fromstring() functions.
1918
+
1919
+ The new parser must be an etree.XMLParser.
1920
+
1921
+ Call without arguments to reset to the original parser.
1922
+ """
1923
+ global objectify_parser
1924
+ if new_parser is None:
1925
+ objectify_parser = __DEFAULT_PARSER
1926
+ elif isinstance(new_parser, etree.XMLParser):
1927
+ objectify_parser = new_parser
1928
+ else:
1929
+ raise TypeError, "parser must inherit from lxml.etree.XMLParser"
1930
+
1931
+ def makeparser(**kw):
1932
+ """makeparser(remove_blank_text=True, **kw)
1933
+
1934
+ Create a new XML parser for objectify trees.
1935
+
1936
+ You can pass all keyword arguments that are supported by
1937
+ ``etree.XMLParser()``. Note that this parser defaults to removing
1938
+ blank text. You can disable this by passing the
1939
+ ``remove_blank_text`` boolean keyword option yourself.
1940
+ """
1941
+ if 'remove_blank_text' not in kw:
1942
+ kw['remove_blank_text'] = True
1943
+ parser = etree.XMLParser(**kw)
1944
+ parser.set_element_class_lookup( ObjectifyElementClassLookup() )
1945
+ return parser
1946
+
1947
+ cdef _Element _makeElement(tag, text, attrib, nsmap):
1948
+ return cetree.makeElement(tag, None, objectify_parser, text, None, attrib, nsmap)
1949
+
1950
+ ################################################################################
1951
+ # Module level factory functions
1952
+
1953
+ cdef object _fromstring
1954
+ _fromstring = etree.fromstring
1955
+
1956
+ SubElement = etree.SubElement
1957
+
1958
+ def fromstring(xml, parser=None, *, base_url=None):
1959
+ """fromstring(xml, parser=None, base_url=None)
1960
+
1961
+ Objectify specific version of the lxml.etree fromstring() function
1962
+ that uses the objectify parser.
1963
+
1964
+ You can pass a different parser as second argument.
1965
+
1966
+ The ``base_url`` keyword argument allows to set the original base URL of
1967
+ the document to support relative Paths when looking up external entities
1968
+ (DTD, XInclude, ...).
1969
+ """
1970
+ if parser is None:
1971
+ parser = objectify_parser
1972
+ return _fromstring(xml, parser, base_url=base_url)
1973
+
1974
+ def XML(xml, parser=None, *, base_url=None):
1975
+ """XML(xml, parser=None, base_url=None)
1976
+
1977
+ Objectify specific version of the lxml.etree XML() literal factory
1978
+ that uses the objectify parser.
1979
+
1980
+ You can pass a different parser as second argument.
1981
+
1982
+ The ``base_url`` keyword argument allows to set the original base URL of
1983
+ the document to support relative Paths when looking up external entities
1984
+ (DTD, XInclude, ...).
1985
+ """
1986
+ if parser is None:
1987
+ parser = objectify_parser
1988
+ return _fromstring(xml, parser, base_url=base_url)
1989
+
1990
+ cdef object _parse
1991
+ _parse = etree.parse
1992
+
1993
+ def parse(f, parser=None, *, base_url=None):
1994
+ """parse(f, parser=None, base_url=None)
1995
+
1996
+ Parse a file or file-like object with the objectify parser.
1997
+
1998
+ You can pass a different parser as second argument.
1999
+
2000
+ The ``base_url`` keyword allows setting a URL for the document
2001
+ when parsing from a file-like object. This is needed when looking
2002
+ up external entities (DTD, XInclude, ...) with relative paths.
2003
+ """
2004
+ if parser is None:
2005
+ parser = objectify_parser
2006
+ return _parse(f, parser, base_url=base_url)
2007
+
2008
+ cdef dict _DEFAULT_NSMAP = {
2009
+ "py" : PYTYPE_NAMESPACE,
2010
+ "xsi" : XML_SCHEMA_INSTANCE_NS,
2011
+ "xsd" : XML_SCHEMA_NS
2012
+ }
2013
+
2014
+ E = ElementMaker()
2015
+
2016
+ def Element(_tag, attrib=None, nsmap=None, *, _pytype=None, **_attributes):
2017
+ """Element(_tag, attrib=None, nsmap=None, _pytype=None, **_attributes)
2018
+
2019
+ Objectify specific version of the lxml.etree Element() factory that
2020
+ always creates a structural (tree) element.
2021
+
2022
+ NOTE: requires parser based element class lookup activated in lxml.etree!
2023
+ """
2024
+ if attrib is not None:
2025
+ if _attributes:
2026
+ attrib = dict(attrib)
2027
+ attrib.update(_attributes)
2028
+ _attributes = attrib
2029
+ if _pytype is None:
2030
+ _pytype = TREE_PYTYPE_NAME
2031
+ if nsmap is None:
2032
+ nsmap = _DEFAULT_NSMAP
2033
+ _attributes[PYTYPE_ATTRIBUTE] = _pytype
2034
+ return _makeElement(_tag, None, _attributes, nsmap)
2035
+
2036
+ def DataElement(_value, attrib=None, nsmap=None, *, _pytype=None, _xsi=None,
2037
+ **_attributes):
2038
+ """DataElement(_value, attrib=None, nsmap=None, _pytype=None, _xsi=None, **_attributes)
2039
+
2040
+ Create a new element from a Python value and XML attributes taken from
2041
+ keyword arguments or a dictionary passed as second argument.
2042
+
2043
+ Automatically adds a 'pytype' attribute for the Python type of the value,
2044
+ if the type can be identified. If '_pytype' or '_xsi' are among the
2045
+ keyword arguments, they will be used instead.
2046
+
2047
+ If the _value argument is an ObjectifiedDataElement instance, its py:pytype,
2048
+ xsi:type and other attributes and nsmap are reused unless they are redefined
2049
+ in attrib and/or keyword arguments.
2050
+ """
2051
+ if nsmap is None:
2052
+ nsmap = _DEFAULT_NSMAP
2053
+ if attrib is not None and attrib:
2054
+ if _attributes:
2055
+ attrib = dict(attrib)
2056
+ attrib.update(_attributes)
2057
+ _attributes = attrib
2058
+ if isinstance(_value, ObjectifiedElement):
2059
+ if _pytype is None:
2060
+ if _xsi is None and not _attributes and nsmap is _DEFAULT_NSMAP:
2061
+ # special case: no change!
2062
+ return _value.__copy__()
2063
+ if isinstance(_value, ObjectifiedDataElement):
2064
+ # reuse existing nsmap unless redefined in nsmap parameter
2065
+ temp = _value.nsmap
2066
+ if temp is not None and temp:
2067
+ temp = dict(temp)
2068
+ temp.update(nsmap)
2069
+ nsmap = temp
2070
+ # reuse existing attributes unless redefined in attrib/_attributes
2071
+ temp = _value.attrib
2072
+ if temp is not None and temp:
2073
+ temp = dict(temp)
2074
+ temp.update(_attributes)
2075
+ _attributes = temp
2076
+ # reuse existing xsi:type or py:pytype attributes, unless provided as
2077
+ # arguments
2078
+ if _xsi is None and _pytype is None:
2079
+ _xsi = _attributes.get(XML_SCHEMA_INSTANCE_TYPE_ATTR)
2080
+ _pytype = _attributes.get(PYTYPE_ATTRIBUTE)
2081
+
2082
+ if _xsi is not None:
2083
+ if ':' in _xsi:
2084
+ prefix, name = _xsi.split(':', 1)
2085
+ ns = nsmap.get(prefix)
2086
+ if ns != XML_SCHEMA_NS:
2087
+ raise ValueError, "XSD types require the XSD namespace"
2088
+ elif nsmap is _DEFAULT_NSMAP:
2089
+ name = _xsi
2090
+ _xsi = 'xsd:' + _xsi
2091
+ else:
2092
+ name = _xsi
2093
+ for prefix, ns in nsmap.items():
2094
+ if ns == XML_SCHEMA_NS:
2095
+ if prefix is not None and prefix:
2096
+ _xsi = prefix + ':' + _xsi
2097
+ break
2098
+ else:
2099
+ raise ValueError, "XSD types require the XSD namespace"
2100
+ _attributes[XML_SCHEMA_INSTANCE_TYPE_ATTR] = _xsi
2101
+ if _pytype is None:
2102
+ # allow using unregistered or even wrong xsi:type names
2103
+ py_type = <PyType>_SCHEMA_TYPE_DICT.get(_xsi)
2104
+ if py_type is None:
2105
+ py_type = <PyType>_SCHEMA_TYPE_DICT.get(name)
2106
+ if py_type is not None:
2107
+ _pytype = py_type.name
2108
+
2109
+ if _pytype is None:
2110
+ _pytype = _pytypename(_value)
2111
+
2112
+ if _value is None and _pytype != "str":
2113
+ _pytype = _pytype or "NoneType"
2114
+ strval = None
2115
+ elif python._isString(_value):
2116
+ strval = _value
2117
+ elif isinstance(_value, bool):
2118
+ if _value:
2119
+ strval = "true"
2120
+ else:
2121
+ strval = "false"
2122
+ else:
2123
+ py_type = <PyType>_PYTYPE_DICT.get(_pytype)
2124
+ stringify = unicode if py_type is None else py_type.stringify
2125
+ strval = stringify(_value)
2126
+
2127
+ if _pytype is not None:
2128
+ if _pytype == "NoneType" or _pytype == "none":
2129
+ strval = None
2130
+ _attributes[XML_SCHEMA_INSTANCE_NIL_ATTR] = "true"
2131
+ else:
2132
+ # check if type information from arguments is valid
2133
+ py_type = <PyType>_PYTYPE_DICT.get(_pytype)
2134
+ if py_type is not None:
2135
+ if py_type.type_check is not None:
2136
+ py_type.type_check(strval)
2137
+ _attributes[PYTYPE_ATTRIBUTE] = _pytype
2138
+
2139
+ return _makeElement("value", strval, _attributes, nsmap)
2140
+
2141
+
2142
+ ################################################################################
2143
+ # ObjectPath
2144
+
2145
+ include "objectpath.pxi"
llava_video/lib/python3.10/site-packages/lxml/objectpath.pxi ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ################################################################################
2
+ # ObjectPath
3
+
4
+ ctypedef struct _ObjectPath:
5
+ const_xmlChar* href
6
+ const_xmlChar* name
7
+ Py_ssize_t index
8
+
9
+
10
+ cdef object _NO_DEFAULT = object()
11
+
12
+
13
+ cdef class ObjectPath:
14
+ """ObjectPath(path)
15
+ Immutable object that represents a compiled object path.
16
+
17
+ Example for a path: 'root.child[1].{other}child[25]'
18
+ """
19
+ cdef readonly object find
20
+ cdef list _path
21
+ cdef object _path_str
22
+ cdef _ObjectPath* _c_path
23
+ cdef Py_ssize_t _path_len
24
+ def __init__(self, path):
25
+ if python._isString(path):
26
+ self._path = _parse_object_path_string(path)
27
+ self._path_str = path
28
+ else:
29
+ self._path = _parse_object_path_list(path)
30
+ self._path_str = '.'.join(path)
31
+ self._path_len = len(self._path)
32
+ self._c_path = _build_object_path_segments(self._path)
33
+ self.find = self.__call__
34
+
35
+ def __dealloc__(self):
36
+ if self._c_path is not NULL:
37
+ python.lxml_free(self._c_path)
38
+
39
+ def __str__(self):
40
+ return self._path_str
41
+
42
+ def __call__(self, _Element root not None, *_default):
43
+ """Follow the attribute path in the object structure and return the
44
+ target attribute value.
45
+
46
+ If it it not found, either returns a default value (if one was passed
47
+ as second argument) or raises AttributeError.
48
+ """
49
+ if _default:
50
+ if len(_default) > 1:
51
+ raise TypeError, "invalid number of arguments: needs one or two"
52
+ default = _default[0]
53
+ else:
54
+ default = _NO_DEFAULT
55
+ return _find_object_path(root, self._c_path, self._path_len, default)
56
+
57
+ def hasattr(self, _Element root not None):
58
+ "hasattr(self, root)"
59
+ try:
60
+ _find_object_path(root, self._c_path, self._path_len, _NO_DEFAULT)
61
+ except AttributeError:
62
+ return False
63
+ return True
64
+
65
+ def setattr(self, _Element root not None, value):
66
+ """setattr(self, root, value)
67
+
68
+ Set the value of the target element in a subtree.
69
+
70
+ If any of the children on the path does not exist, it is created.
71
+ """
72
+ _create_object_path(root, self._c_path, self._path_len, 1, value)
73
+
74
+ def addattr(self, _Element root not None, value):
75
+ """addattr(self, root, value)
76
+
77
+ Append a value to the target element in a subtree.
78
+
79
+ If any of the children on the path does not exist, it is created.
80
+ """
81
+ _create_object_path(root, self._c_path, self._path_len, 0, value)
82
+
83
+
84
+ cdef object __MATCH_PATH_SEGMENT = re.compile(
85
+ r"(\.?)\s*(?:\{([^}]*)\})?\s*([^.{}\[\]\s]+)\s*(?:\[\s*([-0-9]+)\s*\])?",
86
+ re.U).match
87
+
88
+ cdef tuple _RELATIVE_PATH_SEGMENT = (None, None, 0)
89
+
90
+
91
+ cdef list _parse_object_path_string(_path):
92
+ """Parse object path string into a (ns, name, index) list.
93
+ """
94
+ cdef bint has_dot
95
+ cdef unicode path
96
+ new_path = []
97
+ if isinstance(_path, bytes):
98
+ path = (<bytes>_path).decode('ascii')
99
+ elif type(_path) is not unicode:
100
+ path = unicode(_path)
101
+ else:
102
+ path = _path
103
+ path = path.strip()
104
+ if path == '.':
105
+ return [_RELATIVE_PATH_SEGMENT]
106
+ path_pos = 0
107
+ while path:
108
+ match = __MATCH_PATH_SEGMENT(path, path_pos)
109
+ if match is None:
110
+ break
111
+
112
+ dot, ns, name, index = match.groups()
113
+ index = int(index) if index else 0
114
+ has_dot = dot == '.'
115
+ if not new_path:
116
+ if has_dot:
117
+ # path '.child' => ignore root
118
+ new_path.append(_RELATIVE_PATH_SEGMENT)
119
+ elif index:
120
+ raise ValueError, "index not allowed on root node"
121
+ elif not has_dot:
122
+ raise ValueError, "invalid path"
123
+ if ns is not None:
124
+ ns = python.PyUnicode_AsUTF8String(ns)
125
+ name = python.PyUnicode_AsUTF8String(name)
126
+ new_path.append( (ns, name, index) )
127
+
128
+ path_pos = match.end()
129
+ if not new_path or len(path) > path_pos:
130
+ raise ValueError, "invalid path"
131
+ return new_path
132
+
133
+
134
+ cdef list _parse_object_path_list(path):
135
+ """Parse object path sequence into a (ns, name, index) list.
136
+ """
137
+ new_path = []
138
+ for item in path:
139
+ item = item.strip()
140
+ if not new_path and item == '':
141
+ # path '.child' => ignore root
142
+ ns = name = None
143
+ index = 0
144
+ else:
145
+ ns, name = cetree.getNsTag(item)
146
+ c_name = _xcstr(name)
147
+ index_pos = tree.xmlStrchr(c_name, c'[')
148
+ if index_pos is NULL:
149
+ index = 0
150
+ else:
151
+ index_end = tree.xmlStrchr(index_pos + 1, c']')
152
+ if index_end is NULL:
153
+ raise ValueError, "index must be enclosed in []"
154
+ index = int(index_pos[1:index_end - index_pos])
155
+ if not new_path and index != 0:
156
+ raise ValueError, "index not allowed on root node"
157
+ name = <bytes>c_name[:index_pos - c_name]
158
+ new_path.append( (ns, name, index) )
159
+ if not new_path:
160
+ raise ValueError, "invalid path"
161
+ return new_path
162
+
163
+
164
+ cdef _ObjectPath* _build_object_path_segments(list path_list) except NULL:
165
+ cdef _ObjectPath* c_path
166
+ cdef _ObjectPath* c_path_segments
167
+ c_path_segments = <_ObjectPath*>python.lxml_malloc(len(path_list), sizeof(_ObjectPath))
168
+ if c_path_segments is NULL:
169
+ raise MemoryError()
170
+ c_path = c_path_segments
171
+ for href, name, index in path_list:
172
+ c_path[0].href = _xcstr(href) if href is not None else NULL
173
+ c_path[0].name = _xcstr(name) if name is not None else NULL
174
+ c_path[0].index = index
175
+ c_path += 1
176
+ return c_path_segments
177
+
178
+
179
+ cdef _find_object_path(_Element root, _ObjectPath* c_path, Py_ssize_t c_path_len, default_value):
180
+ """Follow the path to find the target element.
181
+ """
182
+ cdef tree.xmlNode* c_node
183
+ cdef Py_ssize_t c_index
184
+ c_node = root._c_node
185
+ c_name = c_path[0].name
186
+ c_href = c_path[0].href
187
+ if c_href is NULL or c_href[0] == c'\0':
188
+ c_href = tree._getNs(c_node)
189
+ if not cetree.tagMatches(c_node, c_href, c_name):
190
+ if default_value is not _NO_DEFAULT:
191
+ return default_value
192
+ else:
193
+ raise ValueError(
194
+ f"root element does not match: need {cetree.namespacedNameFromNsName(c_href, c_name)}, got {root.tag}")
195
+
196
+ while c_node is not NULL:
197
+ c_path_len -= 1
198
+ if c_path_len <= 0:
199
+ break
200
+
201
+ c_path += 1
202
+ if c_path[0].href is not NULL:
203
+ c_href = c_path[0].href # otherwise: keep parent namespace
204
+ c_name = tree.xmlDictExists(c_node.doc.dict, c_path[0].name, -1)
205
+ if c_name is NULL:
206
+ c_name = c_path[0].name
207
+ c_node = NULL
208
+ break
209
+ c_index = c_path[0].index
210
+ c_node = c_node.last if c_index < 0 else c_node.children
211
+ c_node = _findFollowingSibling(c_node, c_href, c_name, c_index)
212
+
213
+ if c_node is not NULL:
214
+ return cetree.elementFactory(root._doc, c_node)
215
+ elif default_value is not _NO_DEFAULT:
216
+ return default_value
217
+ else:
218
+ tag = cetree.namespacedNameFromNsName(c_href, c_name)
219
+ raise AttributeError, f"no such child: {tag}"
220
+
221
+
222
+ cdef _create_object_path(_Element root, _ObjectPath* c_path,
223
+ Py_ssize_t c_path_len, int replace, value):
224
+ """Follow the path to find the target element, build the missing children
225
+ as needed and set the target element to 'value'. If replace is true, an
226
+ existing value is replaced, otherwise the new value is added.
227
+ """
228
+ cdef _Element child
229
+ cdef tree.xmlNode* c_node
230
+ cdef tree.xmlNode* c_child
231
+ cdef Py_ssize_t c_index
232
+ if c_path_len == 1:
233
+ raise TypeError, "cannot update root node"
234
+
235
+ c_node = root._c_node
236
+ c_name = c_path[0].name
237
+ c_href = c_path[0].href
238
+ if c_href is NULL or c_href[0] == c'\0':
239
+ c_href = tree._getNs(c_node)
240
+ if not cetree.tagMatches(c_node, c_href, c_name):
241
+ raise ValueError(
242
+ f"root element does not match: need {cetree.namespacedNameFromNsName(c_href, c_name)}, got {root.tag}")
243
+
244
+ while c_path_len > 1:
245
+ c_path_len -= 1
246
+ c_path += 1
247
+ if c_path[0].href is not NULL:
248
+ c_href = c_path[0].href # otherwise: keep parent namespace
249
+ c_index = c_path[0].index
250
+ c_name = tree.xmlDictExists(c_node.doc.dict, c_path[0].name, -1)
251
+ if c_name is NULL:
252
+ c_name = c_path[0].name
253
+ c_child = NULL
254
+ else:
255
+ c_child = c_node.last if c_index < 0 else c_node.children
256
+ c_child = _findFollowingSibling(c_child, c_href, c_name, c_index)
257
+
258
+ if c_child is not NULL:
259
+ c_node = c_child
260
+ elif c_index != 0:
261
+ raise TypeError, "creating indexed path attributes is not supported"
262
+ elif c_path_len == 1:
263
+ _appendValue(cetree.elementFactory(root._doc, c_node),
264
+ cetree.namespacedNameFromNsName(c_href, c_name),
265
+ value)
266
+ return
267
+ else:
268
+ child = cetree.makeSubElement(
269
+ cetree.elementFactory(root._doc, c_node),
270
+ cetree.namespacedNameFromNsName(c_href, c_name),
271
+ None, None, None, None)
272
+ c_node = child._c_node
273
+
274
+ # if we get here, the entire path was already there
275
+ if replace:
276
+ element = cetree.elementFactory(root._doc, c_node)
277
+ _replaceElement(element, value)
278
+ else:
279
+ _appendValue(cetree.elementFactory(root._doc, c_node.parent),
280
+ cetree.namespacedName(c_node), value)
281
+
282
+
283
+ cdef list _build_descendant_paths(tree.xmlNode* c_node, prefix_string):
284
+ """Returns a list of all descendant paths.
285
+ """
286
+ cdef list path, path_list
287
+ tag = cetree.namespacedName(c_node)
288
+ if prefix_string:
289
+ if prefix_string[-1] != '.':
290
+ prefix_string += '.'
291
+ prefix_string = prefix_string + tag
292
+ else:
293
+ prefix_string = tag
294
+ path = [prefix_string]
295
+ path_list = []
296
+ _recursive_build_descendant_paths(c_node, path, path_list)
297
+ return path_list
298
+
299
+
300
+ cdef int _recursive_build_descendant_paths(tree.xmlNode* c_node,
301
+ list path, list path_list) except -1:
302
+ """Fills the list 'path_list' with all descendant paths, initial prefix
303
+ being in the list 'path'.
304
+ """
305
+ cdef tree.xmlNode* c_child
306
+ tags = {}
307
+ path_list.append('.'.join(path))
308
+ c_href = tree._getNs(c_node)
309
+ c_child = c_node.children
310
+ while c_child is not NULL:
311
+ while c_child.type != tree.XML_ELEMENT_NODE:
312
+ c_child = c_child.next
313
+ if c_child is NULL:
314
+ return 0
315
+ if c_href is tree._getNs(c_child):
316
+ tag = pyunicode(c_child.name)
317
+ elif c_href is not NULL and tree._getNs(c_child) is NULL:
318
+ # special case: parent has namespace, child does not
319
+ tag = '{}' + pyunicode(c_child.name)
320
+ else:
321
+ tag = cetree.namespacedName(c_child)
322
+ count = tags.get(tag)
323
+ if count is None:
324
+ tags[tag] = 1
325
+ else:
326
+ tags[tag] = count + 1
327
+ tag += f'[{count}]'
328
+ path.append(tag)
329
+ _recursive_build_descendant_paths(c_child, path, path_list)
330
+ del path[-1]
331
+ c_child = c_child.next
332
+ return 0
llava_video/lib/python3.10/site-packages/lxml/parser.pxi ADDED
@@ -0,0 +1,2000 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Parsers for XML and HTML
2
+
3
+ from lxml.includes cimport xmlparser
4
+ from lxml.includes cimport htmlparser
5
+
6
+
7
+ class ParseError(LxmlSyntaxError):
8
+ """Syntax error while parsing an XML document.
9
+
10
+ For compatibility with ElementTree 1.3 and later.
11
+ """
12
+ def __init__(self, message, code, line, column, filename=None):
13
+ super(_ParseError, self).__init__(message)
14
+ self.lineno, self.offset = (line, column - 1)
15
+ self.code = code
16
+ self.filename = filename
17
+
18
+ @property
19
+ def position(self):
20
+ return self.lineno, self.offset + 1
21
+
22
+ @position.setter
23
+ def position(self, new_pos):
24
+ self.lineno, column = new_pos
25
+ self.offset = column - 1
26
+
27
+ cdef object _ParseError = ParseError
28
+
29
+
30
+ class XMLSyntaxError(ParseError):
31
+ """Syntax error while parsing an XML document.
32
+ """
33
+
34
+ cdef class ParserError(LxmlError):
35
+ """Internal lxml parser error.
36
+ """
37
+
38
+
39
+ @cython.final
40
+ @cython.internal
41
+ cdef class _ParserDictionaryContext:
42
+ # Global parser context to share the string dictionary.
43
+ #
44
+ # This class is a delegate singleton!
45
+ #
46
+ # It creates _ParserDictionaryContext objects for each thread to keep thread state,
47
+ # but those must never be used directly. Always stick to using the static
48
+ # __GLOBAL_PARSER_CONTEXT as defined below the class.
49
+ #
50
+
51
+ cdef tree.xmlDict* _c_dict
52
+ cdef _BaseParser _default_parser
53
+ cdef list _implied_parser_contexts
54
+
55
+ def __cinit__(self):
56
+ self._c_dict = NULL
57
+ self._implied_parser_contexts = []
58
+
59
+ def __dealloc__(self):
60
+ if self._c_dict is not NULL:
61
+ xmlparser.xmlDictFree(self._c_dict)
62
+
63
+ cdef int initMainParserContext(self) except -1:
64
+ """Put the global context into the thread dictionary of the main
65
+ thread. To be called once and only in the main thread."""
66
+ thread_dict = python.PyThreadState_GetDict()
67
+ if thread_dict is not NULL:
68
+ (<dict>thread_dict)["_ParserDictionaryContext"] = self
69
+
70
+ cdef _ParserDictionaryContext _findThreadParserContext(self):
71
+ "Find (or create) the _ParserDictionaryContext object for the current thread"
72
+ cdef _ParserDictionaryContext context
73
+ thread_dict = python.PyThreadState_GetDict()
74
+ if thread_dict is NULL:
75
+ return self
76
+ d = <dict>thread_dict
77
+ result = python.PyDict_GetItem(d, "_ParserDictionaryContext")
78
+ if result is not NULL:
79
+ return <object>result
80
+ context = <_ParserDictionaryContext>_ParserDictionaryContext.__new__(_ParserDictionaryContext)
81
+ d["_ParserDictionaryContext"] = context
82
+ return context
83
+
84
+ cdef int setDefaultParser(self, _BaseParser parser) except -1:
85
+ "Set the default parser for the current thread"
86
+ cdef _ParserDictionaryContext context
87
+ context = self._findThreadParserContext()
88
+ context._default_parser = parser
89
+
90
+ cdef _BaseParser getDefaultParser(self):
91
+ "Return (or create) the default parser of the current thread"
92
+ cdef _ParserDictionaryContext context
93
+ context = self._findThreadParserContext()
94
+ if context._default_parser is None:
95
+ if self._default_parser is None:
96
+ self._default_parser = __DEFAULT_XML_PARSER._copy()
97
+ if context is not self:
98
+ context._default_parser = self._default_parser._copy()
99
+ return context._default_parser
100
+
101
+ cdef tree.xmlDict* _getThreadDict(self, tree.xmlDict* default):
102
+ "Return the thread-local dict or create a new one if necessary."
103
+ cdef _ParserDictionaryContext context
104
+ context = self._findThreadParserContext()
105
+ if context._c_dict is NULL:
106
+ # thread dict not yet set up => use default or create a new one
107
+ if default is not NULL:
108
+ context._c_dict = default
109
+ xmlparser.xmlDictReference(default)
110
+ return default
111
+ if self._c_dict is NULL:
112
+ self._c_dict = xmlparser.xmlDictCreate()
113
+ if context is not self:
114
+ context._c_dict = xmlparser.xmlDictCreateSub(self._c_dict)
115
+ return context._c_dict
116
+
117
+ cdef int initThreadDictRef(self, tree.xmlDict** c_dict_ref) except -1:
118
+ c_dict = c_dict_ref[0]
119
+ c_thread_dict = self._getThreadDict(c_dict)
120
+ if c_dict is c_thread_dict:
121
+ return 0
122
+ if c_dict is not NULL:
123
+ xmlparser.xmlDictFree(c_dict)
124
+ c_dict_ref[0] = c_thread_dict
125
+ xmlparser.xmlDictReference(c_thread_dict)
126
+
127
+ cdef int initParserDict(self, xmlparser.xmlParserCtxt* pctxt) except -1:
128
+ "Assure we always use the same string dictionary."
129
+ self.initThreadDictRef(&pctxt.dict)
130
+ pctxt.dictNames = 1
131
+
132
+ cdef int initXPathParserDict(self, xpath.xmlXPathContext* pctxt) except -1:
133
+ "Assure we always use the same string dictionary."
134
+ self.initThreadDictRef(&pctxt.dict)
135
+
136
+ cdef int initDocDict(self, xmlDoc* result) except -1:
137
+ "Store dict of last object parsed if no shared dict yet"
138
+ # XXX We also free the result dict here if there already was one.
139
+ # This case should only occur for new documents with empty dicts,
140
+ # otherwise we'd free data that's in use => segfault
141
+ self.initThreadDictRef(&result.dict)
142
+
143
+ cdef _ParserContext findImpliedContext(self):
144
+ """Return any current implied xml parser context for the current
145
+ thread. This is used when the resolver functions are called
146
+ with an xmlParserCtxt that was generated from within libxml2
147
+ (i.e. without a _ParserContext) - which happens when parsing
148
+ schema and xinclude external references."""
149
+ cdef _ParserDictionaryContext context
150
+ cdef _ParserContext implied_context
151
+
152
+ # see if we have a current implied parser
153
+ context = self._findThreadParserContext()
154
+ if context._implied_parser_contexts:
155
+ implied_context = context._implied_parser_contexts[-1]
156
+ return implied_context
157
+ return None
158
+
159
+ cdef int pushImpliedContextFromParser(self, _BaseParser parser) except -1:
160
+ "Push a new implied context object taken from the parser."
161
+ if parser is not None:
162
+ self.pushImpliedContext(parser._getParserContext())
163
+ else:
164
+ self.pushImpliedContext(None)
165
+
166
+ cdef int pushImpliedContext(self, _ParserContext parser_context) except -1:
167
+ "Push a new implied context object."
168
+ cdef _ParserDictionaryContext context
169
+ context = self._findThreadParserContext()
170
+ context._implied_parser_contexts.append(parser_context)
171
+
172
+ cdef int popImpliedContext(self) except -1:
173
+ "Pop the current implied context object."
174
+ cdef _ParserDictionaryContext context
175
+ context = self._findThreadParserContext()
176
+ context._implied_parser_contexts.pop()
177
+
178
+ cdef _ParserDictionaryContext __GLOBAL_PARSER_CONTEXT = _ParserDictionaryContext()
179
+ __GLOBAL_PARSER_CONTEXT.initMainParserContext()
180
+
181
+ ############################################################
182
+ ## support for Python unicode I/O
183
+ ############################################################
184
+
185
+ # name of Python Py_UNICODE encoding as known to libxml2
186
+ cdef const_char* _PY_UNICODE_ENCODING = NULL
187
+
188
+ cdef int _setupPythonUnicode() except -1:
189
+ """Sets _PY_UNICODE_ENCODING to the internal encoding name of Python unicode
190
+ strings if libxml2 supports reading native Python unicode. This depends
191
+ on iconv and the local Python installation, so we simply check if we find
192
+ a matching encoding handler.
193
+ """
194
+ cdef tree.xmlCharEncodingHandler* enchandler
195
+ cdef Py_ssize_t l
196
+ cdef const_char* enc
197
+ cdef Py_UNICODE *uchars = [c'<', c't', c'e', c's', c't', c'/', c'>']
198
+ cdef const_xmlChar* buffer = <const_xmlChar*>uchars
199
+ # apparently, libxml2 can't detect UTF-16 on some systems
200
+ if (buffer[0] == c'<' and buffer[1] == c'\0' and
201
+ buffer[2] == c't' and buffer[3] == c'\0'):
202
+ enc = "UTF-16LE"
203
+ elif (buffer[0] == c'\0' and buffer[1] == c'<' and
204
+ buffer[2] == c'\0' and buffer[3] == c't'):
205
+ enc = "UTF-16BE"
206
+ else:
207
+ # let libxml2 give it a try
208
+ enc = _findEncodingName(buffer, sizeof(Py_UNICODE) * 7)
209
+ if enc is NULL:
210
+ # not my fault, it's YOUR broken system :)
211
+ return 0
212
+ enchandler = tree.xmlFindCharEncodingHandler(enc)
213
+ if enchandler is not NULL:
214
+ global _PY_UNICODE_ENCODING
215
+ tree.xmlCharEncCloseFunc(enchandler)
216
+ _PY_UNICODE_ENCODING = enc
217
+ return 0
218
+
219
+ cdef const_char* _findEncodingName(const_xmlChar* buffer, int size):
220
+ "Work around bug in libxml2: find iconv name of encoding on our own."
221
+ cdef tree.xmlCharEncoding enc
222
+ enc = tree.xmlDetectCharEncoding(buffer, size)
223
+ if enc == tree.XML_CHAR_ENCODING_UTF16LE:
224
+ if size >= 4 and (buffer[0] == <const_xmlChar> b'\xFF' and
225
+ buffer[1] == <const_xmlChar> b'\xFE' and
226
+ buffer[2] == 0 and buffer[3] == 0):
227
+ return "UTF-32LE" # according to BOM
228
+ else:
229
+ return "UTF-16LE"
230
+ elif enc == tree.XML_CHAR_ENCODING_UTF16BE:
231
+ return "UTF-16BE"
232
+ elif enc == tree.XML_CHAR_ENCODING_UCS4LE:
233
+ return "UCS-4LE"
234
+ elif enc == tree.XML_CHAR_ENCODING_UCS4BE:
235
+ return "UCS-4BE"
236
+ elif enc == tree.XML_CHAR_ENCODING_NONE:
237
+ return NULL
238
+ else:
239
+ # returns a constant char*, no need to free it
240
+ return tree.xmlGetCharEncodingName(enc)
241
+
242
+ # Python 3.12 removed support for "Py_UNICODE".
243
+ if python.PY_VERSION_HEX < 0x030C0000:
244
+ _setupPythonUnicode()
245
+
246
+
247
+ cdef unicode _find_PyUCS4EncodingName():
248
+ """
249
+ Find a suitable encoding for Py_UCS4 PyUnicode strings in libxml2.
250
+ """
251
+ ustring = "<xml>\U0001F92A</xml>"
252
+ cdef const xmlChar* buffer = <const xmlChar*> python.PyUnicode_DATA(ustring)
253
+ cdef Py_ssize_t py_buffer_len = python.PyUnicode_GET_LENGTH(ustring)
254
+
255
+ encoding_name = ''
256
+ cdef tree.xmlCharEncoding enc = tree.xmlDetectCharEncoding(buffer, py_buffer_len)
257
+ enchandler = tree.xmlGetCharEncodingHandler(enc)
258
+ if enchandler is not NULL:
259
+ try:
260
+ if enchandler.name:
261
+ encoding_name = enchandler.name.decode('UTF-8')
262
+ finally:
263
+ tree.xmlCharEncCloseFunc(enchandler)
264
+ else:
265
+ c_name = tree.xmlGetCharEncodingName(enc)
266
+ if c_name:
267
+ encoding_name = c_name.decode('UTF-8')
268
+
269
+
270
+ if encoding_name and not encoding_name.endswith('LE') and not encoding_name.endswith('BE'):
271
+ encoding_name += 'BE' if python.PY_BIG_ENDIAN else 'LE'
272
+ return encoding_name or None
273
+
274
+ _pyucs4_encoding_name = _find_PyUCS4EncodingName()
275
+
276
+
277
+ ############################################################
278
+ ## support for file-like objects
279
+ ############################################################
280
+
281
+ @cython.final
282
+ @cython.internal
283
+ cdef class _FileReaderContext:
284
+ cdef object _filelike
285
+ cdef object _encoding
286
+ cdef object _url
287
+ cdef object _bytes
288
+ cdef _ExceptionContext _exc_context
289
+ cdef Py_ssize_t _bytes_read
290
+ cdef char* _c_url
291
+ cdef bint _close_file_after_read
292
+
293
+ def __cinit__(self, filelike, exc_context not None, url, encoding=None, bint close_file=False):
294
+ self._exc_context = exc_context
295
+ self._filelike = filelike
296
+ self._close_file_after_read = close_file
297
+ self._encoding = encoding
298
+ if url is None:
299
+ self._c_url = NULL
300
+ else:
301
+ url = _encodeFilename(url)
302
+ self._c_url = _cstr(url)
303
+ self._url = url
304
+ self._bytes = b''
305
+ self._bytes_read = 0
306
+
307
+ cdef _close_file(self):
308
+ if self._filelike is None or not self._close_file_after_read:
309
+ return
310
+ try:
311
+ close = self._filelike.close
312
+ except AttributeError:
313
+ close = None
314
+ finally:
315
+ self._filelike = None
316
+ if close is not None:
317
+ close()
318
+
319
+ cdef xmlparser.xmlParserInputBuffer* _createParserInputBuffer(self) noexcept:
320
+ cdef xmlparser.xmlParserInputBuffer* c_buffer = xmlparser.xmlAllocParserInputBuffer(0)
321
+ if c_buffer:
322
+ c_buffer.readcallback = _readFilelikeParser
323
+ c_buffer.context = <python.PyObject*> self
324
+ return c_buffer
325
+
326
+ cdef xmlparser.xmlParserInput* _createParserInput(
327
+ self, xmlparser.xmlParserCtxt* ctxt) noexcept:
328
+ cdef xmlparser.xmlParserInputBuffer* c_buffer = self._createParserInputBuffer()
329
+ if not c_buffer:
330
+ return NULL
331
+ return xmlparser.xmlNewIOInputStream(ctxt, c_buffer, 0)
332
+
333
+ cdef tree.xmlDtd* _readDtd(self) noexcept:
334
+ cdef xmlparser.xmlParserInputBuffer* c_buffer = self._createParserInputBuffer()
335
+ if not c_buffer:
336
+ return NULL
337
+ with nogil:
338
+ return xmlparser.xmlIOParseDTD(NULL, c_buffer, 0)
339
+
340
+ cdef xmlDoc* _readDoc(self, xmlparser.xmlParserCtxt* ctxt, int options) noexcept:
341
+ cdef xmlDoc* result
342
+ cdef void* c_callback_context = <python.PyObject*> self
343
+ cdef char* c_encoding = _cstr(self._encoding) if self._encoding is not None else NULL
344
+
345
+ orig_options = ctxt.options
346
+ with nogil:
347
+ if ctxt.html:
348
+ result = htmlparser.htmlCtxtReadIO(
349
+ ctxt, _readFilelikeParser, NULL, c_callback_context,
350
+ self._c_url, c_encoding, options)
351
+ if result is not NULL:
352
+ if _fixHtmlDictNames(ctxt.dict, result) < 0:
353
+ tree.xmlFreeDoc(result)
354
+ result = NULL
355
+ else:
356
+ result = xmlparser.xmlCtxtReadIO(
357
+ ctxt, _readFilelikeParser, NULL, c_callback_context,
358
+ self._c_url, c_encoding, options)
359
+ ctxt.options = orig_options # work around libxml2 problem
360
+
361
+ try:
362
+ self._close_file()
363
+ except:
364
+ self._exc_context._store_raised()
365
+ finally:
366
+ return result # swallow any exceptions
367
+
368
+ cdef int copyToBuffer(self, char* c_buffer, int c_requested) noexcept:
369
+ cdef int c_byte_count = 0
370
+ cdef char* c_start
371
+ cdef Py_ssize_t byte_count, remaining
372
+ if self._bytes_read < 0:
373
+ return 0
374
+ try:
375
+ byte_count = python.PyBytes_GET_SIZE(self._bytes)
376
+ remaining = byte_count - self._bytes_read
377
+ while c_requested > remaining:
378
+ c_start = _cstr(self._bytes) + self._bytes_read
379
+ cstring_h.memcpy(c_buffer, c_start, remaining)
380
+ c_byte_count += remaining
381
+ c_buffer += remaining
382
+ c_requested -= remaining
383
+
384
+ self._bytes = self._filelike.read(c_requested)
385
+ if not isinstance(self._bytes, bytes):
386
+ if isinstance(self._bytes, unicode):
387
+ if self._encoding is None:
388
+ self._bytes = (<unicode>self._bytes).encode('utf8')
389
+ else:
390
+ self._bytes = python.PyUnicode_AsEncodedString(
391
+ self._bytes, _cstr(self._encoding), NULL)
392
+ else:
393
+ self._close_file()
394
+ raise TypeError, \
395
+ "reading from file-like objects must return byte strings or unicode strings"
396
+
397
+ remaining = python.PyBytes_GET_SIZE(self._bytes)
398
+ if remaining == 0:
399
+ self._bytes_read = -1
400
+ self._close_file()
401
+ return c_byte_count
402
+ self._bytes_read = 0
403
+
404
+ if c_requested > 0:
405
+ c_start = _cstr(self._bytes) + self._bytes_read
406
+ cstring_h.memcpy(c_buffer, c_start, c_requested)
407
+ c_byte_count += c_requested
408
+ self._bytes_read += c_requested
409
+ except:
410
+ c_byte_count = -1
411
+ self._exc_context._store_raised()
412
+ try:
413
+ self._close_file()
414
+ except:
415
+ self._exc_context._store_raised()
416
+ finally:
417
+ return c_byte_count # swallow any exceptions
418
+
419
+ cdef int _readFilelikeParser(void* ctxt, char* c_buffer, int c_size) noexcept with gil:
420
+ return (<_FileReaderContext>ctxt).copyToBuffer(c_buffer, c_size)
421
+
422
+ cdef int _readFileParser(void* ctxt, char* c_buffer, int c_size) noexcept nogil:
423
+ return stdio.fread(c_buffer, 1, c_size, <stdio.FILE*>ctxt)
424
+
425
+ ############################################################
426
+ ## support for custom document loaders
427
+ ############################################################
428
+
429
+ cdef xmlparser.xmlParserInput* _local_resolver(const_char* c_url, const_char* c_pubid,
430
+ xmlparser.xmlParserCtxt* c_context) noexcept with gil:
431
+ cdef _ResolverContext context
432
+ cdef xmlparser.xmlParserInput* c_input
433
+ cdef _InputDocument doc_ref
434
+ cdef _FileReaderContext file_context
435
+ # if there is no _ParserContext associated with the xmlParserCtxt
436
+ # passed, check to see if the thread state object has an implied
437
+ # context.
438
+ if c_context._private is not NULL:
439
+ context = <_ResolverContext>c_context._private
440
+ else:
441
+ context = __GLOBAL_PARSER_CONTEXT.findImpliedContext()
442
+
443
+ if context is None:
444
+ if __DEFAULT_ENTITY_LOADER is NULL:
445
+ return NULL
446
+ with nogil:
447
+ # free the GIL as we might do serious I/O here (e.g. HTTP)
448
+ c_input = __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
449
+ return c_input
450
+
451
+ try:
452
+ if c_url is NULL:
453
+ url = None
454
+ else:
455
+ # parsing a related document (DTD etc.) => UTF-8 encoded URL?
456
+ url = _decodeFilename(<const_xmlChar*>c_url)
457
+ if c_pubid is NULL:
458
+ pubid = None
459
+ else:
460
+ pubid = funicode(<const_xmlChar*>c_pubid) # always UTF-8
461
+
462
+ doc_ref = context._resolvers.resolve(url, pubid, context)
463
+ except:
464
+ context._store_raised()
465
+ return NULL
466
+
467
+ if doc_ref is not None:
468
+ if doc_ref._type == PARSER_DATA_STRING:
469
+ data = doc_ref._data_bytes
470
+ filename = doc_ref._filename
471
+ if not filename:
472
+ filename = None
473
+ elif not isinstance(filename, bytes):
474
+ # most likely a text URL
475
+ filename = filename.encode('utf8')
476
+ if not isinstance(filename, bytes):
477
+ filename = None
478
+
479
+ c_input = xmlparser.xmlNewInputStream(c_context)
480
+ if c_input is not NULL:
481
+ if filename is not None:
482
+ c_input.filename = <char *>tree.xmlStrdup(_xcstr(filename))
483
+ c_input.base = _xcstr(data)
484
+ c_input.length = python.PyBytes_GET_SIZE(data)
485
+ c_input.cur = c_input.base
486
+ c_input.end = c_input.base + c_input.length
487
+ elif doc_ref._type == PARSER_DATA_FILENAME:
488
+ data = None
489
+ c_filename = _cstr(doc_ref._filename)
490
+ with nogil:
491
+ # free the GIL as we might do serious I/O here
492
+ c_input = xmlparser.xmlNewInputFromFile(
493
+ c_context, c_filename)
494
+ elif doc_ref._type == PARSER_DATA_FILE:
495
+ file_context = _FileReaderContext(doc_ref._file, context, url,
496
+ None, doc_ref._close_file)
497
+ c_input = file_context._createParserInput(c_context)
498
+ data = file_context
499
+ else:
500
+ data = None
501
+ c_input = NULL
502
+
503
+ if data is not None:
504
+ context._storage.add(data)
505
+ if c_input is not NULL:
506
+ return c_input
507
+
508
+ if __DEFAULT_ENTITY_LOADER is NULL:
509
+ return NULL
510
+
511
+ with nogil:
512
+ # free the GIL as we might do serious I/O here (e.g. HTTP)
513
+ c_input = __DEFAULT_ENTITY_LOADER(c_url, c_pubid, c_context)
514
+ return c_input
515
+
516
+ cdef xmlparser.xmlExternalEntityLoader __DEFAULT_ENTITY_LOADER
517
+ __DEFAULT_ENTITY_LOADER = xmlparser.xmlGetExternalEntityLoader()
518
+
519
+
520
+ cdef xmlparser.xmlExternalEntityLoader _register_document_loader() noexcept nogil:
521
+ cdef xmlparser.xmlExternalEntityLoader old = xmlparser.xmlGetExternalEntityLoader()
522
+ xmlparser.xmlSetExternalEntityLoader(<xmlparser.xmlExternalEntityLoader>_local_resolver)
523
+ return old
524
+
525
+ cdef void _reset_document_loader(xmlparser.xmlExternalEntityLoader old) noexcept nogil:
526
+ xmlparser.xmlSetExternalEntityLoader(old)
527
+
528
+
529
+ ############################################################
530
+ ## Parsers
531
+ ############################################################
532
+
533
+ @cython.no_gc_clear # May have to call "self._validator.disconnect()" on dealloc.
534
+ @cython.internal
535
+ cdef class _ParserContext(_ResolverContext):
536
+ cdef _ErrorLog _error_log
537
+ cdef _ParserSchemaValidationContext _validator
538
+ cdef xmlparser.xmlParserCtxt* _c_ctxt
539
+ cdef xmlparser.xmlExternalEntityLoader _orig_loader
540
+ cdef python.PyThread_type_lock _lock
541
+ cdef _Document _doc
542
+ cdef bint _collect_ids
543
+
544
+ def __cinit__(self):
545
+ self._c_ctxt = NULL
546
+ self._collect_ids = True
547
+ if not config.ENABLE_THREADING:
548
+ self._lock = NULL
549
+ else:
550
+ self._lock = python.PyThread_allocate_lock()
551
+ self._error_log = _ErrorLog()
552
+
553
+ def __dealloc__(self):
554
+ if config.ENABLE_THREADING and self._lock is not NULL:
555
+ python.PyThread_free_lock(self._lock)
556
+ self._lock = NULL
557
+ if self._c_ctxt is not NULL:
558
+ if <void*>self._validator is not NULL and self._validator is not None:
559
+ # If the parser was not closed correctly (e.g. interrupted iterparse()),
560
+ # and the schema validator wasn't freed and cleaned up yet, the libxml2 SAX
561
+ # validator plug might still be in place, which will make xmlFreeParserCtxt()
562
+ # crash when trying to xmlFree() a static SAX handler.
563
+ # Thus, make sure we disconnect the handler interceptor here at the latest.
564
+ self._validator.disconnect()
565
+ xmlparser.xmlFreeParserCtxt(self._c_ctxt)
566
+
567
+ cdef _ParserContext _copy(self):
568
+ cdef _ParserContext context
569
+ context = self.__class__()
570
+ context._collect_ids = self._collect_ids
571
+ context._validator = self._validator.copy()
572
+ _initParserContext(context, self._resolvers._copy(), NULL)
573
+ return context
574
+
575
+ cdef void _initParserContext(self, xmlparser.xmlParserCtxt* c_ctxt) noexcept:
576
+ self._c_ctxt = c_ctxt
577
+ c_ctxt._private = <void*>self
578
+
579
+ cdef void _resetParserContext(self) noexcept:
580
+ if self._c_ctxt is not NULL:
581
+ if self._c_ctxt.html:
582
+ htmlparser.htmlCtxtReset(self._c_ctxt)
583
+ self._c_ctxt.disableSAX = 0 # work around bug in libxml2
584
+ else:
585
+ xmlparser.xmlClearParserCtxt(self._c_ctxt)
586
+ # work around bug in libxml2 [2.9.10 .. 2.9.14]:
587
+ # https://gitlab.gnome.org/GNOME/libxml2/-/issues/378
588
+ self._c_ctxt.nsNr = 0
589
+
590
+ cdef int prepare(self, bint set_document_loader=True) except -1:
591
+ cdef int result
592
+ if config.ENABLE_THREADING and self._lock is not NULL:
593
+ with nogil:
594
+ result = python.PyThread_acquire_lock(
595
+ self._lock, python.WAIT_LOCK)
596
+ if result == 0:
597
+ raise ParserError, "parser locking failed"
598
+ self._error_log.clear()
599
+ self._doc = None
600
+ # Need a cast here because older libxml2 releases do not use 'const' in the functype.
601
+ self._c_ctxt.sax.serror = <xmlerror.xmlStructuredErrorFunc> _receiveParserError
602
+ self._orig_loader = _register_document_loader() if set_document_loader else NULL
603
+ if self._validator is not None:
604
+ self._validator.connect(self._c_ctxt, self._error_log)
605
+ return 0
606
+
607
+ cdef int cleanup(self) except -1:
608
+ if self._orig_loader is not NULL:
609
+ _reset_document_loader(self._orig_loader)
610
+ try:
611
+ if self._validator is not None:
612
+ self._validator.disconnect()
613
+ self._resetParserContext()
614
+ self.clear()
615
+ self._doc = None
616
+ self._c_ctxt.sax.serror = NULL
617
+ finally:
618
+ if config.ENABLE_THREADING and self._lock is not NULL:
619
+ python.PyThread_release_lock(self._lock)
620
+ return 0
621
+
622
+ cdef object _handleParseResult(self, _BaseParser parser,
623
+ xmlDoc* result, filename):
624
+ c_doc = self._handleParseResultDoc(parser, result, filename)
625
+ if self._doc is not None and self._doc._c_doc is c_doc:
626
+ return self._doc
627
+ else:
628
+ return _documentFactory(c_doc, parser)
629
+
630
+ cdef xmlDoc* _handleParseResultDoc(self, _BaseParser parser,
631
+ xmlDoc* result, filename) except NULL:
632
+ recover = parser._parse_options & xmlparser.XML_PARSE_RECOVER
633
+ return _handleParseResult(self, self._c_ctxt, result,
634
+ filename, recover,
635
+ free_doc=self._doc is None)
636
+
637
+ cdef _initParserContext(_ParserContext context,
638
+ _ResolverRegistry resolvers,
639
+ xmlparser.xmlParserCtxt* c_ctxt):
640
+ _initResolverContext(context, resolvers)
641
+ if c_ctxt is not NULL:
642
+ context._initParserContext(c_ctxt)
643
+
644
+ cdef void _forwardParserError(xmlparser.xmlParserCtxt* _parser_context, const xmlerror.xmlError* error) noexcept with gil:
645
+ (<_ParserContext>_parser_context._private)._error_log._receive(error)
646
+
647
+ cdef void _receiveParserError(void* c_context, const xmlerror.xmlError* error) noexcept nogil:
648
+ if __DEBUG:
649
+ if c_context is NULL or (<xmlparser.xmlParserCtxt*>c_context)._private is NULL:
650
+ _forwardError(NULL, error)
651
+ else:
652
+ _forwardParserError(<xmlparser.xmlParserCtxt*>c_context, error)
653
+
654
+ cdef int _raiseParseError(xmlparser.xmlParserCtxt* ctxt, filename,
655
+ _ErrorLog error_log) except -1:
656
+ if filename is not None and \
657
+ ctxt.lastError.domain == xmlerror.XML_FROM_IO:
658
+ if isinstance(filename, bytes):
659
+ filename = _decodeFilenameWithLength(
660
+ <bytes>filename, len(<bytes>filename))
661
+ if ctxt.lastError.message is not NULL:
662
+ try:
663
+ message = ctxt.lastError.message.decode('utf-8')
664
+ except UnicodeDecodeError:
665
+ # the filename may be in there => play it safe
666
+ message = ctxt.lastError.message.decode('iso8859-1')
667
+ message = f"Error reading file '{filename}': {message.strip()}"
668
+ else:
669
+ message = f"Error reading '{filename}'"
670
+ raise IOError, message
671
+ elif error_log:
672
+ raise error_log._buildParseException(
673
+ XMLSyntaxError, "Document is not well formed")
674
+ elif ctxt.lastError.message is not NULL:
675
+ message = ctxt.lastError.message.strip()
676
+ code = ctxt.lastError.code
677
+ line = ctxt.lastError.line
678
+ column = ctxt.lastError.int2
679
+ if ctxt.lastError.line > 0:
680
+ message = f"line {line}: {message}"
681
+ raise XMLSyntaxError(message, code, line, column, filename)
682
+ else:
683
+ raise XMLSyntaxError(None, xmlerror.XML_ERR_INTERNAL_ERROR, 0, 0,
684
+ filename)
685
+
686
+ cdef xmlDoc* _handleParseResult(_ParserContext context,
687
+ xmlparser.xmlParserCtxt* c_ctxt,
688
+ xmlDoc* result, filename,
689
+ bint recover, bint free_doc) except NULL:
690
+ cdef bint well_formed
691
+ if result is not NULL:
692
+ __GLOBAL_PARSER_CONTEXT.initDocDict(result)
693
+
694
+ if c_ctxt.myDoc is not NULL:
695
+ if c_ctxt.myDoc is not result:
696
+ __GLOBAL_PARSER_CONTEXT.initDocDict(c_ctxt.myDoc)
697
+ tree.xmlFreeDoc(c_ctxt.myDoc)
698
+ c_ctxt.myDoc = NULL
699
+
700
+ if result is not NULL:
701
+ if (context._validator is not None and
702
+ not context._validator.isvalid()):
703
+ well_formed = 0 # actually not 'valid', but anyway ...
704
+ elif (not c_ctxt.wellFormed and not c_ctxt.html and
705
+ c_ctxt.charset == tree.XML_CHAR_ENCODING_8859_1 and
706
+ [1 for error in context._error_log
707
+ if error.type == ErrorTypes.ERR_INVALID_CHAR]):
708
+ # An encoding error occurred and libxml2 switched from UTF-8
709
+ # input to (undecoded) Latin-1, at some arbitrary point in the
710
+ # document. Better raise an error than allowing for a broken
711
+ # tree with mixed encodings. This is fixed in libxml2 2.12.
712
+ well_formed = 0
713
+ elif recover or (c_ctxt.wellFormed and
714
+ c_ctxt.lastError.level < xmlerror.XML_ERR_ERROR):
715
+ well_formed = 1
716
+ elif not c_ctxt.replaceEntities and not c_ctxt.validate \
717
+ and context is not None:
718
+ # in this mode, we ignore errors about undefined entities
719
+ for error in context._error_log.filter_from_errors():
720
+ if error.type != ErrorTypes.WAR_UNDECLARED_ENTITY and \
721
+ error.type != ErrorTypes.ERR_UNDECLARED_ENTITY:
722
+ well_formed = 0
723
+ break
724
+ else:
725
+ well_formed = 1
726
+ else:
727
+ well_formed = 0
728
+
729
+ if not well_formed:
730
+ if free_doc:
731
+ tree.xmlFreeDoc(result)
732
+ result = NULL
733
+
734
+ if context is not None and context._has_raised():
735
+ if result is not NULL:
736
+ if free_doc:
737
+ tree.xmlFreeDoc(result)
738
+ result = NULL
739
+ context._raise_if_stored()
740
+
741
+ if result is NULL:
742
+ if context is not None:
743
+ _raiseParseError(c_ctxt, filename, context._error_log)
744
+ else:
745
+ _raiseParseError(c_ctxt, filename, None)
746
+ else:
747
+ if result.URL is NULL and filename is not None:
748
+ result.URL = tree.xmlStrdup(_xcstr(filename))
749
+ if result.encoding is NULL:
750
+ result.encoding = tree.xmlStrdup(<unsigned char*>"UTF-8")
751
+
752
+ if context._validator is not None and \
753
+ context._validator._add_default_attributes:
754
+ # we currently need to do this here as libxml2 does not
755
+ # support inserting default attributes during parse-time
756
+ # validation
757
+ context._validator.inject_default_attributes(result)
758
+
759
+ return result
760
+
761
+ cdef int _fixHtmlDictNames(tree.xmlDict* c_dict, xmlDoc* c_doc) noexcept nogil:
762
+ cdef xmlNode* c_node
763
+ if c_doc is NULL:
764
+ return 0
765
+ c_node = c_doc.children
766
+ tree.BEGIN_FOR_EACH_ELEMENT_FROM(<xmlNode*>c_doc, c_node, 1)
767
+ if c_node.type == tree.XML_ELEMENT_NODE:
768
+ if _fixHtmlDictNodeNames(c_dict, c_node) < 0:
769
+ return -1
770
+ tree.END_FOR_EACH_ELEMENT_FROM(c_node)
771
+ return 0
772
+
773
+ cdef int _fixHtmlDictSubtreeNames(tree.xmlDict* c_dict, xmlDoc* c_doc,
774
+ xmlNode* c_start_node) noexcept nogil:
775
+ """
776
+ Move names to the dict, iterating in document order, starting at
777
+ c_start_node. This is used in incremental parsing after each chunk.
778
+ """
779
+ cdef xmlNode* c_node
780
+ if not c_doc:
781
+ return 0
782
+ if not c_start_node:
783
+ return _fixHtmlDictNames(c_dict, c_doc)
784
+ c_node = c_start_node
785
+ tree.BEGIN_FOR_EACH_ELEMENT_FROM(<xmlNode*>c_doc, c_node, 1)
786
+ if c_node.type == tree.XML_ELEMENT_NODE:
787
+ if _fixHtmlDictNodeNames(c_dict, c_node) < 0:
788
+ return -1
789
+ tree.END_FOR_EACH_ELEMENT_FROM(c_node)
790
+ return 0
791
+
792
+ cdef inline int _fixHtmlDictNodeNames(tree.xmlDict* c_dict,
793
+ xmlNode* c_node) noexcept nogil:
794
+ cdef xmlNode* c_attr
795
+ c_name = tree.xmlDictLookup(c_dict, c_node.name, -1)
796
+ if c_name is NULL:
797
+ return -1
798
+ if c_name is not c_node.name:
799
+ tree.xmlFree(<char*>c_node.name)
800
+ c_node.name = c_name
801
+ c_attr = <xmlNode*>c_node.properties
802
+ while c_attr is not NULL:
803
+ c_name = tree.xmlDictLookup(c_dict, c_attr.name, -1)
804
+ if c_name is NULL:
805
+ return -1
806
+ if c_name is not c_attr.name:
807
+ tree.xmlFree(<char*>c_attr.name)
808
+ c_attr.name = c_name
809
+ c_attr = c_attr.next
810
+ return 0
811
+
812
+
813
+ @cython.internal
814
+ cdef class _BaseParser:
815
+ cdef ElementClassLookup _class_lookup
816
+ cdef _ResolverRegistry _resolvers
817
+ cdef _ParserContext _parser_context
818
+ cdef _ParserContext _push_parser_context
819
+ cdef int _parse_options
820
+ cdef bint _for_html
821
+ cdef bint _remove_comments
822
+ cdef bint _remove_pis
823
+ cdef bint _strip_cdata
824
+ cdef bint _collect_ids
825
+ cdef bint _resolve_external_entities
826
+ cdef XMLSchema _schema
827
+ cdef bytes _filename
828
+ cdef readonly object target
829
+ cdef object _default_encoding
830
+ cdef tuple _events_to_collect # (event_types, tag)
831
+
832
+ def __init__(self, int parse_options, bint for_html, XMLSchema schema,
833
+ remove_comments, remove_pis, strip_cdata, collect_ids,
834
+ target, encoding, bint resolve_external_entities=True):
835
+ cdef tree.xmlCharEncodingHandler* enchandler
836
+ cdef int c_encoding
837
+ if not isinstance(self, (XMLParser, HTMLParser)):
838
+ raise TypeError, "This class cannot be instantiated"
839
+
840
+ self._parse_options = parse_options
841
+ self.target = target
842
+ self._for_html = for_html
843
+ self._remove_comments = remove_comments
844
+ self._remove_pis = remove_pis
845
+ self._strip_cdata = strip_cdata
846
+ self._collect_ids = collect_ids
847
+ self._resolve_external_entities = resolve_external_entities
848
+ self._schema = schema
849
+
850
+ self._resolvers = _ResolverRegistry()
851
+
852
+ if encoding is None:
853
+ self._default_encoding = None
854
+ else:
855
+ encoding = _utf8(encoding)
856
+ enchandler = tree.xmlFindCharEncodingHandler(_cstr(encoding))
857
+ if enchandler is NULL:
858
+ raise LookupError, f"unknown encoding: '{encoding}'"
859
+ tree.xmlCharEncCloseFunc(enchandler)
860
+ self._default_encoding = encoding
861
+
862
+ cdef _setBaseURL(self, base_url):
863
+ self._filename = _encodeFilename(base_url)
864
+
865
+ cdef _collectEvents(self, event_types, tag):
866
+ if event_types is None:
867
+ event_types = ()
868
+ else:
869
+ event_types = tuple(set(event_types))
870
+ _buildParseEventFilter(event_types) # purely for validation
871
+ self._events_to_collect = (event_types, tag)
872
+
873
+ cdef _ParserContext _getParserContext(self):
874
+ cdef xmlparser.xmlParserCtxt* pctxt
875
+ if self._parser_context is None:
876
+ self._parser_context = self._createContext(self.target, None)
877
+ self._parser_context._collect_ids = self._collect_ids
878
+ if self._schema is not None:
879
+ self._parser_context._validator = \
880
+ self._schema._newSaxValidator(
881
+ self._parse_options & xmlparser.XML_PARSE_DTDATTR)
882
+ pctxt = self._newParserCtxt()
883
+ _initParserContext(self._parser_context, self._resolvers, pctxt)
884
+ self._configureSaxContext(pctxt)
885
+ return self._parser_context
886
+
887
+ cdef _ParserContext _getPushParserContext(self):
888
+ cdef xmlparser.xmlParserCtxt* pctxt
889
+ if self._push_parser_context is None:
890
+ self._push_parser_context = self._createContext(
891
+ self.target, self._events_to_collect)
892
+ self._push_parser_context._collect_ids = self._collect_ids
893
+ if self._schema is not None:
894
+ self._push_parser_context._validator = \
895
+ self._schema._newSaxValidator(
896
+ self._parse_options & xmlparser.XML_PARSE_DTDATTR)
897
+ pctxt = self._newPushParserCtxt()
898
+ _initParserContext(
899
+ self._push_parser_context, self._resolvers, pctxt)
900
+ self._configureSaxContext(pctxt)
901
+ return self._push_parser_context
902
+
903
+ cdef _ParserContext _createContext(self, target, events_to_collect):
904
+ cdef _SaxParserContext sax_context
905
+ if target is not None:
906
+ sax_context = _TargetParserContext(self)
907
+ (<_TargetParserContext>sax_context)._setTarget(target)
908
+ elif events_to_collect:
909
+ sax_context = _SaxParserContext(self)
910
+ else:
911
+ # nothing special to configure
912
+ return _ParserContext()
913
+ if events_to_collect:
914
+ events, tag = events_to_collect
915
+ sax_context._setEventFilter(events, tag)
916
+ return sax_context
917
+
918
+ @cython.final
919
+ cdef int _configureSaxContext(self, xmlparser.xmlParserCtxt* pctxt) except -1:
920
+ if self._remove_comments:
921
+ pctxt.sax.comment = NULL
922
+ if self._remove_pis:
923
+ pctxt.sax.processingInstruction = NULL
924
+ if self._strip_cdata:
925
+ # hard switch-off for CDATA nodes => makes them plain text
926
+ pctxt.sax.cdataBlock = NULL
927
+ if not self._resolve_external_entities:
928
+ pctxt.sax.getEntity = _getInternalEntityOnly
929
+
930
+ cdef int _registerHtmlErrorHandler(self, xmlparser.xmlParserCtxt* c_ctxt) except -1:
931
+ cdef xmlparser.xmlSAXHandler* sax = c_ctxt.sax
932
+ if sax is not NULL and sax.initialized and sax.initialized != xmlparser.XML_SAX2_MAGIC:
933
+ # need to extend SAX1 context to SAX2 to get proper error reports
934
+ if <xmlparser.xmlSAXHandlerV1*>sax is &htmlparser.htmlDefaultSAXHandler:
935
+ sax = <xmlparser.xmlSAXHandler*> tree.xmlMalloc(sizeof(xmlparser.xmlSAXHandler))
936
+ if sax is NULL:
937
+ raise MemoryError()
938
+ cstring_h.memcpy(sax, &htmlparser.htmlDefaultSAXHandler,
939
+ sizeof(htmlparser.htmlDefaultSAXHandler))
940
+ c_ctxt.sax = sax
941
+ sax.initialized = xmlparser.XML_SAX2_MAGIC
942
+ # Need a cast here because older libxml2 releases do not use 'const' in the functype.
943
+ sax.serror = <xmlerror.xmlStructuredErrorFunc> _receiveParserError
944
+ sax.startElementNs = NULL
945
+ sax.endElementNs = NULL
946
+ sax._private = NULL
947
+ return 0
948
+
949
+ cdef xmlparser.xmlParserCtxt* _newParserCtxt(self) except NULL:
950
+ cdef xmlparser.xmlParserCtxt* c_ctxt
951
+ if self._for_html:
952
+ c_ctxt = htmlparser.htmlCreateMemoryParserCtxt('dummy', 5)
953
+ if c_ctxt is not NULL:
954
+ self._registerHtmlErrorHandler(c_ctxt)
955
+ else:
956
+ c_ctxt = xmlparser.xmlNewParserCtxt()
957
+ if c_ctxt is NULL:
958
+ raise MemoryError
959
+ c_ctxt.sax.startDocument = _initSaxDocument
960
+ return c_ctxt
961
+
962
+ cdef xmlparser.xmlParserCtxt* _newPushParserCtxt(self) except NULL:
963
+ cdef xmlparser.xmlParserCtxt* c_ctxt
964
+ cdef char* c_filename = _cstr(self._filename) if self._filename is not None else NULL
965
+ if self._for_html:
966
+ c_ctxt = htmlparser.htmlCreatePushParserCtxt(
967
+ NULL, NULL, NULL, 0, c_filename, tree.XML_CHAR_ENCODING_NONE)
968
+ if c_ctxt is not NULL:
969
+ self._registerHtmlErrorHandler(c_ctxt)
970
+ htmlparser.htmlCtxtUseOptions(c_ctxt, self._parse_options)
971
+ else:
972
+ c_ctxt = xmlparser.xmlCreatePushParserCtxt(
973
+ NULL, NULL, NULL, 0, c_filename)
974
+ if c_ctxt is not NULL:
975
+ xmlparser.xmlCtxtUseOptions(c_ctxt, self._parse_options)
976
+ if c_ctxt is NULL:
977
+ raise MemoryError()
978
+ c_ctxt.sax.startDocument = _initSaxDocument
979
+ return c_ctxt
980
+
981
+ @property
982
+ def error_log(self):
983
+ """The error log of the last parser run.
984
+ """
985
+ cdef _ParserContext context
986
+ context = self._getParserContext()
987
+ return context._error_log.copy()
988
+
989
+ @property
990
+ def resolvers(self):
991
+ """The custom resolver registry of this parser."""
992
+ return self._resolvers
993
+
994
+ @property
995
+ def version(self):
996
+ """The version of the underlying XML parser."""
997
+ return "libxml2 %d.%d.%d" % LIBXML_VERSION
998
+
999
+ def set_element_class_lookup(self, ElementClassLookup lookup = None):
1000
+ """set_element_class_lookup(self, lookup = None)
1001
+
1002
+ Set a lookup scheme for element classes generated from this parser.
1003
+
1004
+ Reset it by passing None or nothing.
1005
+ """
1006
+ self._class_lookup = lookup
1007
+
1008
+ cdef _BaseParser _copy(self):
1009
+ "Create a new parser with the same configuration."
1010
+ cdef _BaseParser parser
1011
+ parser = self.__class__()
1012
+ parser._parse_options = self._parse_options
1013
+ parser._for_html = self._for_html
1014
+ parser._remove_comments = self._remove_comments
1015
+ parser._remove_pis = self._remove_pis
1016
+ parser._strip_cdata = self._strip_cdata
1017
+ parser._filename = self._filename
1018
+ parser._resolvers = self._resolvers
1019
+ parser.target = self.target
1020
+ parser._class_lookup = self._class_lookup
1021
+ parser._default_encoding = self._default_encoding
1022
+ parser._schema = self._schema
1023
+ parser._events_to_collect = self._events_to_collect
1024
+ return parser
1025
+
1026
+ def copy(self):
1027
+ """copy(self)
1028
+
1029
+ Create a new parser with the same configuration.
1030
+ """
1031
+ return self._copy()
1032
+
1033
+ def makeelement(self, _tag, attrib=None, nsmap=None, **_extra):
1034
+ """makeelement(self, _tag, attrib=None, nsmap=None, **_extra)
1035
+
1036
+ Creates a new element associated with this parser.
1037
+ """
1038
+ return _makeElement(_tag, NULL, None, self, None, None,
1039
+ attrib, nsmap, _extra)
1040
+
1041
+ # internal parser methods
1042
+
1043
+ cdef xmlDoc* _parseUnicodeDoc(self, utext, char* c_filename) except NULL:
1044
+ """Parse unicode document, share dictionary if possible.
1045
+ """
1046
+ cdef _ParserContext context
1047
+ cdef xmlDoc* result
1048
+ cdef xmlparser.xmlParserCtxt* pctxt
1049
+ cdef Py_ssize_t py_buffer_len
1050
+ cdef int buffer_len, c_kind
1051
+ cdef const_char* c_text
1052
+ cdef const_char* c_encoding = _PY_UNICODE_ENCODING
1053
+ if python.PyUnicode_IS_READY(utext):
1054
+ # PEP-393 string
1055
+ c_text = <const_char*>python.PyUnicode_DATA(utext)
1056
+ py_buffer_len = python.PyUnicode_GET_LENGTH(utext)
1057
+ c_kind = python.PyUnicode_KIND(utext)
1058
+ if c_kind == 1:
1059
+ if python.PyUnicode_MAX_CHAR_VALUE(utext) <= 127:
1060
+ c_encoding = 'UTF-8'
1061
+ else:
1062
+ c_encoding = 'ISO-8859-1'
1063
+ elif c_kind == 2:
1064
+ py_buffer_len *= 2
1065
+ if python.PY_BIG_ENDIAN:
1066
+ c_encoding = 'UTF-16BE' # actually UCS-2
1067
+ else:
1068
+ c_encoding = 'UTF-16LE' # actually UCS-2
1069
+ elif c_kind == 4:
1070
+ py_buffer_len *= 4
1071
+ if python.PY_BIG_ENDIAN:
1072
+ c_encoding = 'UTF-32BE' # actually UCS-4
1073
+ else:
1074
+ c_encoding = 'UTF-32LE' # actually UCS-4
1075
+ else:
1076
+ assert False, f"Illegal Unicode kind {c_kind}"
1077
+ else:
1078
+ # old Py_UNICODE string
1079
+ py_buffer_len = python.PyUnicode_GET_DATA_SIZE(utext)
1080
+ c_text = python.PyUnicode_AS_DATA(utext)
1081
+ assert 0 <= py_buffer_len <= limits.INT_MAX
1082
+ buffer_len = py_buffer_len
1083
+
1084
+ context = self._getParserContext()
1085
+ context.prepare()
1086
+ try:
1087
+ pctxt = context._c_ctxt
1088
+ __GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
1089
+ orig_options = pctxt.options
1090
+ with nogil:
1091
+ if self._for_html:
1092
+ result = htmlparser.htmlCtxtReadMemory(
1093
+ pctxt, c_text, buffer_len, c_filename, c_encoding,
1094
+ self._parse_options)
1095
+ if result is not NULL:
1096
+ if _fixHtmlDictNames(pctxt.dict, result) < 0:
1097
+ tree.xmlFreeDoc(result)
1098
+ result = NULL
1099
+ else:
1100
+ result = xmlparser.xmlCtxtReadMemory(
1101
+ pctxt, c_text, buffer_len, c_filename, c_encoding,
1102
+ self._parse_options)
1103
+ pctxt.options = orig_options # work around libxml2 problem
1104
+
1105
+ return context._handleParseResultDoc(self, result, None)
1106
+ finally:
1107
+ context.cleanup()
1108
+
1109
+ cdef xmlDoc* _parseDoc(self, char* c_text, int c_len,
1110
+ char* c_filename) except NULL:
1111
+ """Parse document, share dictionary if possible.
1112
+ """
1113
+ cdef _ParserContext context
1114
+ cdef xmlDoc* result
1115
+ cdef xmlparser.xmlParserCtxt* pctxt
1116
+ cdef char* c_encoding
1117
+ cdef tree.xmlCharEncoding enc
1118
+ context = self._getParserContext()
1119
+ context.prepare()
1120
+ try:
1121
+ pctxt = context._c_ctxt
1122
+ __GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
1123
+
1124
+ if self._default_encoding is None:
1125
+ c_encoding = NULL
1126
+ # libxml2 (at least 2.9.3) does not recognise UTF-32 BOMs
1127
+ # NOTE: limit to problematic cases because it changes character offsets
1128
+ if c_len >= 4 and (c_text[0] == b'\xFF' and c_text[1] == b'\xFE' and
1129
+ c_text[2] == 0 and c_text[3] == 0):
1130
+ c_encoding = "UTF-32LE"
1131
+ c_text += 4
1132
+ c_len -= 4
1133
+ elif c_len >= 4 and (c_text[0] == 0 and c_text[1] == 0 and
1134
+ c_text[2] == b'\xFE' and c_text[3] == b'\xFF'):
1135
+ c_encoding = "UTF-32BE"
1136
+ c_text += 4
1137
+ c_len -= 4
1138
+ else:
1139
+ # no BOM => try to determine encoding
1140
+ enc = tree.xmlDetectCharEncoding(<const_xmlChar*>c_text, c_len)
1141
+ if enc == tree.XML_CHAR_ENCODING_UCS4LE:
1142
+ c_encoding = 'UTF-32LE'
1143
+ elif enc == tree.XML_CHAR_ENCODING_UCS4BE:
1144
+ c_encoding = 'UTF-32BE'
1145
+ else:
1146
+ c_encoding = _cstr(self._default_encoding)
1147
+
1148
+ orig_options = pctxt.options
1149
+ with nogil:
1150
+ if self._for_html:
1151
+ result = htmlparser.htmlCtxtReadMemory(
1152
+ pctxt, c_text, c_len, c_filename,
1153
+ c_encoding, self._parse_options)
1154
+ if result is not NULL:
1155
+ if _fixHtmlDictNames(pctxt.dict, result) < 0:
1156
+ tree.xmlFreeDoc(result)
1157
+ result = NULL
1158
+ else:
1159
+ result = xmlparser.xmlCtxtReadMemory(
1160
+ pctxt, c_text, c_len, c_filename,
1161
+ c_encoding, self._parse_options)
1162
+ pctxt.options = orig_options # work around libxml2 problem
1163
+
1164
+ return context._handleParseResultDoc(self, result, None)
1165
+ finally:
1166
+ context.cleanup()
1167
+
1168
+ cdef xmlDoc* _parseDocFromFile(self, char* c_filename) except NULL:
1169
+ cdef _ParserContext context
1170
+ cdef xmlDoc* result
1171
+ cdef xmlparser.xmlParserCtxt* pctxt
1172
+ cdef char* c_encoding
1173
+ result = NULL
1174
+
1175
+ context = self._getParserContext()
1176
+ context.prepare()
1177
+ try:
1178
+ pctxt = context._c_ctxt
1179
+ __GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
1180
+
1181
+ if self._default_encoding is None:
1182
+ c_encoding = NULL
1183
+ else:
1184
+ c_encoding = _cstr(self._default_encoding)
1185
+
1186
+ orig_options = pctxt.options
1187
+ with nogil:
1188
+ if self._for_html:
1189
+ result = htmlparser.htmlCtxtReadFile(
1190
+ pctxt, c_filename, c_encoding, self._parse_options)
1191
+ if result is not NULL:
1192
+ if _fixHtmlDictNames(pctxt.dict, result) < 0:
1193
+ tree.xmlFreeDoc(result)
1194
+ result = NULL
1195
+ else:
1196
+ result = xmlparser.xmlCtxtReadFile(
1197
+ pctxt, c_filename, c_encoding, self._parse_options)
1198
+ pctxt.options = orig_options # work around libxml2 problem
1199
+
1200
+ return context._handleParseResultDoc(self, result, c_filename)
1201
+ finally:
1202
+ context.cleanup()
1203
+
1204
+ cdef xmlDoc* _parseDocFromFilelike(self, filelike, filename,
1205
+ encoding) except NULL:
1206
+ cdef _ParserContext context
1207
+ cdef _FileReaderContext file_context
1208
+ cdef xmlDoc* result
1209
+ cdef xmlparser.xmlParserCtxt* pctxt
1210
+ cdef char* c_filename
1211
+ if not filename:
1212
+ filename = None
1213
+
1214
+ context = self._getParserContext()
1215
+ context.prepare()
1216
+ try:
1217
+ pctxt = context._c_ctxt
1218
+ __GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
1219
+ file_context = _FileReaderContext(
1220
+ filelike, context, filename,
1221
+ encoding or self._default_encoding)
1222
+ result = file_context._readDoc(pctxt, self._parse_options)
1223
+
1224
+ return context._handleParseResultDoc(
1225
+ self, result, filename)
1226
+ finally:
1227
+ context.cleanup()
1228
+
1229
+
1230
+ cdef tree.xmlEntity* _getInternalEntityOnly(void* ctxt, const_xmlChar* name) noexcept nogil:
1231
+ """
1232
+ Callback function to intercept the entity resolution when external entity loading is disabled.
1233
+ """
1234
+ cdef tree.xmlEntity* entity = xmlparser.xmlSAX2GetEntity(ctxt, name)
1235
+ if not entity:
1236
+ return NULL
1237
+ if entity.etype not in (
1238
+ tree.xmlEntityType.XML_EXTERNAL_GENERAL_PARSED_ENTITY,
1239
+ tree.xmlEntityType.XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
1240
+ tree.xmlEntityType.XML_EXTERNAL_PARAMETER_ENTITY):
1241
+ return entity
1242
+
1243
+ # Reject all external entities and fail the parsing instead. There is currently
1244
+ # no way in libxml2 to just prevent the entity resolution in this case.
1245
+ cdef xmlerror.xmlError c_error
1246
+ cdef xmlerror.xmlStructuredErrorFunc err_func
1247
+ cdef xmlparser.xmlParserInput* parser_input
1248
+ cdef void* err_context
1249
+
1250
+ c_ctxt = <xmlparser.xmlParserCtxt *> ctxt
1251
+ err_func = xmlerror.xmlStructuredError
1252
+ if err_func:
1253
+ parser_input = c_ctxt.input
1254
+ # Copied from xmlVErrParser() in libxml2: get current input from stack.
1255
+ if parser_input and parser_input.filename is NULL and c_ctxt.inputNr > 1:
1256
+ parser_input = c_ctxt.inputTab[c_ctxt.inputNr - 2]
1257
+
1258
+ c_error = xmlerror.xmlError(
1259
+ domain=xmlerror.xmlErrorDomain.XML_FROM_PARSER,
1260
+ code=xmlerror.xmlParserErrors.XML_ERR_EXT_ENTITY_STANDALONE,
1261
+ level=xmlerror.xmlErrorLevel.XML_ERR_FATAL,
1262
+ message=b"External entity resolution is disabled for security reasons "
1263
+ b"when resolving '&%s;'. Use 'XMLParser(resolve_entities=True)' "
1264
+ b"if you consider it safe to enable it.",
1265
+ file=parser_input.filename,
1266
+ node=entity,
1267
+ str1=<char*> name,
1268
+ str2=NULL,
1269
+ str3=NULL,
1270
+ line=parser_input.line if parser_input else 0,
1271
+ int1=0,
1272
+ int2=parser_input.col if parser_input else 0,
1273
+ )
1274
+ err_context = xmlerror.xmlStructuredErrorContext
1275
+ err_func(err_context, &c_error)
1276
+
1277
+ c_ctxt.wellFormed = 0
1278
+ # The entity was looked up and does not need to be freed.
1279
+ return NULL
1280
+
1281
+
1282
+ cdef void _initSaxDocument(void* ctxt) noexcept with gil:
1283
+ xmlparser.xmlSAX2StartDocument(ctxt)
1284
+ c_ctxt = <xmlparser.xmlParserCtxt*>ctxt
1285
+ c_doc = c_ctxt.myDoc
1286
+
1287
+ # set up document dict
1288
+ if c_doc and c_ctxt.dict and not c_doc.dict:
1289
+ # I have no idea why libxml2 disables this - we need it
1290
+ c_ctxt.dictNames = 1
1291
+ c_doc.dict = c_ctxt.dict
1292
+ xmlparser.xmlDictReference(c_ctxt.dict)
1293
+
1294
+ # set up XML ID hash table
1295
+ if c_ctxt._private:
1296
+ context = <_ParserContext>c_ctxt._private
1297
+ if context._collect_ids:
1298
+ # keep the global parser dict from filling up with XML IDs
1299
+ if c_doc and not c_doc.ids:
1300
+ # memory errors are not fatal here
1301
+ c_dict = xmlparser.xmlDictCreate()
1302
+ if c_dict:
1303
+ c_doc.ids = tree.xmlHashCreateDict(0, c_dict)
1304
+ xmlparser.xmlDictFree(c_dict)
1305
+ else:
1306
+ c_doc.ids = tree.xmlHashCreate(0)
1307
+ else:
1308
+ c_ctxt.loadsubset |= xmlparser.XML_SKIP_IDS
1309
+ if c_doc and c_doc.ids and not tree.xmlHashSize(c_doc.ids):
1310
+ # already initialised but empty => clear
1311
+ tree.xmlHashFree(c_doc.ids, NULL)
1312
+ c_doc.ids = NULL
1313
+
1314
+
1315
+ ############################################################
1316
+ ## ET feed parser
1317
+ ############################################################
1318
+
1319
+ cdef class _FeedParser(_BaseParser):
1320
+ cdef bint _feed_parser_running
1321
+
1322
+ @property
1323
+ def feed_error_log(self):
1324
+ """The error log of the last (or current) run of the feed parser.
1325
+
1326
+ Note that this is local to the feed parser and thus is
1327
+ different from what the ``error_log`` property returns.
1328
+ """
1329
+ return self._getPushParserContext()._error_log.copy()
1330
+
1331
+ cpdef feed(self, data):
1332
+ """feed(self, data)
1333
+
1334
+ Feeds data to the parser. The argument should be an 8-bit string
1335
+ buffer containing encoded data, although Unicode is supported as long
1336
+ as both string types are not mixed.
1337
+
1338
+ This is the main entry point to the consumer interface of a
1339
+ parser. The parser will parse as much of the XML stream as it
1340
+ can on each call. To finish parsing or to reset the parser,
1341
+ call the ``close()`` method. Both methods may raise
1342
+ ParseError if errors occur in the input data. If an error is
1343
+ raised, there is no longer a need to call ``close()``.
1344
+
1345
+ The feed parser interface is independent of the normal parser
1346
+ usage. You can use the same parser as a feed parser and in
1347
+ the ``parse()`` function concurrently.
1348
+ """
1349
+ cdef _ParserContext context
1350
+ cdef bytes bstring
1351
+ cdef xmlparser.xmlParserCtxt* pctxt
1352
+ cdef Py_ssize_t py_buffer_len, ustart
1353
+ cdef const_char* char_data
1354
+ cdef const_char* c_encoding
1355
+ cdef int buffer_len
1356
+ cdef int error
1357
+ cdef bint recover = self._parse_options & xmlparser.XML_PARSE_RECOVER
1358
+
1359
+ if isinstance(data, bytes):
1360
+ if self._default_encoding is None:
1361
+ c_encoding = NULL
1362
+ else:
1363
+ c_encoding = self._default_encoding
1364
+ char_data = _cstr(data)
1365
+ py_buffer_len = python.PyBytes_GET_SIZE(data)
1366
+ ustart = 0
1367
+ elif isinstance(data, unicode):
1368
+ c_encoding = b"UTF-8"
1369
+ char_data = NULL
1370
+ py_buffer_len = len(<unicode> data)
1371
+ ustart = 0
1372
+ else:
1373
+ raise TypeError, "Parsing requires string data"
1374
+
1375
+ context = self._getPushParserContext()
1376
+ pctxt = context._c_ctxt
1377
+ error = 0
1378
+ if not self._feed_parser_running:
1379
+ context.prepare(set_document_loader=False)
1380
+ self._feed_parser_running = 1
1381
+ c_filename = (_cstr(self._filename)
1382
+ if self._filename is not None else NULL)
1383
+
1384
+ # We have to give *mlCtxtResetPush() enough input to figure
1385
+ # out the character encoding (at least four bytes),
1386
+ # however if we give it all we got, we'll have nothing for
1387
+ # *mlParseChunk() and things go wrong.
1388
+ buffer_len = 0
1389
+ if char_data is not NULL:
1390
+ buffer_len = 4 if py_buffer_len > 4 else <int>py_buffer_len
1391
+ orig_loader = _register_document_loader()
1392
+ if self._for_html:
1393
+ error = _htmlCtxtResetPush(
1394
+ pctxt, char_data, buffer_len, c_filename, c_encoding,
1395
+ self._parse_options)
1396
+ else:
1397
+ xmlparser.xmlCtxtUseOptions(pctxt, self._parse_options)
1398
+ error = xmlparser.xmlCtxtResetPush(
1399
+ pctxt, char_data, buffer_len, c_filename, c_encoding)
1400
+ _reset_document_loader(orig_loader)
1401
+ py_buffer_len -= buffer_len
1402
+ char_data += buffer_len
1403
+ if error:
1404
+ raise MemoryError()
1405
+ __GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
1406
+
1407
+ #print pctxt.charset, 'NONE' if c_encoding is NULL else c_encoding
1408
+
1409
+ fixup_error = 0
1410
+ while py_buffer_len > 0 and (error == 0 or recover):
1411
+ if char_data is NULL:
1412
+ # Unicode parsing by converting chunks to UTF-8
1413
+ buffer_len = 2**19 # len(bytes) <= 4 * (2**19) == 2 MiB
1414
+ bstring = (<unicode> data)[ustart : ustart+buffer_len].encode('UTF-8')
1415
+ ustart += buffer_len
1416
+ py_buffer_len -= buffer_len # may end up < 0
1417
+ error, fixup_error = _parse_data_chunk(pctxt, <const char*> bstring, <int> len(bstring))
1418
+ else:
1419
+ # Direct byte string parsing.
1420
+ buffer_len = <int>py_buffer_len if py_buffer_len <= limits.INT_MAX else limits.INT_MAX
1421
+ error, fixup_error = _parse_data_chunk(pctxt, char_data, buffer_len)
1422
+ py_buffer_len -= buffer_len
1423
+ char_data += buffer_len
1424
+
1425
+ if fixup_error:
1426
+ context.store_exception(MemoryError())
1427
+
1428
+ if context._has_raised():
1429
+ # propagate Python exceptions immediately
1430
+ recover = 0
1431
+ error = 1
1432
+ break
1433
+
1434
+ if error and not pctxt.replaceEntities and not pctxt.validate:
1435
+ # in this mode, we ignore errors about undefined entities
1436
+ for entry in context._error_log.filter_from_errors():
1437
+ if entry.type != ErrorTypes.WAR_UNDECLARED_ENTITY and \
1438
+ entry.type != ErrorTypes.ERR_UNDECLARED_ENTITY:
1439
+ break
1440
+ else:
1441
+ error = 0
1442
+
1443
+ if not pctxt.wellFormed and pctxt.disableSAX and context._has_raised():
1444
+ # propagate Python exceptions immediately
1445
+ recover = 0
1446
+ error = 1
1447
+
1448
+ if fixup_error or not recover and (error or not pctxt.wellFormed):
1449
+ self._feed_parser_running = 0
1450
+ try:
1451
+ context._handleParseResult(self, pctxt.myDoc, None)
1452
+ finally:
1453
+ context.cleanup()
1454
+
1455
+ cpdef close(self):
1456
+ """close(self)
1457
+
1458
+ Terminates feeding data to this parser. This tells the parser to
1459
+ process any remaining data in the feed buffer, and then returns the
1460
+ root Element of the tree that was parsed.
1461
+
1462
+ This method must be called after passing the last chunk of data into
1463
+ the ``feed()`` method. It should only be called when using the feed
1464
+ parser interface, all other usage is undefined.
1465
+ """
1466
+ if not self._feed_parser_running:
1467
+ raise XMLSyntaxError("no element found",
1468
+ xmlerror.XML_ERR_INTERNAL_ERROR, 0, 0,
1469
+ self._filename)
1470
+
1471
+ context = self._getPushParserContext()
1472
+ pctxt = context._c_ctxt
1473
+
1474
+ self._feed_parser_running = 0
1475
+ if self._for_html:
1476
+ htmlparser.htmlParseChunk(pctxt, NULL, 0, 1)
1477
+ else:
1478
+ xmlparser.xmlParseChunk(pctxt, NULL, 0, 1)
1479
+
1480
+ if (pctxt.recovery and not pctxt.disableSAX and
1481
+ isinstance(context, _SaxParserContext)):
1482
+ # apply any left-over 'end' events
1483
+ (<_SaxParserContext>context).flushEvents()
1484
+
1485
+ try:
1486
+ result = context._handleParseResult(self, pctxt.myDoc, None)
1487
+ finally:
1488
+ context.cleanup()
1489
+
1490
+ if isinstance(result, _Document):
1491
+ return (<_Document>result).getroot()
1492
+ else:
1493
+ return result
1494
+
1495
+
1496
+ cdef (int, int) _parse_data_chunk(xmlparser.xmlParserCtxt* c_ctxt,
1497
+ const char* char_data, int buffer_len):
1498
+ fixup_error = 0
1499
+ with nogil:
1500
+ if c_ctxt.html:
1501
+ c_node = c_ctxt.node # last node where the parser stopped
1502
+ orig_loader = _register_document_loader()
1503
+ error = htmlparser.htmlParseChunk(c_ctxt, char_data, buffer_len, 0)
1504
+ _reset_document_loader(orig_loader)
1505
+ # and now for the fun part: move node names to the dict
1506
+ if c_ctxt.myDoc:
1507
+ fixup_error = _fixHtmlDictSubtreeNames(
1508
+ c_ctxt.dict, c_ctxt.myDoc, c_node)
1509
+ if c_ctxt.myDoc.dict and c_ctxt.myDoc.dict is not c_ctxt.dict:
1510
+ xmlparser.xmlDictFree(c_ctxt.myDoc.dict)
1511
+ c_ctxt.myDoc.dict = c_ctxt.dict
1512
+ xmlparser.xmlDictReference(c_ctxt.dict)
1513
+ else:
1514
+ orig_loader = _register_document_loader()
1515
+ error = xmlparser.xmlParseChunk(c_ctxt, char_data, buffer_len, 0)
1516
+ _reset_document_loader(orig_loader)
1517
+ return (error, fixup_error)
1518
+
1519
+
1520
+ cdef int _htmlCtxtResetPush(xmlparser.xmlParserCtxt* c_ctxt,
1521
+ const_char* c_data, int buffer_len,
1522
+ const_char* c_filename, const_char* c_encoding,
1523
+ int parse_options) except -1:
1524
+ cdef xmlparser.xmlParserInput* c_input_stream
1525
+ # libxml2 lacks an HTML push parser setup function
1526
+ error = xmlparser.xmlCtxtResetPush(
1527
+ c_ctxt, c_data, buffer_len, c_filename, c_encoding)
1528
+ if error:
1529
+ return error
1530
+
1531
+ # fix libxml2 setup for HTML
1532
+ c_ctxt.progressive = 1
1533
+ c_ctxt.html = 1
1534
+ htmlparser.htmlCtxtUseOptions(c_ctxt, parse_options)
1535
+
1536
+ return 0
1537
+
1538
+
1539
+ ############################################################
1540
+ ## XML parser
1541
+ ############################################################
1542
+
1543
+ cdef int _XML_DEFAULT_PARSE_OPTIONS
1544
+ _XML_DEFAULT_PARSE_OPTIONS = (
1545
+ xmlparser.XML_PARSE_NOENT |
1546
+ xmlparser.XML_PARSE_NOCDATA |
1547
+ xmlparser.XML_PARSE_NONET |
1548
+ xmlparser.XML_PARSE_COMPACT |
1549
+ xmlparser.XML_PARSE_BIG_LINES
1550
+ )
1551
+
1552
+ cdef class XMLParser(_FeedParser):
1553
+ """XMLParser(self, encoding=None, attribute_defaults=False, dtd_validation=False, load_dtd=False, no_network=True, ns_clean=False, recover=False, schema: XMLSchema =None, huge_tree=False, remove_blank_text=False, resolve_entities=True, remove_comments=False, remove_pis=False, strip_cdata=True, collect_ids=True, target=None, compact=True)
1554
+
1555
+ The XML parser.
1556
+
1557
+ Parsers can be supplied as additional argument to various parse
1558
+ functions of the lxml API. A default parser is always available
1559
+ and can be replaced by a call to the global function
1560
+ 'set_default_parser'. New parsers can be created at any time
1561
+ without a major run-time overhead.
1562
+
1563
+ The keyword arguments in the constructor are mainly based on the
1564
+ libxml2 parser configuration. A DTD will also be loaded if DTD
1565
+ validation or attribute default values are requested (unless you
1566
+ additionally provide an XMLSchema from which the default
1567
+ attributes can be read).
1568
+
1569
+ Available boolean keyword arguments:
1570
+
1571
+ - attribute_defaults - inject default attributes from DTD or XMLSchema
1572
+ - dtd_validation - validate against a DTD referenced by the document
1573
+ - load_dtd - use DTD for parsing
1574
+ - no_network - prevent network access for related files (default: True)
1575
+ - ns_clean - clean up redundant namespace declarations
1576
+ - recover - try hard to parse through broken XML
1577
+ - remove_blank_text - discard blank text nodes that appear ignorable
1578
+ - remove_comments - discard comments
1579
+ - remove_pis - discard processing instructions
1580
+ - strip_cdata - replace CDATA sections by normal text content (default: True)
1581
+ - compact - save memory for short text content (default: True)
1582
+ - collect_ids - use a hash table of XML IDs for fast access (default: True, always True with DTD validation)
1583
+ - huge_tree - disable security restrictions and support very deep trees
1584
+ and very long text content (only affects libxml2 2.7+)
1585
+
1586
+ Other keyword arguments:
1587
+
1588
+ - resolve_entities - replace entities by their text value: False for keeping the
1589
+ entity references, True for resolving them, and 'internal' for resolving
1590
+ internal definitions only (no external file/URL access).
1591
+ The default used to be True and was changed to 'internal' in lxml 5.0.
1592
+ - encoding - override the document encoding (note: libiconv encoding name)
1593
+ - target - a parser target object that will receive the parse events
1594
+ - schema - an XMLSchema to validate against
1595
+
1596
+ Note that you should avoid sharing parsers between threads. While this is
1597
+ not harmful, it is more efficient to use separate parsers. This does not
1598
+ apply to the default parser.
1599
+ """
1600
+ def __init__(self, *, encoding=None, attribute_defaults=False,
1601
+ dtd_validation=False, load_dtd=False, no_network=True,
1602
+ ns_clean=False, recover=False, XMLSchema schema=None,
1603
+ huge_tree=False, remove_blank_text=False, resolve_entities='internal',
1604
+ remove_comments=False, remove_pis=False, strip_cdata=True,
1605
+ collect_ids=True, target=None, compact=True):
1606
+ cdef int parse_options
1607
+ cdef bint resolve_external = True
1608
+ parse_options = _XML_DEFAULT_PARSE_OPTIONS
1609
+ if load_dtd:
1610
+ parse_options = parse_options | xmlparser.XML_PARSE_DTDLOAD
1611
+ if dtd_validation:
1612
+ parse_options = parse_options | xmlparser.XML_PARSE_DTDVALID | \
1613
+ xmlparser.XML_PARSE_DTDLOAD
1614
+ if attribute_defaults:
1615
+ parse_options = parse_options | xmlparser.XML_PARSE_DTDATTR
1616
+ if schema is None:
1617
+ parse_options = parse_options | xmlparser.XML_PARSE_DTDLOAD
1618
+ if ns_clean:
1619
+ parse_options = parse_options | xmlparser.XML_PARSE_NSCLEAN
1620
+ if recover:
1621
+ parse_options = parse_options | xmlparser.XML_PARSE_RECOVER
1622
+ if remove_blank_text:
1623
+ parse_options = parse_options | xmlparser.XML_PARSE_NOBLANKS
1624
+ if huge_tree:
1625
+ parse_options = parse_options | xmlparser.XML_PARSE_HUGE
1626
+ if not no_network:
1627
+ parse_options = parse_options ^ xmlparser.XML_PARSE_NONET
1628
+ if not compact:
1629
+ parse_options = parse_options ^ xmlparser.XML_PARSE_COMPACT
1630
+ if not resolve_entities:
1631
+ parse_options = parse_options ^ xmlparser.XML_PARSE_NOENT
1632
+ elif resolve_entities == 'internal':
1633
+ resolve_external = False
1634
+ if not strip_cdata:
1635
+ parse_options = parse_options ^ xmlparser.XML_PARSE_NOCDATA
1636
+
1637
+ _BaseParser.__init__(self, parse_options, False, schema,
1638
+ remove_comments, remove_pis, strip_cdata,
1639
+ collect_ids, target, encoding, resolve_external)
1640
+
1641
+
1642
+ cdef class XMLPullParser(XMLParser):
1643
+ """XMLPullParser(self, events=None, *, tag=None, **kwargs)
1644
+
1645
+ XML parser that collects parse events in an iterator.
1646
+
1647
+ The collected events are the same as for iterparse(), but the
1648
+ parser itself is non-blocking in the sense that it receives
1649
+ data chunks incrementally through its .feed() method, instead
1650
+ of reading them directly from a file(-like) object all by itself.
1651
+
1652
+ By default, it collects Element end events. To change that,
1653
+ pass any subset of the available events into the ``events``
1654
+ argument: ``'start'``, ``'end'``, ``'start-ns'``,
1655
+ ``'end-ns'``, ``'comment'``, ``'pi'``.
1656
+
1657
+ To support loading external dependencies relative to the input
1658
+ source, you can pass the ``base_url``.
1659
+ """
1660
+ def __init__(self, events=None, *, tag=None, base_url=None, **kwargs):
1661
+ XMLParser.__init__(self, **kwargs)
1662
+ if events is None:
1663
+ events = ('end',)
1664
+ self._setBaseURL(base_url)
1665
+ self._collectEvents(events, tag)
1666
+
1667
+ def read_events(self):
1668
+ return (<_SaxParserContext?>self._getPushParserContext()).events_iterator
1669
+
1670
+
1671
+ cdef class ETCompatXMLParser(XMLParser):
1672
+ """ETCompatXMLParser(self, encoding=None, attribute_defaults=False, \
1673
+ dtd_validation=False, load_dtd=False, no_network=True, \
1674
+ ns_clean=False, recover=False, schema=None, \
1675
+ huge_tree=False, remove_blank_text=False, resolve_entities=True, \
1676
+ remove_comments=True, remove_pis=True, strip_cdata=True, \
1677
+ target=None, compact=True)
1678
+
1679
+ An XML parser with an ElementTree compatible default setup.
1680
+
1681
+ See the XMLParser class for details.
1682
+
1683
+ This parser has ``remove_comments`` and ``remove_pis`` enabled by default
1684
+ and thus ignores comments and processing instructions.
1685
+ """
1686
+ def __init__(self, *, encoding=None, attribute_defaults=False,
1687
+ dtd_validation=False, load_dtd=False, no_network=True,
1688
+ ns_clean=False, recover=False, schema=None,
1689
+ huge_tree=False, remove_blank_text=False, resolve_entities=True,
1690
+ remove_comments=True, remove_pis=True, strip_cdata=True,
1691
+ target=None, compact=True):
1692
+ XMLParser.__init__(self,
1693
+ attribute_defaults=attribute_defaults,
1694
+ dtd_validation=dtd_validation,
1695
+ load_dtd=load_dtd,
1696
+ no_network=no_network,
1697
+ ns_clean=ns_clean,
1698
+ recover=recover,
1699
+ remove_blank_text=remove_blank_text,
1700
+ huge_tree=huge_tree,
1701
+ compact=compact,
1702
+ resolve_entities=resolve_entities,
1703
+ remove_comments=remove_comments,
1704
+ remove_pis=remove_pis,
1705
+ strip_cdata=strip_cdata,
1706
+ target=target,
1707
+ encoding=encoding,
1708
+ schema=schema)
1709
+
1710
+ # ET 1.2 compatible name
1711
+ XMLTreeBuilder = ETCompatXMLParser
1712
+
1713
+
1714
+ cdef XMLParser __DEFAULT_XML_PARSER
1715
+ __DEFAULT_XML_PARSER = XMLParser()
1716
+
1717
+ __GLOBAL_PARSER_CONTEXT.setDefaultParser(__DEFAULT_XML_PARSER)
1718
+
1719
+ def set_default_parser(_BaseParser parser=None):
1720
+ """set_default_parser(parser=None)
1721
+
1722
+ Set a default parser for the current thread. This parser is used
1723
+ globally whenever no parser is supplied to the various parse functions of
1724
+ the lxml API. If this function is called without a parser (or if it is
1725
+ None), the default parser is reset to the original configuration.
1726
+
1727
+ Note that the pre-installed default parser is not thread-safe. Avoid the
1728
+ default parser in multi-threaded environments. You can create a separate
1729
+ parser for each thread explicitly or use a parser pool.
1730
+ """
1731
+ if parser is None:
1732
+ parser = __DEFAULT_XML_PARSER
1733
+ __GLOBAL_PARSER_CONTEXT.setDefaultParser(parser)
1734
+
1735
+ def get_default_parser():
1736
+ "get_default_parser()"
1737
+ return __GLOBAL_PARSER_CONTEXT.getDefaultParser()
1738
+
1739
+ ############################################################
1740
+ ## HTML parser
1741
+ ############################################################
1742
+
1743
+ cdef int _HTML_DEFAULT_PARSE_OPTIONS
1744
+ _HTML_DEFAULT_PARSE_OPTIONS = (
1745
+ htmlparser.HTML_PARSE_RECOVER |
1746
+ htmlparser.HTML_PARSE_NONET |
1747
+ htmlparser.HTML_PARSE_COMPACT
1748
+ )
1749
+
1750
+ cdef object _UNUSED = object()
1751
+
1752
+ cdef class HTMLParser(_FeedParser):
1753
+ """HTMLParser(self, encoding=None, remove_blank_text=False, \
1754
+ remove_comments=False, remove_pis=False, \
1755
+ no_network=True, target=None, schema: XMLSchema =None, \
1756
+ recover=True, compact=True, collect_ids=True, huge_tree=False)
1757
+
1758
+ The HTML parser.
1759
+
1760
+ This parser allows reading HTML into a normal XML tree. By
1761
+ default, it can read broken (non well-formed) HTML, depending on
1762
+ the capabilities of libxml2. Use the 'recover' option to switch
1763
+ this off.
1764
+
1765
+ Available boolean keyword arguments:
1766
+
1767
+ - recover - try hard to parse through broken HTML (default: True)
1768
+ - no_network - prevent network access for related files (default: True)
1769
+ - remove_blank_text - discard empty text nodes that are ignorable (i.e. not actual text content)
1770
+ - remove_comments - discard comments
1771
+ - remove_pis - discard processing instructions
1772
+ - compact - save memory for short text content (default: True)
1773
+ - default_doctype - add a default doctype even if it is not found in the HTML (default: True)
1774
+ - collect_ids - use a hash table of XML IDs for fast access (default: True)
1775
+ - huge_tree - disable security restrictions and support very deep trees
1776
+ and very long text content (only affects libxml2 2.7+)
1777
+
1778
+ Other keyword arguments:
1779
+
1780
+ - encoding - override the document encoding (note: libiconv encoding name)
1781
+ - target - a parser target object that will receive the parse events
1782
+ - schema - an XMLSchema to validate against
1783
+
1784
+ Note that you should avoid sharing parsers between threads for performance
1785
+ reasons.
1786
+ """
1787
+ def __init__(self, *, encoding=None, remove_blank_text=False,
1788
+ remove_comments=False, remove_pis=False, strip_cdata=_UNUSED,
1789
+ no_network=True, target=None, XMLSchema schema=None,
1790
+ recover=True, compact=True, default_doctype=True,
1791
+ collect_ids=True, huge_tree=False):
1792
+ cdef int parse_options
1793
+ parse_options = _HTML_DEFAULT_PARSE_OPTIONS
1794
+ if remove_blank_text:
1795
+ parse_options = parse_options | htmlparser.HTML_PARSE_NOBLANKS
1796
+ if not recover:
1797
+ parse_options = parse_options ^ htmlparser.HTML_PARSE_RECOVER
1798
+ if not no_network:
1799
+ parse_options = parse_options ^ htmlparser.HTML_PARSE_NONET
1800
+ if not compact:
1801
+ parse_options = parse_options ^ htmlparser.HTML_PARSE_COMPACT
1802
+ if not default_doctype:
1803
+ parse_options = parse_options ^ htmlparser.HTML_PARSE_NODEFDTD
1804
+ if huge_tree:
1805
+ parse_options = parse_options | xmlparser.XML_PARSE_HUGE
1806
+
1807
+ if strip_cdata is not _UNUSED:
1808
+ import warnings
1809
+ warnings.warn(
1810
+ "The 'strip_cdata' option of HTMLParser() has never done anything and will eventually be removed.",
1811
+ DeprecationWarning)
1812
+ _BaseParser.__init__(self, parse_options, True, schema,
1813
+ remove_comments, remove_pis, strip_cdata,
1814
+ collect_ids, target, encoding)
1815
+
1816
+
1817
+ cdef HTMLParser __DEFAULT_HTML_PARSER
1818
+ __DEFAULT_HTML_PARSER = HTMLParser()
1819
+
1820
+
1821
+ cdef class HTMLPullParser(HTMLParser):
1822
+ """HTMLPullParser(self, events=None, *, tag=None, base_url=None, **kwargs)
1823
+
1824
+ HTML parser that collects parse events in an iterator.
1825
+
1826
+ The collected events are the same as for iterparse(), but the
1827
+ parser itself is non-blocking in the sense that it receives
1828
+ data chunks incrementally through its .feed() method, instead
1829
+ of reading them directly from a file(-like) object all by itself.
1830
+
1831
+ By default, it collects Element end events. To change that,
1832
+ pass any subset of the available events into the ``events``
1833
+ argument: ``'start'``, ``'end'``, ``'start-ns'``,
1834
+ ``'end-ns'``, ``'comment'``, ``'pi'``.
1835
+
1836
+ To support loading external dependencies relative to the input
1837
+ source, you can pass the ``base_url``.
1838
+ """
1839
+ def __init__(self, events=None, *, tag=None, base_url=None, **kwargs):
1840
+ HTMLParser.__init__(self, **kwargs)
1841
+ if events is None:
1842
+ events = ('end',)
1843
+ self._setBaseURL(base_url)
1844
+ self._collectEvents(events, tag)
1845
+
1846
+ def read_events(self):
1847
+ return (<_SaxParserContext?>self._getPushParserContext()).events_iterator
1848
+
1849
+
1850
+ ############################################################
1851
+ ## helper functions for document creation
1852
+ ############################################################
1853
+
1854
+ cdef xmlDoc* _parseDoc(text, filename, _BaseParser parser) except NULL:
1855
+ cdef char* c_filename
1856
+ cdef char* c_text
1857
+ cdef Py_ssize_t c_len
1858
+ if parser is None:
1859
+ parser = __GLOBAL_PARSER_CONTEXT.getDefaultParser()
1860
+ if not filename:
1861
+ c_filename = NULL
1862
+ else:
1863
+ filename_utf = _encodeFilenameUTF8(filename)
1864
+ c_filename = _cstr(filename_utf)
1865
+ if isinstance(text, unicode):
1866
+ if python.PyUnicode_IS_READY(text):
1867
+ # PEP-393 Unicode string
1868
+ c_len = python.PyUnicode_GET_LENGTH(text) * python.PyUnicode_KIND(text)
1869
+ else:
1870
+ # old Py_UNICODE string
1871
+ c_len = python.PyUnicode_GET_DATA_SIZE(text)
1872
+ if c_len > limits.INT_MAX:
1873
+ return (<_BaseParser>parser)._parseDocFromFilelike(
1874
+ StringIO(text), filename, None)
1875
+ return (<_BaseParser>parser)._parseUnicodeDoc(text, c_filename)
1876
+ else:
1877
+ c_len = python.PyBytes_GET_SIZE(text)
1878
+ if c_len > limits.INT_MAX:
1879
+ return (<_BaseParser>parser)._parseDocFromFilelike(
1880
+ BytesIO(text), filename, None)
1881
+ c_text = _cstr(text)
1882
+ return (<_BaseParser>parser)._parseDoc(c_text, c_len, c_filename)
1883
+
1884
+ cdef xmlDoc* _parseDocFromFile(filename8, _BaseParser parser) except NULL:
1885
+ if parser is None:
1886
+ parser = __GLOBAL_PARSER_CONTEXT.getDefaultParser()
1887
+ return (<_BaseParser>parser)._parseDocFromFile(_cstr(filename8))
1888
+
1889
+ cdef xmlDoc* _parseDocFromFilelike(source, filename,
1890
+ _BaseParser parser) except NULL:
1891
+ if parser is None:
1892
+ parser = __GLOBAL_PARSER_CONTEXT.getDefaultParser()
1893
+ return (<_BaseParser>parser)._parseDocFromFilelike(source, filename, None)
1894
+
1895
+ cdef xmlDoc* _newXMLDoc() except NULL:
1896
+ cdef xmlDoc* result
1897
+ result = tree.xmlNewDoc(NULL)
1898
+ if result is NULL:
1899
+ raise MemoryError()
1900
+ if result.encoding is NULL:
1901
+ result.encoding = tree.xmlStrdup(<unsigned char*>"UTF-8")
1902
+ __GLOBAL_PARSER_CONTEXT.initDocDict(result)
1903
+ return result
1904
+
1905
+ cdef xmlDoc* _newHTMLDoc() except NULL:
1906
+ cdef xmlDoc* result
1907
+ result = tree.htmlNewDoc(NULL, NULL)
1908
+ if result is NULL:
1909
+ raise MemoryError()
1910
+ __GLOBAL_PARSER_CONTEXT.initDocDict(result)
1911
+ return result
1912
+
1913
+ cdef xmlDoc* _copyDoc(xmlDoc* c_doc, int recursive) except NULL:
1914
+ cdef xmlDoc* result
1915
+ if recursive:
1916
+ with nogil:
1917
+ result = tree.xmlCopyDoc(c_doc, recursive)
1918
+ else:
1919
+ result = tree.xmlCopyDoc(c_doc, 0)
1920
+ if result is NULL:
1921
+ raise MemoryError()
1922
+ __GLOBAL_PARSER_CONTEXT.initDocDict(result)
1923
+ return result
1924
+
1925
+ cdef xmlDoc* _copyDocRoot(xmlDoc* c_doc, xmlNode* c_new_root) except NULL:
1926
+ "Recursively copy the document and make c_new_root the new root node."
1927
+ cdef xmlDoc* result
1928
+ cdef xmlNode* c_node
1929
+ result = tree.xmlCopyDoc(c_doc, 0) # non recursive
1930
+ __GLOBAL_PARSER_CONTEXT.initDocDict(result)
1931
+ with nogil:
1932
+ c_node = tree.xmlDocCopyNode(c_new_root, result, 1) # recursive
1933
+ if c_node is NULL:
1934
+ raise MemoryError()
1935
+ tree.xmlDocSetRootElement(result, c_node)
1936
+ _copyTail(c_new_root.next, c_node)
1937
+ return result
1938
+
1939
+ cdef xmlNode* _copyNodeToDoc(xmlNode* c_node, xmlDoc* c_doc) except NULL:
1940
+ "Recursively copy the element into the document. c_doc is not modified."
1941
+ cdef xmlNode* c_root
1942
+ c_root = tree.xmlDocCopyNode(c_node, c_doc, 1) # recursive
1943
+ if c_root is NULL:
1944
+ raise MemoryError()
1945
+ _copyTail(c_node.next, c_root)
1946
+ return c_root
1947
+
1948
+
1949
+ ############################################################
1950
+ ## API level helper functions for _Document creation
1951
+ ############################################################
1952
+
1953
+ cdef _Document _parseDocument(source, _BaseParser parser, base_url):
1954
+ cdef _Document doc
1955
+ source = _getFSPathOrObject(source)
1956
+ if _isString(source):
1957
+ # parse the file directly from the filesystem
1958
+ doc = _parseDocumentFromURL(_encodeFilename(source), parser)
1959
+ # fix base URL if requested
1960
+ if base_url is not None:
1961
+ base_url = _encodeFilenameUTF8(base_url)
1962
+ if doc._c_doc.URL is not NULL:
1963
+ tree.xmlFree(<char*>doc._c_doc.URL)
1964
+ doc._c_doc.URL = tree.xmlStrdup(_xcstr(base_url))
1965
+ return doc
1966
+
1967
+ if base_url is not None:
1968
+ url = base_url
1969
+ else:
1970
+ url = _getFilenameForFile(source)
1971
+
1972
+ if hasattr(source, 'getvalue') and hasattr(source, 'tell'):
1973
+ # StringIO - reading from start?
1974
+ if source.tell() == 0:
1975
+ return _parseMemoryDocument(source.getvalue(), url, parser)
1976
+
1977
+ # Support for file-like objects (urlgrabber.urlopen, ...)
1978
+ if hasattr(source, 'read'):
1979
+ return _parseFilelikeDocument(source, url, parser)
1980
+
1981
+ raise TypeError, f"cannot parse from '{python._fqtypename(source).decode('UTF-8')}'"
1982
+
1983
+ cdef _Document _parseDocumentFromURL(url, _BaseParser parser):
1984
+ c_doc = _parseDocFromFile(url, parser)
1985
+ return _documentFactory(c_doc, parser)
1986
+
1987
+ cdef _Document _parseMemoryDocument(text, url, _BaseParser parser):
1988
+ if isinstance(text, unicode):
1989
+ if _hasEncodingDeclaration(text):
1990
+ raise ValueError(
1991
+ "Unicode strings with encoding declaration are not supported. "
1992
+ "Please use bytes input or XML fragments without declaration.")
1993
+ elif not isinstance(text, bytes):
1994
+ raise ValueError, "can only parse strings"
1995
+ c_doc = _parseDoc(text, url, parser)
1996
+ return _documentFactory(c_doc, parser)
1997
+
1998
+ cdef _Document _parseFilelikeDocument(source, url, _BaseParser parser):
1999
+ c_doc = _parseDocFromFilelike(source, url, parser)
2000
+ return _documentFactory(c_doc, parser)
llava_video/lib/python3.10/site-packages/lxml/parsertarget.pxi ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Parser target context (ET target interface)
2
+
3
+ cdef object inspect_getargspec
4
+ try:
5
+ from inspect import getfullargspec as inspect_getargspec
6
+ except ImportError:
7
+ from inspect import getargspec as inspect_getargspec
8
+
9
+
10
+ class _TargetParserResult(Exception):
11
+ # Admittedly, this is somewhat ugly, but it's the easiest way
12
+ # to push the Python level parser result through the parser
13
+ # machinery towards the API level functions
14
+ def __init__(self, result):
15
+ self.result = result
16
+
17
+
18
+ @cython.final
19
+ @cython.internal
20
+ cdef class _PythonSaxParserTarget(_SaxParserTarget):
21
+ cdef object _target_start
22
+ cdef object _target_end
23
+ cdef object _target_data
24
+ cdef object _target_start_ns
25
+ cdef object _target_end_ns
26
+ cdef object _target_doctype
27
+ cdef object _target_pi
28
+ cdef object _target_comment
29
+ cdef bint _start_takes_nsmap
30
+
31
+ def __cinit__(self, target):
32
+ cdef int event_filter
33
+ event_filter = 0
34
+ self._start_takes_nsmap = 0
35
+ try:
36
+ self._target_start = target.start
37
+ if self._target_start is not None:
38
+ event_filter |= SAX_EVENT_START
39
+ except AttributeError:
40
+ pass
41
+ else:
42
+ try:
43
+ arguments = inspect_getargspec(self._target_start)
44
+ if len(arguments[0]) > 3 or arguments[1] is not None:
45
+ self._start_takes_nsmap = 1
46
+ except TypeError:
47
+ pass
48
+ try:
49
+ self._target_end = target.end
50
+ if self._target_end is not None:
51
+ event_filter |= SAX_EVENT_END
52
+ except AttributeError:
53
+ pass
54
+ try:
55
+ self._target_start_ns = target.start_ns
56
+ if self._target_start_ns is not None:
57
+ event_filter |= SAX_EVENT_START_NS
58
+ except AttributeError:
59
+ pass
60
+ try:
61
+ self._target_end_ns = target.end_ns
62
+ if self._target_end_ns is not None:
63
+ event_filter |= SAX_EVENT_END_NS
64
+ except AttributeError:
65
+ pass
66
+ try:
67
+ self._target_data = target.data
68
+ if self._target_data is not None:
69
+ event_filter |= SAX_EVENT_DATA
70
+ except AttributeError:
71
+ pass
72
+ try:
73
+ self._target_doctype = target.doctype
74
+ if self._target_doctype is not None:
75
+ event_filter |= SAX_EVENT_DOCTYPE
76
+ except AttributeError:
77
+ pass
78
+ try:
79
+ self._target_pi = target.pi
80
+ if self._target_pi is not None:
81
+ event_filter |= SAX_EVENT_PI
82
+ except AttributeError:
83
+ pass
84
+ try:
85
+ self._target_comment = target.comment
86
+ if self._target_comment is not None:
87
+ event_filter |= SAX_EVENT_COMMENT
88
+ except AttributeError:
89
+ pass
90
+ self._sax_event_filter = event_filter
91
+
92
+ cdef _handleSaxStart(self, tag, attrib, nsmap):
93
+ if self._start_takes_nsmap:
94
+ return self._target_start(tag, attrib, nsmap)
95
+ else:
96
+ return self._target_start(tag, attrib)
97
+
98
+ cdef _handleSaxEnd(self, tag):
99
+ return self._target_end(tag)
100
+
101
+ cdef _handleSaxStartNs(self, prefix, uri):
102
+ return self._target_start_ns(prefix, uri)
103
+
104
+ cdef _handleSaxEndNs(self, prefix):
105
+ return self._target_end_ns(prefix)
106
+
107
+ cdef int _handleSaxData(self, data) except -1:
108
+ self._target_data(data)
109
+
110
+ cdef int _handleSaxDoctype(self, root_tag, public_id, system_id) except -1:
111
+ self._target_doctype(root_tag, public_id, system_id)
112
+
113
+ cdef _handleSaxPi(self, target, data):
114
+ return self._target_pi(target, data)
115
+
116
+ cdef _handleSaxComment(self, comment):
117
+ return self._target_comment(comment)
118
+
119
+
120
+ @cython.final
121
+ @cython.internal
122
+ @cython.no_gc_clear # Required because parent class uses it - Cython bug.
123
+ cdef class _TargetParserContext(_SaxParserContext):
124
+ """This class maps SAX2 events to the ET parser target interface.
125
+ """
126
+ cdef object _python_target
127
+ cdef int _setTarget(self, target) except -1:
128
+ self._python_target = target
129
+ if not isinstance(target, _SaxParserTarget) or \
130
+ hasattr(target, '__dict__'):
131
+ target = _PythonSaxParserTarget(target)
132
+ self._setSaxParserTarget(target)
133
+ return 0
134
+
135
+ cdef _ParserContext _copy(self):
136
+ cdef _TargetParserContext context
137
+ context = _ParserContext._copy(self)
138
+ context._setTarget(self._python_target)
139
+ return context
140
+
141
+ cdef void _cleanupTargetParserContext(self, xmlDoc* result) noexcept:
142
+ if self._c_ctxt.myDoc is not NULL:
143
+ if self._c_ctxt.myDoc is not result and \
144
+ self._c_ctxt.myDoc._private is NULL:
145
+ # no _Document proxy => orphen
146
+ tree.xmlFreeDoc(self._c_ctxt.myDoc)
147
+ self._c_ctxt.myDoc = NULL
148
+
149
+ cdef object _handleParseResult(self, _BaseParser parser, xmlDoc* result,
150
+ filename):
151
+ cdef bint recover
152
+ recover = parser._parse_options & xmlparser.XML_PARSE_RECOVER
153
+ try:
154
+ if self._has_raised():
155
+ self._cleanupTargetParserContext(result)
156
+ self._raise_if_stored()
157
+ if not self._c_ctxt.wellFormed and not recover:
158
+ _raiseParseError(self._c_ctxt, filename, self._error_log)
159
+ except:
160
+ self._python_target.close()
161
+ raise
162
+ return self._python_target.close()
163
+
164
+ cdef xmlDoc* _handleParseResultDoc(self, _BaseParser parser,
165
+ xmlDoc* result, filename) except NULL:
166
+ cdef bint recover
167
+ recover = parser._parse_options & xmlparser.XML_PARSE_RECOVER
168
+ if result is not NULL and result._private is NULL:
169
+ # no _Document proxy => orphen
170
+ tree.xmlFreeDoc(result)
171
+ try:
172
+ self._cleanupTargetParserContext(result)
173
+ self._raise_if_stored()
174
+ if not self._c_ctxt.wellFormed and not recover:
175
+ _raiseParseError(self._c_ctxt, filename, self._error_log)
176
+ except:
177
+ self._python_target.close()
178
+ raise
179
+ parse_result = self._python_target.close()
180
+ raise _TargetParserResult(parse_result)
llava_video/lib/python3.10/site-packages/lxml/proxy.pxi ADDED
@@ -0,0 +1,619 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Proxy functions and low level node allocation stuff
2
+
3
+ # Proxies represent elements, their reference is stored in the C
4
+ # structure of the respective node to avoid multiple instantiation of
5
+ # the Python class.
6
+
7
+ @cython.linetrace(False)
8
+ @cython.profile(False)
9
+ cdef inline _Element getProxy(xmlNode* c_node):
10
+ """Get a proxy for a given node.
11
+ """
12
+ #print "getProxy for:", <int>c_node
13
+ if c_node is not NULL and c_node._private is not NULL:
14
+ return <_Element>c_node._private
15
+ else:
16
+ return None
17
+
18
+
19
+ @cython.linetrace(False)
20
+ @cython.profile(False)
21
+ cdef inline bint hasProxy(xmlNode* c_node):
22
+ if c_node._private is NULL:
23
+ return False
24
+ return True
25
+
26
+
27
+ @cython.linetrace(False)
28
+ @cython.profile(False)
29
+ cdef inline int _registerProxy(_Element proxy, _Document doc,
30
+ xmlNode* c_node) except -1:
31
+ """Register a proxy and type for the node it's proxying for.
32
+ """
33
+ #print "registering for:", <int>proxy._c_node
34
+ assert not hasProxy(c_node), "double registering proxy!"
35
+ proxy._doc = doc
36
+ proxy._c_node = c_node
37
+ c_node._private = <void*>proxy
38
+ return 0
39
+
40
+
41
+ @cython.linetrace(False)
42
+ @cython.profile(False)
43
+ cdef inline int _unregisterProxy(_Element proxy) except -1:
44
+ """Unregister a proxy for the node it's proxying for.
45
+ """
46
+ cdef xmlNode* c_node = proxy._c_node
47
+ assert c_node._private is <void*>proxy, "Tried to unregister unknown proxy"
48
+ c_node._private = NULL
49
+ return 0
50
+
51
+
52
+ ################################################################################
53
+ # temporarily make a node the root node of its document
54
+
55
+ cdef xmlDoc* _fakeRootDoc(xmlDoc* c_base_doc, xmlNode* c_node) except NULL:
56
+ return _plainFakeRootDoc(c_base_doc, c_node, 1)
57
+
58
+ cdef xmlDoc* _plainFakeRootDoc(xmlDoc* c_base_doc, xmlNode* c_node,
59
+ bint with_siblings) except NULL:
60
+ # build a temporary document that has the given node as root node
61
+ # note that copy and original must not be modified during its lifetime!!
62
+ # always call _destroyFakeDoc() after use!
63
+ cdef xmlNode* c_child
64
+ cdef xmlNode* c_root
65
+ cdef xmlNode* c_new_root
66
+ cdef xmlDoc* c_doc
67
+ if with_siblings or (c_node.prev is NULL and c_node.next is NULL):
68
+ c_root = tree.xmlDocGetRootElement(c_base_doc)
69
+ if c_root is c_node:
70
+ # already the root node, no siblings
71
+ return c_base_doc
72
+
73
+ c_doc = _copyDoc(c_base_doc, 0) # non recursive!
74
+ c_new_root = tree.xmlDocCopyNode(c_node, c_doc, 2) # non recursive!
75
+ tree.xmlDocSetRootElement(c_doc, c_new_root)
76
+ _copyParentNamespaces(c_node, c_new_root)
77
+
78
+ c_new_root.children = c_node.children
79
+ c_new_root.last = c_node.last
80
+ c_new_root.next = c_new_root.prev = NULL
81
+
82
+ # store original node
83
+ c_doc._private = c_node
84
+
85
+ # divert parent pointers of children
86
+ c_child = c_new_root.children
87
+ while c_child is not NULL:
88
+ c_child.parent = c_new_root
89
+ c_child = c_child.next
90
+
91
+ c_doc.children = c_new_root
92
+ return c_doc
93
+
94
+ cdef void _destroyFakeDoc(xmlDoc* c_base_doc, xmlDoc* c_doc) noexcept:
95
+ # delete a temporary document
96
+ cdef xmlNode* c_child
97
+ cdef xmlNode* c_parent
98
+ cdef xmlNode* c_root
99
+ if c_doc is c_base_doc:
100
+ return
101
+ c_root = tree.xmlDocGetRootElement(c_doc)
102
+
103
+ # restore parent pointers of children
104
+ c_parent = <xmlNode*>c_doc._private
105
+ c_child = c_root.children
106
+ while c_child is not NULL:
107
+ c_child.parent = c_parent
108
+ c_child = c_child.next
109
+
110
+ # prevent recursive removal of children
111
+ c_root.children = c_root.last = NULL
112
+ tree.xmlFreeDoc(c_doc)
113
+
114
+ cdef _Element _fakeDocElementFactory(_Document doc, xmlNode* c_element):
115
+ """Special element factory for cases where we need to create a fake
116
+ root document, but still need to instantiate arbitrary nodes from
117
+ it. If we instantiate the fake root node, things will turn bad
118
+ when it's destroyed.
119
+
120
+ Instead, if we are asked to instantiate the fake root node, we
121
+ instantiate the original node instead.
122
+ """
123
+ if c_element.doc is not doc._c_doc:
124
+ if c_element.doc._private is not NULL:
125
+ if c_element is c_element.doc.children:
126
+ c_element = <xmlNode*>c_element.doc._private
127
+ #assert c_element.type == tree.XML_ELEMENT_NODE
128
+ return _elementFactory(doc, c_element)
129
+
130
+ ################################################################################
131
+ # support for freeing tree elements when proxy objects are destroyed
132
+
133
+ cdef int attemptDeallocation(xmlNode* c_node) noexcept:
134
+ """Attempt deallocation of c_node (or higher up in tree).
135
+ """
136
+ cdef xmlNode* c_top
137
+ # could be we actually aren't referring to the tree at all
138
+ if c_node is NULL:
139
+ #print "not freeing, node is NULL"
140
+ return 0
141
+ c_top = getDeallocationTop(c_node)
142
+ if c_top is not NULL:
143
+ #print "freeing:", c_top.name
144
+ _removeText(c_top.next) # tail
145
+ tree.xmlFreeNode(c_top)
146
+ return 1
147
+ return 0
148
+
149
+ cdef xmlNode* getDeallocationTop(xmlNode* c_node) noexcept:
150
+ """Return the top of the tree that can be deallocated, or NULL.
151
+ """
152
+ cdef xmlNode* c_next
153
+ #print "trying to do deallocating:", c_node.type
154
+ if hasProxy(c_node):
155
+ #print "Not freeing: proxies still exist"
156
+ return NULL
157
+ while c_node.parent is not NULL:
158
+ c_node = c_node.parent
159
+ #print "checking:", c_current.type
160
+ if c_node.type == tree.XML_DOCUMENT_NODE or \
161
+ c_node.type == tree.XML_HTML_DOCUMENT_NODE:
162
+ #print "not freeing: still in doc"
163
+ return NULL
164
+ # if we're still attached to the document, don't deallocate
165
+ if hasProxy(c_node):
166
+ #print "Not freeing: proxies still exist"
167
+ return NULL
168
+ # see whether we have children to deallocate
169
+ if not canDeallocateChildNodes(c_node):
170
+ return NULL
171
+ # see whether we have siblings to deallocate
172
+ c_next = c_node.prev
173
+ while c_next:
174
+ if _isElement(c_next):
175
+ if hasProxy(c_next) or not canDeallocateChildNodes(c_next):
176
+ return NULL
177
+ c_next = c_next.prev
178
+ c_next = c_node.next
179
+ while c_next:
180
+ if _isElement(c_next):
181
+ if hasProxy(c_next) or not canDeallocateChildNodes(c_next):
182
+ return NULL
183
+ c_next = c_next.next
184
+ return c_node
185
+
186
+ cdef int canDeallocateChildNodes(xmlNode* c_parent) noexcept:
187
+ cdef xmlNode* c_node
188
+ c_node = c_parent.children
189
+ tree.BEGIN_FOR_EACH_ELEMENT_FROM(c_parent, c_node, 1)
190
+ if hasProxy(c_node):
191
+ return 0
192
+ tree.END_FOR_EACH_ELEMENT_FROM(c_node)
193
+ return 1
194
+
195
+ ################################################################################
196
+ # fix _Document references and namespaces when a node changes documents
197
+
198
+ cdef void _copyParentNamespaces(xmlNode* c_from_node, xmlNode* c_to_node) noexcept nogil:
199
+ """Copy the namespaces of all ancestors of c_from_node to c_to_node.
200
+ """
201
+ cdef xmlNode* c_parent
202
+ cdef xmlNs* c_ns
203
+ cdef xmlNs* c_new_ns
204
+ cdef int prefix_known
205
+ c_parent = c_from_node.parent
206
+ while c_parent and (tree._isElementOrXInclude(c_parent) or
207
+ c_parent.type == tree.XML_DOCUMENT_NODE):
208
+ c_new_ns = c_parent.nsDef
209
+ while c_new_ns:
210
+ # libxml2 will check if the prefix is already defined
211
+ tree.xmlNewNs(c_to_node, c_new_ns.href, c_new_ns.prefix)
212
+ c_new_ns = c_new_ns.next
213
+ c_parent = c_parent.parent
214
+
215
+
216
+ ctypedef struct _ns_update_map:
217
+ xmlNs* old
218
+ xmlNs* new
219
+
220
+
221
+ ctypedef struct _nscache:
222
+ _ns_update_map* ns_map
223
+ size_t size
224
+ size_t last
225
+
226
+
227
+ cdef int _growNsCache(_nscache* c_ns_cache) except -1:
228
+ cdef _ns_update_map* ns_map_ptr
229
+ if c_ns_cache.size == 0:
230
+ c_ns_cache.size = 20
231
+ else:
232
+ c_ns_cache.size *= 2
233
+ ns_map_ptr = <_ns_update_map*> python.lxml_realloc(
234
+ c_ns_cache.ns_map, c_ns_cache.size, sizeof(_ns_update_map))
235
+ if not ns_map_ptr:
236
+ python.lxml_free(c_ns_cache.ns_map)
237
+ c_ns_cache.ns_map = NULL
238
+ raise MemoryError()
239
+ c_ns_cache.ns_map = ns_map_ptr
240
+ return 0
241
+
242
+
243
+ cdef inline int _appendToNsCache(_nscache* c_ns_cache,
244
+ xmlNs* c_old_ns, xmlNs* c_new_ns) except -1:
245
+ if c_ns_cache.last >= c_ns_cache.size:
246
+ _growNsCache(c_ns_cache)
247
+ c_ns_cache.ns_map[c_ns_cache.last] = _ns_update_map(old=c_old_ns, new=c_new_ns)
248
+ c_ns_cache.last += 1
249
+
250
+
251
+ cdef int _stripRedundantNamespaceDeclarations(xmlNode* c_element, _nscache* c_ns_cache,
252
+ xmlNs** c_del_ns_list) except -1:
253
+ """Removes namespace declarations from an element that are already
254
+ defined in its parents. Does not free the xmlNs's, just prepends
255
+ them to the c_del_ns_list.
256
+ """
257
+ cdef xmlNs* c_ns
258
+ cdef xmlNs* c_ns_next
259
+ cdef xmlNs** c_nsdef
260
+ # use a xmlNs** to handle assignments to "c_element.nsDef" correctly
261
+ c_nsdef = &c_element.nsDef
262
+ while c_nsdef[0] is not NULL:
263
+ c_ns = tree.xmlSearchNsByHref(
264
+ c_element.doc, c_element.parent, c_nsdef[0].href)
265
+ if c_ns is NULL:
266
+ # new namespace href => keep and cache the ns declaration
267
+ _appendToNsCache(c_ns_cache, c_nsdef[0], c_nsdef[0])
268
+ c_nsdef = &c_nsdef[0].next
269
+ else:
270
+ # known namespace href => cache mapping and strip old ns
271
+ _appendToNsCache(c_ns_cache, c_nsdef[0], c_ns)
272
+ # cut out c_nsdef.next and prepend it to garbage chain
273
+ c_ns_next = c_nsdef[0].next
274
+ c_nsdef[0].next = c_del_ns_list[0]
275
+ c_del_ns_list[0] = c_nsdef[0]
276
+ c_nsdef[0] = c_ns_next
277
+ return 0
278
+
279
+
280
+ cdef void _cleanUpFromNamespaceAdaptation(xmlNode* c_start_node,
281
+ _nscache* c_ns_cache, xmlNs* c_del_ns_list) noexcept:
282
+ # Try to recover from exceptions with really bad timing. We were in the middle
283
+ # of ripping out xmlNS-es and likely ran out of memory. Try to fix up the tree
284
+ # by re-adding the original xmlNs declarations (which might still be used in some
285
+ # places).
286
+ if c_ns_cache.ns_map:
287
+ python.lxml_free(c_ns_cache.ns_map)
288
+ if c_del_ns_list:
289
+ if not c_start_node.nsDef:
290
+ c_start_node.nsDef = c_del_ns_list
291
+ else:
292
+ c_ns = c_start_node.nsDef
293
+ while c_ns.next:
294
+ c_ns = c_ns.next
295
+ c_ns.next = c_del_ns_list
296
+
297
+
298
+ cdef int moveNodeToDocument(_Document doc, xmlDoc* c_source_doc,
299
+ xmlNode* c_element) except -1:
300
+ """Fix the xmlNs pointers of a node and its subtree that were moved.
301
+
302
+ Originally copied from libxml2's xmlReconciliateNs(). Expects
303
+ libxml2 doc pointers of node to be correct already, but fixes
304
+ _Document references.
305
+
306
+ For each node in the subtree, we do this:
307
+
308
+ 1) Remove redundant declarations of namespace that are already
309
+ defined in its parents.
310
+
311
+ 2) Replace namespaces that are *not* defined on the node or its
312
+ parents by the equivalent namespace declarations that *are*
313
+ defined on the node or its parents (possibly using a different
314
+ prefix). If a namespace is unknown, declare a new one on the
315
+ node.
316
+
317
+ 3) Reassign the names of tags and attribute from the dict of the
318
+ target document *iff* it is different from the dict used in the
319
+ source subtree.
320
+
321
+ 4) Set the Document reference to the new Document (if different).
322
+ This is done on backtracking to keep the original Document
323
+ alive as long as possible, until all its elements are updated.
324
+
325
+ Note that the namespace declarations are removed from the tree in
326
+ step 1), but freed only after the complete subtree was traversed
327
+ and all occurrences were replaced by tree-internal pointers.
328
+ """
329
+ cdef xmlNode* c_start_node
330
+ cdef xmlNode* c_node
331
+ cdef xmlDoc* c_doc = doc._c_doc
332
+ cdef tree.xmlAttr* c_attr
333
+ cdef char* c_name
334
+ cdef _nscache c_ns_cache = [NULL, 0, 0]
335
+ cdef xmlNs* c_del_ns_list = NULL
336
+ cdef proxy_count = 0
337
+
338
+ if not tree._isElementOrXInclude(c_element):
339
+ return 0
340
+
341
+ c_start_node = c_element
342
+
343
+ tree.BEGIN_FOR_EACH_FROM(c_element, c_element, 1)
344
+ if tree._isElementOrXInclude(c_element):
345
+ if hasProxy(c_element):
346
+ proxy_count += 1
347
+
348
+ # 1) cut out namespaces defined here that are already known by
349
+ # the ancestors
350
+ if c_element.nsDef is not NULL:
351
+ try:
352
+ _stripRedundantNamespaceDeclarations(c_element, &c_ns_cache, &c_del_ns_list)
353
+ except:
354
+ _cleanUpFromNamespaceAdaptation(c_start_node, &c_ns_cache, c_del_ns_list)
355
+ raise
356
+
357
+ # 2) make sure the namespaces of an element and its attributes
358
+ # are declared in this document (i.e. on the node or its parents)
359
+ if c_element.ns is not NULL:
360
+ _fixCNs(doc, c_start_node, c_element, &c_ns_cache, c_del_ns_list)
361
+
362
+ c_node = <xmlNode*>c_element.properties
363
+ while c_node is not NULL:
364
+ if c_node.ns is not NULL:
365
+ _fixCNs(doc, c_start_node, c_node, &c_ns_cache, c_del_ns_list)
366
+ c_node = c_node.next
367
+
368
+ tree.END_FOR_EACH_FROM(c_element)
369
+
370
+ # free now unused namespace declarations
371
+ if c_del_ns_list is not NULL:
372
+ tree.xmlFreeNsList(c_del_ns_list)
373
+
374
+ # cleanup
375
+ if c_ns_cache.ns_map is not NULL:
376
+ python.lxml_free(c_ns_cache.ns_map)
377
+
378
+ # 3) fix the names in the tree if we moved it from a different thread
379
+ if doc._c_doc.dict is not c_source_doc.dict:
380
+ fixThreadDictNames(c_start_node, c_source_doc.dict, doc._c_doc.dict)
381
+
382
+ # 4) fix _Document references
383
+ # (and potentially deallocate the source document)
384
+ if proxy_count > 0:
385
+ if proxy_count == 1 and c_start_node._private is not NULL:
386
+ proxy = getProxy(c_start_node)
387
+ if proxy is not None:
388
+ if proxy._doc is not doc:
389
+ proxy._doc = doc
390
+ else:
391
+ fixElementDocument(c_start_node, doc, proxy_count)
392
+ else:
393
+ fixElementDocument(c_start_node, doc, proxy_count)
394
+
395
+ return 0
396
+
397
+
398
+ cdef void _setTreeDoc(xmlNode* c_node, xmlDoc* c_doc) noexcept:
399
+ """Adaptation of 'xmlSetTreeDoc()' that deep-fixes the document links iteratively.
400
+ It avoids https://gitlab.gnome.org/GNOME/libxml2/issues/42
401
+ """
402
+ tree.BEGIN_FOR_EACH_FROM(c_node, c_node, 1)
403
+ if c_node.type == tree.XML_ELEMENT_NODE:
404
+ c_attr = <tree.xmlAttr*>c_node.properties
405
+ while c_attr:
406
+ if c_attr.atype == tree.XML_ATTRIBUTE_ID:
407
+ tree.xmlRemoveID(c_node.doc, c_attr)
408
+ c_attr.doc = c_doc
409
+ _fixDocChildren(c_attr.children, c_doc)
410
+ c_attr = c_attr.next
411
+ # Set doc link for all nodes, not only elements.
412
+ c_node.doc = c_doc
413
+ tree.END_FOR_EACH_FROM(c_node)
414
+
415
+
416
+ cdef inline void _fixDocChildren(xmlNode* c_child, xmlDoc* c_doc) noexcept:
417
+ while c_child:
418
+ c_child.doc = c_doc
419
+ if c_child.children:
420
+ _fixDocChildren(c_child.children, c_doc)
421
+ c_child = c_child.next
422
+
423
+
424
+ cdef int _fixCNs(_Document doc, xmlNode* c_start_node, xmlNode* c_node,
425
+ _nscache* c_ns_cache, xmlNs* c_del_ns_list) except -1:
426
+ cdef xmlNs* c_ns = NULL
427
+ cdef bint is_prefixed_attr = (c_node.type == tree.XML_ATTRIBUTE_NODE and c_node.ns.prefix)
428
+
429
+ for ns_map in c_ns_cache.ns_map[:c_ns_cache.last]:
430
+ if c_node.ns is ns_map.old:
431
+ if is_prefixed_attr and not ns_map.new.prefix:
432
+ # avoid dropping prefix from attributes
433
+ continue
434
+ c_ns = ns_map.new
435
+ break
436
+
437
+ if c_ns:
438
+ c_node.ns = c_ns
439
+ else:
440
+ # not in cache or not acceptable
441
+ # => find a replacement from this document
442
+ try:
443
+ c_ns = doc._findOrBuildNodeNs(
444
+ c_start_node, c_node.ns.href, c_node.ns.prefix,
445
+ c_node.type == tree.XML_ATTRIBUTE_NODE)
446
+ c_node.ns = c_ns
447
+ _appendToNsCache(c_ns_cache, c_node.ns, c_ns)
448
+ except:
449
+ _cleanUpFromNamespaceAdaptation(c_start_node, c_ns_cache, c_del_ns_list)
450
+ raise
451
+ return 0
452
+
453
+
454
+ cdef int fixElementDocument(xmlNode* c_element, _Document doc,
455
+ size_t proxy_count) except -1:
456
+ cdef xmlNode* c_node = c_element
457
+ cdef _Element proxy = None # init-to-None required due to fake-loop below
458
+ tree.BEGIN_FOR_EACH_FROM(c_element, c_node, 1)
459
+ if c_node._private is not NULL:
460
+ proxy = getProxy(c_node)
461
+ if proxy is not None:
462
+ if proxy._doc is not doc:
463
+ proxy._doc = doc
464
+ proxy_count -= 1
465
+ if proxy_count == 0:
466
+ return 0
467
+ tree.END_FOR_EACH_FROM(c_node)
468
+
469
+
470
+ cdef void fixThreadDictNames(xmlNode* c_element,
471
+ tree.xmlDict* c_src_dict,
472
+ tree.xmlDict* c_dict) noexcept nogil:
473
+ # re-assign the names of tags and attributes
474
+ #
475
+ # this should only be called when the element is based on a
476
+ # different libxml2 tag name dictionary
477
+ if c_element.type == tree.XML_DOCUMENT_NODE or \
478
+ c_element.type == tree.XML_HTML_DOCUMENT_NODE:
479
+ # may define "xml" namespace
480
+ fixThreadDictNsForNode(c_element, c_src_dict, c_dict)
481
+ if c_element.doc.extSubset:
482
+ fixThreadDictNamesForDtd(c_element.doc.extSubset, c_src_dict, c_dict)
483
+ if c_element.doc.intSubset:
484
+ fixThreadDictNamesForDtd(c_element.doc.intSubset, c_src_dict, c_dict)
485
+ c_element = c_element.children
486
+ while c_element is not NULL:
487
+ fixThreadDictNamesForNode(c_element, c_src_dict, c_dict)
488
+ c_element = c_element.next
489
+ elif tree._isElementOrXInclude(c_element):
490
+ fixThreadDictNamesForNode(c_element, c_src_dict, c_dict)
491
+
492
+
493
+ cdef inline void _fixThreadDictPtr(const_xmlChar** c_ptr,
494
+ tree.xmlDict* c_src_dict,
495
+ tree.xmlDict* c_dict) noexcept nogil:
496
+ c_str = c_ptr[0]
497
+ if c_str and c_src_dict and tree.xmlDictOwns(c_src_dict, c_str):
498
+ # return value can be NULL on memory error, but we don't handle that here
499
+ c_str = tree.xmlDictLookup(c_dict, c_str, -1)
500
+ if c_str:
501
+ c_ptr[0] = c_str
502
+
503
+
504
+ cdef void fixThreadDictNamesForNode(xmlNode* c_element,
505
+ tree.xmlDict* c_src_dict,
506
+ tree.xmlDict* c_dict) noexcept nogil:
507
+ cdef xmlNode* c_node = c_element
508
+ tree.BEGIN_FOR_EACH_FROM(c_element, c_node, 1)
509
+ if c_node.type in (tree.XML_ELEMENT_NODE, tree.XML_XINCLUDE_START):
510
+ fixThreadDictNamesForAttributes(
511
+ c_node.properties, c_src_dict, c_dict)
512
+ fixThreadDictNsForNode(c_node, c_src_dict, c_dict)
513
+ _fixThreadDictPtr(&c_node.name, c_src_dict, c_dict)
514
+ elif c_node.type == tree.XML_TEXT_NODE:
515
+ # libxml2's SAX2 parser interns some indentation space
516
+ fixThreadDictContentForNode(c_node, c_src_dict, c_dict)
517
+ elif c_node.type == tree.XML_COMMENT_NODE:
518
+ pass # don't touch c_node.name
519
+ else:
520
+ _fixThreadDictPtr(&c_node.name, c_src_dict, c_dict)
521
+ tree.END_FOR_EACH_FROM(c_node)
522
+
523
+
524
+ cdef inline void fixThreadDictNamesForAttributes(tree.xmlAttr* c_attr,
525
+ tree.xmlDict* c_src_dict,
526
+ tree.xmlDict* c_dict) noexcept nogil:
527
+ cdef xmlNode* c_child
528
+ cdef xmlNode* c_node = <xmlNode*>c_attr
529
+ while c_node is not NULL:
530
+ if c_node.type not in (tree.XML_TEXT_NODE, tree.XML_COMMENT_NODE):
531
+ _fixThreadDictPtr(&c_node.name, c_src_dict, c_dict)
532
+ # libxml2 keeps some (!) attribute values in the dict
533
+ c_child = c_node.children
534
+ while c_child is not NULL:
535
+ fixThreadDictContentForNode(c_child, c_src_dict, c_dict)
536
+ c_child = c_child.next
537
+ c_node = c_node.next
538
+
539
+
540
+ cdef inline void fixThreadDictContentForNode(xmlNode* c_node,
541
+ tree.xmlDict* c_src_dict,
542
+ tree.xmlDict* c_dict) noexcept nogil:
543
+ if c_node.content is not NULL and \
544
+ c_node.content is not <xmlChar*>&c_node.properties:
545
+ if tree.xmlDictOwns(c_src_dict, c_node.content):
546
+ # result can be NULL on memory error, but we don't handle that here
547
+ c_node.content = <xmlChar*>tree.xmlDictLookup(c_dict, c_node.content, -1)
548
+
549
+
550
+ cdef inline void fixThreadDictNsForNode(xmlNode* c_node,
551
+ tree.xmlDict* c_src_dict,
552
+ tree.xmlDict* c_dict) noexcept nogil:
553
+ cdef xmlNs* c_ns = c_node.nsDef
554
+ while c_ns is not NULL:
555
+ _fixThreadDictPtr(&c_ns.href, c_src_dict, c_dict)
556
+ _fixThreadDictPtr(&c_ns.prefix, c_src_dict, c_dict)
557
+ c_ns = c_ns.next
558
+
559
+
560
+ cdef void fixThreadDictNamesForDtd(tree.xmlDtd* c_dtd,
561
+ tree.xmlDict* c_src_dict,
562
+ tree.xmlDict* c_dict) noexcept nogil:
563
+ cdef xmlNode* c_node
564
+ cdef tree.xmlElement* c_element
565
+ cdef tree.xmlAttribute* c_attribute
566
+ cdef tree.xmlEntity* c_entity
567
+
568
+ c_node = c_dtd.children
569
+ while c_node:
570
+ if c_node.type == tree.XML_ELEMENT_DECL:
571
+ c_element = <tree.xmlElement*>c_node
572
+ if c_element.content:
573
+ _fixThreadDictPtr(&c_element.content.name, c_src_dict, c_dict)
574
+ _fixThreadDictPtr(&c_element.content.prefix, c_src_dict, c_dict)
575
+ c_attribute = c_element.attributes
576
+ while c_attribute:
577
+ _fixThreadDictPtr(&c_attribute.defaultValue, c_src_dict, c_dict)
578
+ _fixThreadDictPtr(&c_attribute.name, c_src_dict, c_dict)
579
+ _fixThreadDictPtr(&c_attribute.prefix, c_src_dict, c_dict)
580
+ _fixThreadDictPtr(&c_attribute.elem, c_src_dict, c_dict)
581
+ c_attribute = c_attribute.nexth
582
+ elif c_node.type == tree.XML_ENTITY_DECL:
583
+ c_entity = <tree.xmlEntity*>c_node
584
+ _fixThreadDictPtr(&c_entity.name, c_src_dict, c_dict)
585
+ _fixThreadDictPtr(&c_entity.ExternalID, c_src_dict, c_dict)
586
+ _fixThreadDictPtr(&c_entity.SystemID, c_src_dict, c_dict)
587
+ _fixThreadDictPtr(<const_xmlChar**>&c_entity.content, c_src_dict, c_dict)
588
+ c_node = c_node.next
589
+
590
+
591
+ ################################################################################
592
+ # adopt an xmlDoc from an external libxml2 document source
593
+
594
+ cdef _Document _adoptForeignDoc(xmlDoc* c_doc, _BaseParser parser=None, bint is_owned=True):
595
+ """Convert and wrap an externally produced xmlDoc for use in lxml.
596
+ Assures that all '_private' pointers are NULL to prevent accidental
597
+ dereference into lxml proxy objects.
598
+ """
599
+ if c_doc is NULL:
600
+ raise ValueError("Illegal document provided: NULL")
601
+ if c_doc.type not in (tree.XML_DOCUMENT_NODE, tree.XML_HTML_DOCUMENT_NODE):
602
+ doc_type = c_doc.type
603
+ if is_owned:
604
+ tree.xmlFreeDoc(c_doc)
605
+ raise ValueError(f"Illegal document provided: expected XML or HTML, found {doc_type}")
606
+
607
+ cdef xmlNode* c_node = <xmlNode*>c_doc
608
+
609
+ if is_owned:
610
+ tree.BEGIN_FOR_EACH_FROM(<xmlNode*>c_doc, c_node, 1)
611
+ c_node._private = NULL
612
+ tree.END_FOR_EACH_FROM(c_node)
613
+ else:
614
+ # create a fresh copy that lxml owns
615
+ c_doc = tree.xmlCopyDoc(c_doc, 1)
616
+ if c_doc is NULL:
617
+ raise MemoryError()
618
+
619
+ return _documentFactory(c_doc, parser)
llava_video/lib/python3.10/site-packages/lxml/public-api.pxi ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Public C API for lxml.etree
2
+
3
+ cdef public api _Element deepcopyNodeToDocument(_Document doc, xmlNode* c_root):
4
+ "Recursively copy the element into the document. doc is not modified."
5
+ cdef xmlNode* c_node
6
+ c_node = _copyNodeToDoc(c_root, doc._c_doc)
7
+ return _elementFactory(doc, c_node)
8
+
9
+ cdef public api _ElementTree elementTreeFactory(_Element context_node):
10
+ _assertValidNode(context_node)
11
+ return newElementTree(context_node, _ElementTree)
12
+
13
+ cdef public api _ElementTree newElementTree(_Element context_node,
14
+ object subclass):
15
+ if <void*>context_node is NULL or context_node is None:
16
+ raise TypeError
17
+ _assertValidNode(context_node)
18
+ return _newElementTree(context_node._doc, context_node, subclass)
19
+
20
+ cdef public api _ElementTree adoptExternalDocument(xmlDoc* c_doc, parser, bint is_owned):
21
+ if c_doc is NULL:
22
+ raise TypeError
23
+ doc = _adoptForeignDoc(c_doc, parser, is_owned)
24
+ return _elementTreeFactory(doc, None)
25
+
26
+ cdef public api _Element elementFactory(_Document doc, xmlNode* c_node):
27
+ if c_node is NULL or doc is None:
28
+ raise TypeError
29
+ return _elementFactory(doc, c_node)
30
+
31
+ cdef public api _Element makeElement(tag, _Document doc, parser,
32
+ text, tail, attrib, nsmap):
33
+ return _makeElement(tag, NULL, doc, parser, text, tail, attrib, nsmap, None)
34
+
35
+ cdef public api _Element makeSubElement(_Element parent, tag, text, tail,
36
+ attrib, nsmap):
37
+ _assertValidNode(parent)
38
+ return _makeSubElement(parent, tag, text, tail, attrib, nsmap, None)
39
+
40
+ cdef public api void setElementClassLookupFunction(
41
+ _element_class_lookup_function function, state):
42
+ _setElementClassLookupFunction(function, state)
43
+
44
+ cdef public api object lookupDefaultElementClass(state, doc, xmlNode* c_node):
45
+ return _lookupDefaultElementClass(state, doc, c_node)
46
+
47
+ cdef public api object lookupNamespaceElementClass(state, doc, xmlNode* c_node):
48
+ return _find_nselement_class(state, doc, c_node)
49
+
50
+ cdef public api object callLookupFallback(FallbackElementClassLookup lookup,
51
+ _Document doc, xmlNode* c_node):
52
+ return _callLookupFallback(lookup, doc, c_node)
53
+
54
+ cdef public api int tagMatches(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name):
55
+ if c_node is NULL:
56
+ return -1
57
+ return _tagMatches(c_node, c_href, c_name)
58
+
59
+ cdef public api _Document documentOrRaise(object input):
60
+ return _documentOrRaise(input)
61
+
62
+ cdef public api _Element rootNodeOrRaise(object input):
63
+ return _rootNodeOrRaise(input)
64
+
65
+ cdef public api bint hasText(xmlNode* c_node):
66
+ return _hasText(c_node)
67
+
68
+ cdef public api bint hasTail(xmlNode* c_node):
69
+ return _hasTail(c_node)
70
+
71
+ cdef public api unicode textOf(xmlNode* c_node):
72
+ if c_node is NULL:
73
+ return None
74
+ return _collectText(c_node.children)
75
+
76
+ cdef public api unicode tailOf(xmlNode* c_node):
77
+ if c_node is NULL:
78
+ return None
79
+ return _collectText(c_node.next)
80
+
81
+ cdef public api int setNodeText(xmlNode* c_node, text) except -1:
82
+ if c_node is NULL:
83
+ raise ValueError
84
+ return _setNodeText(c_node, text)
85
+
86
+ cdef public api int setTailText(xmlNode* c_node, text) except -1:
87
+ if c_node is NULL:
88
+ raise ValueError
89
+ return _setTailText(c_node, text)
90
+
91
+ cdef public api unicode attributeValue(xmlNode* c_element, xmlAttr* c_attrib_node):
92
+ return _attributeValue(c_element, c_attrib_node)
93
+
94
+ cdef public api unicode attributeValueFromNsName(xmlNode* c_element,
95
+ const_xmlChar* ns, const_xmlChar* name):
96
+ return _attributeValueFromNsName(c_element, ns, name)
97
+
98
+ cdef public api object getAttributeValue(_Element element, key, default):
99
+ _assertValidNode(element)
100
+ return _getAttributeValue(element, key, default)
101
+
102
+ cdef public api object iterattributes(_Element element, int keysvalues):
103
+ _assertValidNode(element)
104
+ return _attributeIteratorFactory(element, keysvalues)
105
+
106
+ cdef public api list collectAttributes(xmlNode* c_element, int keysvalues):
107
+ return _collectAttributes(c_element, keysvalues)
108
+
109
+ cdef public api int setAttributeValue(_Element element, key, value) except -1:
110
+ _assertValidNode(element)
111
+ return _setAttributeValue(element, key, value)
112
+
113
+ cdef public api int delAttribute(_Element element, key) except -1:
114
+ _assertValidNode(element)
115
+ return _delAttribute(element, key)
116
+
117
+ cdef public api int delAttributeFromNsName(tree.xmlNode* c_element,
118
+ const_xmlChar* c_href, const_xmlChar* c_name):
119
+ return _delAttributeFromNsName(c_element, c_href, c_name)
120
+
121
+ cdef public api bint hasChild(xmlNode* c_node):
122
+ return _hasChild(c_node)
123
+
124
+ cdef public api xmlNode* findChild(xmlNode* c_node, Py_ssize_t index):
125
+ return _findChild(c_node, index)
126
+
127
+ cdef public api xmlNode* findChildForwards(xmlNode* c_node, Py_ssize_t index):
128
+ return _findChildForwards(c_node, index)
129
+
130
+ cdef public api xmlNode* findChildBackwards(xmlNode* c_node, Py_ssize_t index):
131
+ return _findChildBackwards(c_node, index)
132
+
133
+ cdef public api xmlNode* nextElement(xmlNode* c_node):
134
+ return _nextElement(c_node)
135
+
136
+ cdef public api xmlNode* previousElement(xmlNode* c_node):
137
+ return _previousElement(c_node)
138
+
139
+ cdef public api void appendChild(_Element parent, _Element child):
140
+ # deprecated, use appendChildToElement() instead!
141
+ _appendChild(parent, child)
142
+
143
+ cdef public api int appendChildToElement(_Element parent, _Element child) except -1:
144
+ return _appendChild(parent, child)
145
+
146
+ cdef public api unicode pyunicode(const_xmlChar* s):
147
+ if s is NULL:
148
+ raise TypeError
149
+ return funicode(s)
150
+
151
+ cdef public api bytes utf8(object s):
152
+ return _utf8(s)
153
+
154
+ cdef public api tuple getNsTag(object tag):
155
+ return _getNsTag(tag)
156
+
157
+ cdef public api tuple getNsTagWithEmptyNs(object tag):
158
+ return _getNsTagWithEmptyNs(tag)
159
+
160
+ cdef public api unicode namespacedName(xmlNode* c_node):
161
+ return _namespacedName(c_node)
162
+
163
+ cdef public api unicode namespacedNameFromNsName(const_xmlChar* href, const_xmlChar* name):
164
+ return _namespacedNameFromNsName(href, name)
165
+
166
+ cdef public api void iteratorStoreNext(_ElementIterator iterator, _Element node):
167
+ # deprecated!
168
+ iterator._storeNext(node)
169
+
170
+ cdef public api void initTagMatch(_ElementTagMatcher matcher, tag):
171
+ # deprecated!
172
+ matcher._initTagMatch(tag)
173
+
174
+ cdef public api tree.xmlNs* findOrBuildNodeNsPrefix(
175
+ _Document doc, xmlNode* c_node, const_xmlChar* href, const_xmlChar* prefix) except NULL:
176
+ if doc is None:
177
+ raise TypeError
178
+ return doc._findOrBuildNodeNs(c_node, href, prefix, 0)