blob: 53a061807e9ddcde35244a5add014f0b7e89a80d [file] [log] [blame]
Daniel Veillard3ce52572002-02-03 15:08:05 +00001#include <Python.h>
Daniel Veillardd2897fd2002-01-30 16:37:32 +00002#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>
Daniel Veillard96fe0952002-01-30 20:52:23 +000013#include <libxml/HTMLparser.h>
14#include <libxml/HTMLtree.h>
15#include <libxml/xinclude.h>
Daniel Veillard1971ee22002-01-31 20:29:19 +000016#include <libxml/xpointer.h>
Daniel Veillardbd9afb52002-09-25 22:25:35 +000017#include <libxml/xmlunicode.h>
18#include <libxml/xmlregexp.h>
19#include <libxml/xmlautomata.h>
Daniel Veillard0eb38c72002-12-14 23:00:35 +000020#include <libxml/xmlreader.h>
Daniel Veillard259f0df2004-08-18 09:13:18 +000021#ifdef LIBXML_SCHEMAS_ENABLED
Daniel Veillard71531f32003-02-05 13:19:53 +000022#include <libxml/relaxng.h>
Daniel Veillard259f0df2004-08-18 09:13:18 +000023#include <libxml/xmlschemas.h>
24#endif
Daniel Veillard0eb38c72002-12-14 23:00:35 +000025
Daniel Veillardbf4a8f02013-04-02 10:27:57 +080026/*
27 * for older versions of Python, we don't use PyBytes, but keep PyString
28 * and don't use Capsule but CObjects
29 */
30#if PY_VERSION_HEX < 0x02070000
31#ifndef PyBytes_Check
32#define PyBytes_Check PyString_Check
33#define PyBytes_Size PyString_Size
34#define PyBytes_AsString PyString_AsString
35#define PyBytes_AS_STRING PyString_AS_STRING
36#define PyBytes_GET_SIZE PyString_GET_SIZE
Petr Sumbera722923b2013-05-03 22:25:38 +080037#endif
38#ifndef PyCapsule_New
Daniel Veillardbf4a8f02013-04-02 10:27:57 +080039#define PyCapsule_New PyCObject_FromVoidPtrAndDesc
40#define PyCapsule_CheckExact PyCObject_Check
41#define PyCapsule_GetPointer(o, n) PyCObject_GetDesc((o))
Daniel Veillardbf4a8f02013-04-02 10:27:57 +080042#endif
43#endif
44
Daniel Veillard0eb38c72002-12-14 23:00:35 +000045/**
46 * ATTRIBUTE_UNUSED:
47 *
48 * Macro used to signal to GCC unused function parameters
49 * Repeated here since the definition is not available when
50 * compiled outside the libxml2 build tree.
51 */
52#ifdef __GNUC__
53#ifdef ATTRIBUTE_UNUSED
54#undef ATTRIBUTE_UNUSED
55#endif
Daniel Veillard0eb38c72002-12-14 23:00:35 +000056#ifndef ATTRIBUTE_UNUSED
Daniel Veillard0e9dafa2002-12-27 11:58:25 +000057#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
58#endif /* ATTRIBUTE_UNUSED */
Daniel Veillard0eb38c72002-12-14 23:00:35 +000059#else
60#define ATTRIBUTE_UNUSED
61#endif
Daniel Veillard96fe0952002-01-30 20:52:23 +000062
Daniel Veillard36eea2d2002-02-04 00:17:01 +000063#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
64 (((PyxmlNode_Object *)(v))->obj))
Daniel Veillard96fe0952002-01-30 20:52:23 +000065
66typedef struct {
67 PyObject_HEAD
68 xmlNodePtr obj;
69} PyxmlNode_Object;
Daniel Veillardd2897fd2002-01-30 16:37:32 +000070
Daniel Veillard36eea2d2002-02-04 00:17:01 +000071#define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
72 (((PyxmlXPathContext_Object *)(v))->obj))
73
Daniel Veillard1971ee22002-01-31 20:29:19 +000074typedef struct {
75 PyObject_HEAD
76 xmlXPathContextPtr obj;
77} PyxmlXPathContext_Object;
78
Daniel Veillard7db38712002-02-07 16:39:11 +000079#define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
80 (((PyxmlXPathParserContext_Object *)(v))->obj))
81
82typedef struct {
83 PyObject_HEAD
84 xmlXPathParserContextPtr obj;
85} PyxmlXPathParserContext_Object;
86
Daniel Veillard36eea2d2002-02-04 00:17:01 +000087#define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
88 (((PyparserCtxt_Object *)(v))->obj))
89
Daniel Veillard3ce52572002-02-03 15:08:05 +000090typedef struct {
91 PyObject_HEAD
92 xmlParserCtxtPtr obj;
93} PyparserCtxt_Object;
94
Daniel Veillard850ce9b2004-11-10 11:55:47 +000095#define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
96 (((PyValidCtxt_Object *)(v))->obj))
97
98typedef struct {
99 PyObject_HEAD
100 xmlValidCtxtPtr obj;
101} PyValidCtxt_Object;
102
Daniel Veillard7db38712002-02-07 16:39:11 +0000103#define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
104 (((Pycatalog_Object *)(v))->obj))
105
106typedef struct {
107 PyObject_HEAD
108 xmlCatalogPtr obj;
109} Pycatalog_Object;
110
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000111#ifdef LIBXML_REGEXP_ENABLED
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000112#define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
113 (((PyxmlReg_Object *)(v))->obj))
114
115typedef struct {
116 PyObject_HEAD
117 xmlRegexpPtr obj;
118} PyxmlReg_Object;
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000119#endif /* LIBXML_REGEXP_ENABLED */
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000120
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000121#ifdef LIBXML_READER_ENABLED
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000122#define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
123 (((PyxmlTextReader_Object *)(v))->obj))
124
125typedef struct {
126 PyObject_HEAD
127 xmlTextReaderPtr obj;
128} PyxmlTextReader_Object;
129
Daniel Veillard417be3a2003-01-20 21:26:34 +0000130#define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
131 (((PyxmlTextReaderLocator_Object *)(v))->obj))
132
133typedef struct {
134 PyObject_HEAD
135 xmlTextReaderLocatorPtr obj;
136} PyxmlTextReaderLocator_Object;
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000137#endif
Daniel Veillard417be3a2003-01-20 21:26:34 +0000138
Daniel Veillard6361da02002-02-23 10:10:33 +0000139#define PyURI_Get(v) (((v) == Py_None) ? NULL : \
140 (((PyURI_Object *)(v))->obj))
141
142typedef struct {
143 PyObject_HEAD
Daniel Veillard46da4642004-01-06 22:54:57 +0000144 xmlErrorPtr obj;
145} PyError_Object;
146
147#define PyError_Get(v) (((v) == Py_None) ? NULL : \
148 (((PyError_Object *)(v))->obj))
149
150typedef struct {
151 PyObject_HEAD
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000152 xmlOutputBufferPtr obj;
153} PyoutputBuffer_Object;
154
155#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillard6cbd6c02003-12-04 12:31:49 +0000156 (((PyoutputBuffer_Object *)(v))->obj))
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000157
158typedef struct {
159 PyObject_HEAD
160 xmlParserInputBufferPtr obj;
161} PyinputBuffer_Object;
162
163#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillard6cbd6c02003-12-04 12:31:49 +0000164 (((PyinputBuffer_Object *)(v))->obj))
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000165
166typedef struct {
167 PyObject_HEAD
Daniel Veillard6361da02002-02-23 10:10:33 +0000168 xmlURIPtr obj;
169} PyURI_Object;
170
171/* FILE * have their own internal representation */
Daniel Veillard3798c4a2013-03-29 13:46:24 +0800172#if PY_MAJOR_VERSION >= 3
173FILE *libxml_PyFileGet(PyObject *f);
174void libxml_PyFileRelease(FILE *f);
175#define PyFile_Get(v) (((v) == Py_None) ? NULL : libxml_PyFileGet(v))
176#define PyFile_Release(f) libxml_PyFileRelease(f)
177#else
Daniel Veillard7db38712002-02-07 16:39:11 +0000178#define PyFile_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000179 (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
Daniel Veillard3798c4a2013-03-29 13:46:24 +0800180#define PyFile_Release(f)
181#endif
Daniel Veillard7db38712002-02-07 16:39:11 +0000182
Daniel Veillard591b4be2003-02-09 23:33:36 +0000183#ifdef LIBXML_SCHEMAS_ENABLED
184typedef struct {
185 PyObject_HEAD
186 xmlRelaxNGPtr obj;
187} PyrelaxNgSchema_Object;
188
189#define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
190 (((PyrelaxNgSchema_Object *)(v))->obj))
191
192typedef struct {
193 PyObject_HEAD
194 xmlRelaxNGParserCtxtPtr obj;
195} PyrelaxNgParserCtxt_Object;
196
197#define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
198 (((PyrelaxNgParserCtxt_Object *)(v))->obj))
199
200typedef struct {
201 PyObject_HEAD
202 xmlRelaxNGValidCtxtPtr obj;
203} PyrelaxNgValidCtxt_Object;
204
205#define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
206 (((PyrelaxNgValidCtxt_Object *)(v))->obj))
207
Daniel Veillard259f0df2004-08-18 09:13:18 +0000208typedef struct {
209 PyObject_HEAD
210 xmlSchemaPtr obj;
211} PySchema_Object;
212
213#define PySchema_Get(v) (((v) == Py_None) ? NULL : \
214 (((PySchema_Object *)(v))->obj))
215
216typedef struct {
217 PyObject_HEAD
218 xmlSchemaParserCtxtPtr obj;
219} PySchemaParserCtxt_Object;
220
221#define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
222 (((PySchemaParserCtxt_Object *)(v))->obj))
223
224typedef struct {
225 PyObject_HEAD
226 xmlSchemaValidCtxtPtr obj;
227} PySchemaValidCtxt_Object;
228
229#define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
230 (((PySchemaValidCtxt_Object *)(v))->obj))
231
Daniel Veillard591b4be2003-02-09 23:33:36 +0000232#endif /* LIBXML_SCHEMAS_ENABLED */
Daniel Veillard6361da02002-02-23 10:10:33 +0000233
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000234PyObject * libxml_intWrap(int val);
Daniel Veillard4e1b26c2002-02-03 20:13:06 +0000235PyObject * libxml_longWrap(long val);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000236PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
237PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
238PyObject * libxml_charPtrWrap(char *str);
239PyObject * libxml_constcharPtrWrap(const char *str);
Daniel Veillardc575b992002-02-08 13:28:40 +0000240PyObject * libxml_charPtrConstWrap(const char *str);
241PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000242PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
243PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
244PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000245PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
246PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
247PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
Daniel Veillard96fe0952002-01-30 20:52:23 +0000248PyObject * libxml_doubleWrap(double val);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000249PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
Daniel Veillard3ce52572002-02-03 15:08:05 +0000250PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
Daniel Veillard7db38712002-02-07 16:39:11 +0000251PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000252PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
Daniel Veillard850ce9b2004-11-10 11:55:47 +0000253PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
Daniel Veillard7db38712002-02-07 16:39:11 +0000254PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
Daniel Veillard6361da02002-02-23 10:10:33 +0000255PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000256PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
257PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000258#ifdef LIBXML_REGEXP_ENABLED
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000259PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000260#endif /* LIBXML_REGEXP_ENABLED */
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000261#ifdef LIBXML_READER_ENABLED
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000262PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
Daniel Veillard417be3a2003-01-20 21:26:34 +0000263PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000264#endif
Daniel Veillard96fe0952002-01-30 20:52:23 +0000265
Daniel Veillard3ce52572002-02-03 15:08:05 +0000266xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
Daniel Veillard591b4be2003-02-09 23:33:36 +0000267#ifdef LIBXML_SCHEMAS_ENABLED
268PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
269PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
270PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
Daniel Veillard259f0df2004-08-18 09:13:18 +0000271PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
272PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
273PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
Daniel Veillard591b4be2003-02-09 23:33:36 +0000274#endif /* LIBXML_SCHEMAS_ENABLED */
Daniel Veillard46da4642004-01-06 22:54:57 +0000275PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error);
Daniel Veillard6ebf3c42004-08-22 13:11:39 +0000276PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
Alexey Neyman48da90b2013-02-25 15:54:25 +0800277PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
278PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
Daniel Veillard3798c4a2013-03-29 13:46:24 +0800279PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);