@@ -90,18 +90,18 @@ def _get_intermediate_items(cls, item):
9090 raise NotImplementedError ("To be implemented in subclass" )
9191
9292
93- def traverse ( self , predicate = lambda i : True ,
94- prune = lambda i : False , depth = - 1 , branch_first = True ,
93+ def traverse ( self , predicate = lambda i , d : True ,
94+ prune = lambda i , d : False , depth = - 1 , branch_first = True ,
9595 visit_once = True , ignore_self = 1 ):
9696 """
9797 ``Returns``
9898 iterator yieling of items found when traversing self
9999
100100 ``predicate``
101- f(i) returns False if item i should not be included in the result
101+ f(i,d ) returns False if item i at depth d should not be included in the result
102102
103103 ``prune``
104- f(i) return True if the search should stop at item i.
104+ f(i,d ) return True if the search should stop at item i at depth d .
105105 Item i will not be returned.
106106
107107 ``depth``
@@ -132,11 +132,11 @@ def addToStack( stack, lst, branch_first, dpth ):
132132 while stack :
133133 d , item = stack .pop () # depth of item, item
134134
135- if prune ( item ):
135+ if prune ( item , d ):
136136 continue
137137
138138 skipStartItem = ignore_self and ( item == self )
139- if not skipStartItem and predicate ( item ):
139+ if not skipStartItem and predicate ( item , d ):
140140 yield item
141141
142142 # only continue to next level if this is appropriate !
0 commit comments