blob: eaa5e96998a618cef938c2d915d8945b477f1b70 [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
26/**
27 * ATTRIBUTE_UNUSED:
28 *
29 * Macro used to signal to GCC unused function parameters
30 * Repeated here since the definition is not available when
31 * compiled outside the libxml2 build tree.
32 */
33#ifdef __GNUC__
34#ifdef ATTRIBUTE_UNUSED
35#undef ATTRIBUTE_UNUSED
36#endif
Daniel Veillard0eb38c72002-12-14 23:00:35 +000037#ifndef ATTRIBUTE_UNUSED
Daniel Veillard0e9dafa2002-12-27 11:58:25 +000038#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
39#endif /* ATTRIBUTE_UNUSED */
Daniel Veillard0eb38c72002-12-14 23:00:35 +000040#else
41#define ATTRIBUTE_UNUSED
42#endif
Daniel Veillard96fe0952002-01-30 20:52:23 +000043
Daniel Veillard36eea2d2002-02-04 00:17:01 +000044#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
45 (((PyxmlNode_Object *)(v))->obj))
Daniel Veillard96fe0952002-01-30 20:52:23 +000046
47typedef struct {
48 PyObject_HEAD
49 xmlNodePtr obj;
50} PyxmlNode_Object;
Daniel Veillardd2897fd2002-01-30 16:37:32 +000051
Daniel Veillard36eea2d2002-02-04 00:17:01 +000052#define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
53 (((PyxmlXPathContext_Object *)(v))->obj))
54
Daniel Veillard1971ee22002-01-31 20:29:19 +000055typedef struct {
56 PyObject_HEAD
57 xmlXPathContextPtr obj;
58} PyxmlXPathContext_Object;
59
Daniel Veillard7db38712002-02-07 16:39:11 +000060#define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
61 (((PyxmlXPathParserContext_Object *)(v))->obj))
62
63typedef struct {
64 PyObject_HEAD
65 xmlXPathParserContextPtr obj;
66} PyxmlXPathParserContext_Object;
67
Daniel Veillard36eea2d2002-02-04 00:17:01 +000068#define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
69 (((PyparserCtxt_Object *)(v))->obj))
70
Daniel Veillard3ce52572002-02-03 15:08:05 +000071typedef struct {
72 PyObject_HEAD
73 xmlParserCtxtPtr obj;
74} PyparserCtxt_Object;
75
Daniel Veillard850ce9b2004-11-10 11:55:47 +000076#define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
77 (((PyValidCtxt_Object *)(v))->obj))
78
79typedef struct {
80 PyObject_HEAD
81 xmlValidCtxtPtr obj;
82} PyValidCtxt_Object;
83
Daniel Veillard7db38712002-02-07 16:39:11 +000084#define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
85 (((Pycatalog_Object *)(v))->obj))
86
87typedef struct {
88 PyObject_HEAD
89 xmlCatalogPtr obj;
90} Pycatalog_Object;
91
Daniel Veillard0e298ad2003-02-04 16:14:33 +000092#ifdef LIBXML_REGEXP_ENABLED
Daniel Veillardbd9afb52002-09-25 22:25:35 +000093#define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
94 (((PyxmlReg_Object *)(v))->obj))
95
96typedef struct {
97 PyObject_HEAD
98 xmlRegexpPtr obj;
99} PyxmlReg_Object;
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000100#endif /* LIBXML_REGEXP_ENABLED */
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000101
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000102#ifdef LIBXML_READER_ENABLED
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000103#define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
104 (((PyxmlTextReader_Object *)(v))->obj))
105
106typedef struct {
107 PyObject_HEAD
108 xmlTextReaderPtr obj;
109} PyxmlTextReader_Object;
110
Daniel Veillard417be3a2003-01-20 21:26:34 +0000111#define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
112 (((PyxmlTextReaderLocator_Object *)(v))->obj))
113
114typedef struct {
115 PyObject_HEAD
116 xmlTextReaderLocatorPtr obj;
117} PyxmlTextReaderLocator_Object;
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000118#endif
Daniel Veillard417be3a2003-01-20 21:26:34 +0000119
Daniel Veillard6361da02002-02-23 10:10:33 +0000120#define PyURI_Get(v) (((v) == Py_None) ? NULL : \
121 (((PyURI_Object *)(v))->obj))
122
123typedef struct {
124 PyObject_HEAD
Daniel Veillard46da4642004-01-06 22:54:57 +0000125 xmlErrorPtr obj;
126} PyError_Object;
127
128#define PyError_Get(v) (((v) == Py_None) ? NULL : \
129 (((PyError_Object *)(v))->obj))
130
131typedef struct {
132 PyObject_HEAD
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000133 xmlOutputBufferPtr obj;
134} PyoutputBuffer_Object;
135
136#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillard6cbd6c02003-12-04 12:31:49 +0000137 (((PyoutputBuffer_Object *)(v))->obj))
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000138
139typedef struct {
140 PyObject_HEAD
141 xmlParserInputBufferPtr obj;
142} PyinputBuffer_Object;
143
144#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillard6cbd6c02003-12-04 12:31:49 +0000145 (((PyinputBuffer_Object *)(v))->obj))
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000146
147typedef struct {
148 PyObject_HEAD
Daniel Veillard6361da02002-02-23 10:10:33 +0000149 xmlURIPtr obj;
150} PyURI_Object;
151
152/* FILE * have their own internal representation */
Daniel Veillard7db38712002-02-07 16:39:11 +0000153#define PyFile_Get(v) (((v) == Py_None) ? NULL : \
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000154 (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
Daniel Veillard7db38712002-02-07 16:39:11 +0000155
Daniel Veillard591b4be2003-02-09 23:33:36 +0000156#ifdef LIBXML_SCHEMAS_ENABLED
157typedef struct {
158 PyObject_HEAD
159 xmlRelaxNGPtr obj;
160} PyrelaxNgSchema_Object;
161
162#define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
163 (((PyrelaxNgSchema_Object *)(v))->obj))
164
165typedef struct {
166 PyObject_HEAD
167 xmlRelaxNGParserCtxtPtr obj;
168} PyrelaxNgParserCtxt_Object;
169
170#define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
171 (((PyrelaxNgParserCtxt_Object *)(v))->obj))
172
173typedef struct {
174 PyObject_HEAD
175 xmlRelaxNGValidCtxtPtr obj;
176} PyrelaxNgValidCtxt_Object;
177
178#define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
179 (((PyrelaxNgValidCtxt_Object *)(v))->obj))
180
Daniel Veillard259f0df2004-08-18 09:13:18 +0000181typedef struct {
182 PyObject_HEAD
183 xmlSchemaPtr obj;
184} PySchema_Object;
185
186#define PySchema_Get(v) (((v) == Py_None) ? NULL : \
187 (((PySchema_Object *)(v))->obj))
188
189typedef struct {
190 PyObject_HEAD
191 xmlSchemaParserCtxtPtr obj;
192} PySchemaParserCtxt_Object;
193
194#define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
195 (((PySchemaParserCtxt_Object *)(v))->obj))
196
197typedef struct {
198 PyObject_HEAD
199 xmlSchemaValidCtxtPtr obj;
200} PySchemaValidCtxt_Object;
201
202#define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
203 (((PySchemaValidCtxt_Object *)(v))->obj))
204
Daniel Veillard591b4be2003-02-09 23:33:36 +0000205#endif /* LIBXML_SCHEMAS_ENABLED */
Daniel Veillard6361da02002-02-23 10:10:33 +0000206
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000207PyObject * libxml_intWrap(int val);
Daniel Veillard4e1b26c2002-02-03 20:13:06 +0000208PyObject * libxml_longWrap(long val);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000209PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
210PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
211PyObject * libxml_charPtrWrap(char *str);
212PyObject * libxml_constcharPtrWrap(const char *str);
Daniel Veillardc575b992002-02-08 13:28:40 +0000213PyObject * libxml_charPtrConstWrap(const char *str);
214PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000215PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
216PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
217PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000218PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
219PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
220PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
Daniel Veillard96fe0952002-01-30 20:52:23 +0000221PyObject * libxml_doubleWrap(double val);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000222PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
Daniel Veillard3ce52572002-02-03 15:08:05 +0000223PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
Daniel Veillard7db38712002-02-07 16:39:11 +0000224PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
Daniel Veillard1971ee22002-01-31 20:29:19 +0000225PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
Daniel Veillard850ce9b2004-11-10 11:55:47 +0000226PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
Daniel Veillard7db38712002-02-07 16:39:11 +0000227PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
Daniel Veillard6361da02002-02-23 10:10:33 +0000228PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
Daniel Veillardc6d4a932002-09-12 15:00:57 +0000229PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
230PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000231#ifdef LIBXML_REGEXP_ENABLED
Daniel Veillardbd9afb52002-09-25 22:25:35 +0000232PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
Daniel Veillard0e298ad2003-02-04 16:14:33 +0000233#endif /* LIBXML_REGEXP_ENABLED */
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000234#ifdef LIBXML_READER_ENABLED
Daniel Veillard0eb38c72002-12-14 23:00:35 +0000235PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
Daniel Veillard417be3a2003-01-20 21:26:34 +0000236PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
Daniel Veillard438ebbd2008-05-12 12:58:46 +0000237#endif
Daniel Veillard96fe0952002-01-30 20:52:23 +0000238
Daniel Veillard3ce52572002-02-03 15:08:05 +0000239xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
Daniel Veillard591b4be2003-02-09 23:33:36 +0000240#ifdef LIBXML_SCHEMAS_ENABLED
241PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
242PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
243PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
Daniel Veillard259f0df2004-08-18 09:13:18 +0000244PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
245PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
246PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
Daniel Veillard591b4be2003-02-09 23:33:36 +0000247#endif /* LIBXML_SCHEMAS_ENABLED */
Daniel Veillard46da4642004-01-06 22:54:57 +0000248PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error);
Daniel Veillard6ebf3c42004-08-22 13:11:39 +0000249PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);