Ticket #3044: filepath.py.diff
| File filepath.py.diff, 1.9 KB (added by djfroofy, 3 years ago) |
|---|
-
twisted/python/filepath.py
176 176 raise UnlistableError(ose) 177 177 return map(self.child, subnames) 178 178 179 def walk(self ):179 def walk(self, exclude=None): 180 180 """ 181 181 Yield myself, then each of my children, and each of those children's 182 182 children in turn. 183 183 184 @param exclude: optional list of directory base names to exclude in 185 traversal. (Note: the root directory is traversed regardless of 186 values in exclude) 187 184 188 @return: a generator yielding FilePath-like objects. 185 189 """ 186 190 yield self 191 exclude = exclude or [] 187 192 if self.isdir(): 188 193 for c in self.children(): 189 for subc in c.walk(): 194 if c.isdir() and c.basename() in exclude: 195 continue 196 for subc in c.walk(exclude=exclude): 190 197 yield subc 191 198 192 199 def sibling(self, path): -
twisted/test/test_paths.py
73 73 x.sort() 74 74 self.assertEquals(x, self.all) 75 75 76 def test_walkExclusions(self): 77 """Verify that directories we declure for exclusion are actually excluded. 78 """ 79 sub3 = self.path.child('sub3') 80 for p in self.path.walk(exclude=['sub3']): 81 if p == sub3 or p in sub3.children(): 82 self.fail('Should not have encountered sub3 or children in walk') 83 84 76 85 def test_validSubdir(self): 77 86 """Verify that a valid subdirectory will show up as a directory, but not as a 78 87 file, not as a symlink, and be listable.
