1 | #include <Python.h>
|
---|
2 | #include <libxml/tree.h>
|
---|
3 | #include <libxml/parser.h>
|
---|
4 | #include <libxml/parserInternals.h>
|
---|
5 | #include <libxml/catalog.h>
|
---|
6 | #include <libxml/threads.h>
|
---|
7 | #include <libxml/nanoftp.h>
|
---|
8 | #include <libxml/nanohttp.h>
|
---|
9 | #include <libxml/uri.h>
|
---|
10 | #include <libxml/xpath.h>
|
---|
11 | #include <libxml/xpathInternals.h>
|
---|
12 | #include <libxml/debugXML.h>
|
---|
13 | #include <libxml/HTMLparser.h>
|
---|
14 | #include <libxml/HTMLtree.h>
|
---|
15 | #include <libxml/xinclude.h>
|
---|
16 | #include <libxml/xpointer.h>
|
---|
17 | #include <libxml/xmlunicode.h>
|
---|
18 | #include <libxml/xmlregexp.h>
|
---|
19 | #include <libxml/xmlautomata.h>
|
---|
20 | #include <libxml/xmlreader.h>
|
---|
21 | #include <libxml/globals.h>
|
---|
22 | #include <libxml/xmlsave.h>
|
---|
23 | #ifdef LIBXML_SCHEMAS_ENABLED
|
---|
24 | #include <libxml/relaxng.h>
|
---|
25 | #include <libxml/xmlschemas.h>
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * for older versions of Python, we don't use PyBytes, but keep PyString
|
---|
30 | * and don't use Capsule but CObjects
|
---|
31 | */
|
---|
32 | #if PY_VERSION_HEX < 0x02070000
|
---|
33 | #ifndef PyBytes_Check
|
---|
34 | #define PyBytes_Check PyString_Check
|
---|
35 | #define PyBytes_Size PyString_Size
|
---|
36 | #define PyBytes_AsString PyString_AsString
|
---|
37 | #define PyBytes_AS_STRING PyString_AS_STRING
|
---|
38 | #define PyBytes_GET_SIZE PyString_GET_SIZE
|
---|
39 | #endif
|
---|
40 | #ifndef PyCapsule_New
|
---|
41 | #define PyCapsule_New PyCObject_FromVoidPtrAndDesc
|
---|
42 | #define PyCapsule_CheckExact PyCObject_Check
|
---|
43 | #define PyCapsule_GetPointer(o, n) PyCObject_GetDesc((o))
|
---|
44 | #endif
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * ATTRIBUTE_UNUSED:
|
---|
49 | *
|
---|
50 | * Macro used to signal to GCC unused function parameters
|
---|
51 | * Repeated here since the definition is not available when
|
---|
52 | * compiled outside the libxml2 build tree.
|
---|
53 | */
|
---|
54 | #ifdef __GNUC__
|
---|
55 | #ifdef ATTRIBUTE_UNUSED
|
---|
56 | #undef ATTRIBUTE_UNUSED
|
---|
57 | #endif
|
---|
58 | #ifndef ATTRIBUTE_UNUSED
|
---|
59 | #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
---|
60 | #endif /* ATTRIBUTE_UNUSED */
|
---|
61 | #else
|
---|
62 | #define ATTRIBUTE_UNUSED
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Macros to ignore deprecation warnings
|
---|
67 | */
|
---|
68 | #if defined(__LCC__)
|
---|
69 | #define XML_IGNORE_DEPRECATION_WARNINGS \
|
---|
70 | _Pragma("diag_suppress 1215")
|
---|
71 | #elif defined(__clang__) || \
|
---|
72 | (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
|
---|
73 | #define XML_IGNORE_DEPRECATION_WARNINGS \
|
---|
74 | _Pragma("GCC diagnostic push") \
|
---|
75 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
---|
76 | #elif defined (_MSC_VER) && (_MSC_VER >= 1400)
|
---|
77 | #define XML_IGNORE_DEPRECATION_WARNINGS \
|
---|
78 | __pragma(warning(push)) \
|
---|
79 | __pragma(warning(disable : 4996))
|
---|
80 | #else
|
---|
81 | #define XML_IGNORE_DEPRECATION_WARNINGS
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | #define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
|
---|
85 | (((PyxmlNode_Object *)(v))->obj))
|
---|
86 |
|
---|
87 | typedef struct {
|
---|
88 | PyObject_HEAD
|
---|
89 | xmlNodePtr obj;
|
---|
90 | } PyxmlNode_Object;
|
---|
91 |
|
---|
92 | #ifdef LIBXML_XPATH_ENABLED
|
---|
93 | #define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
|
---|
94 | (((PyxmlXPathContext_Object *)(v))->obj))
|
---|
95 |
|
---|
96 | typedef struct {
|
---|
97 | PyObject_HEAD
|
---|
98 | xmlXPathContextPtr obj;
|
---|
99 | } PyxmlXPathContext_Object;
|
---|
100 |
|
---|
101 | #define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
|
---|
102 | (((PyxmlXPathParserContext_Object *)(v))->obj))
|
---|
103 |
|
---|
104 | typedef struct {
|
---|
105 | PyObject_HEAD
|
---|
106 | xmlXPathParserContextPtr obj;
|
---|
107 | } PyxmlXPathParserContext_Object;
|
---|
108 | #endif /* LIBXML_XPATH_ENABLED */
|
---|
109 |
|
---|
110 | #define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
111 | (((PyparserCtxt_Object *)(v))->obj))
|
---|
112 |
|
---|
113 | typedef struct {
|
---|
114 | PyObject_HEAD
|
---|
115 | xmlParserCtxtPtr obj;
|
---|
116 | } PyparserCtxt_Object;
|
---|
117 |
|
---|
118 | #define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
119 | (((PyValidCtxt_Object *)(v))->obj))
|
---|
120 |
|
---|
121 | typedef struct {
|
---|
122 | PyObject_HEAD
|
---|
123 | xmlValidCtxtPtr obj;
|
---|
124 | } PyValidCtxt_Object;
|
---|
125 |
|
---|
126 | #ifdef LIBXML_CATALOG_ENABLED
|
---|
127 | #define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
|
---|
128 | (((Pycatalog_Object *)(v))->obj))
|
---|
129 |
|
---|
130 | typedef struct {
|
---|
131 | PyObject_HEAD
|
---|
132 | xmlCatalogPtr obj;
|
---|
133 | } Pycatalog_Object;
|
---|
134 | #endif /* LIBXML_CATALOG_ENABLED */
|
---|
135 |
|
---|
136 | #ifdef LIBXML_REGEXP_ENABLED
|
---|
137 | #define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
|
---|
138 | (((PyxmlReg_Object *)(v))->obj))
|
---|
139 |
|
---|
140 | typedef struct {
|
---|
141 | PyObject_HEAD
|
---|
142 | xmlRegexpPtr obj;
|
---|
143 | } PyxmlReg_Object;
|
---|
144 | #endif /* LIBXML_REGEXP_ENABLED */
|
---|
145 |
|
---|
146 | #ifdef LIBXML_READER_ENABLED
|
---|
147 | #define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
|
---|
148 | (((PyxmlTextReader_Object *)(v))->obj))
|
---|
149 |
|
---|
150 | typedef struct {
|
---|
151 | PyObject_HEAD
|
---|
152 | xmlTextReaderPtr obj;
|
---|
153 | } PyxmlTextReader_Object;
|
---|
154 |
|
---|
155 | #define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
|
---|
156 | (((PyxmlTextReaderLocator_Object *)(v))->obj))
|
---|
157 |
|
---|
158 | typedef struct {
|
---|
159 | PyObject_HEAD
|
---|
160 | xmlTextReaderLocatorPtr obj;
|
---|
161 | } PyxmlTextReaderLocator_Object;
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | #define PyURI_Get(v) (((v) == Py_None) ? NULL : \
|
---|
165 | (((PyURI_Object *)(v))->obj))
|
---|
166 |
|
---|
167 | typedef struct {
|
---|
168 | PyObject_HEAD
|
---|
169 | xmlErrorPtr obj;
|
---|
170 | } PyError_Object;
|
---|
171 |
|
---|
172 | #define PyError_Get(v) (((v) == Py_None) ? NULL : \
|
---|
173 | (((PyError_Object *)(v))->obj))
|
---|
174 |
|
---|
175 | typedef struct {
|
---|
176 | PyObject_HEAD
|
---|
177 | xmlOutputBufferPtr obj;
|
---|
178 | } PyoutputBuffer_Object;
|
---|
179 |
|
---|
180 | #define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
---|
181 | (((PyoutputBuffer_Object *)(v))->obj))
|
---|
182 |
|
---|
183 | typedef struct {
|
---|
184 | PyObject_HEAD
|
---|
185 | xmlParserInputBufferPtr obj;
|
---|
186 | } PyinputBuffer_Object;
|
---|
187 |
|
---|
188 | #define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
|
---|
189 | (((PyinputBuffer_Object *)(v))->obj))
|
---|
190 |
|
---|
191 | typedef struct {
|
---|
192 | PyObject_HEAD
|
---|
193 | xmlURIPtr obj;
|
---|
194 | } PyURI_Object;
|
---|
195 |
|
---|
196 | /* FILE * have their own internal representation */
|
---|
197 | #if PY_MAJOR_VERSION >= 3
|
---|
198 | FILE *libxml_PyFileGet(PyObject *f);
|
---|
199 | void libxml_PyFileRelease(FILE *f);
|
---|
200 | #define PyFile_Get(v) (((v) == Py_None) ? NULL : libxml_PyFileGet(v))
|
---|
201 | #define PyFile_Release(f) libxml_PyFileRelease(f)
|
---|
202 | #else
|
---|
203 | #define PyFile_Get(v) (((v) == Py_None) ? NULL : \
|
---|
204 | (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
|
---|
205 | #define PyFile_Release(f)
|
---|
206 | #endif
|
---|
207 |
|
---|
208 | #ifdef LIBXML_SCHEMAS_ENABLED
|
---|
209 | typedef struct {
|
---|
210 | PyObject_HEAD
|
---|
211 | xmlRelaxNGPtr obj;
|
---|
212 | } PyrelaxNgSchema_Object;
|
---|
213 |
|
---|
214 | #define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
|
---|
215 | (((PyrelaxNgSchema_Object *)(v))->obj))
|
---|
216 |
|
---|
217 | typedef struct {
|
---|
218 | PyObject_HEAD
|
---|
219 | xmlRelaxNGParserCtxtPtr obj;
|
---|
220 | } PyrelaxNgParserCtxt_Object;
|
---|
221 |
|
---|
222 | #define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
223 | (((PyrelaxNgParserCtxt_Object *)(v))->obj))
|
---|
224 |
|
---|
225 | typedef struct {
|
---|
226 | PyObject_HEAD
|
---|
227 | xmlRelaxNGValidCtxtPtr obj;
|
---|
228 | } PyrelaxNgValidCtxt_Object;
|
---|
229 |
|
---|
230 | #define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
231 | (((PyrelaxNgValidCtxt_Object *)(v))->obj))
|
---|
232 |
|
---|
233 | typedef struct {
|
---|
234 | PyObject_HEAD
|
---|
235 | xmlSchemaPtr obj;
|
---|
236 | } PySchema_Object;
|
---|
237 |
|
---|
238 | #define PySchema_Get(v) (((v) == Py_None) ? NULL : \
|
---|
239 | (((PySchema_Object *)(v))->obj))
|
---|
240 |
|
---|
241 | typedef struct {
|
---|
242 | PyObject_HEAD
|
---|
243 | xmlSchemaParserCtxtPtr obj;
|
---|
244 | } PySchemaParserCtxt_Object;
|
---|
245 |
|
---|
246 | #define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
247 | (((PySchemaParserCtxt_Object *)(v))->obj))
|
---|
248 |
|
---|
249 | typedef struct {
|
---|
250 | PyObject_HEAD
|
---|
251 | xmlSchemaValidCtxtPtr obj;
|
---|
252 | } PySchemaValidCtxt_Object;
|
---|
253 |
|
---|
254 | #define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
|
---|
255 | (((PySchemaValidCtxt_Object *)(v))->obj))
|
---|
256 |
|
---|
257 | #endif /* LIBXML_SCHEMAS_ENABLED */
|
---|
258 |
|
---|
259 | PyObject * libxml_intWrap(int val);
|
---|
260 | PyObject * libxml_longWrap(long val);
|
---|
261 | PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
|
---|
262 | PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
|
---|
263 | PyObject * libxml_charPtrWrap(char *str);
|
---|
264 | PyObject * libxml_constcharPtrWrap(const char *str);
|
---|
265 | PyObject * libxml_charPtrConstWrap(const char *str);
|
---|
266 | PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
|
---|
267 | PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
|
---|
268 | PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
|
---|
269 | PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
|
---|
270 | PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
|
---|
271 | PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
|
---|
272 | PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
|
---|
273 | PyObject * libxml_doubleWrap(double val);
|
---|
274 | PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
|
---|
275 | #ifdef LIBXML_XPATH_ENABLED
|
---|
276 | PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
|
---|
277 | PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
|
---|
278 | PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
|
---|
279 | xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
|
---|
280 | #endif
|
---|
281 | PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
|
---|
282 | #ifdef LIBXML_CATALOG_ENABLED
|
---|
283 | PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
|
---|
284 | #endif
|
---|
285 | PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
|
---|
286 | PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
|
---|
287 | PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
|
---|
288 | #ifdef LIBXML_REGEXP_ENABLED
|
---|
289 | PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
|
---|
290 | #endif /* LIBXML_REGEXP_ENABLED */
|
---|
291 | #ifdef LIBXML_READER_ENABLED
|
---|
292 | PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
|
---|
293 | PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
|
---|
294 | #endif
|
---|
295 |
|
---|
296 | #ifdef LIBXML_SCHEMAS_ENABLED
|
---|
297 | PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
|
---|
298 | PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
|
---|
299 | PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
|
---|
300 | PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
|
---|
301 | PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
|
---|
302 | PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
|
---|
303 | #endif /* LIBXML_SCHEMAS_ENABLED */
|
---|
304 | PyObject * libxml_xmlErrorPtrWrap(const xmlError *error);
|
---|
305 | PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
|
---|
306 | PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
|
---|
307 | PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
|
---|
308 | PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
|
---|
309 |
|
---|
310 | int libxml_deprecationWarning(const char *func);
|
---|