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
diff --git a/python/TODO b/python/TODO
index 40fadf9..d1799fb 100644
--- a/python/TODO
+++ b/python/TODO
@@ -41,5 +41,7 @@
   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 587528a..3d28200 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -341,7 +341,11 @@
         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 @@
     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 @@
 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 @@
         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 ec76f6e..2c5eb04 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 d952c2c..374fe48 100644
--- a/python/libxml2class.txt
+++ b/python/libxml2class.txt
@@ -333,6 +333,13 @@
 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 b8e9cec..76bf897 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -6,10 +6,13 @@
     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 0000000..21cf558
--- /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 0000000..7c9b27e
--- /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 0000000..8a7f679
--- /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 0000000..5762f60
--- /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"