Commit a94ec6ff authored by Daniel Veillard's avatar Daniel Veillard
Browse files

commiting some Python bindings work done while travelling Daniel

* python/*: commiting some Python bindings work done while travelling
Daniel
parent 9730051f
Fri Mar 1 13:56:12 CET 2002 Daniel Veillard <daniel@veillard.com>
* python/*: commiting some Python bindings work done while travelling
Fri Mar 1 10:11:15 CET 2002 Daniel Veillard <daniel@veillard.com>
* xmllint.c: close #72663 and #72658, don't memdump unless compiled
......
......@@ -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 }
};
......
<?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"/>
......
......@@ -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)
......
......@@ -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");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment