lxml 5.2.0__cp310-cp310-win32.whl → 5.2.2__cp310-cp310-win32.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 (89) hide show
  1. lxml/ElementInclude.py +244 -244
  2. lxml/__init__.py +22 -22
  3. lxml/_elementpath.cp310-win32.pyd +0 -0
  4. lxml/_elementpath.py +341 -341
  5. lxml/apihelpers.pxi +1793 -1793
  6. lxml/builder.cp310-win32.pyd +0 -0
  7. lxml/builder.py +232 -232
  8. lxml/classlookup.pxi +580 -580
  9. lxml/cleanup.pxi +215 -215
  10. lxml/cssselect.py +101 -101
  11. lxml/debug.pxi +90 -90
  12. lxml/docloader.pxi +178 -178
  13. lxml/doctestcompare.py +488 -488
  14. lxml/dtd.pxi +478 -478
  15. lxml/etree.cp310-win32.pyd +0 -0
  16. lxml/etree.h +6 -6
  17. lxml/etree.pyx +3732 -3711
  18. lxml/extensions.pxi +833 -833
  19. lxml/html/ElementSoup.py +10 -10
  20. lxml/html/__init__.py +1923 -1923
  21. lxml/html/_diffcommand.py +86 -86
  22. lxml/html/_html5builder.py +100 -100
  23. lxml/html/_setmixin.py +56 -56
  24. lxml/html/builder.py +133 -133
  25. lxml/html/clean.py +21 -21
  26. lxml/html/defs.py +135 -135
  27. lxml/html/diff.cp310-win32.pyd +0 -0
  28. lxml/html/diff.py +878 -878
  29. lxml/html/formfill.py +299 -299
  30. lxml/html/html5parser.py +260 -260
  31. lxml/html/soupparser.py +314 -314
  32. lxml/html/usedoctest.py +13 -13
  33. lxml/includes/c14n.pxd +25 -25
  34. lxml/includes/config.pxd +3 -3
  35. lxml/includes/dtdvalid.pxd +18 -18
  36. lxml/includes/etree_defs.h +379 -379
  37. lxml/includes/etreepublic.pxd +237 -237
  38. lxml/includes/htmlparser.pxd +56 -56
  39. lxml/includes/lxml-version.h +1 -1
  40. lxml/includes/relaxng.pxd +64 -64
  41. lxml/includes/schematron.pxd +34 -34
  42. lxml/includes/tree.pxd +494 -494
  43. lxml/includes/uri.pxd +5 -5
  44. lxml/includes/xinclude.pxd +22 -22
  45. lxml/includes/xmlerror.pxd +852 -852
  46. lxml/includes/xmlparser.pxd +265 -265
  47. lxml/includes/xmlschema.pxd +35 -35
  48. lxml/includes/xpath.pxd +136 -136
  49. lxml/includes/xslt.pxd +190 -190
  50. lxml/isoschematron/__init__.py +348 -348
  51. lxml/isoschematron/resources/rng/iso-schematron.rng +709 -709
  52. lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl +75 -75
  53. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +312 -312
  54. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl +1159 -1159
  55. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl +54 -54
  56. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1796 -1796
  57. lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -588
  58. lxml/iterparse.pxi +438 -438
  59. lxml/lxml.etree.h +6 -6
  60. lxml/nsclasses.pxi +281 -281
  61. lxml/objectify.cp310-win32.pyd +0 -0
  62. lxml/objectify.pyx +2145 -2145
  63. lxml/objectpath.pxi +332 -332
  64. lxml/parser.pxi +1994 -1994
  65. lxml/parsertarget.pxi +180 -180
  66. lxml/proxy.pxi +619 -619
  67. lxml/public-api.pxi +178 -178
  68. lxml/pyclasslookup.py +3 -3
  69. lxml/readonlytree.pxi +565 -565
  70. lxml/relaxng.pxi +165 -165
  71. lxml/sax.cp310-win32.pyd +0 -0
  72. lxml/sax.py +275 -275
  73. lxml/saxparser.pxi +875 -875
  74. lxml/schematron.pxi +168 -168
  75. lxml/serializer.pxi +1871 -1871
  76. lxml/usedoctest.py +13 -13
  77. lxml/xinclude.pxi +67 -67
  78. lxml/xmlerror.pxi +1654 -1654
  79. lxml/xmlid.pxi +179 -179
  80. lxml/xmlschema.pxi +215 -215
  81. lxml/xpath.pxi +487 -487
  82. lxml/xslt.pxi +950 -950
  83. lxml/xsltext.pxi +242 -242
  84. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/LICENSE.txt +29 -29
  85. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/LICENSES.txt +29 -29
  86. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/METADATA +9 -17
  87. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/RECORD +89 -89
  88. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/WHEEL +0 -0
  89. {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/top_level.txt +0 -0
@@ -1,379 +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 */
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 */