Changed to the MIT Licence updated the doc accordingly preparing 2.4.14
* Copyright Makefile.am README configure.in libxml.spec.in:
Changed to the MIT Licence
* doc/FAQ.html doc/catalog.html doc/intro.html doc/xml.html
doc/xmlio.html: updated the doc accordingly
* include/libxml/xmlwin32version.h configure.in: preparing
2.4.14 release
* python/generator.py python/libxml.c python/libxml2-python-api.xml
python/libxml2class.txt python/libxml_wrap.h python/types.c:
fixed the const xmlChar * wrapper and generator, XPath extension
functions now use the context as first argument
* python/tests/tstxpath.py python/tests/xpath.py
python/tests/xpathext.py: Updated the tests accordingly
* tree.c: fixed bug #70067
Daniel
diff --git a/python/generator.py b/python/generator.py
index 0b13c41..13a1011 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -214,9 +214,9 @@
'xmlChar': ('c', None, "int", "int"),
'unsigned char *': ('z', None, "charPtr", "char *"),
'char *': ('z', None, "charPtr", "char *"),
- 'const char *': ('z', None, "charPtr", "char *"),
+ 'const char *': ('z', None, "charPtrConst", "const char *"),
'xmlChar *': ('z', None, "xmlCharPtr", "xmlChar *"),
- 'const xmlChar *': ('z', None, "xmlCharPtr", "xmlChar *"),
+ 'const xmlChar *': ('z', None, "xmlCharPtrConst", "const xmlChar *"),
'xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
'const xmlNodePtr': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
'xmlNode *': ('O', "xmlNode", "xmlNodePtr", "xmlNodePtr"),
@@ -523,7 +523,6 @@
"xmlAttribute" : "xmlNode",
}
classes_destructors = {
- "xpathContext": "xmlXPathFreeContext",
"parserCtxt": "xmlFreeParserCtxt",
"catalog": "xmlFreeCatalog",
}
@@ -576,6 +575,12 @@
elif name[0:10] == "xmlNodeGet" and file == "python_accessor":
func = name[10:]
func = string.lower(func[0:1]) + func[1:]
+ elif name[0:17] == "xmlXPathParserGet" and file == "python_accessor":
+ func = name[17:]
+ func = string.lower(func[0:1]) + func[1:]
+ elif name[0:11] == "xmlXPathGet" and file == "python_accessor":
+ func = name[11:]
+ func = string.lower(func[0:1]) + func[1:]
elif name[0:11] == "xmlACatalog":
func = name[11:]
func = string.lower(func[0:1]) + func[1:]
diff --git a/python/libxml.c b/python/libxml.c
index 62d9dcd..30dfd58 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -806,11 +806,12 @@
return;
}
- list = PyTuple_New(nargs);
+ list = PyTuple_New(nargs + 1);
+ PyTuple_SetItem(list, 0, libxml_xmlXPathParserContextPtrWrap(ctxt));
for (i = 0;i < nargs;i++) {
obj = valuePop(ctxt);
cur = libxml_xmlXPathObjectPtrWrap(obj);
- PyTuple_SetItem(list, i, cur);
+ PyTuple_SetItem(list, i + 1, cur);
}
result = PyEval_CallObject(current_function, list);
Py_DECREF(list);
diff --git a/python/libxml2-python-api.xml b/python/libxml2-python-api.xml
index 94d8f84..24e28af 100644
--- a/python/libxml2-python-api.xml
+++ b/python/libxml2-python-api.xml
@@ -36,6 +36,7 @@
<arg name='size' type='int' info='the size of the initial data'/>
<arg name='URI' type='xmlChar *' info='The URI used for base computations'/>
</function>
+ <!-- xmlParserCtxtPtr accessors -->
<function name='xmlParserGetDoc' file='python_accessor'>
<info>Get the document tree from a parser context.</info>
<return type='xmlDocPtr' info="the document tree" field="myDoc"/>
@@ -90,6 +91,7 @@
<info>dump the memory allocated in the file .memdump</info>
<return type='void'/>
</function>
+ <!-- xmlNsPtr accessors -->
<function name='xmlNodeGetNs' file='python_accessor'>
<info>Get the namespace of a node</info>
<return type='xmlNsPtr' info="The namespace or None"/>
@@ -100,5 +102,41 @@
<return type='xmlNsPtr' info="The namespace or None"/>
<arg name='node' type='xmlNodePtr' info='the node'/>
</function>
+ <!-- xmlXPathParserContextPtr accessors -->
+ <function name='xmlXPathParserGetContext' file='python_accessor'>
+ <info>Get the xpathContext from an xpathParserContext</info>
+ <return type='xmlXPathContextPtr' info="The XPath context" field="context"/>
+ <arg name='ctxt' type='xmlXPathParserContextPtr' info='the XPath parser context'/>
+ </function>
+ <function name='xmlXPathGetContextDoc' file='python_accessor'>
+ <info>Get the doc from an xpathContext</info>
+ <return type='xmlDocPtr' info="The doc context" field="doc"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
+ <function name='xmlXPathGetContextNode' file='python_accessor'>
+ <info>Get the current node from an xpathContext</info>
+ <return type='xmlNodePtr' info="The node context" field="node"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
+ <function name='xmlXPathGetContextPosition' file='python_accessor'>
+ <info>Get the current node from an xpathContext</info>
+ <return type='int' info="The node context" field="proximityPosition"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
+ <function name='xmlXPathGetContextSize' file='python_accessor'>
+ <info>Get the current node from an xpathContext</info>
+ <return type='int' info="The node context" field="contextSize"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
+ <function name='xmlXPathGetFunction' file='python_accessor'>
+ <info>Get the current function name xpathContext</info>
+ <return type='const xmlChar *' info="The function name" field="function"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
+ <function name='xmlXPathGetFunctionURI' file='python_accessor'>
+ <info>Get the current function name URI xpathContext</info>
+ <return type='const xmlChar *' info="The function name URI" field="functionURI"/>
+ <arg name='ctxt' type='xmlXPathContextPtr' info='the XPath context'/>
+ </function>
</symbols>
</api>
diff --git a/python/libxml2class.txt b/python/libxml2class.txt
index 00070a5..3e5a311 100644
--- a/python/libxml2class.txt
+++ b/python/libxml2class.txt
@@ -374,6 +374,8 @@
resolveSystem()
resolveURI()
Class xpathParserContext()
+ # accessors
+ context()
# functions from module xpathInternals
xpathAddValues()
@@ -507,6 +509,13 @@
freePropList()
removeProp()
Class xpathContext()
+ # accessors
+ contextDoc()
+ contextNode()
+ contextPosition()
+ contextSize()
+ function()
+ functionURI()
# functions from module python
registerXPathFunction()
diff --git a/python/libxml_wrap.h b/python/libxml_wrap.h
index fb8b79e..77c0736 100644
--- a/python/libxml_wrap.h
+++ b/python/libxml_wrap.h
@@ -64,6 +64,8 @@
PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
PyObject * libxml_charPtrWrap(char *str);
PyObject * libxml_constcharPtrWrap(const char *str);
+PyObject * libxml_charPtrConstWrap(const char *str);
+PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
diff --git a/python/tests/tstxpath.py b/python/tests/tstxpath.py
index 9fc3d4c..b27ff2f 100755
--- a/python/tests/tstxpath.py
+++ b/python/tests/tstxpath.py
@@ -5,11 +5,20 @@
#memory debug specific
libxml2.debugMemory(1)
+called = ""
-def foo(x):
+def foo(ctx, x):
+ global called
+
+ #
+ # test that access to the XPath evaluation contexts
+ #
+ pctxt = libxml2.xpathParserContext(_obj=ctx)
+ ctxt = pctxt.context()
+ called = ctxt.function()
return x + 1
-def bar(x):
+def bar(ctxt, x):
return "%d" % (x + 2)
doc = libxml2.parseFile("tst.xml")
@@ -21,7 +30,6 @@
if res[0].name != "doc" or res[1].name != "foo":
print "xpath query: wrong node set value"
sys.exit(1)
-
libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
i = 10000
@@ -39,7 +47,12 @@
sys.exit(1)
i = i - 1
doc.freeDoc()
-del ctxt
+ctxt.xpathFreeContext()
+
+if called != "foo":
+ print "xpath function: failed to access the context"
+ print "xpath function: %s" % (called)
+ sys.exit(1)
#memory debug specific
libxml2.cleanupParser()
diff --git a/python/tests/xpath.py b/python/tests/xpath.py
index 0d35a99..73ab735 100755
--- a/python/tests/xpath.py
+++ b/python/tests/xpath.py
@@ -23,12 +23,14 @@
print "xpath query: wrong node set value"
sys.exit(1)
doc.freeDoc()
+ctxt.xpathFreeContext()
i = 1000
while i > 0:
doc = libxml2.parseFile("tst.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
doc.freeDoc()
+ ctxt.xpathFreeContext()
i = i -1
del ctxt
diff --git a/python/tests/xpathext.py b/python/tests/xpathext.py
index 14cb69f..c497b55 100755
--- a/python/tests/xpathext.py
+++ b/python/tests/xpathext.py
@@ -5,10 +5,10 @@
# Memory debug specific
libxml2.debugMemory(1)
-def foo(x):
+def foo(ctx, x):
return x + 1
-def bar(x):
+def bar(ctx, x):
return "%d" % (x + 2)
doc = libxml2.parseFile("tst.xml")
@@ -38,7 +38,7 @@
sys.exit(1)
i = i - 1
doc.freeDoc()
-del ctxt
+ctxt.xpathFreeContext()
# Memory debug specific
libxml2.cleanupParser()
diff --git a/python/types.c b/python/types.c
index 70f7701..7718d5f 100644
--- a/python/types.c
+++ b/python/types.c
@@ -59,6 +59,22 @@
}
PyObject *
+libxml_charPtrConstWrap(const char *str) {
+ PyObject *ret;
+
+#ifdef DEBUG
+ printf("libxml_xmlcharPtrWrap: str = %s\n", str);
+#endif
+ if (str == NULL) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+ /* TODO: look at deallocation */
+ ret = PyString_FromString(str);
+ return(ret);
+}
+
+PyObject *
libxml_xmlCharPtrWrap(xmlChar *str) {
PyObject *ret;
@@ -76,6 +92,22 @@
}
PyObject *
+libxml_xmlCharPtrConstWrap(const xmlChar *str) {
+ PyObject *ret;
+
+#ifdef DEBUG
+ printf("libxml_xmlCharPtrWrap: str = %s\n", str);
+#endif
+ if (str == NULL) {
+ Py_INCREF(Py_None);
+ return(Py_None);
+ }
+ /* TODO: look at deallocation */
+ ret = PyString_FromString(str);
+ return(ret);
+}
+
+PyObject *
libxml_constcharPtrWrap(const char *str) {
PyObject *ret;