summaryrefslogtreecommitdiff
path: root/tree.py
diff options
context:
space:
mode:
authorsyt <syt@localhost.localdomain>2006-11-23 15:37:29 +0100
committersyt <syt@localhost.localdomain>2006-11-23 15:37:29 +0100
commit1bfddfdb575c57d6383efefdb13a44ccd56b3be1 (patch)
tree98c4d05d03664d0893bb672207dacc639bbc301f /tree.py
parentc642a7e6d32438bc78947b6f967a6118f3fa0650 (diff)
downloadlogilab-common-1bfddfdb575c57d6383efefdb13a44ccd56b3be1.tar.gz
make Node iterable
Diffstat (limited to 'tree.py')
-rw-r--r--tree.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/tree.py b/tree.py
index f8c0828..a69a851 100644
--- a/tree.py
+++ b/tree.py
@@ -19,6 +19,7 @@
import sys
+from logilab.common import flatten
from logilab.common.visitor import VisitedMixIn, FilteredIterator, no_filter
## Exceptions #################################################################
@@ -182,16 +183,14 @@ class Node :
else:
return [self]
+ def __iter__(self):
+ return iter(self.children)
+
def flatten(self, _list=None):
"""
return a list with all the nodes descendant from this node
"""
- if _list is None:
- _list = []
- _list.append(self)
- for c in self.children:
- c.flatten(_list)
- return _list
+ return flatten(self)
def lineage(self):
"""