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_wrap.h"
26 #include "libxml2-py.h"
28 #if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(vsnprintf)
29 #define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
30 #elif defined(WITH_TRIO)
32 #define vsnprintf trio_vsnprintf
36 /* #define DEBUG_SAX */
37 /* #define DEBUG_XPATH */
38 /* #define DEBUG_ERROR */
39 /* #define DEBUG_MEMORY */
40 /* #define DEBUG_FILES */
41 /* #define DEBUG_LOADER */
43 void initlibxml2mod(void);
48 * macro to flag unimplemented blocks
51 xmlGenericError(xmlGenericErrorContext, \
52 "Unimplemented block at %s:%d\n", \
55 /************************************************************************
57 * Memory debug interface *
59 ************************************************************************/
62 extern void xmlMemFree(void *ptr);
63 extern void *xmlMemMalloc(size_t size);
64 extern void *xmlMemRealloc(void *ptr, size_t size);
65 extern char *xmlMemoryStrdup(const char *str);
68 static int libxmlMemoryDebugActivated = 0;
69 static long libxmlMemoryAllocatedBase = 0;
71 static int libxmlMemoryDebug = 0;
72 static xmlFreeFunc freeFunc = NULL;
73 static xmlMallocFunc mallocFunc = NULL;
74 static xmlReallocFunc reallocFunc = NULL;
75 static xmlStrdupFunc strdupFunc = NULL;
78 libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
84 if (!PyArg_ParseTuple(args, (char *) "i:xmlDebugMemory", &activate))
88 printf("libxml_xmlDebugMemory(%d) called\n", activate);
92 if (libxmlMemoryDebug == 0) {
94 * First initialize the library and grab the old memory handlers
95 * and switch the library to memory debugging
97 xmlMemGet((xmlFreeFunc *) & freeFunc,
98 (xmlMallocFunc *) & mallocFunc,
99 (xmlReallocFunc *) & reallocFunc,
100 (xmlStrdupFunc *) & strdupFunc);
101 if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) &&
102 (reallocFunc == xmlMemRealloc) &&
103 (strdupFunc == xmlMemoryStrdup)) {
104 libxmlMemoryAllocatedBase = xmlMemUsed();
106 ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
107 xmlMemRealloc, xmlMemoryStrdup);
110 libxmlMemoryAllocatedBase = xmlMemUsed();
114 } else if (libxmlMemoryDebugActivated == 0) {
115 libxmlMemoryAllocatedBase = xmlMemUsed();
118 ret = xmlMemUsed() - libxmlMemoryAllocatedBase;
120 libxmlMemoryDebug = 1;
121 libxmlMemoryDebugActivated = 1;
123 if (libxmlMemoryDebugActivated == 1)
124 ret = xmlMemUsed() - libxmlMemoryAllocatedBase;
127 libxmlMemoryDebugActivated = 0;
130 py_retval = libxml_longWrap(ret);
135 libxml_xmlDumpMemory(ATTRIBUTE_UNUSED PyObject * self,
136 ATTRIBUTE_UNUSED PyObject * args)
139 if (libxmlMemoryDebug != 0)
145 /************************************************************************
147 * Handling Python FILE I/O at the C level *
148 * The raw I/O attack diectly the File objects, while the *
149 * other routines address the ioWrapper instance instead *
151 ************************************************************************/
154 * xmlPythonFileCloseUnref:
155 * @context: the I/O context
157 * Close an I/O channel
160 xmlPythonFileCloseRaw (void * context) {
161 PyObject *file, *ret;
164 printf("xmlPythonFileCloseUnref\n");
166 file = (PyObject *) context;
167 if (file == NULL) return(-1);
168 ret = PyEval_CallMethod(file, (char *) "close", (char *) "()");
177 * xmlPythonFileReadRaw:
178 * @context: the I/O context
179 * @buffer: where to drop data
180 * @len: number of bytes to write
182 * Read @len bytes to @buffer from the Python file in the I/O channel
184 * Returns the number of bytes read
187 xmlPythonFileReadRaw (void * context, char * buffer, int len) {
194 printf("xmlPythonFileReadRaw: %d\n", len);
196 file = (PyObject *) context;
197 if (file == NULL) return(-1);
198 ret = PyEval_CallMethod(file, (char *) "read", (char *) "(i)", len);
200 printf("xmlPythonFileReadRaw: result is NULL\n");
202 } else if (PyString_Check(ret)) {
203 lenread = PyString_Size(ret);
204 data = PyString_AsString(ret);
206 memcpy(buffer, data, len);
208 memcpy(buffer, data, lenread);
211 printf("xmlPythonFileReadRaw: result is not a String\n");
219 * @context: the I/O context
220 * @buffer: where to drop data
221 * @len: number of bytes to write
223 * Read @len bytes to @buffer from the I/O channel.
225 * Returns the number of bytes read
228 xmlPythonFileRead (void * context, char * buffer, int len) {
235 printf("xmlPythonFileRead: %d\n", len);
237 file = (PyObject *) context;
238 if (file == NULL) return(-1);
239 ret = PyEval_CallMethod(file, (char *) "io_read", (char *) "(i)", len);
241 printf("xmlPythonFileRead: result is NULL\n");
243 } else if (PyString_Check(ret)) {
244 lenread = PyString_Size(ret);
245 data = PyString_AsString(ret);
247 memcpy(buffer, data, len);
249 memcpy(buffer, data, lenread);
252 printf("xmlPythonFileRead: result is not a String\n");
260 * @context: the I/O context
261 * @buffer: where to drop data
262 * @len: number of bytes to write
264 * Write @len bytes from @buffer to the I/O channel.
266 * Returns the number of bytes written
269 xmlPythonFileWrite (void * context, const char * buffer, int len) {
276 printf("xmlPythonFileWrite: %d\n", len);
278 file = (PyObject *) context;
279 if (file == NULL) return(-1);
280 string = PyString_FromStringAndSize(buffer, len);
281 if (string == NULL) return(-1);
282 ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", string);
285 printf("xmlPythonFileWrite: result is NULL\n");
287 } else if (PyInt_Check(ret)) {
288 written = (int) PyInt_AsLong(ret);
290 } else if (ret == Py_None) {
294 printf("xmlPythonFileWrite: result is not an Int nor None\n");
301 * xmlPythonFileClose:
302 * @context: the I/O context
304 * Close an I/O channel
307 xmlPythonFileClose (void * context) {
308 PyObject *file, *ret;
311 printf("xmlPythonFileClose\n");
313 file = (PyObject *) context;
314 if (file == NULL) return(-1);
315 ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()");
323 * xmlOutputBufferCreatePythonFile:
324 * @file: a PyFile_Type
325 * @encoder: the encoding converter or NULL
327 * Create a buffered output for the progressive saving to a PyFile_Type
330 * Returns the new parser output or NULL
332 static xmlOutputBufferPtr
333 xmlOutputBufferCreatePythonFile(PyObject *file,
334 xmlCharEncodingHandlerPtr encoder) {
335 xmlOutputBufferPtr ret;
337 if (file == NULL) return(NULL);
339 ret = xmlAllocOutputBuffer(encoder);
342 /* Py_INCREF(file); */
343 ret->writecallback = xmlPythonFileWrite;
344 ret->closecallback = xmlPythonFileClose;
351 libxml_xmlCreateOutputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
355 xmlCharEncodingHandlerPtr handler = NULL;
356 xmlOutputBufferPtr buffer;
359 if (!PyArg_ParseTuple(args, (char *)"Oz:xmlOutputBufferCreate",
362 if ((encoding != NULL) && (encoding[0] != 0)) {
363 handler = xmlFindCharEncodingHandler((const char *) encoding);
365 buffer = xmlOutputBufferCreatePythonFile(file, handler);
367 printf("libxml_xmlCreateOutputBuffer: buffer == NULL\n");
368 py_retval = libxml_xmlOutputBufferPtrWrap(buffer);
374 * xmlParserInputBufferCreatePythonFile:
375 * @file: a PyFile_Type
376 * @encoder: the encoding converter or NULL
378 * Create a buffered output for the progressive saving to a PyFile_Type
381 * Returns the new parser output or NULL
383 static xmlParserInputBufferPtr
384 xmlParserInputBufferCreatePythonFile(PyObject *file,
385 xmlCharEncoding encoding) {
386 xmlParserInputBufferPtr ret;
388 if (file == NULL) return(NULL);
390 ret = xmlAllocParserInputBuffer(encoding);
393 /* Py_INCREF(file); */
394 ret->readcallback = xmlPythonFileRead;
395 ret->closecallback = xmlPythonFileClose;
402 libxml_xmlCreateInputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
406 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
407 xmlParserInputBufferPtr buffer;
410 if (!PyArg_ParseTuple(args, (char *)"Oz:xmlParserInputBufferCreate",
413 if ((encoding != NULL) && (encoding[0] != 0)) {
414 enc = xmlParseCharEncoding((const char *) encoding);
416 buffer = xmlParserInputBufferCreatePythonFile(file, enc);
418 printf("libxml_xmlParserInputBufferCreate: buffer == NULL\n");
419 py_retval = libxml_xmlParserInputBufferPtrWrap(buffer);
423 /************************************************************************
425 * Providing the resolver at the Python level *
427 ************************************************************************/
429 static xmlExternalEntityLoader defaultExternalEntityLoader = NULL;
430 static PyObject *pythonExternalEntityLoaderObjext;
432 static xmlParserInputPtr
433 pythonExternalEntityLoader(const char *URL, const char *ID,
434 xmlParserCtxtPtr ctxt) {
435 xmlParserInputPtr result = NULL;
436 if (pythonExternalEntityLoaderObjext != NULL) {
440 ctxtobj = libxml_xmlParserCtxtPtrWrap(ctxt);
442 printf("pythonExternalEntityLoader: ready to call\n");
445 ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext,
446 (char *) "(ssO)", URL, ID, ctxtobj);
449 printf("pythonExternalEntityLoader: result ");
450 PyObject_Print(ret, stdout, 0);
455 if (PyObject_HasAttrString(ret, (char *) "read")) {
456 xmlParserInputBufferPtr buf;
458 buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
461 buf->readcallback = xmlPythonFileReadRaw;
462 buf->closecallback = xmlPythonFileCloseRaw;
463 result = xmlNewIOInputStream(ctxt, buf,
464 XML_CHAR_ENCODING_NONE);
467 printf("pythonExternalEntityLoader: can't read\n");
469 if (result == NULL) {
471 } else if (URL != NULL) {
472 result->filename = (char *) xmlStrdup((const xmlChar *)URL);
473 result->directory = xmlParserGetDirectory((const char *) URL);
477 if ((result == NULL) && (defaultExternalEntityLoader != NULL)) {
478 result = defaultExternalEntityLoader(URL, ID, ctxt);
484 libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
488 if (!PyArg_ParseTuple(args, (char *)"O:libxml_xmlSetEntityLoader",
493 printf("libxml_xmlSetEntityLoader\n");
495 if (defaultExternalEntityLoader == NULL)
496 defaultExternalEntityLoader = xmlGetExternalEntityLoader();
498 pythonExternalEntityLoaderObjext = loader;
499 xmlSetExternalEntityLoader(pythonExternalEntityLoader);
501 py_retval = PyInt_FromLong(0);
506 /************************************************************************
508 * Handling SAX/xmllib/sgmlop callback interfaces *
510 ************************************************************************/
513 pythonStartElement(void *user_data, const xmlChar * name,
514 const xmlChar ** attrs)
521 PyObject *result = NULL;
525 printf("pythonStartElement(%s) called\n", name);
527 handler = (PyObject *) user_data;
528 if (PyObject_HasAttrString(handler, (char *) "startElement"))
530 else if (PyObject_HasAttrString(handler, (char *) "start"))
534 * the xmllib interface always generate a dictionnary,
537 if ((attrs == NULL) && (type == 1)) {
540 } else if (attrs == NULL) {
544 for (i = 0; attrs[i] != NULL; i++) {
545 attrname = PyString_FromString((char *) attrs[i]);
547 if (attrs[i] != NULL) {
548 attrvalue = PyString_FromString((char *) attrs[i]);
553 PyDict_SetItem(dict, attrname, attrvalue);
558 result = PyObject_CallMethod(handler, (char *) "startElement",
559 (char *) "sO", name, dict);
561 result = PyObject_CallMethod(handler, (char *) "start",
562 (char *) "sO", name, dict);
563 if (PyErr_Occurred())
571 pythonStartDocument(void *user_data)
577 printf("pythonStartDocument() called\n");
579 handler = (PyObject *) user_data;
580 if (PyObject_HasAttrString(handler, (char *) "startDocument")) {
582 PyObject_CallMethod(handler, (char *) "startDocument", NULL);
583 if (PyErr_Occurred())
590 pythonEndDocument(void *user_data)
596 printf("pythonEndDocument() called\n");
598 handler = (PyObject *) user_data;
599 if (PyObject_HasAttrString(handler, (char *) "endDocument")) {
601 PyObject_CallMethod(handler, (char *) "endDocument", NULL);
602 if (PyErr_Occurred())
607 * The reference to the handler is released there
613 pythonEndElement(void *user_data, const xmlChar * name)
619 printf("pythonEndElement(%s) called\n", name);
621 handler = (PyObject *) user_data;
622 if (PyObject_HasAttrString(handler, (char *) "endElement")) {
623 result = PyObject_CallMethod(handler, (char *) "endElement",
625 if (PyErr_Occurred())
628 } else if (PyObject_HasAttrString(handler, (char *) "end")) {
629 result = PyObject_CallMethod(handler, (char *) "end",
631 if (PyErr_Occurred())
638 pythonReference(void *user_data, const xmlChar * name)
644 printf("pythonReference(%s) called\n", name);
646 handler = (PyObject *) user_data;
647 if (PyObject_HasAttrString(handler, (char *) "reference")) {
648 result = PyObject_CallMethod(handler, (char *) "reference",
650 if (PyErr_Occurred())
657 pythonCharacters(void *user_data, const xmlChar * ch, int len)
660 PyObject *result = NULL;
664 printf("pythonCharacters(%s, %d) called\n", ch, len);
666 handler = (PyObject *) user_data;
667 if (PyObject_HasAttrString(handler, (char *) "characters"))
669 else if (PyObject_HasAttrString(handler, (char *) "data"))
673 result = PyObject_CallMethod(handler, (char *) "characters",
674 (char *) "s#", ch, len);
676 result = PyObject_CallMethod(handler, (char *) "data",
677 (char *) "s#", ch, len);
678 if (PyErr_Occurred())
685 pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len)
688 PyObject *result = NULL;
692 printf("pythonIgnorableWhitespace(%s, %d) called\n", ch, len);
694 handler = (PyObject *) user_data;
695 if (PyObject_HasAttrString(handler, (char *) "ignorableWhitespace"))
697 else if (PyObject_HasAttrString(handler, (char *) "data"))
702 PyObject_CallMethod(handler,
703 (char *) "ignorableWhitespace",
704 (char *) "s#", ch, len);
707 PyObject_CallMethod(handler, (char *) "data",
708 (char *) "s#", ch, len);
714 pythonProcessingInstruction(void *user_data,
715 const xmlChar * target, const xmlChar * data)
721 printf("pythonProcessingInstruction(%s, %s) called\n", target, data);
723 handler = (PyObject *) user_data;
724 if (PyObject_HasAttrString(handler, (char *) "processingInstruction")) {
725 result = PyObject_CallMethod(handler, (char *)
726 "processingInstruction",
727 (char *) "ss", target, data);
733 pythonComment(void *user_data, const xmlChar * value)
739 printf("pythonComment(%s) called\n", value);
741 handler = (PyObject *) user_data;
742 if (PyObject_HasAttrString(handler, (char *) "comment")) {
744 PyObject_CallMethod(handler, (char *) "comment", (char *) "s",
746 if (PyErr_Occurred())
753 pythonWarning(void *user_data, const char *msg, ...)
761 printf("pythonWarning(%s) called\n", msg);
763 handler = (PyObject *) user_data;
764 if (PyObject_HasAttrString(handler, (char *) "warning")) {
766 vsnprintf(buf, 1023, msg, args);
770 PyObject_CallMethod(handler, (char *) "warning", (char *) "s",
772 if (PyErr_Occurred())
779 pythonError(void *user_data, const char *msg, ...)
787 printf("pythonError(%s) called\n", msg);
789 handler = (PyObject *) user_data;
790 if (PyObject_HasAttrString(handler, (char *) "error")) {
792 vsnprintf(buf, 1023, msg, args);
796 PyObject_CallMethod(handler, (char *) "error", (char *) "s",
798 if (PyErr_Occurred())
805 pythonFatalError(void *user_data, const char *msg, ...)
813 printf("pythonFatalError(%s) called\n", msg);
815 handler = (PyObject *) user_data;
816 if (PyObject_HasAttrString(handler, (char *) "fatalError")) {
818 vsnprintf(buf, 1023, msg, args);
822 PyObject_CallMethod(handler, (char *) "fatalError",
824 if (PyErr_Occurred())
831 pythonCdataBlock(void *user_data, const xmlChar * ch, int len)
834 PyObject *result = NULL;
838 printf("pythonCdataBlock(%s, %d) called\n", ch, len);
840 handler = (PyObject *) user_data;
841 if (PyObject_HasAttrString(handler, (char *) "cdataBlock"))
843 else if (PyObject_HasAttrString(handler, (char *) "cdata"))
848 PyObject_CallMethod(handler, (char *) "cdataBlock",
849 (char *) "s#", ch, len);
852 PyObject_CallMethod(handler, (char *) "cdata",
853 (char *) "s#", ch, len);
854 if (PyErr_Occurred())
861 pythonExternalSubset(void *user_data,
862 const xmlChar * name,
863 const xmlChar * externalID, const xmlChar * systemID)
869 printf("pythonExternalSubset(%s, %s, %s) called\n",
870 name, externalID, systemID);
872 handler = (PyObject *) user_data;
873 if (PyObject_HasAttrString(handler, (char *) "externalSubset")) {
875 PyObject_CallMethod(handler, (char *) "externalSubset",
876 (char *) "sss", name, externalID,
883 pythonEntityDecl(void *user_data,
884 const xmlChar * name,
886 const xmlChar * publicId,
887 const xmlChar * systemId, xmlChar * content)
892 handler = (PyObject *) user_data;
893 if (PyObject_HasAttrString(handler, (char *) "entityDecl")) {
894 result = PyObject_CallMethod(handler, (char *) "entityDecl",
895 (char *) "sisss", name, type,
896 publicId, systemId, content);
897 if (PyErr_Occurred())
907 pythonNotationDecl(void *user_data,
908 const xmlChar * name,
909 const xmlChar * publicId, const xmlChar * systemId)
914 handler = (PyObject *) user_data;
915 if (PyObject_HasAttrString(handler, (char *) "notationDecl")) {
916 result = PyObject_CallMethod(handler, (char *) "notationDecl",
917 (char *) "sss", name, publicId,
919 if (PyErr_Occurred())
926 pythonAttributeDecl(void *user_data,
927 const xmlChar * elem,
928 const xmlChar * name,
931 const xmlChar * defaultValue, xmlEnumerationPtr tree)
936 xmlEnumerationPtr node;
940 handler = (PyObject *) user_data;
941 if (PyObject_HasAttrString(handler, (char *) "attributeDecl")) {
943 for (node = tree; node != NULL; node = node->next) {
946 nameList = PyList_New(count);
948 for (node = tree; node != NULL; node = node->next) {
949 newName = PyString_FromString((char *) node->name);
950 PyList_SetItem(nameList, count, newName);
953 result = PyObject_CallMethod(handler, (char *) "attributeDecl",
954 (char *) "ssiisO", elem, name, type,
955 def, defaultValue, nameList);
956 if (PyErr_Occurred())
958 Py_XDECREF(nameList);
964 pythonElementDecl(void *user_data,
965 const xmlChar * name,
966 int type, ATTRIBUTE_UNUSED xmlElementContentPtr content)
972 handler = (PyObject *) user_data;
973 if (PyObject_HasAttrString(handler, (char *) "elementDecl")) {
974 /* TODO: wrap in an elementContent object */
976 ("pythonElementDecl: xmlElementContentPtr wrapper missing !\n");
978 /* Py_XINCREF(Py_None); isn't the reference just borrowed ??? */
979 result = PyObject_CallMethod(handler, (char *) "elementDecl",
980 (char *) "siO", name, type, obj);
981 if (PyErr_Occurred())
988 pythonUnparsedEntityDecl(void *user_data,
989 const xmlChar * name,
990 const xmlChar * publicId,
991 const xmlChar * systemId,
992 const xmlChar * notationName)
997 handler = (PyObject *) user_data;
998 if (PyObject_HasAttrString(handler, (char *) "unparsedEntityDecl")) {
1000 PyObject_CallMethod(handler, (char *) "unparsedEntityDecl",
1001 (char *) "ssss", name, publicId, systemId,
1003 if (PyErr_Occurred())
1010 pythonInternalSubset(void *user_data, const xmlChar * name,
1011 const xmlChar * ExternalID, const xmlChar * SystemID)
1017 printf("pythonInternalSubset(%s, %s, %s) called\n",
1018 name, ExternalID, SystemID);
1020 handler = (PyObject *) user_data;
1021 if (PyObject_HasAttrString(handler, (char *) "internalSubset")) {
1022 result = PyObject_CallMethod(handler, (char *) "internalSubset",
1023 (char *) "sss", name, ExternalID,
1025 if (PyErr_Occurred())
1031 static xmlSAXHandler pythonSaxHandler = {
1032 pythonInternalSubset,
1033 NULL, /* TODO pythonIsStandalone, */
1034 NULL, /* TODO pythonHasInternalSubset, */
1035 NULL, /* TODO pythonHasExternalSubset, */
1036 NULL, /* TODO pythonResolveEntity, */
1037 NULL, /* TODO pythonGetEntity, */
1040 pythonAttributeDecl,
1042 pythonUnparsedEntityDecl,
1043 NULL, /* OBSOLETED pythonSetDocumentLocator, */
1044 pythonStartDocument,
1050 pythonIgnorableWhitespace,
1051 pythonProcessingInstruction,
1056 NULL, /* TODO pythonGetParameterEntity, */
1058 pythonExternalSubset,
1062 /************************************************************************
1064 * Handling of specific parser context *
1066 ************************************************************************/
1069 libxml_xmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self,
1075 PyObject *pyobj_SAX = NULL;
1076 xmlSAXHandlerPtr SAX = NULL;
1077 xmlParserCtxtPtr ret;
1080 if (!PyArg_ParseTuple
1081 (args, (char *) "Oziz:xmlCreatePushParser", &pyobj_SAX, &chunk,
1086 printf("libxml_xmlCreatePushParser(%p, %s, %d, %s) called\n",
1087 pyobj_SAX, chunk, size, URI);
1089 if (pyobj_SAX != Py_None) {
1090 SAX = &pythonSaxHandler;
1091 Py_INCREF(pyobj_SAX);
1092 /* The reference is released in pythonEndDocument() */
1094 ret = xmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI);
1095 pyret = libxml_xmlParserCtxtPtrWrap(ret);
1100 libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self,
1106 PyObject *pyobj_SAX = NULL;
1107 xmlSAXHandlerPtr SAX = NULL;
1108 xmlParserCtxtPtr ret;
1111 if (!PyArg_ParseTuple
1112 (args, (char *) "Oziz:htmlCreatePushParser", &pyobj_SAX, &chunk,
1117 printf("libxml_htmlCreatePushParser(%p, %s, %d, %s) called\n",
1118 pyobj_SAX, chunk, size, URI);
1120 if (pyobj_SAX != Py_None) {
1121 SAX = &pythonSaxHandler;
1122 Py_INCREF(pyobj_SAX);
1123 /* The reference is released in pythonEndDocument() */
1125 ret = htmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI,
1126 XML_CHAR_ENCODING_NONE);
1127 pyret = libxml_xmlParserCtxtPtrWrap(ret);
1132 libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1136 PyObject *pyobj_SAX = NULL;
1137 xmlSAXHandlerPtr SAX = NULL;
1139 if (!PyArg_ParseTuple(args, (char *) "Osi:xmlSAXParseFile", &pyobj_SAX,
1144 printf("libxml_xmlSAXParseFile(%p, %s, %d) called\n",
1145 pyobj_SAX, URI, recover);
1147 if (pyobj_SAX == Py_None) {
1151 SAX = &pythonSaxHandler;
1152 Py_INCREF(pyobj_SAX);
1153 /* The reference is released in pythonEndDocument() */
1154 xmlSAXParseFileWithData(SAX, URI, recover, pyobj_SAX);
1160 libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1163 const char *encoding;
1164 PyObject *pyobj_SAX = NULL;
1165 xmlSAXHandlerPtr SAX = NULL;
1167 if (!PyArg_ParseTuple
1168 (args, (char *) "Osz:htmlSAXParseFile", &pyobj_SAX, &URI,
1173 printf("libxml_htmlSAXParseFile(%p, %s, %s) called\n",
1174 pyobj_SAX, URI, encoding);
1176 if (pyobj_SAX == Py_None) {
1180 SAX = &pythonSaxHandler;
1181 Py_INCREF(pyobj_SAX);
1182 /* The reference is released in pythonEndDocument() */
1183 htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX);
1188 /************************************************************************
1190 * Error message callback *
1192 ************************************************************************/
1194 static PyObject *libxml_xmlPythonErrorFuncHandler = NULL;
1195 static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL;
1197 /* helper to build a xmlMalloc'ed string from a format and va_list */
1199 libxml_buildMessage(const char *msg, va_list ap)
1206 str = (char *) xmlMalloc(150);
1213 chars = vsnprintf(str, size, msg, ap);
1214 if ((chars > -1) && (chars < size))
1220 if ((larger = (char *) xmlRealloc(str, size)) == NULL) {
1231 libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
1241 printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
1245 if (libxml_xmlPythonErrorFuncHandler == NULL) {
1247 vfprintf(stdout, msg, ap);
1251 str = libxml_buildMessage(msg,ap);
1254 list = PyTuple_New(2);
1255 PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
1256 Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
1257 message = libxml_charPtrWrap(str);
1258 PyTuple_SetItem(list, 1, message);
1259 result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
1266 libxml_xmlErrorInitialize(void)
1269 printf("libxml_xmlErrorInitialize() called\n");
1271 xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1272 xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1276 libxml_xmlRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
1279 PyObject *py_retval;
1281 PyObject *pyobj_ctx;
1283 if (!PyArg_ParseTuple
1284 (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f,
1289 printf("libxml_registerXPathFunction(%p, %p) called\n", pyobj_ctx,
1293 if (libxml_xmlPythonErrorFuncHandler != NULL) {
1294 Py_XDECREF(libxml_xmlPythonErrorFuncHandler);
1296 if (libxml_xmlPythonErrorFuncCtxt != NULL) {
1297 Py_XDECREF(libxml_xmlPythonErrorFuncCtxt);
1300 Py_XINCREF(pyobj_ctx);
1301 Py_XINCREF(pyobj_f);
1303 /* TODO: check f is a function ! */
1304 libxml_xmlPythonErrorFuncHandler = pyobj_f;
1305 libxml_xmlPythonErrorFuncCtxt = pyobj_ctx;
1307 py_retval = libxml_intWrap(1);
1312 /************************************************************************
1314 * Per parserCtxt error handler *
1316 ************************************************************************/
1322 } xmlParserCtxtPyCtxt;
1323 typedef xmlParserCtxtPyCtxt *xmlParserCtxtPyCtxtPtr;
1326 libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str)
1330 xmlParserCtxtPtr ctxt;
1331 xmlParserCtxtPyCtxtPtr pyCtxt;
1334 printf("libxml_xmlParserCtxtGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
1337 ctxt = (xmlParserCtxtPtr)ctx;
1338 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1340 list = PyTuple_New(4);
1341 PyTuple_SetItem(list, 0, pyCtxt->arg);
1342 Py_XINCREF(pyCtxt->arg);
1343 PyTuple_SetItem(list, 1, libxml_charPtrWrap(str));
1344 PyTuple_SetItem(list, 2, libxml_intWrap(severity));
1345 PyTuple_SetItem(list, 3, Py_None);
1347 result = PyEval_CallObject(pyCtxt->f, list);
1350 /* TODO: manage for the exception to be propagated... */
1358 libxml_xmlParserCtxtErrorFuncHandler(void *ctx, const char *msg, ...)
1363 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_ERROR,libxml_buildMessage(msg,ap));
1368 libxml_xmlParserCtxtWarningFuncHandler(void *ctx, const char *msg, ...)
1373 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_WARNING,libxml_buildMessage(msg,ap));
1378 libxml_xmlParserCtxtValidityErrorFuncHandler(void *ctx, const char *msg, ...)
1383 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap));
1388 libxml_xmlParserCtxtValidityWarningFuncHandler(void *ctx, const char *msg, ...)
1393 libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap));
1398 libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1400 PyObject *py_retval;
1401 xmlParserCtxtPtr ctxt;
1402 xmlParserCtxtPyCtxtPtr pyCtxt;
1403 PyObject *pyobj_ctxt;
1405 PyObject *pyobj_arg;
1407 if (!PyArg_ParseTuple(args, (char *)"OOO:xmlParserCtxtSetErrorHandler",
1408 &pyobj_ctxt, &pyobj_f, &pyobj_arg))
1410 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1411 if (ctxt->_private == NULL) {
1412 pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt));
1413 if (pyCtxt == NULL) {
1414 py_retval = libxml_intWrap(-1);
1417 memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt));
1418 ctxt->_private = pyCtxt;
1421 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1423 /* TODO: check f is a function ! */
1424 Py_XDECREF(pyCtxt->f);
1425 Py_XINCREF(pyobj_f);
1426 pyCtxt->f = pyobj_f;
1427 Py_XDECREF(pyCtxt->arg);
1428 Py_XINCREF(pyobj_arg);
1429 pyCtxt->arg = pyobj_arg;
1431 if (pyobj_f != Py_None) {
1432 ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler;
1433 ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler;
1434 ctxt->vctxt.error = libxml_xmlParserCtxtValidityErrorFuncHandler;
1435 ctxt->vctxt.warning = libxml_xmlParserCtxtValidityWarningFuncHandler;
1438 ctxt->sax->error = xmlParserError;
1439 ctxt->vctxt.error = xmlParserValidityError;
1440 ctxt->sax->warning = xmlParserWarning;
1441 ctxt->vctxt.warning = xmlParserValidityWarning;
1444 py_retval = libxml_intWrap(1);
1449 libxml_xmlParserCtxtGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1451 PyObject *py_retval;
1452 xmlParserCtxtPtr ctxt;
1453 xmlParserCtxtPyCtxtPtr pyCtxt;
1454 PyObject *pyobj_ctxt;
1456 if (!PyArg_ParseTuple(args, (char *)"O:xmlParserCtxtGetErrorHandler",
1459 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1460 py_retval = PyTuple_New(2);
1461 if (ctxt->_private != NULL) {
1462 pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private;
1464 PyTuple_SetItem(py_retval, 0, pyCtxt->f);
1465 Py_XINCREF(pyCtxt->f);
1466 PyTuple_SetItem(py_retval, 1, pyCtxt->arg);
1467 Py_XINCREF(pyCtxt->arg);
1470 /* no python error handler registered */
1471 PyTuple_SetItem(py_retval, 0, Py_None);
1472 Py_XINCREF(Py_None);
1473 PyTuple_SetItem(py_retval, 1, Py_None);
1474 Py_XINCREF(Py_None);
1480 libxml_xmlFreeParserCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
1481 xmlParserCtxtPtr ctxt;
1482 PyObject *pyobj_ctxt;
1483 xmlParserCtxtPyCtxtPtr pyCtxt;
1485 if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeParserCtxt", &pyobj_ctxt))
1487 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
1490 pyCtxt = (xmlParserCtxtPyCtxtPtr)((xmlParserCtxtPtr)ctxt)->_private;
1492 Py_XDECREF(pyCtxt->f);
1493 Py_XDECREF(pyCtxt->arg);
1496 xmlFreeParserCtxt(ctxt);
1503 /************************************************************************
1505 * Per xmlTextReader error handler *
1507 ************************************************************************/
1513 } xmlTextReaderPyCtxt;
1514 typedef xmlTextReaderPyCtxt *xmlTextReaderPyCtxtPtr;
1517 libxml_xmlTextReaderErrorCallback(void *arg,
1520 xmlTextReaderLocatorPtr locator)
1522 xmlTextReaderPyCtxt *pyCtxt = (xmlTextReaderPyCtxt *)arg;
1526 list = PyTuple_New(4);
1527 PyTuple_SetItem(list, 0, pyCtxt->arg);
1528 Py_XINCREF(pyCtxt->arg);
1529 PyTuple_SetItem(list, 1, libxml_charPtrConstWrap(msg));
1530 PyTuple_SetItem(list, 2, libxml_intWrap(severity));
1531 PyTuple_SetItem(list, 3, libxml_xmlTextReaderLocatorPtrWrap(locator));
1532 result = PyEval_CallObject(pyCtxt->f, list);
1535 /* TODO: manage for the exception to be propagated... */
1543 libxml_xmlTextReaderSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1545 xmlTextReaderPtr reader;
1546 xmlTextReaderPyCtxtPtr pyCtxt;
1547 xmlTextReaderErrorFunc f;
1549 PyObject *pyobj_reader;
1551 PyObject *pyobj_arg;
1552 PyObject *py_retval;
1554 if (!PyArg_ParseTuple(args, (char *)"OOO:xmlTextReaderSetErrorHandler", &pyobj_reader, &pyobj_f, &pyobj_arg))
1556 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
1557 /* clear previous error handler */
1558 xmlTextReaderGetErrorHandler(reader,&f,&arg);
1560 if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) {
1561 /* ok, it's our error handler! */
1562 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
1563 Py_XDECREF(pyCtxt->f);
1564 Py_XDECREF(pyCtxt->arg);
1569 * there already an arg, and it's not ours,
1570 * there is definitely something wrong going on here...
1571 * we don't know how to free it, so we bail out...
1573 py_retval = libxml_intWrap(-1);
1577 xmlTextReaderSetErrorHandler(reader,NULL,NULL);
1578 /* set new error handler */
1579 if (pyobj_f != Py_None)
1581 pyCtxt = (xmlTextReaderPyCtxtPtr)xmlMalloc(sizeof(xmlTextReaderPyCtxt));
1582 if (pyCtxt == NULL) {
1583 py_retval = libxml_intWrap(-1);
1586 Py_XINCREF(pyobj_f);
1587 pyCtxt->f = pyobj_f;
1588 Py_XINCREF(pyobj_arg);
1589 pyCtxt->arg = pyobj_arg;
1590 xmlTextReaderSetErrorHandler(reader,
1591 (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback,
1595 py_retval = libxml_intWrap(1);
1600 libxml_xmlTextReaderGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args)
1602 xmlTextReaderPtr reader;
1603 xmlTextReaderPyCtxtPtr pyCtxt;
1604 xmlTextReaderErrorFunc f;
1606 PyObject *pyobj_reader;
1607 PyObject *py_retval;
1609 if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderSetErrorHandler", &pyobj_reader))
1611 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
1612 xmlTextReaderGetErrorHandler(reader,&f,&arg);
1613 py_retval = PyTuple_New(2);
1614 if (f == (xmlTextReaderErrorFunc)libxml_xmlTextReaderErrorCallback) {
1615 /* ok, it's our error handler! */
1616 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
1617 PyTuple_SetItem(py_retval, 0, pyCtxt->f);
1618 Py_XINCREF(pyCtxt->f);
1619 PyTuple_SetItem(py_retval, 1, pyCtxt->arg);
1620 Py_XINCREF(pyCtxt->arg);
1624 /* f is null or it's not our error handler */
1625 PyTuple_SetItem(py_retval, 0, Py_None);
1626 Py_XINCREF(Py_None);
1627 PyTuple_SetItem(py_retval, 1, Py_None);
1628 Py_XINCREF(Py_None);
1634 libxml_xmlFreeTextReader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
1635 xmlTextReaderPtr reader;
1636 PyObject *pyobj_reader;
1637 xmlTextReaderPyCtxtPtr pyCtxt;
1638 xmlTextReaderErrorFunc f;
1641 if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader))
1643 reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
1645 xmlTextReaderGetErrorHandler(reader,&f,&arg);
1647 if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) {
1648 /* ok, it's our error handler! */
1649 pyCtxt = (xmlTextReaderPyCtxtPtr)arg;
1650 Py_XDECREF(pyCtxt->f);
1651 Py_XDECREF(pyCtxt->arg);
1655 * else, something wrong happened, because the error handler is
1656 * not owned by the python bindings...
1660 xmlFreeTextReader(reader);
1665 /************************************************************************
1667 * XPath extensions *
1669 ************************************************************************/
1671 static int libxml_xpathCallbacksInitialized = 0;
1673 typedef struct libxml_xpathCallback {
1674 xmlXPathContextPtr ctx;
1678 } libxml_xpathCallback, *libxml_xpathCallbackPtr;
1679 static libxml_xpathCallback libxml_xpathCallbacks[10];
1680 static int libxml_xpathCallbacksNb = 0;
1681 static int libxml_xpathCallbacksMax = 10;
1684 libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs)
1686 PyObject *list, *cur, *result;
1687 xmlXPathObjectPtr obj;
1688 xmlXPathContextPtr rctxt;
1689 PyObject *current_function = NULL;
1690 const xmlChar *name;
1691 const xmlChar *ns_uri;
1696 rctxt = ctxt->context;
1699 name = rctxt->function;
1700 ns_uri = rctxt->functionURI;
1702 printf("libxml_xmlXPathFuncCallback called name %s URI %s\n", name,
1707 * Find the function, it should be there it was there at lookup
1709 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
1710 if ( /* TODO (ctxt == libxml_xpathCallbacks[i].ctx) && */
1711 (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) &&
1712 (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) {
1713 current_function = libxml_xpathCallbacks[i].function;
1716 if (current_function == NULL) {
1718 ("libxml_xmlXPathFuncCallback: internal error %s not found !\n",
1723 list = PyTuple_New(nargs + 1);
1724 PyTuple_SetItem(list, 0, libxml_xmlXPathParserContextPtrWrap(ctxt));
1725 for (i = 0; i < nargs; i++) {
1726 obj = valuePop(ctxt);
1727 cur = libxml_xmlXPathObjectPtrWrap(obj);
1728 PyTuple_SetItem(list, i + 1, cur);
1730 result = PyEval_CallObject(current_function, list);
1733 obj = libxml_xmlXPathObjectPtrConvert(result);
1734 valuePush(ctxt, obj);
1737 static xmlXPathFunction
1738 libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar * name,
1739 const xmlChar * ns_uri)
1744 printf("libxml_xmlXPathFuncLookupFunc(%p, %s, %s) called\n",
1745 ctxt, name, ns_uri);
1748 * This is called once only. The address is then stored in the
1749 * XPath expression evaluation, the proper object to call can
1750 * then still be found using the execution context function
1751 * and functionURI fields.
1753 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
1754 if ((ctxt == libxml_xpathCallbacks[i].ctx) &&
1755 (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) &&
1756 (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) {
1757 return (libxml_xmlXPathFuncCallback);
1764 libxml_xpathCallbacksInitialize(void)
1768 if (libxml_xpathCallbacksInitialized != 0)
1772 printf("libxml_xpathCallbacksInitialized called\n");
1775 for (i = 0; i < libxml_xpathCallbacksMax; i++) {
1776 libxml_xpathCallbacks[i].ctx = NULL;
1777 libxml_xpathCallbacks[i].name = NULL;
1778 libxml_xpathCallbacks[i].ns_uri = NULL;
1779 libxml_xpathCallbacks[i].function = NULL;
1781 libxml_xpathCallbacksInitialized = 1;
1785 libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObject * self,
1788 PyObject *py_retval;
1792 xmlXPathContextPtr ctx;
1793 PyObject *pyobj_ctx;
1797 if (!PyArg_ParseTuple
1798 (args, (char *) "OszO:registerXPathFunction", &pyobj_ctx, &name,
1802 ctx = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctx);
1803 if (libxml_xpathCallbacksInitialized == 0)
1804 libxml_xpathCallbacksInitialize();
1805 xmlXPathRegisterFuncLookup(ctx, libxml_xmlXPathFuncLookupFunc, ctx);
1807 if ((pyobj_ctx == NULL) || (name == NULL) || (pyobj_f == NULL)) {
1808 py_retval = libxml_intWrap(-1);
1812 printf("libxml_registerXPathFunction(%p, %s, %s) called\n",
1815 for (i = 0; i < libxml_xpathCallbacksNb; i++) {
1816 if ((ctx == libxml_xpathCallbacks[i].ctx) &&
1817 (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) &&
1818 (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) {
1819 Py_XINCREF(pyobj_f);
1820 Py_XDECREF(libxml_xpathCallbacks[i].function);
1821 libxml_xpathCallbacks[i].function = pyobj_f;
1826 if (libxml_xpathCallbacksNb >= libxml_xpathCallbacksMax) {
1827 printf("libxml_registerXPathFunction() table full\n");
1829 i = libxml_xpathCallbacksNb++;
1830 Py_XINCREF(pyobj_f);
1831 libxml_xpathCallbacks[i].ctx = ctx;
1832 libxml_xpathCallbacks[i].name = xmlStrdup(name);
1833 libxml_xpathCallbacks[i].ns_uri = xmlStrdup(ns_uri);
1834 libxml_xpathCallbacks[i].function = pyobj_f;
1838 py_retval = libxml_intWrap((int) c_retval);
1842 /************************************************************************
1844 * Global properties access *
1846 ************************************************************************/
1848 libxml_name(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1850 PyObject *resultobj, *obj;
1854 if (!PyArg_ParseTuple(args, (char *) "O:name", &obj))
1856 cur = PyxmlNode_Get(obj);
1859 printf("libxml_name: cur = %p type %d\n", cur, cur->type);
1862 switch (cur->type) {
1863 case XML_DOCUMENT_NODE:
1864 #ifdef LIBXML_DOCB_ENABLED
1865 case XML_DOCB_DOCUMENT_NODE:
1867 case XML_HTML_DOCUMENT_NODE:{
1868 xmlDocPtr doc = (xmlDocPtr) cur;
1873 case XML_ATTRIBUTE_NODE:{
1874 xmlAttrPtr attr = (xmlAttrPtr) cur;
1879 case XML_NAMESPACE_DECL:{
1880 xmlNsPtr ns = (xmlNsPtr) cur;
1889 resultobj = libxml_constxmlCharPtrWrap(res);
1895 libxml_doc(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1897 PyObject *resultobj, *obj;
1901 if (!PyArg_ParseTuple(args, (char *) "O:doc", &obj))
1903 cur = PyxmlNode_Get(obj);
1906 printf("libxml_doc: cur = %p\n", cur);
1909 switch (cur->type) {
1910 case XML_DOCUMENT_NODE:
1911 #ifdef LIBXML_DOCB_ENABLED
1912 case XML_DOCB_DOCUMENT_NODE:
1914 case XML_HTML_DOCUMENT_NODE:
1917 case XML_ATTRIBUTE_NODE:{
1918 xmlAttrPtr attr = (xmlAttrPtr) cur;
1923 case XML_NAMESPACE_DECL:
1930 resultobj = libxml_xmlDocPtrWrap(res);
1935 libxml_properties(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1937 PyObject *resultobj, *obj;
1938 xmlNodePtr cur = NULL;
1941 if (!PyArg_ParseTuple(args, (char *) "O:properties", &obj))
1943 cur = PyxmlNode_Get(obj);
1944 if (cur->type == XML_ELEMENT_NODE)
1945 res = cur->properties;
1948 resultobj = libxml_xmlAttrPtrWrap(res);
1953 libxml_next(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1955 PyObject *resultobj, *obj;
1959 if (!PyArg_ParseTuple(args, (char *) "O:next", &obj))
1961 cur = PyxmlNode_Get(obj);
1964 printf("libxml_next: cur = %p\n", cur);
1967 switch (cur->type) {
1968 case XML_DOCUMENT_NODE:
1969 #ifdef LIBXML_DOCB_ENABLED
1970 case XML_DOCB_DOCUMENT_NODE:
1972 case XML_HTML_DOCUMENT_NODE:
1975 case XML_ATTRIBUTE_NODE:{
1976 xmlAttrPtr attr = (xmlAttrPtr) cur;
1978 res = (xmlNodePtr) attr->next;
1981 case XML_NAMESPACE_DECL:{
1982 xmlNsPtr ns = (xmlNsPtr) cur;
1984 res = (xmlNodePtr) ns->next;
1992 resultobj = libxml_xmlNodePtrWrap(res);
1997 libxml_prev(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
1999 PyObject *resultobj, *obj;
2003 if (!PyArg_ParseTuple(args, (char *) "O:prev", &obj))
2005 cur = PyxmlNode_Get(obj);
2008 printf("libxml_prev: cur = %p\n", cur);
2011 switch (cur->type) {
2012 case XML_DOCUMENT_NODE:
2013 #ifdef LIBXML_DOCB_ENABLED
2014 case XML_DOCB_DOCUMENT_NODE:
2016 case XML_HTML_DOCUMENT_NODE:
2019 case XML_ATTRIBUTE_NODE:{
2020 xmlAttrPtr attr = (xmlAttrPtr) cur;
2022 res = (xmlNodePtr) attr->prev;
2024 case XML_NAMESPACE_DECL:
2031 resultobj = libxml_xmlNodePtrWrap(res);
2036 libxml_children(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2038 PyObject *resultobj, *obj;
2042 if (!PyArg_ParseTuple(args, (char *) "O:children", &obj))
2044 cur = PyxmlNode_Get(obj);
2047 printf("libxml_children: cur = %p\n", cur);
2050 switch (cur->type) {
2051 case XML_ELEMENT_NODE:
2052 case XML_ENTITY_REF_NODE:
2053 case XML_ENTITY_NODE:
2055 case XML_COMMENT_NODE:
2056 case XML_DOCUMENT_NODE:
2057 #ifdef LIBXML_DOCB_ENABLED
2058 case XML_DOCB_DOCUMENT_NODE:
2060 case XML_HTML_DOCUMENT_NODE:
2062 res = cur->children;
2064 case XML_ATTRIBUTE_NODE:{
2065 xmlAttrPtr attr = (xmlAttrPtr) cur;
2067 res = attr->children;
2074 resultobj = libxml_xmlNodePtrWrap(res);
2079 libxml_last(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2081 PyObject *resultobj, *obj;
2085 if (!PyArg_ParseTuple(args, (char *) "O:last", &obj))
2087 cur = PyxmlNode_Get(obj);
2090 printf("libxml_last: cur = %p\n", cur);
2093 switch (cur->type) {
2094 case XML_ELEMENT_NODE:
2095 case XML_ENTITY_REF_NODE:
2096 case XML_ENTITY_NODE:
2098 case XML_COMMENT_NODE:
2099 case XML_DOCUMENT_NODE:
2100 #ifdef LIBXML_DOCB_ENABLED
2101 case XML_DOCB_DOCUMENT_NODE:
2103 case XML_HTML_DOCUMENT_NODE:
2107 case XML_ATTRIBUTE_NODE:{
2108 xmlAttrPtr attr = (xmlAttrPtr) cur;
2116 resultobj = libxml_xmlNodePtrWrap(res);
2121 libxml_parent(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2123 PyObject *resultobj, *obj;
2127 if (!PyArg_ParseTuple(args, (char *) "O:parent", &obj))
2129 cur = PyxmlNode_Get(obj);
2132 printf("libxml_parent: cur = %p\n", cur);
2135 switch (cur->type) {
2136 case XML_DOCUMENT_NODE:
2137 case XML_HTML_DOCUMENT_NODE:
2138 #ifdef LIBXML_DOCB_ENABLED
2139 case XML_DOCB_DOCUMENT_NODE:
2143 case XML_ATTRIBUTE_NODE:{
2144 xmlAttrPtr attr = (xmlAttrPtr) cur;
2148 case XML_ENTITY_DECL:
2149 case XML_NAMESPACE_DECL:
2150 case XML_XINCLUDE_START:
2151 case XML_XINCLUDE_END:
2158 resultobj = libxml_xmlNodePtrWrap(res);
2163 libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2165 PyObject *resultobj, *obj;
2167 const xmlChar *res = NULL;
2169 if (!PyArg_ParseTuple(args, (char *) "O:last", &obj))
2171 cur = PyxmlNode_Get(obj);
2174 printf("libxml_type: cur = %p\n", cur);
2177 switch (cur->type) {
2178 case XML_ELEMENT_NODE:
2179 res = (const xmlChar *) "element";
2181 case XML_ATTRIBUTE_NODE:
2182 res = (const xmlChar *) "attribute";
2185 res = (const xmlChar *) "text";
2187 case XML_CDATA_SECTION_NODE:
2188 res = (const xmlChar *) "cdata";
2190 case XML_ENTITY_REF_NODE:
2191 res = (const xmlChar *) "entity_ref";
2193 case XML_ENTITY_NODE:
2194 res = (const xmlChar *) "entity";
2197 res = (const xmlChar *) "pi";
2199 case XML_COMMENT_NODE:
2200 res = (const xmlChar *) "comment";
2202 case XML_DOCUMENT_NODE:
2203 res = (const xmlChar *) "document_xml";
2205 case XML_DOCUMENT_TYPE_NODE:
2206 res = (const xmlChar *) "doctype";
2208 case XML_DOCUMENT_FRAG_NODE:
2209 res = (const xmlChar *) "fragment";
2211 case XML_NOTATION_NODE:
2212 res = (const xmlChar *) "notation";
2214 case XML_HTML_DOCUMENT_NODE:
2215 res = (const xmlChar *) "document_html";
2218 res = (const xmlChar *) "dtd";
2220 case XML_ELEMENT_DECL:
2221 res = (const xmlChar *) "elem_decl";
2223 case XML_ATTRIBUTE_DECL:
2224 res = (const xmlChar *) "attribute_decl";
2226 case XML_ENTITY_DECL:
2227 res = (const xmlChar *) "entity_decl";
2229 case XML_NAMESPACE_DECL:
2230 res = (const xmlChar *) "namespace";
2232 case XML_XINCLUDE_START:
2233 res = (const xmlChar *) "xinclude_start";
2235 case XML_XINCLUDE_END:
2236 res = (const xmlChar *) "xinclude_end";
2238 #ifdef LIBXML_DOCB_ENABLED
2239 case XML_DOCB_DOCUMENT_NODE:
2240 res = (const xmlChar *) "document_docbook";
2245 printf("libxml_type: cur = %p: %s\n", cur, res);
2248 resultobj = libxml_constxmlCharPtrWrap(res);
2252 /************************************************************************
2254 * Specific accessor functions *
2256 ************************************************************************/
2258 libxml_xmlNodeGetNsDefs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2260 PyObject *py_retval;
2263 PyObject *pyobj_node;
2265 if (!PyArg_ParseTuple
2266 (args, (char *) "O:xmlNodeGetNsDefs", &pyobj_node))
2268 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2270 if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) {
2274 c_retval = node->nsDef;
2275 py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval);
2280 libxml_xmlNodeGetNs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2282 PyObject *py_retval;
2285 PyObject *pyobj_node;
2287 if (!PyArg_ParseTuple(args, (char *) "O:xmlNodeGetNs", &pyobj_node))
2289 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2291 if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) {
2295 c_retval = node->ns;
2296 py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval);
2300 /************************************************************************
2302 * Serialization front-end *
2304 ************************************************************************/
2307 libxml_serializeNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2309 PyObject *py_retval = NULL;
2311 PyObject *pyobj_node;
2314 const char *encoding;
2318 if (!PyArg_ParseTuple(args, (char *) "Ozi:serializeNode", &pyobj_node,
2319 &encoding, &format))
2321 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2327 if (node->type == XML_DOCUMENT_NODE) {
2328 doc = (xmlDocPtr) node;
2329 xmlDocDumpFormatMemoryEnc(doc, &c_retval, &len,
2330 (const char *) encoding, format);
2331 py_retval = libxml_charPtrWrap((char *) c_retval);
2332 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2333 xmlOutputBufferPtr buf;
2334 xmlCharEncodingHandlerPtr handler = NULL;
2336 doc = (xmlDocPtr) node;
2337 if (encoding != NULL)
2338 htmlSetMetaEncoding(doc, (const xmlChar *) encoding);
2339 encoding = (const char *) htmlGetMetaEncoding(doc);
2341 if (encoding != NULL) {
2342 handler = xmlFindCharEncodingHandler(encoding);
2343 if (handler == NULL) {
2350 * Fallback to HTML or ASCII when the encoding is unspecified
2352 if (handler == NULL)
2353 handler = xmlFindCharEncodingHandler("HTML");
2354 if (handler == NULL)
2355 handler = xmlFindCharEncodingHandler("ascii");
2357 buf = xmlAllocOutputBuffer(handler);
2362 htmlDocContentDumpFormatOutput(buf, doc, encoding, format);
2363 xmlOutputBufferFlush(buf);
2364 if (buf->conv != NULL) {
2365 len = buf->conv->use;
2366 c_retval = buf->conv->content;
2367 buf->conv->content = NULL;
2369 len = buf->buffer->use;
2370 c_retval = buf->buffer->content;
2371 buf->buffer->content = NULL;
2373 (void) xmlOutputBufferClose(buf);
2374 py_retval = libxml_charPtrWrap((char *) c_retval);
2377 if ((doc == NULL) || (doc->type == XML_DOCUMENT_NODE)) {
2378 xmlOutputBufferPtr buf;
2379 xmlCharEncodingHandlerPtr handler = NULL;
2381 if (encoding != NULL) {
2382 handler = xmlFindCharEncodingHandler(encoding);
2383 if (handler == NULL) {
2389 buf = xmlAllocOutputBuffer(handler);
2394 xmlNodeDumpOutput(buf, doc, node, 0, format, encoding);
2395 xmlOutputBufferFlush(buf);
2396 if (buf->conv != NULL) {
2397 len = buf->conv->use;
2398 c_retval = buf->conv->content;
2399 buf->conv->content = NULL;
2401 len = buf->buffer->use;
2402 c_retval = buf->buffer->content;
2403 buf->buffer->content = NULL;
2405 (void) xmlOutputBufferClose(buf);
2406 py_retval = libxml_charPtrWrap((char *) c_retval);
2407 } else if (doc->type == XML_HTML_DOCUMENT_NODE) {
2408 xmlOutputBufferPtr buf;
2409 xmlCharEncodingHandlerPtr handler = NULL;
2411 if (encoding != NULL)
2412 htmlSetMetaEncoding(doc, (const xmlChar *) encoding);
2413 encoding = (const char *) htmlGetMetaEncoding(doc);
2414 if (encoding != NULL) {
2415 handler = xmlFindCharEncodingHandler(encoding);
2416 if (handler == NULL) {
2423 * Fallback to HTML or ASCII when the encoding is unspecified
2425 if (handler == NULL)
2426 handler = xmlFindCharEncodingHandler("HTML");
2427 if (handler == NULL)
2428 handler = xmlFindCharEncodingHandler("ascii");
2430 buf = xmlAllocOutputBuffer(handler);
2435 htmlNodeDumpFormatOutput(buf, doc, node, encoding, format);
2436 xmlOutputBufferFlush(buf);
2437 if (buf->conv != NULL) {
2438 len = buf->conv->use;
2439 c_retval = buf->conv->content;
2440 buf->conv->content = NULL;
2442 len = buf->buffer->use;
2443 c_retval = buf->buffer->content;
2444 buf->buffer->content = NULL;
2446 (void) xmlOutputBufferClose(buf);
2447 py_retval = libxml_charPtrWrap((char *) c_retval);
2457 libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2459 PyObject *py_file = NULL;
2461 PyObject *pyobj_node;
2464 const char *encoding;
2467 xmlOutputBufferPtr buf;
2468 xmlCharEncodingHandlerPtr handler = NULL;
2470 if (!PyArg_ParseTuple(args, (char *) "OOzi:serializeNode", &pyobj_node,
2471 &py_file, &encoding, &format))
2473 node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
2476 return (PyInt_FromLong((long) -1));
2478 if ((py_file == NULL) || (!(PyFile_Check(py_file)))) {
2479 return (PyInt_FromLong((long) -1));
2481 output = PyFile_AsFile(py_file);
2482 if (output == NULL) {
2483 return (PyInt_FromLong((long) -1));
2486 if (node->type == XML_DOCUMENT_NODE) {
2487 doc = (xmlDocPtr) node;
2488 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2489 doc = (xmlDocPtr) node;
2493 if (doc->type == XML_HTML_DOCUMENT_NODE) {
2494 if (encoding == NULL)
2495 encoding = (const char *) htmlGetMetaEncoding(doc);
2497 if (encoding != NULL) {
2498 handler = xmlFindCharEncodingHandler(encoding);
2499 if (handler == NULL) {
2500 return (PyInt_FromLong((long) -1));
2503 if (doc->type == XML_HTML_DOCUMENT_NODE) {
2504 if (handler == NULL)
2505 handler = xmlFindCharEncodingHandler("HTML");
2506 if (handler == NULL)
2507 handler = xmlFindCharEncodingHandler("ascii");
2510 buf = xmlOutputBufferCreateFile(output, handler);
2511 if (node->type == XML_DOCUMENT_NODE) {
2512 len = xmlSaveFormatFileTo(buf, doc, encoding, format);
2513 } else if (node->type == XML_HTML_DOCUMENT_NODE) {
2514 htmlDocContentDumpFormatOutput(buf, doc, encoding, format);
2515 len = xmlOutputBufferClose(buf);
2516 } else if (doc->type == XML_HTML_DOCUMENT_NODE) {
2517 htmlNodeDumpFormatOutput(buf, doc, node, encoding, format);
2518 len = xmlOutputBufferClose(buf);
2520 xmlNodeDumpOutput(buf, doc, node, 0, format, encoding);
2521 len = xmlOutputBufferClose(buf);
2523 return (PyInt_FromLong((long) len));
2526 /************************************************************************
2530 ************************************************************************/
2532 libxml_xmlNewNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2534 PyObject *py_retval;
2538 if (!PyArg_ParseTuple(args, (char *) "s:xmlNewNode", &name))
2540 node = (xmlNodePtr) xmlNewNode(NULL, name);
2542 printf("NewNode: %s : %p\n", name, (void *) node);
2549 py_retval = libxml_xmlNodePtrWrap(node);
2554 /************************************************************************
2556 * Local Catalog stuff *
2558 ************************************************************************/
2560 libxml_addLocalCatalog(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2563 xmlParserCtxtPtr ctxt;
2564 PyObject *pyobj_ctxt;
2566 if (!PyArg_ParseTuple(args, (char *)"Os:addLocalCatalog", &pyobj_ctxt, &URL))
2569 ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
2572 ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs, URL);
2576 printf("LocalCatalog: %s\n", URL);
2583 #ifdef LIBXML_SCHEMAS_ENABLED
2585 /************************************************************************
2587 * RelaxNG error handler registration *
2589 ************************************************************************/
2596 } xmlRelaxNGValidCtxtPyCtxt;
2597 typedef xmlRelaxNGValidCtxtPyCtxt *xmlRelaxNGValidCtxtPyCtxtPtr;
2600 libxml_xmlRelaxNGValidityGenericErrorFuncHandler(void *ctx, char *str)
2604 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
2607 printf("libxml_xmlRelaxNGValidityGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str);
2610 pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx;
2612 list = PyTuple_New(2);
2613 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
2614 PyTuple_SetItem(list, 1, pyCtxt->arg);
2615 Py_XINCREF(pyCtxt->arg);
2616 result = PyEval_CallObject(pyCtxt->error, list);
2619 /* TODO: manage for the exception to be propagated... */
2627 libxml_xmlRelaxNGValidityGenericWarningFuncHandler(void *ctx, char *str)
2631 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
2634 printf("libxml_xmlRelaxNGValidityGenericWarningFuncHandler(%p, %s, ...) called\n", ctx, str);
2637 pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx;
2639 list = PyTuple_New(2);
2640 PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
2641 PyTuple_SetItem(list, 1, pyCtxt->arg);
2642 Py_XINCREF(pyCtxt->arg);
2643 result = PyEval_CallObject(pyCtxt->warn, list);
2646 /* TODO: manage for the exception to be propagated... */
2654 libxml_xmlRelaxNGValidityErrorFunc(void *ctx, const char *msg, ...)
2659 libxml_xmlRelaxNGValidityGenericErrorFuncHandler(ctx, libxml_buildMessage(msg, ap));
2664 libxml_xmlRelaxNGValidityWarningFunc(void *ctx, const char *msg, ...)
2669 libxml_xmlRelaxNGValidityGenericWarningFuncHandler(ctx, libxml_buildMessage(msg, ap));
2674 libxml_xmlRelaxNGSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
2676 PyObject *py_retval;
2677 PyObject *pyobj_error;
2678 PyObject *pyobj_warn;
2679 PyObject *pyobj_ctx;
2680 PyObject *pyobj_arg = Py_None;
2681 xmlRelaxNGValidCtxtPtr ctxt;
2682 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
2684 if (!PyArg_ParseTuple
2685 (args, (char *) "OOO|O:xmlRelaxNGSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg))
2689 printf("libxml_xmlRelaxNGSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn);
2692 ctxt = PyrelaxNgValidCtxt_Get(pyobj_ctx);
2693 if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == -1)
2695 py_retval = libxml_intWrap(-1);
2701 /* first time to set the error handlers */
2702 pyCtxt = xmlMalloc(sizeof(xmlRelaxNGValidCtxtPyCtxt));
2703 if (pyCtxt == NULL) {
2704 py_retval = libxml_intWrap(-1);
2707 memset(pyCtxt, 0, sizeof(xmlRelaxNGValidCtxtPyCtxt));
2710 /* TODO: check warn and error is a function ! */
2711 Py_XDECREF(pyCtxt->error);
2712 Py_XINCREF(pyobj_error);
2713 pyCtxt->error = pyobj_error;
2715 Py_XDECREF(pyCtxt->warn);
2716 Py_XINCREF(pyobj_warn);
2717 pyCtxt->warn = pyobj_warn;
2719 Py_XDECREF(pyCtxt->arg);
2720 Py_XINCREF(pyobj_arg);
2721 pyCtxt->arg = pyobj_arg;
2723 xmlRelaxNGSetValidErrors(ctxt, &libxml_xmlRelaxNGValidityErrorFunc, &libxml_xmlRelaxNGValidityWarningFunc, pyCtxt);
2725 py_retval = libxml_intWrap(1);
2730 libxml_xmlRelaxNGFreeValidCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) {
2731 xmlRelaxNGValidCtxtPtr ctxt;
2732 xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt;
2733 PyObject *pyobj_ctxt;
2735 if (!PyArg_ParseTuple(args, (char *)"O:xmlRelaxNGFreeValidCtxt", &pyobj_ctxt))
2737 ctxt = (xmlRelaxNGValidCtxtPtr) PyrelaxNgValidCtxt_Get(pyobj_ctxt);
2739 if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == 0)
2743 Py_XDECREF(pyCtxt->error);
2744 Py_XDECREF(pyCtxt->warn);
2745 Py_XDECREF(pyCtxt->arg);
2750 xmlRelaxNGFreeValidCtxt(ctxt);
2757 /************************************************************************
2759 * The registration stuff *
2761 ************************************************************************/
2762 static PyMethodDef libxmlMethods[] = {
2763 #include "libxml2-export.c"
2764 {(char *) "name", libxml_name, METH_VARARGS, NULL},
2765 {(char *) "children", libxml_children, METH_VARARGS, NULL},
2766 {(char *) "properties", libxml_properties, METH_VARARGS, NULL},
2767 {(char *) "last", libxml_last, METH_VARARGS, NULL},
2768 {(char *) "prev", libxml_prev, METH_VARARGS, NULL},
2769 {(char *) "next", libxml_next, METH_VARARGS, NULL},
2770 {(char *) "parent", libxml_parent, METH_VARARGS, NULL},
2771 {(char *) "type", libxml_type, METH_VARARGS, NULL},
2772 {(char *) "doc", libxml_doc, METH_VARARGS, NULL},
2773 {(char *) "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL},
2774 {(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL},
2775 {(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL},
2776 {(char *) "outputBufferCreate", libxml_xmlCreateOutputBuffer, METH_VARARGS, NULL},
2777 {(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL},
2778 {(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL},
2779 {(char *)"xmlRegisterErrorHandler", libxml_xmlRegisterErrorHandler, METH_VARARGS, NULL },
2780 {(char *)"xmlParserCtxtSetErrorHandler", libxml_xmlParserCtxtSetErrorHandler, METH_VARARGS, NULL },
2781 {(char *)"xmlParserCtxtGetErrorHandler", libxml_xmlParserCtxtGetErrorHandler, METH_VARARGS, NULL },
2782 {(char *)"xmlFreeParserCtxt", libxml_xmlFreeParserCtxt, METH_VARARGS, NULL },
2783 {(char *)"xmlTextReaderSetErrorHandler", libxml_xmlTextReaderSetErrorHandler, METH_VARARGS, NULL },
2784 {(char *)"xmlTextReaderGetErrorHandler", libxml_xmlTextReaderGetErrorHandler, METH_VARARGS, NULL },
2785 {(char *)"xmlFreeTextReader", libxml_xmlFreeTextReader, METH_VARARGS, NULL },
2786 {(char *)"addLocalCatalog", libxml_addLocalCatalog, METH_VARARGS, NULL },
2787 #ifdef LIBXML_SCHEMAS_ENABLED
2788 {(char *)"xmlRelaxNGSetValidErrors", libxml_xmlRelaxNGSetValidErrors, METH_VARARGS, NULL},
2789 {(char *)"xmlRelaxNGFreeValidCtxt", libxml_xmlRelaxNGFreeValidCtxt, METH_VARARGS, NULL},
2791 {NULL, NULL, 0, NULL}
2794 #ifdef MERGED_MODULES
2795 extern void initlibxsltmod(void);
2799 initlibxml2mod(void)
2801 static int initialized = 0;
2804 if (initialized != 0)
2806 /* XXX xmlInitParser does much more than this */
2808 xmlRegisterDefaultOutputCallbacks();
2809 xmlRegisterDefaultInputCallbacks();
2810 m = Py_InitModule((char *) "libxml2mod", libxmlMethods);
2812 libxml_xmlErrorInitialize();
2814 #ifdef MERGED_MODULES