diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2006-10-10 08:40:04 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2006-10-10 08:40:04 +0000 |
commit | 46459066c50190cee070ed1fcafdf6d307c09301 (patch) | |
tree | c70002c88bfc54fbcb06ca60894958c2762e5f38 /python | |
parent | 681e904e37273dedfb69393a29463b7e5aea4d37 (diff) | |
download | android_external_libxml2-46459066c50190cee070ed1fcafdf6d307c09301.tar.gz android_external_libxml2-46459066c50190cee070ed1fcafdf6d307c09301.tar.bz2 android_external_libxml2-46459066c50190cee070ed1fcafdf6d307c09301.zip |
applied patch from Ross Reedstrom, Brian West and Stefan Anca to add
* python/libxml.py python/types.c: applied patch from Ross Reedstrom,
Brian West and Stefan Anca to add XPointer suport to the Python bindings
Daniel
Diffstat (limited to 'python')
-rw-r--r-- | python/libxml.py | 13 | ||||
-rw-r--r-- | python/types.c | 98 |
2 files changed, 108 insertions, 3 deletions
diff --git a/python/libxml.py b/python/libxml.py index f7c31299..4c9fe92f 100644 --- a/python/libxml.py +++ b/python/libxml.py @@ -552,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/types.c b/python/types.c index 6bcbcf69..5c5dcca2 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); |