2 * libxml.c: this modules implements the main part of the glue of the
3 * libxml2 library and the Python interpreter. It provides the
4 * entry points where an automatically generated stub is either
5 * unpractical or would not match cleanly the Python model.
7 * If compiled with MERGED_MODULES, the entry point will be used to
8 * initialize both the libxml2 and the libxslt wrappers
10 * See Copyright for the status of this software.
15 #include <fileobject.h>
16 /* #include "config.h" */
17 #include <libxml/xmlmemory.h>
18 #include <libxml/parser.h>
19 #include <libxml/tree.h>
20 #include <libxml/xpath.h>
21 #include <libxml/xmlerror.h>
22 #include <libxml/xpathInternals.h>
23 #include <libxml/xmlmemory.h>
24 #include <libxml/xmlIO.h>
25 #include <libxml/c14n.h>
26 #include <libxml/xmlreader.h>
27 #include <libxml/xmlsave.h>
28 #include "libxml_wrap.h"
29 #include "libxml2-py.h"
31 #if defined(_MSC_VER) && !defined(vsnprintf)
32 #define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
33 #elif defined(WITH_TRIO) && !defined(vsnprintf)
35 #define vsnprintf trio_vsnprintf
39 /* #define DEBUG_SAX */
40 /* #define DEBUG_XPATH */
41 /* #define DEBUG_ERROR */
42 /* #define DEBUG_MEMORY */
43 /* #define DEBUG_FILES */
44 /* #define DEBUG_LOADER */
46 void initlibxml2mod(void);
51 * macro to flag unimplemented blocks
54 xmlGenericError(xmlGenericErrorContext, \
55 "Unimplemented block at %s:%d\n", \
58 * the following vars are used for XPath extensions, but
59 * are also referenced within the parser cleanup routine.
61 static int libxml_xpathCallbacksInitialized = 0;
63 typedef struct libxml_xpathCallback {
64 xmlXPathContextPtr ctx;
68 } libxml_xpathCallback, *libxml_xpathCallbackPtr;
69 typedef libxml_xpathCallback libxml_xpathCallbackArray[];
70 static int libxml_xpathCallbacksAllocd = 10;
71 static libxml_xpathCallbackArray *libxml_xpathCallbacks = NULL;
72 static int libxml_xpathCallbacksNb = 0;
74 /************************************************************************
76 * Memory debug interface *
78 ************************************************************************/
81 extern void xmlMemFree(void *ptr);
82 extern void *xmlMemMalloc(size_t size);
83 extern void *xmlMemRealloc(void *ptr, size_t size);
84 extern char *xmlMemoryStrdup(const char *str);
87 static int libxmlMemoryDebugActivated = 0;
88 static long libxmlMemoryAllocatedBase = 0;
90 static int libxmlMemoryDebug = 0;
91 static xmlFreeFunc freeFunc = NULL;
92 static xmlMallocFunc mallocFunc = NULL;
93 static xmlReallocFunc reallocFunc = NULL;
94 static xmlStrdupFunc strdupFunc = NULL;
97 libxml_xmlErrorInitialize(void); /* forward declare */
100 libxml_xmlMemoryUsed(PyObject * self ATTRIBUTE_UNUSED,
101 PyObject * args ATTRIBUTE_UNUSED)
108 py_retval = libxml_longWrap(ret);
113 libxml_xmlDebugMemory(PyObject * self ATTRIBUTE_UNUSED, PyObject * args)
119 if (!PyArg_ParseTuple(args, (char *) "i:xmlDebugMemory", &activate))
123 printf("libxml_xmlDebugMemory(%d) called\n", activate);
127 if (libxmlMemoryDebug == 0) {
129 * First initialize the library and grab the old memory handlers
130 * and switch the library to memory debugging
132 xmlMemGet((xmlFreeFunc *) & freeFunc,
133 (xmlMallocFunc *) & mallocFunc,
134 (xmlReallocFunc *) & reallocFunc,
135 (xmlStrdupFunc *) & strdupFunc);
136 if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) &&
137 (reallocFunc == xmlMemRealloc) &&
138 (strdupFunc == xmlMemoryStrdup)) {
139 libxmlMemoryAllocatedBase = xmlMemUsed();
142 * cleanup first, because some memory has been
143 * allocated with the non-debug malloc in xmlInitParser
144 * when the python module was imported
147 ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
148 xmlMemRealloc, xmlMemoryStrdup);
151 libxmlMemoryAllocatedBase = xmlMemUsed();
154 libxml_xmlErrorInitialize();
157 } else if (libxmlMemoryDebugActivated == 0) {
158 libxmlMemoryAllocatedBase = xmlMemUsed();
161 ret = xmlMemUsed() - libxmlMemoryAllocatedBase;
163 libxmlMemoryDebug = 1;
164 libxmlMemoryDebugActivated = 1;
166 if (libxmlMemoryDebugActivated == 1)
167 ret = xmlMemUsed() - libxmlMemoryAllocatedBase;
170 libxmlMemoryDebugActivated = 0;
173 py_retval = libxml_longWrap(ret);
178 libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED,
179 PyObject *args ATTRIBUTE_UNUSED) {
184 if (libxmlMemoryDebug) {
185 freed = xmlMemUsed();
190 * Need to confirm whether we really want to do this (required for
191 * memcheck) in all cases...
194 if (libxml_xpathCallbacks != NULL) { /* if ext funcs declared */
195 for (ix=0; ix<libxml_xpathCallbacksNb; ix++) {
196 if ((*libxml_xpathCallbacks)[ix].name != NULL)
197 xmlFree((*libxml_xpathCallbacks)[ix].name);
198 if ((*libxml_xpathCallbacks)[ix].ns_uri != NULL)
199 xmlFree((*libxml_xpathCallbacks)[ix].ns_uri);
201 libxml_xpathCallbacksNb = 0;
202 xmlFree(libxml_xpathCallbacks);
203 libxml_xpathCallbacks = NULL;
206 if (libxmlMemoryDebug) {
207 freed -= xmlMemUsed();
208 libxmlMemoryAllocatedBase -= freed;
209 if (libxmlMemoryAllocatedBase < 0)
210 libxmlMemoryAllocatedBase = 0;
218 libxml_xmlDumpMemory(ATTRIBUTE_UNUSED PyObject * self,
219 ATTRIBUTE_UNUSED PyObject * args)
222 if (libxmlMemoryDebug != 0)
228 /************************************************************************
230 * Handling Python FILE I/O at the C level *
231 * The raw I/O attack diectly the File objects, while the *
232 * other routines address the ioWrapper instance instead *
234 ************************************************************************/
237 * xmlPythonFileCloseUnref:
238 * @context: the I/O context
240 * Close an I/O channel
243 xmlPythonFileCloseRaw (void * context) {
244 PyObject *file, *ret;
247 printf("xmlPythonFileCloseUnref\n");
249 file = (PyObject *) context;
250 if (file == NULL) return(-1);
251 ret = PyEval_CallMethod(file, (char *) "close", (char *) "()");
260 * xmlPythonFileReadRaw:
261 * @context: the I/O context
262 * @buffer: where to drop data
263 * @len: number of bytes to write
265 * Read @len bytes to @buffer from the Python file in the I/O channel
267 * Returns the number of bytes read
270 xmlPythonFileReadRaw (void * context, char * buffer, int len) {
277 printf("xmlPythonFileReadRaw: %d\n", len);
279 file = (PyObject *) context;
280 if (file == NULL) return(-1);
281 ret = PyEval_CallMethod(file, (char *) "read", (char *) "(i)", len);
283 printf("xmlPythonFileReadRaw: result is NULL\n");
285 } else if (PyString_Check(ret)) {
286 lenread = PyString_Size(ret);
287 data = PyString_AsString(ret);
289 memcpy(buffer, data, len);
291 memcpy(buffer, data, lenread);
294 printf("xmlPythonFileReadRaw: result is not a String\n");
302 * @context: the I/O context
303 * @buffer: where to drop data
304 * @len: number of bytes to write
306 * Read @len bytes to @buffer from the I/O channel.
308 * Returns the number of bytes read
311 xmlPythonFileRead (void * context, char * buffer, int len) {
318 printf("xmlPythonFileRead: %d\n", len);
320 file = (PyObject *) context;
321 if (file == NULL) return(-1);
322 ret = PyEval_CallMethod(file, (char *) "io_read", (char *) "(i)", len);
324 printf("xmlPythonFileRead: result is NULL\n");
326 } else if (PyString_Check(ret)) {
327 lenread = PyString_Size(ret);
328 data = PyString_AsString(ret);
330 memcpy(buffer, data, len);
332 memcpy(buffer, data, lenread);
335 printf("xmlPythonFileRead: result is not a String\n");
343 * @context: the I/O context
344 * @buffer: where to drop data
345 * @len: number of bytes to write
347 * Write @len bytes from @buffer to the I/O channel.
349 * Returns the number of bytes written
352 xmlPythonFileWrite (void * context, const char * buffer, int len) {
355 PyObject *ret = NULL;
359 printf("xmlPythonFileWrite: %d\n", len);
361 file = (PyObject *) context;
362 if (file == NULL) return(-1);
363 string = PyString_FromStringAndSize(buffer, len);
364 if (string == NULL) return(-1);
365 if (PyObject_HasAttrString(file, (char *) "io_write")) {
366 ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)",
368 } else if (PyObject_HasAttrString(file, (char *) "write")) {
369 ret = PyEval_CallMethod(file, (char *) "write", (char *) "(O)",
374 printf("xmlPythonFileWrite: result is NULL\n");
376 } else if (PyInt_Check(ret)) {
377 written = (int) PyInt_AsLong(ret);
379 } else if (ret == Py_None) {
383 printf("xmlPythonFileWrite: result is not an Int nor None\n");
390 * xmlPythonFileClose:
391 * @context: the I/O context
393 * Close an I/O channel
396 xmlPythonFileClose (void * context) {
397 PyObject *file, *ret = NULL;
400 printf("xmlPythonFileClose\n");
402 file = (PyObject *) context;
403 if (file == NULL) return(-1);
404 if (PyObject_HasAttrString(file, (char *) "io_close")) {
405 ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()");
406 } else if (PyObject_HasAttrString(file, (char *) "flush")) {
407 ret = PyEval_CallMethod(file, (char *) "flush", (char *) "()");
415 #ifdef LIBXML_OUTPUT_ENABLED
417 * xmlOutputBufferCreatePythonFile:
418 * @file: a PyFile_Type
419 * @encoder: the encoding converter or NULL
421 * Create a buffered output for the progressive saving to a PyFile_Type
424 * Returns the new parser output or NULL
426 static xmlOutputBufferPtr
427 xmlOutputBufferCreatePythonFile(PyObject *file,
428 xmlCharEncodingHandlerPtr encoder) {
429 xmlOutputBufferPtr ret;
431 if (file == NULL) return(NULL);
433 ret = xmlAllocOutputBuffer(encoder);
436 /* Py_INCREF(file); */
437 ret->writecallback = xmlPythonFileWrite;
438 ret->closecallback = xmlPythonFileClose;
445 libxml_xmlCreateOutputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
449 xmlCharEncodingHandlerPtr handler = NULL;
450 xmlOutputBufferPtr buffer;
453 if (!PyArg_ParseTuple(args, (char *)"Oz:xmlOutputBufferCreate",
456 if ((encoding != NULL) && (encoding[0] != 0)) {
457 handler = xmlFindCharEncodingHandler((const char *) encoding);
459 buffer = xmlOutputBufferCreatePythonFile(file, handler);
461 printf("libxml_xmlCreateOutputBuffer: buffer == NULL\n");
462 py_retval = libxml_xmlOutputBufferPtrWrap(buffer);
467 * libxml_outputBufferGetPythonFile:
468 * @buffer: the I/O buffer
470 * read the Python I/O from the CObject
472 * Returns the new parser output or NULL
475 libxml_outputBufferGetPythonFile(ATTRIBUTE_UNUSED PyObject *self,
479 xmlOutputBufferPtr obj;
481 if (!PyArg_ParseTuple(args, (char *)"O:outputBufferGetPythonFile",
485 obj = PyoutputBuffer_Get(buffer);
488 "outputBufferGetPythonFile: obj == NULL\n");
492 if (obj->closecallback != xmlPythonFileClose) {
494 "outputBufferGetPythonFile: not a python file wrapper\n");
498 file = (PyObject *) obj->context;
508 libxml_xmlOutputBufferClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
511 xmlOutputBufferPtr out;
514 if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferClose", &pyobj_out))
516 out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out);
517 /* Buffer may already have been destroyed elsewhere. This is harmless. */
523 c_retval = xmlOutputBufferClose(out);
524 py_retval = libxml_intWrap((int) c_retval);
529 libxml_xmlOutputBufferFlush(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
532 xmlOutputBufferPtr out;
535 if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferFlush", &pyobj_out))
537 out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out);
539 c_retval = xmlOutputBufferFlush(out);
540 py_retval = libxml_intWrap((int) c_retval);
545 libxml_xmlSaveFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
548 xmlOutputBufferPtr buf;
554 if (!PyArg_ParseTuple(args, (char *)"OOz:xmlSaveFileTo", &pyobj_buf, &pyobj_cur, &encoding))
556 buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf);
557 cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur);
559 c_retval = xmlSaveFileTo(buf, cur, encoding);
560 /* xmlSaveTo() freed the memory pointed to by buf, so record that in the
562 ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL;
563 py_retval = libxml_intWrap((int) c_retval);
568 libxml_xmlSaveFormatFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
571 xmlOutputBufferPtr buf;
578 if (!PyArg_ParseTuple(args, (char *)"OOzi:xmlSaveFormatFileTo", &pyobj_buf, &pyobj_cur, &encoding, &format))
580 buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf);
581 cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur);
583 c_retval = xmlSaveFormatFileTo(buf, cur, encoding, format);
584 /* xmlSaveFormatFileTo() freed the memory pointed to by buf, so record that
585 * in the Python object */
586 ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL;
587 py_retval = libxml_intWrap((int) c_retval);
590 #endif /* LIBXML_OUTPUT_ENABLED */
594 * xmlParserInputBufferCreatePythonFile:
595 * @file: a PyFile_Type
596 * @encoder: the encoding converter or NULL
598 * Create a buffered output for the progressive saving to a PyFile_Type
601 * Returns the new parser output or NULL
603 static xmlParserInputBufferPtr
604 xmlParserInputBufferCreatePythonFile(PyObject *file,
605 xmlCharEncoding encoding) {
606 xmlParserInputBufferPtr ret;
608 if (file == NULL) return(NULL);
610 ret = xmlAllocParserInputBuffer(encoding);
613 /* Py_INCREF(file); */
614 ret->readcallback = xmlPythonFileRead;
615 ret->closecallback = xmlPythonFileClose;
622 libxml_xmlCreateInputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
626 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
627 xmlParserInputBufferPtr buffer;
630 if (!PyArg_ParseTuple(args, (char *)"Oz:xmlParserInputBufferCreate",
633 if ((encoding != NULL) && (encoding[0] != 0)) {
634 enc = xmlParseCharEncoding((const char *) encoding);
636 buffer = xmlParserInputBufferCreatePythonFile(file, enc);
638 printf("libxml_xmlParserInputBufferCreate: buffer == NULL\n");
639 py_retval = libxml_xmlParserInputBufferPtrWrap(buffer);
643 /************************************************************************
645 * Providing the resolver at the Python level *
647 ************************************************************************/
649 static xmlExternalEntityLoader defaultExternalEntityLoader = NULL;
650 static PyObject *pythonExternalEntityLoaderObjext;
652 static xmlParserInputPtr
653 pythonExternalEntityLoader(const char *URL, const char *ID,
654 xmlParserCtxtPtr ctxt) {
655 xmlParserInputPtr result = NULL;
656 if (pythonExternalEntityLoaderObjext != NULL) {
660 ctxtobj = libxml_xmlParserCtxtPtrWrap(ctxt);
662 printf("pythonExternalEntityLoader: ready to call\n");
665 ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext,
666 (char *) "(ssO)", URL, ID, ctxtobj);
669 printf("pythonExternalEntityLoader: result ");
670 PyObject_Print(ret, stderr, 0);
675 if (PyObject_HasAttrString(ret, (char *) "read")) {
676 xmlParserInputBufferPtr buf;
678 buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
681 buf->readcallback = xmlPythonFileReadRaw;
682 buf->closecallback = xmlPythonFileCloseRaw;
683 result = xmlNewIOInputStream(ctxt, buf,
684 XML_CHAR_ENCODING_NONE);
689 printf("pythonExternalEntityLoader: can't read %s\n",
693 if (result == NULL) {
695 } else if (URL != NULL) {
696 result->filename = (char *) xmlStrdup((const xmlChar *)URL);
697 result->directory = xmlParserGetDirectory((const char *) URL);
701 if ((result == NULL) && (defaultExternalEntityLoader != NULL)) {
702 result = defaultExternalEntityLoader(URL, ID, ctxt);
708 libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
712 if (!PyArg_ParseTuple(args, (char *)"O:libxml_xmlSetEntityLoader",
717 printf("libxml_xmlSetEntityLoader\n");
719 if (defaultExternalEntityLoader == NULL)
720 defaultExternalEntityLoader = xmlGetExternalEntityLoader();
722 pythonExternalEntityLoaderObjext = loader;
723 xmlSetExternalEntityLoader(pythonExternalEntityLoader);
725 py_retval = PyInt_FromLong(0);
730 /************************************************************************
732 * Handling SAX/xmllib/sgmlop callback interfaces *
734 ************************************************************************/
737 pythonStartElement(void *user_data, const xmlChar * name,
738 const xmlChar ** attrs)
745 PyObject *result = NULL;
749 printf("pythonStartElement(%s) called\n", name);
751 handler = (PyObject *) user_data;
752 if (PyObject_HasAttrString(handler, (char *) "startElement"))
754 else if (PyObject_HasAttrString(handler, (char *) "start"))
758 * the xmllib interface always generate a dictionnary,
761 if ((attrs == NULL) && (type == 1)) {
764 } else if (attrs == NULL) {
768 for (i = 0; attrs[i] != NULL; i++) {
769 attrname = PyString_FromString((char *) attrs[i]);
771 if (attrs[i] != NULL) {
772 attrvalue = PyString_FromString((char *) attrs[i]);
777 PyDict_SetItem(dict, attrname, attrvalue);
779 Py_DECREF(attrvalue);
784 result = PyObject_CallMethod(handler, (char *) "startElement",
785 (char *) "sO", name, dict);
787 result = PyObject_CallMethod(handler, (char *) "start",
788 (char *) "sO", name, dict);
789 if (PyErr_Occurred())
797 pythonStartDocument(void *user_data)
803 printf("pythonStartDocument() called\n");
805 handler = (PyObject *) user_data;
806 if (PyObject_HasAttrString(handler, (char *) "startDocument")) {
808 PyObject_CallMethod(handler, (char *) "startDocument", NULL);
809 if (PyErr_Occurred())
816 pythonEndDocument(void *user_data)
822 printf("pythonEndDocument() called\n");
824 handler = (PyObject *) user_data;
825 if (PyObject_HasAttrString(handler, (char *) "endDocument")) {
827 PyObject_CallMethod(handler, (char *) "endDocument", NULL);
828 if (PyErr_Occurred())
833 * The reference to the handler is released there
839 pythonEndElement(void *user_data, const xmlChar * name)
845 printf("pythonEndElement(%s) called\n", name);
847 handler = (PyObject *) user_data;
848 if (PyObject_HasAttrString(handler, (char *) "endElement")) {
849 result = PyObject_CallMethod(handler, (char *) "endElement",
851 if (PyErr_Occurred())
854 } else if (PyObject_HasAttrString(handler, (char *) "end")) {
855 result = PyObject_CallMethod(handler, (char *) "end",
857 if (PyErr_Occurred())
864 pythonReference(void *user_data, const xmlChar * name)
870 printf("pythonReference(%s) called\n", name);
872 handler = (PyObject *) user_data;
873 if (PyObject_HasAttrString(handler, (char *) "reference")) {
874 result = PyObject_CallMethod(handler, (char *) "reference",
876 if (PyErr_Occurred())
883 pythonCharacters(void *user_data, const xmlChar * ch, int len)
886 PyObject *result = NULL;
890 printf("pythonCharacters(%s, %d) called\n", ch, len);
892 handler = (PyObject *) user_data;
893 if (PyObject_HasAttrString(handler, (char *) "characters"))
895 else if (PyObject_HasAttrString(handler, (char *) "data"))
899 result = PyObject_CallMethod(handler, (char *) "characters",
900 (char *) "s#", ch, len);
902 result = PyObject_CallMethod(handler, (char *) "data",
903 (char *) "s#", ch, len);
904 if (PyErr_Occurred())
911 pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len)
914 PyObject *result = NULL;
918 printf("pythonIgnorableWhitespace(%s, %d) called\n", ch, len);
920 handler = (PyObject *) user_data;
921 if (PyObject_HasAttrString(handler, (char *) "ignorableWhitespace"))
923 else if (PyObject_HasAttrString(handler, (char *) "data"))
928 PyObject_CallMethod(handler,
929 (char *) "ignorableWhitespace",
930 (char *) "s#", ch, len);
933 PyObject_CallMethod(handler, (char *) "data",
934 (char *) "s#", ch, len);
940 pythonProcessingInstruction(void *user_data,
941 const xmlChar * target, const xmlChar * data)
947 printf("pythonProcessingInstruction(%s, %s) called\n", target, data);
949 handler = (PyObject *) user_data;
950 if (PyObject_HasAttrString(handler, (char *) "processingInstruction")) {
951 result = PyObject_CallMethod(handler, (char *)
952 "processingInstruction",
953 (char *) "ss", target, data);
959 pythonComment(void *user_data, const xmlChar * value)
965 printf("pythonComment(%s) called\n", value);
967 handler = (PyObject *) user_data;
968 if (PyObject_HasAttrString(handler, (char *) "comment")) {
970 PyObject_CallMethod(handler, (char *) "comment", (char *) "s",
972 if (PyErr_Occurred())
979 pythonWarning(void *user_data, const char *msg, ...)
987 printf("pythonWarning(%s) called\n", msg);
989 handler = (PyObject *) user_data;
990 if (PyObject_HasAttrString(handler, (char *) "warning")) {
992 vsnprintf(buf, 1023, msg, args);
996 PyObject_CallMethod(handler, (char *) "warning", (char *) "s",
998 if (PyErr_Occurred())
1005 pythonError(void *user_data, const char *msg, ...)
1013 printf("pythonError(%s) called\n", msg);
1015 handler = (PyObject *) user_data;
1016 if (PyObject_HasAttrString(handler, (char *) "error")) {
1017 va_start(args, msg);
1018 vsnprintf(buf, 1023, msg, args);
1022 PyObject_CallMethod(handler, (char *) "error", (char *) "s",
1024 if (PyErr_Occurred())
1031 pythonFatalError(void *user_data, const char *msg, ...)
1039 printf("pythonFatalError(%s) called\n", msg);
1041 handler = (PyObject *) user_data;
1042 if (PyObject_HasAttrString(handler, (char *) "fatalError")) {
1043 va_start(args, msg);
1044 vsnprintf(buf, 1023, msg, args);
1048 PyObject_CallMethod(handler, (char *) "fatalError",
1050 if (PyErr_Occurred())
1057 pythonCdataBlock(void *user_data, const xmlChar * ch, int len)
1060 PyObject *result = NULL;
1064 printf("pythonCdataBlock(%s, %d) called\n", ch, len);
1066 handler = (PyObject *) user_data;
1067 if (PyObject_HasAttrString(handler, (char *) "cdataBlock"))
1069 else if (PyObject_HasAttrString(handler, (char *) "cdata"))
1074 PyObject_CallMethod(handler, (char *) "cdataBlock",
1075 (char *) "s#", ch, len);
1078 PyObject_CallMethod(handler, (char *) "cdata",
1079 (char *) "s#", ch, len);
1080 if (PyErr_Occurred())
1087 pythonExternalSubset(void *user_data,
1088 const xmlChar * name,
1089 const xmlChar * externalID, const xmlChar * systemID)
1095 printf("pythonExternalSubset(%s, %s, %s) called\n",
1096 name, externalID, systemID);
1098 handler = (PyObject *) user_data;
1099 if (PyObject_HasAttrString(handler, (char *) "externalSubset")) {
1101 PyObject_CallMethod(handler, (char *) "externalSubset",
1102 (char *) "sss", name, externalID,
1109 pythonEntityDecl(void *user_data,
1110 const xmlChar * name,
1112 const xmlChar * publicId,
1113 const xmlChar * systemId, xmlChar * content)
1118 handler = (PyObject *) user_data;
1119 if (PyObject_HasAttrString(handler, (char *) "entityDecl")) {
1120 result = PyObject_CallMethod(handler, (char *) "entityDecl",
1121 (char *) "sisss", name, type,
1122 publicId, systemId, content);
1123 if (PyErr_Occurred())
1133 pythonNotationDecl(void *user_data,
1134 const xmlChar * name,
1135 const xmlChar * publicId, const xmlChar * systemId)
1140 handler = (PyObject *) user_data;
1141 if (PyObject_HasAttrString(handler, (char *) "notationDecl")) {
1142 result = PyObject_CallMethod(handler, (char *) "notationDecl",
1143 (char *) "sss", name, publicId,
1145 if (PyErr_Occurred())
1152 pythonAttributeDecl(void *user_data,
1153 const xmlChar * elem,
1154 const xmlChar * name,
1157 const xmlChar * defaultValue, xmlEnumerationPtr tree)
1162 xmlEnumerationPtr node;
1166 handler = (PyObject *) user_data;
1167 if (PyObject_HasAttrString(handler, (char *) "attributeDecl")) {
1169 for (node = tree; node != NULL; node = node->next) {
1172 nameList = PyList_New(count);
1174 for (node = tree; node != NULL; node = node->next) {
1175 newName = PyString_FromString((char *) node->name);
1176 PyList_SetItem(nameList, count, newName);
1180 result = PyObject_CallMethod(handler, (char *) "attributeDecl",
1181 (char *) "ssiisO", elem, name, type,
1182 def, defaultValue, nameList);
1183 if (PyErr_Occurred())
1185 Py_XDECREF(nameList);
1191 pythonElementDecl(void *user_data,
1192 const xmlChar * name,
1193 int type, ATTRIBUTE_UNUSED xmlElementContentPtr content)
1199 handler = (PyObject *) user_data;
1200 if (PyObject_HasAttrString(handler, (char *) "elementDecl")) {
1201 /* TODO: wrap in an elementContent object */
1203 ("pythonElementDecl: xmlElementContentPtr wrapper missing !\n");
1205 /* Py_XINCREF(Py_None); isn't the reference just borrowed ??? */
1206 result = PyObject_CallMethod(handler, (char *) "elementDecl",
1207 (char *) "siO", name, type, obj);
1208 if (PyErr_Occurred())
1215 pythonUnparsedEntityDecl(void *user_data,
1216 const xmlChar * name,
1217 const xmlChar * publicId,
1218 const xmlChar * systemId,
1219 const xmlChar * notationName)
1224 handler = (PyObject *) user_data;
1225 if (PyObject_HasAttrString(handler, (char *) "unparsedEntityDecl")) {
1227 PyObject_CallMethod(handler, (char *) "unparsedEntityDecl",
1228 (char *) "ssss", name, publicId, systemId,
1230 if (PyErr_Occurred())
1237 pythonInternalSubset(void *user_data, const xmlChar * name,
1238 const xmlChar * ExternalID, const xmlChar * SystemID)
1244 printf("pythonInternalSubset(%s, %s, %s) called\n",
1245 name, ExternalID, SystemID);
1247 handler = (PyObject *) user_data;
1248 if (PyObject_HasAttrString(handler, (char *) "internalSubset")) {
1249 result = PyObject_CallMethod(handler, (char *) "internalSubset",
1250 (char *) "sss", name, ExternalID,
1252 if (PyErr_Occurred())
1258 static xmlSAXHandler pythonSaxHandler = {
1259 pythonInternalSubset,
1260 NULL, /* TODO pythonIsStandalone, */
1261 NULL, /* TODO pythonHasInternalSubset, */
1262 NULL, /* TODO pythonHasExternalSubset, */
1263 NULL, /* TODO pythonResolveEntity, */
1264 NULL, /* TODO pythonGetEntity, */
1267 pythonAttributeDecl,
1269 pythonUnparsedEntityDecl,
1270 NULL, /* OBSOLETED pythonSetDocumentLocator, */
1271 pythonStartDocument,
1277 pythonIgnorableWhitespace,
1278 pythonProcessingInstruction,
1283 NULL, /* TODO pythonGetParameterEntity, */
1285 pythonExternalSubset,
1287 NULL, /* TODO mograte to SAX2 */
1293 /************************************************************************
1295 * Handling of specific parser context *
1297 ************************************************************************/
1300 libxml_xmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self,
1306 PyObject *pyobj_SAX = NULL;
1307 xmlSAXHandlerPtr SAX = NULL;
1308 xmlParserCtxtPtr ret;
1311 if (!PyArg_ParseTuple
1312 (args, (char *) "Oziz:xmlCreatePushParser", &pyobj_SAX, &chunk,
1317 printf("libxml_xmlCreatePushParser(%p, %s, %d, %s) called\n",
1318 pyobj_SAX, chunk, size, URI);
1320 if (pyobj_SAX != Py_None) {
1321 SAX = &pythonSaxHandler;
1322 Py_INCREF(pyobj_SAX);
1323 /* The reference is released in pythonEndDocument() */
1325 ret = xmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI);
1326 pyret = libxml_xmlParserCtxtPtrWrap(ret);
1331 libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self,
1334 #ifdef LIBXML_HTML_ENABLED
1338 PyObject *pyobj_SAX = NULL;
1339 xmlSAXHandlerPtr SAX = NULL;
1340 xmlParserCtxtPtr ret;
1343 if (!PyArg_ParseTuple
1344 (args, (char *) "Oziz:htmlCreatePushParser", &pyobj_SAX, &chunk,
1349 printf("libxml_htmlCreatePushParser(%p, %s, %d, %s) called\n",
1350 pyobj_SAX, chunk, size, URI);
1352 if (pyobj_SAX != Py_None) {
1353 SAX = &pythonSaxHandler;
1354 Py_INCREF(pyobj_SAX);
1355 /* The reference is released in pythonEndDocument() */
1357 ret = htmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI,
1358 XML_CHAR_ENCODING_NONE);
1359 pyret = libxml_xmlParserCtxtPtrWrap(ret);
1364 #endif /* LIBXML_HTML_ENABLED */
1368 libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1372 PyObject *pyobj_SAX = NULL;
1373 xmlSAXHandlerPtr SAX = NULL;
1375 if (!PyArg_ParseTuple(args, (char *) "Osi:xmlSAXParseFile", &pyobj_SAX,
1380 printf("libxml_xmlSAXParseFile(%p, %s, %d) called\n",
1381 pyobj_SAX, URI, recover);
1383 if (pyobj_SAX == Py_None) {
1387 SAX = &pythonSaxHandler;
1388 Py_INCREF(pyobj_SAX);
1389 /* The reference is released in pythonEndDocument() */
1390 xmlSAXUserParseFile(SAX, pyobj_SAX, URI);
1396 libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1398 #ifdef LIBXML_HTML_ENABLED
1400 const char *encoding;
1401 PyObject *pyobj_SAX = NULL;
1402 xmlSAXHandlerPtr SAX = NULL;
1404 if (!PyArg_ParseTuple
1405 (args, (char *) "Osz:htmlSAXParseFile", &pyobj_SAX, &URI,
1410 printf("libxml_htmlSAXParseFile(%p, %s, %s) called\n",
1411 pyobj_SAX, URI, encoding);
1413 if (pyobj_SAX == Py_None) {
1417 SAX = &pythonSaxHandler;
1418 Py_INCREF(pyobj_SAX);
1419 /* The reference is released in pythonEndDocument() */
1420 htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX);
1426 #endif /* LIBXML_HTML_ENABLED */
1429 /************************************************************************
1431 * Error message callback *
1433 ************************************************************************/
1435 static PyObject *libxml_xmlPythonErrorFuncHandler = NULL;
1436 static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL;
1438 /* helper to build a xmlMalloc'ed string from a format and va_list */
1440 * disabled the loop, the repeated call to vsnprintf without reset of ap
1441 * in case the initial buffer was too small segfaulted on x86_64
1442 * we now directly vsnprintf on a large buffer.
1445 libxml_buildMessage(const char *msg, va_list ap)
1450 str = (char *) xmlMalloc(1000);
1454 chars = vsnprintf(str, 999, msg, ap);
1462 libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
1472 printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
1476 if (libxml_xmlPythonErrorFuncHandler == NULL) {
1478 vfprintf(stderr, msg, ap);
1482 if (vsnprintf(str, 999, msg, ap) >= 998)
1486 list = PyTuple_New(2);
1487 PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
1488 Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
1489 message = libxml_charPtrConstWrap(str);
1490 PyTuple_SetItem(list, 1, message);
1491 result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
1498 libxml_xmlErrorInitialize(void)
1501 printf("libxml_xmlErrorInitialize() called\n");
1503 xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1504 xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1508 libxml_xmlRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
1511 PyObject *py_retval;
1513 PyObject *pyobj_ctx;
1515 if (!PyArg_ParseTuple
1516 (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
1521 printf("libxml_xmlRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
1525 if (libxml_xmlPythonErrorFuncHandler != NULL) {
1526 Py_XDECREF(libxml_xmlPythonErrorFuncHandler);
1528 if (libxml_xmlPythonErrorFuncCtxt != NULL) {
1529 Py_XDECREF(libxml_xmlPythonErrorFuncCtxt);
1532 Py_XINCREF(pyobj_ctx);
1533 Py_XINCREF(pyobj_f);
1535 /* TODO: check f is a function ! */
1536 libxml_xmlPythonErrorFuncHandler = pyobj_f;
1537 libxml_xmlPythonErrorFuncCtxt = pyobj_ctx;
1539 py_retval = libxml_intWrap(1);
1544 /************************************************************************
1546 * Per parserCtxt error handler *
1548 ************************************************************************/
1554 } xmlParserCtxtPyCtxt;
1555 typedef xmlParserCtxtPyCtxt *xmlParserCtxtPyCtxtPtr;
1558 libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str)
1562 xmlParserCtxtPtr ctxt;
1563 xmlParserCtxtPyCtxtPtr pyCtxt;
1566 printf("libxml_xmlParserCtxtGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str);
1569 ctxt = (xmlParserCtxtPtr)ctx;
1570 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1572 list = PyTuple_New(4);
1573 PyTuple_SetItem(list, 0, pyCtxt->arg);
1574 Py_XINCREF(pyCtxt->arg);
1575 PyTuple_SetItem(list, 1, libxml_charPtrWrap(str));
1576 PyTuple_SetItem(list, 2, libxml_intWrap(severity));
1577 PyTuple_SetItem(list, 3, Py_None);
1579 result = PyEval_CallObject(pyCtxt->f, list);
1582 /* TODO: manage for the exception to be propagated... */
1590 libxml_xmlParserCtxtErrorFuncHandler(void *ctx, const char *msg, ...)
1595 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_ERROR,libxml_buildMessage(msg,ap));
1600 libxml_xmlParserCtxtWarningFuncHandler(void *ctx, const char *msg, ...)
1605 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_WARNING,libxml_buildMessage(msg,ap));
1610 libxml_xmlParserCtxtValidityErrorFuncHandler(void *ctx, const char *msg, ...)
1615 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap));
1620 libxml_xmlParserCtxtValidityWarningFuncHandler(void *ctx, const char *msg, ...)
1625 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap));
1630 libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1632 PyObject *py_retval;
1633 xmlParserCtxtPtr ctxt;
1634 xmlParserCtxtPyCtxtPtr pyCtxt;
1635 PyObject *pyobj_ctxt;
1637 PyObject *pyobj_arg;
1639 if (!PyArg_ParseTuple(args, (char *)"OOO:xmlParserCtxtSetErrorHandler",
1640 &pyobj_ctxt, &pyobj_f, &pyobj_arg))
1642 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1643 if (ctxt->_private == NULL) {
1644 pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt));
1645 if (pyCtxt == NULL) {
1646 py_retval = libxml_intWrap(-1);
1649 memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt));
1650 ctxt->_private = pyCtxt;
1653 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1655 /* TODO: check f is a function ! */
1656 Py_XDECREF(pyCtxt->f);
1657 Py_XINCREF(pyobj_f);
1658 pyCtxt->f = pyobj_f;
1659 Py_XDECREF(pyCtxt->arg);
1660 Py_XINCREF(pyobj_arg);
1661 pyCtxt->arg = pyobj_arg;
1663 if (pyobj_f != Py_None) {
1664 ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler;
1665 ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler;
1666 ctxt->vctxt.error = libxml_xmlParserCtxtValidityErrorFuncHandler;
1667 ctxt->vctxt.warning = libxml_xmlParserCtxtValidityWarningFuncHandler;
1670 ctxt->sax->error = xmlParserError;
1671 ctxt->vctxt.error = xmlParserValidityError;
1672 ctxt->sax->warning = xmlParserWarning;
1673 ctxt->vctxt.warning = xmlParserValidityWarning;
1676 py_retval = libxml_intWrap(1);
1681 libxml_xmlParserCtxtGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1683 PyObject *py_retval;
1684 xmlParserCtxtPtr ctxt;
1685 xmlParserCtxtPyCtxtPtr pyCtxt;
1686 PyObject *pyobj_ctxt;
1688 if (!PyArg_ParseTuple(args, (char *)"O:xmlParserCtxtGetErrorHandler",
1691 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1692 py_retval = PyTuple_New(2);
1693 if (ctxt->_private != NULL) {
1694 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1696 PyTuple_SetItem(py_retval, 0, pyCtxt->f);
1697 Py_XINCREF(pyCtxt->f);
1698 PyTuple_SetItem(py_retval, 1, pyCtxt->arg);
1699 Py_XINCREF(pyCtxt->arg);
1702 /* no python error handler registered */
1703 PyTuple_SetItem(py_retval, 0, Py_None);
1704 Py_XINCREF(Py_None);
1705 PyTuple_SetItem(py_retval, 1, Py_None);
1706 Py_XINCREF(Py_None);
1712 libxml_xmlFreeParserCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
1713 xmlParserCtxtPtr ctxt;
1714 PyObject *pyobj_ctxt;
1715 xmlParserCtxtPyCtxtPtr pyCtxt;
1717 if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeParserCtxt", &pyobj_ctxt))
1719 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1722 pyCtxt = (xmlParserCtxtPyCtxtPtr)((xmlParserCtxtPtr)ctxt)->_private;
1724 Py_XDECREF(pyCtxt->f);
1725 Py_XDECREF(pyCtxt->arg);
1728 xmlFreeParserCtxt(ctxt);
1736 * xmlValidCtxt stuff
1744 } xmlValidCtxtPyCtxt;
1745 typedef xmlValidCtxtPyCtxt *xmlValidCtxtPyCtxtPtr;
1748 libxml_xmlValidCtxtGenericErrorFuncHandler(void *ctx, ATTRIBUTE_UNUSED int severity, char *str)
1752 xmlValidCtxtPyCtxtPtr pyCtxt;
1755 printf("libxml_xmlValidCtxtGenericErrorFuncHandler(%p, %d, %s, ...) called\n", ctx, severity, str);
1758 pyCtxt = (xmlValidCtxtPyCtxtPtr)ctx;
1760 list = PyTuple_New(2);
1761 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
1762 PyTuple_SetItem(list, 1, pyCtxt->arg);
1763 Py_XINCREF(pyCtxt->arg);
1764 result = PyEval_CallObject(pyCtxt->error, list);
1767 /* TODO: manage for the exception to be propagated... */
1775 libxml_xmlValidCtxtGenericWarningFuncHandler(void *ctx, ATTRIBUTE_UNUSED int severity, char *str)
1779 xmlValidCtxtPyCtxtPtr pyCtxt;
1782 printf("libxml_xmlValidCtxtGenericWarningFuncHandler(%p, %d, %s, ...) called\n", ctx, severity, str);
1785 pyCtxt = (xmlValidCtxtPyCtxtPtr)ctx;
1787 list = PyTuple_New(2);
1788 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
1789 PyTuple_SetItem(list, 1, pyCtxt->arg);
1790 Py_XINCREF(pyCtxt->arg);
1791 result = PyEval_CallObject(pyCtxt->warn, list);
1794 /* TODO: manage for the exception to be propagated... */
1802 libxml_xmlValidCtxtErrorFuncHandler(void *ctx, const char *msg, ...)
1807 libxml_xmlValidCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap));
1812 libxml_xmlValidCtxtWarningFuncHandler(void *ctx, const char *msg, ...)
1817 libxml_xmlValidCtxtGenericWarningFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap));
1822 libxml_xmlSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1824 PyObject *py_retval;
1825 PyObject *pyobj_error;
1826 PyObject *pyobj_warn;
1827 PyObject *pyobj_ctx;
1828 PyObject *pyobj_arg = Py_None;
1829 xmlValidCtxtPtr ctxt;
1830 xmlValidCtxtPyCtxtPtr pyCtxt;
1832 if (!PyArg_ParseTuple
1833 (args, (char *) "OOO|O:xmlSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg))
1837 printf("libxml_xmlSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn);
1840 ctxt = PyValidCtxt_Get(pyobj_ctx);
1841 pyCtxt = xmlMalloc(sizeof(xmlValidCtxtPyCtxt));
1842 if (pyCtxt == NULL) {
1843 py_retval = libxml_intWrap(-1);
1846 memset(pyCtxt, 0, sizeof(xmlValidCtxtPyCtxt));
1849 /* TODO: check warn and error is a function ! */
1850 Py_XDECREF(pyCtxt->error);
1851 Py_XINCREF(pyobj_error);
1852 pyCtxt->error = pyobj_error;
1854 Py_XDECREF(pyCtxt->warn);
1855 Py_XINCREF(pyobj_warn);
1856 pyCtxt->warn = pyobj_warn;
1858 Py_XDECREF(pyCtxt->arg);
1859 Py_XINCREF(pyobj_arg);
1860 pyCtxt->arg = pyobj_arg;
1862 ctxt->error = libxml_xmlValidCtxtErrorFuncHandler;
1863 ctxt->warning = libxml_xmlValidCtxtWarningFuncHandler;
1864 ctxt->userData = pyCtxt;
1866 py_retval = libxml_intWrap(1);
1872 libxml_xmlFreeValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
1873 xmlValidCtxtPtr cur;
1874 xmlValidCtxtPyCtxtPtr pyCtxt;
1875 PyObject *pyobj_cur;
1877 if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeValidCtxt", &pyobj_cur))
1879 cur = (xmlValidCtxtPtr) PyValidCtxt_Get(pyobj_cur);
1881 pyCtxt = (xmlValidCtxtPyCtxtPtr)(cur->userData);
1884 Py_XDECREF(pyCtxt->error);
1885 Py_XDECREF(pyCtxt->warn);
1886 Py_XDECREF(pyCtxt->arg);
1890 xmlFreeValidCtxt(cur);
1895 #ifdef LIBXML_READER_ENABLED
1896 /************************************************************************
1898 * Per xmlTextReader error handler *
1900 ************************************************************************/
1906 } xmlTextReaderPyCtxt;
1907 typedef xmlTextReaderPyCtxt *xmlTextReaderPyCtxtPtr;
1910 libxml_xmlTextReaderErrorCallback(void *arg,
1913 xmlTextReaderLocatorPtr locator)
1915 xmlTextReaderPyCtxt *pyCtxt = (xmlTextReaderPyCtxt *)arg;
1919 list = PyTuple_New(4);
1920 PyTuple_SetItem(list, 0, pyCtxt->arg);
1921 Py_XINCREF(pyCtxt->arg);
1922 PyTuple_SetItem(list, 1, libxml_charPtrConstWrap(msg));
1923 PyTuple_SetItem(list, 2, libxml_intWrap(severity));
1924 PyTuple_SetItem(list, 3, libxml_xmlTextReaderLocatorPtrWrap(locator));
1925 result = PyEval_CallObject(pyCtxt->f, list);
1928 /* TODO: manage for the exception to be propagated... */
1936 libxml_xmlTextReaderSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1938 xmlTextReaderPtr reader;
1939 xmlTextReaderPyCtxtPtr pyCtxt;
1940 xmlTextReaderErrorFunc f;
1942 PyObject *pyobj_reader;
1944 PyObject *pyobj_arg;
1945 PyObject *py_retval;
1947 if (!PyArg_ParseTuple(args, (char *)"OOO:xmlTextReaderSetErrorHandler", &pyobj_reader, &pyobj_f, &pyobj_arg))
1949 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
1950 /* clear previous error handler */
1951 xmlTextReaderGetErrorHandler(reader,&f,&arg);
1953 if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) {
1954 /* ok, it's our error handler! */
1955 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
1956 Py_XDECREF(pyCtxt->f);
1957 Py_XDECREF(pyCtxt->arg);
1962 * there already an arg, and it's not ours,
1963 * there is definitely something wrong going on here...
1964 * we don't know how to free it, so we bail out...
1966 py_retval = libxml_intWrap(-1);
1970 xmlTextReaderSetErrorHandler(reader,NULL,NULL);
1971 /* set new error handler */
1972 if (pyobj_f != Py_None)
1974 pyCtxt = (xmlTextReaderPyCtxtPtr)xmlMalloc(sizeof(xmlTextReaderPyCtxt));
1975 if (pyCtxt == NULL) {
1976 py_retval = libxml_intWrap(-1);
1979 Py_XINCREF(pyobj_f);
1980 pyCtxt->f = pyobj_f;
1981 Py_XINCREF(pyobj_arg);
1982 pyCtxt->arg = pyobj_arg;
1983 xmlTextReaderSetErrorHandler(reader,
1984 (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback,
1988 py_retval = libxml_intWrap(1);
1993 libxml_xmlTextReaderGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1995 xmlTextReaderPtr reader;
1996 xmlTextReaderPyCtxtPtr pyCtxt;
1997 xmlTextReaderErrorFunc f;
1999 PyObject *pyobj_reader;
2000 PyObject *py_retval;
2002 if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderSetErrorHandler", &pyobj_reader))
2004 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
2005 xmlTextReaderGetErrorHandler(reader,&f,&arg);
2006 py_retval = PyTuple_New(2);
2007 if (f == (xmlTextReaderErrorFunc)libxml_xmlTextReaderErrorCallback) {
2008 /* ok, it's our error handler! */
2009 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
2010 PyTuple_SetItem(py_retval, 0, pyCtxt->f);
2011 Py_XINCREF(pyCtxt->f);
2012 PyTuple_SetItem(py_retval, 1, pyCtxt->arg);
2013 Py_XINCREF(pyCtxt->arg);
2017 /* f is null or it's not our error handler */
2018 PyTuple_SetItem(py_retval, 0, Py_None);
2019 Py_XINCREF(Py_None);
2020 PyTuple_SetItem(py_retval, 1, Py_None);
2021 Py_XINCREF(Py_None);
2027 libxml_xmlFreeTextReader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
2028 xmlTextReaderPtr reader;
2029 PyObject *pyobj_reader;
2030 xmlTextReaderPyCtxtPtr pyCtxt;
2031 xmlTextReaderErrorFunc f;
2034 if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader))
2036 if (!PyCObject_Check(pyobj_reader)) {
2040 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
2041 if (reader == NULL) {
2046 xmlTextReaderGetErrorHandler(reader,&f,&arg);
2048 if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) {
2049 /* ok, it's our error handler! */
2050 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
2051 Py_XDECREF(pyCtxt->f);
2052 Py_XDECREF(pyCtxt->arg);
2056 * else, something wrong happened, because the error handler is
2057 * not owned by the python bindings...
2061 xmlFreeTextReader(reader);
2067 /************************************************************************
2069 * XPath extensions *
2071 ************************************************************************/
2074 libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs)
2076 PyObject *list, *cur, *result;
2077 xmlXPathObjectPtr obj;
2078 xmlXPathContextPtr rctxt;
2079 PyObject *current_function = NULL;
2080 const xmlChar *name;
2081 const xmlChar *ns_uri;
2086 rctxt = ctxt->context;
2089 name = rctxt->function;
2090 ns_uri = rctxt->functionURI;
2092 printf("libxml_xmlXPathFuncCallback called name %s URI %s\n", name,
2097 * Find the function, it should be there it was there at lookup
2099 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
2100 if ( /* TODO (ctxt == libxml_xpathCallbacks[i].ctx) && */
2101 (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) &&
2102 (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) {
2103 current_function = (*libxml_xpathCallbacks)[i].function;
2106 if (current_function == NULL) {
2108 ("libxml_xmlXPathFuncCallback: internal error %s not found !\n",
2113 list = PyTuple_New(nargs + 1);
2114 PyTuple_SetItem(list, 0, libxml_xmlXPathParserContextPtrWrap(ctxt));
2115 for (i = nargs - 1; i >= 0; i--) {
2116 obj = valuePop(ctxt);
2117 cur = libxml_xmlXPathObjectPtrWrap(obj);
2118 PyTuple_SetItem(list, i + 1, cur);
2120 result = PyEval_CallObject(current_function, list);
2123 obj = libxml_xmlXPathObjectPtrConvert(result);
2124 valuePush(ctxt, obj);
2127 static xmlXPathFunction
2128 libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar * name,
2129 const xmlChar * ns_uri)
2134 printf("libxml_xmlXPathFuncLookupFunc(%p, %s, %s) called\n",
2135 ctxt, name, ns_uri);
2138 * This is called once only. The address is then stored in the
2139 * XPath expression evaluation, the proper object to call can
2140 * then still be found using the execution context function
2141 * and functionURI fields.
2143 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
2144 if ((ctxt == (*libxml_xpathCallbacks)[i].ctx) &&
2145 (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) &&
2146 (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) {
2147 return (libxml_xmlXPathFuncCallback);
2154 libxml_xpathCallbacksInitialize(void)
2158 if (libxml_xpathCallbacksInitialized != 0)
2162 printf("libxml_xpathCallbacksInitialized called\n");
2164 libxml_xpathCallbacks = (libxml_xpathCallbackArray*)xmlMalloc(
2165 libxml_xpathCallbacksAllocd*sizeof(libxml_xpathCallback));
2167 for (i = 0; i < libxml_xpathCallbacksAllocd; i++) {
2168 (*libxml_xpathCallbacks)[i].ctx = NULL;
2169 (*libxml_xpathCallbacks)[i].name = NULL;
2170 (*libxml_xpathCallbacks)[i].ns_uri = NULL;
2171 (*libxml_xpathCallbacks)[i].function = NULL;
2173 libxml_xpathCallbacksInitialized = 1;
2177 libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObject * self,
2180 PyObject *py_retval;
2184 xmlXPathContextPtr ctx;
2185 PyObject *pyobj_ctx;
2189 if (!PyArg_ParseTuple
2190 (args, (char *) "OszO:registerXPathFunction", &pyobj_ctx, &name,
2194 ctx = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctx);
2195 if (libxml_xpathCallbacksInitialized == 0)
2196 libxml_xpathCallbacksInitialize();
2197 xmlXPathRegisterFuncLookup(ctx, libxml_xmlXPathFuncLookupFunc, ctx);
2199 if ((pyobj_ctx == NULL) || (name == NULL) || (pyobj_f == NULL)) {
2200 py_retval = libxml_intWrap(-1);
2204 printf("libxml_registerXPathFunction(%p, %s, %s) called\n",
2207 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
2208 if ((ctx == (*libxml_xpathCallbacks)[i].ctx) &&
2209 (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) &&
2210 (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) {
2211 Py_XINCREF(pyobj_f);
2212 Py_XDECREF((*libxml_xpathCallbacks)[i].function);
2213 (*libxml_xpathCallbacks)[i].function = pyobj_f;
2218 if (libxml_xpathCallbacksNb >= libxml_xpathCallbacksAllocd) {
2219 libxml_xpathCallbacksAllocd+=10;
2220 libxml_xpathCallbacks = (libxml_xpathCallbackArray*)xmlRealloc(
2221 libxml_xpathCallbacks,
2222 libxml_xpathCallbacksAllocd*sizeof(libxml_xpathCallback));
2224 i = libxml_xpathCallbacksNb++;
2225 Py_XINCREF(pyobj_f);
2226 (*libxml_xpathCallbacks)[i].ctx = ctx;
2227 (*libxml_xpathCallbacks)[i].name = xmlStrdup(name);
2228 (*libxml_xpathCallbacks)[i].ns_uri = xmlStrdup(ns_uri);
2229 (*libxml_xpathCallbacks)[i].function = pyobj_f;
2233 py_retval = libxml_intWrap((int) c_retval);
2237 /************************************************************************
2239 * Global properties access *
2241 ************************************************************************/
2243 libxml_name(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2245 PyObject *resultobj, *obj;
2249 if (!PyArg_ParseTuple(args, (char *) "O:name", &obj))
2251 cur = PyxmlNode_Get(obj);
2254 printf("libxml_name: cur = %p type %d\n", cur, cur->type);
2257 switch (cur->type) {
2258 case XML_DOCUMENT_NODE:
2259 #ifdef LIBXML_DOCB_ENABLED
2260 case XML_DOCB_DOCUMENT_NODE:
2262 case XML_HTML_DOCUMENT_NODE:{
2263 xmlDocPtr doc = (xmlDocPtr) cur;
2268 case XML_ATTRIBUTE_NODE:{
2269 xmlAttrPtr attr = (xmlAttrPtr) cur;
2274 case XML_NAMESPACE_DECL:{
2275 xmlNsPtr ns = (xmlNsPtr) cur;
2284 resultobj = libxml_constxmlCharPtrWrap(res);
2290 libxml_doc(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2292 PyObject *resultobj, *obj;
2296 if (!PyArg_ParseTuple(args, (char *) "O:doc", &obj))
2298 cur = PyxmlNode_Get(obj);
2301 printf("libxml_doc: cur = %p\n", cur);
2304 switch (cur->type) {
2305 case XML_DOCUMENT_NODE:
2306 #ifdef LIBXML_DOCB_ENABLED
2307 case XML_DOCB_DOCUMENT_NODE:
2309 case XML_HTML_DOCUMENT_NODE:
2312 case XML_ATTRIBUTE_NODE:{
2313 xmlAttrPtr attr = (xmlAttrPtr) cur;
2318 case XML_NAMESPACE_DECL:
2325 resultobj = libxml_xmlDocPtrWrap(res);
2330 libxml_properties(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2332 PyObject *resultobj, *obj;
2336 if (!PyArg_ParseTuple(args, (char *) "O:properties", &obj))
2338 cur = PyxmlNode_Get(obj);
2339 if ((cur != NULL) && (cur->type == XML_ELEMENT_NODE))
2340 res = cur->properties;
2343 resultobj = libxml_xmlAttrPtrWrap(res);
2348 libxml_next(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2350 PyObject *resultobj, *obj;
2354 if (!PyArg_ParseTuple(args, (char *) "O:next", &obj))
2356 cur = PyxmlNode_Get(obj);
2359 printf("libxml_next: cur = %p\n", cur);
2362 switch (cur->type) {
2363 case XML_DOCUMENT_NODE:
2364 #ifdef LIBXML_DOCB_ENABLED
2365 case XML_DOCB_DOCUMENT_NODE:
2367 case XML_HTML_DOCUMENT_NODE:
2370 case XML_ATTRIBUTE_NODE:{
2371 xmlAttrPtr attr = (xmlAttrPtr) cur;
2373 res = (xmlNodePtr) attr->next;
2376 case XML_NAMESPACE_DECL:{
2377 xmlNsPtr ns = (xmlNsPtr) cur;
2379 res = (xmlNodePtr) ns->next;
2387 resultobj = libxml_xmlNodePtrWrap(res);
2392 libxml_prev(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2394 PyObject *resultobj, *obj;
2398 if (!PyArg_ParseTuple(args, (char *) "O:prev", &obj))
2400 cur = PyxmlNode_Get(obj);
2403 printf("libxml_prev: cur = %p\n", cur);
2406 switch (cur->type) {
2407 case XML_DOCUMENT_NODE:
2408 #ifdef LIBXML_DOCB_ENABLED
2409 case XML_DOCB_DOCUMENT_NODE:
2411 case XML_HTML_DOCUMENT_NODE:
2414 case XML_ATTRIBUTE_NODE:{
2415 xmlAttrPtr attr = (xmlAttrPtr) cur;
2417 res = (xmlNodePtr) attr->prev;
2420 case XML_NAMESPACE_DECL:
2427 resultobj = libxml_xmlNodePtrWrap(res);
2432 libxml_children(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2434 PyObject *resultobj, *obj;
2438 if (!PyArg_ParseTuple(args, (char *) "O:children", &obj))
2440 cur = PyxmlNode_Get(obj);
2443 printf("libxml_children: cur = %p\n", cur);
2446 switch (cur->type) {
2447 case XML_ELEMENT_NODE:
2448 case XML_ENTITY_REF_NODE:
2449 case XML_ENTITY_NODE:
2451 case XML_COMMENT_NODE:
2452 case XML_DOCUMENT_NODE:
2453 #ifdef LIBXML_DOCB_ENABLED
2454 case XML_DOCB_DOCUMENT_NODE:
2456 case XML_HTML_DOCUMENT_NODE:
2458 res = cur->children;
2460 case XML_ATTRIBUTE_NODE:{
2461 xmlAttrPtr attr = (xmlAttrPtr) cur;
2463 res = attr->children;
2470 resultobj = libxml_xmlNodePtrWrap(res);
2475 libxml_last(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2477 PyObject *resultobj, *obj;
2481 if (!PyArg_ParseTuple(args, (char *) "O:last", &obj))
2483 cur = PyxmlNode_Get(obj);
2486 printf("libxml_last: cur = %p\n", cur);
2489 switch (cur->type) {
2490 case XML_ELEMENT_NODE:
2491 case XML_ENTITY_REF_NODE:
2492 case XML_ENTITY_NODE:
2494 case XML_COMMENT_NODE:
2495 case XML_DOCUMENT_NODE:
2496 #ifdef LIBXML_DOCB_ENABLED
2497 case XML_DOCB_DOCUMENT_NODE:
2499 case XML_HTML_DOCUMENT_NODE:
2503 case XML_ATTRIBUTE_NODE:{
2504 xmlAttrPtr attr = (xmlAttrPtr) cur;
2512 resultobj = libxml_xmlNodePtrWrap(res);
2517 libxml_parent(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2519 PyObject *resultobj, *obj;
2523 if (!PyArg_ParseTuple(args, (char *) "O:parent", &obj))
2525 cur = PyxmlNode_Get(obj);
2528 printf("libxml_parent: cur = %p\n", cur);
2531 switch (cur->type) {
2532 case XML_DOCUMENT_NODE:
2533 case XML_HTML_DOCUMENT_NODE:
2534 #ifdef LIBXML_DOCB_ENABLED
2535 case XML_DOCB_DOCUMENT_NODE:
2539 case XML_ATTRIBUTE_NODE:{
2540 xmlAttrPtr attr = (xmlAttrPtr) cur;
2545 case XML_ENTITY_DECL:
2546 case XML_NAMESPACE_DECL:
2547 case XML_XINCLUDE_START:
2548 case XML_XINCLUDE_END:
2555 resultobj = libxml_xmlNodePtrWrap(res);
2560 libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2562 PyObject *resultobj, *obj;
2564 const xmlChar *res = NULL;
2566 if (!PyArg_ParseTuple(args, (char *) "O:last", &obj))
2568 cur = PyxmlNode_Get(obj);
2571 printf("libxml_type: cur = %p\n", cur);
2574 switch (cur->type) {
2575 case XML_ELEMENT_NODE:
2576 res = (const xmlChar *) "element";
2578 case XML_ATTRIBUTE_NODE:
2579 res = (const xmlChar *) "attribute";
2582 res = (const xmlChar *) "text";
2584 case XML_CDATA_SECTION_NODE:
2585 res = (const xmlChar *) "cdata";
2587 case XML_ENTITY_REF_NODE:
2588 res = (const xmlChar *) "entity_ref";
2590 case XML_ENTITY_NODE:
2591 res = (const xmlChar *) "entity";
2594 res = (const xmlChar *) "pi";
2596 case XML_COMMENT_NODE:
2597 res = (const xmlChar *) "comment";
2599 case XML_DOCUMENT_NODE:
2600 res = (const xmlChar *) "document_xml";
2602 case XML_DOCUMENT_TYPE_NODE:
2603 res = (const xmlChar *) "doctype";
2605 case XML_DOCUMENT_FRAG_NODE:
2606 res = (const xmlChar *) "fragment";
2608 case XML_NOTATION_NODE:
2609 res = (const xmlChar *) "notation";
2611 case XML_HTML_DOCUMENT_NODE:
2612 res = (const xmlChar *) "document_html";
2615 res = (const xmlChar *) "dtd";
2617 case XML_ELEMENT_DECL:
2618 res = (const xmlChar *) "elem_decl";
2620 case XML_ATTRIBUTE_DECL:
2621 res = (const xmlChar *) "attribute_decl";
2623 case XML_ENTITY_DECL:
2624 res = (const xmlChar *) "entity_decl";
2626 case XML_NAMESPACE_DECL:
2627 res = (const xmlChar *) "namespace";
2629 case XML_XINCLUDE_START:
2630 res = (const xmlChar *) "xinclude_start";
2632 case XML_XINCLUDE_END:
2633 res = (const xmlChar *) "xinclude_end";
2635 #ifdef LIBXML_DOCB_ENABLED
2636 case XML_DOCB_DOCUMENT_NODE:
2637 res = (const xmlChar *) "document_docbook";
2642 printf("libxml_type: cur = %p: %s\n", cur, res);
2645 resultobj = libxml_constxmlCharPtrWrap(res);
2649 /************************************************************************
2651 * Specific accessor functions *
2653 ************************************************************************/
2655 libxml_xmlNodeGetNsDefs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2657 PyObject *py_retval;
2660 PyObject *pyobj_node;
2662 if (!PyArg_ParseTuple
2663 (args, (char *) "O:xmlNodeGetNsDefs", &pyobj_node))
2665 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2667 if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) {
2671 c_retval = node->nsDef;
2672 py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval);
2677 libxml_xmlNodeRemoveNsDef(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2679 PyObject *py_retval;
2682 PyObject *pyobj_node;
2686 if (!PyArg_ParseTuple
2687 (args, (char *) "Oz:xmlNodeRemoveNsDef", &pyobj_node, &href))
2689 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2692 if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) {
2705 while (ns != NULL) {
2706 if (xmlStrEqual(ns->href, href)) {
2708 prev->next = ns->next;
2710 node->nsDef = ns->next;
2721 py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval);
2726 libxml_xmlNodeGetNs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2728 PyObject *py_retval;
2731 PyObject *pyobj_node;
2733 if (!PyArg_ParseTuple(args, (char *) "O:xmlNodeGetNs", &pyobj_node))
2735 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2737 if ((node == NULL) ||
2738 ((node->type != XML_ELEMENT_NODE) &&
2739 (node->type != XML_ATTRIBUTE_NODE))) {
2743 c_retval = node->ns;
2744 py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval);
2748 #ifdef LIBXML_OUTPUT_ENABLED
2749 /************************************************************************
2751 * Serialization front-end *
2753 ************************************************************************/
2756 libxml_serializeNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2758 PyObject *py_retval = NULL;
2760 PyObject *pyobj_node;
2763 const char *encoding;
2765 xmlSaveCtxtPtr ctxt;
2769 if (!PyArg_ParseTuple(args, (char *) "Ozi:serializeNode", &pyobj_node,
2770 &encoding, &format))
2772 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2778 if (node->type == XML_DOCUMENT_NODE) {
2779 doc = (xmlDocPtr) node;
2781 #ifdef LIBXML_HTML_ENABLED
2782 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2783 doc = (xmlDocPtr) node;
2787 if (node->type == XML_NAMESPACE_DECL)
2791 if ((doc == NULL) || (doc->type == XML_DOCUMENT_NODE)) {
2792 #ifdef LIBXML_HTML_ENABLED
2793 } else if (doc->type == XML_HTML_DOCUMENT_NODE) {
2794 #endif /* LIBXML_HTML_ENABLED */
2802 buf = xmlBufferCreate();
2807 if (format) options |= XML_SAVE_FORMAT;
2808 ctxt = xmlSaveToBuffer(buf, encoding, options);
2815 xmlSaveDoc(ctxt, doc);
2817 xmlSaveTree(ctxt, node);
2820 c_retval = buf->content;
2821 buf->content = NULL;
2824 py_retval = libxml_charPtrWrap((char *) c_retval);
2830 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2832 PyObject *py_file = NULL;
2834 PyObject *pyobj_node;
2837 const char *encoding;
2840 xmlOutputBufferPtr buf;
2841 xmlCharEncodingHandlerPtr handler = NULL;
2843 if (!PyArg_ParseTuple(args, (char *) "OOzi:serializeNode", &pyobj_node,
2844 &py_file, &encoding, &format))
2846 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2849 return (PyInt_FromLong((long) -1));
2851 if ((py_file == NULL) || (!(PyFile_Check(py_file)))) {
2852 return (PyInt_FromLong((long) -1));
2854 output = PyFile_AsFile(py_file);
2855 if (output == NULL) {
2856 return (PyInt_FromLong((long) -1));
2859 if (node->type == XML_DOCUMENT_NODE) {
2860 doc = (xmlDocPtr) node;
2861 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2862 doc = (xmlDocPtr) node;
2866 #ifdef LIBXML_HTML_ENABLED
2867 if (doc->type == XML_HTML_DOCUMENT_NODE) {
2868 if (encoding == NULL)
2869 encoding = (const char *) htmlGetMetaEncoding(doc);
2871 #endif /* LIBXML_HTML_ENABLED */
2872 if (encoding != NULL) {
2873 handler = xmlFindCharEncodingHandler(encoding);
2874 if (handler == NULL) {
2875 return (PyInt_FromLong((long) -1));
2878 if (doc->type == XML_HTML_DOCUMENT_NODE) {
2879 if (handler == NULL)
2880 handler = xmlFindCharEncodingHandler("HTML");
2881 if (handler == NULL)
2882 handler = xmlFindCharEncodingHandler("ascii");
2885 buf = xmlOutputBufferCreateFile(output, handler);
2886 if (node->type == XML_DOCUMENT_NODE) {
2887 len = xmlSaveFormatFileTo(buf, doc, encoding, format);
2888 #ifdef LIBXML_HTML_ENABLED
2889 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2890 htmlDocContentDumpFormatOutput(buf, doc, encoding, format);
2891 len = xmlOutputBufferClose(buf);
2892 } else if (doc->type == XML_HTML_DOCUMENT_NODE) {
2893 htmlNodeDumpFormatOutput(buf, doc, node, encoding, format);
2894 len = xmlOutputBufferClose(buf);
2895 #endif /* LIBXML_HTML_ENABLED */
2897 xmlNodeDumpOutput(buf, doc, node, 0, format, encoding);
2898 len = xmlOutputBufferClose(buf);
2900 return (PyInt_FromLong((long) len));
2902 #endif /* LIBXML_OUTPUT_ENABLED */
2904 /************************************************************************
2908 ************************************************************************/
2910 libxml_xmlNewNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2912 PyObject *py_retval;
2916 if (!PyArg_ParseTuple(args, (char *) "s:xmlNewNode", &name))
2918 node = (xmlNodePtr) xmlNewNode(NULL, name);
2920 printf("NewNode: %s : %p\n", name, (void *) node);
2927 py_retval = libxml_xmlNodePtrWrap(node);
2932 /************************************************************************
2934 * Local Catalog stuff *
2936 ************************************************************************/
2938 libxml_addLocalCatalog(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2941 xmlParserCtxtPtr ctxt;
2942 PyObject *pyobj_ctxt;
2944 if (!PyArg_ParseTuple(args, (char *)"Os:addLocalCatalog", &pyobj_ctxt, &URL))
2947 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
2950 ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs, URL);
2954 printf("LocalCatalog: %s\n", URL);
2961 #ifdef LIBXML_SCHEMAS_ENABLED
2963 /************************************************************************
2965 * RelaxNG error handler registration *
2967 ************************************************************************/
2974 } xmlRelaxNGValidCtxtPyCtxt;
2975 typedef xmlRelaxNGValidCtxtPyCtxt *xmlRelaxNGValidCtxtPyCtxtPtr;
2978 libxml_xmlRelaxNGValidityGenericErrorFuncHandler(void *ctx, char *str)
2982 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
2985 printf("libxml_xmlRelaxNGValidityGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str);
2988 pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx;
2990 list = PyTuple_New(2);
2991 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
2992 PyTuple_SetItem(list, 1, pyCtxt->arg);
2993 Py_XINCREF(pyCtxt->arg);
2994 result = PyEval_CallObject(pyCtxt->error, list);
2997 /* TODO: manage for the exception to be propagated... */
3005 libxml_xmlRelaxNGValidityGenericWarningFuncHandler(void *ctx, char *str)
3009 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
3012 printf("libxml_xmlRelaxNGValidityGenericWarningFuncHandler(%p, %s, ...) called\n", ctx, str);
3015 pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx;
3017 list = PyTuple_New(2);
3018 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
3019 PyTuple_SetItem(list, 1, pyCtxt->arg);
3020 Py_XINCREF(pyCtxt->arg);
3021 result = PyEval_CallObject(pyCtxt->warn, list);
3024 /* TODO: manage for the exception to be propagated... */
3032 libxml_xmlRelaxNGValidityErrorFunc(void *ctx, const char *msg, ...)
3037 libxml_xmlRelaxNGValidityGenericErrorFuncHandler(ctx, libxml_buildMessage(msg, ap));
3042 libxml_xmlRelaxNGValidityWarningFunc(void *ctx, const char *msg, ...)
3047 libxml_xmlRelaxNGValidityGenericWarningFuncHandler(ctx, libxml_buildMessage(msg, ap));
3052 libxml_xmlRelaxNGSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
3054 PyObject *py_retval;
3055 PyObject *pyobj_error;
3056 PyObject *pyobj_warn;
3057 PyObject *pyobj_ctx;
3058 PyObject *pyobj_arg = Py_None;
3059 xmlRelaxNGValidCtxtPtr ctxt;
3060 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
3062 if (!PyArg_ParseTuple
3063 (args, (char *) "OOO|O:xmlRelaxNGSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg))
3067 printf("libxml_xmlRelaxNGSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn);
3070 ctxt = PyrelaxNgValidCtxt_Get(pyobj_ctx);
3071 if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == -1)
3073 py_retval = libxml_intWrap(-1);
3079 /* first time to set the error handlers */
3080 pyCtxt = xmlMalloc(sizeof(xmlRelaxNGValidCtxtPyCtxt));
3081 if (pyCtxt == NULL) {
3082 py_retval = libxml_intWrap(-1);
3085 memset(pyCtxt, 0, sizeof(xmlRelaxNGValidCtxtPyCtxt));
3088 /* TODO: check warn and error is a function ! */
3089 Py_XDECREF(pyCtxt->error);
3090 Py_XINCREF(pyobj_error);
3091 pyCtxt->error = pyobj_error;
3093 Py_XDECREF(pyCtxt->warn);
3094 Py_XINCREF(pyobj_warn);
3095 pyCtxt->warn = pyobj_warn;
3097 Py_XDECREF(pyCtxt->arg);
3098 Py_XINCREF(pyobj_arg);
3099 pyCtxt->arg = pyobj_arg;
3101 xmlRelaxNGSetValidErrors(ctxt, &libxml_xmlRelaxNGValidityErrorFunc, &libxml_xmlRelaxNGValidityWarningFunc, pyCtxt);
3103 py_retval = libxml_intWrap(1);
3108 libxml_xmlRelaxNGFreeValidCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
3109 xmlRelaxNGValidCtxtPtr ctxt;
3110 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
3111 PyObject *pyobj_ctxt;
3113 if (!PyArg_ParseTuple(args, (char *)"O:xmlRelaxNGFreeValidCtxt", &pyobj_ctxt))
3115 ctxt = (xmlRelaxNGValidCtxtPtr) PyrelaxNgValidCtxt_Get(pyobj_ctxt);
3117 if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == 0)
3121 Py_XDECREF(pyCtxt->error);
3122 Py_XDECREF(pyCtxt->warn);
3123 Py_XDECREF(pyCtxt->arg);
3128 xmlRelaxNGFreeValidCtxt(ctxt);
3138 } xmlSchemaValidCtxtPyCtxt;
3139 typedef xmlSchemaValidCtxtPyCtxt *xmlSchemaValidCtxtPyCtxtPtr;
3142 libxml_xmlSchemaValidityGenericErrorFuncHandler(void *ctx, char *str)
3146 xmlSchemaValidCtxtPyCtxtPtr pyCtxt;
3149 printf("libxml_xmlSchemaValiditiyGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str);
3152 pyCtxt = (xmlSchemaValidCtxtPyCtxtPtr) ctx;
3154 list = PyTuple_New(2);
3155 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
3156 PyTuple_SetItem(list, 1, pyCtxt->arg);
3157 Py_XINCREF(pyCtxt->arg);
3158 result = PyEval_CallObject(pyCtxt->error, list);
3161 /* TODO: manage for the exception to be propagated... */
3169 libxml_xmlSchemaValidityGenericWarningFuncHandler(void *ctx, char *str)
3173 xmlSchemaValidCtxtPyCtxtPtr pyCtxt;
3176 printf("libxml_xmlSchemaValidityGenericWarningFuncHandler(%p, %s, ...) called\n", ctx, str);
3179 pyCtxt = (xmlSchemaValidCtxtPyCtxtPtr) ctx;
3181 list = PyTuple_New(2);
3182 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
3183 PyTuple_SetItem(list, 1, pyCtxt->arg);
3184 Py_XINCREF(pyCtxt->arg);
3185 result = PyEval_CallObject(pyCtxt->warn, list);
3188 /* TODO: manage for the exception to be propagated... */
3196 libxml_xmlSchemaValidityErrorFunc(void *ctx, const char *msg, ...)
3201 libxml_xmlSchemaValidityGenericErrorFuncHandler(ctx, libxml_buildMessage(msg, ap));
3206 libxml_xmlSchemaValidityWarningFunc(void *ctx, const char *msg, ...)
3211 libxml_xmlSchemaValidityGenericWarningFuncHandler(ctx, libxml_buildMessage(msg, ap));
3216 libxml_xmlSchemaSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
3218 PyObject *py_retval;
3219 PyObject *pyobj_error;
3220 PyObject *pyobj_warn;
3221 PyObject *pyobj_ctx;
3222 PyObject *pyobj_arg = Py_None;
3223 xmlSchemaValidCtxtPtr ctxt;
3224 xmlSchemaValidCtxtPyCtxtPtr pyCtxt;
3226 if (!PyArg_ParseTuple
3227 (args, (char *) "OOO|O:xmlSchemaSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg))
3231 printf("libxml_xmlSchemaSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn);
3234 ctxt = PySchemaValidCtxt_Get(pyobj_ctx);
3235 if (xmlSchemaGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == -1)
3237 py_retval = libxml_intWrap(-1);
3243 /* first time to set the error handlers */
3244 pyCtxt = xmlMalloc(sizeof(xmlSchemaValidCtxtPyCtxt));
3245 if (pyCtxt == NULL) {
3246 py_retval = libxml_intWrap(-1);
3249 memset(pyCtxt, 0, sizeof(xmlSchemaValidCtxtPyCtxt));
3252 /* TODO: check warn and error is a function ! */
3253 Py_XDECREF(pyCtxt->error);
3254 Py_XINCREF(pyobj_error);
3255 pyCtxt->error = pyobj_error;
3257 Py_XDECREF(pyCtxt->warn);
3258 Py_XINCREF(pyobj_warn);
3259 pyCtxt->warn = pyobj_warn;
3261 Py_XDECREF(pyCtxt->arg);
3262 Py_XINCREF(pyobj_arg);
3263 pyCtxt->arg = pyobj_arg;
3265 xmlSchemaSetValidErrors(ctxt, &libxml_xmlSchemaValidityErrorFunc, &libxml_xmlSchemaValidityWarningFunc, pyCtxt);
3267 py_retval = libxml_intWrap(1);
3272 libxml_xmlSchemaFreeValidCtxt(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
3274 xmlSchemaValidCtxtPtr ctxt;
3275 xmlSchemaValidCtxtPyCtxtPtr pyCtxt;
3276 PyObject *pyobj_ctxt;
3278 if (!PyArg_ParseTuple(args, (char *)"O:xmlSchemaFreeValidCtxt", &pyobj_ctxt))
3280 ctxt = (xmlSchemaValidCtxtPtr) PySchemaValidCtxt_Get(pyobj_ctxt);
3282 if (xmlSchemaGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == 0)
3286 Py_XDECREF(pyCtxt->error);
3287 Py_XDECREF(pyCtxt->warn);
3288 Py_XDECREF(pyCtxt->arg);
3293 xmlSchemaFreeValidCtxt(ctxt);
3300 #ifdef LIBXML_C14N_ENABLED
3301 #ifdef LIBXML_OUTPUT_ENABLED
3303 /************************************************************************
3305 * XML Canonicalization c14n *
3307 ************************************************************************/
3310 PyxmlNodeSet_Convert(PyObject *py_nodeset, xmlNodeSetPtr *result)
3312 xmlNodeSetPtr nodeSet;
3315 if (PyTuple_Check(py_nodeset))
3317 else if (PyList_Check(py_nodeset))
3319 else if (py_nodeset == Py_None) {
3324 PyErr_SetString(PyExc_TypeError,
3325 "must be a tuple or list of nodes.");
3329 nodeSet = (xmlNodeSetPtr) xmlMalloc(sizeof(xmlNodeSet));
3330 if (nodeSet == NULL) {
3331 PyErr_SetString(PyExc_MemoryError, "");
3335 nodeSet->nodeNr = 0;
3336 nodeSet->nodeMax = (is_tuple
3337 ? PyTuple_GET_SIZE(py_nodeset)
3338 : PyList_GET_SIZE(py_nodeset));
3340 = (xmlNodePtr *) xmlMalloc (nodeSet->nodeMax
3341 * sizeof(xmlNodePtr));
3342 if (nodeSet->nodeTab == NULL) {
3344 PyErr_SetString(PyExc_MemoryError, "");
3347 memset(nodeSet->nodeTab, 0 ,
3348 nodeSet->nodeMax * sizeof(xmlNodePtr));
3352 for (idx=0; idx < nodeSet->nodeMax; ++idx) {
3354 PyxmlNode_Get (is_tuple
3355 ? PyTuple_GET_ITEM(py_nodeset, idx)
3356 : PyList_GET_ITEM(py_nodeset, idx));
3358 nodeSet->nodeTab[nodeSet->nodeNr++] = pynode;
3366 PystringSet_Convert(PyObject *py_strings, xmlChar *** result)
3368 /* NOTE: the array should be freed, but the strings are shared
3369 with the python strings and so must not be freed. */
3376 if (PyTuple_Check(py_strings))
3378 else if (PyList_Check(py_strings))
3380 else if (py_strings == Py_None) {
3385 PyErr_SetString(PyExc_TypeError,
3386 "must be a tuple or list of strings.");
3391 ? PyTuple_GET_SIZE(py_strings)
3392 : PyList_GET_SIZE(py_strings));
3394 strings = (xmlChar **) xmlMalloc(sizeof(xmlChar *) * count);
3396 if (strings == NULL) {
3397 PyErr_SetString(PyExc_MemoryError, "");
3401 memset(strings, 0 , sizeof(xmlChar *) * count);
3405 for (idx=0; idx < count; ++idx) {
3406 char* s = PyString_AsString
3408 ? PyTuple_GET_ITEM(py_strings, idx)
3409 : PyList_GET_ITEM(py_strings, idx));
3411 strings[init_index++] = (xmlChar *)s;
3414 PyErr_SetString(PyExc_TypeError,
3415 "must be a tuple or list of strings.");
3426 libxml_C14NDocDumpMemory(ATTRIBUTE_UNUSED PyObject * self,
3429 PyObject *py_retval = NULL;
3431 PyObject *pyobj_doc;
3432 PyObject *pyobj_nodes;
3434 PyObject *pyobj_prefixes;
3438 xmlNodeSetPtr nodes;
3439 xmlChar **prefixes = NULL;
3444 if (!PyArg_ParseTuple(args, (char *) "OOiOi:C14NDocDumpMemory",
3452 doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc);
3454 PyErr_SetString(PyExc_TypeError, "bad document.");
3458 result = PyxmlNodeSet_Convert(pyobj_nodes, &nodes);
3459 if (result < 0) return NULL;
3462 result = PystringSet_Convert(pyobj_prefixes, &prefixes);
3465 xmlFree(nodes->nodeTab);
3472 result = xmlC14NDocDumpMemory(doc,
3480 xmlFree(nodes->nodeTab);
3484 xmlChar ** idx = prefixes;
3485 while (*idx) xmlFree(*(idx++));
3490 PyErr_SetString(PyExc_Exception,
3491 "libxml2 xmlC14NDocDumpMemory failure.");
3495 py_retval = PyString_FromStringAndSize((const char *) doc_txt,
3503 libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self,
3506 PyObject *pyobj_doc;
3508 PyObject *pyobj_nodes;
3510 PyObject *pyobj_prefixes;
3514 xmlNodeSetPtr nodes;
3515 xmlChar **prefixes = NULL;
3517 xmlOutputBufferPtr buf;
3522 if (!PyArg_ParseTuple(args, (char *) "OOiOiO:C14NDocSaveTo",
3531 doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc);
3533 PyErr_SetString(PyExc_TypeError, "bad document.");
3537 if ((py_file == NULL) || (!(PyFile_Check(py_file)))) {
3538 PyErr_SetString(PyExc_TypeError, "bad file.");
3541 output = PyFile_AsFile(py_file);
3542 if (output == NULL) {
3543 PyErr_SetString(PyExc_TypeError, "bad file.");
3546 buf = xmlOutputBufferCreateFile(output, NULL);
3548 result = PyxmlNodeSet_Convert(pyobj_nodes, &nodes);
3549 if (result < 0) return NULL;
3552 result = PystringSet_Convert(pyobj_prefixes, &prefixes);
3555 xmlFree(nodes->nodeTab);
3562 result = xmlC14NDocSaveTo(doc,
3570 xmlFree(nodes->nodeTab);
3574 xmlChar ** idx = prefixes;
3575 while (*idx) xmlFree(*(idx++));
3579 len = xmlOutputBufferClose(buf);
3582 PyErr_SetString(PyExc_Exception,
3583 "libxml2 xmlC14NDocSaveTo failure.");
3587 return PyInt_FromLong((long) len);
3594 libxml_getObjDesc(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3599 if (!PyArg_ParseTuple(args, (char *)"O:getObjDesc", &obj))
3601 str = PyCObject_GetDesc(obj);
3602 return Py_BuildValue((char *)"s", str);
3606 libxml_compareNodesEqual(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3608 PyObject *py_node1, *py_node2;
3609 xmlNodePtr node1, node2;
3611 if (!PyArg_ParseTuple(args, (char *)"OO:compareNodesEqual",
3612 &py_node1, &py_node2))
3614 /* To compare two node objects, we compare their pointer addresses */
3615 node1 = PyxmlNode_Get(py_node1);
3616 node2 = PyxmlNode_Get(py_node2);
3617 if ( node1 == node2 )
3618 return Py_BuildValue((char *)"i", 1);
3620 return Py_BuildValue((char *)"i", 0);
3625 libxml_nodeHash(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
3630 if (!PyArg_ParseTuple(args, (char *)"O:nodeHash", &py_node1))
3632 /* For simplicity, we use the node pointer address as a hash value */
3633 node1 = PyxmlNode_Get(py_node1);
3635 return PyLong_FromVoidPtr(node1);
3639 /************************************************************************
3641 * The registration stuff *
3643 ************************************************************************/
3644 static PyMethodDef libxmlMethods[] = {
3645 #include "libxml2-export.c"
3646 {(char *) "name", libxml_name, METH_VARARGS, NULL},
3647 {(char *) "children", libxml_children, METH_VARARGS, NULL},
3648 {(char *) "properties", libxml_properties, METH_VARARGS, NULL},
3649 {(char *) "last", libxml_last, METH_VARARGS, NULL},
3650 {(char *) "prev", libxml_prev, METH_VARARGS, NULL},
3651 {(char *) "next", libxml_next, METH_VARARGS, NULL},
3652 {(char *) "parent", libxml_parent, METH_VARARGS, NULL},
3653 {(char *) "type", libxml_type, METH_VARARGS, NULL},
3654 {(char *) "doc", libxml_doc, METH_VARARGS, NULL},
3655 {(char *) "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL},
3656 {(char *) "xmlNodeRemoveNsDef", libxml_xmlNodeRemoveNsDef, METH_VARARGS, NULL},
3657 {(char *)"xmlSetValidErrors", libxml_xmlSetValidErrors, METH_VARARGS, NULL},
3658 {(char *)"xmlFreeValidCtxt", libxml_xmlFreeValidCtxt, METH_VARARGS, NULL},
3659 #ifdef LIBXML_OUTPUT_ENABLED
3660 {(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL},
3661 {(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL},
3662 {(char *) "outputBufferCreate", libxml_xmlCreateOutputBuffer, METH_VARARGS, NULL},
3663 {(char *) "outputBufferGetPythonFile", libxml_outputBufferGetPythonFile, METH_VARARGS, NULL},
3664 {(char *) "xmlOutputBufferClose", libxml_xmlOutputBufferClose, METH_VARARGS, NULL},
3665 { (char *)"xmlOutputBufferFlush", libxml_xmlOutputBufferFlush, METH_VARARGS, NULL },
3666 { (char *)"xmlSaveFileTo", libxml_xmlSaveFileTo, METH_VARARGS, NULL },
3667 { (char *)"xmlSaveFormatFileTo", libxml_xmlSaveFormatFileTo, METH_VARARGS, NULL },
3668 #endif /* LIBXML_OUTPUT_ENABLED */
3669 {(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
3670 {(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},
3671 {(char *)"xmlRegisterErrorHandler", libxml_xmlRegisterErrorHandler, METH_VARARGS, NULL },
3672 {(char *)"xmlParserCtxtSetErrorHandler", libxml_xmlParserCtxtSetErrorHandler, METH_VARARGS, NULL },
3673 {(char *)"xmlParserCtxtGetErrorHandler", libxml_xmlParserCtxtGetErrorHandler, METH_VARARGS, NULL },
3674 {(char *)"xmlFreeParserCtxt", libxml_xmlFreeParserCtxt, METH_VARARGS, NULL },
3675 #ifdef LIBXML_READER_ENABLED
3676 {(char *)"xmlTextReaderSetErrorHandler", libxml_xmlTextReaderSetErrorHandler, METH_VARARGS, NULL },
3677 {(char *)"xmlTextReaderGetErrorHandler", libxml_xmlTextReaderGetErrorHandler, METH_VARARGS, NULL },
3678 {(char *)"xmlFreeTextReader", libxml_xmlFreeTextReader, METH_VARARGS, NULL },
3680 {(char *)"addLocalCatalog", libxml_addLocalCatalog, METH_VARARGS, NULL },
3681 #ifdef LIBXML_SCHEMAS_ENABLED
3682 {(char *)"xmlRelaxNGSetValidErrors", libxml_xmlRelaxNGSetValidErrors, METH_VARARGS, NULL},
3683 {(char *)"xmlRelaxNGFreeValidCtxt", libxml_xmlRelaxNGFreeValidCtxt, METH_VARARGS, NULL},
3684 {(char *)"xmlSchemaSetValidErrors", libxml_xmlSchemaSetValidErrors, METH_VARARGS, NULL},
3685 {(char *)"xmlSchemaFreeValidCtxt", libxml_xmlSchemaFreeValidCtxt, METH_VARARGS, NULL},
3687 #ifdef LIBXML_C14N_ENABLED
3688 #ifdef LIBXML_OUTPUT_ENABLED
3689 {(char *)"xmlC14NDocDumpMemory", libxml_C14NDocDumpMemory, METH_VARARGS, NULL},
3690 {(char *)"xmlC14NDocSaveTo", libxml_C14NDocSaveTo, METH_VARARGS, NULL},
3693 {(char *) "getObjDesc", libxml_getObjDesc, METH_VARARGS, NULL},
3694 {(char *) "compareNodesEqual", libxml_compareNodesEqual, METH_VARARGS, NULL},
3695 {(char *) "nodeHash", libxml_nodeHash, METH_VARARGS, NULL},
3696 {NULL, NULL, 0, NULL}
3699 #ifdef MERGED_MODULES
3700 extern void initlibxsltmod(void);
3704 initlibxml2mod(void)
3706 static int initialized = 0;
3708 if (initialized != 0)
3711 /* intialize the python extension module */
3712 Py_InitModule((char *) "libxml2mod", libxmlMethods);
3714 /* initialize libxml2 */
3716 libxml_xmlErrorInitialize();
3720 #ifdef MERGED_MODULES