lxml 6.0.0__cp39-cp39-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lxml/ElementInclude.py +244 -0
- lxml/__init__.py +22 -0
- lxml/_elementpath.cp39-win_arm64.pyd +0 -0
- lxml/_elementpath.py +343 -0
- lxml/apihelpers.pxi +1801 -0
- lxml/builder.cp39-win_arm64.pyd +0 -0
- lxml/builder.py +243 -0
- lxml/classlookup.pxi +580 -0
- lxml/cleanup.pxi +215 -0
- lxml/cssselect.py +101 -0
- lxml/debug.pxi +36 -0
- lxml/docloader.pxi +178 -0
- lxml/doctestcompare.py +488 -0
- lxml/dtd.pxi +479 -0
- lxml/etree.cp39-win_arm64.pyd +0 -0
- lxml/etree.h +244 -0
- lxml/etree.pyx +3853 -0
- lxml/etree_api.h +204 -0
- lxml/extensions.pxi +830 -0
- lxml/html/ElementSoup.py +10 -0
- lxml/html/__init__.py +1927 -0
- lxml/html/_diffcommand.py +86 -0
- lxml/html/_difflib.cp39-win_arm64.pyd +0 -0
- lxml/html/_difflib.py +2106 -0
- lxml/html/_html5builder.py +100 -0
- lxml/html/_setmixin.py +56 -0
- lxml/html/builder.py +173 -0
- lxml/html/clean.py +21 -0
- lxml/html/defs.py +135 -0
- lxml/html/diff.cp39-win_arm64.pyd +0 -0
- lxml/html/diff.py +972 -0
- lxml/html/formfill.py +299 -0
- lxml/html/html5parser.py +260 -0
- lxml/html/soupparser.py +314 -0
- lxml/html/usedoctest.py +13 -0
- lxml/includes/__init__.pxd +0 -0
- lxml/includes/__init__.py +0 -0
- lxml/includes/c14n.pxd +25 -0
- lxml/includes/config.pxd +3 -0
- lxml/includes/dtdvalid.pxd +18 -0
- lxml/includes/etree_defs.h +379 -0
- lxml/includes/etreepublic.pxd +237 -0
- lxml/includes/extlibs/__init__.py +0 -0
- lxml/includes/extlibs/zconf.h +543 -0
- lxml/includes/extlibs/zlib.h +1938 -0
- lxml/includes/htmlparser.pxd +56 -0
- lxml/includes/libexslt/__init__.py +0 -0
- lxml/includes/libexslt/exslt.h +108 -0
- lxml/includes/libexslt/exsltconfig.h +70 -0
- lxml/includes/libexslt/exsltexports.h +63 -0
- lxml/includes/libexslt/libexslt.h +29 -0
- lxml/includes/libxml/HTMLparser.h +320 -0
- lxml/includes/libxml/HTMLtree.h +147 -0
- lxml/includes/libxml/SAX.h +204 -0
- lxml/includes/libxml/SAX2.h +173 -0
- lxml/includes/libxml/__init__.py +0 -0
- lxml/includes/libxml/c14n.h +128 -0
- lxml/includes/libxml/catalog.h +182 -0
- lxml/includes/libxml/chvalid.h +230 -0
- lxml/includes/libxml/debugXML.h +217 -0
- lxml/includes/libxml/dict.h +81 -0
- lxml/includes/libxml/encoding.h +233 -0
- lxml/includes/libxml/entities.h +151 -0
- lxml/includes/libxml/globals.h +529 -0
- lxml/includes/libxml/hash.h +236 -0
- lxml/includes/libxml/list.h +137 -0
- lxml/includes/libxml/nanoftp.h +186 -0
- lxml/includes/libxml/nanohttp.h +81 -0
- lxml/includes/libxml/parser.h +1265 -0
- lxml/includes/libxml/parserInternals.h +662 -0
- lxml/includes/libxml/pattern.h +100 -0
- lxml/includes/libxml/relaxng.h +218 -0
- lxml/includes/libxml/schemasInternals.h +958 -0
- lxml/includes/libxml/schematron.h +142 -0
- lxml/includes/libxml/threads.h +94 -0
- lxml/includes/libxml/tree.h +1314 -0
- lxml/includes/libxml/uri.h +94 -0
- lxml/includes/libxml/valid.h +448 -0
- lxml/includes/libxml/xinclude.h +129 -0
- lxml/includes/libxml/xlink.h +189 -0
- lxml/includes/libxml/xmlIO.h +369 -0
- lxml/includes/libxml/xmlautomata.h +146 -0
- lxml/includes/libxml/xmlerror.h +919 -0
- lxml/includes/libxml/xmlexports.h +50 -0
- lxml/includes/libxml/xmlmemory.h +228 -0
- lxml/includes/libxml/xmlmodule.h +57 -0
- lxml/includes/libxml/xmlreader.h +428 -0
- lxml/includes/libxml/xmlregexp.h +222 -0
- lxml/includes/libxml/xmlsave.h +88 -0
- lxml/includes/libxml/xmlschemas.h +246 -0
- lxml/includes/libxml/xmlschemastypes.h +152 -0
- lxml/includes/libxml/xmlstring.h +140 -0
- lxml/includes/libxml/xmlunicode.h +202 -0
- lxml/includes/libxml/xmlversion.h +526 -0
- lxml/includes/libxml/xmlwriter.h +488 -0
- lxml/includes/libxml/xpath.h +575 -0
- lxml/includes/libxml/xpathInternals.h +632 -0
- lxml/includes/libxml/xpointer.h +137 -0
- lxml/includes/libxslt/__init__.py +0 -0
- lxml/includes/libxslt/attributes.h +39 -0
- lxml/includes/libxslt/documents.h +93 -0
- lxml/includes/libxslt/extensions.h +262 -0
- lxml/includes/libxslt/extra.h +72 -0
- lxml/includes/libxslt/functions.h +78 -0
- lxml/includes/libxslt/imports.h +75 -0
- lxml/includes/libxslt/keys.h +53 -0
- lxml/includes/libxslt/libxslt.h +36 -0
- lxml/includes/libxslt/namespaces.h +68 -0
- lxml/includes/libxslt/numbersInternals.h +73 -0
- lxml/includes/libxslt/preproc.h +43 -0
- lxml/includes/libxslt/security.h +104 -0
- lxml/includes/libxslt/templates.h +77 -0
- lxml/includes/libxslt/transform.h +207 -0
- lxml/includes/libxslt/trio.h +216 -0
- lxml/includes/libxslt/triodef.h +220 -0
- lxml/includes/libxslt/variables.h +118 -0
- lxml/includes/libxslt/win32config.h +51 -0
- lxml/includes/libxslt/xslt.h +110 -0
- lxml/includes/libxslt/xsltInternals.h +1992 -0
- lxml/includes/libxslt/xsltconfig.h +179 -0
- lxml/includes/libxslt/xsltexports.h +64 -0
- lxml/includes/libxslt/xsltlocale.h +44 -0
- lxml/includes/libxslt/xsltutils.h +343 -0
- lxml/includes/lxml-version.h +3 -0
- lxml/includes/relaxng.pxd +64 -0
- lxml/includes/schematron.pxd +34 -0
- lxml/includes/tree.pxd +492 -0
- lxml/includes/uri.pxd +5 -0
- lxml/includes/xinclude.pxd +22 -0
- lxml/includes/xmlerror.pxd +852 -0
- lxml/includes/xmlparser.pxd +303 -0
- lxml/includes/xmlschema.pxd +35 -0
- lxml/includes/xpath.pxd +136 -0
- lxml/includes/xslt.pxd +190 -0
- lxml/isoschematron/__init__.py +348 -0
- lxml/isoschematron/resources/rng/iso-schematron.rng +709 -0
- lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl +75 -0
- lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl +77 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +313 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl +1160 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1796 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt +84 -0
- lxml/iterparse.pxi +438 -0
- lxml/lxml.etree.h +244 -0
- lxml/lxml.etree_api.h +204 -0
- lxml/nsclasses.pxi +281 -0
- lxml/objectify.cp39-win_arm64.pyd +0 -0
- lxml/objectify.pyx +2149 -0
- lxml/objectpath.pxi +332 -0
- lxml/parser.pxi +2059 -0
- lxml/parsertarget.pxi +180 -0
- lxml/proxy.pxi +619 -0
- lxml/public-api.pxi +178 -0
- lxml/pyclasslookup.py +3 -0
- lxml/readonlytree.pxi +565 -0
- lxml/relaxng.pxi +165 -0
- lxml/sax.cp39-win_arm64.pyd +0 -0
- lxml/sax.py +286 -0
- lxml/saxparser.pxi +875 -0
- lxml/schematron.pxi +173 -0
- lxml/serializer.pxi +1849 -0
- lxml/usedoctest.py +13 -0
- lxml/xinclude.pxi +67 -0
- lxml/xmlerror.pxi +1654 -0
- lxml/xmlid.pxi +179 -0
- lxml/xmlschema.pxi +215 -0
- lxml/xpath.pxi +487 -0
- lxml/xslt.pxi +957 -0
- lxml/xsltext.pxi +242 -0
- lxml-6.0.0.dist-info/METADATA +163 -0
- lxml-6.0.0.dist-info/RECORD +177 -0
- lxml-6.0.0.dist-info/WHEEL +5 -0
- lxml-6.0.0.dist-info/licenses/LICENSE.txt +31 -0
- lxml-6.0.0.dist-info/licenses/LICENSES.txt +29 -0
- lxml-6.0.0.dist-info/top_level.txt +1 -0
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
|