Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1 | /* |
| 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. |
| 6 | * |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 7 | * If compiled with MERGED_MODULES, the entry point will be used to |
| 8 | * initialize both the libxml2 and the libxslt wrappers |
| 9 | * |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 10 | * See Copyright for the status of this software. |
| 11 | * |
| 12 | * daniel@veillard.com |
| 13 | */ |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 14 | #include <Python.h> |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 15 | #include <fileobject.h> |
Daniel Veillard | a1196ed | 2002-11-23 11:22:49 +0000 | [diff] [blame] | 16 | /* #include "config.h" */ |
Daniel Veillard | f1d0e6b | 2002-01-31 23:42:44 +0000 | [diff] [blame] | 17 | #include <libxml/xmlmemory.h> |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 18 | #include <libxml/parser.h> |
| 19 | #include <libxml/tree.h> |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 20 | #include <libxml/xpath.h> |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 21 | #include <libxml/xmlerror.h> |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 22 | #include <libxml/xpathInternals.h> |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 23 | #include <libxml/xmlmemory.h> |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 24 | #include <libxml/xmlIO.h> |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 25 | #include <libxml/c14n.h> |
Daniel Veillard | 438ebbd | 2008-05-12 12:58:46 +0000 | [diff] [blame] | 26 | #include <libxml/xmlreader.h> |
Daniel Veillard | da3fee4 | 2008-09-01 13:08:57 +0000 | [diff] [blame] | 27 | #include <libxml/xmlsave.h> |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 28 | #include "libxml_wrap.h" |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 29 | #include "libxml2-py.h" |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 30 | |
Roumen Petrov | c3b1d09 | 2012-08-13 16:50:48 +0800 | [diff] [blame] | 31 | #if defined(WITH_TRIO) |
Daniel Veillard | e4fa293 | 2003-03-26 00:38:10 +0000 | [diff] [blame] | 32 | #include "trio.h" |
| 33 | #define vsnprintf trio_vsnprintf |
Daniel Veillard | 0d132cf | 2002-12-23 14:43:32 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 36 | /* #define DEBUG */ |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 37 | /* #define DEBUG_SAX */ |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 38 | /* #define DEBUG_XPATH */ |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 39 | /* #define DEBUG_ERROR */ |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 40 | /* #define DEBUG_MEMORY */ |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 41 | /* #define DEBUG_FILES */ |
| 42 | /* #define DEBUG_LOADER */ |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 43 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 44 | void initlibxml2mod(void); |
| 45 | |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 46 | /** |
| 47 | * TODO: |
| 48 | * |
| 49 | * macro to flag unimplemented blocks |
| 50 | */ |
| 51 | #define TODO \ |
| 52 | xmlGenericError(xmlGenericErrorContext, \ |
| 53 | "Unimplemented block at %s:%d\n", \ |
| 54 | __FILE__, __LINE__); |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 55 | /* |
| 56 | * the following vars are used for XPath extensions, but |
| 57 | * are also referenced within the parser cleanup routine. |
| 58 | */ |
| 59 | static int libxml_xpathCallbacksInitialized = 0; |
| 60 | |
| 61 | typedef struct libxml_xpathCallback { |
| 62 | xmlXPathContextPtr ctx; |
| 63 | xmlChar *name; |
| 64 | xmlChar *ns_uri; |
| 65 | PyObject *function; |
| 66 | } libxml_xpathCallback, *libxml_xpathCallbackPtr; |
| 67 | typedef libxml_xpathCallback libxml_xpathCallbackArray[]; |
| 68 | static int libxml_xpathCallbacksAllocd = 10; |
| 69 | static libxml_xpathCallbackArray *libxml_xpathCallbacks = NULL; |
| 70 | static int libxml_xpathCallbacksNb = 0; |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 71 | |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 72 | /************************************************************************ |
| 73 | * * |
| 74 | * Memory debug interface * |
| 75 | * * |
| 76 | ************************************************************************/ |
| 77 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 78 | #if 0 |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 79 | extern void xmlMemFree(void *ptr); |
| 80 | extern void *xmlMemMalloc(size_t size); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 81 | extern void *xmlMemRealloc(void *ptr, size_t size); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 82 | extern char *xmlMemoryStrdup(const char *str); |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 83 | #endif |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 84 | |
| 85 | static int libxmlMemoryDebugActivated = 0; |
| 86 | static long libxmlMemoryAllocatedBase = 0; |
| 87 | |
| 88 | static int libxmlMemoryDebug = 0; |
| 89 | static xmlFreeFunc freeFunc = NULL; |
| 90 | static xmlMallocFunc mallocFunc = NULL; |
| 91 | static xmlReallocFunc reallocFunc = NULL; |
| 92 | static xmlStrdupFunc strdupFunc = NULL; |
| 93 | |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 94 | static void |
| 95 | libxml_xmlErrorInitialize(void); /* forward declare */ |
| 96 | |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 97 | PyObject * |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 98 | libxml_xmlMemoryUsed(PyObject * self ATTRIBUTE_UNUSED, |
| 99 | PyObject * args ATTRIBUTE_UNUSED) |
Daniel Veillard | 529233c | 2004-07-02 12:23:44 +0000 | [diff] [blame] | 100 | { |
| 101 | long ret; |
| 102 | PyObject *py_retval; |
| 103 | |
| 104 | ret = xmlMemUsed(); |
| 105 | |
| 106 | py_retval = libxml_longWrap(ret); |
| 107 | return (py_retval); |
| 108 | } |
| 109 | |
| 110 | PyObject * |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 111 | libxml_xmlDebugMemory(PyObject * self ATTRIBUTE_UNUSED, PyObject * args) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 112 | { |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 113 | int activate; |
| 114 | PyObject *py_retval; |
| 115 | long ret; |
| 116 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 117 | if (!PyArg_ParseTuple(args, (char *) "i:xmlDebugMemory", &activate)) |
| 118 | return (NULL); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 119 | |
| 120 | #ifdef DEBUG_MEMORY |
| 121 | printf("libxml_xmlDebugMemory(%d) called\n", activate); |
| 122 | #endif |
| 123 | |
| 124 | if (activate != 0) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 125 | if (libxmlMemoryDebug == 0) { |
| 126 | /* |
| 127 | * First initialize the library and grab the old memory handlers |
| 128 | * and switch the library to memory debugging |
| 129 | */ |
| 130 | xmlMemGet((xmlFreeFunc *) & freeFunc, |
| 131 | (xmlMallocFunc *) & mallocFunc, |
| 132 | (xmlReallocFunc *) & reallocFunc, |
| 133 | (xmlStrdupFunc *) & strdupFunc); |
| 134 | if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) && |
| 135 | (reallocFunc == xmlMemRealloc) && |
| 136 | (strdupFunc == xmlMemoryStrdup)) { |
| 137 | libxmlMemoryAllocatedBase = xmlMemUsed(); |
| 138 | } else { |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 139 | /* |
| 140 | * cleanup first, because some memory has been |
| 141 | * allocated with the non-debug malloc in xmlInitParser |
| 142 | * when the python module was imported |
| 143 | */ |
| 144 | xmlCleanupParser(); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 145 | ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc, |
| 146 | xmlMemRealloc, xmlMemoryStrdup); |
| 147 | if (ret < 0) |
| 148 | goto error; |
| 149 | libxmlMemoryAllocatedBase = xmlMemUsed(); |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 150 | /* reinitialize */ |
| 151 | xmlInitParser(); |
| 152 | libxml_xmlErrorInitialize(); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 153 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 154 | ret = 0; |
| 155 | } else if (libxmlMemoryDebugActivated == 0) { |
| 156 | libxmlMemoryAllocatedBase = xmlMemUsed(); |
| 157 | ret = 0; |
| 158 | } else { |
| 159 | ret = xmlMemUsed() - libxmlMemoryAllocatedBase; |
| 160 | } |
| 161 | libxmlMemoryDebug = 1; |
| 162 | libxmlMemoryDebugActivated = 1; |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 163 | } else { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 164 | if (libxmlMemoryDebugActivated == 1) |
| 165 | ret = xmlMemUsed() - libxmlMemoryAllocatedBase; |
| 166 | else |
| 167 | ret = 0; |
| 168 | libxmlMemoryDebugActivated = 0; |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 169 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 170 | error: |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 171 | py_retval = libxml_longWrap(ret); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 172 | return (py_retval); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | PyObject * |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 176 | libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED, |
| 177 | PyObject *args ATTRIBUTE_UNUSED) { |
| 178 | |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 179 | int ix; |
| 180 | long freed = -1; |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 181 | |
| 182 | if (libxmlMemoryDebug) { |
| 183 | freed = xmlMemUsed(); |
| 184 | } |
| 185 | |
| 186 | xmlCleanupParser(); |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 187 | /* |
| 188 | * Need to confirm whether we really want to do this (required for |
| 189 | * memcheck) in all cases... |
| 190 | */ |
| 191 | |
| 192 | if (libxml_xpathCallbacks != NULL) { /* if ext funcs declared */ |
| 193 | for (ix=0; ix<libxml_xpathCallbacksNb; ix++) { |
| 194 | if ((*libxml_xpathCallbacks)[ix].name != NULL) |
| 195 | xmlFree((*libxml_xpathCallbacks)[ix].name); |
| 196 | if ((*libxml_xpathCallbacks)[ix].ns_uri != NULL) |
| 197 | xmlFree((*libxml_xpathCallbacks)[ix].ns_uri); |
| 198 | } |
| 199 | libxml_xpathCallbacksNb = 0; |
| 200 | xmlFree(libxml_xpathCallbacks); |
| 201 | libxml_xpathCallbacks = NULL; |
| 202 | } |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 203 | |
| 204 | if (libxmlMemoryDebug) { |
| 205 | freed -= xmlMemUsed(); |
| 206 | libxmlMemoryAllocatedBase -= freed; |
| 207 | if (libxmlMemoryAllocatedBase < 0) |
| 208 | libxmlMemoryAllocatedBase = 0; |
| 209 | } |
| 210 | |
| 211 | Py_INCREF(Py_None); |
| 212 | return(Py_None); |
| 213 | } |
| 214 | |
| 215 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 216 | libxml_xmlDumpMemory(ATTRIBUTE_UNUSED PyObject * self, |
| 217 | ATTRIBUTE_UNUSED PyObject * args) |
| 218 | { |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 219 | |
| 220 | if (libxmlMemoryDebug != 0) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 221 | xmlMemoryDump(); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 222 | Py_INCREF(Py_None); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 223 | return (Py_None); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 224 | } |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 225 | |
| 226 | /************************************************************************ |
| 227 | * * |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 228 | * Handling Python FILE I/O at the C level * |
| 229 | * The raw I/O attack diectly the File objects, while the * |
| 230 | * other routines address the ioWrapper instance instead * |
| 231 | * * |
| 232 | ************************************************************************/ |
| 233 | |
| 234 | /** |
| 235 | * xmlPythonFileCloseUnref: |
| 236 | * @context: the I/O context |
| 237 | * |
| 238 | * Close an I/O channel |
| 239 | */ |
| 240 | static int |
| 241 | xmlPythonFileCloseRaw (void * context) { |
| 242 | PyObject *file, *ret; |
| 243 | |
| 244 | #ifdef DEBUG_FILES |
| 245 | printf("xmlPythonFileCloseUnref\n"); |
| 246 | #endif |
| 247 | file = (PyObject *) context; |
| 248 | if (file == NULL) return(-1); |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 249 | ret = PyEval_CallMethod(file, (char *) "close", (char *) "()"); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 250 | if (ret != NULL) { |
| 251 | Py_DECREF(ret); |
| 252 | } |
| 253 | Py_DECREF(file); |
| 254 | return(0); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * xmlPythonFileReadRaw: |
| 259 | * @context: the I/O context |
| 260 | * @buffer: where to drop data |
| 261 | * @len: number of bytes to write |
| 262 | * |
| 263 | * Read @len bytes to @buffer from the Python file in the I/O channel |
| 264 | * |
| 265 | * Returns the number of bytes read |
| 266 | */ |
| 267 | static int |
| 268 | xmlPythonFileReadRaw (void * context, char * buffer, int len) { |
| 269 | PyObject *file; |
| 270 | PyObject *ret; |
| 271 | int lenread = -1; |
| 272 | char *data; |
| 273 | |
| 274 | #ifdef DEBUG_FILES |
| 275 | printf("xmlPythonFileReadRaw: %d\n", len); |
| 276 | #endif |
| 277 | file = (PyObject *) context; |
| 278 | if (file == NULL) return(-1); |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 279 | ret = PyEval_CallMethod(file, (char *) "read", (char *) "(i)", len); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 280 | if (ret == NULL) { |
| 281 | printf("xmlPythonFileReadRaw: result is NULL\n"); |
| 282 | return(-1); |
| 283 | } else if (PyString_Check(ret)) { |
| 284 | lenread = PyString_Size(ret); |
| 285 | data = PyString_AsString(ret); |
| 286 | if (lenread > len) |
| 287 | memcpy(buffer, data, len); |
| 288 | else |
| 289 | memcpy(buffer, data, lenread); |
| 290 | Py_DECREF(ret); |
| 291 | } else { |
| 292 | printf("xmlPythonFileReadRaw: result is not a String\n"); |
| 293 | Py_DECREF(ret); |
| 294 | } |
| 295 | return(lenread); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * xmlPythonFileRead: |
| 300 | * @context: the I/O context |
| 301 | * @buffer: where to drop data |
| 302 | * @len: number of bytes to write |
| 303 | * |
| 304 | * Read @len bytes to @buffer from the I/O channel. |
| 305 | * |
| 306 | * Returns the number of bytes read |
| 307 | */ |
| 308 | static int |
| 309 | xmlPythonFileRead (void * context, char * buffer, int len) { |
| 310 | PyObject *file; |
| 311 | PyObject *ret; |
| 312 | int lenread = -1; |
| 313 | char *data; |
| 314 | |
| 315 | #ifdef DEBUG_FILES |
| 316 | printf("xmlPythonFileRead: %d\n", len); |
| 317 | #endif |
| 318 | file = (PyObject *) context; |
| 319 | if (file == NULL) return(-1); |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 320 | ret = PyEval_CallMethod(file, (char *) "io_read", (char *) "(i)", len); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 321 | if (ret == NULL) { |
| 322 | printf("xmlPythonFileRead: result is NULL\n"); |
| 323 | return(-1); |
| 324 | } else if (PyString_Check(ret)) { |
| 325 | lenread = PyString_Size(ret); |
| 326 | data = PyString_AsString(ret); |
| 327 | if (lenread > len) |
| 328 | memcpy(buffer, data, len); |
| 329 | else |
| 330 | memcpy(buffer, data, lenread); |
| 331 | Py_DECREF(ret); |
| 332 | } else { |
| 333 | printf("xmlPythonFileRead: result is not a String\n"); |
| 334 | Py_DECREF(ret); |
| 335 | } |
| 336 | return(lenread); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * xmlFileWrite: |
| 341 | * @context: the I/O context |
| 342 | * @buffer: where to drop data |
| 343 | * @len: number of bytes to write |
| 344 | * |
| 345 | * Write @len bytes from @buffer to the I/O channel. |
| 346 | * |
| 347 | * Returns the number of bytes written |
| 348 | */ |
| 349 | static int |
| 350 | xmlPythonFileWrite (void * context, const char * buffer, int len) { |
| 351 | PyObject *file; |
| 352 | PyObject *string; |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 353 | PyObject *ret = NULL; |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 354 | int written = -1; |
| 355 | |
| 356 | #ifdef DEBUG_FILES |
| 357 | printf("xmlPythonFileWrite: %d\n", len); |
| 358 | #endif |
| 359 | file = (PyObject *) context; |
| 360 | if (file == NULL) return(-1); |
| 361 | string = PyString_FromStringAndSize(buffer, len); |
| 362 | if (string == NULL) return(-1); |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 363 | if (PyObject_HasAttrString(file, (char *) "io_write")) { |
| 364 | ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", |
| 365 | string); |
| 366 | } else if (PyObject_HasAttrString(file, (char *) "write")) { |
| 367 | ret = PyEval_CallMethod(file, (char *) "write", (char *) "(O)", |
| 368 | string); |
| 369 | } |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 370 | Py_DECREF(string); |
| 371 | if (ret == NULL) { |
| 372 | printf("xmlPythonFileWrite: result is NULL\n"); |
| 373 | return(-1); |
| 374 | } else if (PyInt_Check(ret)) { |
| 375 | written = (int) PyInt_AsLong(ret); |
| 376 | Py_DECREF(ret); |
| 377 | } else if (ret == Py_None) { |
| 378 | written = len; |
| 379 | Py_DECREF(ret); |
| 380 | } else { |
| 381 | printf("xmlPythonFileWrite: result is not an Int nor None\n"); |
| 382 | Py_DECREF(ret); |
| 383 | } |
| 384 | return(written); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * xmlPythonFileClose: |
| 389 | * @context: the I/O context |
| 390 | * |
| 391 | * Close an I/O channel |
| 392 | */ |
| 393 | static int |
| 394 | xmlPythonFileClose (void * context) { |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 395 | PyObject *file, *ret = NULL; |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 396 | |
| 397 | #ifdef DEBUG_FILES |
| 398 | printf("xmlPythonFileClose\n"); |
| 399 | #endif |
| 400 | file = (PyObject *) context; |
| 401 | if (file == NULL) return(-1); |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 402 | if (PyObject_HasAttrString(file, (char *) "io_close")) { |
| 403 | ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()"); |
| 404 | } else if (PyObject_HasAttrString(file, (char *) "flush")) { |
| 405 | ret = PyEval_CallMethod(file, (char *) "flush", (char *) "()"); |
| 406 | } |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 407 | if (ret != NULL) { |
| 408 | Py_DECREF(ret); |
| 409 | } |
| 410 | return(0); |
| 411 | } |
| 412 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 413 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 414 | /** |
| 415 | * xmlOutputBufferCreatePythonFile: |
| 416 | * @file: a PyFile_Type |
| 417 | * @encoder: the encoding converter or NULL |
| 418 | * |
| 419 | * Create a buffered output for the progressive saving to a PyFile_Type |
| 420 | * buffered C I/O |
| 421 | * |
| 422 | * Returns the new parser output or NULL |
| 423 | */ |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 424 | static xmlOutputBufferPtr |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 425 | xmlOutputBufferCreatePythonFile(PyObject *file, |
| 426 | xmlCharEncodingHandlerPtr encoder) { |
| 427 | xmlOutputBufferPtr ret; |
| 428 | |
| 429 | if (file == NULL) return(NULL); |
| 430 | |
| 431 | ret = xmlAllocOutputBuffer(encoder); |
| 432 | if (ret != NULL) { |
| 433 | ret->context = file; |
| 434 | /* Py_INCREF(file); */ |
| 435 | ret->writecallback = xmlPythonFileWrite; |
| 436 | ret->closecallback = xmlPythonFileClose; |
| 437 | } |
| 438 | |
| 439 | return(ret); |
| 440 | } |
| 441 | |
| 442 | PyObject * |
| 443 | libxml_xmlCreateOutputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 444 | PyObject *py_retval; |
| 445 | PyObject *file; |
| 446 | xmlChar *encoding; |
| 447 | xmlCharEncodingHandlerPtr handler = NULL; |
| 448 | xmlOutputBufferPtr buffer; |
| 449 | |
| 450 | |
| 451 | if (!PyArg_ParseTuple(args, (char *)"Oz:xmlOutputBufferCreate", |
| 452 | &file, &encoding)) |
| 453 | return(NULL); |
| 454 | if ((encoding != NULL) && (encoding[0] != 0)) { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 455 | handler = xmlFindCharEncodingHandler((const char *) encoding); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 456 | } |
| 457 | buffer = xmlOutputBufferCreatePythonFile(file, handler); |
| 458 | if (buffer == NULL) |
| 459 | printf("libxml_xmlCreateOutputBuffer: buffer == NULL\n"); |
| 460 | py_retval = libxml_xmlOutputBufferPtrWrap(buffer); |
| 461 | return(py_retval); |
| 462 | } |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 463 | |
| 464 | /** |
| 465 | * libxml_outputBufferGetPythonFile: |
| 466 | * @buffer: the I/O buffer |
| 467 | * |
| 468 | * read the Python I/O from the CObject |
| 469 | * |
| 470 | * Returns the new parser output or NULL |
| 471 | */ |
| 472 | static PyObject * |
| 473 | libxml_outputBufferGetPythonFile(ATTRIBUTE_UNUSED PyObject *self, |
| 474 | PyObject *args) { |
| 475 | PyObject *buffer; |
| 476 | PyObject *file; |
| 477 | xmlOutputBufferPtr obj; |
| 478 | |
| 479 | if (!PyArg_ParseTuple(args, (char *)"O:outputBufferGetPythonFile", |
| 480 | &buffer)) |
| 481 | return(NULL); |
| 482 | |
| 483 | obj = PyoutputBuffer_Get(buffer); |
| 484 | if (obj == NULL) { |
| 485 | fprintf(stderr, |
| 486 | "outputBufferGetPythonFile: obj == NULL\n"); |
| 487 | Py_INCREF(Py_None); |
| 488 | return(Py_None); |
| 489 | } |
| 490 | if (obj->closecallback != xmlPythonFileClose) { |
| 491 | fprintf(stderr, |
| 492 | "outputBufferGetPythonFile: not a python file wrapper\n"); |
| 493 | Py_INCREF(Py_None); |
| 494 | return(Py_None); |
| 495 | } |
| 496 | file = (PyObject *) obj->context; |
| 497 | if (file == NULL) { |
| 498 | Py_INCREF(Py_None); |
| 499 | return(Py_None); |
| 500 | } |
| 501 | Py_INCREF(file); |
| 502 | return(file); |
| 503 | } |
| 504 | |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 505 | static PyObject * |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 506 | libxml_xmlOutputBufferClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 507 | PyObject *py_retval; |
| 508 | int c_retval; |
| 509 | xmlOutputBufferPtr out; |
| 510 | PyObject *pyobj_out; |
| 511 | |
| 512 | if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferClose", &pyobj_out)) |
| 513 | return(NULL); |
| 514 | out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out); |
Daniel Veillard | 263ec86 | 2004-10-04 10:26:54 +0000 | [diff] [blame] | 515 | /* Buffer may already have been destroyed elsewhere. This is harmless. */ |
| 516 | if (out == NULL) { |
| 517 | Py_INCREF(Py_None); |
| 518 | return(Py_None); |
| 519 | } |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 520 | |
| 521 | c_retval = xmlOutputBufferClose(out); |
| 522 | py_retval = libxml_intWrap((int) c_retval); |
| 523 | return(py_retval); |
| 524 | } |
| 525 | |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 526 | static PyObject * |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 527 | libxml_xmlOutputBufferFlush(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 528 | PyObject *py_retval; |
| 529 | int c_retval; |
| 530 | xmlOutputBufferPtr out; |
| 531 | PyObject *pyobj_out; |
| 532 | |
| 533 | if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferFlush", &pyobj_out)) |
| 534 | return(NULL); |
| 535 | out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out); |
| 536 | |
| 537 | c_retval = xmlOutputBufferFlush(out); |
| 538 | py_retval = libxml_intWrap((int) c_retval); |
| 539 | return(py_retval); |
| 540 | } |
Daniel Veillard | 263ec86 | 2004-10-04 10:26:54 +0000 | [diff] [blame] | 541 | |
| 542 | static PyObject * |
| 543 | libxml_xmlSaveFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 544 | PyObject *py_retval; |
| 545 | int c_retval; |
| 546 | xmlOutputBufferPtr buf; |
| 547 | PyObject *pyobj_buf; |
| 548 | xmlDocPtr cur; |
| 549 | PyObject *pyobj_cur; |
| 550 | char * encoding; |
| 551 | |
| 552 | if (!PyArg_ParseTuple(args, (char *)"OOz:xmlSaveFileTo", &pyobj_buf, &pyobj_cur, &encoding)) |
| 553 | return(NULL); |
| 554 | buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); |
| 555 | cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); |
| 556 | |
| 557 | c_retval = xmlSaveFileTo(buf, cur, encoding); |
| 558 | /* xmlSaveTo() freed the memory pointed to by buf, so record that in the |
| 559 | * Python object. */ |
| 560 | ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL; |
| 561 | py_retval = libxml_intWrap((int) c_retval); |
| 562 | return(py_retval); |
| 563 | } |
| 564 | |
| 565 | static PyObject * |
| 566 | libxml_xmlSaveFormatFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 567 | PyObject *py_retval; |
| 568 | int c_retval; |
| 569 | xmlOutputBufferPtr buf; |
| 570 | PyObject *pyobj_buf; |
| 571 | xmlDocPtr cur; |
| 572 | PyObject *pyobj_cur; |
| 573 | char * encoding; |
| 574 | int format; |
| 575 | |
| 576 | if (!PyArg_ParseTuple(args, (char *)"OOzi:xmlSaveFormatFileTo", &pyobj_buf, &pyobj_cur, &encoding, &format)) |
| 577 | return(NULL); |
| 578 | buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); |
| 579 | cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); |
| 580 | |
| 581 | c_retval = xmlSaveFormatFileTo(buf, cur, encoding, format); |
| 582 | /* xmlSaveFormatFileTo() freed the memory pointed to by buf, so record that |
| 583 | * in the Python object */ |
| 584 | ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL; |
| 585 | py_retval = libxml_intWrap((int) c_retval); |
| 586 | return(py_retval); |
| 587 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 588 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 589 | |
| 590 | |
| 591 | /** |
| 592 | * xmlParserInputBufferCreatePythonFile: |
| 593 | * @file: a PyFile_Type |
| 594 | * @encoder: the encoding converter or NULL |
| 595 | * |
| 596 | * Create a buffered output for the progressive saving to a PyFile_Type |
| 597 | * buffered C I/O |
| 598 | * |
| 599 | * Returns the new parser output or NULL |
| 600 | */ |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 601 | static xmlParserInputBufferPtr |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 602 | xmlParserInputBufferCreatePythonFile(PyObject *file, |
| 603 | xmlCharEncoding encoding) { |
| 604 | xmlParserInputBufferPtr ret; |
| 605 | |
| 606 | if (file == NULL) return(NULL); |
| 607 | |
| 608 | ret = xmlAllocParserInputBuffer(encoding); |
| 609 | if (ret != NULL) { |
| 610 | ret->context = file; |
| 611 | /* Py_INCREF(file); */ |
| 612 | ret->readcallback = xmlPythonFileRead; |
| 613 | ret->closecallback = xmlPythonFileClose; |
| 614 | } |
| 615 | |
| 616 | return(ret); |
| 617 | } |
| 618 | |
| 619 | PyObject * |
| 620 | libxml_xmlCreateInputBuffer(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 621 | PyObject *py_retval; |
| 622 | PyObject *file; |
| 623 | xmlChar *encoding; |
| 624 | xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; |
| 625 | xmlParserInputBufferPtr buffer; |
| 626 | |
| 627 | |
| 628 | if (!PyArg_ParseTuple(args, (char *)"Oz:xmlParserInputBufferCreate", |
| 629 | &file, &encoding)) |
| 630 | return(NULL); |
| 631 | if ((encoding != NULL) && (encoding[0] != 0)) { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 632 | enc = xmlParseCharEncoding((const char *) encoding); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 633 | } |
| 634 | buffer = xmlParserInputBufferCreatePythonFile(file, enc); |
| 635 | if (buffer == NULL) |
| 636 | printf("libxml_xmlParserInputBufferCreate: buffer == NULL\n"); |
| 637 | py_retval = libxml_xmlParserInputBufferPtrWrap(buffer); |
| 638 | return(py_retval); |
| 639 | } |
| 640 | |
| 641 | /************************************************************************ |
| 642 | * * |
| 643 | * Providing the resolver at the Python level * |
| 644 | * * |
| 645 | ************************************************************************/ |
| 646 | |
| 647 | static xmlExternalEntityLoader defaultExternalEntityLoader = NULL; |
| 648 | static PyObject *pythonExternalEntityLoaderObjext; |
| 649 | |
| 650 | static xmlParserInputPtr |
| 651 | pythonExternalEntityLoader(const char *URL, const char *ID, |
| 652 | xmlParserCtxtPtr ctxt) { |
| 653 | xmlParserInputPtr result = NULL; |
| 654 | if (pythonExternalEntityLoaderObjext != NULL) { |
| 655 | PyObject *ret; |
| 656 | PyObject *ctxtobj; |
| 657 | |
| 658 | ctxtobj = libxml_xmlParserCtxtPtrWrap(ctxt); |
| 659 | #ifdef DEBUG_LOADER |
| 660 | printf("pythonExternalEntityLoader: ready to call\n"); |
| 661 | #endif |
| 662 | |
| 663 | ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext, |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 664 | (char *) "(ssO)", URL, ID, ctxtobj); |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 665 | Py_XDECREF(ctxtobj); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 666 | #ifdef DEBUG_LOADER |
| 667 | printf("pythonExternalEntityLoader: result "); |
Daniel Veillard | 007d51e | 2003-09-17 20:07:28 +0000 | [diff] [blame] | 668 | PyObject_Print(ret, stderr, 0); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 669 | printf("\n"); |
| 670 | #endif |
| 671 | |
| 672 | if (ret != NULL) { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 673 | if (PyObject_HasAttrString(ret, (char *) "read")) { |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 674 | xmlParserInputBufferPtr buf; |
| 675 | |
| 676 | buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE); |
| 677 | if (buf != NULL) { |
| 678 | buf->context = ret; |
| 679 | buf->readcallback = xmlPythonFileReadRaw; |
| 680 | buf->closecallback = xmlPythonFileCloseRaw; |
| 681 | result = xmlNewIOInputStream(ctxt, buf, |
| 682 | XML_CHAR_ENCODING_NONE); |
| 683 | } |
Daniel Veillard | 4ea89f0 | 2005-07-29 10:12:45 +0000 | [diff] [blame] | 684 | #if 0 |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 685 | } else { |
Daniel Veillard | 4ea89f0 | 2005-07-29 10:12:45 +0000 | [diff] [blame] | 686 | if (URL != NULL) |
| 687 | printf("pythonExternalEntityLoader: can't read %s\n", |
| 688 | URL); |
| 689 | #endif |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 690 | } |
| 691 | if (result == NULL) { |
| 692 | Py_DECREF(ret); |
Daniel Veillard | c64b8e9 | 2003-02-24 11:47:13 +0000 | [diff] [blame] | 693 | } else if (URL != NULL) { |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 694 | result->filename = (char *) xmlStrdup((const xmlChar *)URL); |
Daniel Veillard | c64b8e9 | 2003-02-24 11:47:13 +0000 | [diff] [blame] | 695 | result->directory = xmlParserGetDirectory((const char *) URL); |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | } |
| 699 | if ((result == NULL) && (defaultExternalEntityLoader != NULL)) { |
| 700 | result = defaultExternalEntityLoader(URL, ID, ctxt); |
| 701 | } |
| 702 | return(result); |
| 703 | } |
| 704 | |
| 705 | PyObject * |
| 706 | libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 707 | PyObject *py_retval; |
| 708 | PyObject *loader; |
| 709 | |
| 710 | if (!PyArg_ParseTuple(args, (char *)"O:libxml_xmlSetEntityLoader", |
| 711 | &loader)) |
| 712 | return(NULL); |
| 713 | |
| 714 | #ifdef DEBUG_LOADER |
| 715 | printf("libxml_xmlSetEntityLoader\n"); |
| 716 | #endif |
| 717 | if (defaultExternalEntityLoader == NULL) |
| 718 | defaultExternalEntityLoader = xmlGetExternalEntityLoader(); |
| 719 | |
| 720 | pythonExternalEntityLoaderObjext = loader; |
| 721 | xmlSetExternalEntityLoader(pythonExternalEntityLoader); |
| 722 | |
| 723 | py_retval = PyInt_FromLong(0); |
| 724 | return(py_retval); |
| 725 | } |
| 726 | |
Alexey Neyman | 48da90b | 2013-02-25 15:54:25 +0800 | [diff] [blame^] | 727 | /************************************************************************ |
| 728 | * * |
| 729 | * Input callback registration * |
| 730 | * * |
| 731 | ************************************************************************/ |
| 732 | static PyObject *pythonInputOpenCallbackObject; |
| 733 | static int pythonInputCallbackID = -1; |
| 734 | |
| 735 | static int |
| 736 | pythonInputMatchCallback(ATTRIBUTE_UNUSED const char *URI) |
| 737 | { |
| 738 | /* Always return success, real decision whether URI is supported will be |
| 739 | * made in open callback. */ |
| 740 | return 1; |
| 741 | } |
| 742 | |
| 743 | static void * |
| 744 | pythonInputOpenCallback(const char *URI) |
| 745 | { |
| 746 | PyObject *ret; |
| 747 | |
| 748 | ret = PyObject_CallFunction(pythonInputOpenCallbackObject, |
| 749 | (char *)"s", URI); |
| 750 | if (ret == Py_None) { |
| 751 | Py_DECREF(Py_None); |
| 752 | return NULL; |
| 753 | } |
| 754 | return ret; |
| 755 | } |
| 756 | |
| 757 | PyObject * |
| 758 | libxml_xmlRegisterInputCallback(ATTRIBUTE_UNUSED PyObject *self, |
| 759 | PyObject *args) { |
| 760 | PyObject *cb; |
| 761 | |
| 762 | if (!PyArg_ParseTuple(args, |
| 763 | (const char *)"O:libxml_xmlRegisterInputCallback", &cb)) |
| 764 | return(NULL); |
| 765 | |
| 766 | if (!PyCallable_Check(cb)) { |
| 767 | PyErr_SetString(PyExc_ValueError, "input callback is not callable"); |
| 768 | return(NULL); |
| 769 | } |
| 770 | |
| 771 | /* Python module registers a single callback and manages the list of |
| 772 | * all callbacks internally. This is necessitated by xmlInputMatchCallback |
| 773 | * API, which does not allow for passing of data objects to discriminate |
| 774 | * different Python methods. */ |
| 775 | if (pythonInputCallbackID == -1) { |
| 776 | pythonInputCallbackID = xmlRegisterInputCallbacks( |
| 777 | pythonInputMatchCallback, pythonInputOpenCallback, |
| 778 | xmlPythonFileReadRaw, xmlPythonFileCloseRaw); |
| 779 | if (pythonInputCallbackID == -1) |
| 780 | return PyErr_NoMemory(); |
| 781 | pythonInputOpenCallbackObject = cb; |
| 782 | Py_INCREF(pythonInputOpenCallbackObject); |
| 783 | } |
| 784 | |
| 785 | Py_INCREF(Py_None); |
| 786 | return(Py_None); |
| 787 | } |
| 788 | |
| 789 | PyObject * |
| 790 | libxml_xmlUnregisterInputCallback(ATTRIBUTE_UNUSED PyObject *self, |
| 791 | ATTRIBUTE_UNUSED PyObject *args) { |
| 792 | int ret; |
| 793 | |
| 794 | ret = xmlPopInputCallbacks(); |
| 795 | if (pythonInputCallbackID != -1) { |
| 796 | /* Assert that the right input callback was popped. libxml's API does not |
| 797 | * allow removal by ID, so all that could be done is an assert. */ |
| 798 | if (pythonInputCallbackID == ret) { |
| 799 | pythonInputCallbackID = -1; |
| 800 | Py_DECREF(pythonInputOpenCallbackObject); |
| 801 | pythonInputOpenCallbackObject = NULL; |
| 802 | } else { |
| 803 | PyErr_SetString(PyExc_AssertionError, "popped non-python input callback"); |
| 804 | return(NULL); |
| 805 | } |
| 806 | } else if (ret == -1) { |
| 807 | /* No more callbacks to pop */ |
| 808 | PyErr_SetString(PyExc_IndexError, "no input callbacks to pop"); |
| 809 | return(NULL); |
| 810 | } |
| 811 | |
| 812 | Py_INCREF(Py_None); |
| 813 | return(Py_None); |
| 814 | } |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 815 | |
| 816 | /************************************************************************ |
| 817 | * * |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 818 | * Handling SAX/xmllib/sgmlop callback interfaces * |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 819 | * * |
| 820 | ************************************************************************/ |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 821 | |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 822 | static void |
| 823 | pythonStartElement(void *user_data, const xmlChar * name, |
| 824 | const xmlChar ** attrs) |
| 825 | { |
| 826 | int i; |
| 827 | PyObject *handler; |
| 828 | PyObject *dict; |
| 829 | PyObject *attrname; |
| 830 | PyObject *attrvalue; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 831 | PyObject *result = NULL; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 832 | int type = 0; |
| 833 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 834 | #ifdef DEBUG_SAX |
| 835 | printf("pythonStartElement(%s) called\n", name); |
| 836 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 837 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 838 | if (PyObject_HasAttrString(handler, (char *) "startElement")) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 839 | type = 1; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 840 | else if (PyObject_HasAttrString(handler, (char *) "start")) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 841 | type = 2; |
| 842 | if (type != 0) { |
| 843 | /* |
| 844 | * the xmllib interface always generate a dictionnary, |
| 845 | * possibly empty |
| 846 | */ |
| 847 | if ((attrs == NULL) && (type == 1)) { |
| 848 | Py_XINCREF(Py_None); |
| 849 | dict = Py_None; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 850 | } else if (attrs == NULL) { |
| 851 | dict = PyDict_New(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 852 | } else { |
| 853 | dict = PyDict_New(); |
| 854 | for (i = 0; attrs[i] != NULL; i++) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 855 | attrname = PyString_FromString((char *) attrs[i]); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 856 | i++; |
| 857 | if (attrs[i] != NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 858 | attrvalue = PyString_FromString((char *) attrs[i]); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 859 | } else { |
| 860 | Py_XINCREF(Py_None); |
| 861 | attrvalue = Py_None; |
| 862 | } |
| 863 | PyDict_SetItem(dict, attrname, attrvalue); |
Daniel Veillard | a3d2305 | 2007-01-09 21:24:34 +0000 | [diff] [blame] | 864 | Py_DECREF(attrname); |
| 865 | Py_DECREF(attrvalue); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | if (type == 1) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 870 | result = PyObject_CallMethod(handler, (char *) "startElement", |
| 871 | (char *) "sO", name, dict); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 872 | else if (type == 2) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 873 | result = PyObject_CallMethod(handler, (char *) "start", |
| 874 | (char *) "sO", name, dict); |
| 875 | if (PyErr_Occurred()) |
| 876 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 877 | Py_XDECREF(dict); |
| 878 | Py_XDECREF(result); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | static void |
| 883 | pythonStartDocument(void *user_data) |
| 884 | { |
| 885 | PyObject *handler; |
| 886 | PyObject *result; |
| 887 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 888 | #ifdef DEBUG_SAX |
| 889 | printf("pythonStartDocument() called\n"); |
| 890 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 891 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 892 | if (PyObject_HasAttrString(handler, (char *) "startDocument")) { |
| 893 | result = |
| 894 | PyObject_CallMethod(handler, (char *) "startDocument", NULL); |
| 895 | if (PyErr_Occurred()) |
| 896 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 897 | Py_XDECREF(result); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | static void |
| 902 | pythonEndDocument(void *user_data) |
| 903 | { |
| 904 | PyObject *handler; |
| 905 | PyObject *result; |
| 906 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 907 | #ifdef DEBUG_SAX |
| 908 | printf("pythonEndDocument() called\n"); |
| 909 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 910 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 911 | if (PyObject_HasAttrString(handler, (char *) "endDocument")) { |
| 912 | result = |
| 913 | PyObject_CallMethod(handler, (char *) "endDocument", NULL); |
| 914 | if (PyErr_Occurred()) |
| 915 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 916 | Py_XDECREF(result); |
| 917 | } |
| 918 | /* |
| 919 | * The reference to the handler is released there |
| 920 | */ |
| 921 | Py_XDECREF(handler); |
| 922 | } |
| 923 | |
| 924 | static void |
| 925 | pythonEndElement(void *user_data, const xmlChar * name) |
| 926 | { |
| 927 | PyObject *handler; |
| 928 | PyObject *result; |
| 929 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 930 | #ifdef DEBUG_SAX |
| 931 | printf("pythonEndElement(%s) called\n", name); |
| 932 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 933 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 934 | if (PyObject_HasAttrString(handler, (char *) "endElement")) { |
| 935 | result = PyObject_CallMethod(handler, (char *) "endElement", |
| 936 | (char *) "s", name); |
| 937 | if (PyErr_Occurred()) |
| 938 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 939 | Py_XDECREF(result); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 940 | } else if (PyObject_HasAttrString(handler, (char *) "end")) { |
| 941 | result = PyObject_CallMethod(handler, (char *) "end", |
| 942 | (char *) "s", name); |
| 943 | if (PyErr_Occurred()) |
| 944 | PyErr_Print(); |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 945 | Py_XDECREF(result); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | static void |
| 950 | pythonReference(void *user_data, const xmlChar * name) |
| 951 | { |
| 952 | PyObject *handler; |
| 953 | PyObject *result; |
| 954 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 955 | #ifdef DEBUG_SAX |
| 956 | printf("pythonReference(%s) called\n", name); |
| 957 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 958 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 959 | if (PyObject_HasAttrString(handler, (char *) "reference")) { |
| 960 | result = PyObject_CallMethod(handler, (char *) "reference", |
| 961 | (char *) "s", name); |
| 962 | if (PyErr_Occurred()) |
| 963 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 964 | Py_XDECREF(result); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | static void |
| 969 | pythonCharacters(void *user_data, const xmlChar * ch, int len) |
| 970 | { |
| 971 | PyObject *handler; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 972 | PyObject *result = NULL; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 973 | int type = 0; |
| 974 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 975 | #ifdef DEBUG_SAX |
| 976 | printf("pythonCharacters(%s, %d) called\n", ch, len); |
| 977 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 978 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 979 | if (PyObject_HasAttrString(handler, (char *) "characters")) |
| 980 | type = 1; |
| 981 | else if (PyObject_HasAttrString(handler, (char *) "data")) |
| 982 | type = 2; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 983 | if (type != 0) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 984 | if (type == 1) |
| 985 | result = PyObject_CallMethod(handler, (char *) "characters", |
| 986 | (char *) "s#", ch, len); |
| 987 | else if (type == 2) |
| 988 | result = PyObject_CallMethod(handler, (char *) "data", |
| 989 | (char *) "s#", ch, len); |
| 990 | if (PyErr_Occurred()) |
| 991 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 992 | Py_XDECREF(result); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | static void |
| 997 | pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len) |
| 998 | { |
| 999 | PyObject *handler; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1000 | PyObject *result = NULL; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1001 | int type = 0; |
| 1002 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1003 | #ifdef DEBUG_SAX |
| 1004 | printf("pythonIgnorableWhitespace(%s, %d) called\n", ch, len); |
| 1005 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1006 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1007 | if (PyObject_HasAttrString(handler, (char *) "ignorableWhitespace")) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1008 | type = 1; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1009 | else if (PyObject_HasAttrString(handler, (char *) "data")) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1010 | type = 2; |
| 1011 | if (type != 0) { |
| 1012 | if (type == 1) |
| 1013 | result = |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1014 | PyObject_CallMethod(handler, |
| 1015 | (char *) "ignorableWhitespace", |
| 1016 | (char *) "s#", ch, len); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1017 | else if (type == 2) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1018 | result = |
| 1019 | PyObject_CallMethod(handler, (char *) "data", |
| 1020 | (char *) "s#", ch, len); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1021 | Py_XDECREF(result); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | static void |
| 1026 | pythonProcessingInstruction(void *user_data, |
| 1027 | const xmlChar * target, const xmlChar * data) |
| 1028 | { |
| 1029 | PyObject *handler; |
| 1030 | PyObject *result; |
| 1031 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1032 | #ifdef DEBUG_SAX |
| 1033 | printf("pythonProcessingInstruction(%s, %s) called\n", target, data); |
| 1034 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1035 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1036 | if (PyObject_HasAttrString(handler, (char *) "processingInstruction")) { |
| 1037 | result = PyObject_CallMethod(handler, (char *) |
| 1038 | "processingInstruction", |
| 1039 | (char *) "ss", target, data); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1040 | Py_XDECREF(result); |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | static void |
| 1045 | pythonComment(void *user_data, const xmlChar * value) |
| 1046 | { |
| 1047 | PyObject *handler; |
| 1048 | PyObject *result; |
| 1049 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1050 | #ifdef DEBUG_SAX |
| 1051 | printf("pythonComment(%s) called\n", value); |
| 1052 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1053 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1054 | if (PyObject_HasAttrString(handler, (char *) "comment")) { |
| 1055 | result = |
| 1056 | PyObject_CallMethod(handler, (char *) "comment", (char *) "s", |
| 1057 | value); |
| 1058 | if (PyErr_Occurred()) |
| 1059 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1060 | Py_XDECREF(result); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | static void |
| 1065 | pythonWarning(void *user_data, const char *msg, ...) |
| 1066 | { |
| 1067 | PyObject *handler; |
| 1068 | PyObject *result; |
| 1069 | va_list args; |
| 1070 | char buf[1024]; |
| 1071 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1072 | #ifdef DEBUG_SAX |
| 1073 | printf("pythonWarning(%s) called\n", msg); |
| 1074 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1075 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1076 | if (PyObject_HasAttrString(handler, (char *) "warning")) { |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1077 | va_start(args, msg); |
| 1078 | vsnprintf(buf, 1023, msg, args); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1079 | va_end(args); |
| 1080 | buf[1023] = 0; |
| 1081 | result = |
| 1082 | PyObject_CallMethod(handler, (char *) "warning", (char *) "s", |
| 1083 | buf); |
| 1084 | if (PyErr_Occurred()) |
| 1085 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1086 | Py_XDECREF(result); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | static void |
| 1091 | pythonError(void *user_data, const char *msg, ...) |
| 1092 | { |
| 1093 | PyObject *handler; |
| 1094 | PyObject *result; |
| 1095 | va_list args; |
| 1096 | char buf[1024]; |
| 1097 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1098 | #ifdef DEBUG_SAX |
| 1099 | printf("pythonError(%s) called\n", msg); |
| 1100 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1101 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1102 | if (PyObject_HasAttrString(handler, (char *) "error")) { |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1103 | va_start(args, msg); |
| 1104 | vsnprintf(buf, 1023, msg, args); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1105 | va_end(args); |
| 1106 | buf[1023] = 0; |
| 1107 | result = |
| 1108 | PyObject_CallMethod(handler, (char *) "error", (char *) "s", |
| 1109 | buf); |
| 1110 | if (PyErr_Occurred()) |
| 1111 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1112 | Py_XDECREF(result); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | pythonFatalError(void *user_data, const char *msg, ...) |
| 1118 | { |
| 1119 | PyObject *handler; |
| 1120 | PyObject *result; |
| 1121 | va_list args; |
| 1122 | char buf[1024]; |
| 1123 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1124 | #ifdef DEBUG_SAX |
| 1125 | printf("pythonFatalError(%s) called\n", msg); |
| 1126 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1127 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1128 | if (PyObject_HasAttrString(handler, (char *) "fatalError")) { |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1129 | va_start(args, msg); |
| 1130 | vsnprintf(buf, 1023, msg, args); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1131 | va_end(args); |
| 1132 | buf[1023] = 0; |
| 1133 | result = |
| 1134 | PyObject_CallMethod(handler, (char *) "fatalError", |
| 1135 | (char *) "s", buf); |
| 1136 | if (PyErr_Occurred()) |
| 1137 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1138 | Py_XDECREF(result); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | static void |
| 1143 | pythonCdataBlock(void *user_data, const xmlChar * ch, int len) |
| 1144 | { |
| 1145 | PyObject *handler; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1146 | PyObject *result = NULL; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1147 | int type = 0; |
| 1148 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1149 | #ifdef DEBUG_SAX |
| 1150 | printf("pythonCdataBlock(%s, %d) called\n", ch, len); |
| 1151 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1152 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1153 | if (PyObject_HasAttrString(handler, (char *) "cdataBlock")) |
| 1154 | type = 1; |
| 1155 | else if (PyObject_HasAttrString(handler, (char *) "cdata")) |
| 1156 | type = 2; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1157 | if (type != 0) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1158 | if (type == 1) |
| 1159 | result = |
| 1160 | PyObject_CallMethod(handler, (char *) "cdataBlock", |
| 1161 | (char *) "s#", ch, len); |
| 1162 | else if (type == 2) |
| 1163 | result = |
| 1164 | PyObject_CallMethod(handler, (char *) "cdata", |
| 1165 | (char *) "s#", ch, len); |
| 1166 | if (PyErr_Occurred()) |
| 1167 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1168 | Py_XDECREF(result); |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | static void |
| 1173 | pythonExternalSubset(void *user_data, |
| 1174 | const xmlChar * name, |
| 1175 | const xmlChar * externalID, const xmlChar * systemID) |
| 1176 | { |
| 1177 | PyObject *handler; |
| 1178 | PyObject *result; |
| 1179 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1180 | #ifdef DEBUG_SAX |
| 1181 | printf("pythonExternalSubset(%s, %s, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1182 | name, externalID, systemID); |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1183 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1184 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1185 | if (PyObject_HasAttrString(handler, (char *) "externalSubset")) { |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1186 | result = |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1187 | PyObject_CallMethod(handler, (char *) "externalSubset", |
| 1188 | (char *) "sss", name, externalID, |
| 1189 | systemID); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1190 | Py_XDECREF(result); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | static void |
| 1195 | pythonEntityDecl(void *user_data, |
| 1196 | const xmlChar * name, |
| 1197 | int type, |
| 1198 | const xmlChar * publicId, |
| 1199 | const xmlChar * systemId, xmlChar * content) |
| 1200 | { |
| 1201 | PyObject *handler; |
| 1202 | PyObject *result; |
| 1203 | |
| 1204 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1205 | if (PyObject_HasAttrString(handler, (char *) "entityDecl")) { |
| 1206 | result = PyObject_CallMethod(handler, (char *) "entityDecl", |
| 1207 | (char *) "sisss", name, type, |
| 1208 | publicId, systemId, content); |
| 1209 | if (PyErr_Occurred()) |
| 1210 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1211 | Py_XDECREF(result); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | static void |
| 1218 | |
| 1219 | pythonNotationDecl(void *user_data, |
| 1220 | const xmlChar * name, |
| 1221 | const xmlChar * publicId, const xmlChar * systemId) |
| 1222 | { |
| 1223 | PyObject *handler; |
| 1224 | PyObject *result; |
| 1225 | |
| 1226 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1227 | if (PyObject_HasAttrString(handler, (char *) "notationDecl")) { |
| 1228 | result = PyObject_CallMethod(handler, (char *) "notationDecl", |
| 1229 | (char *) "sss", name, publicId, |
| 1230 | systemId); |
| 1231 | if (PyErr_Occurred()) |
| 1232 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1233 | Py_XDECREF(result); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | static void |
| 1238 | pythonAttributeDecl(void *user_data, |
| 1239 | const xmlChar * elem, |
| 1240 | const xmlChar * name, |
| 1241 | int type, |
| 1242 | int def, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1243 | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1244 | { |
| 1245 | PyObject *handler; |
| 1246 | PyObject *nameList; |
| 1247 | PyObject *newName; |
| 1248 | xmlEnumerationPtr node; |
| 1249 | PyObject *result; |
| 1250 | int count; |
| 1251 | |
| 1252 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1253 | if (PyObject_HasAttrString(handler, (char *) "attributeDecl")) { |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1254 | count = 0; |
| 1255 | for (node = tree; node != NULL; node = node->next) { |
| 1256 | count++; |
| 1257 | } |
| 1258 | nameList = PyList_New(count); |
| 1259 | count = 0; |
| 1260 | for (node = tree; node != NULL; node = node->next) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1261 | newName = PyString_FromString((char *) node->name); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1262 | PyList_SetItem(nameList, count, newName); |
Daniel Veillard | a3d2305 | 2007-01-09 21:24:34 +0000 | [diff] [blame] | 1263 | Py_DECREF(newName); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1264 | count++; |
| 1265 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1266 | result = PyObject_CallMethod(handler, (char *) "attributeDecl", |
| 1267 | (char *) "ssiisO", elem, name, type, |
| 1268 | def, defaultValue, nameList); |
| 1269 | if (PyErr_Occurred()) |
| 1270 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1271 | Py_XDECREF(nameList); |
| 1272 | Py_XDECREF(result); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | static void |
| 1277 | pythonElementDecl(void *user_data, |
| 1278 | const xmlChar * name, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1279 | int type, ATTRIBUTE_UNUSED xmlElementContentPtr content) |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1280 | { |
| 1281 | PyObject *handler; |
| 1282 | PyObject *obj; |
| 1283 | PyObject *result; |
| 1284 | |
| 1285 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1286 | if (PyObject_HasAttrString(handler, (char *) "elementDecl")) { |
| 1287 | /* TODO: wrap in an elementContent object */ |
| 1288 | printf |
| 1289 | ("pythonElementDecl: xmlElementContentPtr wrapper missing !\n"); |
| 1290 | obj = Py_None; |
| 1291 | /* Py_XINCREF(Py_None); isn't the reference just borrowed ??? */ |
| 1292 | result = PyObject_CallMethod(handler, (char *) "elementDecl", |
| 1293 | (char *) "siO", name, type, obj); |
| 1294 | if (PyErr_Occurred()) |
| 1295 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1296 | Py_XDECREF(result); |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | static void |
| 1301 | pythonUnparsedEntityDecl(void *user_data, |
| 1302 | const xmlChar * name, |
| 1303 | const xmlChar * publicId, |
| 1304 | const xmlChar * systemId, |
| 1305 | const xmlChar * notationName) |
| 1306 | { |
| 1307 | PyObject *handler; |
| 1308 | PyObject *result; |
| 1309 | |
| 1310 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1311 | if (PyObject_HasAttrString(handler, (char *) "unparsedEntityDecl")) { |
| 1312 | result = |
| 1313 | PyObject_CallMethod(handler, (char *) "unparsedEntityDecl", |
| 1314 | (char *) "ssss", name, publicId, systemId, |
| 1315 | notationName); |
| 1316 | if (PyErr_Occurred()) |
| 1317 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1318 | Py_XDECREF(result); |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | static void |
| 1323 | pythonInternalSubset(void *user_data, const xmlChar * name, |
| 1324 | const xmlChar * ExternalID, const xmlChar * SystemID) |
| 1325 | { |
| 1326 | PyObject *handler; |
| 1327 | PyObject *result; |
| 1328 | |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1329 | #ifdef DEBUG_SAX |
| 1330 | printf("pythonInternalSubset(%s, %s, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1331 | name, ExternalID, SystemID); |
Daniel Veillard | 797a565 | 2002-02-12 13:46:21 +0000 | [diff] [blame] | 1332 | #endif |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1333 | handler = (PyObject *) user_data; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1334 | if (PyObject_HasAttrString(handler, (char *) "internalSubset")) { |
| 1335 | result = PyObject_CallMethod(handler, (char *) "internalSubset", |
| 1336 | (char *) "sss", name, ExternalID, |
| 1337 | SystemID); |
| 1338 | if (PyErr_Occurred()) |
| 1339 | PyErr_Print(); |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1340 | Py_XDECREF(result); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | static xmlSAXHandler pythonSaxHandler = { |
| 1345 | pythonInternalSubset, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1346 | NULL, /* TODO pythonIsStandalone, */ |
| 1347 | NULL, /* TODO pythonHasInternalSubset, */ |
| 1348 | NULL, /* TODO pythonHasExternalSubset, */ |
| 1349 | NULL, /* TODO pythonResolveEntity, */ |
| 1350 | NULL, /* TODO pythonGetEntity, */ |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1351 | pythonEntityDecl, |
| 1352 | pythonNotationDecl, |
| 1353 | pythonAttributeDecl, |
| 1354 | pythonElementDecl, |
| 1355 | pythonUnparsedEntityDecl, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1356 | NULL, /* OBSOLETED pythonSetDocumentLocator, */ |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1357 | pythonStartDocument, |
| 1358 | pythonEndDocument, |
| 1359 | pythonStartElement, |
| 1360 | pythonEndElement, |
| 1361 | pythonReference, |
| 1362 | pythonCharacters, |
| 1363 | pythonIgnorableWhitespace, |
| 1364 | pythonProcessingInstruction, |
| 1365 | pythonComment, |
| 1366 | pythonWarning, |
| 1367 | pythonError, |
| 1368 | pythonFatalError, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1369 | NULL, /* TODO pythonGetParameterEntity, */ |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1370 | pythonCdataBlock, |
| 1371 | pythonExternalSubset, |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1372 | 1, |
| 1373 | NULL, /* TODO mograte to SAX2 */ |
| 1374 | NULL, |
William M. Brack | 871611b | 2003-10-18 04:53:14 +0000 | [diff] [blame] | 1375 | NULL, |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1376 | NULL |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1377 | }; |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1378 | |
| 1379 | /************************************************************************ |
| 1380 | * * |
| 1381 | * Handling of specific parser context * |
| 1382 | * * |
| 1383 | ************************************************************************/ |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 1384 | |
| 1385 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1386 | libxml_xmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self, |
| 1387 | PyObject * args) |
| 1388 | { |
| 1389 | const char *chunk; |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1390 | int size; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1391 | const char *URI; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1392 | PyObject *pyobj_SAX = NULL; |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1393 | xmlSAXHandlerPtr SAX = NULL; |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1394 | xmlParserCtxtPtr ret; |
| 1395 | PyObject *pyret; |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 1396 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1397 | if (!PyArg_ParseTuple |
| 1398 | (args, (char *) "Oziz:xmlCreatePushParser", &pyobj_SAX, &chunk, |
| 1399 | &size, &URI)) |
| 1400 | return (NULL); |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1401 | |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1402 | #ifdef DEBUG |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1403 | printf("libxml_xmlCreatePushParser(%p, %s, %d, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1404 | pyobj_SAX, chunk, size, URI); |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 1405 | #endif |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1406 | if (pyobj_SAX != Py_None) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1407 | SAX = &pythonSaxHandler; |
| 1408 | Py_INCREF(pyobj_SAX); |
| 1409 | /* The reference is released in pythonEndDocument() */ |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 1410 | } |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1411 | ret = xmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI); |
Daniel Veillard | 3ce5257 | 2002-02-03 15:08:05 +0000 | [diff] [blame] | 1412 | pyret = libxml_xmlParserCtxtPtrWrap(ret); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1413 | return (pyret); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 1414 | } |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1415 | |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1416 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1417 | libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self, |
| 1418 | PyObject * args) |
| 1419 | { |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 1420 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1421 | const char *chunk; |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1422 | int size; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1423 | const char *URI; |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1424 | PyObject *pyobj_SAX = NULL; |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1425 | xmlSAXHandlerPtr SAX = NULL; |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1426 | xmlParserCtxtPtr ret; |
| 1427 | PyObject *pyret; |
| 1428 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1429 | if (!PyArg_ParseTuple |
| 1430 | (args, (char *) "Oziz:htmlCreatePushParser", &pyobj_SAX, &chunk, |
| 1431 | &size, &URI)) |
| 1432 | return (NULL); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1433 | |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1434 | #ifdef DEBUG |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1435 | printf("libxml_htmlCreatePushParser(%p, %s, %d, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1436 | pyobj_SAX, chunk, size, URI); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1437 | #endif |
| 1438 | if (pyobj_SAX != Py_None) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1439 | SAX = &pythonSaxHandler; |
| 1440 | Py_INCREF(pyobj_SAX); |
| 1441 | /* The reference is released in pythonEndDocument() */ |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1442 | } |
Daniel Veillard | 33caa0b | 2002-02-04 14:07:26 +0000 | [diff] [blame] | 1443 | ret = htmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1444 | XML_CHAR_ENCODING_NONE); |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1445 | pyret = libxml_xmlParserCtxtPtrWrap(ret); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1446 | return (pyret); |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 1447 | #else |
| 1448 | Py_INCREF(Py_None); |
| 1449 | return (Py_None); |
| 1450 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 4e1b26c | 2002-02-03 20:13:06 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1453 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1454 | libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 1455 | { |
Akira TAGOH | 961b535 | 2012-07-03 14:13:59 +0900 | [diff] [blame] | 1456 | #ifdef LIBXML_SAX1_ENABLED |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1457 | int recover; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1458 | const char *URI; |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1459 | PyObject *pyobj_SAX = NULL; |
| 1460 | xmlSAXHandlerPtr SAX = NULL; |
| 1461 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1462 | if (!PyArg_ParseTuple(args, (char *) "Osi:xmlSAXParseFile", &pyobj_SAX, |
| 1463 | &URI, &recover)) |
| 1464 | return (NULL); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1465 | |
| 1466 | #ifdef DEBUG |
| 1467 | printf("libxml_xmlSAXParseFile(%p, %s, %d) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1468 | pyobj_SAX, URI, recover); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1469 | #endif |
| 1470 | if (pyobj_SAX == Py_None) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1471 | Py_INCREF(Py_None); |
| 1472 | return (Py_None); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1473 | } |
| 1474 | SAX = &pythonSaxHandler; |
| 1475 | Py_INCREF(pyobj_SAX); |
| 1476 | /* The reference is released in pythonEndDocument() */ |
Daniel Veillard | f2531af | 2005-03-31 11:06:29 +0000 | [diff] [blame] | 1477 | xmlSAXUserParseFile(SAX, pyobj_SAX, URI); |
Akira TAGOH | 961b535 | 2012-07-03 14:13:59 +0900 | [diff] [blame] | 1478 | #endif /* LIBXML_SAX1_ENABLED */ |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1479 | Py_INCREF(Py_None); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1480 | return (Py_None); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1484 | libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 1485 | { |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 1486 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1487 | const char *URI; |
| 1488 | const char *encoding; |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1489 | PyObject *pyobj_SAX = NULL; |
| 1490 | xmlSAXHandlerPtr SAX = NULL; |
| 1491 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1492 | if (!PyArg_ParseTuple |
| 1493 | (args, (char *) "Osz:htmlSAXParseFile", &pyobj_SAX, &URI, |
| 1494 | &encoding)) |
| 1495 | return (NULL); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1496 | |
| 1497 | #ifdef DEBUG |
| 1498 | printf("libxml_htmlSAXParseFile(%p, %s, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1499 | pyobj_SAX, URI, encoding); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1500 | #endif |
| 1501 | if (pyobj_SAX == Py_None) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1502 | Py_INCREF(Py_None); |
| 1503 | return (Py_None); |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1504 | } |
| 1505 | SAX = &pythonSaxHandler; |
| 1506 | Py_INCREF(pyobj_SAX); |
| 1507 | /* The reference is released in pythonEndDocument() */ |
| 1508 | htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX); |
| 1509 | Py_INCREF(Py_None); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1510 | return (Py_None); |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 1511 | #else |
| 1512 | Py_INCREF(Py_None); |
| 1513 | return (Py_None); |
| 1514 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 8d24cc1 | 2002-03-05 15:41:29 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1517 | /************************************************************************ |
| 1518 | * * |
| 1519 | * Error message callback * |
| 1520 | * * |
| 1521 | ************************************************************************/ |
| 1522 | |
| 1523 | static PyObject *libxml_xmlPythonErrorFuncHandler = NULL; |
| 1524 | static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL; |
| 1525 | |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1526 | /* helper to build a xmlMalloc'ed string from a format and va_list */ |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1527 | /* |
| 1528 | * disabled the loop, the repeated call to vsnprintf without reset of ap |
| 1529 | * in case the initial buffer was too small segfaulted on x86_64 |
| 1530 | * we now directly vsnprintf on a large buffer. |
| 1531 | */ |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1532 | static char * |
| 1533 | libxml_buildMessage(const char *msg, va_list ap) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1534 | { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1535 | int chars; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1536 | char *str; |
| 1537 | |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1538 | str = (char *) xmlMalloc(1000); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1539 | if (str == NULL) |
| 1540 | return NULL; |
| 1541 | |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1542 | chars = vsnprintf(str, 999, msg, ap); |
| 1543 | if (chars >= 998) |
| 1544 | str[999] = 0; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1545 | |
| 1546 | return str; |
| 1547 | } |
| 1548 | |
| 1549 | static void |
| 1550 | libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, |
| 1551 | ...) |
| 1552 | { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1553 | va_list ap; |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1554 | PyObject *list; |
| 1555 | PyObject *message; |
| 1556 | PyObject *result; |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1557 | char str[1000]; |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1558 | |
| 1559 | #ifdef DEBUG_ERROR |
| 1560 | printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg); |
| 1561 | #endif |
| 1562 | |
| 1563 | |
| 1564 | if (libxml_xmlPythonErrorFuncHandler == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1565 | va_start(ap, msg); |
Daniel Veillard | 007d51e | 2003-09-17 20:07:28 +0000 | [diff] [blame] | 1566 | vfprintf(stderr, msg, ap); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1567 | va_end(ap); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1568 | } else { |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1569 | va_start(ap, msg); |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1570 | if (vsnprintf(str, 999, msg, ap) >= 998) |
| 1571 | str[999] = 0; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1572 | va_end(ap); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1573 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1574 | list = PyTuple_New(2); |
| 1575 | PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt); |
| 1576 | Py_XINCREF(libxml_xmlPythonErrorFuncCtxt); |
Daniel Veillard | ad9fb7c | 2004-10-22 11:05:37 +0000 | [diff] [blame] | 1577 | message = libxml_charPtrConstWrap(str); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1578 | PyTuple_SetItem(list, 1, message); |
| 1579 | result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list); |
| 1580 | Py_XDECREF(list); |
| 1581 | Py_XDECREF(result); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | static void |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1586 | libxml_xmlErrorInitialize(void) |
| 1587 | { |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1588 | #ifdef DEBUG_ERROR |
| 1589 | printf("libxml_xmlErrorInitialize() called\n"); |
| 1590 | #endif |
| 1591 | xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler); |
Daniel Veillard | 781ac8b | 2003-05-15 22:11:36 +0000 | [diff] [blame] | 1592 | xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 1595 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1596 | libxml_xmlRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self, |
| 1597 | PyObject * args) |
| 1598 | { |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1599 | PyObject *py_retval; |
| 1600 | PyObject *pyobj_f; |
| 1601 | PyObject *pyobj_ctx; |
| 1602 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1603 | if (!PyArg_ParseTuple |
| 1604 | (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f, |
| 1605 | &pyobj_ctx)) |
| 1606 | return (NULL); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1607 | |
| 1608 | #ifdef DEBUG_ERROR |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 1609 | printf("libxml_xmlRegisterErrorHandler(%p, %p) called\n", pyobj_ctx, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1610 | pyobj_f); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1611 | #endif |
| 1612 | |
| 1613 | if (libxml_xmlPythonErrorFuncHandler != NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1614 | Py_XDECREF(libxml_xmlPythonErrorFuncHandler); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1615 | } |
| 1616 | if (libxml_xmlPythonErrorFuncCtxt != NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1617 | Py_XDECREF(libxml_xmlPythonErrorFuncCtxt); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | Py_XINCREF(pyobj_ctx); |
| 1621 | Py_XINCREF(pyobj_f); |
| 1622 | |
| 1623 | /* TODO: check f is a function ! */ |
| 1624 | libxml_xmlPythonErrorFuncHandler = pyobj_f; |
| 1625 | libxml_xmlPythonErrorFuncCtxt = pyobj_ctx; |
| 1626 | |
| 1627 | py_retval = libxml_intWrap(1); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1628 | return (py_retval); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 1629 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 1630 | |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1631 | |
| 1632 | /************************************************************************ |
| 1633 | * * |
| 1634 | * Per parserCtxt error handler * |
| 1635 | * * |
| 1636 | ************************************************************************/ |
| 1637 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1638 | typedef struct |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1639 | { |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1640 | PyObject *f; |
| 1641 | PyObject *arg; |
| 1642 | } xmlParserCtxtPyCtxt; |
| 1643 | typedef xmlParserCtxtPyCtxt *xmlParserCtxtPyCtxtPtr; |
| 1644 | |
| 1645 | static void |
| 1646 | libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str) |
| 1647 | { |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1648 | PyObject *list; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1649 | PyObject *result; |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1650 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1651 | xmlParserCtxtPyCtxtPtr pyCtxt; |
| 1652 | |
| 1653 | #ifdef DEBUG_ERROR |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 1654 | printf("libxml_xmlParserCtxtGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1655 | #endif |
| 1656 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1657 | ctxt = (xmlParserCtxtPtr)ctx; |
| 1658 | pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1659 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1660 | list = PyTuple_New(4); |
| 1661 | PyTuple_SetItem(list, 0, pyCtxt->arg); |
| 1662 | Py_XINCREF(pyCtxt->arg); |
| 1663 | PyTuple_SetItem(list, 1, libxml_charPtrWrap(str)); |
| 1664 | PyTuple_SetItem(list, 2, libxml_intWrap(severity)); |
| 1665 | PyTuple_SetItem(list, 3, Py_None); |
| 1666 | Py_INCREF(Py_None); |
| 1667 | result = PyEval_CallObject(pyCtxt->f, list); |
| 1668 | if (result == NULL) |
| 1669 | { |
| 1670 | /* TODO: manage for the exception to be propagated... */ |
| 1671 | PyErr_Print(); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1672 | } |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1673 | Py_XDECREF(list); |
| 1674 | Py_XDECREF(result); |
| 1675 | } |
| 1676 | |
| 1677 | static void |
| 1678 | libxml_xmlParserCtxtErrorFuncHandler(void *ctx, const char *msg, ...) |
| 1679 | { |
| 1680 | va_list ap; |
| 1681 | |
| 1682 | va_start(ap, msg); |
| 1683 | libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_ERROR,libxml_buildMessage(msg,ap)); |
| 1684 | va_end(ap); |
| 1685 | } |
| 1686 | |
| 1687 | static void |
| 1688 | libxml_xmlParserCtxtWarningFuncHandler(void *ctx, const char *msg, ...) |
| 1689 | { |
| 1690 | va_list ap; |
| 1691 | |
| 1692 | va_start(ap, msg); |
| 1693 | libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_WARNING,libxml_buildMessage(msg,ap)); |
| 1694 | va_end(ap); |
| 1695 | } |
| 1696 | |
| 1697 | static void |
| 1698 | libxml_xmlParserCtxtValidityErrorFuncHandler(void *ctx, const char *msg, ...) |
| 1699 | { |
| 1700 | va_list ap; |
| 1701 | |
| 1702 | va_start(ap, msg); |
| 1703 | libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap)); |
| 1704 | va_end(ap); |
| 1705 | } |
| 1706 | |
| 1707 | static void |
| 1708 | libxml_xmlParserCtxtValidityWarningFuncHandler(void *ctx, const char *msg, ...) |
| 1709 | { |
| 1710 | va_list ap; |
| 1711 | |
| 1712 | va_start(ap, msg); |
| 1713 | libxml_xmlParserCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap)); |
| 1714 | va_end(ap); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 1717 | static PyObject * |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1718 | libxml_xmlParserCtxtSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1719 | { |
| 1720 | PyObject *py_retval; |
| 1721 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1722 | xmlParserCtxtPyCtxtPtr pyCtxt; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1723 | PyObject *pyobj_ctxt; |
| 1724 | PyObject *pyobj_f; |
| 1725 | PyObject *pyobj_arg; |
| 1726 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1727 | if (!PyArg_ParseTuple(args, (char *)"OOO:xmlParserCtxtSetErrorHandler", |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1728 | &pyobj_ctxt, &pyobj_f, &pyobj_arg)) |
| 1729 | return(NULL); |
| 1730 | ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); |
| 1731 | if (ctxt->_private == NULL) { |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1732 | pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt)); |
| 1733 | if (pyCtxt == NULL) { |
| 1734 | py_retval = libxml_intWrap(-1); |
| 1735 | return(py_retval); |
| 1736 | } |
| 1737 | memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt)); |
| 1738 | ctxt->_private = pyCtxt; |
| 1739 | } |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1740 | else { |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1741 | pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private; |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1742 | } |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1743 | /* TODO: check f is a function ! */ |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1744 | Py_XDECREF(pyCtxt->f); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1745 | Py_XINCREF(pyobj_f); |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1746 | pyCtxt->f = pyobj_f; |
| 1747 | Py_XDECREF(pyCtxt->arg); |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1748 | Py_XINCREF(pyobj_arg); |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1749 | pyCtxt->arg = pyobj_arg; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1750 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1751 | if (pyobj_f != Py_None) { |
| 1752 | ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler; |
| 1753 | ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler; |
| 1754 | ctxt->vctxt.error = libxml_xmlParserCtxtValidityErrorFuncHandler; |
| 1755 | ctxt->vctxt.warning = libxml_xmlParserCtxtValidityWarningFuncHandler; |
| 1756 | } |
| 1757 | else { |
| 1758 | ctxt->sax->error = xmlParserError; |
| 1759 | ctxt->vctxt.error = xmlParserValidityError; |
| 1760 | ctxt->sax->warning = xmlParserWarning; |
| 1761 | ctxt->vctxt.warning = xmlParserValidityWarning; |
| 1762 | } |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1763 | |
| 1764 | py_retval = libxml_intWrap(1); |
| 1765 | return(py_retval); |
| 1766 | } |
| 1767 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 1768 | static PyObject * |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1769 | libxml_xmlParserCtxtGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1770 | { |
| 1771 | PyObject *py_retval; |
| 1772 | xmlParserCtxtPtr ctxt; |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1773 | xmlParserCtxtPyCtxtPtr pyCtxt; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1774 | PyObject *pyobj_ctxt; |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1775 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1776 | if (!PyArg_ParseTuple(args, (char *)"O:xmlParserCtxtGetErrorHandler", |
| 1777 | &pyobj_ctxt)) |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1778 | return(NULL); |
| 1779 | ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1780 | py_retval = PyTuple_New(2); |
| 1781 | if (ctxt->_private != NULL) { |
| 1782 | pyCtxt = (xmlParserCtxtPyCtxtPtr)ctxt->_private; |
| 1783 | |
| 1784 | PyTuple_SetItem(py_retval, 0, pyCtxt->f); |
| 1785 | Py_XINCREF(pyCtxt->f); |
| 1786 | PyTuple_SetItem(py_retval, 1, pyCtxt->arg); |
| 1787 | Py_XINCREF(pyCtxt->arg); |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1788 | } |
| 1789 | else { |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1790 | /* no python error handler registered */ |
| 1791 | PyTuple_SetItem(py_retval, 0, Py_None); |
| 1792 | Py_XINCREF(Py_None); |
| 1793 | PyTuple_SetItem(py_retval, 1, Py_None); |
| 1794 | Py_XINCREF(Py_None); |
Daniel Veillard | e4a07e7 | 2003-01-14 14:40:25 +0000 | [diff] [blame] | 1795 | } |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 1796 | return(py_retval); |
| 1797 | } |
| 1798 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 1799 | static PyObject * |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 1800 | libxml_xmlFreeParserCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 1801 | xmlParserCtxtPtr ctxt; |
| 1802 | PyObject *pyobj_ctxt; |
| 1803 | xmlParserCtxtPyCtxtPtr pyCtxt; |
| 1804 | |
| 1805 | if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeParserCtxt", &pyobj_ctxt)) |
| 1806 | return(NULL); |
| 1807 | ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); |
| 1808 | |
| 1809 | if (ctxt != NULL) { |
| 1810 | pyCtxt = (xmlParserCtxtPyCtxtPtr)((xmlParserCtxtPtr)ctxt)->_private; |
| 1811 | if (pyCtxt) { |
| 1812 | Py_XDECREF(pyCtxt->f); |
| 1813 | Py_XDECREF(pyCtxt->arg); |
| 1814 | xmlFree(pyCtxt); |
| 1815 | } |
| 1816 | xmlFreeParserCtxt(ctxt); |
| 1817 | } |
| 1818 | |
| 1819 | Py_INCREF(Py_None); |
| 1820 | return(Py_None); |
| 1821 | } |
| 1822 | |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 1823 | /*** |
| 1824 | * xmlValidCtxt stuff |
| 1825 | */ |
| 1826 | |
| 1827 | typedef struct |
| 1828 | { |
| 1829 | PyObject *warn; |
| 1830 | PyObject *error; |
| 1831 | PyObject *arg; |
| 1832 | } xmlValidCtxtPyCtxt; |
| 1833 | typedef xmlValidCtxtPyCtxt *xmlValidCtxtPyCtxtPtr; |
| 1834 | |
| 1835 | static void |
Stefan Kost | c31e06c | 2011-05-09 12:52:28 +0300 | [diff] [blame] | 1836 | libxml_xmlValidCtxtGenericErrorFuncHandler(void *ctx, ATTRIBUTE_UNUSED int severity, char *str) |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 1837 | { |
| 1838 | PyObject *list; |
| 1839 | PyObject *result; |
| 1840 | xmlValidCtxtPyCtxtPtr pyCtxt; |
| 1841 | |
| 1842 | #ifdef DEBUG_ERROR |
| 1843 | printf("libxml_xmlValidCtxtGenericErrorFuncHandler(%p, %d, %s, ...) called\n", ctx, severity, str); |
| 1844 | #endif |
| 1845 | |
| 1846 | pyCtxt = (xmlValidCtxtPyCtxtPtr)ctx; |
| 1847 | |
| 1848 | list = PyTuple_New(2); |
| 1849 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 1850 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 1851 | Py_XINCREF(pyCtxt->arg); |
| 1852 | result = PyEval_CallObject(pyCtxt->error, list); |
| 1853 | if (result == NULL) |
| 1854 | { |
| 1855 | /* TODO: manage for the exception to be propagated... */ |
| 1856 | PyErr_Print(); |
| 1857 | } |
| 1858 | Py_XDECREF(list); |
| 1859 | Py_XDECREF(result); |
| 1860 | } |
| 1861 | |
| 1862 | static void |
Stefan Kost | c31e06c | 2011-05-09 12:52:28 +0300 | [diff] [blame] | 1863 | libxml_xmlValidCtxtGenericWarningFuncHandler(void *ctx, ATTRIBUTE_UNUSED int severity, char *str) |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 1864 | { |
| 1865 | PyObject *list; |
| 1866 | PyObject *result; |
| 1867 | xmlValidCtxtPyCtxtPtr pyCtxt; |
| 1868 | |
| 1869 | #ifdef DEBUG_ERROR |
| 1870 | printf("libxml_xmlValidCtxtGenericWarningFuncHandler(%p, %d, %s, ...) called\n", ctx, severity, str); |
| 1871 | #endif |
| 1872 | |
| 1873 | pyCtxt = (xmlValidCtxtPyCtxtPtr)ctx; |
| 1874 | |
| 1875 | list = PyTuple_New(2); |
| 1876 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 1877 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 1878 | Py_XINCREF(pyCtxt->arg); |
| 1879 | result = PyEval_CallObject(pyCtxt->warn, list); |
| 1880 | if (result == NULL) |
| 1881 | { |
| 1882 | /* TODO: manage for the exception to be propagated... */ |
| 1883 | PyErr_Print(); |
| 1884 | } |
| 1885 | Py_XDECREF(list); |
| 1886 | Py_XDECREF(result); |
| 1887 | } |
| 1888 | |
| 1889 | static void |
| 1890 | libxml_xmlValidCtxtErrorFuncHandler(void *ctx, const char *msg, ...) |
| 1891 | { |
| 1892 | va_list ap; |
| 1893 | |
| 1894 | va_start(ap, msg); |
| 1895 | libxml_xmlValidCtxtGenericErrorFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_ERROR,libxml_buildMessage(msg,ap)); |
| 1896 | va_end(ap); |
| 1897 | } |
| 1898 | |
| 1899 | static void |
| 1900 | libxml_xmlValidCtxtWarningFuncHandler(void *ctx, const char *msg, ...) |
| 1901 | { |
| 1902 | va_list ap; |
| 1903 | |
| 1904 | va_start(ap, msg); |
| 1905 | libxml_xmlValidCtxtGenericWarningFuncHandler(ctx,XML_PARSER_SEVERITY_VALIDITY_WARNING,libxml_buildMessage(msg,ap)); |
| 1906 | va_end(ap); |
| 1907 | } |
| 1908 | |
| 1909 | static PyObject * |
| 1910 | libxml_xmlSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 1911 | { |
| 1912 | PyObject *py_retval; |
| 1913 | PyObject *pyobj_error; |
| 1914 | PyObject *pyobj_warn; |
| 1915 | PyObject *pyobj_ctx; |
| 1916 | PyObject *pyobj_arg = Py_None; |
| 1917 | xmlValidCtxtPtr ctxt; |
| 1918 | xmlValidCtxtPyCtxtPtr pyCtxt; |
| 1919 | |
| 1920 | if (!PyArg_ParseTuple |
| 1921 | (args, (char *) "OOO|O:xmlSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg)) |
| 1922 | return (NULL); |
| 1923 | |
| 1924 | #ifdef DEBUG_ERROR |
| 1925 | printf("libxml_xmlSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn); |
| 1926 | #endif |
| 1927 | |
| 1928 | ctxt = PyValidCtxt_Get(pyobj_ctx); |
| 1929 | pyCtxt = xmlMalloc(sizeof(xmlValidCtxtPyCtxt)); |
| 1930 | if (pyCtxt == NULL) { |
| 1931 | py_retval = libxml_intWrap(-1); |
| 1932 | return(py_retval); |
| 1933 | } |
| 1934 | memset(pyCtxt, 0, sizeof(xmlValidCtxtPyCtxt)); |
| 1935 | |
| 1936 | |
| 1937 | /* TODO: check warn and error is a function ! */ |
| 1938 | Py_XDECREF(pyCtxt->error); |
| 1939 | Py_XINCREF(pyobj_error); |
| 1940 | pyCtxt->error = pyobj_error; |
| 1941 | |
| 1942 | Py_XDECREF(pyCtxt->warn); |
| 1943 | Py_XINCREF(pyobj_warn); |
| 1944 | pyCtxt->warn = pyobj_warn; |
| 1945 | |
| 1946 | Py_XDECREF(pyCtxt->arg); |
| 1947 | Py_XINCREF(pyobj_arg); |
| 1948 | pyCtxt->arg = pyobj_arg; |
| 1949 | |
| 1950 | ctxt->error = libxml_xmlValidCtxtErrorFuncHandler; |
| 1951 | ctxt->warning = libxml_xmlValidCtxtWarningFuncHandler; |
| 1952 | ctxt->userData = pyCtxt; |
| 1953 | |
| 1954 | py_retval = libxml_intWrap(1); |
| 1955 | return (py_retval); |
| 1956 | } |
| 1957 | |
Daniel Veillard | 25c90c5 | 2005-03-02 10:47:41 +0000 | [diff] [blame] | 1958 | |
Daniel Veillard | bb8502c | 2005-03-30 07:40:35 +0000 | [diff] [blame] | 1959 | static PyObject * |
Daniel Veillard | 25c90c5 | 2005-03-02 10:47:41 +0000 | [diff] [blame] | 1960 | libxml_xmlFreeValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 1961 | xmlValidCtxtPtr cur; |
| 1962 | xmlValidCtxtPyCtxtPtr pyCtxt; |
| 1963 | PyObject *pyobj_cur; |
| 1964 | |
| 1965 | if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeValidCtxt", &pyobj_cur)) |
| 1966 | return(NULL); |
| 1967 | cur = (xmlValidCtxtPtr) PyValidCtxt_Get(pyobj_cur); |
| 1968 | |
| 1969 | pyCtxt = (xmlValidCtxtPyCtxtPtr)(cur->userData); |
| 1970 | if (pyCtxt != NULL) |
| 1971 | { |
| 1972 | Py_XDECREF(pyCtxt->error); |
| 1973 | Py_XDECREF(pyCtxt->warn); |
| 1974 | Py_XDECREF(pyCtxt->arg); |
| 1975 | xmlFree(pyCtxt); |
| 1976 | } |
| 1977 | |
| 1978 | xmlFreeValidCtxt(cur); |
| 1979 | Py_INCREF(Py_None); |
| 1980 | return(Py_None); |
| 1981 | } |
| 1982 | |
Daniel Veillard | 438ebbd | 2008-05-12 12:58:46 +0000 | [diff] [blame] | 1983 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 1984 | /************************************************************************ |
| 1985 | * * |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 1986 | * Per xmlTextReader error handler * |
| 1987 | * * |
| 1988 | ************************************************************************/ |
| 1989 | |
| 1990 | typedef struct |
| 1991 | { |
| 1992 | PyObject *f; |
| 1993 | PyObject *arg; |
| 1994 | } xmlTextReaderPyCtxt; |
| 1995 | typedef xmlTextReaderPyCtxt *xmlTextReaderPyCtxtPtr; |
| 1996 | |
| 1997 | static void |
| 1998 | libxml_xmlTextReaderErrorCallback(void *arg, |
| 1999 | const char *msg, |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 2000 | int severity, |
| 2001 | xmlTextReaderLocatorPtr locator) |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2002 | { |
| 2003 | xmlTextReaderPyCtxt *pyCtxt = (xmlTextReaderPyCtxt *)arg; |
| 2004 | PyObject *list; |
| 2005 | PyObject *result; |
| 2006 | |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 2007 | list = PyTuple_New(4); |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2008 | PyTuple_SetItem(list, 0, pyCtxt->arg); |
| 2009 | Py_XINCREF(pyCtxt->arg); |
| 2010 | PyTuple_SetItem(list, 1, libxml_charPtrConstWrap(msg)); |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 2011 | PyTuple_SetItem(list, 2, libxml_intWrap(severity)); |
| 2012 | PyTuple_SetItem(list, 3, libxml_xmlTextReaderLocatorPtrWrap(locator)); |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2013 | result = PyEval_CallObject(pyCtxt->f, list); |
| 2014 | if (result == NULL) |
| 2015 | { |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 2016 | /* TODO: manage for the exception to be propagated... */ |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2017 | PyErr_Print(); |
| 2018 | } |
| 2019 | Py_XDECREF(list); |
| 2020 | Py_XDECREF(result); |
| 2021 | } |
| 2022 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2023 | static PyObject * |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2024 | libxml_xmlTextReaderSetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) |
| 2025 | { |
| 2026 | xmlTextReaderPtr reader; |
| 2027 | xmlTextReaderPyCtxtPtr pyCtxt; |
| 2028 | xmlTextReaderErrorFunc f; |
| 2029 | void *arg; |
| 2030 | PyObject *pyobj_reader; |
| 2031 | PyObject *pyobj_f; |
| 2032 | PyObject *pyobj_arg; |
| 2033 | PyObject *py_retval; |
| 2034 | |
| 2035 | if (!PyArg_ParseTuple(args, (char *)"OOO:xmlTextReaderSetErrorHandler", &pyobj_reader, &pyobj_f, &pyobj_arg)) |
| 2036 | return(NULL); |
| 2037 | reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); |
| 2038 | /* clear previous error handler */ |
| 2039 | xmlTextReaderGetErrorHandler(reader,&f,&arg); |
| 2040 | if (arg != NULL) { |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2041 | if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) { |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2042 | /* ok, it's our error handler! */ |
| 2043 | pyCtxt = (xmlTextReaderPyCtxtPtr)arg; |
| 2044 | Py_XDECREF(pyCtxt->f); |
| 2045 | Py_XDECREF(pyCtxt->arg); |
| 2046 | xmlFree(pyCtxt); |
| 2047 | } |
| 2048 | else { |
| 2049 | /* |
| 2050 | * there already an arg, and it's not ours, |
| 2051 | * there is definitely something wrong going on here... |
| 2052 | * we don't know how to free it, so we bail out... |
| 2053 | */ |
| 2054 | py_retval = libxml_intWrap(-1); |
| 2055 | return(py_retval); |
| 2056 | } |
| 2057 | } |
| 2058 | xmlTextReaderSetErrorHandler(reader,NULL,NULL); |
| 2059 | /* set new error handler */ |
| 2060 | if (pyobj_f != Py_None) |
| 2061 | { |
| 2062 | pyCtxt = (xmlTextReaderPyCtxtPtr)xmlMalloc(sizeof(xmlTextReaderPyCtxt)); |
| 2063 | if (pyCtxt == NULL) { |
| 2064 | py_retval = libxml_intWrap(-1); |
| 2065 | return(py_retval); |
| 2066 | } |
| 2067 | Py_XINCREF(pyobj_f); |
| 2068 | pyCtxt->f = pyobj_f; |
| 2069 | Py_XINCREF(pyobj_arg); |
| 2070 | pyCtxt->arg = pyobj_arg; |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2071 | xmlTextReaderSetErrorHandler(reader, |
| 2072 | (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback, |
| 2073 | pyCtxt); |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | py_retval = libxml_intWrap(1); |
| 2077 | return(py_retval); |
| 2078 | } |
| 2079 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2080 | static PyObject * |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2081 | libxml_xmlTextReaderGetErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) |
| 2082 | { |
| 2083 | xmlTextReaderPtr reader; |
| 2084 | xmlTextReaderPyCtxtPtr pyCtxt; |
| 2085 | xmlTextReaderErrorFunc f; |
| 2086 | void *arg; |
| 2087 | PyObject *pyobj_reader; |
| 2088 | PyObject *py_retval; |
| 2089 | |
| 2090 | if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderSetErrorHandler", &pyobj_reader)) |
| 2091 | return(NULL); |
| 2092 | reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); |
| 2093 | xmlTextReaderGetErrorHandler(reader,&f,&arg); |
| 2094 | py_retval = PyTuple_New(2); |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2095 | if (f == (xmlTextReaderErrorFunc)libxml_xmlTextReaderErrorCallback) { |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2096 | /* ok, it's our error handler! */ |
| 2097 | pyCtxt = (xmlTextReaderPyCtxtPtr)arg; |
| 2098 | PyTuple_SetItem(py_retval, 0, pyCtxt->f); |
| 2099 | Py_XINCREF(pyCtxt->f); |
| 2100 | PyTuple_SetItem(py_retval, 1, pyCtxt->arg); |
| 2101 | Py_XINCREF(pyCtxt->arg); |
| 2102 | } |
| 2103 | else |
| 2104 | { |
| 2105 | /* f is null or it's not our error handler */ |
| 2106 | PyTuple_SetItem(py_retval, 0, Py_None); |
| 2107 | Py_XINCREF(Py_None); |
| 2108 | PyTuple_SetItem(py_retval, 1, Py_None); |
| 2109 | Py_XINCREF(Py_None); |
| 2110 | } |
| 2111 | return(py_retval); |
| 2112 | } |
| 2113 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2114 | static PyObject * |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2115 | libxml_xmlFreeTextReader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 2116 | xmlTextReaderPtr reader; |
| 2117 | PyObject *pyobj_reader; |
| 2118 | xmlTextReaderPyCtxtPtr pyCtxt; |
| 2119 | xmlTextReaderErrorFunc f; |
| 2120 | void *arg; |
| 2121 | |
Daniel Veillard | 157fee0 | 2003-10-31 10:36:03 +0000 | [diff] [blame] | 2122 | if (!PyArg_ParseTuple(args, (char *)"O:xmlFreeTextReader", &pyobj_reader)) |
| 2123 | return(NULL); |
| 2124 | if (!PyCObject_Check(pyobj_reader)) { |
Daniel Veillard | bb3ba32 | 2003-10-30 13:12:43 +0000 | [diff] [blame] | 2125 | Py_INCREF(Py_None); |
| 2126 | return(Py_None); |
| 2127 | } |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2128 | reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); |
Daniel Veillard | bb3ba32 | 2003-10-30 13:12:43 +0000 | [diff] [blame] | 2129 | if (reader == NULL) { |
| 2130 | Py_INCREF(Py_None); |
| 2131 | return(Py_None); |
| 2132 | } |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2133 | |
| 2134 | xmlTextReaderGetErrorHandler(reader,&f,&arg); |
| 2135 | if (arg != NULL) { |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 2136 | if (f == (xmlTextReaderErrorFunc) libxml_xmlTextReaderErrorCallback) { |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2137 | /* ok, it's our error handler! */ |
| 2138 | pyCtxt = (xmlTextReaderPyCtxtPtr)arg; |
| 2139 | Py_XDECREF(pyCtxt->f); |
| 2140 | Py_XDECREF(pyCtxt->arg); |
| 2141 | xmlFree(pyCtxt); |
| 2142 | } |
| 2143 | /* |
| 2144 | * else, something wrong happened, because the error handler is |
| 2145 | * not owned by the python bindings... |
| 2146 | */ |
| 2147 | } |
| 2148 | |
| 2149 | xmlFreeTextReader(reader); |
| 2150 | Py_INCREF(Py_None); |
| 2151 | return(Py_None); |
| 2152 | } |
Daniel Veillard | 438ebbd | 2008-05-12 12:58:46 +0000 | [diff] [blame] | 2153 | #endif |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 2154 | |
| 2155 | /************************************************************************ |
| 2156 | * * |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2157 | * XPath extensions * |
| 2158 | * * |
| 2159 | ************************************************************************/ |
| 2160 | |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2161 | static void |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2162 | libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) |
| 2163 | { |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2164 | PyObject *list, *cur, *result; |
| 2165 | xmlXPathObjectPtr obj; |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2166 | xmlXPathContextPtr rctxt; |
| 2167 | PyObject *current_function = NULL; |
| 2168 | const xmlChar *name; |
| 2169 | const xmlChar *ns_uri; |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2170 | int i; |
| 2171 | |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2172 | if (ctxt == NULL) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2173 | return; |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2174 | rctxt = ctxt->context; |
| 2175 | if (rctxt == NULL) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2176 | return; |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2177 | name = rctxt->function; |
| 2178 | ns_uri = rctxt->functionURI; |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2179 | #ifdef DEBUG_XPATH |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2180 | printf("libxml_xmlXPathFuncCallback called name %s URI %s\n", name, |
| 2181 | ns_uri); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2182 | #endif |
| 2183 | |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2184 | /* |
| 2185 | * Find the function, it should be there it was there at lookup |
| 2186 | */ |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2187 | for (i = 0; i < libxml_xpathCallbacksNb; i++) { |
| 2188 | if ( /* TODO (ctxt == libxml_xpathCallbacks[i].ctx) && */ |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2189 | (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) && |
| 2190 | (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) { |
| 2191 | current_function = (*libxml_xpathCallbacks)[i].function; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2192 | } |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2193 | } |
| 2194 | if (current_function == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2195 | printf |
| 2196 | ("libxml_xmlXPathFuncCallback: internal error %s not found !\n", |
| 2197 | name); |
| 2198 | return; |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Daniel Veillard | c575b99 | 2002-02-08 13:28:40 +0000 | [diff] [blame] | 2201 | list = PyTuple_New(nargs + 1); |
| 2202 | PyTuple_SetItem(list, 0, libxml_xmlXPathParserContextPtrWrap(ctxt)); |
Daniel Veillard | 05349ab | 2004-01-25 20:01:35 +0000 | [diff] [blame] | 2203 | for (i = nargs - 1; i >= 0; i--) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2204 | obj = valuePop(ctxt); |
| 2205 | cur = libxml_xmlXPathObjectPtrWrap(obj); |
| 2206 | PyTuple_SetItem(list, i + 1, cur); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2207 | } |
| 2208 | result = PyEval_CallObject(current_function, list); |
| 2209 | Py_DECREF(list); |
| 2210 | |
| 2211 | obj = libxml_xmlXPathObjectPtrConvert(result); |
| 2212 | valuePush(ctxt, obj); |
| 2213 | } |
| 2214 | |
| 2215 | static xmlXPathFunction |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2216 | libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar * name, |
| 2217 | const xmlChar * ns_uri) |
| 2218 | { |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2219 | int i; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2220 | |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2221 | #ifdef DEBUG_XPATH |
| 2222 | printf("libxml_xmlXPathFuncLookupFunc(%p, %s, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2223 | ctxt, name, ns_uri); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2224 | #endif |
Daniel Veillard | 70cab35 | 2002-02-06 16:06:58 +0000 | [diff] [blame] | 2225 | /* |
| 2226 | * This is called once only. The address is then stored in the |
| 2227 | * XPath expression evaluation, the proper object to call can |
| 2228 | * then still be found using the execution context function |
| 2229 | * and functionURI fields. |
| 2230 | */ |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2231 | for (i = 0; i < libxml_xpathCallbacksNb; i++) { |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2232 | if ((ctxt == (*libxml_xpathCallbacks)[i].ctx) && |
| 2233 | (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) && |
| 2234 | (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2235 | return (libxml_xmlXPathFuncCallback); |
| 2236 | } |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2237 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2238 | return (NULL); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | static void |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2242 | libxml_xpathCallbacksInitialize(void) |
| 2243 | { |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2244 | int i; |
| 2245 | |
| 2246 | if (libxml_xpathCallbacksInitialized != 0) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2247 | return; |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2248 | |
| 2249 | #ifdef DEBUG_XPATH |
| 2250 | printf("libxml_xpathCallbacksInitialized called\n"); |
| 2251 | #endif |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2252 | libxml_xpathCallbacks = (libxml_xpathCallbackArray*)xmlMalloc( |
| 2253 | libxml_xpathCallbacksAllocd*sizeof(libxml_xpathCallback)); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2254 | |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2255 | for (i = 0; i < libxml_xpathCallbacksAllocd; i++) { |
| 2256 | (*libxml_xpathCallbacks)[i].ctx = NULL; |
| 2257 | (*libxml_xpathCallbacks)[i].name = NULL; |
| 2258 | (*libxml_xpathCallbacks)[i].ns_uri = NULL; |
| 2259 | (*libxml_xpathCallbacks)[i].function = NULL; |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2260 | } |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2261 | libxml_xpathCallbacksInitialized = 1; |
| 2262 | } |
| 2263 | |
| 2264 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2265 | libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObject * self, |
| 2266 | PyObject * args) |
| 2267 | { |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2268 | PyObject *py_retval; |
| 2269 | int c_retval = 0; |
| 2270 | xmlChar *name; |
| 2271 | xmlChar *ns_uri; |
| 2272 | xmlXPathContextPtr ctx; |
| 2273 | PyObject *pyobj_ctx; |
| 2274 | PyObject *pyobj_f; |
| 2275 | int i; |
| 2276 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2277 | if (!PyArg_ParseTuple |
| 2278 | (args, (char *) "OszO:registerXPathFunction", &pyobj_ctx, &name, |
| 2279 | &ns_uri, &pyobj_f)) |
| 2280 | return (NULL); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2281 | |
| 2282 | ctx = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctx); |
| 2283 | if (libxml_xpathCallbacksInitialized == 0) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2284 | libxml_xpathCallbacksInitialize(); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2285 | xmlXPathRegisterFuncLookup(ctx, libxml_xmlXPathFuncLookupFunc, ctx); |
| 2286 | |
| 2287 | if ((pyobj_ctx == NULL) || (name == NULL) || (pyobj_f == NULL)) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2288 | py_retval = libxml_intWrap(-1); |
| 2289 | return (py_retval); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2290 | } |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2291 | #ifdef DEBUG_XPATH |
| 2292 | printf("libxml_registerXPathFunction(%p, %s, %s) called\n", |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2293 | ctx, name, ns_uri); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2294 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2295 | for (i = 0; i < libxml_xpathCallbacksNb; i++) { |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2296 | if ((ctx == (*libxml_xpathCallbacks)[i].ctx) && |
| 2297 | (xmlStrEqual(name, (*libxml_xpathCallbacks)[i].name)) && |
| 2298 | (xmlStrEqual(ns_uri, (*libxml_xpathCallbacks)[i].ns_uri))) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2299 | Py_XINCREF(pyobj_f); |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2300 | Py_XDECREF((*libxml_xpathCallbacks)[i].function); |
| 2301 | (*libxml_xpathCallbacks)[i].function = pyobj_f; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2302 | c_retval = 1; |
| 2303 | goto done; |
| 2304 | } |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2305 | } |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2306 | if (libxml_xpathCallbacksNb >= libxml_xpathCallbacksAllocd) { |
| 2307 | libxml_xpathCallbacksAllocd+=10; |
| 2308 | libxml_xpathCallbacks = (libxml_xpathCallbackArray*)xmlRealloc( |
| 2309 | libxml_xpathCallbacks, |
| 2310 | libxml_xpathCallbacksAllocd*sizeof(libxml_xpathCallback)); |
| 2311 | } |
| 2312 | i = libxml_xpathCallbacksNb++; |
| 2313 | Py_XINCREF(pyobj_f); |
| 2314 | (*libxml_xpathCallbacks)[i].ctx = ctx; |
| 2315 | (*libxml_xpathCallbacks)[i].name = xmlStrdup(name); |
| 2316 | (*libxml_xpathCallbacks)[i].ns_uri = xmlStrdup(ns_uri); |
| 2317 | (*libxml_xpathCallbacks)[i].function = pyobj_f; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2318 | c_retval = 1; |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 2319 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2320 | done: |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2321 | py_retval = libxml_intWrap((int) c_retval); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2322 | return (py_retval); |
Daniel Veillard | a7340c8 | 2002-02-01 17:56:45 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 2325 | /************************************************************************ |
| 2326 | * * |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2327 | * Global properties access * |
| 2328 | * * |
| 2329 | ************************************************************************/ |
| 2330 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2331 | libxml_name(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2332 | { |
| 2333 | PyObject *resultobj, *obj; |
| 2334 | xmlNodePtr cur; |
| 2335 | const xmlChar *res; |
| 2336 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2337 | if (!PyArg_ParseTuple(args, (char *) "O:name", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2338 | return NULL; |
| 2339 | cur = PyxmlNode_Get(obj); |
| 2340 | |
| 2341 | #ifdef DEBUG |
| 2342 | printf("libxml_name: cur = %p type %d\n", cur, cur->type); |
| 2343 | #endif |
| 2344 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2345 | switch (cur->type) { |
| 2346 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2347 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2348 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2349 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2350 | case XML_HTML_DOCUMENT_NODE:{ |
| 2351 | xmlDocPtr doc = (xmlDocPtr) cur; |
| 2352 | |
| 2353 | res = doc->URL; |
| 2354 | break; |
| 2355 | } |
| 2356 | case XML_ATTRIBUTE_NODE:{ |
| 2357 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2358 | |
| 2359 | res = attr->name; |
| 2360 | break; |
| 2361 | } |
| 2362 | case XML_NAMESPACE_DECL:{ |
| 2363 | xmlNsPtr ns = (xmlNsPtr) cur; |
| 2364 | |
| 2365 | res = ns->prefix; |
| 2366 | break; |
| 2367 | } |
| 2368 | default: |
| 2369 | res = cur->name; |
| 2370 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2371 | } |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 2372 | resultobj = libxml_constxmlCharPtrWrap(res); |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2373 | |
| 2374 | return resultobj; |
| 2375 | } |
| 2376 | |
| 2377 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2378 | libxml_doc(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2379 | { |
| 2380 | PyObject *resultobj, *obj; |
| 2381 | xmlNodePtr cur; |
| 2382 | xmlDocPtr res; |
| 2383 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2384 | if (!PyArg_ParseTuple(args, (char *) "O:doc", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2385 | return NULL; |
| 2386 | cur = PyxmlNode_Get(obj); |
| 2387 | |
| 2388 | #ifdef DEBUG |
| 2389 | printf("libxml_doc: cur = %p\n", cur); |
| 2390 | #endif |
| 2391 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2392 | switch (cur->type) { |
| 2393 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2394 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2395 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2396 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2397 | case XML_HTML_DOCUMENT_NODE: |
| 2398 | res = NULL; |
| 2399 | break; |
| 2400 | case XML_ATTRIBUTE_NODE:{ |
| 2401 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2402 | |
| 2403 | res = attr->doc; |
| 2404 | break; |
| 2405 | } |
| 2406 | case XML_NAMESPACE_DECL: |
| 2407 | res = NULL; |
| 2408 | break; |
| 2409 | default: |
| 2410 | res = cur->doc; |
| 2411 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2412 | } |
| 2413 | resultobj = libxml_xmlDocPtrWrap(res); |
| 2414 | return resultobj; |
| 2415 | } |
| 2416 | |
| 2417 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2418 | libxml_properties(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2419 | { |
| 2420 | PyObject *resultobj, *obj; |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 2421 | xmlNodePtr cur; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2422 | xmlAttrPtr res; |
| 2423 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2424 | if (!PyArg_ParseTuple(args, (char *) "O:properties", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2425 | return NULL; |
| 2426 | cur = PyxmlNode_Get(obj); |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 2427 | if ((cur != NULL) && (cur->type == XML_ELEMENT_NODE)) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2428 | res = cur->properties; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2429 | else |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2430 | res = NULL; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2431 | resultobj = libxml_xmlAttrPtrWrap(res); |
| 2432 | return resultobj; |
| 2433 | } |
| 2434 | |
| 2435 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2436 | libxml_next(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2437 | { |
| 2438 | PyObject *resultobj, *obj; |
| 2439 | xmlNodePtr cur; |
| 2440 | xmlNodePtr res; |
| 2441 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2442 | if (!PyArg_ParseTuple(args, (char *) "O:next", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2443 | return NULL; |
| 2444 | cur = PyxmlNode_Get(obj); |
| 2445 | |
| 2446 | #ifdef DEBUG |
| 2447 | printf("libxml_next: cur = %p\n", cur); |
| 2448 | #endif |
| 2449 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2450 | switch (cur->type) { |
| 2451 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2452 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2453 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2454 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2455 | case XML_HTML_DOCUMENT_NODE: |
| 2456 | res = NULL; |
| 2457 | break; |
| 2458 | case XML_ATTRIBUTE_NODE:{ |
| 2459 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2460 | |
| 2461 | res = (xmlNodePtr) attr->next; |
| 2462 | break; |
| 2463 | } |
| 2464 | case XML_NAMESPACE_DECL:{ |
| 2465 | xmlNsPtr ns = (xmlNsPtr) cur; |
| 2466 | |
| 2467 | res = (xmlNodePtr) ns->next; |
| 2468 | break; |
| 2469 | } |
| 2470 | default: |
| 2471 | res = cur->next; |
| 2472 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2473 | |
| 2474 | } |
| 2475 | resultobj = libxml_xmlNodePtrWrap(res); |
| 2476 | return resultobj; |
| 2477 | } |
| 2478 | |
| 2479 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2480 | libxml_prev(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2481 | { |
| 2482 | PyObject *resultobj, *obj; |
| 2483 | xmlNodePtr cur; |
| 2484 | xmlNodePtr res; |
| 2485 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2486 | if (!PyArg_ParseTuple(args, (char *) "O:prev", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2487 | return NULL; |
| 2488 | cur = PyxmlNode_Get(obj); |
| 2489 | |
| 2490 | #ifdef DEBUG |
| 2491 | printf("libxml_prev: cur = %p\n", cur); |
| 2492 | #endif |
| 2493 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2494 | switch (cur->type) { |
| 2495 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2496 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2497 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2498 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2499 | case XML_HTML_DOCUMENT_NODE: |
| 2500 | res = NULL; |
| 2501 | break; |
| 2502 | case XML_ATTRIBUTE_NODE:{ |
| 2503 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2504 | |
Daniel Veillard | faa35ff | 2002-11-24 13:53:43 +0000 | [diff] [blame] | 2505 | res = (xmlNodePtr) attr->prev; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2506 | } |
Daniel Veillard | 594e5df | 2009-09-07 14:58:47 +0200 | [diff] [blame] | 2507 | break; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2508 | case XML_NAMESPACE_DECL: |
| 2509 | res = NULL; |
| 2510 | break; |
| 2511 | default: |
Daniel Veillard | faa35ff | 2002-11-24 13:53:43 +0000 | [diff] [blame] | 2512 | res = cur->prev; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2513 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2514 | } |
| 2515 | resultobj = libxml_xmlNodePtrWrap(res); |
| 2516 | return resultobj; |
| 2517 | } |
| 2518 | |
| 2519 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2520 | libxml_children(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2521 | { |
| 2522 | PyObject *resultobj, *obj; |
| 2523 | xmlNodePtr cur; |
| 2524 | xmlNodePtr res; |
| 2525 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2526 | if (!PyArg_ParseTuple(args, (char *) "O:children", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2527 | return NULL; |
| 2528 | cur = PyxmlNode_Get(obj); |
| 2529 | |
| 2530 | #ifdef DEBUG |
| 2531 | printf("libxml_children: cur = %p\n", cur); |
| 2532 | #endif |
| 2533 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2534 | switch (cur->type) { |
| 2535 | case XML_ELEMENT_NODE: |
| 2536 | case XML_ENTITY_REF_NODE: |
| 2537 | case XML_ENTITY_NODE: |
| 2538 | case XML_PI_NODE: |
| 2539 | case XML_COMMENT_NODE: |
| 2540 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2541 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2542 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2543 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2544 | case XML_HTML_DOCUMENT_NODE: |
| 2545 | case XML_DTD_NODE: |
| 2546 | res = cur->children; |
| 2547 | break; |
| 2548 | case XML_ATTRIBUTE_NODE:{ |
| 2549 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2550 | |
| 2551 | res = attr->children; |
| 2552 | break; |
| 2553 | } |
| 2554 | default: |
| 2555 | res = NULL; |
| 2556 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2557 | } |
| 2558 | resultobj = libxml_xmlNodePtrWrap(res); |
| 2559 | return resultobj; |
| 2560 | } |
| 2561 | |
| 2562 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2563 | libxml_last(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2564 | { |
| 2565 | PyObject *resultobj, *obj; |
| 2566 | xmlNodePtr cur; |
| 2567 | xmlNodePtr res; |
| 2568 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2569 | if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2570 | return NULL; |
| 2571 | cur = PyxmlNode_Get(obj); |
| 2572 | |
| 2573 | #ifdef DEBUG |
| 2574 | printf("libxml_last: cur = %p\n", cur); |
| 2575 | #endif |
| 2576 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2577 | switch (cur->type) { |
| 2578 | case XML_ELEMENT_NODE: |
| 2579 | case XML_ENTITY_REF_NODE: |
| 2580 | case XML_ENTITY_NODE: |
| 2581 | case XML_PI_NODE: |
| 2582 | case XML_COMMENT_NODE: |
| 2583 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2584 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2585 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2586 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2587 | case XML_HTML_DOCUMENT_NODE: |
| 2588 | case XML_DTD_NODE: |
| 2589 | res = cur->last; |
| 2590 | break; |
| 2591 | case XML_ATTRIBUTE_NODE:{ |
| 2592 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2593 | |
| 2594 | res = attr->last; |
| 2595 | } |
| 2596 | default: |
| 2597 | res = NULL; |
| 2598 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2599 | } |
| 2600 | resultobj = libxml_xmlNodePtrWrap(res); |
| 2601 | return resultobj; |
| 2602 | } |
| 2603 | |
| 2604 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2605 | libxml_parent(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2606 | { |
| 2607 | PyObject *resultobj, *obj; |
| 2608 | xmlNodePtr cur; |
| 2609 | xmlNodePtr res; |
| 2610 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2611 | if (!PyArg_ParseTuple(args, (char *) "O:parent", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2612 | return NULL; |
| 2613 | cur = PyxmlNode_Get(obj); |
| 2614 | |
| 2615 | #ifdef DEBUG |
| 2616 | printf("libxml_parent: cur = %p\n", cur); |
| 2617 | #endif |
| 2618 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2619 | switch (cur->type) { |
| 2620 | case XML_DOCUMENT_NODE: |
| 2621 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2622 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2623 | case XML_DOCB_DOCUMENT_NODE: |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2624 | #endif |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2625 | res = NULL; |
| 2626 | break; |
| 2627 | case XML_ATTRIBUTE_NODE:{ |
| 2628 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2629 | |
| 2630 | res = attr->parent; |
| 2631 | } |
Daniel Veillard | 22eda2b | 2005-08-01 05:20:16 +0000 | [diff] [blame] | 2632 | break; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2633 | case XML_ENTITY_DECL: |
| 2634 | case XML_NAMESPACE_DECL: |
| 2635 | case XML_XINCLUDE_START: |
| 2636 | case XML_XINCLUDE_END: |
| 2637 | res = NULL; |
| 2638 | break; |
| 2639 | default: |
| 2640 | res = cur->parent; |
| 2641 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2642 | } |
| 2643 | resultobj = libxml_xmlNodePtrWrap(res); |
| 2644 | return resultobj; |
| 2645 | } |
| 2646 | |
| 2647 | static PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2648 | libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2649 | { |
| 2650 | PyObject *resultobj, *obj; |
| 2651 | xmlNodePtr cur; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2652 | const xmlChar *res = NULL; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2653 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2654 | if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2655 | return NULL; |
| 2656 | cur = PyxmlNode_Get(obj); |
| 2657 | |
| 2658 | #ifdef DEBUG |
| 2659 | printf("libxml_type: cur = %p\n", cur); |
| 2660 | #endif |
| 2661 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2662 | switch (cur->type) { |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2663 | case XML_ELEMENT_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2664 | res = (const xmlChar *) "element"; |
| 2665 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2666 | case XML_ATTRIBUTE_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2667 | res = (const xmlChar *) "attribute"; |
| 2668 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2669 | case XML_TEXT_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2670 | res = (const xmlChar *) "text"; |
| 2671 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2672 | case XML_CDATA_SECTION_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2673 | res = (const xmlChar *) "cdata"; |
| 2674 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2675 | case XML_ENTITY_REF_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2676 | res = (const xmlChar *) "entity_ref"; |
| 2677 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2678 | case XML_ENTITY_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2679 | res = (const xmlChar *) "entity"; |
| 2680 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2681 | case XML_PI_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2682 | res = (const xmlChar *) "pi"; |
| 2683 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2684 | case XML_COMMENT_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2685 | res = (const xmlChar *) "comment"; |
| 2686 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2687 | case XML_DOCUMENT_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2688 | res = (const xmlChar *) "document_xml"; |
| 2689 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2690 | case XML_DOCUMENT_TYPE_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2691 | res = (const xmlChar *) "doctype"; |
| 2692 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2693 | case XML_DOCUMENT_FRAG_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2694 | res = (const xmlChar *) "fragment"; |
| 2695 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2696 | case XML_NOTATION_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2697 | res = (const xmlChar *) "notation"; |
| 2698 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2699 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2700 | res = (const xmlChar *) "document_html"; |
| 2701 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2702 | case XML_DTD_NODE: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2703 | res = (const xmlChar *) "dtd"; |
| 2704 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2705 | case XML_ELEMENT_DECL: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2706 | res = (const xmlChar *) "elem_decl"; |
| 2707 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2708 | case XML_ATTRIBUTE_DECL: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2709 | res = (const xmlChar *) "attribute_decl"; |
| 2710 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2711 | case XML_ENTITY_DECL: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2712 | res = (const xmlChar *) "entity_decl"; |
| 2713 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2714 | case XML_NAMESPACE_DECL: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2715 | res = (const xmlChar *) "namespace"; |
| 2716 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2717 | case XML_XINCLUDE_START: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2718 | res = (const xmlChar *) "xinclude_start"; |
| 2719 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2720 | case XML_XINCLUDE_END: |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2721 | res = (const xmlChar *) "xinclude_end"; |
| 2722 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2723 | #ifdef LIBXML_DOCB_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2724 | case XML_DOCB_DOCUMENT_NODE: |
| 2725 | res = (const xmlChar *) "document_docbook"; |
| 2726 | break; |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2727 | #endif |
| 2728 | } |
| 2729 | #ifdef DEBUG |
| 2730 | printf("libxml_type: cur = %p: %s\n", cur, res); |
| 2731 | #endif |
| 2732 | |
Daniel Veillard | 1971ee2 | 2002-01-31 20:29:19 +0000 | [diff] [blame] | 2733 | resultobj = libxml_constxmlCharPtrWrap(res); |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 2734 | return resultobj; |
| 2735 | } |
| 2736 | |
| 2737 | /************************************************************************ |
| 2738 | * * |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2739 | * Specific accessor functions * |
| 2740 | * * |
| 2741 | ************************************************************************/ |
| 2742 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2743 | libxml_xmlNodeGetNsDefs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2744 | { |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2745 | PyObject *py_retval; |
| 2746 | xmlNsPtr c_retval; |
| 2747 | xmlNodePtr node; |
| 2748 | PyObject *pyobj_node; |
| 2749 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2750 | if (!PyArg_ParseTuple |
| 2751 | (args, (char *) "O:xmlNodeGetNsDefs", &pyobj_node)) |
| 2752 | return (NULL); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2753 | node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
| 2754 | |
| 2755 | if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2756 | Py_INCREF(Py_None); |
| 2757 | return (Py_None); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2758 | } |
| 2759 | c_retval = node->nsDef; |
| 2760 | py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2761 | return (py_retval); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | PyObject * |
Daniel Veillard | f9cf6f5 | 2005-04-12 01:02:29 +0000 | [diff] [blame] | 2765 | libxml_xmlNodeRemoveNsDef(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2766 | { |
| 2767 | PyObject *py_retval; |
| 2768 | xmlNsPtr ns, prev; |
| 2769 | xmlNodePtr node; |
| 2770 | PyObject *pyobj_node; |
| 2771 | xmlChar *href; |
| 2772 | xmlNsPtr c_retval; |
| 2773 | |
| 2774 | if (!PyArg_ParseTuple |
| 2775 | (args, (char *) "Oz:xmlNodeRemoveNsDef", &pyobj_node, &href)) |
| 2776 | return (NULL); |
| 2777 | node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
| 2778 | ns = NULL; |
| 2779 | |
| 2780 | if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) { |
| 2781 | Py_INCREF(Py_None); |
| 2782 | return (Py_None); |
| 2783 | } |
| 2784 | |
| 2785 | if (href == NULL) { |
| 2786 | ns = node->nsDef; |
| 2787 | node->nsDef = NULL; |
| 2788 | c_retval = 0; |
| 2789 | } |
| 2790 | else { |
| 2791 | prev = NULL; |
| 2792 | ns = node->nsDef; |
| 2793 | while (ns != NULL) { |
| 2794 | if (xmlStrEqual(ns->href, href)) { |
| 2795 | if (prev != NULL) |
| 2796 | prev->next = ns->next; |
| 2797 | else |
| 2798 | node->nsDef = ns->next; |
| 2799 | ns->next = NULL; |
| 2800 | c_retval = 0; |
| 2801 | break; |
| 2802 | } |
| 2803 | prev = ns; |
| 2804 | ns = ns->next; |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | c_retval = ns; |
| 2809 | py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval); |
| 2810 | return (py_retval); |
| 2811 | } |
| 2812 | |
| 2813 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2814 | libxml_xmlNodeGetNs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2815 | { |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2816 | PyObject *py_retval; |
| 2817 | xmlNsPtr c_retval; |
| 2818 | xmlNodePtr node; |
| 2819 | PyObject *pyobj_node; |
| 2820 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2821 | if (!PyArg_ParseTuple(args, (char *) "O:xmlNodeGetNs", &pyobj_node)) |
| 2822 | return (NULL); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2823 | node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
| 2824 | |
Daniel Veillard | e96a2a4 | 2003-09-24 21:23:56 +0000 | [diff] [blame] | 2825 | if ((node == NULL) || |
| 2826 | ((node->type != XML_ELEMENT_NODE) && |
| 2827 | (node->type != XML_ATTRIBUTE_NODE))) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2828 | Py_INCREF(Py_None); |
| 2829 | return (Py_None); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2830 | } |
| 2831 | c_retval = node->ns; |
| 2832 | py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2833 | return (py_retval); |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2836 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 36eea2d | 2002-02-04 00:17:01 +0000 | [diff] [blame] | 2837 | /************************************************************************ |
| 2838 | * * |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2839 | * Serialization front-end * |
| 2840 | * * |
| 2841 | ************************************************************************/ |
| 2842 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2843 | static PyObject * |
| 2844 | libxml_serializeNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2845 | { |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2846 | PyObject *py_retval = NULL; |
| 2847 | xmlChar *c_retval; |
| 2848 | PyObject *pyobj_node; |
| 2849 | xmlNodePtr node; |
| 2850 | xmlDocPtr doc; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2851 | const char *encoding; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2852 | int format; |
Daniel Veillard | da3fee4 | 2008-09-01 13:08:57 +0000 | [diff] [blame] | 2853 | xmlSaveCtxtPtr ctxt; |
| 2854 | xmlBufferPtr buf; |
| 2855 | int options = 0; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2856 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2857 | if (!PyArg_ParseTuple(args, (char *) "Ozi:serializeNode", &pyobj_node, |
| 2858 | &encoding, &format)) |
| 2859 | return (NULL); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2860 | node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
| 2861 | |
| 2862 | if (node == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2863 | Py_INCREF(Py_None); |
| 2864 | return (Py_None); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2865 | } |
| 2866 | if (node->type == XML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2867 | doc = (xmlDocPtr) node; |
Daniel Veillard | da3fee4 | 2008-09-01 13:08:57 +0000 | [diff] [blame] | 2868 | node = NULL; |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2869 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2870 | } else if (node->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2871 | doc = (xmlDocPtr) node; |
Daniel Veillard | da3fee4 | 2008-09-01 13:08:57 +0000 | [diff] [blame] | 2872 | node = NULL; |
| 2873 | #endif |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2874 | } else { |
William M. Brack | 95af594 | 2004-02-08 04:12:49 +0000 | [diff] [blame] | 2875 | if (node->type == XML_NAMESPACE_DECL) |
| 2876 | doc = NULL; |
| 2877 | else |
| 2878 | doc = node->doc; |
Daniel Veillard | a8c0adb | 2002-11-17 22:37:35 +0000 | [diff] [blame] | 2879 | if ((doc == NULL) || (doc->type == XML_DOCUMENT_NODE)) { |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2880 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2881 | } else if (doc->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2882 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2883 | } else { |
| 2884 | Py_INCREF(Py_None); |
| 2885 | return (Py_None); |
| 2886 | } |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2887 | } |
Daniel Veillard | da3fee4 | 2008-09-01 13:08:57 +0000 | [diff] [blame] | 2888 | |
| 2889 | |
| 2890 | buf = xmlBufferCreate(); |
| 2891 | if (buf == NULL) { |
| 2892 | Py_INCREF(Py_None); |
| 2893 | return (Py_None); |
| 2894 | } |
| 2895 | if (format) options |= XML_SAVE_FORMAT; |
| 2896 | ctxt = xmlSaveToBuffer(buf, encoding, options); |
| 2897 | if (ctxt == NULL) { |
| 2898 | xmlBufferFree(buf); |
| 2899 | Py_INCREF(Py_None); |
| 2900 | return (Py_None); |
| 2901 | } |
| 2902 | if (node == NULL) |
| 2903 | xmlSaveDoc(ctxt, doc); |
| 2904 | else |
| 2905 | xmlSaveTree(ctxt, node); |
| 2906 | xmlSaveClose(ctxt); |
| 2907 | |
| 2908 | c_retval = buf->content; |
| 2909 | buf->content = NULL; |
| 2910 | |
| 2911 | xmlBufferFree(buf); |
| 2912 | py_retval = libxml_charPtrWrap((char *) c_retval); |
| 2913 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2914 | return (py_retval); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2917 | static PyObject * |
| 2918 | libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2919 | { |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2920 | PyObject *py_file = NULL; |
| 2921 | FILE *output; |
| 2922 | PyObject *pyobj_node; |
| 2923 | xmlNodePtr node; |
| 2924 | xmlDocPtr doc; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2925 | const char *encoding; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2926 | int format; |
| 2927 | int len; |
| 2928 | xmlOutputBufferPtr buf; |
| 2929 | xmlCharEncodingHandlerPtr handler = NULL; |
| 2930 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2931 | if (!PyArg_ParseTuple(args, (char *) "OOzi:serializeNode", &pyobj_node, |
| 2932 | &py_file, &encoding, &format)) |
| 2933 | return (NULL); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2934 | node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); |
| 2935 | |
| 2936 | if (node == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2937 | return (PyInt_FromLong((long) -1)); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2938 | } |
| 2939 | if ((py_file == NULL) || (!(PyFile_Check(py_file)))) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2940 | return (PyInt_FromLong((long) -1)); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2941 | } |
| 2942 | output = PyFile_AsFile(py_file); |
| 2943 | if (output == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2944 | return (PyInt_FromLong((long) -1)); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | if (node->type == XML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2948 | doc = (xmlDocPtr) node; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2949 | } else if (node->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2950 | doc = (xmlDocPtr) node; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2951 | } else { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2952 | doc = node->doc; |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2953 | } |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2954 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2955 | if (doc->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2956 | if (encoding == NULL) |
| 2957 | encoding = (const char *) htmlGetMetaEncoding(doc); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2958 | } |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2959 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2960 | if (encoding != NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2961 | handler = xmlFindCharEncodingHandler(encoding); |
| 2962 | if (handler == NULL) { |
| 2963 | return (PyInt_FromLong((long) -1)); |
| 2964 | } |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2965 | } |
| 2966 | if (doc->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2967 | if (handler == NULL) |
| 2968 | handler = xmlFindCharEncodingHandler("HTML"); |
| 2969 | if (handler == NULL) |
| 2970 | handler = xmlFindCharEncodingHandler("ascii"); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | buf = xmlOutputBufferCreateFile(output, handler); |
| 2974 | if (node->type == XML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2975 | len = xmlSaveFormatFileTo(buf, doc, encoding, format); |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2976 | #ifdef LIBXML_HTML_ENABLED |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2977 | } else if (node->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2978 | htmlDocContentDumpFormatOutput(buf, doc, encoding, format); |
| 2979 | len = xmlOutputBufferClose(buf); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2980 | } else if (doc->type == XML_HTML_DOCUMENT_NODE) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2981 | htmlNodeDumpFormatOutput(buf, doc, node, encoding, format); |
| 2982 | len = xmlOutputBufferClose(buf); |
Daniel Veillard | 656ce94 | 2004-04-30 23:11:45 +0000 | [diff] [blame] | 2983 | #endif /* LIBXML_HTML_ENABLED */ |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2984 | } else { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2985 | xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); |
| 2986 | len = xmlOutputBufferClose(buf); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2987 | } |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2988 | return (PyInt_FromLong((long) len)); |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2989 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2990 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 1e77438 | 2002-03-06 17:35:40 +0000 | [diff] [blame] | 2991 | |
| 2992 | /************************************************************************ |
| 2993 | * * |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 2994 | * Extra stuff * |
| 2995 | * * |
| 2996 | ************************************************************************/ |
| 2997 | PyObject * |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 2998 | libxml_xmlNewNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 2999 | { |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3000 | PyObject *py_retval; |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3001 | xmlChar *name; |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3002 | xmlNodePtr node; |
| 3003 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3004 | if (!PyArg_ParseTuple(args, (char *) "s:xmlNewNode", &name)) |
| 3005 | return (NULL); |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3006 | node = (xmlNodePtr) xmlNewNode(NULL, name); |
Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 3007 | #ifdef DEBUG |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3008 | printf("NewNode: %s : %p\n", name, (void *) node); |
Daniel Veillard | 3b2e4e1 | 2003-02-03 08:52:58 +0000 | [diff] [blame] | 3009 | #endif |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3010 | |
| 3011 | if (node == NULL) { |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3012 | Py_INCREF(Py_None); |
| 3013 | return (Py_None); |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3014 | } |
| 3015 | py_retval = libxml_xmlNodePtrWrap(node); |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3016 | return (py_retval); |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
Daniel Veillard | 5439624 | 2003-04-23 07:36:50 +0000 | [diff] [blame] | 3019 | |
| 3020 | /************************************************************************ |
| 3021 | * * |
| 3022 | * Local Catalog stuff * |
| 3023 | * * |
| 3024 | ************************************************************************/ |
| 3025 | static PyObject * |
| 3026 | libxml_addLocalCatalog(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 3027 | { |
| 3028 | xmlChar *URL; |
| 3029 | xmlParserCtxtPtr ctxt; |
| 3030 | PyObject *pyobj_ctxt; |
| 3031 | |
| 3032 | if (!PyArg_ParseTuple(args, (char *)"Os:addLocalCatalog", &pyobj_ctxt, &URL)) |
| 3033 | return(NULL); |
| 3034 | |
| 3035 | ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); |
| 3036 | |
| 3037 | if (URL != NULL) { |
| 3038 | ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs, URL); |
| 3039 | } |
| 3040 | |
| 3041 | #ifdef DEBUG |
| 3042 | printf("LocalCatalog: %s\n", URL); |
| 3043 | #endif |
| 3044 | |
| 3045 | Py_INCREF(Py_None); |
| 3046 | return (Py_None); |
| 3047 | } |
| 3048 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3049 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 3050 | |
| 3051 | /************************************************************************ |
| 3052 | * * |
| 3053 | * RelaxNG error handler registration * |
| 3054 | * * |
| 3055 | ************************************************************************/ |
| 3056 | |
| 3057 | typedef struct |
| 3058 | { |
| 3059 | PyObject *warn; |
| 3060 | PyObject *error; |
| 3061 | PyObject *arg; |
| 3062 | } xmlRelaxNGValidCtxtPyCtxt; |
| 3063 | typedef xmlRelaxNGValidCtxtPyCtxt *xmlRelaxNGValidCtxtPyCtxtPtr; |
| 3064 | |
| 3065 | static void |
| 3066 | libxml_xmlRelaxNGValidityGenericErrorFuncHandler(void *ctx, char *str) |
| 3067 | { |
| 3068 | PyObject *list; |
| 3069 | PyObject *result; |
| 3070 | xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt; |
| 3071 | |
| 3072 | #ifdef DEBUG_ERROR |
| 3073 | printf("libxml_xmlRelaxNGValidityGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str); |
| 3074 | #endif |
| 3075 | |
| 3076 | pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx; |
| 3077 | |
| 3078 | list = PyTuple_New(2); |
| 3079 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 3080 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 3081 | Py_XINCREF(pyCtxt->arg); |
| 3082 | result = PyEval_CallObject(pyCtxt->error, list); |
| 3083 | if (result == NULL) |
| 3084 | { |
| 3085 | /* TODO: manage for the exception to be propagated... */ |
| 3086 | PyErr_Print(); |
| 3087 | } |
| 3088 | Py_XDECREF(list); |
| 3089 | Py_XDECREF(result); |
| 3090 | } |
| 3091 | |
| 3092 | static void |
| 3093 | libxml_xmlRelaxNGValidityGenericWarningFuncHandler(void *ctx, char *str) |
| 3094 | { |
| 3095 | PyObject *list; |
| 3096 | PyObject *result; |
| 3097 | xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt; |
| 3098 | |
| 3099 | #ifdef DEBUG_ERROR |
| 3100 | printf("libxml_xmlRelaxNGValidityGenericWarningFuncHandler(%p, %s, ...) called\n", ctx, str); |
| 3101 | #endif |
| 3102 | |
| 3103 | pyCtxt = (xmlRelaxNGValidCtxtPyCtxtPtr)ctx; |
| 3104 | |
| 3105 | list = PyTuple_New(2); |
| 3106 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 3107 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 3108 | Py_XINCREF(pyCtxt->arg); |
| 3109 | result = PyEval_CallObject(pyCtxt->warn, list); |
| 3110 | if (result == NULL) |
| 3111 | { |
| 3112 | /* TODO: manage for the exception to be propagated... */ |
| 3113 | PyErr_Print(); |
| 3114 | } |
| 3115 | Py_XDECREF(list); |
| 3116 | Py_XDECREF(result); |
| 3117 | } |
| 3118 | |
| 3119 | static void |
| 3120 | libxml_xmlRelaxNGValidityErrorFunc(void *ctx, const char *msg, ...) |
| 3121 | { |
| 3122 | va_list ap; |
| 3123 | |
| 3124 | va_start(ap, msg); |
| 3125 | libxml_xmlRelaxNGValidityGenericErrorFuncHandler(ctx, libxml_buildMessage(msg, ap)); |
| 3126 | va_end(ap); |
| 3127 | } |
| 3128 | |
| 3129 | static void |
| 3130 | libxml_xmlRelaxNGValidityWarningFunc(void *ctx, const char *msg, ...) |
| 3131 | { |
| 3132 | va_list ap; |
| 3133 | |
| 3134 | va_start(ap, msg); |
| 3135 | libxml_xmlRelaxNGValidityGenericWarningFuncHandler(ctx, libxml_buildMessage(msg, ap)); |
| 3136 | va_end(ap); |
| 3137 | } |
| 3138 | |
| 3139 | static PyObject * |
| 3140 | libxml_xmlRelaxNGSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 3141 | { |
| 3142 | PyObject *py_retval; |
| 3143 | PyObject *pyobj_error; |
| 3144 | PyObject *pyobj_warn; |
| 3145 | PyObject *pyobj_ctx; |
| 3146 | PyObject *pyobj_arg = Py_None; |
| 3147 | xmlRelaxNGValidCtxtPtr ctxt; |
| 3148 | xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt; |
| 3149 | |
| 3150 | if (!PyArg_ParseTuple |
| 3151 | (args, (char *) "OOO|O:xmlRelaxNGSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg)) |
| 3152 | return (NULL); |
| 3153 | |
| 3154 | #ifdef DEBUG_ERROR |
| 3155 | printf("libxml_xmlRelaxNGSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn); |
| 3156 | #endif |
| 3157 | |
| 3158 | ctxt = PyrelaxNgValidCtxt_Get(pyobj_ctx); |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 3159 | if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == -1) |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3160 | { |
| 3161 | py_retval = libxml_intWrap(-1); |
| 3162 | return(py_retval); |
| 3163 | } |
| 3164 | |
| 3165 | if (pyCtxt == NULL) |
| 3166 | { |
| 3167 | /* first time to set the error handlers */ |
| 3168 | pyCtxt = xmlMalloc(sizeof(xmlRelaxNGValidCtxtPyCtxt)); |
| 3169 | if (pyCtxt == NULL) { |
| 3170 | py_retval = libxml_intWrap(-1); |
| 3171 | return(py_retval); |
| 3172 | } |
| 3173 | memset(pyCtxt, 0, sizeof(xmlRelaxNGValidCtxtPyCtxt)); |
| 3174 | } |
| 3175 | |
| 3176 | /* TODO: check warn and error is a function ! */ |
| 3177 | Py_XDECREF(pyCtxt->error); |
| 3178 | Py_XINCREF(pyobj_error); |
| 3179 | pyCtxt->error = pyobj_error; |
| 3180 | |
| 3181 | Py_XDECREF(pyCtxt->warn); |
| 3182 | Py_XINCREF(pyobj_warn); |
| 3183 | pyCtxt->warn = pyobj_warn; |
| 3184 | |
| 3185 | Py_XDECREF(pyCtxt->arg); |
| 3186 | Py_XINCREF(pyobj_arg); |
| 3187 | pyCtxt->arg = pyobj_arg; |
| 3188 | |
| 3189 | xmlRelaxNGSetValidErrors(ctxt, &libxml_xmlRelaxNGValidityErrorFunc, &libxml_xmlRelaxNGValidityWarningFunc, pyCtxt); |
| 3190 | |
| 3191 | py_retval = libxml_intWrap(1); |
| 3192 | return (py_retval); |
| 3193 | } |
| 3194 | |
| 3195 | static PyObject * |
| 3196 | libxml_xmlRelaxNGFreeValidCtxt(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { |
| 3197 | xmlRelaxNGValidCtxtPtr ctxt; |
| 3198 | xmlRelaxNGValidCtxtPyCtxtPtr pyCtxt; |
| 3199 | PyObject *pyobj_ctxt; |
| 3200 | |
| 3201 | if (!PyArg_ParseTuple(args, (char *)"O:xmlRelaxNGFreeValidCtxt", &pyobj_ctxt)) |
| 3202 | return(NULL); |
| 3203 | ctxt = (xmlRelaxNGValidCtxtPtr) PyrelaxNgValidCtxt_Get(pyobj_ctxt); |
| 3204 | |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 3205 | if (xmlRelaxNGGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == 0) |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3206 | { |
| 3207 | if (pyCtxt != NULL) |
| 3208 | { |
| 3209 | Py_XDECREF(pyCtxt->error); |
| 3210 | Py_XDECREF(pyCtxt->warn); |
| 3211 | Py_XDECREF(pyCtxt->arg); |
| 3212 | xmlFree(pyCtxt); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | xmlRelaxNGFreeValidCtxt(ctxt); |
| 3217 | Py_INCREF(Py_None); |
| 3218 | return(Py_None); |
| 3219 | } |
| 3220 | |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 3221 | typedef struct |
| 3222 | { |
| 3223 | PyObject *warn; |
| 3224 | PyObject *error; |
| 3225 | PyObject *arg; |
| 3226 | } xmlSchemaValidCtxtPyCtxt; |
| 3227 | typedef xmlSchemaValidCtxtPyCtxt *xmlSchemaValidCtxtPyCtxtPtr; |
| 3228 | |
| 3229 | static void |
| 3230 | libxml_xmlSchemaValidityGenericErrorFuncHandler(void *ctx, char *str) |
| 3231 | { |
| 3232 | PyObject *list; |
| 3233 | PyObject *result; |
| 3234 | xmlSchemaValidCtxtPyCtxtPtr pyCtxt; |
| 3235 | |
| 3236 | #ifdef DEBUG_ERROR |
| 3237 | printf("libxml_xmlSchemaValiditiyGenericErrorFuncHandler(%p, %s, ...) called\n", ctx, str); |
| 3238 | #endif |
| 3239 | |
| 3240 | pyCtxt = (xmlSchemaValidCtxtPyCtxtPtr) ctx; |
| 3241 | |
| 3242 | list = PyTuple_New(2); |
| 3243 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 3244 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 3245 | Py_XINCREF(pyCtxt->arg); |
| 3246 | result = PyEval_CallObject(pyCtxt->error, list); |
| 3247 | if (result == NULL) |
| 3248 | { |
| 3249 | /* TODO: manage for the exception to be propagated... */ |
| 3250 | PyErr_Print(); |
| 3251 | } |
| 3252 | Py_XDECREF(list); |
| 3253 | Py_XDECREF(result); |
| 3254 | } |
| 3255 | |
| 3256 | static void |
| 3257 | libxml_xmlSchemaValidityGenericWarningFuncHandler(void *ctx, char *str) |
| 3258 | { |
| 3259 | PyObject *list; |
| 3260 | PyObject *result; |
| 3261 | xmlSchemaValidCtxtPyCtxtPtr pyCtxt; |
| 3262 | |
| 3263 | #ifdef DEBUG_ERROR |
| 3264 | printf("libxml_xmlSchemaValidityGenericWarningFuncHandler(%p, %s, ...) called\n", ctx, str); |
| 3265 | #endif |
| 3266 | |
| 3267 | pyCtxt = (xmlSchemaValidCtxtPyCtxtPtr) ctx; |
| 3268 | |
| 3269 | list = PyTuple_New(2); |
| 3270 | PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); |
| 3271 | PyTuple_SetItem(list, 1, pyCtxt->arg); |
| 3272 | Py_XINCREF(pyCtxt->arg); |
| 3273 | result = PyEval_CallObject(pyCtxt->warn, list); |
| 3274 | if (result == NULL) |
| 3275 | { |
| 3276 | /* TODO: manage for the exception to be propagated... */ |
| 3277 | PyErr_Print(); |
| 3278 | } |
| 3279 | Py_XDECREF(list); |
| 3280 | Py_XDECREF(result); |
| 3281 | } |
| 3282 | |
| 3283 | static void |
| 3284 | libxml_xmlSchemaValidityErrorFunc(void *ctx, const char *msg, ...) |
| 3285 | { |
| 3286 | va_list ap; |
| 3287 | |
| 3288 | va_start(ap, msg); |
| 3289 | libxml_xmlSchemaValidityGenericErrorFuncHandler(ctx, libxml_buildMessage(msg, ap)); |
| 3290 | va_end(ap); |
| 3291 | } |
| 3292 | |
| 3293 | static void |
| 3294 | libxml_xmlSchemaValidityWarningFunc(void *ctx, const char *msg, ...) |
| 3295 | { |
| 3296 | va_list ap; |
| 3297 | |
| 3298 | va_start(ap, msg); |
| 3299 | libxml_xmlSchemaValidityGenericWarningFuncHandler(ctx, libxml_buildMessage(msg, ap)); |
| 3300 | va_end(ap); |
| 3301 | } |
| 3302 | |
Daniel Veillard | 6ebf3c4 | 2004-08-22 13:11:39 +0000 | [diff] [blame] | 3303 | PyObject * |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 3304 | libxml_xmlSchemaSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 3305 | { |
| 3306 | PyObject *py_retval; |
| 3307 | PyObject *pyobj_error; |
| 3308 | PyObject *pyobj_warn; |
| 3309 | PyObject *pyobj_ctx; |
| 3310 | PyObject *pyobj_arg = Py_None; |
| 3311 | xmlSchemaValidCtxtPtr ctxt; |
| 3312 | xmlSchemaValidCtxtPyCtxtPtr pyCtxt; |
| 3313 | |
| 3314 | if (!PyArg_ParseTuple |
| 3315 | (args, (char *) "OOO|O:xmlSchemaSetValidErrors", &pyobj_ctx, &pyobj_error, &pyobj_warn, &pyobj_arg)) |
| 3316 | return (NULL); |
| 3317 | |
| 3318 | #ifdef DEBUG_ERROR |
| 3319 | printf("libxml_xmlSchemaSetValidErrors(%p, %p, %p) called\n", pyobj_ctx, pyobj_error, pyobj_warn); |
| 3320 | #endif |
| 3321 | |
| 3322 | ctxt = PySchemaValidCtxt_Get(pyobj_ctx); |
| 3323 | if (xmlSchemaGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == -1) |
| 3324 | { |
| 3325 | py_retval = libxml_intWrap(-1); |
| 3326 | return(py_retval); |
| 3327 | } |
| 3328 | |
| 3329 | if (pyCtxt == NULL) |
| 3330 | { |
| 3331 | /* first time to set the error handlers */ |
| 3332 | pyCtxt = xmlMalloc(sizeof(xmlSchemaValidCtxtPyCtxt)); |
| 3333 | if (pyCtxt == NULL) { |
| 3334 | py_retval = libxml_intWrap(-1); |
| 3335 | return(py_retval); |
| 3336 | } |
| 3337 | memset(pyCtxt, 0, sizeof(xmlSchemaValidCtxtPyCtxt)); |
| 3338 | } |
| 3339 | |
| 3340 | /* TODO: check warn and error is a function ! */ |
| 3341 | Py_XDECREF(pyCtxt->error); |
| 3342 | Py_XINCREF(pyobj_error); |
| 3343 | pyCtxt->error = pyobj_error; |
| 3344 | |
| 3345 | Py_XDECREF(pyCtxt->warn); |
| 3346 | Py_XINCREF(pyobj_warn); |
| 3347 | pyCtxt->warn = pyobj_warn; |
| 3348 | |
| 3349 | Py_XDECREF(pyCtxt->arg); |
| 3350 | Py_XINCREF(pyobj_arg); |
| 3351 | pyCtxt->arg = pyobj_arg; |
| 3352 | |
| 3353 | xmlSchemaSetValidErrors(ctxt, &libxml_xmlSchemaValidityErrorFunc, &libxml_xmlSchemaValidityWarningFunc, pyCtxt); |
| 3354 | |
| 3355 | py_retval = libxml_intWrap(1); |
| 3356 | return(py_retval); |
| 3357 | } |
| 3358 | |
Daniel Veillard | bb8502c | 2005-03-30 07:40:35 +0000 | [diff] [blame] | 3359 | static PyObject * |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 3360 | libxml_xmlSchemaFreeValidCtxt(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) |
| 3361 | { |
| 3362 | xmlSchemaValidCtxtPtr ctxt; |
| 3363 | xmlSchemaValidCtxtPyCtxtPtr pyCtxt; |
| 3364 | PyObject *pyobj_ctxt; |
| 3365 | |
| 3366 | if (!PyArg_ParseTuple(args, (char *)"O:xmlSchemaFreeValidCtxt", &pyobj_ctxt)) |
| 3367 | return(NULL); |
| 3368 | ctxt = (xmlSchemaValidCtxtPtr) PySchemaValidCtxt_Get(pyobj_ctxt); |
| 3369 | |
| 3370 | if (xmlSchemaGetValidErrors(ctxt, NULL, NULL, (void **) &pyCtxt) == 0) |
| 3371 | { |
| 3372 | if (pyCtxt != NULL) |
| 3373 | { |
| 3374 | Py_XDECREF(pyCtxt->error); |
| 3375 | Py_XDECREF(pyCtxt->warn); |
| 3376 | Py_XDECREF(pyCtxt->arg); |
| 3377 | xmlFree(pyCtxt); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | xmlSchemaFreeValidCtxt(ctxt); |
| 3382 | Py_INCREF(Py_None); |
| 3383 | return(Py_None); |
| 3384 | } |
| 3385 | |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3386 | #endif |
| 3387 | |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 3388 | #ifdef LIBXML_C14N_ENABLED |
| 3389 | #ifdef LIBXML_OUTPUT_ENABLED |
| 3390 | |
| 3391 | /************************************************************************ |
| 3392 | * * |
| 3393 | * XML Canonicalization c14n * |
| 3394 | * * |
| 3395 | ************************************************************************/ |
| 3396 | |
| 3397 | static int |
| 3398 | PyxmlNodeSet_Convert(PyObject *py_nodeset, xmlNodeSetPtr *result) |
| 3399 | { |
| 3400 | xmlNodeSetPtr nodeSet; |
| 3401 | int is_tuple = 0; |
| 3402 | |
| 3403 | if (PyTuple_Check(py_nodeset)) |
| 3404 | is_tuple = 1; |
| 3405 | else if (PyList_Check(py_nodeset)) |
| 3406 | is_tuple = 0; |
| 3407 | else if (py_nodeset == Py_None) { |
| 3408 | *result = NULL; |
| 3409 | return 0; |
| 3410 | } |
| 3411 | else { |
| 3412 | PyErr_SetString(PyExc_TypeError, |
| 3413 | "must be a tuple or list of nodes."); |
| 3414 | return -1; |
| 3415 | } |
| 3416 | |
| 3417 | nodeSet = (xmlNodeSetPtr) xmlMalloc(sizeof(xmlNodeSet)); |
| 3418 | if (nodeSet == NULL) { |
| 3419 | PyErr_SetString(PyExc_MemoryError, ""); |
| 3420 | return -1; |
| 3421 | } |
| 3422 | |
| 3423 | nodeSet->nodeNr = 0; |
| 3424 | nodeSet->nodeMax = (is_tuple |
| 3425 | ? PyTuple_GET_SIZE(py_nodeset) |
| 3426 | : PyList_GET_SIZE(py_nodeset)); |
| 3427 | nodeSet->nodeTab |
| 3428 | = (xmlNodePtr *) xmlMalloc (nodeSet->nodeMax |
| 3429 | * sizeof(xmlNodePtr)); |
| 3430 | if (nodeSet->nodeTab == NULL) { |
| 3431 | xmlFree(nodeSet); |
| 3432 | PyErr_SetString(PyExc_MemoryError, ""); |
| 3433 | return -1; |
| 3434 | } |
| 3435 | memset(nodeSet->nodeTab, 0 , |
| 3436 | nodeSet->nodeMax * sizeof(xmlNodePtr)); |
| 3437 | |
| 3438 | { |
| 3439 | int idx; |
| 3440 | for (idx=0; idx < nodeSet->nodeMax; ++idx) { |
| 3441 | xmlNodePtr pynode = |
| 3442 | PyxmlNode_Get (is_tuple |
| 3443 | ? PyTuple_GET_ITEM(py_nodeset, idx) |
| 3444 | : PyList_GET_ITEM(py_nodeset, idx)); |
| 3445 | if (pynode) |
| 3446 | nodeSet->nodeTab[nodeSet->nodeNr++] = pynode; |
| 3447 | } |
| 3448 | } |
| 3449 | *result = nodeSet; |
| 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | static int |
| 3454 | PystringSet_Convert(PyObject *py_strings, xmlChar *** result) |
| 3455 | { |
| 3456 | /* NOTE: the array should be freed, but the strings are shared |
| 3457 | with the python strings and so must not be freed. */ |
| 3458 | |
| 3459 | xmlChar ** strings; |
| 3460 | int is_tuple = 0; |
| 3461 | int count; |
| 3462 | int init_index = 0; |
| 3463 | |
| 3464 | if (PyTuple_Check(py_strings)) |
| 3465 | is_tuple = 1; |
| 3466 | else if (PyList_Check(py_strings)) |
| 3467 | is_tuple = 0; |
| 3468 | else if (py_strings == Py_None) { |
| 3469 | *result = NULL; |
| 3470 | return 0; |
| 3471 | } |
| 3472 | else { |
| 3473 | PyErr_SetString(PyExc_TypeError, |
| 3474 | "must be a tuple or list of strings."); |
| 3475 | return -1; |
| 3476 | } |
| 3477 | |
| 3478 | count = (is_tuple |
| 3479 | ? PyTuple_GET_SIZE(py_strings) |
| 3480 | : PyList_GET_SIZE(py_strings)); |
| 3481 | |
| 3482 | strings = (xmlChar **) xmlMalloc(sizeof(xmlChar *) * count); |
| 3483 | |
| 3484 | if (strings == NULL) { |
| 3485 | PyErr_SetString(PyExc_MemoryError, ""); |
| 3486 | return -1; |
| 3487 | } |
| 3488 | |
| 3489 | memset(strings, 0 , sizeof(xmlChar *) * count); |
| 3490 | |
| 3491 | { |
| 3492 | int idx; |
| 3493 | for (idx=0; idx < count; ++idx) { |
| 3494 | char* s = PyString_AsString |
| 3495 | (is_tuple |
| 3496 | ? PyTuple_GET_ITEM(py_strings, idx) |
| 3497 | : PyList_GET_ITEM(py_strings, idx)); |
| 3498 | if (s) |
| 3499 | strings[init_index++] = (xmlChar *)s; |
| 3500 | else { |
| 3501 | xmlFree(strings); |
| 3502 | PyErr_SetString(PyExc_TypeError, |
| 3503 | "must be a tuple or list of strings."); |
| 3504 | return -1; |
| 3505 | } |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | *result = strings; |
| 3510 | return 0; |
| 3511 | } |
| 3512 | |
| 3513 | static PyObject * |
| 3514 | libxml_C14NDocDumpMemory(ATTRIBUTE_UNUSED PyObject * self, |
| 3515 | PyObject * args) |
| 3516 | { |
| 3517 | PyObject *py_retval = NULL; |
| 3518 | |
| 3519 | PyObject *pyobj_doc; |
| 3520 | PyObject *pyobj_nodes; |
| 3521 | int exclusive; |
| 3522 | PyObject *pyobj_prefixes; |
| 3523 | int with_comments; |
| 3524 | |
| 3525 | xmlDocPtr doc; |
| 3526 | xmlNodeSetPtr nodes; |
| 3527 | xmlChar **prefixes = NULL; |
| 3528 | xmlChar *doc_txt; |
| 3529 | |
| 3530 | int result; |
| 3531 | |
| 3532 | if (!PyArg_ParseTuple(args, (char *) "OOiOi:C14NDocDumpMemory", |
| 3533 | &pyobj_doc, |
| 3534 | &pyobj_nodes, |
| 3535 | &exclusive, |
| 3536 | &pyobj_prefixes, |
| 3537 | &with_comments)) |
| 3538 | return (NULL); |
| 3539 | |
| 3540 | doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc); |
| 3541 | if (!doc) { |
| 3542 | PyErr_SetString(PyExc_TypeError, "bad document."); |
| 3543 | return NULL; |
| 3544 | } |
| 3545 | |
| 3546 | result = PyxmlNodeSet_Convert(pyobj_nodes, &nodes); |
| 3547 | if (result < 0) return NULL; |
| 3548 | |
| 3549 | if (exclusive) { |
| 3550 | result = PystringSet_Convert(pyobj_prefixes, &prefixes); |
| 3551 | if (result < 0) { |
| 3552 | if (nodes) { |
| 3553 | xmlFree(nodes->nodeTab); |
| 3554 | xmlFree(nodes); |
| 3555 | } |
| 3556 | return NULL; |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | result = xmlC14NDocDumpMemory(doc, |
| 3561 | nodes, |
| 3562 | exclusive, |
| 3563 | prefixes, |
| 3564 | with_comments, |
| 3565 | &doc_txt); |
| 3566 | |
| 3567 | if (nodes) { |
| 3568 | xmlFree(nodes->nodeTab); |
| 3569 | xmlFree(nodes); |
| 3570 | } |
| 3571 | if (prefixes) { |
| 3572 | xmlChar ** idx = prefixes; |
| 3573 | while (*idx) xmlFree(*(idx++)); |
| 3574 | xmlFree(prefixes); |
| 3575 | } |
| 3576 | |
| 3577 | if (result < 0) { |
| 3578 | PyErr_SetString(PyExc_Exception, |
| 3579 | "libxml2 xmlC14NDocDumpMemory failure."); |
| 3580 | return NULL; |
| 3581 | } |
| 3582 | else { |
| 3583 | py_retval = PyString_FromStringAndSize((const char *) doc_txt, |
| 3584 | result); |
| 3585 | xmlFree(doc_txt); |
| 3586 | return py_retval; |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | static PyObject * |
| 3591 | libxml_C14NDocSaveTo(ATTRIBUTE_UNUSED PyObject * self, |
| 3592 | PyObject * args) |
| 3593 | { |
| 3594 | PyObject *pyobj_doc; |
| 3595 | PyObject *py_file; |
| 3596 | PyObject *pyobj_nodes; |
| 3597 | int exclusive; |
| 3598 | PyObject *pyobj_prefixes; |
| 3599 | int with_comments; |
| 3600 | |
| 3601 | xmlDocPtr doc; |
| 3602 | xmlNodeSetPtr nodes; |
| 3603 | xmlChar **prefixes = NULL; |
| 3604 | FILE * output; |
| 3605 | xmlOutputBufferPtr buf; |
| 3606 | |
| 3607 | int result; |
| 3608 | int len; |
| 3609 | |
| 3610 | if (!PyArg_ParseTuple(args, (char *) "OOiOiO:C14NDocSaveTo", |
| 3611 | &pyobj_doc, |
| 3612 | &pyobj_nodes, |
| 3613 | &exclusive, |
| 3614 | &pyobj_prefixes, |
| 3615 | &with_comments, |
| 3616 | &py_file)) |
| 3617 | return (NULL); |
| 3618 | |
| 3619 | doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc); |
| 3620 | if (!doc) { |
| 3621 | PyErr_SetString(PyExc_TypeError, "bad document."); |
| 3622 | return NULL; |
| 3623 | } |
| 3624 | |
| 3625 | if ((py_file == NULL) || (!(PyFile_Check(py_file)))) { |
| 3626 | PyErr_SetString(PyExc_TypeError, "bad file."); |
| 3627 | return NULL; |
| 3628 | } |
| 3629 | output = PyFile_AsFile(py_file); |
| 3630 | if (output == NULL) { |
| 3631 | PyErr_SetString(PyExc_TypeError, "bad file."); |
| 3632 | return NULL; |
| 3633 | } |
| 3634 | buf = xmlOutputBufferCreateFile(output, NULL); |
| 3635 | |
| 3636 | result = PyxmlNodeSet_Convert(pyobj_nodes, &nodes); |
| 3637 | if (result < 0) return NULL; |
| 3638 | |
| 3639 | if (exclusive) { |
| 3640 | result = PystringSet_Convert(pyobj_prefixes, &prefixes); |
| 3641 | if (result < 0) { |
| 3642 | if (nodes) { |
| 3643 | xmlFree(nodes->nodeTab); |
| 3644 | xmlFree(nodes); |
| 3645 | } |
| 3646 | return NULL; |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | result = xmlC14NDocSaveTo(doc, |
| 3651 | nodes, |
| 3652 | exclusive, |
| 3653 | prefixes, |
| 3654 | with_comments, |
| 3655 | buf); |
| 3656 | |
| 3657 | if (nodes) { |
| 3658 | xmlFree(nodes->nodeTab); |
| 3659 | xmlFree(nodes); |
| 3660 | } |
| 3661 | if (prefixes) { |
| 3662 | xmlChar ** idx = prefixes; |
| 3663 | while (*idx) xmlFree(*(idx++)); |
| 3664 | xmlFree(prefixes); |
| 3665 | } |
| 3666 | |
| 3667 | len = xmlOutputBufferClose(buf); |
| 3668 | |
| 3669 | if (result < 0) { |
| 3670 | PyErr_SetString(PyExc_Exception, |
| 3671 | "libxml2 xmlC14NDocSaveTo failure."); |
| 3672 | return NULL; |
| 3673 | } |
| 3674 | else |
| 3675 | return PyInt_FromLong((long) len); |
| 3676 | } |
| 3677 | |
| 3678 | #endif |
| 3679 | #endif |
| 3680 | |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 3681 | static PyObject * |
| 3682 | libxml_getObjDesc(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 3683 | |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 3684 | PyObject *obj; |
| 3685 | char *str; |
| 3686 | |
| 3687 | if (!PyArg_ParseTuple(args, (char *)"O:getObjDesc", &obj)) |
| 3688 | return NULL; |
| 3689 | str = PyCObject_GetDesc(obj); |
| 3690 | return Py_BuildValue((char *)"s", str); |
| 3691 | } |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 3692 | |
William M. Brack | 40cca61 | 2006-06-26 18:25:40 +0000 | [diff] [blame] | 3693 | static PyObject * |
| 3694 | libxml_compareNodesEqual(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 3695 | |
| 3696 | PyObject *py_node1, *py_node2; |
| 3697 | xmlNodePtr node1, node2; |
| 3698 | |
| 3699 | if (!PyArg_ParseTuple(args, (char *)"OO:compareNodesEqual", |
| 3700 | &py_node1, &py_node2)) |
| 3701 | return NULL; |
| 3702 | /* To compare two node objects, we compare their pointer addresses */ |
| 3703 | node1 = PyxmlNode_Get(py_node1); |
| 3704 | node2 = PyxmlNode_Get(py_node2); |
| 3705 | if ( node1 == node2 ) |
| 3706 | return Py_BuildValue((char *)"i", 1); |
| 3707 | else |
| 3708 | return Py_BuildValue((char *)"i", 0); |
| 3709 | |
| 3710 | } |
| 3711 | |
| 3712 | static PyObject * |
| 3713 | libxml_nodeHash(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { |
| 3714 | |
| 3715 | PyObject *py_node1; |
| 3716 | xmlNodePtr node1; |
| 3717 | |
| 3718 | if (!PyArg_ParseTuple(args, (char *)"O:nodeHash", &py_node1)) |
| 3719 | return NULL; |
| 3720 | /* For simplicity, we use the node pointer address as a hash value */ |
| 3721 | node1 = PyxmlNode_Get(py_node1); |
| 3722 | |
| 3723 | return PyLong_FromVoidPtr(node1); |
| 3724 | |
| 3725 | } |
| 3726 | |
Daniel Veillard | a94ec6f | 2002-03-01 13:00:53 +0000 | [diff] [blame] | 3727 | /************************************************************************ |
| 3728 | * * |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 3729 | * The registration stuff * |
| 3730 | * * |
| 3731 | ************************************************************************/ |
| 3732 | static PyMethodDef libxmlMethods[] = { |
Daniel Veillard | 96fe095 | 2002-01-30 20:52:23 +0000 | [diff] [blame] | 3733 | #include "libxml2-export.c" |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3734 | {(char *) "name", libxml_name, METH_VARARGS, NULL}, |
| 3735 | {(char *) "children", libxml_children, METH_VARARGS, NULL}, |
| 3736 | {(char *) "properties", libxml_properties, METH_VARARGS, NULL}, |
| 3737 | {(char *) "last", libxml_last, METH_VARARGS, NULL}, |
| 3738 | {(char *) "prev", libxml_prev, METH_VARARGS, NULL}, |
| 3739 | {(char *) "next", libxml_next, METH_VARARGS, NULL}, |
| 3740 | {(char *) "parent", libxml_parent, METH_VARARGS, NULL}, |
| 3741 | {(char *) "type", libxml_type, METH_VARARGS, NULL}, |
| 3742 | {(char *) "doc", libxml_doc, METH_VARARGS, NULL}, |
| 3743 | {(char *) "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL}, |
Daniel Veillard | f9cf6f5 | 2005-04-12 01:02:29 +0000 | [diff] [blame] | 3744 | {(char *) "xmlNodeRemoveNsDef", libxml_xmlNodeRemoveNsDef, METH_VARARGS, NULL}, |
Daniel Veillard | 850ce9b | 2004-11-10 11:55:47 +0000 | [diff] [blame] | 3745 | {(char *)"xmlSetValidErrors", libxml_xmlSetValidErrors, METH_VARARGS, NULL}, |
Daniel Veillard | 25c90c5 | 2005-03-02 10:47:41 +0000 | [diff] [blame] | 3746 | {(char *)"xmlFreeValidCtxt", libxml_xmlFreeValidCtxt, METH_VARARGS, NULL}, |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3747 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3748 | {(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL}, |
| 3749 | {(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL}, |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 3750 | {(char *) "outputBufferCreate", libxml_xmlCreateOutputBuffer, METH_VARARGS, NULL}, |
Daniel Veillard | 6cbd6c0 | 2003-12-04 12:31:49 +0000 | [diff] [blame] | 3751 | {(char *) "outputBufferGetPythonFile", libxml_outputBufferGetPythonFile, METH_VARARGS, NULL}, |
| 3752 | {(char *) "xmlOutputBufferClose", libxml_xmlOutputBufferClose, METH_VARARGS, NULL}, |
| 3753 | { (char *)"xmlOutputBufferFlush", libxml_xmlOutputBufferFlush, METH_VARARGS, NULL }, |
Daniel Veillard | 263ec86 | 2004-10-04 10:26:54 +0000 | [diff] [blame] | 3754 | { (char *)"xmlSaveFileTo", libxml_xmlSaveFileTo, METH_VARARGS, NULL }, |
| 3755 | { (char *)"xmlSaveFormatFileTo", libxml_xmlSaveFormatFileTo, METH_VARARGS, NULL }, |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3756 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | c6d4a93 | 2002-09-12 15:00:57 +0000 | [diff] [blame] | 3757 | {(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL}, |
| 3758 | {(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL}, |
Daniel Veillard | 3e20a29 | 2003-01-10 13:14:40 +0000 | [diff] [blame] | 3759 | {(char *)"xmlRegisterErrorHandler", libxml_xmlRegisterErrorHandler, METH_VARARGS, NULL }, |
Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3760 | {(char *)"xmlParserCtxtSetErrorHandler", libxml_xmlParserCtxtSetErrorHandler, METH_VARARGS, NULL }, |
| 3761 | {(char *)"xmlParserCtxtGetErrorHandler", libxml_xmlParserCtxtGetErrorHandler, METH_VARARGS, NULL }, |
Daniel Veillard | e6227e0 | 2003-01-14 11:42:39 +0000 | [diff] [blame] | 3762 | {(char *)"xmlFreeParserCtxt", libxml_xmlFreeParserCtxt, METH_VARARGS, NULL }, |
Daniel Veillard | 438ebbd | 2008-05-12 12:58:46 +0000 | [diff] [blame] | 3763 | #ifdef LIBXML_READER_ENABLED |
Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3764 | {(char *)"xmlTextReaderSetErrorHandler", libxml_xmlTextReaderSetErrorHandler, METH_VARARGS, NULL }, |
| 3765 | {(char *)"xmlTextReaderGetErrorHandler", libxml_xmlTextReaderGetErrorHandler, METH_VARARGS, NULL }, |
| 3766 | {(char *)"xmlFreeTextReader", libxml_xmlFreeTextReader, METH_VARARGS, NULL }, |
Daniel Veillard | 438ebbd | 2008-05-12 12:58:46 +0000 | [diff] [blame] | 3767 | #endif |
Daniel Veillard | 5439624 | 2003-04-23 07:36:50 +0000 | [diff] [blame] | 3768 | {(char *)"addLocalCatalog", libxml_addLocalCatalog, METH_VARARGS, NULL }, |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3769 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 3770 | {(char *)"xmlRelaxNGSetValidErrors", libxml_xmlRelaxNGSetValidErrors, METH_VARARGS, NULL}, |
| 3771 | {(char *)"xmlRelaxNGFreeValidCtxt", libxml_xmlRelaxNGFreeValidCtxt, METH_VARARGS, NULL}, |
Daniel Veillard | eff45a9 | 2004-10-29 12:10:55 +0000 | [diff] [blame] | 3772 | {(char *)"xmlSchemaSetValidErrors", libxml_xmlSchemaSetValidErrors, METH_VARARGS, NULL}, |
Daniel Veillard | bb8502c | 2005-03-30 07:40:35 +0000 | [diff] [blame] | 3773 | {(char *)"xmlSchemaFreeValidCtxt", libxml_xmlSchemaFreeValidCtxt, METH_VARARGS, NULL}, |
Daniel Veillard | c266464 | 2003-07-29 20:44:53 +0000 | [diff] [blame] | 3774 | #endif |
Daniel Veillard | d5e198a | 2004-03-09 09:03:28 +0000 | [diff] [blame] | 3775 | #ifdef LIBXML_C14N_ENABLED |
| 3776 | #ifdef LIBXML_OUTPUT_ENABLED |
| 3777 | {(char *)"xmlC14NDocDumpMemory", libxml_C14NDocDumpMemory, METH_VARARGS, NULL}, |
| 3778 | {(char *)"xmlC14NDocSaveTo", libxml_C14NDocSaveTo, METH_VARARGS, NULL}, |
| 3779 | #endif |
| 3780 | #endif |
William M. Brack | c68d78d | 2004-07-16 10:39:30 +0000 | [diff] [blame] | 3781 | {(char *) "getObjDesc", libxml_getObjDesc, METH_VARARGS, NULL}, |
William M. Brack | 40cca61 | 2006-06-26 18:25:40 +0000 | [diff] [blame] | 3782 | {(char *) "compareNodesEqual", libxml_compareNodesEqual, METH_VARARGS, NULL}, |
| 3783 | {(char *) "nodeHash", libxml_nodeHash, METH_VARARGS, NULL}, |
Alexey Neyman | 48da90b | 2013-02-25 15:54:25 +0800 | [diff] [blame^] | 3784 | {(char *) "xmlRegisterInputCallback", libxml_xmlRegisterInputCallback, METH_VARARGS, NULL}, |
| 3785 | {(char *) "xmlUnregisterInputCallback", libxml_xmlUnregisterInputCallback, METH_VARARGS, NULL}, |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3786 | {NULL, NULL, 0, NULL} |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 3787 | }; |
| 3788 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 3789 | #ifdef MERGED_MODULES |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 3790 | extern void initlibxsltmod(void); |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 3791 | #endif |
| 3792 | |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3793 | void |
| 3794 | initlibxml2mod(void) |
| 3795 | { |
Daniel Veillard | af43f63 | 2002-03-08 15:05:20 +0000 | [diff] [blame] | 3796 | static int initialized = 0; |
Daniel Veillard | af43f63 | 2002-03-08 15:05:20 +0000 | [diff] [blame] | 3797 | |
| 3798 | if (initialized != 0) |
Daniel Veillard | d237901 | 2002-03-15 22:24:56 +0000 | [diff] [blame] | 3799 | return; |
William M. Brack | 8e2cc6f | 2004-07-03 23:28:52 +0000 | [diff] [blame] | 3800 | |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 3801 | /* intialize the python extension module */ |
| 3802 | Py_InitModule((char *) "libxml2mod", libxmlMethods); |
| 3803 | |
| 3804 | /* initialize libxml2 */ |
| 3805 | xmlInitParser(); |
Daniel Veillard | 5d81903 | 2002-02-02 21:49:17 +0000 | [diff] [blame] | 3806 | libxml_xmlErrorInitialize(); |
Daniel Veillard | 6361da0 | 2002-02-23 10:10:33 +0000 | [diff] [blame] | 3807 | |
Daniel Veillard | f93a866 | 2004-07-01 12:56:30 +0000 | [diff] [blame] | 3808 | initialized = 1; |
| 3809 | |
Daniel Veillard | 0fea6f4 | 2002-02-22 22:51:13 +0000 | [diff] [blame] | 3810 | #ifdef MERGED_MODULES |
| 3811 | initlibxsltmod(); |
| 3812 | #endif |
Daniel Veillard | d2897fd | 2002-01-30 16:37:32 +0000 | [diff] [blame] | 3813 | } |