mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
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
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Tue Oct 10 10:33:43 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* python/libxml.py python/types.c: applied patch from Ross Reedstrom,
|
||||||
|
Brian West and Stefan Anca to add XPointer suport to the Python bindings
|
||||||
|
|
||||||
Fri Sep 29 11:13:59 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
Fri Sep 29 11:13:59 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* xmlsave.c: fixed a comment
|
* xmlsave.c: fixed a comment
|
||||||
|
@ -552,10 +552,17 @@ def nodeWrap(o):
|
|||||||
return xmlNode(_obj=o)
|
return xmlNode(_obj=o)
|
||||||
|
|
||||||
def xpathObjectRet(o):
|
def xpathObjectRet(o):
|
||||||
if type(o) == type([]) or type(o) == type(()):
|
otype = type(o)
|
||||||
ret = map(lambda x: nodeWrap(x), o)
|
if otype == type([]):
|
||||||
|
ret = map(xpathObjectRet, o)
|
||||||
return ret
|
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
|
# register an XPath function
|
||||||
|
@ -395,8 +395,106 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj)
|
|||||||
ret = PyString_FromString((char *) obj->stringval);
|
ret = PyString_FromString((char *) obj->stringval);
|
||||||
break;
|
break;
|
||||||
case XPATH_POINT:
|
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:
|
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:
|
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:
|
default:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Unable to convert XPath object type %d\n", obj->type);
|
printf("Unable to convert XPath object type %d\n", obj->type);
|
||||||
|
Reference in New Issue
Block a user