Home | History | Annotate | Download | only in python
      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 #ifdef LIBXML_SCHEMAS_ENABLED
     22 #include <libxml/relaxng.h>
     23 #include <libxml/xmlschemas.h>
     24 #endif
     25 
     26 /*
     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
     37 #endif
     38 #ifndef PyCapsule_New
     39 #define PyCapsule_New PyCObject_FromVoidPtrAndDesc
     40 #define PyCapsule_CheckExact PyCObject_Check
     41 #define PyCapsule_GetPointer(o, n) PyCObject_GetDesc((o))
     42 #endif
     43 #endif
     44 
     45 /**
     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
     56 #ifndef ATTRIBUTE_UNUSED
     57 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
     58 #endif /* ATTRIBUTE_UNUSED */
     59 #else
     60 #define ATTRIBUTE_UNUSED
     61 #endif
     62 
     63 #define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
     64 	(((PyxmlNode_Object *)(v))->obj))
     65 
     66 typedef struct {
     67     PyObject_HEAD
     68     xmlNodePtr obj;
     69 } PyxmlNode_Object;
     70 
     71 #define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
     72 	(((PyxmlXPathContext_Object *)(v))->obj))
     73 
     74 typedef struct {
     75     PyObject_HEAD
     76     xmlXPathContextPtr obj;
     77 } PyxmlXPathContext_Object;
     78 
     79 #define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
     80 	(((PyxmlXPathParserContext_Object *)(v))->obj))
     81 
     82 typedef struct {
     83     PyObject_HEAD
     84     xmlXPathParserContextPtr obj;
     85 } PyxmlXPathParserContext_Object;
     86 
     87 #define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
     88         (((PyparserCtxt_Object *)(v))->obj))
     89 
     90 typedef struct {
     91     PyObject_HEAD
     92     xmlParserCtxtPtr obj;
     93 } PyparserCtxt_Object;
     94 
     95 #define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
     96 	(((PyValidCtxt_Object *)(v))->obj))
     97 
     98 typedef struct {
     99 	PyObject_HEAD
    100 	xmlValidCtxtPtr obj;
    101 } PyValidCtxt_Object;
    102 
    103 #define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
    104         (((Pycatalog_Object *)(v))->obj))
    105 
    106 typedef struct {
    107     PyObject_HEAD
    108     xmlCatalogPtr obj;
    109 } Pycatalog_Object;
    110 
    111 #ifdef LIBXML_REGEXP_ENABLED
    112 #define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
    113         (((PyxmlReg_Object *)(v))->obj))
    114 
    115 typedef struct {
    116     PyObject_HEAD
    117     xmlRegexpPtr obj;
    118 } PyxmlReg_Object;
    119 #endif /* LIBXML_REGEXP_ENABLED */
    120 
    121 #ifdef LIBXML_READER_ENABLED
    122 #define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
    123         (((PyxmlTextReader_Object *)(v))->obj))
    124 
    125 typedef struct {
    126     PyObject_HEAD
    127     xmlTextReaderPtr obj;
    128 } PyxmlTextReader_Object;
    129 
    130 #define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
    131         (((PyxmlTextReaderLocator_Object *)(v))->obj))
    132 
    133 typedef struct {
    134     PyObject_HEAD
    135     xmlTextReaderLocatorPtr obj;
    136 } PyxmlTextReaderLocator_Object;
    137 #endif
    138 
    139 #define PyURI_Get(v) (((v) == Py_None) ? NULL : \
    140 	(((PyURI_Object *)(v))->obj))
    141 
    142 typedef struct {
    143     PyObject_HEAD
    144     xmlErrorPtr obj;
    145 } PyError_Object;
    146 
    147 #define PyError_Get(v) (((v) == Py_None) ? NULL : \
    148 	(((PyError_Object *)(v))->obj))
    149 
    150 typedef struct {
    151     PyObject_HEAD
    152     xmlOutputBufferPtr obj;
    153 } PyoutputBuffer_Object;
    154 
    155 #define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
    156 	(((PyoutputBuffer_Object *)(v))->obj))
    157 
    158 typedef struct {
    159     PyObject_HEAD
    160     xmlParserInputBufferPtr obj;
    161 } PyinputBuffer_Object;
    162 
    163 #define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
    164 	(((PyinputBuffer_Object *)(v))->obj))
    165 
    166 typedef struct {
    167     PyObject_HEAD
    168     xmlURIPtr obj;
    169 } PyURI_Object;
    170 
    171 /* FILE * have their own internal representation */
    172 #if PY_MAJOR_VERSION >= 3
    173 FILE *libxml_PyFileGet(PyObject *f);
    174 void 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
    178 #define PyFile_Get(v) (((v) == Py_None) ? NULL : \
    179 	(PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
    180 #define PyFile_Release(f)
    181 #endif
    182 
    183 #ifdef LIBXML_SCHEMAS_ENABLED
    184 typedef 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 
    192 typedef 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 
    200 typedef 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 
    208 typedef 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 
    216 typedef 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 
    224 typedef 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 
    232 #endif /* LIBXML_SCHEMAS_ENABLED */
    233 
    234 PyObject * libxml_intWrap(int val);
    235 PyObject * libxml_longWrap(long val);
    236 PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
    237 PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
    238 PyObject * libxml_charPtrWrap(char *str);
    239 PyObject * libxml_constcharPtrWrap(const char *str);
    240 PyObject * libxml_charPtrConstWrap(const char *str);
    241 PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
    242 PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
    243 PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
    244 PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
    245 PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
    246 PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
    247 PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
    248 PyObject * libxml_doubleWrap(double val);
    249 PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
    250 PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
    251 PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
    252 PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
    253 PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
    254 PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
    255 PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
    256 PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
    257 PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
    258 #ifdef LIBXML_REGEXP_ENABLED
    259 PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
    260 #endif /* LIBXML_REGEXP_ENABLED */
    261 #ifdef LIBXML_READER_ENABLED
    262 PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
    263 PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
    264 #endif
    265 
    266 xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
    267 #ifdef LIBXML_SCHEMAS_ENABLED
    268 PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
    269 PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
    270 PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
    271 PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
    272 PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
    273 PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
    274 #endif /* LIBXML_SCHEMAS_ENABLED */
    275 PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error);
    276 PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
    277 PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
    278 PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
    279 PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
    280