From 9705f1a5e858108d21a0128556f42b25d16833cd Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 28 Oct 2004 09:07:41 +0000 Subject: Load /tmp/tmp.SgII7T/libxml2-2.6.15 into packages/libxml2/branches/upstream/current. --- python/Makefile.am | 3 +- python/Makefile.in | 4 +- python/generator.py | 10 ++ python/libxml.c | 89 ++++++++++++---- python/libxml2-py.c | 269 ++++++++++++++++++++++++++++++----------------- python/setup.py | 2 +- python/tests/Makefile.in | 1 + python/tests/outbuf.py | 116 ++++++++++++++++---- 8 files changed, 353 insertions(+), 141 deletions(-) (limited to 'python') diff --git a/python/Makefile.am b/python/Makefile.am index 27feef0..fa13310 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -5,7 +5,8 @@ SUBDIRS= . tests INCLUDES = \ -I$(PYTHON_INCLUDES) \ - -I$(top_srcdir)/include + -I$(top_srcdir)/include \ + -I$(top_builddir)/include DOCS_DIR = $(datadir)/doc/libxml2-python-$(LIBXML_VERSION) # libxml2class.txt is generated diff --git a/python/Makefile.in b/python/Makefile.in index a1054fc..28ced16 100644 --- a/python/Makefile.in +++ b/python/Makefile.in @@ -213,6 +213,7 @@ WITH_PYTHON_FALSE = @WITH_PYTHON_FALSE@ WITH_PYTHON_TRUE = @WITH_PYTHON_TRUE@ WITH_READER = @WITH_READER@ WITH_REGEXPS = @WITH_REGEXPS@ +WITH_RUN_DEBUG = @WITH_RUN_DEBUG@ WITH_SAX1 = @WITH_SAX1@ WITH_SCHEMAS = @WITH_SCHEMAS@ WITH_THREADS = @WITH_THREADS@ @@ -288,7 +289,8 @@ AUTOMAKE_OPTIONS = 1.4 foreign SUBDIRS = . tests INCLUDES = \ -I$(PYTHON_INCLUDES) \ - -I$(top_srcdir)/include + -I$(top_srcdir)/include \ + -I$(top_builddir)/include DOCS_DIR = $(datadir)/doc/libxml2-python-$(LIBXML_VERSION) # libxml2class.txt is generated diff --git a/python/generator.py b/python/generator.py index df89c4e..04b3832 100755 --- a/python/generator.py +++ b/python/generator.py @@ -300,6 +300,13 @@ unknown_types = {} # ####################################################################### +# Class methods which are written by hand in libxml.c but the Python-level +# code is still automatically generated (so they are not in skip_function()). +skip_impl = ( + 'xmlSaveFileTo', + 'xmlSaveFormatFileTo', +) + def skip_function(name): if name[0:12] == "xmlXPathWrap": return 1 @@ -356,6 +363,9 @@ def print_function_wrapper(name, output, export, include): return 0 if skip_function(name) == 1: return 0 + if name in skip_impl: + # Don't delete the function entry in the caller. + return 1 c_call = ""; format="" diff --git a/python/libxml.c b/python/libxml.c index 9e24314..bb2649a 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -512,6 +512,11 @@ libxml_xmlOutputBufferClose(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { if (!PyArg_ParseTuple(args, (char *)"O:xmlOutputBufferClose", &pyobj_out)) return(NULL); out = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_out); + /* Buffer may already have been destroyed elsewhere. This is harmless. */ + if (out == NULL) { + Py_INCREF(Py_None); + return(Py_None); + } c_retval = xmlOutputBufferClose(out); py_retval = libxml_intWrap((int) c_retval); @@ -533,6 +538,53 @@ libxml_xmlOutputBufferFlush(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { py_retval = libxml_intWrap((int) c_retval); return(py_retval); } + +static PyObject * +libxml_xmlSaveFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + xmlOutputBufferPtr buf; + PyObject *pyobj_buf; + xmlDocPtr cur; + PyObject *pyobj_cur; + char * encoding; + + if (!PyArg_ParseTuple(args, (char *)"OOz:xmlSaveFileTo", &pyobj_buf, &pyobj_cur, &encoding)) + return(NULL); + buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); + cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); + + c_retval = xmlSaveFileTo(buf, cur, encoding); + /* xmlSaveTo() freed the memory pointed to by buf, so record that in the + * Python object. */ + ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL; + py_retval = libxml_intWrap((int) c_retval); + return(py_retval); +} + +static PyObject * +libxml_xmlSaveFormatFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + xmlOutputBufferPtr buf; + PyObject *pyobj_buf; + xmlDocPtr cur; + PyObject *pyobj_cur; + char * encoding; + int format; + + if (!PyArg_ParseTuple(args, (char *)"OOzi:xmlSaveFormatFileTo", &pyobj_buf, &pyobj_cur, &encoding, &format)) + return(NULL); + buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); + cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); + + c_retval = xmlSaveFormatFileTo(buf, cur, encoding, format); + /* xmlSaveFormatFileTo() freed the memory pointed to by buf, so record that + * in the Python object */ + ((PyoutputBuffer_Object *)(pyobj_buf))->obj = NULL; + py_retval = libxml_intWrap((int) c_retval); + return(py_retval); +} #endif /* LIBXML_OUTPUT_ENABLED */ @@ -1375,34 +1427,24 @@ static PyObject *libxml_xmlPythonErrorFuncHandler = NULL; static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL; /* helper to build a xmlMalloc'ed string from a format and va_list */ +/* + * disabled the loop, the repeated call to vsnprintf without reset of ap + * in case the initial buffer was too small segfaulted on x86_64 + * we now directly vsnprintf on a large buffer. + */ static char * libxml_buildMessage(const char *msg, va_list ap) { - int size; int chars; - char *larger; char *str; - str = (char *) xmlMalloc(150); + str = (char *) xmlMalloc(1000); if (str == NULL) return NULL; - size = 150; - - while (1) { - chars = vsnprintf(str, size, msg, ap); - if ((chars > -1) && (chars < size)) - break; - if (chars > -1) - size += chars + 1; - else - size += 100; - if ((larger = (char *) xmlRealloc(str, size)) == NULL) { - xmlFree(str); - return NULL; - } - str = larger; - } + chars = vsnprintf(str, 999, msg, ap); + if (chars >= 998) + str[999] = 0; return str; } @@ -1412,10 +1454,10 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...) { va_list ap; - char *str; PyObject *list; PyObject *message; PyObject *result; + char str[1000]; #ifdef DEBUG_ERROR printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg); @@ -1428,13 +1470,14 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, va_end(ap); } else { va_start(ap, msg); - str = libxml_buildMessage(msg,ap); + if (vsnprintf(str, 999, msg, ap) >= 998) + str[999] = 0; va_end(ap); list = PyTuple_New(2); PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt); Py_XINCREF(libxml_xmlPythonErrorFuncCtxt); - message = libxml_charPtrWrap(str); + message = libxml_charPtrConstWrap(str); PyTuple_SetItem(list, 1, message); result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list); Py_XDECREF(list); @@ -3446,6 +3489,8 @@ static PyMethodDef libxmlMethods[] = { {(char *) "outputBufferGetPythonFile", libxml_outputBufferGetPythonFile, METH_VARARGS, NULL}, {(char *) "xmlOutputBufferClose", libxml_xmlOutputBufferClose, METH_VARARGS, NULL}, { (char *)"xmlOutputBufferFlush", libxml_xmlOutputBufferFlush, METH_VARARGS, NULL }, + { (char *)"xmlSaveFileTo", libxml_xmlSaveFileTo, METH_VARARGS, NULL }, + { (char *)"xmlSaveFormatFileTo", libxml_xmlSaveFormatFileTo, METH_VARARGS, NULL }, #endif /* LIBXML_OUTPUT_ENABLED */ {(char *) "inputBufferCreate", libxml_xmlCreateInputBuffer, METH_VARARGS, NULL}, {(char *) "setEntityLoader", libxml_xmlSetEntityLoader, METH_VARARGS, NULL}, diff --git a/python/libxml2-py.c b/python/libxml2-py.c index 1a4ba1d..e67f193 100644 --- a/python/libxml2-py.c +++ b/python/libxml2-py.c @@ -1637,6 +1637,22 @@ libxml_htmlCreateFileParserCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) } #endif /* LIBXML_HTML_ENABLED */ +PyObject * +libxml_xmlTextReaderConstEncoding(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + const xmlChar * c_retval; + xmlTextReaderPtr reader; + PyObject *pyobj_reader; + + if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderConstEncoding", &pyobj_reader)) + return(NULL); + reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); + + c_retval = xmlTextReaderConstEncoding(reader); + py_retval = libxml_xmlCharPtrConstWrap((const xmlChar *) c_retval); + return(py_retval); +} + PyObject * libxml_xmlHasNsProp(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -1855,6 +1871,22 @@ libxml_xmlNormalizeURIPath(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +PyObject * +libxml_xmlTextReaderConstXmlVersion(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + const xmlChar * c_retval; + xmlTextReaderPtr reader; + PyObject *pyobj_reader; + + if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderConstXmlVersion", &pyobj_reader)) + return(NULL); + reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); + + c_retval = xmlTextReaderConstXmlVersion(reader); + py_retval = libxml_xmlCharPtrConstWrap((const xmlChar *) c_retval); + return(py_retval); +} + PyObject * libxml_xmlUCSIsCombiningDiacriticalMarksforSymbols(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -2918,6 +2950,25 @@ libxml_xmlSaveFile(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +PyObject * +libxml_xmlDocCopyNodeList(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + xmlNodePtr c_retval; + xmlDocPtr doc; + PyObject *pyobj_doc; + xmlNodePtr node; + PyObject *pyobj_node; + + if (!PyArg_ParseTuple(args, (char *)"OO:xmlDocCopyNodeList", &pyobj_doc, &pyobj_node)) + return(NULL); + doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc); + node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); + + c_retval = xmlDocCopyNodeList(doc, node); + py_retval = libxml_xmlNodePtrWrap((xmlNodePtr) c_retval); + return(py_retval); +} + #ifdef LIBXML_XPATH_ENABLED PyObject * libxml_xmlXPathNextNamespace(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -3344,22 +3395,26 @@ libxml_xmlValidateName(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } -#ifdef LIBXML_XPATH_ENABLED +#ifdef LIBXML_HTML_ENABLED PyObject * -libxml_xmlXPathFreeContext(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - xmlXPathContextPtr ctxt; - PyObject *pyobj_ctxt; +libxml_htmlReadMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + htmlDocPtr c_retval; + char * buffer; + int size; + char * URL; + char * encoding; + int options; - if (!PyArg_ParseTuple(args, (char *)"O:xmlXPathFreeContext", &pyobj_ctxt)) + if (!PyArg_ParseTuple(args, (char *)"zizzi:htmlReadMemory", &buffer, &size, &URL, &encoding, &options)) return(NULL); - ctxt = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctxt); - xmlXPathFreeContext(ctxt); - Py_INCREF(Py_None); - return(Py_None); + c_retval = htmlReadMemory(buffer, size, URL, encoding, options); + py_retval = libxml_xmlDocPtrWrap((xmlDocPtr) c_retval); + return(py_retval); } -#endif /* LIBXML_XPATH_ENABLED */ +#endif /* LIBXML_HTML_ENABLED */ PyObject * libxml_xmlURIGetAuthority(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -4962,6 +5017,20 @@ libxml_xmlSchemaParse(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } #endif /* LIBXML_SCHEMAS_ENABLED */ +PyObject * +libxml_xmlThrDefDefaultBufferSize(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + int v; + + if (!PyArg_ParseTuple(args, (char *)"i:xmlThrDefDefaultBufferSize", &v)) + return(NULL); + + c_retval = xmlThrDefDefaultBufferSize(v); + py_retval = libxml_intWrap((int) c_retval); + return(py_retval); +} + PyObject * libxml_xmlTextReaderReadState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -5434,6 +5503,24 @@ libxml_xmlAddEncodingAlias(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +PyObject * +libxml_xmlNewDocPI(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + xmlNodePtr c_retval; + xmlDocPtr doc; + PyObject *pyobj_doc; + xmlChar * name; + xmlChar * content; + + if (!PyArg_ParseTuple(args, (char *)"Ozz:xmlNewDocPI", &pyobj_doc, &name, &content)) + return(NULL); + doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc); + + c_retval = xmlNewDocPI(doc, name, content); + py_retval = libxml_xmlNodePtrWrap((xmlNodePtr) c_retval); + return(py_retval); +} + PyObject * libxml_xmlUCSIsCatPc(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -7556,26 +7643,22 @@ libxml_xmlUCSIsCatLl(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } -#ifdef LIBXML_HTML_ENABLED +#ifdef LIBXML_XPATH_ENABLED PyObject * -libxml_htmlReadMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - PyObject *py_retval; - htmlDocPtr c_retval; - char * buffer; - int size; - char * URL; - char * encoding; - int options; +libxml_xmlXPathFreeContext(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + xmlXPathContextPtr ctxt; + PyObject *pyobj_ctxt; - if (!PyArg_ParseTuple(args, (char *)"zizzi:htmlReadMemory", &buffer, &size, &URL, &encoding, &options)) + if (!PyArg_ParseTuple(args, (char *)"O:xmlXPathFreeContext", &pyobj_ctxt)) return(NULL); + ctxt = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctxt); - c_retval = htmlReadMemory(buffer, size, URL, encoding, options); - py_retval = libxml_xmlDocPtrWrap((xmlDocPtr) c_retval); - return(py_retval); + xmlXPathFreeContext(ctxt); + Py_INCREF(Py_None); + return(Py_None); } -#endif /* LIBXML_HTML_ENABLED */ +#endif /* LIBXML_XPATH_ENABLED */ PyObject * libxml_xmlUCSIsCypriotSyllabary(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -8223,21 +8306,27 @@ libxml_xmlLoadCatalog(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +#ifdef LIBXML_DEBUG_ENABLED PyObject * -libxml_xmlParserSetLoadSubset(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - xmlParserCtxtPtr ctxt; - PyObject *pyobj_ctxt; - int loadsubset; +libxml_xmlDebugCheckDocument(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + FILE * output; + PyObject *pyobj_output; + xmlDocPtr doc; + PyObject *pyobj_doc; - if (!PyArg_ParseTuple(args, (char *)"Oi:xmlParserSetLoadSubset", &pyobj_ctxt, &loadsubset)) + if (!PyArg_ParseTuple(args, (char *)"OO:xmlDebugCheckDocument", &pyobj_output, &pyobj_doc)) return(NULL); - ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); + output = (FILE *) PyFile_Get(pyobj_output); + doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc); - ctxt->loadsubset = loadsubset; - Py_INCREF(Py_None); - return(Py_None); + c_retval = xmlDebugCheckDocument(output, doc); + py_retval = libxml_intWrap((int) c_retval); + return(py_retval); } +#endif /* LIBXML_DEBUG_ENABLED */ PyObject * libxml_xmlURIGetScheme(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -8545,24 +8634,20 @@ libxml_xmlTextReaderConstXmlLang(PyObject *self ATTRIBUTE_UNUSED, PyObject *args return(py_retval); } -#ifdef LIBXML_SCHEMAS_ENABLED PyObject * -libxml_xmlSchemaNewValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { +libxml_xmlUCSIsCherokee(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - xmlSchemaValidCtxtPtr c_retval; - xmlSchemaPtr schema; - PyObject *pyobj_schema; + int c_retval; + int code; - if (!PyArg_ParseTuple(args, (char *)"O:xmlSchemaNewValidCtxt", &pyobj_schema)) + if (!PyArg_ParseTuple(args, (char *)"i:xmlUCSIsCherokee", &code)) return(NULL); - schema = (xmlSchemaPtr) PySchema_Get(pyobj_schema); - c_retval = xmlSchemaNewValidCtxt(schema); - py_retval = libxml_xmlSchemaValidCtxtPtrWrap((xmlSchemaValidCtxtPtr) c_retval); + c_retval = xmlUCSIsCherokee(code); + py_retval = libxml_intWrap((int) c_retval); return(py_retval); } -#endif /* LIBXML_SCHEMAS_ENABLED */ PyObject * libxml_xmlUCSIsKhmer(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -9413,15 +9498,17 @@ libxml_xmlXPathNewCString(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { #endif /* LIBXML_XPATH_ENABLED */ PyObject * -libxml_xmlThrDefDefaultBufferSize(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { +libxml_xmlTextReaderIsNamespaceDecl(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; int c_retval; - int v; + xmlTextReaderPtr reader; + PyObject *pyobj_reader; - if (!PyArg_ParseTuple(args, (char *)"i:xmlThrDefDefaultBufferSize", &v)) + if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderIsNamespaceDecl", &pyobj_reader)) return(NULL); + reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); - c_retval = xmlThrDefDefaultBufferSize(v); + c_retval = xmlTextReaderIsNamespaceDecl(reader); py_retval = libxml_intWrap((int) c_retval); return(py_retval); } @@ -10264,26 +10351,6 @@ libxml_xmlInitParser(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_U return(Py_None); } -PyObject * -libxml_xmlSaveFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - PyObject *py_retval; - int c_retval; - xmlOutputBufferPtr buf; - PyObject *pyobj_buf; - xmlDocPtr cur; - PyObject *pyobj_cur; - char * encoding; - - if (!PyArg_ParseTuple(args, (char *)"OOz:xmlSaveFileTo", &pyobj_buf, &pyobj_cur, &encoding)) - return(NULL); - buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); - cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); - - c_retval = xmlSaveFileTo(buf, cur, encoding); - py_retval = libxml_intWrap((int) c_retval); - return(py_retval); -} - #ifdef LIBXML_XPATH_ENABLED PyObject * libxml_xmlXPathStartsWithFunction(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -10651,6 +10718,21 @@ libxml_xmlRelaxParserSetFlag(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } #endif /* LIBXML_SCHEMAS_ENABLED */ +PyObject * +libxml_xmlParserSetLoadSubset(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + xmlParserCtxtPtr ctxt; + PyObject *pyobj_ctxt; + int loadsubset; + + if (!PyArg_ParseTuple(args, (char *)"Oi:xmlParserSetLoadSubset", &pyobj_ctxt, &loadsubset)) + return(NULL); + ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); + + ctxt->loadsubset = loadsubset; + Py_INCREF(Py_None); + return(Py_None); +} + PyObject * libxml_xmlParseURI(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -11420,6 +11502,22 @@ libxml_xmlIsMixedElement(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +PyObject * +libxml_xmlTextReaderStandalone(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + xmlTextReaderPtr reader; + PyObject *pyobj_reader; + + if (!PyArg_ParseTuple(args, (char *)"O:xmlTextReaderStandalone", &pyobj_reader)) + return(NULL); + reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader); + + c_retval = xmlTextReaderStandalone(reader); + py_retval = libxml_intWrap((int) c_retval); + return(py_retval); +} + PyObject * libxml_xmlUCSIsMiscellaneousSymbolsandArrows(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -11794,27 +11892,6 @@ libxml_xmlNodeSetName(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(Py_None); } -PyObject * -libxml_xmlSaveFormatFileTo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - PyObject *py_retval; - int c_retval; - xmlOutputBufferPtr buf; - PyObject *pyobj_buf; - xmlDocPtr cur; - PyObject *pyobj_cur; - char * encoding; - int format; - - if (!PyArg_ParseTuple(args, (char *)"OOzi:xmlSaveFormatFileTo", &pyobj_buf, &pyobj_cur, &encoding, &format)) - return(NULL); - buf = (xmlOutputBufferPtr) PyoutputBuffer_Get(pyobj_buf); - cur = (xmlDocPtr) PyxmlNode_Get(pyobj_cur); - - c_retval = xmlSaveFormatFileTo(buf, cur, encoding, format); - py_retval = libxml_intWrap((int) c_retval); - return(py_retval); -} - PyObject * libxml_xmlUCSIsYiRadicals(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; @@ -12270,20 +12347,24 @@ libxml_xmlTextReaderIsEmptyElement(PyObject *self ATTRIBUTE_UNUSED, PyObject *ar return(py_retval); } +#ifdef LIBXML_SCHEMAS_ENABLED PyObject * -libxml_xmlUCSIsCherokee(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { +libxml_xmlSchemaNewValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - int c_retval; - int code; + xmlSchemaValidCtxtPtr c_retval; + xmlSchemaPtr schema; + PyObject *pyobj_schema; - if (!PyArg_ParseTuple(args, (char *)"i:xmlUCSIsCherokee", &code)) + if (!PyArg_ParseTuple(args, (char *)"O:xmlSchemaNewValidCtxt", &pyobj_schema)) return(NULL); + schema = (xmlSchemaPtr) PySchema_Get(pyobj_schema); - c_retval = xmlUCSIsCherokee(code); - py_retval = libxml_intWrap((int) c_retval); + c_retval = xmlSchemaNewValidCtxt(schema); + py_retval = libxml_xmlSchemaValidCtxtPtrWrap((xmlSchemaValidCtxtPtr) c_retval); return(py_retval); } +#endif /* LIBXML_SCHEMAS_ENABLED */ PyObject * libxml_xmlErrorGetLevel(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; diff --git a/python/setup.py b/python/setup.py index 6d9d1c6..e8bd1ae 100755 --- a/python/setup.py +++ b/python/setup.py @@ -226,7 +226,7 @@ else: setup (name = "libxml2-python", # On *nix, the version number is created from setup.py.in # On windows, it is set by configure.js - version = "2.6.14", + version = "2.6.15", description = descr, author = "Daniel Veillard", author_email = "veillard@redhat.com", diff --git a/python/tests/Makefile.in b/python/tests/Makefile.in index 3084356..3b55268 100644 --- a/python/tests/Makefile.in +++ b/python/tests/Makefile.in @@ -178,6 +178,7 @@ WITH_PYTHON_FALSE = @WITH_PYTHON_FALSE@ WITH_PYTHON_TRUE = @WITH_PYTHON_TRUE@ WITH_READER = @WITH_READER@ WITH_REGEXPS = @WITH_REGEXPS@ +WITH_RUN_DEBUG = @WITH_RUN_DEBUG@ WITH_SAX1 = @WITH_SAX1@ WITH_SCHEMAS = @WITH_SCHEMAS@ WITH_THREADS = @WITH_THREADS@ diff --git a/python/tests/outbuf.py b/python/tests/outbuf.py index 4213159..09cd9b5 100755 --- a/python/tests/outbuf.py +++ b/python/tests/outbuf.py @@ -3,31 +3,103 @@ import sys import libxml2 import StringIO -#print "Skipped" -#sys.exit(1) +def testSimpleBufferWrites(): + f = StringIO.StringIO() + buf = libxml2.createOutputBuffer(f, "ISO-8859-1") + buf.write(3, "foo") + buf.writeString("bar") + buf.close() + + if f.getvalue() != "foobar": + print "Failed to save to StringIO" + sys.exit(1) -# Memory debug specific -libxml2.debugMemory(1) +def testSaveDocToBuffer(): + """ + Regression test for bug #154294. + """ + input = 'Hello' + expected = '''\ + +Hello +''' + f = StringIO.StringIO() + buf = libxml2.createOutputBuffer(f, 'UTF-8') + doc = libxml2.parseDoc(input) + doc.saveFileTo(buf, 'UTF-8') + doc.freeDoc() + if f.getvalue() != expected: + print 'xmlDoc.saveFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) + sys.exit(1) -#f = open('res', 'w') -f = StringIO.StringIO() -buf = libxml2.createOutputBuffer(f, "ISO-8859-1") -buf.write(3, "foo") -buf.writeString("bar") -buf.close() +def testSaveFormattedDocToBuffer(): + input = 'Some text' + # The formatted and non-formatted versions of the output. + expected = ('''\ + +Some text +''', '''\ + + + Some text + + +''') + doc = libxml2.parseDoc(input) + for i in (0, 1): + f = StringIO.StringIO() + buf = libxml2.createOutputBuffer(f, 'UTF-8') + doc.saveFormatFileTo(buf, 'UTF-8', i) + if f.getvalue() != expected[i]: + print 'xmlDoc.saveFormatFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected[i]) + sys.exit(1) + doc.freeDoc() -if f.getvalue() != "foobar": - print "Failed to save to StringIO" - sys.exit(1) +def testSaveIntoOutputBuffer(): + """ + Similar to the previous two tests, except this time we invoke the save + methods on the output buffer object and pass in an XML node object. + """ + input = 'Hello' + expected = '''\ + +Hello +''' + f = StringIO.StringIO() + doc = libxml2.parseDoc(input) + buf = libxml2.createOutputBuffer(f, 'UTF-8') + buf.saveFileTo(doc, 'UTF-8') + if f.getvalue() != expected: + print 'outputBuffer.saveFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) + sys.exit(1) + f = StringIO.StringIO() + buf = libxml2.createOutputBuffer(f, 'UTF-8') + buf.saveFormatFileTo(doc, 'UTF-8', 1) + if f.getvalue() != expected: + print 'outputBuffer.saveFormatFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) + sys.exit(1) + doc.freeDoc() -del buf -del f +if __name__ == '__main__': + # Memory debug specific + libxml2.debugMemory(1) -# Memory debug specific -libxml2.cleanupParser() -if libxml2.debugMemory(1) == 0: - print "OK" -else: - print "Memory leak %d bytes" % (libxml2.debugMemory(1)) - libxml2.dumpMemory() + testSimpleBufferWrites() + testSaveDocToBuffer() + testSaveFormattedDocToBuffer() + testSaveIntoOutputBuffer() + libxml2.cleanupParser() + if libxml2.debugMemory(1) == 0: + print "OK" + else: + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) + libxml2.dumpMemory() -- cgit v1.2.3