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:
parent
e3595e882a
commit
324a992a98
2 changed files with 13 additions and 10 deletions
14
README.txt
14
README.txt
|
@ -165,7 +165,7 @@ What is returned by these may be controlled by the nodeType attribute:
|
|||
True
|
||||
>>> m111.nodeType = 'info'
|
||||
>>> m112.nodeType = 'text'
|
||||
>>> len(m11.getChildNodes('text'))
|
||||
>>> len(list(m11.getChildNodes('text')))
|
||||
1
|
||||
|
||||
There are also shortcut methods to retrieve certain types of nodes
|
||||
|
@ -181,17 +181,17 @@ in a simple and logical way:
|
|||
True
|
||||
>>> m112.getPage() is m11
|
||||
True
|
||||
>>> len(m1.getMenuItems())
|
||||
>>> len(list(m1.getMenuItems()))
|
||||
1
|
||||
>>> len(m11.getMenuItems())
|
||||
>>> len(list(m11.getMenuItems()))
|
||||
0
|
||||
>>> len(m111.getMenuItems())
|
||||
>>> len(list(m111.getMenuItems()))
|
||||
0
|
||||
>>> len(m1.getTextItems())
|
||||
>>> len(list(m1.getTextItems()))
|
||||
0
|
||||
>>> len(m11.getTextItems())
|
||||
>>> len(list(m11.getTextItems()))
|
||||
1
|
||||
>>> len(m111.getTextItems())
|
||||
>>> len(list(m111.getTextItems()))
|
||||
0
|
||||
|
||||
Targets
|
||||
|
|
9
view.py
9
view.py
|
@ -104,9 +104,12 @@ class Node(View, OrderedContainer):
|
|||
return None
|
||||
|
||||
def getChildNodes(self, nodeTypes=None):
|
||||
return [item for item in self.values()
|
||||
if INode.providedBy(item)
|
||||
and (not nodeTypes or item.nodeType in nodeTypes)]
|
||||
for item in self.values():
|
||||
if INode.providedBy(item) \
|
||||
and (not nodeTypes or item.nodeType in nodeTypes):
|
||||
yield item
|
||||
else:
|
||||
continue
|
||||
|
||||
def getMenu(self):
|
||||
return self.nodeType == 'menu' and self or self.getParentNode(['menu'])
|
||||
|
|
Loading…
Add table
Reference in a new issue