Changeset 1506:f40b9f6738d0


Ignore:
Timestamp:
Jun 7, 2014, 10:06:24 AM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Added support for `followlinks` in `FTPHost.walk` (ticket #73).
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1502 r1506  
    846846        return self._stat._stat(path, _exception_for_missing_path)
    847847
    848     def walk(self, top, topdown=True, onerror=None):
     848    def walk(self, top, topdown=True, onerror=None, followlinks=False):
    849849        """
    850850        Iterate over directory tree and return a tuple (dirpath,
    851851        dirnames, filenames) on each iteration, like the `os.walk`
    852         function (see http://docs.python.org/lib/os-file-dir.html ).
     852        function (see https://docs.python.org/library/os.html#os.walk ).
    853853        """
    854854        top = ftputil.tool.as_unicode(top)
     
    871871        for name in dirs:
    872872            path = self.path.join(top, name)
    873             if not self.path.islink(path):
    874                 for item in self.walk(path, topdown, onerror):
     873            if followlinks or not self.path.islink(path):
     874                for item in self.walk(path, topdown, onerror, followlinks):
    875875                    yield item
    876876        if not topdown:
  • test/test_real_ftp.py

    r1505 r1506  
    391391          ]
    392392        self._walk_test(expected_result, top="walk_test", topdown=False)
     393
     394    def test_walk_following_links(self):
     395        # Preparation: build tree in directory `walk_test`.
     396        expected_result = [
     397          ("walk_test",
     398           ["dir1", "dir2", "dir3"],
     399           ["file4"]),
     400
     401          ("walk_test/dir1",
     402           ["dir11", "dir12"],
     403           []),
     404
     405          ("walk_test/dir1/dir11",
     406           [],
     407           []),
     408
     409          ("walk_test/dir1/dir12",
     410           ["dir123"],
     411           ["file121", "file122"]),
     412
     413          ("walk_test/dir1/dir12/dir123",
     414           [],
     415           ["file1234"]),
     416
     417          ("walk_test/dir2",
     418           [],
     419           []),
     420
     421          ("walk_test/dir3",
     422           ["dir31", "dir32"],
     423           ["file31", "file32"]),
     424
     425          ("walk_test/dir3/dir31",
     426           [],
     427           []),
     428
     429          ("walk_test/dir3/dir32",
     430           [],
     431           ["file1234"]),
     432          ]
     433        self._walk_test(expected_result, top="walk_test", followlinks=True)
    393434
    394435
Note: See TracChangeset for help on using the changeset viewer.