Ticket #3044: filepath.py.diff

File filepath.py.diff, 1.9 kB (added by djfroofy, 1 year ago)

Patch for filepath and test_paths

  • twisted/python/filepath.py

     
    176176            raise UnlistableError(ose) 
    177177        return map(self.child, subnames) 
    178178 
    179     def walk(self): 
     179    def walk(self, exclude=None): 
    180180        """ 
    181181        Yield myself, then each of my children, and each of those children's 
    182182        children in turn. 
    183183 
     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 
    184188        @return: a generator yielding FilePath-like objects. 
    185189        """ 
    186190        yield self 
     191        exclude = exclude or [] 
    187192        if self.isdir(): 
    188193            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): 
    190197                    yield subc 
    191198 
    192199    def sibling(self, path): 
  • twisted/test/test_paths.py

     
    7373        x.sort() 
    7474        self.assertEquals(x, self.all) 
    7575 
     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 
    7685    def test_validSubdir(self): 
    7786        """Verify that a valid subdirectory will show up as a directory, but not as a 
    7887        file, not as a symlink, and be listable.