version 1.1.1.2, 2013/07/22 01:22:29
|
version 1.1.1.3, 2014/06/15 19:53:33
|
Line 28
|
Line 28
|
#include "libxml_wrap.h" |
#include "libxml_wrap.h" |
#include "libxml2-py.h" |
#include "libxml2-py.h" |
|
|
#if defined(_MSC_VER) && !defined(vsnprintf) | #if defined(WITH_TRIO) |
#define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a) | |
#elif defined(WITH_TRIO) && !defined(vsnprintf) | |
#include "trio.h" |
#include "trio.h" |
#define vsnprintf trio_vsnprintf |
#define vsnprintf trio_vsnprintf |
#endif |
#endif |
Line 43
|
Line 41
|
/* #define DEBUG_FILES */ |
/* #define DEBUG_FILES */ |
/* #define DEBUG_LOADER */ |
/* #define DEBUG_LOADER */ |
|
|
|
#if PY_MAJOR_VERSION >= 3 |
|
PyObject *PyInit_libxml2mod(void); |
|
|
|
#define PY_IMPORT_STRING_SIZE PyUnicode_FromStringAndSize |
|
#define PY_IMPORT_STRING PyUnicode_FromString |
|
#else |
void initlibxml2mod(void); |
void initlibxml2mod(void); |
|
#define PY_IMPORT_STRING_SIZE PyString_FromStringAndSize |
|
#define PY_IMPORT_STRING PyString_FromString |
|
#endif |
|
|
|
|
/** |
/** |
* TODO: |
* TODO: |
* |
* |
Line 282 xmlPythonFileReadRaw (void * context, char * buffer, i
|
Line 290 xmlPythonFileReadRaw (void * context, char * buffer, i
|
if (ret == NULL) { |
if (ret == NULL) { |
printf("xmlPythonFileReadRaw: result is NULL\n"); |
printf("xmlPythonFileReadRaw: result is NULL\n"); |
return(-1); |
return(-1); |
} else if (PyString_Check(ret)) { | } else if (PyBytes_Check(ret)) { |
lenread = PyString_Size(ret); | lenread = PyBytes_Size(ret); |
data = PyString_AsString(ret); | data = PyBytes_AsString(ret); |
if (lenread > len) | #ifdef PyUnicode_Check |
memcpy(buffer, data, len); | } else if PyUnicode_Check (ret) { |
else | #if PY_VERSION_HEX >= 0x03030000 |
memcpy(buffer, data, lenread); | size_t size; |
Py_DECREF(ret); | const char *tmp; |
| |
| /* tmp doesn't need to be deallocated */ |
| tmp = PyUnicode_AsUTF8AndSize(ret, &size); |
| |
| lenread = (int) size; |
| data = (char *) tmp; |
| #else |
| PyObject *b; |
| b = PyUnicode_AsUTF8String(ret); |
| if (b == NULL) { |
| printf("xmlPythonFileReadRaw: failed to convert to UTF-8\n"); |
| return(-1); |
| } |
| lenread = PyBytes_Size(b); |
| data = PyBytes_AsString(b); |
| Py_DECREF(b); |
| #endif |
| #endif |
} else { |
} else { |
printf("xmlPythonFileReadRaw: result is not a String\n"); |
printf("xmlPythonFileReadRaw: result is not a String\n"); |
Py_DECREF(ret); |
Py_DECREF(ret); |
|
return(-1); |
} |
} |
|
if (lenread > len) |
|
memcpy(buffer, data, len); |
|
else |
|
memcpy(buffer, data, lenread); |
|
Py_DECREF(ret); |
return(lenread); |
return(lenread); |
} |
} |
|
|
Line 323 xmlPythonFileRead (void * context, char * buffer, int
|
Line 355 xmlPythonFileRead (void * context, char * buffer, int
|
if (ret == NULL) { |
if (ret == NULL) { |
printf("xmlPythonFileRead: result is NULL\n"); |
printf("xmlPythonFileRead: result is NULL\n"); |
return(-1); |
return(-1); |
} else if (PyString_Check(ret)) { | } else if (PyBytes_Check(ret)) { |
lenread = PyString_Size(ret); | lenread = PyBytes_Size(ret); |
data = PyString_AsString(ret); | data = PyBytes_AsString(ret); |
if (lenread > len) | #ifdef PyUnicode_Check |
memcpy(buffer, data, len); | } else if PyUnicode_Check (ret) { |
else | #if PY_VERSION_HEX >= 0x03030000 |
memcpy(buffer, data, lenread); | size_t size; |
Py_DECREF(ret); | const char *tmp; |
| |
| /* tmp doesn't need to be deallocated */ |
| tmp = PyUnicode_AsUTF8AndSize(ret, &size); |
| |
| lenread = (int) size; |
| data = (char *) tmp; |
| #else |
| PyObject *b; |
| b = PyUnicode_AsUTF8String(ret); |
| if (b == NULL) { |
| printf("xmlPythonFileRead: failed to convert to UTF-8\n"); |
| return(-1); |
| } |
| lenread = PyBytes_Size(b); |
| data = PyBytes_AsString(b); |
| Py_DECREF(b); |
| #endif |
| #endif |
} else { |
} else { |
printf("xmlPythonFileRead: result is not a String\n"); |
printf("xmlPythonFileRead: result is not a String\n"); |
Py_DECREF(ret); |
Py_DECREF(ret); |
|
return(-1); |
} |
} |
|
if (lenread > len) |
|
memcpy(buffer, data, len); |
|
else |
|
memcpy(buffer, data, lenread); |
|
Py_DECREF(ret); |
return(lenread); |
return(lenread); |
} |
} |
|
|
Line 360 xmlPythonFileWrite (void * context, const char * buffe
|
Line 416 xmlPythonFileWrite (void * context, const char * buffe
|
#endif |
#endif |
file = (PyObject *) context; |
file = (PyObject *) context; |
if (file == NULL) return(-1); |
if (file == NULL) return(-1); |
string = PyString_FromStringAndSize(buffer, len); | string = PY_IMPORT_STRING_SIZE(buffer, len); |
if (string == NULL) return(-1); |
if (string == NULL) return(-1); |
if (PyObject_HasAttrString(file, (char *) "io_write")) { |
if (PyObject_HasAttrString(file, (char *) "io_write")) { |
ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", |
ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", |
Line 373 xmlPythonFileWrite (void * context, const char * buffe
|
Line 429 xmlPythonFileWrite (void * context, const char * buffe
|
if (ret == NULL) { |
if (ret == NULL) { |
printf("xmlPythonFileWrite: result is NULL\n"); |
printf("xmlPythonFileWrite: result is NULL\n"); |
return(-1); |
return(-1); |
} else if (PyInt_Check(ret)) { | } else if (PyLong_Check(ret)) { |
written = (int) PyInt_AsLong(ret); | written = (int) PyLong_AsLong(ret); |
Py_DECREF(ret); |
Py_DECREF(ret); |
} else if (ret == Py_None) { |
} else if (ret == Py_None) { |
written = len; |
written = len; |
Line 667 pythonExternalEntityLoader(const char *URL, const char
|
Line 723 pythonExternalEntityLoader(const char *URL, const char
|
Py_XDECREF(ctxtobj); |
Py_XDECREF(ctxtobj); |
#ifdef DEBUG_LOADER |
#ifdef DEBUG_LOADER |
printf("pythonExternalEntityLoader: result "); |
printf("pythonExternalEntityLoader: result "); |
PyObject_Print(ret, stderr, 0); | PyObject_Print(ret, stdout, 0); |
printf("\n"); |
printf("\n"); |
#endif |
#endif |
|
|
Line 713 libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *s
|
Line 769 libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *s
|
&loader)) |
&loader)) |
return(NULL); |
return(NULL); |
|
|
|
if (!PyCallable_Check(loader)) { |
|
PyErr_SetString(PyExc_ValueError, "entity loader is not callable"); |
|
return(NULL); |
|
} |
|
|
#ifdef DEBUG_LOADER |
#ifdef DEBUG_LOADER |
printf("libxml_xmlSetEntityLoader\n"); |
printf("libxml_xmlSetEntityLoader\n"); |
#endif |
#endif |
if (defaultExternalEntityLoader == NULL) |
if (defaultExternalEntityLoader == NULL) |
defaultExternalEntityLoader = xmlGetExternalEntityLoader(); |
defaultExternalEntityLoader = xmlGetExternalEntityLoader(); |
|
|
|
Py_XDECREF(pythonExternalEntityLoaderObjext); |
pythonExternalEntityLoaderObjext = loader; |
pythonExternalEntityLoaderObjext = loader; |
|
Py_XINCREF(pythonExternalEntityLoaderObjext); |
xmlSetExternalEntityLoader(pythonExternalEntityLoader); |
xmlSetExternalEntityLoader(pythonExternalEntityLoader); |
|
|
py_retval = PyInt_FromLong(0); | py_retval = PyLong_FromLong(0); |
return(py_retval); |
return(py_retval); |
} |
} |
|
|
|
/************************************************************************ |
|
* * |
|
* Input callback registration * |
|
* * |
|
************************************************************************/ |
|
static PyObject *pythonInputOpenCallbackObject; |
|
static int pythonInputCallbackID = -1; |
|
|
|
static int |
|
pythonInputMatchCallback(ATTRIBUTE_UNUSED const char *URI) |
|
{ |
|
/* Always return success, real decision whether URI is supported will be |
|
* made in open callback. */ |
|
return 1; |
|
} |
|
|
|
static void * |
|
pythonInputOpenCallback(const char *URI) |
|
{ |
|
PyObject *ret; |
|
|
|
ret = PyObject_CallFunction(pythonInputOpenCallbackObject, |
|
(char *)"s", URI); |
|
if (ret == Py_None) { |
|
Py_DECREF(Py_None); |
|
return NULL; |
|
} |
|
return ret; |
|
} |
|
|
|
PyObject * |
|
libxml_xmlRegisterInputCallback(ATTRIBUTE_UNUSED PyObject *self, |
|
PyObject *args) { |
|
PyObject *cb; |
|
|
|
if (!PyArg_ParseTuple(args, |
|
(const char *)"O:libxml_xmlRegisterInputCallback", &cb)) |
|
return(NULL); |
|
|
|
if (!PyCallable_Check(cb)) { |
|
PyErr_SetString(PyExc_ValueError, "input callback is not callable"); |
|
return(NULL); |
|
} |
|
|
|
/* Python module registers a single callback and manages the list of |
|
* all callbacks internally. This is necessitated by xmlInputMatchCallback |
|
* API, which does not allow for passing of data objects to discriminate |
|
* different Python methods. */ |
|
if (pythonInputCallbackID == -1) { |
|
pythonInputCallbackID = xmlRegisterInputCallbacks( |
|
pythonInputMatchCallback, pythonInputOpenCallback, |
|
xmlPythonFileReadRaw, xmlPythonFileCloseRaw); |
|
if (pythonInputCallbackID == -1) |
|
return PyErr_NoMemory(); |
|
pythonInputOpenCallbackObject = cb; |
|
Py_INCREF(pythonInputOpenCallbackObject); |
|
} |
|
|
|
Py_INCREF(Py_None); |
|
return(Py_None); |
|
} |
|
|
|
PyObject * |
|
libxml_xmlUnregisterInputCallback(ATTRIBUTE_UNUSED PyObject *self, |
|
ATTRIBUTE_UNUSED PyObject *args) { |
|
int ret; |
|
|
|
ret = xmlPopInputCallbacks(); |
|
if (pythonInputCallbackID != -1) { |
|
/* Assert that the right input callback was popped. libxml's API does not |
|
* allow removal by ID, so all that could be done is an assert. */ |
|
if (pythonInputCallbackID == ret) { |
|
pythonInputCallbackID = -1; |
|
Py_DECREF(pythonInputOpenCallbackObject); |
|
pythonInputOpenCallbackObject = NULL; |
|
} else { |
|
PyErr_SetString(PyExc_AssertionError, "popped non-python input callback"); |
|
return(NULL); |
|
} |
|
} else if (ret == -1) { |
|
/* No more callbacks to pop */ |
|
PyErr_SetString(PyExc_IndexError, "no input callbacks to pop"); |
|
return(NULL); |
|
} |
|
|
|
Py_INCREF(Py_None); |
|
return(Py_None); |
|
} |
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Handling SAX/xmllib/sgmlop callback interfaces * |
* Handling SAX/xmllib/sgmlop callback interfaces * |
Line 766 pythonStartElement(void *user_data, const xmlChar * na
|
Line 917 pythonStartElement(void *user_data, const xmlChar * na
|
} else { |
} else { |
dict = PyDict_New(); |
dict = PyDict_New(); |
for (i = 0; attrs[i] != NULL; i++) { |
for (i = 0; attrs[i] != NULL; i++) { |
attrname = PyString_FromString((char *) attrs[i]); | attrname = PY_IMPORT_STRING((char *) attrs[i]); |
i++; |
i++; |
if (attrs[i] != NULL) { |
if (attrs[i] != NULL) { |
attrvalue = PyString_FromString((char *) attrs[i]); | attrvalue = PY_IMPORT_STRING((char *) attrs[i]); |
} else { |
} else { |
Py_XINCREF(Py_None); |
Py_XINCREF(Py_None); |
attrvalue = Py_None; |
attrvalue = Py_None; |
Line 1172 pythonAttributeDecl(void *user_data,
|
Line 1323 pythonAttributeDecl(void *user_data,
|
nameList = PyList_New(count); |
nameList = PyList_New(count); |
count = 0; |
count = 0; |
for (node = tree; node != NULL; node = node->next) { |
for (node = tree; node != NULL; node = node->next) { |
newName = PyString_FromString((char *) node->name); | newName = PY_IMPORT_STRING((char *) node->name); |
PyList_SetItem(nameList, count, newName); |
PyList_SetItem(nameList, count, newName); |
Py_DECREF(newName); |
Py_DECREF(newName); |
count++; |
count++; |
Line 1367 libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject
|
Line 1518 libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject
|
PyObject * |
PyObject * |
libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
{ |
{ |
|
#ifdef LIBXML_SAX1_ENABLED |
int recover; |
int recover; |
const char *URI; |
const char *URI; |
PyObject *pyobj_SAX = NULL; |
PyObject *pyobj_SAX = NULL; |
Line 1388 libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * sel
|
Line 1540 libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * sel
|
Py_INCREF(pyobj_SAX); |
Py_INCREF(pyobj_SAX); |
/* The reference is released in pythonEndDocument() */ |
/* The reference is released in pythonEndDocument() */ |
xmlSAXUserParseFile(SAX, pyobj_SAX, URI); |
xmlSAXUserParseFile(SAX, pyobj_SAX, URI); |
|
#endif /* LIBXML_SAX1_ENABLED */ |
Py_INCREF(Py_None); |
Py_INCREF(Py_None); |
return (Py_None); |
return (Py_None); |
} |
} |
Line 2033 libxml_xmlFreeTextReader(ATTRIBUTE_UNUSED PyObject *se
|
Line 2186 libxml_xmlFreeTextReader(ATTRIBUTE_UNUSED PyObject *se
|
|
|
if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader)) |
if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader)) |
return(NULL); |
return(NULL); |
if (!PyCObject_Check(pyobj_reader)) { | if (!PyCapsule_CheckExact(pyobj_reader)) { |
Py_INCREF(Py_None); |
Py_INCREF(Py_None); |
return(Py_None); |
return(Py_None); |
} |
} |
Line 2234 libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObj
|
Line 2387 libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObj
|
return (py_retval); |
return (py_retval); |
} |
} |
|
|
|
PyObject * |
|
libxml_xmlXPathRegisterVariable(ATTRIBUTE_UNUSED PyObject * self, |
|
PyObject * args) |
|
{ |
|
PyObject *py_retval; |
|
int c_retval = 0; |
|
xmlChar *name; |
|
xmlChar *ns_uri; |
|
xmlXPathContextPtr ctx; |
|
xmlXPathObjectPtr val; |
|
PyObject *pyobj_ctx; |
|
PyObject *pyobj_value; |
|
|
|
if (!PyArg_ParseTuple |
|
(args, (char *) "OszO:xpathRegisterVariable", &pyobj_ctx, &name, |
|
&ns_uri, &pyobj_value)) |
|
return (NULL); |
|
|
|
ctx = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctx); |
|
val = libxml_xmlXPathObjectPtrConvert(pyobj_value); |
|
|
|
c_retval = xmlXPathRegisterVariableNS(ctx, name, ns_uri, val); |
|
py_retval = libxml_intWrap(c_retval); |
|
return (py_retval); |
|
} |
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Global properties access * |
* Global properties access * |
Line 2566 libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject
|
Line 2745 libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject
|
if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) |
if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) |
return NULL; |
return NULL; |
cur = PyxmlNode_Get(obj); |
cur = PyxmlNode_Get(obj); |
|
if (cur == NULL) { |
|
Py_INCREF(Py_None); |
|
return (Py_None); |
|
} |
|
|
#ifdef DEBUG |
#ifdef DEBUG |
printf("libxml_type: cur = %p\n", cur); |
printf("libxml_type: cur = %p\n", cur); |
Line 2682 libxml_xmlNodeRemoveNsDef(ATTRIBUTE_UNUSED PyObject *
|
Line 2865 libxml_xmlNodeRemoveNsDef(ATTRIBUTE_UNUSED PyObject *
|
PyObject *pyobj_node; |
PyObject *pyobj_node; |
xmlChar *href; |
xmlChar *href; |
xmlNsPtr c_retval; |
xmlNsPtr c_retval; |
| |
if (!PyArg_ParseTuple |
if (!PyArg_ParseTuple |
(args, (char *) "Oz:xmlNodeRemoveNsDef", &pyobj_node, &href)) |
(args, (char *) "Oz:xmlNodeRemoveNsDef", &pyobj_node, &href)) |
return (NULL); |
return (NULL); |
Line 2844 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
Line 3027 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
&py_file, &encoding, &format)) |
&py_file, &encoding, &format)) |
return (NULL); |
return (NULL); |
node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
|
|
if (node == NULL) { |
if (node == NULL) { |
return (PyInt_FromLong((long) -1)); | return (PyLong_FromLong((long) -1)); |
} |
} |
if ((py_file == NULL) || (!(PyFile_Check(py_file)))) { | output = PyFile_Get(py_file); |
return (PyInt_FromLong((long) -1)); | |
} | |
output = PyFile_AsFile(py_file); | |
if (output == NULL) { |
if (output == NULL) { |
return (PyInt_FromLong((long) -1)); | return (PyLong_FromLong((long) -1)); |
} |
} |
|
|
if (node->type == XML_DOCUMENT_NODE) { |
if (node->type == XML_DOCUMENT_NODE) { |
Line 2872 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
Line 3051 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
if (encoding != NULL) { |
if (encoding != NULL) { |
handler = xmlFindCharEncodingHandler(encoding); |
handler = xmlFindCharEncodingHandler(encoding); |
if (handler == NULL) { |
if (handler == NULL) { |
return (PyInt_FromLong((long) -1)); | return (PyLong_FromLong((long) -1)); |
} |
} |
} |
} |
if (doc->type == XML_HTML_DOCUMENT_NODE) { |
if (doc->type == XML_HTML_DOCUMENT_NODE) { |
Line 2897 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
Line 3076 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, Py
|
xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); |
xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); |
len = xmlOutputBufferClose(buf); |
len = xmlOutputBufferClose(buf); |
} |
} |
return (PyInt_FromLong((long) len)); | PyFile_Release(output); |
| return (PyLong_FromLong((long) len)); |
} |
} |
#endif /* LIBXML_OUTPUT_ENABLED */ |
#endif /* LIBXML_OUTPUT_ENABLED */ |
|
|
Line 3403 PystringSet_Convert(PyObject *py_strings, xmlChar ***
|
Line 3583 PystringSet_Convert(PyObject *py_strings, xmlChar ***
|
{ |
{ |
int idx; |
int idx; |
for (idx=0; idx < count; ++idx) { |
for (idx=0; idx < count; ++idx) { |
char* s = PyString_AsString | char* s = PyBytes_AsString |
(is_tuple |
(is_tuple |
? PyTuple_GET_ITEM(py_strings, idx) |
? PyTuple_GET_ITEM(py_strings, idx) |
: PyList_GET_ITEM(py_strings, idx)); |
: PyList_GET_ITEM(py_strings, idx)); |
Line 3492 libxml_C14NDocDumpMemory(ATTRIBUTE_UNUSED PyObject * s
|
Line 3672 libxml_C14NDocDumpMemory(ATTRIBUTE_UNUSED PyObject * s
|
return NULL; |
return NULL; |
} |
} |
else { |
else { |
py_retval = PyString_FromStringAndSize((const char *) doc_txt, | py_retval = PY_IMPORT_STRING_SIZE((const char *) doc_txt, |
result); | result); |
xmlFree(doc_txt); |
xmlFree(doc_txt); |
return py_retval; |
return py_retval; |
} |
} |
Line 3534 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
Line 3714 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
return NULL; |
return NULL; |
} |
} |
|
|
if ((py_file == NULL) || (!(PyFile_Check(py_file)))) { | output = PyFile_Get(py_file); |
PyErr_SetString(PyExc_TypeError, "bad file."); | |
return NULL; | |
} | |
output = PyFile_AsFile(py_file); | |
if (output == NULL) { |
if (output == NULL) { |
PyErr_SetString(PyExc_TypeError, "bad file."); |
PyErr_SetString(PyExc_TypeError, "bad file."); |
return NULL; |
return NULL; |
Line 3576 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
Line 3752 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
xmlFree(prefixes); |
xmlFree(prefixes); |
} |
} |
|
|
|
PyFile_Release(output); |
len = xmlOutputBufferClose(buf); |
len = xmlOutputBufferClose(buf); |
|
|
if (result < 0) { |
if (result < 0) { |
Line 3584 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
Line 3761 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
|
return NULL; |
return NULL; |
} |
} |
else |
else |
return PyInt_FromLong((long) len); | return PyLong_FromLong((long) len); |
} |
} |
|
|
#endif |
#endif |
Line 3598 libxml_getObjDesc(PyObject *self ATTRIBUTE_UNUSED, PyO
|
Line 3775 libxml_getObjDesc(PyObject *self ATTRIBUTE_UNUSED, PyO
|
|
|
if (!PyArg_ParseTuple(args, (char *)"O:getObjDesc", &obj)) |
if (!PyArg_ParseTuple(args, (char *)"O:getObjDesc", &obj)) |
return NULL; |
return NULL; |
str = PyCObject_GetDesc(obj); | str = PyCapsule_GetPointer(obj, PyCapsule_GetName(obj)); |
return Py_BuildValue((char *)"s", str); |
return Py_BuildValue((char *)"s", str); |
} |
} |
|
|
Line 3693 static PyMethodDef libxmlMethods[] = {
|
Line 3870 static PyMethodDef libxmlMethods[] = {
|
{(char *) "getObjDesc", libxml_getObjDesc, METH_VARARGS, NULL}, |
{(char *) "getObjDesc", libxml_getObjDesc, METH_VARARGS, NULL}, |
{(char *) "compareNodesEqual", libxml_compareNodesEqual, METH_VARARGS, NULL}, |
{(char *) "compareNodesEqual", libxml_compareNodesEqual, METH_VARARGS, NULL}, |
{(char *) "nodeHash", libxml_nodeHash, METH_VARARGS, NULL}, |
{(char *) "nodeHash", libxml_nodeHash, METH_VARARGS, NULL}, |
|
{(char *) "xmlRegisterInputCallback", libxml_xmlRegisterInputCallback, METH_VARARGS, NULL}, |
|
{(char *) "xmlUnregisterInputCallback", libxml_xmlUnregisterInputCallback, METH_VARARGS, NULL}, |
{NULL, NULL, 0, NULL} |
{NULL, NULL, 0, NULL} |
}; |
}; |
|
|
|
#if PY_MAJOR_VERSION >= 3 |
|
#define INITERROR return NULL |
|
|
|
static struct PyModuleDef moduledef = { |
|
PyModuleDef_HEAD_INIT, |
|
"libxml2mod", |
|
NULL, |
|
-1, |
|
libxmlMethods, |
|
NULL, |
|
NULL, |
|
NULL, |
|
NULL |
|
}; |
|
|
|
#else |
|
#define INITERROR return |
|
|
#ifdef MERGED_MODULES |
#ifdef MERGED_MODULES |
extern void initlibxsltmod(void); |
extern void initlibxsltmod(void); |
#endif |
#endif |
|
|
void | #endif |
initlibxml2mod(void) | |
| #if PY_MAJOR_VERSION >= 3 |
| PyObject *PyInit_libxml2mod(void) |
| #else |
| void initlibxml2mod(void) |
| #endif |
{ |
{ |
static int initialized = 0; | PyObject *module; |
|
|
if (initialized != 0) | #if PY_MAJOR_VERSION >= 3 |
return; | module = PyModule_Create(&moduledef); |
| #else |
/* intialize the python extension module */ |
/* intialize the python extension module */ |
Py_InitModule((char *) "libxml2mod", libxmlMethods); | module = Py_InitModule((char *) "libxml2mod", libxmlMethods); |
| #endif |
| if (module == NULL) |
| INITERROR; |
|
|
/* initialize libxml2 */ |
/* initialize libxml2 */ |
xmlInitParser(); |
xmlInitParser(); |
|
/* TODO this probably need to be revamped for Python3 */ |
libxml_xmlErrorInitialize(); |
libxml_xmlErrorInitialize(); |
|
|
initialized = 1; | #if PY_MAJOR_VERSION < 3 |
| |
#ifdef MERGED_MODULES |
#ifdef MERGED_MODULES |
initlibxsltmod(); |
initlibxsltmod(); |
|
#endif |
|
#endif |
|
|
|
#if PY_MAJOR_VERSION >= 3 |
|
return module; |
#endif |
#endif |
} |
} |