fixed xmlHasNsProp() bugs for defaulted from DTD attribs, added a specific
* tree.c python/tests/Makefile.am python/tests/attribs.py:
fixed xmlHasNsProp() bugs for defaulted from DTD attribs,
added a specific regression test
* python/generator.py: xmlHasNsProp() and xmlHasProp() shall
not raise exceptions when failing to find the attribute.
Daniel
diff --git a/python/generator.py b/python/generator.py
index dbfc5f7..e4618d1 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -551,6 +551,11 @@
"URI": "xmlFreeURI",
}
+functions_noexcept = {
+ "xmlHasProp": 1,
+ "xmlHasNsProp": 1,
+}
+
function_classes = {}
function_classes["None"] = []
@@ -675,6 +680,7 @@
global primary_classes
global classes_ancestor
global classes_destructors
+ global functions_noexcept
for type in classes_type.keys():
function_classes[classes_type[type][2]] = []
@@ -799,7 +805,9 @@
#
# Raise an exception
#
- if string.find(name, "URI") >= 0:
+ if functions_noexcept.has_key(name):
+ classes.write(" if ret == None:return None\n");
+ elif string.find(name, "URI") >= 0:
classes.write(
" if ret == None:raise uriError('%s() failed')\n"
% (name))
@@ -912,7 +920,10 @@
#
# Raise an exception
#
- if string.find(name, "URI") >= 0:
+ if functions_noexcept.has_key(name):
+ classes.write(
+ " if ret == None:return None\n");
+ elif string.find(name, "URI") >= 0:
classes.write(
" if ret == None:raise uriError('%s() failed')\n"
% (name))
@@ -935,7 +946,10 @@
#
# Raise an exception
#
- if string.find(name, "URI") >= 0:
+ if functions_noexcept.has_key(name):
+ classes.write(
+ " if ret == None:return None");
+ elif string.find(name, "URI") >= 0:
classes.write(
" if ret == None:raise uriError('%s() failed')\n"
% (name))
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index b8ee7b7..9a326e4 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -2,6 +2,7 @@
PYTESTS= \
build.py \
+ attribs.py \
tst.py \
tstxpath.py \
xpathext.py \
diff --git a/python/tests/attribs.py b/python/tests/attribs.py
new file mode 100755
index 0000000..9331a27
--- /dev/null
+++ b/python/tests/attribs.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python -u
+import sys
+import libxml2
+
+# Memory debug specific
+libxml2.debugMemory(1)
+
+#
+# Testing XML document serialization
+#
+doc = libxml2.parseDoc(
+"""<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE test [
+<!ELEMENT test (#PCDATA) >
+<!ATTLIST test xmlns:abc CDATA #FIXED "http://abc.org" >
+<!ATTLIST test abc:attr CDATA #FIXED "def" >
+]>
+<test />
+""")
+elem = doc.getRootElement()
+attr = elem.hasNsProp('attr', 'http://abc.org')
+if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""":
+ print "Failed to find defaulted attribute abc:attr"
+ sys.exit(1)
+
+doc.freeDoc()
+
+# Memory debug specific
+libxml2.cleanupParser()
+if libxml2.debugMemory(1) == 0:
+ print "OK"
+else:
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
+ libxml2.dumpMemory()