Anonymous avatar Anonymous committed 2175b89

Tree - Add element only iterator

Comments (0)

Files changed (2)


     l = list(elem.itertext())
     assert len(l) == 1
+def test_Element_iter_elements():
+    elem = Element(u'a')
+    assert len(list(elem.iter_elements())) == 0
+    elem.append(Element(u'c'))
+    assert len(list(elem.iter_elements())) == 1
+    elem.append(u'b')
+    assert len(list(elem.iter_elements())) == 1
 def test_Comment():
     elem = Comment(u'a')
     assert serialize(elem) == u'<!--a-->'


             elif isinstance(e, basestring):
                 yield e
+    def iter_elements(self):
+        """
+        Creates an interator over all direct element children.
+        """
+        for child in self._children:
+            if child.__class__ is Element:
+                yield child
 # Subelement factory.  This function creates an element instance, and
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.