diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2002-12-14 23:00:35 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2002-12-14 23:00:35 +0000 |
commit | 0eb38c7259b04de809f7bc880688f468ac7a15bf (patch) | |
tree | 15fa9c77b5c1ce150b9f4b25b094d432ee469f86 /python | |
parent | 7ef0fcb8a864db768aab150f6c2e9e0fb900da0d (diff) | |
download | libxml2-0eb38c7259b04de809f7bc880688f468ac7a15bf.tar.gz |
added the close and getattribute methods of XmlTextReader. added the
* xmlreader.c doc/libxml2-api.xml: added the close and getattribute
methods of XmlTextReader.
* python/generator.py python/libxml_wrap.h python/types.c
python/libxml2class.txt: added the reader to the Python bindings
* python/tests/Makefile.am python/tests/reader.py: added a specific
test for the Python bindings of the Reader APIs
* parser.c: small cleanup.
Daniel
Diffstat (limited to 'python')
-rwxr-xr-x | python/generator.py | 6 | ||||
-rw-r--r-- | python/libxml2class.txt | 30 | ||||
-rw-r--r-- | python/libxml_wrap.h | 29 | ||||
-rw-r--r-- | python/tests/Makefile.am | 3 | ||||
-rwxr-xr-x | python/tests/reader.py | 94 | ||||
-rw-r--r-- | python/types.c | 18 |
6 files changed, 179 insertions, 1 deletions
diff --git a/python/generator.py b/python/generator.py index 9c757133..b42630b9 100755 --- a/python/generator.py +++ b/python/generator.py @@ -271,6 +271,7 @@ py_types = { 'xmlOutputBufferPtr': ('O', "outputBuffer", "xmlOutputBufferPtr", "xmlOutputBufferPtr"), 'xmlParserInputBufferPtr': ('O', "inputBuffer", "xmlParserInputBufferPtr", "xmlParserInputBufferPtr"), 'xmlRegexpPtr': ('O', "xmlReg", "xmlRegexpPtr", "xmlRegexpPtr"), + 'xmlTextReaderPtr': ('O', "xmlTextReader", "xmlTextReaderPtr", "xmlTextReaderPtr"), } py_return_types = { @@ -597,6 +598,7 @@ classes_type = { "xmlOutputBufferPtr": ("._o", "outputBuffer(_obj=%s)", "outputBuffer"), "xmlParserInputBufferPtr": ("._o", "inputBuffer(_obj=%s)", "inputBuffer"), "xmlRegexpPtr": ("._o", "xmlReg(_obj=%s)", "xmlReg"), + "xmlTextReaderPtr": ("._o", "xmlTextReader(_obj=%s)", "xmlTextReader"), } converter_type = { @@ -624,6 +626,7 @@ classes_destructors = { # "outputBuffer": "xmlOutputBufferClose", "inputBuffer": "xmlFreeParserInputBuffer", "xmlReg": "xmlRegFreeRegexp", + "xmlTextReader": "xmlFreeTextReader", } functions_noexcept = { @@ -676,6 +679,9 @@ def nameFixup(name, classe, type, file): func = "regexp" + name[9:] elif name[0:6] == "xmlReg" and file == "xmlregexp": func = "regexp" + name[6:] + elif name[0:13] == "xmlTextReader" and file == "xmlreader": + func = name[13:] + func = string.lower(func[0:1]) + func[1:] elif name[0:11] == "xmlACatalog": func = name[11:] func = string.lower(func[0:1]) + func[1:] diff --git a/python/libxml2class.txt b/python/libxml2class.txt index e15f5999..6127f7b3 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -165,6 +165,9 @@ registerDefaultInputCallbacks() registerDefaultOutputCallbacks() registerHTTPPostCallbacks() +# functions from module xmlreader +newTextReaderFilename() + # functions from module xmlregexp regexpCompile() @@ -556,6 +559,30 @@ Class xmlAttr(xmlNode) freeProp() freePropList() removeProp() +Class xmlTextReader() + + # functions from module xmlreader + attributeCount() + baseUri() + close() + depth() + freeTextReader() + getAttribute() + getAttributeNo() + getAttributeNs() + hasAttributes() + hasValue() + isDefault() + isEmptyElement() + localName() + name() + namespaceUri() + nodeType() + prefix() + quoteChar() + read() + value() + xmlLang() Class xmlReg() # functions from module xmlregexp @@ -731,6 +758,9 @@ Class inputBuffer(ioReadWrapper) push() read() + # functions from module xmlreader + newTextReader() + Class outputBuffer(ioWriteWrapper) diff --git a/python/libxml_wrap.h b/python/libxml_wrap.h index efa79d04..7a38f54c 100644 --- a/python/libxml_wrap.h +++ b/python/libxml_wrap.h @@ -17,6 +17,26 @@ #include <libxml/xmlunicode.h> #include <libxml/xmlregexp.h> #include <libxml/xmlautomata.h> +#include <libxml/xmlreader.h> + +/** + * ATTRIBUTE_UNUSED: + * + * Macro used to signal to GCC unused function parameters + * Repeated here since the definition is not available when + * compiled outside the libxml2 build tree. + */ +#ifdef __GNUC__ +#ifdef ATTRIBUTE_UNUSED +#undef ATTRIBUTE_UNUSED +#endif +#include <ansidecl.h> +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED +#endif +#else +#define ATTRIBUTE_UNUSED +#endif #define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \ (((PyxmlNode_Object *)(v))->obj)) @@ -66,6 +86,14 @@ typedef struct { xmlRegexpPtr obj; } PyxmlReg_Object; +#define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \ + (((PyxmlTextReader_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlTextReaderPtr obj; +} PyxmlTextReader_Object; + #define PyURI_Get(v) (((v) == Py_None) ? NULL : \ (((PyURI_Object *)(v))->obj)) @@ -119,5 +147,6 @@ PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri); PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer); PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer); PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp); +PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader); xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj); diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am index 96cb0333..c6bef2c5 100644 --- a/python/tests/Makefile.am +++ b/python/tests/Makefile.am @@ -19,7 +19,8 @@ PYTESTS= \ outbuf.py \ inbuf.py \ resolver.py \ - regexp.py + regexp.py \ + reader.py XMLS= \ tst.xml \ diff --git a/python/tests/reader.py b/python/tests/reader.py new file mode 100755 index 00000000..1817fe92 --- /dev/null +++ b/python/tests/reader.py @@ -0,0 +1,94 @@ +#!/usr/bin/python -u +import libxml2 +import StringIO +import sys + +# Memory debug specific +libxml2.debugMemory(1) + +f = StringIO.StringIO("""<a><b b1="b1"/><c>content of c</c></a>""") +input = libxml2.inputBuffer(f) +reader = input.newTextReader() +ret = reader.read() +if ret != 1: + print "Error reading to first element" + sys.exit(1) +if reader.name() != "a" or reader.isEmptyElement() != 0 or \ + reader.nodeType() != 1 or reader.hasAttributes() != 0: + print "Error reading the first element" + sys.exit(1) +ret = reader.read() +if ret != 1: + print "Error reading to second element" + sys.exit(1) +if reader.name() != "b" or reader.isEmptyElement() != 1 or \ + reader.nodeType() != 1 or reader.hasAttributes() != 1: + print "Error reading the second element" + sys.exit(1) +ret = reader.read() +if ret != 1: + print "Error reading to third element" + sys.exit(1) +if reader.name() != "c" or reader.isEmptyElement() != 0 or \ + reader.nodeType() != 1 or reader.hasAttributes() != 0: + print "Error reading the third element" + sys.exit(1) +ret = reader.read() +if ret != 1: + print "Error reading to text node" + sys.exit(1) +if reader.name() != "#text" or reader.isEmptyElement() != 0 or \ + reader.nodeType() != 3 or reader.hasAttributes() != 0 or \ + reader.value() != "content of c": + print "Error reading the text node" + sys.exit(1) +ret = reader.read() +if ret != 1: + print "Error reading to end of third element" + sys.exit(1) +if reader.name() != "c" or reader.isEmptyElement() != 0 or \ + reader.nodeType() != 15 or reader.hasAttributes() != 0: + print "Error reading the end of third element" + sys.exit(1) +ret = reader.read() +if ret != 1: + print "Error reading to end of first element" + sys.exit(1) +if reader.name() != "a" or reader.isEmptyElement() != 0 or \ + reader.nodeType() != 15 or reader.hasAttributes() != 0: + print "Error reading the end of first element" + sys.exit(1) +ret = reader.read() +if ret != 0: + print "Error reading to end of document" + sys.exit(1) + +# +# example from the XmlTextReader docs +# +f = StringIO.StringIO("""<test xmlns:dt="urn:datatypes" dt:type="int"/>""") +input = libxml2.inputBuffer(f) +reader = input.newTextReader() + +ret = reader.read() +if ret != 1: + print "Error reading test element" + sys.exit(1) +if reader.getAttributeNo(0) != "urn:datatypes" or \ + reader.getAttributeNo(1) != "int" or \ + reader.getAttributeNs("type", "urn:datatypes") != "int" or \ + reader.getAttribute("dt:type") != "int": + print "error reading test attributes" + sys.exit(1) + +del f +del input +del reader + +# Memory debug specific +libxml2.cleanupParser() +if libxml2.debugMemory(1) == 0: + print "OK" +else: + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) + libxml2.dumpMemory() diff --git a/python/types.c b/python/types.c index 3f490284..2c5a13ec 100644 --- a/python/types.c +++ b/python/types.c @@ -547,3 +547,21 @@ libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp) (char *) "xmlRegexpPtr", NULL); return (ret); } + +PyObject * +libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader) +{ + PyObject *ret; + +#ifdef DEBUG + printf("libxml_xmlTextReaderPtrWrap: reader = %p\n", reader); +#endif + if (reader == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = + PyCObject_FromVoidPtrAndDesc((void *) reader, + (char *) "xmlTextReaderPtr", NULL); + return (ret); +} |