changeset 26:eeb0eb69c1da

Fix namespace uri in XML parser. * emeraldtree/ElementTree.py - Add QName.__repr__. - Use namespace uri correctly in QName generation. * emeraldtree/tests/test_ElementTree.py: Use different strings for all elements.
author Bastian Blank <bblank@thinkmo.de>
date Sun, 08 Jun 2008 12:40:21 +0200
parents 47ae505e63ea
children 4dc29d2eac0e
files emeraldtree/ElementTree.py emeraldtree/tests/test_ElementTree.py
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/emeraldtree/ElementTree.py	Sun Jun 08 12:09:33 2008 +0200
+++ b/emeraldtree/ElementTree.py	Sun Jun 08 12:40:21 2008 +0200
@@ -486,6 +486,9 @@
             text = text[i + 1:]
         self.name, self.uri = text, uri
 
+    def __repr__(self):
+        return '%s(%r, %r)' % (self.__class__.__name__, self.name, self.uri)
+
     def __str__(self):
         return self.text
 
@@ -1329,7 +1332,8 @@
         if key in self._names:
             return self._names[key].copy()
         if '}' in key:
-            name = QName(*key.split('}', 1))
+            uri, name = key.split('}', 1)
+            name = QName(name, uri)
         else:
             name = QName(key)
         self._names[key] = name
--- a/emeraldtree/tests/test_ElementTree.py	Sun Jun 08 12:09:33 2008 +0200
+++ b/emeraldtree/tests/test_ElementTree.py	Sun Jun 08 12:40:21 2008 +0200
@@ -166,18 +166,18 @@
     assert elem[2] == 'd'
 
 def test_XMLParser_namespace():
-    elem = XML('<a:a xmlns:a="a"/>')
+    elem = XML('<a:b xmlns:a="c"/>')
     assert isinstance(elem.tag, QName)
-    assert elem.tag == QName('a', 'a')
-    assert serialize(elem) == '<ns0:a xmlns:ns0="a" />'
+    assert elem.tag == QName('b', 'c')
+    assert serialize(elem) == '<ns0:b xmlns:ns0="c" />'
 
-    elem = XML('<a:a xmlns:a="a" a="a"/>')
-    assert elem.tag == QName('a', 'a')
-    assert elem.attrib == {'a': 'a'}
-    assert serialize(elem) == '<ns0:a a="a" xmlns:ns0="a" />'
+    elem = XML('<a:b xmlns:a="c" d="e"/>')
+    assert elem.tag == QName('b', 'c')
+    assert elem.attrib == {'d': 'e'}
+    assert serialize(elem) == '<ns0:b d="e" xmlns:ns0="c" />'
 
-    elem = XML('<a:a xmlns:a="a" a:a="a"/>')
-    assert elem.tag == QName('a', 'a')
-    assert elem.attrib == {QName('a', 'a'): 'a'}
-    assert serialize(elem) == '<ns0:a ns0:a="a" xmlns:ns0="a" />'
+    elem = XML('<a:b xmlns:a="c" a:d="e"/>')
+    assert elem.tag == QName('b', 'c')
+    assert elem.attrib == {QName('d', 'c'): 'e'}
+    assert serialize(elem) == '<ns0:b ns0:d="e" xmlns:ns0="c" />'