summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2006-10-26 11:17:37 +0200
committerMike Hommey <glandium@debian.org>2006-10-26 11:17:37 +0200
commit968041a8b2ec86c39b5074024ce97d136ecd9a95 (patch)
tree6971d7bce63213fd376b0e66311d0c67a8da4d64 /python
parenta7e9d3f37d5e9fba4b9acaa43e7c12b6d9a669ae (diff)
downloadlibxml2-968041a8b2ec86c39b5074024ce97d136ecd9a95.tar.gz
Load /tmp/libxml2-2.6.27 intoupstream/2.6.27.dfsg
libxml2/branches/upstream/current.
Diffstat (limited to 'python')
-rw-r--r--python/Makefile.am2
-rw-r--r--python/Makefile.in5
-rwxr-xr-xpython/generator.py2
-rw-r--r--python/libxml.c36
-rw-r--r--python/libxml.py30
-rw-r--r--python/libxml2-py.c38
-rwxr-xr-xpython/setup.py2
-rw-r--r--python/tests/Makefile.am3
-rw-r--r--python/tests/Makefile.in6
-rwxr-xr-xpython/tests/compareNodes.py50
-rw-r--r--python/types.c112
11 files changed, 271 insertions, 15 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index c37c0c2..6c0bffa 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -25,7 +25,7 @@ EXTRA_DIST = \
libxml2-python-api.xml \
$(DOCS)
-libxml2mod_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -module -avoid-version -L$(top_builddir)/.libs
+libxml2mod_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -module -avoid-version
if WITH_PYTHON
mylibs = \
diff --git a/python/Makefile.in b/python/Makefile.in
index 9451aaf..9f3a13e 100644
--- a/python/Makefile.in
+++ b/python/Makefile.in
@@ -174,6 +174,7 @@ RDL_LIBS = @RDL_LIBS@
READER_TEST = @READER_TEST@
RELDATE = @RELDATE@
RM = @RM@
+SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STATIC_BINARIES = @STATIC_BINARIES@
@@ -202,6 +203,7 @@ THREAD_CFLAGS = @THREAD_CFLAGS@
THREAD_LIBS = @THREAD_LIBS@
U = @U@
VERSION = @VERSION@
+WGET = @WGET@
WIN32_EXTRA_LDFLAGS = @WIN32_EXTRA_LDFLAGS@
WIN32_EXTRA_LIBADD = @WIN32_EXTRA_LIBADD@
WITH_C14N = @WITH_C14N@
@@ -237,6 +239,7 @@ WITH_WRITER = @WITH_WRITER@
WITH_XINCLUDE = @WITH_XINCLUDE@
WITH_XPATH = @WITH_XPATH@
WITH_XPTR = @WITH_XPTR@
+WITH_ZLIB = @WITH_ZLIB@
XINCLUDE_OBJ = @XINCLUDE_OBJ@
XMLLINT = @XMLLINT@
XML_CFLAGS = @XML_CFLAGS@
@@ -321,7 +324,7 @@ EXTRA_DIST = \
libxml2-python-api.xml \
$(DOCS)
-libxml2mod_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -module -avoid-version -L$(top_builddir)/.libs
+libxml2mod_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ -module -avoid-version
@WITH_PYTHON_TRUE@mylibs = \
@WITH_PYTHON_TRUE@ $(top_builddir)/libxml2.la
diff --git a/python/generator.py b/python/generator.py
index 642b8d1..f116f8a 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -231,7 +231,7 @@ skipped_types = {
py_types = {
'void': (None, None, None, None),
'int': ('i', None, "int", "int"),
- 'long': ('i', None, "int", "int"),
+ 'long': ('l', None, "long", "long"),
'double': ('d', None, "double", "double"),
'unsigned int': ('i', None, "int", "int"),
'xmlChar': ('c', None, "int", "int"),
diff --git a/python/libxml.c b/python/libxml.c
index 88b29cf..6e9a78e 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -3677,6 +3677,40 @@ libxml_getObjDesc(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return Py_BuildValue((char *)"s", str);
}
+static PyObject *
+libxml_compareNodesEqual(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+
+ PyObject *py_node1, *py_node2;
+ xmlNodePtr node1, node2;
+
+ if (!PyArg_ParseTuple(args, (char *)"OO:compareNodesEqual",
+ &py_node1, &py_node2))
+ return NULL;
+ /* To compare two node objects, we compare their pointer addresses */
+ node1 = PyxmlNode_Get(py_node1);
+ node2 = PyxmlNode_Get(py_node2);
+ if ( node1 == node2 )
+ return Py_BuildValue((char *)"i", 1);
+ else
+ return Py_BuildValue((char *)"i", 0);
+
+}
+
+static PyObject *
+libxml_nodeHash(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+
+ PyObject *py_node1;
+ xmlNodePtr node1;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:nodeHash", &py_node1))
+ return NULL;
+ /* For simplicity, we use the node pointer address as a hash value */
+ node1 = PyxmlNode_Get(py_node1);
+
+ return PyLong_FromVoidPtr(node1);
+
+}
+
/************************************************************************
* *
* The registration stuff *
@@ -3730,6 +3764,8 @@ static PyMethodDef libxmlMethods[] = {
#endif
#endif
{(char *) "getObjDesc", libxml_getObjDesc, METH_VARARGS, NULL},
+ {(char *) "compareNodesEqual", libxml_compareNodesEqual, METH_VARARGS, NULL},
+ {(char *) "nodeHash", libxml_nodeHash, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
diff --git a/python/libxml.py b/python/libxml.py
index 997e15f..4c9fe92 100644
--- a/python/libxml.py
+++ b/python/libxml.py
@@ -232,6 +232,23 @@ class xmlCore:
self._o = _obj;
return
self._o = None
+
+ def __eq__(self, other):
+ if other == None:
+ return False
+ ret = libxml2mod.compareNodesEqual(self._o, other._o)
+ if ret == None:
+ return False
+ return ret == True
+ def __ne__(self, other):
+ if other == None:
+ return True
+ ret = libxml2mod.compareNodesEqual(self._o, other._o)
+ return not ret
+ def __hash__(self):
+ ret = libxml2mod.nodeHash(self._o)
+ return ret
+
def __str__(self):
return self.serialize()
def get_parent(self):
@@ -535,10 +552,17 @@ def nodeWrap(o):
return xmlNode(_obj=o)
def xpathObjectRet(o):
- if type(o) == type([]) or type(o) == type(()):
- ret = map(lambda x: nodeWrap(x), o)
+ otype = type(o)
+ if otype == type([]):
+ ret = map(xpathObjectRet, o)
return ret
- return o
+ elif otype == type(()):
+ ret = map(xpathObjectRet, o)
+ return tuple(ret)
+ elif otype == type('') or otype == type(0) or otype == type(0.0):
+ return o
+ else:
+ return nodeWrap(o)
#
# register an XPath function
diff --git a/python/libxml2-py.c b/python/libxml2-py.c
index e0559a0..853a894 100644
--- a/python/libxml2-py.c
+++ b/python/libxml2-py.c
@@ -2412,6 +2412,20 @@ libxml_xmlSaveFormatFile(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
#endif /* defined(LIBXML_OUTPUT_ENABLED) */
PyObject *
+libxml_xmlPathToURI(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ xmlChar * c_retval;
+ xmlChar * path;
+
+ if (!PyArg_ParseTuple(args, (char *)"z:xmlPathToURI", &path))
+ return(NULL);
+
+ c_retval = xmlPathToURI(path);
+ py_retval = libxml_xmlCharPtrWrap((xmlChar *) c_retval);
+ return(py_retval);
+}
+
+PyObject *
libxml_xmlParseXMLDecl(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
xmlParserCtxtPtr ctxt;
PyObject *pyobj_ctxt;
@@ -2535,7 +2549,7 @@ libxml_xmlXPathOrderDocElems(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
doc = (xmlDocPtr) PyxmlNode_Get(pyobj_doc);
c_retval = xmlXPathOrderDocElems(doc);
- py_retval = libxml_intWrap((int) c_retval);
+ py_retval = libxml_longWrap((long) c_retval);
return(py_retval);
}
@@ -4253,7 +4267,7 @@ libxml_xmlByteConsumed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
c_retval = xmlByteConsumed(ctxt);
- py_retval = libxml_intWrap((int) c_retval);
+ py_retval = libxml_longWrap((long) c_retval);
return(py_retval);
}
@@ -7001,7 +7015,7 @@ libxml_xmlClearParserCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(Py_None);
}
-#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED)
+#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED)
PyObject *
libxml_xmlValidateNCName(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
@@ -7017,7 +7031,7 @@ libxml_xmlValidateNCName(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(py_retval);
}
-#endif /* defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) */
+#endif /* defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) */
PyObject *
libxml_xmlStrlen(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
@@ -7365,7 +7379,7 @@ libxml_xmlTextReaderByteConsumed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args
reader = (xmlTextReaderPtr) PyxmlTextReader_Get(pyobj_reader);
c_retval = xmlTextReaderByteConsumed(reader);
- py_retval = libxml_intWrap((int) c_retval);
+ py_retval = libxml_longWrap((long) c_retval);
return(py_retval);
}
@@ -10291,6 +10305,18 @@ libxml_xmlXPtrNewRangeNodes(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
}
#endif /* defined(LIBXML_XPTR_ENABLED) */
+#if defined(LIBXML_HTML_ENABLED)
+PyObject *
+libxml_htmlNewParserCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED) {
+ PyObject *py_retval;
+ htmlParserCtxtPtr c_retval;
+
+ c_retval = htmlNewParserCtxt();
+ py_retval = libxml_xmlParserCtxtPtrWrap((xmlParserCtxtPtr) c_retval);
+ return(py_retval);
+}
+
+#endif /* defined(LIBXML_HTML_ENABLED) */
PyObject *
libxml_xmlStringDecodeEntities(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
@@ -14082,7 +14108,7 @@ libxml_xmlGetLineNo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
node = (xmlNodePtr) PyxmlNode_Get(pyobj_node);
c_retval = xmlGetLineNo(node);
- py_retval = libxml_intWrap((int) c_retval);
+ py_retval = libxml_longWrap((long) c_retval);
return(py_retval);
}
diff --git a/python/setup.py b/python/setup.py
index 99def88..9e3300b 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.26",
+ version = "2.6.27",
description = descr,
author = "Daniel Veillard",
author_email = "veillard@redhat.com",
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index 3571abf..39950f6 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -43,7 +43,8 @@ PYTESTS= \
tstmem.py \
validDTD.py \
validSchemas.py \
- validRNG.py
+ validRNG.py \
+ compareNodes.py
XMLS= \
tst.xml \
diff --git a/python/tests/Makefile.in b/python/tests/Makefile.in
index 5b84cc2..bd49790 100644
--- a/python/tests/Makefile.in
+++ b/python/tests/Makefile.in
@@ -136,6 +136,7 @@ RDL_LIBS = @RDL_LIBS@
READER_TEST = @READER_TEST@
RELDATE = @RELDATE@
RM = @RM@
+SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STATIC_BINARIES = @STATIC_BINARIES@
@@ -164,6 +165,7 @@ THREAD_CFLAGS = @THREAD_CFLAGS@
THREAD_LIBS = @THREAD_LIBS@
U = @U@
VERSION = @VERSION@
+WGET = @WGET@
WIN32_EXTRA_LDFLAGS = @WIN32_EXTRA_LDFLAGS@
WIN32_EXTRA_LIBADD = @WIN32_EXTRA_LIBADD@
WITH_C14N = @WITH_C14N@
@@ -199,6 +201,7 @@ WITH_WRITER = @WITH_WRITER@
WITH_XINCLUDE = @WITH_XINCLUDE@
WITH_XPATH = @WITH_XPATH@
WITH_XPTR = @WITH_XPTR@
+WITH_ZLIB = @WITH_ZLIB@
XINCLUDE_OBJ = @XINCLUDE_OBJ@
XMLLINT = @XMLLINT@
XML_CFLAGS = @XML_CFLAGS@
@@ -302,7 +305,8 @@ PYTESTS = \
tstmem.py \
validDTD.py \
validSchemas.py \
- validRNG.py
+ validRNG.py \
+ compareNodes.py
XMLS = \
tst.xml \
diff --git a/python/tests/compareNodes.py b/python/tests/compareNodes.py
new file mode 100755
index 0000000..ec04323
--- /dev/null
+++ b/python/tests/compareNodes.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python -u
+import sys
+import libxml2
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+#
+# Testing XML Node comparison and Node hash-value
+#
+doc = libxml2.parseDoc("""<root><foo/></root>""")
+root = doc.getRootElement()
+
+# Create two different objects which point to foo
+foonode1 = root.children
+foonode2 = root.children
+
+# Now check that [in]equality tests work ok
+if not ( foonode1 == foonode2 ):
+ print "Error comparing nodes with ==, nodes should be equal but are unequal"
+ sys.exit(1)
+if not ( foonode1 != root ):
+ print "Error comparing nodes with ==, nodes should not be equal but are equal"
+ sys.exit(1)
+if not ( foonode1 != root ):
+ print "Error comparing nodes with !=, nodes should not be equal but are equal"
+if ( foonode1 != foonode2 ):
+ print "Error comparing nodes with !=, nodes should be equal but are unequal"
+
+# Next check that the hash function for the objects also works ok
+if not (hash(foonode1) == hash(foonode2)):
+ print "Error hash values for two equal nodes are different"
+ sys.exit(1)
+if not (hash(foonode1) != hash(root)):
+ print "Error hash values for two unequal nodes are not different"
+ sys.exit(1)
+if hash(foonode1) == hash(root):
+ print "Error hash values for two unequal nodes are equal"
+ sys.exit(1)
+
+# Basic tests successful
+doc.freeDoc()
+
+# 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 8a6a9a0..5c5dcca 100644
--- a/python/types.c
+++ b/python/types.c
@@ -395,8 +395,106 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
ret = PyString_FromString((char *) obj->stringval);
break;
case XPATH_POINT:
+ {
+ PyObject *node;
+ PyObject *indexIntoNode;
+ PyObject *tuple;
+
+ node = libxml_xmlNodePtrWrap(obj->user);
+ indexIntoNode = PyInt_FromLong((long) obj->index);
+
+ tuple = PyTuple_New(2);
+ PyTuple_SetItem(tuple, 0, node);
+ PyTuple_SetItem(tuple, 1, indexIntoNode);
+
+ ret = tuple;
+ break;
+ }
case XPATH_RANGE:
+ {
+ unsigned short bCollapsedRange;
+
+ bCollapsedRange = ( (obj->user2 == NULL) ||
+ ((obj->user2 == obj->user) && (obj->index == obj->index2)) );
+ if ( bCollapsedRange ) {
+ PyObject *node;
+ PyObject *indexIntoNode;
+ PyObject *tuple;
+ PyObject *list;
+
+ list = PyList_New(1);
+
+ node = libxml_xmlNodePtrWrap(obj->user);
+ indexIntoNode = PyInt_FromLong((long) obj->index);
+
+ tuple = PyTuple_New(2);
+ PyTuple_SetItem(tuple, 0, node);
+ PyTuple_SetItem(tuple, 1, indexIntoNode);
+
+ PyList_SetItem(list, 0, tuple);
+
+ ret = list;
+ } else {
+ PyObject *node;
+ PyObject *indexIntoNode;
+ PyObject *tuple;
+ PyObject *list;
+
+ list = PyList_New(2);
+
+ node = libxml_xmlNodePtrWrap(obj->user);
+ indexIntoNode = PyInt_FromLong((long) obj->index);
+
+ tuple = PyTuple_New(2);
+ PyTuple_SetItem(tuple, 0, node);
+ PyTuple_SetItem(tuple, 1, indexIntoNode);
+
+ PyList_SetItem(list, 0, tuple);
+
+ node = libxml_xmlNodePtrWrap(obj->user2);
+ indexIntoNode = PyInt_FromLong((long) obj->index2);
+
+ tuple = PyTuple_New(2);
+ PyTuple_SetItem(tuple, 0, node);
+ PyTuple_SetItem(tuple, 1, indexIntoNode);
+
+ PyList_SetItem(list, 1, tuple);
+
+ ret = list;
+ }
+ break;
+ }
case XPATH_LOCATIONSET:
+ {
+ xmlLocationSetPtr set;
+
+ set = obj->user;
+ if ( set && set->locNr > 0 ) {
+ int i;
+ PyObject *list;
+
+ list = PyList_New(set->locNr);
+
+ for (i=0; i<set->locNr; i++) {
+ xmlXPathObjectPtr setobj;
+ PyObject *pyobj;
+
+ setobj = set->locTab[i]; /*xmlXPathObjectPtr setobj*/
+
+ pyobj = libxml_xmlXPathObjectPtrWrap(setobj);
+ /* xmlXPathFreeObject(setobj) is called */
+ set->locTab[i] = NULL;
+
+ PyList_SetItem(list, i, pyobj);
+ }
+ set->locNr = 0;
+ ret = list;
+ } else {
+ Py_INCREF(Py_None);
+ ret = Py_None;
+ }
+ break;
+ }
default:
#ifdef DEBUG
printf("Unable to convert XPath object type %d\n", obj->type);
@@ -422,6 +520,20 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj)
if PyFloat_Check
(obj) {
ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
+
+ } else if PyInt_Check(obj) {
+
+ ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
+
+ } else if PyBool_Check (obj) {
+
+ if (obj == Py_True) {
+ ret = xmlXPathNewBoolean(1);
+ }
+ else {
+ ret = xmlXPathNewBoolean(0);
+ }
+
} else if PyString_Check
(obj) {
xmlChar *str;