Use generators for Node.getChildNodes()

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1013 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-01-17 13:28:44 +00:00
parent e3595e882a
commit 324a992a98
2 changed files with 13 additions and 10 deletions

View file

@ -165,7 +165,7 @@ What is returned by these may be controlled by the nodeType attribute:
True True
>>> m111.nodeType = 'info' >>> m111.nodeType = 'info'
>>> m112.nodeType = 'text' >>> m112.nodeType = 'text'
>>> len(m11.getChildNodes('text')) >>> len(list(m11.getChildNodes('text')))
1 1
There are also shortcut methods to retrieve certain types of nodes There are also shortcut methods to retrieve certain types of nodes
@ -181,17 +181,17 @@ in a simple and logical way:
True True
>>> m112.getPage() is m11 >>> m112.getPage() is m11
True True
>>> len(m1.getMenuItems()) >>> len(list(m1.getMenuItems()))
1 1
>>> len(m11.getMenuItems()) >>> len(list(m11.getMenuItems()))
0 0
>>> len(m111.getMenuItems()) >>> len(list(m111.getMenuItems()))
0 0
>>> len(m1.getTextItems()) >>> len(list(m1.getTextItems()))
0 0
>>> len(m11.getTextItems()) >>> len(list(m11.getTextItems()))
1 1
>>> len(m111.getTextItems()) >>> len(list(m111.getTextItems()))
0 0
Targets Targets

View file

@ -104,9 +104,12 @@ class Node(View, OrderedContainer):
return None return None
def getChildNodes(self, nodeTypes=None): def getChildNodes(self, nodeTypes=None):
return [item for item in self.values() for item in self.values():
if INode.providedBy(item) if INode.providedBy(item) \
and (not nodeTypes or item.nodeType in nodeTypes)] and (not nodeTypes or item.nodeType in nodeTypes):
yield item
else:
continue
def getMenu(self): def getMenu(self):
return self.nodeType == 'menu' and self or self.getParentNode(['menu']) return self.nodeType == 'menu' and self or self.getParentNode(['menu'])