1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

updated the python bindings, added code for easier File I/O, and the

* python/generator.py python/libxml.c python/libxml.py
  python/libxml2-python-api.xml python/libxml2class.txt
  python/libxml_wrap.h python/types.c: updated the python
  bindings, added code for easier File I/O, and the ability to
  define a resolver from Python fixing bug #91635
* python/tests/Makefile.am python/tests/inbuf.py
  python/tests/outbuf.py python/tests/pushSAXhtml.py
  python/tests/resolver.py python/tests/serialize.py: updated
  and augmented the set of Python tests.
Daniel
This commit is contained in:
Daniel Veillard
2002-09-12 15:00:57 +00:00
parent 353bf5822a
commit c6d4a933f0
14 changed files with 677 additions and 12 deletions

View File

@ -15,7 +15,10 @@ PYTESTS= \
tstURI.py \
cutnpaste.py\
xpathret.py \
xpath.py
xpath.py \
outbuf.py \
inbuf.py \
resolver.py
XMLS= \
tst.xml \

25
python/tests/inbuf.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python -u
import sys
import libxml2
import StringIO
# Memory debug specific
libxml2.debugMemory(1)
i = 0
while i < 5000:
f = StringIO.StringIO("foobar")
buf = libxml2.inputBuffer(f)
i = i + 1
del f
del buf
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()

33
python/tests/outbuf.py Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python -u
import sys
import libxml2
import StringIO
print "Skipped"
sys.exit(1)
# Memory debug specific
libxml2.debugMemory(1)
#f = open('res', 'w')
f = StringIO.StringIO()
buf = libxml2.createOutputBuffer(f, "ISO-8859-1")
buf.write(3, "foo")
buf.writeString("bar")
buf.close()
del buf
if f.getvalue() != "foobar":
print "Failed to save to StringIO"
sys.exit(1)
del f
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()

View File

@ -49,7 +49,8 @@ chunk = "ar</foo>"
ctxt.htmlParseChunk(chunk, len(chunk), 1)
ctxt=None
reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:"
reference = """startDocument:startElement html None:startElement body None:startElement foo {'url': 'tst'}:error: Tag foo invalid
:characters: bar:endElement foo:endElement body:endElement html:endDocument:"""
if log != reference:
print "Error got: %s" % log
print "Exprected: %s" % reference

39
python/tests/resolver.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python -u
import sys
import libxml2
import StringIO
# Memory debug specific
libxml2.debugMemory(1)
def myResolver(URL, ID, ctxt):
return(StringIO.StringIO("<foo/>"))
libxml2.setEntityLoader(myResolver)
doc = libxml2.parseFile("doesnotexist.xml")
root = doc.children
if root.name != "foo":
print "root element name error"
sys.exit(1)
doc.freeDoc()
i = 0
while i < 5000:
doc = libxml2.parseFile("doesnotexist.xml")
root = doc.children
if root.name != "foo":
print "root element name error"
sys.exit(1)
doc.freeDoc()
i = i + 1
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()

View File

@ -76,7 +76,7 @@ if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http
sys.exit(1)
str = doc.serialize("ISO-8859-1")
if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Hello</title></head><body><p>hello</p></body></html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Hello</title></head><body><p>hello</p></body></html>
""":
print "error serializing HTML document 2"
sys.exit(1)
@ -84,7 +84,7 @@ str = doc.serialize(format=1)
if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello</title>
</head>
<body><p>hello</p></body>
@ -96,7 +96,7 @@ str = doc.serialize("iso-8859-1", 1)
if str != """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Hello</title>
</head>
<body><p>hello</p></body>
@ -115,13 +115,13 @@ if str != """<html><head><title>Hello</title></head><body><p>hello</p></body></h
print "error serializing HTML root 1"
sys.exit(1)
str = root.serialize("ISO-8859-1")
if str != """<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Hello</title></head><body><p>hello</p></body></html>""":
if str != """<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Hello</title></head><body><p>hello</p></body></html>""":
print "error serializing HTML root 2"
sys.exit(1)
str = root.serialize(format=1)
if str != """<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello</title>
</head>
<body><p>hello</p></body>
@ -131,7 +131,7 @@ if str != """<html>
str = root.serialize("iso-8859-1", 1)
if str != """<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Hello</title>
</head>
<body><p>hello</p></body>