mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-24 21:33:51 +03:00
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
This commit is contained in:
parent
3ce5257b29
commit
26f1dcc5bd
10
ChangeLog
10
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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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>
|
||||
|
@ -333,6 +333,13 @@ Class xmlElement(xmlNode)
|
||||
Class parserCtxt()
|
||||
# accessors
|
||||
doc()
|
||||
isValid()
|
||||
lineNumbers()
|
||||
loadSubset()
|
||||
pedantic()
|
||||
replaceEntities()
|
||||
validate()
|
||||
wellFormed()
|
||||
|
||||
# functions from module parser
|
||||
clearParserCtxt()
|
||||
|
@ -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)
|
||||
|
||||
|
30
python/tests/error.py
Executable file
30
python/tests/error.py
Executable file
@ -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"
|
6
python/tests/invalid.xml
Normal file
6
python/tests/invalid.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE doc [
|
||||
<!ELEMENT doc (a, b, a)>
|
||||
<!ELEMENT a EMPTY>
|
||||
<!ELEMENT b EMPTY>
|
||||
]>
|
||||
<doc><b/><a/><b/></doc>
|
4
python/tests/valid.xml
Normal file
4
python/tests/valid.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<!DOCTYPE doc [
|
||||
<!ELEMENT doc EMPTY>
|
||||
]>
|
||||
<doc/>
|
72
python/tests/validate.py
Executable file
72
python/tests/validate.py
Executable file
@ -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"
|
Loading…
Reference in New Issue
Block a user