summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2005-04-04 18:23:13 +0000
committerMike Hommey <glandium@debian.org>2005-04-04 18:23:13 +0000
commit0fc063df3ab2ad380d532d210dd1001de473e51b (patch)
tree6f88f0a0f845dd6aec7807b18cb5618d93e159ac /python
parent50e5b428562964b1eb2f876370058b34b47c5e90 (diff)
downloadlibxml2-0fc063df3ab2ad380d532d210dd1001de473e51b.tar.gz
Load /tmp/tmp.98zkCi/libxml2-2.6.19 intoupstream/2.6.19
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'python')
-rwxr-xr-xpython/generator.py6
-rw-r--r--python/libxml.c9
-rw-r--r--python/libxml.py39
-rw-r--r--python/libxml2-py.c16
-rwxr-xr-xpython/setup.py2
-rw-r--r--python/tests/Makefile.am5
-rw-r--r--python/tests/Makefile.in5
-rwxr-xr-xpython/tests/validDTD.py59
-rwxr-xr-xpython/tests/validRNG.py76
-rwxr-xr-xpython/tests/validSchemas.py83
10 files changed, 276 insertions, 24 deletions
diff --git a/python/generator.py b/python/generator.py
index 8add0a9..6144e54 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -346,6 +346,9 @@ def skip_function(name):
return 1
if name == "xmlFreeValidCtxt":
return 1
+ if name == "xmlSchemaFreeValidCtxt":
+ return 1
+
#
# Those are skipped because the Const version is used of the bindings
# instead.
@@ -744,6 +747,9 @@ classes_ancestor = {
"inputBuffer": "ioReadWrapper",
"parserCtxt": "parserCtxtCore",
"xmlTextReader": "xmlTextReaderCore",
+ "ValidCtxt": "ValidCtxtCore",
+ "SchemaValidCtxt": "SchemaValidCtxtCore",
+ "relaxNgValidCtxt": "relaxNgValidCtxtCore",
}
classes_destructors = {
"parserCtxt": "xmlFreeParserCtxt",
diff --git a/python/libxml.c b/python/libxml.c
index b520994..b18f887 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -1378,7 +1378,7 @@ libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
SAX = &pythonSaxHandler;
Py_INCREF(pyobj_SAX);
/* The reference is released in pythonEndDocument() */
- xmlSAXParseFileWithData(SAX, URI, recover, pyobj_SAX);
+ xmlSAXUserParseFile(SAX, pyobj_SAX, URI);
Py_INCREF(Py_None);
return (Py_None);
}
@@ -1859,7 +1859,7 @@ libxml_xmlSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
}
-PyObject *
+static PyObject *
libxml_xmlFreeValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
xmlValidCtxtPtr cur;
xmlValidCtxtPyCtxtPtr pyCtxt;
@@ -3289,8 +3289,7 @@ libxml_xmlSchemaSetValidErrors(ATTRIBUTE_UNUSED PyObject * self, PyObject * args
return(py_retval);
}
-#if 0
-PyObject *
+static PyObject *
libxml_xmlSchemaFreeValidCtxt(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
{
xmlSchemaValidCtxtPtr ctxt;
@@ -3316,7 +3315,6 @@ libxml_xmlSchemaFreeValidCtxt(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
Py_INCREF(Py_None);
return(Py_None);
}
-#endif
#endif
@@ -3668,6 +3666,7 @@ static PyMethodDef libxmlMethods[] = {
{(char *)"xmlRelaxNGSetValidErrors", libxml_xmlRelaxNGSetValidErrors, METH_VARARGS, NULL},
{(char *)"xmlRelaxNGFreeValidCtxt", libxml_xmlRelaxNGFreeValidCtxt, METH_VARARGS, NULL},
{(char *)"xmlSchemaSetValidErrors", libxml_xmlSchemaSetValidErrors, METH_VARARGS, NULL},
+ {(char *)"xmlSchemaFreeValidCtxt", libxml_xmlSchemaFreeValidCtxt, METH_VARARGS, NULL},
#endif
#ifdef LIBXML_C14N_ENABLED
#ifdef LIBXML_OUTPUT_ENABLED
diff --git a/python/libxml.py b/python/libxml.py
index bde8aba..2eca71e 100644
--- a/python/libxml.py
+++ b/python/libxml.py
@@ -587,6 +587,45 @@ class parserCtxtCore:
return libxml2mod.addLocalCatalog(self._o, uri)
+class ValidCtxtCore:
+
+ def __init__(self, *args, **kw):
+ pass
+
+ def setValidityErrorHandler(self, err_func, warn_func, arg=None):
+ """
+ Register error and warning handlers for DTD validation.
+ These will be called back as f(msg,arg)
+ """
+ libxml2mod.xmlSetValidErrors(self._o, err_func, warn_func, arg)
+
+
+class SchemaValidCtxtCore:
+
+ def __init__(self, *args, **kw):
+ pass
+
+ def setValidityErrorHandler(self, err_func, warn_func, arg=None):
+ """
+ Register error and warning handlers for Schema validation.
+ These will be called back as f(msg,arg)
+ """
+ libxml2mod.xmlSchemaSetValidErrors(self._o, err_func, warn_func, arg)
+
+
+class relaxNgValidCtxtCore:
+
+ def __init__(self, *args, **kw):
+ pass
+
+ def setValidityErrorHandler(self, err_func, warn_func, arg=None):
+ """
+ Register error and warning handlers for RelaxNG validation.
+ These will be called back as f(msg,arg)
+ """
+ libxml2mod.xmlRelaxNGSetValidErrors(self._o, err_func, warn_func, arg)
+
+
def _xmlTextReaderErrorFunc((f,arg),msg,severity,locator):
"""Intermediate callback to wrap the locator"""
return f(arg,msg,severity,xmlTextReaderLocator(locator))
diff --git a/python/libxml2-py.c b/python/libxml2-py.c
index b704cd1..f0821d2 100644
--- a/python/libxml2-py.c
+++ b/python/libxml2-py.c
@@ -7738,22 +7738,6 @@ libxml_xmlXPathNewNodeSet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
#endif /* LIBXML_XPATH_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED
PyObject *
-libxml_xmlSchemaFreeValidCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
- xmlSchemaValidCtxtPtr ctxt;
- PyObject *pyobj_ctxt;
-
- if (!PyArg_ParseTuple(args, (char *)"O:xmlSchemaFreeValidCtxt", &pyobj_ctxt))
- return(NULL);
- ctxt = (xmlSchemaValidCtxtPtr) PySchemaValidCtxt_Get(pyobj_ctxt);
-
- xmlSchemaFreeValidCtxt(ctxt);
- Py_INCREF(Py_None);
- return(Py_None);
-}
-
-#endif /* LIBXML_SCHEMAS_ENABLED */
-#ifdef LIBXML_SCHEMAS_ENABLED
-PyObject *
libxml_xmlSchemaNewParserCtxt(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
xmlSchemaParserCtxtPtr c_retval;
diff --git a/python/setup.py b/python/setup.py
index 748c1a8..e1e1cdb 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -226,7 +226,7 @@ else:
setup (name = "libxml2-python",
# On *nix, the version number is created from setup.py.in
# On windows, it is set by configure.js
- version = "2.6.18",
+ version = "2.6.19",
description = descr,
author = "Daniel Veillard",
author_email = "veillard@redhat.com",
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index f41cd6d..c6d03e9 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -39,7 +39,10 @@ PYTESTS= \
tstLastError.py \
indexes.py \
dtdvalid.py \
- tstmem.py
+ tstmem.py \
+ validDTD.py \
+ validSchemas.py \
+ validRNG.py
XMLS= \
tst.xml \
diff --git a/python/tests/Makefile.in b/python/tests/Makefile.in
index 2184681..6769fa1 100644
--- a/python/tests/Makefile.in
+++ b/python/tests/Makefile.in
@@ -295,7 +295,10 @@ PYTESTS = \
tstLastError.py \
indexes.py \
dtdvalid.py \
- tstmem.py
+ tstmem.py \
+ validDTD.py \
+ validSchemas.py \
+ validRNG.py
XMLS = \
tst.xml \
diff --git a/python/tests/validDTD.py b/python/tests/validDTD.py
new file mode 100755
index 0000000..1222f9f
--- /dev/null
+++ b/python/tests/validDTD.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python -u
+import libxml2
+import sys
+
+ARG = 'test string'
+
+class ErrorHandler:
+
+ def __init__(self):
+ self.errors = []
+
+ def handler(self, msg, data):
+ if data != ARG:
+ raise Exception, "Error handler did not receive correct argument"
+ self.errors.append(msg)
+
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+dtd="""<!ELEMENT foo EMPTY>"""
+valid="""<?xml version="1.0"?>
+<foo></foo>"""
+
+invalid="""<?xml version="1.0"?>
+<foo><bar/></foo>"""
+
+dtd = libxml2.parseDTD(None, 'test.dtd')
+ctxt = libxml2.newValidCtxt()
+e = ErrorHandler()
+ctxt.setValidityErrorHandler(e.handler, e.handler, ARG)
+
+# Test valid document
+doc = libxml2.parseDoc(valid)
+ret = doc.validateDtd(ctxt, dtd)
+if ret != 1 or e.errors:
+ print "error doing DTD validation"
+ sys.exit(1)
+doc.freeDoc()
+
+# Test invalid document
+doc = libxml2.parseDoc(invalid)
+ret = doc.validateDtd(ctxt, dtd)
+if ret != 0 or not e.errors:
+ print "Error: document supposed to be invalid"
+doc.freeDoc()
+
+dtd.freeDtd()
+del dtd
+del ctxt
+
+# Memory debug specific
+libxml2.cleanupParser()
+if libxml2.debugMemory(1) == 0:
+ print "OK"
+else:
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+ libxml2.dumpMemory()
+
diff --git a/python/tests/validRNG.py b/python/tests/validRNG.py
new file mode 100755
index 0000000..7022efe
--- /dev/null
+++ b/python/tests/validRNG.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python -u
+import libxml2
+import sys
+
+ARG = 'test string'
+
+class ErrorHandler:
+
+ def __init__(self):
+ self.errors = []
+
+ def handler(self, msg, data):
+ if data != ARG:
+ raise Exception, "Error handler did not receive correct argument"
+ self.errors.append(msg)
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+schema="""<?xml version="1.0"?>
+<element name="foo"
+ xmlns="http://relaxng.org/ns/structure/1.0"
+ xmlns:a="http://relaxng.org/ns/annotation/1.0"
+ xmlns:ex1="http://www.example.com/n1"
+ xmlns:ex2="http://www.example.com/n2">
+ <a:documentation>A foo element.</a:documentation>
+ <element name="ex1:bar1">
+ <empty/>
+ </element>
+ <element name="ex2:bar2">
+ <empty/>
+ </element>
+</element>
+"""
+
+valid="""<?xml version="1.0"?>
+<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>"""
+
+invalid="""<?xml version="1.0"?>
+<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1">bad</pre1:bar1><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>"""
+
+rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
+rngs = rngp.relaxNGParse()
+ctxt = rngs.relaxNGNewValidCtxt()
+e = ErrorHandler()
+ctxt.setValidityErrorHandler(e.handler, e.handler, ARG)
+
+# Test valid document
+doc = libxml2.parseDoc(valid)
+ret = doc.relaxNGValidateDoc(ctxt)
+if ret != 0 or e.errors:
+ print "error doing RelaxNG validation"
+ sys.exit(1)
+doc.freeDoc()
+
+# Test invalid document
+doc = libxml2.parseDoc(invalid)
+ret = doc.relaxNGValidateDoc(ctxt)
+if ret == 0 or not e.errors:
+ print "Error: document supposed to be RelaxNG invalid"
+ sys.exit(1)
+doc.freeDoc()
+
+del rngp
+del rngs
+del ctxt
+libxml2.relaxNGCleanupTypes()
+
+# Memory debug specific
+libxml2.cleanupParser()
+if libxml2.debugMemory(1) == 0:
+ print "OK"
+else:
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+ libxml2.dumpMemory()
+
diff --git a/python/tests/validSchemas.py b/python/tests/validSchemas.py
new file mode 100755
index 0000000..d4d62b2
--- /dev/null
+++ b/python/tests/validSchemas.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python -u
+import libxml2
+import sys
+
+ARG = 'test string'
+
+class ErrorHandler:
+
+ def __init__(self):
+ self.errors = []
+
+ def handler(self, msg, data):
+ if data != ARG:
+ raise Exception, "Error handler did not receive correct argument"
+ self.errors.append(msg)
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+schema="""<?xml version="1.0" encoding="iso-8859-1"?>
+<schema xmlns = "http://www.w3.org/2001/XMLSchema">
+ <element name = "Customer">
+ <complexType>
+ <sequence>
+ <element name = "FirstName" type = "string" />
+ <element name = "MiddleInitial" type = "string" />
+ <element name = "LastName" type = "string" />
+ </sequence>
+ <attribute name = "customerID" type = "integer" />
+ </complexType>
+ </element>
+</schema>"""
+
+valid="""<?xml version="1.0" encoding="iso-8859-1"?>
+<Customer customerID = "24332">
+ <FirstName>Raymond</FirstName>
+ <MiddleInitial>G</MiddleInitial>
+ <LastName>Bayliss</LastName>
+</Customer>
+"""
+
+invalid="""<?xml version="1.0" encoding="iso-8859-1"?>
+<Customer customerID = "24332">
+ <MiddleInitial>G</MiddleInitial>
+ <LastName>Bayliss</LastName>
+</Customer>
+"""
+
+e = ErrorHandler()
+ctxt_parser = libxml2.schemaNewMemParserCtxt(schema, len(schema))
+ctxt_schema = ctxt_parser.schemaParse()
+ctxt_valid = ctxt_schema.schemaNewValidCtxt()
+ctxt_valid.setValidityErrorHandler(e.handler, e.handler, ARG)
+
+# Test valid document
+doc = libxml2.parseDoc(valid)
+ret = doc.schemaValidateDoc(ctxt_valid)
+if ret != 0 or e.errors:
+ print "error doing schema validation"
+ sys.exit(1)
+doc.freeDoc()
+
+# Test invalid document
+doc = libxml2.parseDoc(invalid)
+ret = doc.schemaValidateDoc(ctxt_valid)
+if ret == 0 or not e.errors:
+ print "Error: document supposer to be schema invalid"
+ sys.exit(1)
+doc.freeDoc()
+
+del ctxt_parser
+del ctxt_schema
+del ctxt_valid
+libxml2.schemaCleanupTypes()
+
+# Memory debug specific
+libxml2.cleanupParser()
+if libxml2.debugMemory(1) == 0:
+ print "OK"
+else:
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+ libxml2.dumpMemory()
+