summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-02-03 16:53:19 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-02-03 16:53:19 +0000
commit26f1dcc5bda9fbd0711bd93f72ed20d4eaec3cbf (patch)
tree6fba6d67a5e6c9193a9df3f8dd5004a44eb177ec
parent3ce5257b293ed75d8feb18ed7ab18ea2b52510bd (diff)
downloadlibxml2-26f1dcc5bda9fbd0711bd93f72ed20d4eaec3cbf.tar.gz
more accessor classes for the parser context, allow to switch on and check
* python/TODO python/generator.py python/libxml2-python-api.xml python/libxml2class.txt: more accessor classes for the parser context, allow to switch on and check validity * python/tests/Makefile.am python/tests/error.py python/tests/invalid.xml python/tests/valid.xml python/tests/validate.py: attded more test and and added error.py which I forgot to commit in the last step Daniel
-rw-r--r--ChangeLog10
-rw-r--r--python/TODO2
-rwxr-xr-xpython/generator.py18
-rw-r--r--python/libxml2-python-api.xml42
-rw-r--r--python/libxml2class.txt7
-rw-r--r--python/tests/Makefile.am5
-rwxr-xr-xpython/tests/error.py30
-rw-r--r--python/tests/invalid.xml6
-rw-r--r--python/tests/valid.xml4
-rwxr-xr-xpython/tests/validate.py72
10 files changed, 189 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 800e435d..ba6c7876 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sun Feb 3 17:50:46 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+ * python/TODO python/generator.py python/libxml2-python-api.xml
+ python/libxml2class.txt: more accessor classes for the parser
+ context, allow to switch on and check validity
+ * python/tests/Makefile.am python/tests/error.py
+ python/tests/invalid.xml python/tests/valid.xml
+ python/tests/validate.py: attded more test and and added error.py
+ which I forgot to commit in the last step
+
Sun Feb 3 16:03:55 CET 2002 Daniel Veillard <daniel@veillard.com>
* python/Makefile.am python/types.c: cleanup
diff --git a/python/TODO b/python/TODO
index 40fadf9a..d1799fb5 100644
--- a/python/TODO
+++ b/python/TODO
@@ -41,5 +41,7 @@ Done:
found.
- error redirections and preformat
- handling of node.content
+- access to xmlParserCtxt and push mode
+ - needed for SAX too
Daniel Veillard
diff --git a/python/generator.py b/python/generator.py
index 587528ae..3d282004 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -341,7 +341,11 @@ def print_function_wrapper(name, output, export, include):
format = format + ":%s" % (name)
if ret[0] == 'void':
- c_call = "\n %s(%s);\n" % (name, c_call);
+ if file == "python_accessor":
+ c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
+ args[1][0])
+ else:
+ c_call = "\n %s(%s);\n" % (name, c_call);
ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n"
elif py_types.has_key(ret[0]):
(f, t, n, c) = py_types[ret[0]]
@@ -552,6 +556,9 @@ def nameFixup(function, classe, type, file):
elif name[0:12] == "xmlParserGet" and file == "python_accessor":
func = name[12:]
func = string.lower(func[0:1]) + func[1:]
+ elif name[0:12] == "xmlParserSet" and file == "python_accessor":
+ func = name[12:]
+ func = string.lower(func[0:1]) + func[1:]
elif name[0:l] == classe:
func = name[l:]
func = string.lower(func[0:1]) + func[1:]
@@ -627,6 +634,11 @@ txt.write(" Generated Classes for libxml2-python\n\n")
def functionCompare(info1, info2):
(index1, func1, name1, ret1, args1, file1) = info1
(index2, func2, name2, ret2, args2, file2) = info2
+ if file1 == file2:
+ if func1 < func2:
+ return -1
+ if func1 > func2:
+ return 1
if file1 == "python_accessor":
return -1
if file2 == "python_accessor":
@@ -635,10 +647,6 @@ def functionCompare(info1, info2):
return -1
if file1 > file2:
return 1
- if func1 < func2:
- return -1
- if func1 > func2:
- return 1
return 0
def writeDoc(name, args, indent, output):
diff --git a/python/libxml2-python-api.xml b/python/libxml2-python-api.xml
index ec76f6ed..2c5eb048 100644
--- a/python/libxml2-python-api.xml
+++ b/python/libxml2-python-api.xml
@@ -31,7 +31,47 @@
<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"/>
- <arg name='ctxt' type='xmlParserCtxtPtr' info='the SAX callback object or None'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ </function>
+ <function name='xmlParserGetWellFormed' file='python_accessor'>
+ <info>Get the well formed information from a parser context.</info>
+ <return type='int' info="the wellFormed field" field="wellFormed"/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ </function>
+ <function name='xmlParserGetIsValid' file='python_accessor'>
+ <info>Get the validity information from a parser context.</info>
+ <return type='int' info="the valid field" field="valid"/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ </function>
+ <function name='xmlParserSetValidate' file='python_accessor'>
+ <info>Switch the parser to validation mode.</info>
+ <return type='void'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ <arg name='validate' type='int' info='1 to activate validation'/>
+ </function>
+ <function name='xmlParserSetReplaceEntities' file='python_accessor'>
+ <info>Switch the parser to replace entities.</info>
+ <return type='void'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ <arg name='replaceEntities' type='int' info='1 to replace entities'/>
+ </function>
+ <function name='xmlParserSetPedantic' file='python_accessor'>
+ <info>Switch the parser to be pedantic.</info>
+ <return type='void'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ <arg name='pedantic' type='int' info='1 to run in pedantic mode'/>
+ </function>
+ <function name='xmlParserSetLoadSubset' file='python_accessor'>
+ <info>Switch the parser to load the DTD without validating.</info>
+ <return type='void'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ <arg name='loadsubset' type='int' info='1 to load the DTD'/>
+ </function>
+ <function name='xmlParserSetLineNumbers' file='python_accessor'>
+ <info>Switch on the generation of line number for elements nodes.</info>
+ <return type='void'/>
+ <arg name='ctxt' type='xmlParserCtxtPtr' info='the parser context'/>
+ <arg name='linenumbers' type='int' info='1 to save line numbers'/>
</function>
</symbols>
</api>
diff --git a/python/libxml2class.txt b/python/libxml2class.txt
index d952c2c5..374fe485 100644
--- a/python/libxml2class.txt
+++ b/python/libxml2class.txt
@@ -333,6 +333,13 @@ Class xmlElement(xmlNode)
Class parserCtxt()
# accessors
doc()
+ isValid()
+ lineNumbers()
+ loadSubset()
+ pedantic()
+ replaceEntities()
+ validate()
+ wellFormed()
# functions from module parser
clearParserCtxt()
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index b8e9cec8..76bf897e 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -6,10 +6,13 @@ TESTS= \
xpathext.py \
push.py \
error.py \
+ validate.py \
xpath.py
XMLS= \
- tst.xml
+ tst.xml \
+ valid.xml \
+ invalid.xml
EXTRA_DIST = $(TESTS) $(XMLS)
diff --git a/python/tests/error.py b/python/tests/error.py
new file mode 100755
index 00000000..21cf5589
--- /dev/null
+++ b/python/tests/error.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python -u
+#
+# This test exercise the redirection of error messages with a
+# functions defined in Python.
+#
+import sys
+import libxml2
+
+expect='--> warning: --> failed to load external entity "missing.xml"\n'
+err=""
+def callback(ctx, str):
+ global err
+
+ err = err + "%s %s" % (ctx, str)
+
+libxml2.registerErrorHandler(callback, "-->")
+doc = libxml2.parseFile("missing.xml")
+if err != expect:
+ print "error"
+ print "received %s" %(err)
+ print "expected %s" %(expect)
+ sys.exit(1)
+
+i = 10000
+while i > 0:
+ doc = libxml2.parseFile("missing.xml")
+ err = ""
+ i = i - 1
+
+print "OK"
diff --git a/python/tests/invalid.xml b/python/tests/invalid.xml
new file mode 100644
index 00000000..7c9b27e4
--- /dev/null
+++ b/python/tests/invalid.xml
@@ -0,0 +1,6 @@
+<!DOCTYPE doc [
+<!ELEMENT doc (a, b, a)>
+<!ELEMENT a EMPTY>
+<!ELEMENT b EMPTY>
+]>
+<doc><b/><a/><b/></doc>
diff --git a/python/tests/valid.xml b/python/tests/valid.xml
new file mode 100644
index 00000000..8a7f679f
--- /dev/null
+++ b/python/tests/valid.xml
@@ -0,0 +1,4 @@
+<!DOCTYPE doc [
+<!ELEMENT doc EMPTY>
+]>
+<doc/>
diff --git a/python/tests/validate.py b/python/tests/validate.py
new file mode 100755
index 00000000..5762f609
--- /dev/null
+++ b/python/tests/validate.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python -u
+import sys
+import libxml2
+
+ctxt = libxml2.createFileParserCtxt("valid.xml")
+ctxt.validate(1)
+ctxt.parseDocument()
+doc = ctxt.doc()
+valid = ctxt.isValid()
+
+if doc.name != "valid.xml":
+ print "doc.name failed"
+ sys.exit(1)
+root = doc.children
+if root.name != "doc":
+ print "root.name failed"
+ sys.exit(1)
+if valid != 1:
+ print "validity chec failed"
+ sys.exit(1)
+doc.freeDoc()
+
+i = 1000
+while i > 0:
+ ctxt = libxml2.createFileParserCtxt("valid.xml")
+ ctxt.validate(1)
+ ctxt.parseDocument()
+ doc = ctxt.doc()
+ valid = ctxt.isValid()
+ doc.freeDoc()
+ if valid != 1:
+ print "validity check failed"
+ sys.exit(1)
+ i = i - 1
+
+#desactivate error messages from the validation
+def noerr(ctx, str):
+ pass
+
+libxml2.registerErrorHandler(noerr, None)
+
+ctxt = libxml2.createFileParserCtxt("invalid.xml")
+ctxt.validate(1)
+ctxt.parseDocument()
+doc = ctxt.doc()
+valid = ctxt.isValid()
+if doc.name != "invalid.xml":
+ print "doc.name failed"
+ sys.exit(1)
+root = doc.children
+if root.name != "doc":
+ print "root.name failed"
+ sys.exit(1)
+if valid != 0:
+ print "validity chec failed"
+ sys.exit(1)
+doc.freeDoc()
+
+i = 1000
+while i > 0:
+ ctxt = libxml2.createFileParserCtxt("invalid.xml")
+ ctxt.validate(1)
+ ctxt.parseDocument()
+ doc = ctxt.doc()
+ valid = ctxt.isValid()
+ doc.freeDoc()
+ if valid != 0:
+ print "validity check failed"
+ sys.exit(1)
+ i = i - 1
+
+print "OK"