changeset 38:6e38bcef6030

ElementTree - Make iterators return all childs
author Bastian Blank <bblank@thinkmo.de>
date Mon, 14 Jul 2008 15:25:30 +0200
parents 4bb8fc436265
children 5784bad989d1
files emeraldtree/ElementTree.py emeraldtree/tests/test_ElementTree.py
diffstat 2 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/emeraldtree/ElementTree.py	Mon Jul 14 15:03:10 2008 +0200
+++ b/emeraldtree/ElementTree.py	Mon Jul 14 15:25:30 2008 +0200
@@ -374,12 +374,9 @@
 
     def __iter__(self):
         """
-        Creates a element iterator.  The iterator loops over all (non text)
-        children.
+        Creates a element iterator.  The iterator loops over all children.
         """
-        for e in self._children:
-            if isinstance(e, Node):
-                yield e
+        return self._children.__iter__()
 
     ##
     # Creates a tree iterator.  The iterator loops over this element
@@ -403,8 +400,7 @@
             if isinstance(e, Element):
                 for e in e.iter(tag):
                     yield e
-            # TODO
-            elif isinstance(e, Node):
+            else:
                 yield e
 
     ##
--- a/emeraldtree/tests/test_ElementTree.py	Mon Jul 14 15:03:10 2008 +0200
+++ b/emeraldtree/tests/test_ElementTree.py	Mon Jul 14 15:25:30 2008 +0200
@@ -156,15 +156,15 @@
 
     elem.append('b')
     l = list(elem.iter())
-    assert len(l) == 1
+    assert len(l) == 2
 
     elem.append(Element('c'))
     l = list(elem.iter())
-    assert len(l) == 2
+    assert len(l) == 3
 
     elem.append('d')
     l = list(elem.iter())
-    assert len(l) == 2
+    assert len(l) == 4
 
 def test_Element_itertext():
     elem = Element('a')