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
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index 3255141..435b5ac 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -15,7 +15,10 @@
tstURI.py \
cutnpaste.py\
xpathret.py \
- xpath.py
+ xpath.py \
+ outbuf.py \
+ inbuf.py \
+ resolver.py
XMLS= \
tst.xml \
diff --git a/python/tests/inbuf.py b/python/tests/inbuf.py
new file mode 100755
index 0000000..a7cc7a6
--- /dev/null
+++ b/python/tests/inbuf.py
@@ -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()
+
diff --git a/python/tests/outbuf.py b/python/tests/outbuf.py
new file mode 100755
index 0000000..ba8b25e
--- /dev/null
+++ b/python/tests/outbuf.py
@@ -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()
+
diff --git a/python/tests/pushSAXhtml.py b/python/tests/pushSAXhtml.py
index 43bf656..e6e89d9 100755
--- a/python/tests/pushSAXhtml.py
+++ b/python/tests/pushSAXhtml.py
@@ -49,7 +49,8 @@
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
diff --git a/python/tests/resolver.py b/python/tests/resolver.py
new file mode 100755
index 0000000..16174a0
--- /dev/null
+++ b/python/tests/resolver.py
@@ -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()
+
diff --git a/python/tests/serialize.py b/python/tests/serialize.py
index 984d4eb..d7226c4 100755
--- a/python/tests/serialize.py
+++ b/python/tests/serialize.py
@@ -76,7 +76,7 @@
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 @@
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 @@
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 @@
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 @@
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>