1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-25 02:02:11 +03:00

commiting some Python bindings work done while travelling Daniel

* python/*: commiting some Python bindings work done while travelling
Daniel
This commit is contained in:
Daniel Veillard
2002-03-01 13:00:53 +00:00
parent 9730051f83
commit a94ec6ff13
5 changed files with 55 additions and 7 deletions

View File

@ -1402,6 +1402,30 @@ libxml_xmlNodeGetNs(PyObject *self, PyObject *args) {
return(py_retval);
}
/************************************************************************
* *
* Extra stuff *
* *
************************************************************************/
PyObject *
libxml_xmlNewNode(PyObject *self, PyObject *args) {
PyObject *py_retval;
xmlChar * name;
xmlNodePtr node;
if (!PyArg_ParseTuple(args, "s:xmlNewNode", &name))
return(NULL);
node = (xmlNodePtr) xmlNewNode(NULL, name);
printf("NewNode: %s : %p\n", name, node);
if (node == NULL) {
Py_INCREF(Py_None);
return(Py_None);
}
py_retval = libxml_xmlNodePtrWrap(node);
return(py_retval);
}
/************************************************************************
* *
* The registration stuff *
@ -1418,6 +1442,7 @@ static PyMethodDef libxmlMethods[] = {
{ "parent", libxml_parent, METH_VARARGS, NULL },
{ "type", libxml_type, METH_VARARGS, NULL },
{ "doc", libxml_doc, METH_VARARGS, NULL },
{ "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL },
{ NULL }
};

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<api name='libxml2-python'>
<files>
<file name='python'>
<exports symbol='libxml_registerXPathFunction'/>
</file>
</files>
<symbols>
<function name='xmlRegisterXPathFunction' file='python'>
<info>Register a Python written function to the XPath interpreter</info>
@ -14,6 +9,11 @@
<arg name='ns_uri' type='xmlChar *' info='the namespace or NULL'/>
<arg name='f' type='pythonObject' info='the python function'/>
</function>
<function name='xmlNewNode' file='python'>
<info>Create a new Node</info>
<return type='xmlNodePtr' info="A new element node"/>
<arg name='name' type='xmlChar *' info='the node name'/>
</function>
<function name='xmlRegisterErrorHandler' file='python'>
<info>Register a Python written function to for error reporting. The function is called back as f(ctx, error).</info>
<return type='int' info="1 in case of success, 0 or -1 in case of error"/>

View File

@ -121,6 +121,7 @@ createPushParser()
debugMemory()
dumpMemory()
htmlCreatePushParser()
newNode()
registerErrorHandler()
# functions from module tree
@ -343,7 +344,6 @@ Class xmlNs(xmlNode)
copyNamespaceList()
freeNs()
freeNsList()
newNode()
Class xmlDtd(xmlNode)

View File

@ -346,7 +346,7 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) {
xmlXPathObjectPtr
libxml_xmlXPathObjectPtrConvert(PyObject * obj) {
xmlXPathObjectPtr ret;
xmlXPathObjectPtr ret = NULL;
#ifdef DEBUG
printf("libxml_xmlXPathObjectPtrConvert: obj = %p\n", obj);
@ -362,6 +362,25 @@ libxml_xmlXPathObjectPtrConvert(PyObject * obj) {
str = xmlStrndup((const xmlChar *)PyString_AS_STRING(obj),
PyString_GET_SIZE(obj));
ret = xmlXPathWrapString(str);
} else if PyList_Check(obj) {
int i;
PyObject *node;
xmlNodePtr cur;
xmlNodeSetPtr set;
set = xmlXPathNodeSetCreate(NULL);
for (i = 0;i < PyList_Size(obj);i++) {
node = PyList_GetItem(obj, i);
if ((node == NULL) || (node->ob_type == NULL) ||
(!PyCObject_Check(node)))
continue;
cur = PyxmlNode_Get(node);
if (cur != NULL) {
xmlXPathNodeSetAdd(set, cur);
}
}
ret = xmlXPathWrapNodeSet(set);
} else {
printf("Unable to convert Python Object to XPath");
}