lxml 6.0.0__cp312-cp312-macosx_10_13_universal2.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.
Files changed (174) hide show
  1. lxml/ElementInclude.py +244 -0
  2. lxml/__init__.py +22 -0
  3. lxml/_elementpath.cpython-312-darwin.so +0 -0
  4. lxml/_elementpath.py +343 -0
  5. lxml/apihelpers.pxi +1801 -0
  6. lxml/builder.cpython-312-darwin.so +0 -0
  7. lxml/builder.py +243 -0
  8. lxml/classlookup.pxi +580 -0
  9. lxml/cleanup.pxi +215 -0
  10. lxml/cssselect.py +101 -0
  11. lxml/debug.pxi +36 -0
  12. lxml/docloader.pxi +178 -0
  13. lxml/doctestcompare.py +488 -0
  14. lxml/dtd.pxi +479 -0
  15. lxml/etree.cpython-312-darwin.so +0 -0
  16. lxml/etree.h +244 -0
  17. lxml/etree.pyx +3853 -0
  18. lxml/etree_api.h +204 -0
  19. lxml/extensions.pxi +830 -0
  20. lxml/html/ElementSoup.py +10 -0
  21. lxml/html/__init__.py +1927 -0
  22. lxml/html/_diffcommand.py +86 -0
  23. lxml/html/_difflib.cpython-312-darwin.so +0 -0
  24. lxml/html/_difflib.py +2106 -0
  25. lxml/html/_html5builder.py +100 -0
  26. lxml/html/_setmixin.py +56 -0
  27. lxml/html/builder.py +173 -0
  28. lxml/html/clean.py +21 -0
  29. lxml/html/defs.py +135 -0
  30. lxml/html/diff.cpython-312-darwin.so +0 -0
  31. lxml/html/diff.py +972 -0
  32. lxml/html/formfill.py +299 -0
  33. lxml/html/html5parser.py +260 -0
  34. lxml/html/soupparser.py +314 -0
  35. lxml/html/usedoctest.py +13 -0
  36. lxml/includes/__init__.pxd +0 -0
  37. lxml/includes/__init__.py +0 -0
  38. lxml/includes/c14n.pxd +25 -0
  39. lxml/includes/config.pxd +3 -0
  40. lxml/includes/dtdvalid.pxd +18 -0
  41. lxml/includes/etree_defs.h +379 -0
  42. lxml/includes/etreepublic.pxd +237 -0
  43. lxml/includes/extlibs/__init__.py +0 -0
  44. lxml/includes/extlibs/libcharset.h +45 -0
  45. lxml/includes/extlibs/localcharset.h +137 -0
  46. lxml/includes/extlibs/zconf.h +543 -0
  47. lxml/includes/extlibs/zlib.h +1938 -0
  48. lxml/includes/htmlparser.pxd +56 -0
  49. lxml/includes/libexslt/__init__.py +0 -0
  50. lxml/includes/libexslt/exslt.h +108 -0
  51. lxml/includes/libexslt/exsltconfig.h +70 -0
  52. lxml/includes/libexslt/exsltexports.h +63 -0
  53. lxml/includes/libxml/HTMLparser.h +339 -0
  54. lxml/includes/libxml/HTMLtree.h +148 -0
  55. lxml/includes/libxml/SAX.h +18 -0
  56. lxml/includes/libxml/SAX2.h +170 -0
  57. lxml/includes/libxml/__init__.py +0 -0
  58. lxml/includes/libxml/c14n.h +115 -0
  59. lxml/includes/libxml/catalog.h +183 -0
  60. lxml/includes/libxml/chvalid.h +230 -0
  61. lxml/includes/libxml/debugXML.h +79 -0
  62. lxml/includes/libxml/dict.h +82 -0
  63. lxml/includes/libxml/encoding.h +307 -0
  64. lxml/includes/libxml/entities.h +147 -0
  65. lxml/includes/libxml/globals.h +25 -0
  66. lxml/includes/libxml/hash.h +251 -0
  67. lxml/includes/libxml/list.h +137 -0
  68. lxml/includes/libxml/nanoftp.h +16 -0
  69. lxml/includes/libxml/nanohttp.h +98 -0
  70. lxml/includes/libxml/parser.h +1633 -0
  71. lxml/includes/libxml/parserInternals.h +591 -0
  72. lxml/includes/libxml/relaxng.h +224 -0
  73. lxml/includes/libxml/schemasInternals.h +959 -0
  74. lxml/includes/libxml/schematron.h +143 -0
  75. lxml/includes/libxml/threads.h +81 -0
  76. lxml/includes/libxml/tree.h +1326 -0
  77. lxml/includes/libxml/uri.h +106 -0
  78. lxml/includes/libxml/valid.h +485 -0
  79. lxml/includes/libxml/xinclude.h +141 -0
  80. lxml/includes/libxml/xlink.h +193 -0
  81. lxml/includes/libxml/xmlIO.h +419 -0
  82. lxml/includes/libxml/xmlautomata.h +163 -0
  83. lxml/includes/libxml/xmlerror.h +962 -0
  84. lxml/includes/libxml/xmlexports.h +96 -0
  85. lxml/includes/libxml/xmlmemory.h +188 -0
  86. lxml/includes/libxml/xmlmodule.h +61 -0
  87. lxml/includes/libxml/xmlreader.h +444 -0
  88. lxml/includes/libxml/xmlregexp.h +116 -0
  89. lxml/includes/libxml/xmlsave.h +111 -0
  90. lxml/includes/libxml/xmlschemas.h +254 -0
  91. lxml/includes/libxml/xmlschemastypes.h +152 -0
  92. lxml/includes/libxml/xmlstring.h +140 -0
  93. lxml/includes/libxml/xmlunicode.h +15 -0
  94. lxml/includes/libxml/xmlversion.h +332 -0
  95. lxml/includes/libxml/xmlwriter.h +489 -0
  96. lxml/includes/libxml/xpath.h +569 -0
  97. lxml/includes/libxml/xpathInternals.h +639 -0
  98. lxml/includes/libxml/xpointer.h +48 -0
  99. lxml/includes/libxslt/__init__.py +0 -0
  100. lxml/includes/libxslt/attributes.h +39 -0
  101. lxml/includes/libxslt/documents.h +93 -0
  102. lxml/includes/libxslt/extensions.h +262 -0
  103. lxml/includes/libxslt/extra.h +72 -0
  104. lxml/includes/libxslt/functions.h +78 -0
  105. lxml/includes/libxslt/imports.h +75 -0
  106. lxml/includes/libxslt/keys.h +53 -0
  107. lxml/includes/libxslt/namespaces.h +68 -0
  108. lxml/includes/libxslt/numbersInternals.h +73 -0
  109. lxml/includes/libxslt/pattern.h +84 -0
  110. lxml/includes/libxslt/preproc.h +43 -0
  111. lxml/includes/libxslt/security.h +104 -0
  112. lxml/includes/libxslt/templates.h +77 -0
  113. lxml/includes/libxslt/transform.h +207 -0
  114. lxml/includes/libxslt/variables.h +118 -0
  115. lxml/includes/libxslt/xslt.h +110 -0
  116. lxml/includes/libxslt/xsltInternals.h +1995 -0
  117. lxml/includes/libxslt/xsltconfig.h +146 -0
  118. lxml/includes/libxslt/xsltexports.h +64 -0
  119. lxml/includes/libxslt/xsltlocale.h +44 -0
  120. lxml/includes/libxslt/xsltutils.h +343 -0
  121. lxml/includes/lxml-version.h +3 -0
  122. lxml/includes/relaxng.pxd +64 -0
  123. lxml/includes/schematron.pxd +34 -0
  124. lxml/includes/tree.pxd +492 -0
  125. lxml/includes/uri.pxd +5 -0
  126. lxml/includes/xinclude.pxd +22 -0
  127. lxml/includes/xmlerror.pxd +852 -0
  128. lxml/includes/xmlparser.pxd +303 -0
  129. lxml/includes/xmlschema.pxd +35 -0
  130. lxml/includes/xpath.pxd +136 -0
  131. lxml/includes/xslt.pxd +190 -0
  132. lxml/isoschematron/__init__.py +348 -0
  133. lxml/isoschematron/resources/rng/iso-schematron.rng +709 -0
  134. lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl +75 -0
  135. lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl +77 -0
  136. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +313 -0
  137. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl +1160 -0
  138. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
  139. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1796 -0
  140. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -0
  141. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt +84 -0
  142. lxml/iterparse.pxi +438 -0
  143. lxml/lxml.etree.h +244 -0
  144. lxml/lxml.etree_api.h +204 -0
  145. lxml/nsclasses.pxi +281 -0
  146. lxml/objectify.cpython-312-darwin.so +0 -0
  147. lxml/objectify.pyx +2149 -0
  148. lxml/objectpath.pxi +332 -0
  149. lxml/parser.pxi +2059 -0
  150. lxml/parsertarget.pxi +180 -0
  151. lxml/proxy.pxi +619 -0
  152. lxml/public-api.pxi +178 -0
  153. lxml/pyclasslookup.py +3 -0
  154. lxml/readonlytree.pxi +565 -0
  155. lxml/relaxng.pxi +165 -0
  156. lxml/sax.cpython-312-darwin.so +0 -0
  157. lxml/sax.py +286 -0
  158. lxml/saxparser.pxi +875 -0
  159. lxml/schematron.pxi +173 -0
  160. lxml/serializer.pxi +1849 -0
  161. lxml/usedoctest.py +13 -0
  162. lxml/xinclude.pxi +67 -0
  163. lxml/xmlerror.pxi +1654 -0
  164. lxml/xmlid.pxi +179 -0
  165. lxml/xmlschema.pxi +215 -0
  166. lxml/xpath.pxi +487 -0
  167. lxml/xslt.pxi +957 -0
  168. lxml/xsltext.pxi +242 -0
  169. lxml-6.0.0.dist-info/METADATA +163 -0
  170. lxml-6.0.0.dist-info/RECORD +174 -0
  171. lxml-6.0.0.dist-info/WHEEL +6 -0
  172. lxml-6.0.0.dist-info/licenses/LICENSE.txt +31 -0
  173. lxml-6.0.0.dist-info/licenses/LICENSES.txt +29 -0
  174. lxml-6.0.0.dist-info/top_level.txt +1 -0
@@ -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
+ #if LIBXML_VERSION < 21500
163
+ # define xmlCtxtIsStopped(p_ctxt) ((p_ctxt)->disableSAX != 0)
164
+ #endif
165
+
166
+ /* libexslt 1.1.25+ support EXSLT functions in XPath */
167
+ #if LIBXSLT_VERSION < 10125
168
+ #define exsltDateXpathCtxtRegister(ctxt, prefix)
169
+ #define exsltSetsXpathCtxtRegister(ctxt, prefix)
170
+ #define exsltMathXpathCtxtRegister(ctxt, prefix)
171
+ #define exsltStrXpathCtxtRegister(ctxt, prefix)
172
+ #endif
173
+
174
+ #define LXML_GET_XSLT_ENCODING(result_var, style) XSLT_GET_IMPORT_PTR(result_var, style, encoding)
175
+
176
+ /* work around MSDEV 6.0 */
177
+ #if (_MSC_VER == 1200) && (WINVER < 0x0500)
178
+ long _ftol( double ); //defined by VC6 C libs
179
+ long _ftol2( double dblSource ) { return _ftol( dblSource ); }
180
+ #endif
181
+
182
+ #ifdef __GNUC__
183
+ /* Test for GCC > 2.95 */
184
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
185
+ #define unlikely_condition(x) __builtin_expect((x), 0)
186
+ #else /* __GNUC__ > 2 ... */
187
+ #define unlikely_condition(x) (x)
188
+ #endif /* __GNUC__ > 2 ... */
189
+ #else /* __GNUC__ */
190
+ #define unlikely_condition(x) (x)
191
+ #endif /* __GNUC__ */
192
+
193
+ #ifndef Py_TYPE
194
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
195
+ #endif
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 */
@@ -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)
File without changes
@@ -0,0 +1,45 @@
1
+ /* Copyright (C) 2003 Free Software Foundation, Inc.
2
+ This file is part of the GNU CHARSET Library.
3
+
4
+ The GNU CHARSET Library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public License as
6
+ published by the Free Software Foundation; either version 2 of the
7
+ License, or (at your option) any later version.
8
+
9
+ The GNU CHARSET Library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with the GNU CHARSET Library; see the file COPYING.LIB. If not,
16
+ see <https://www.gnu.org/licenses/>. */
17
+
18
+ #ifndef _LIBCHARSET_H
19
+ #define _LIBCHARSET_H
20
+
21
+ #include <localcharset.h>
22
+
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+
29
+ /* Support for relocatable packages. */
30
+
31
+ /* Sets the original and the current installation prefix of the package.
32
+ Relocation simply replaces a pathname starting with the original prefix
33
+ by the corresponding pathname with the current prefix instead. Both
34
+ prefixes should be directory names without trailing slash (i.e. use ""
35
+ instead of "/"). */
36
+ extern void libcharset_set_relocation_prefix (const char *orig_prefix,
37
+ const char *curr_prefix);
38
+
39
+
40
+ #ifdef __cplusplus
41
+ }
42
+ #endif
43
+
44
+
45
+ #endif /* _LIBCHARSET_H */