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 + + * 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 * 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 @@ Get the document tree from a parser context. - + + + + Get the well formed information from a parser context. + + + + + Get the validity information from a parser context. + + + + + Switch the parser to validation mode. + + + + + + Switch the parser to replace entities. + + + + + + Switch the parser to be pedantic. + + + + + + Switch the parser to load the DTD without validating. + + + + + + Switch on the generation of line number for elements nodes. + + + 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 @@ + + + +]> + 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 @@ + +]> + 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"