Changeset 1683:6f9cfd296288


Ignore:
Timestamp:
Oct 28, 2017, 10:55:10 PM (14 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Put `isdir` before `isfile`

Sort `isdir`, `isfile` and `islink` alphabetically. This is the same
order in that they're tested in the unit tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/path.py

    r1682 r1683  
    123123    # by the exception handling in `isfile`, `isdir` and `islink`.
    124124
     125    def isdir(self, path):
     126        """
     127        Return true if the `path` exists and corresponds to a
     128        directory (no link).
     129
     130        A non-existing path does _not_ cause a `PermanentError`.
     131        """
     132        path = ftputil.tool.as_unicode(path)
     133        # Workaround if we can't go up from the current directory.
     134        # The result from `getcwd` should already be normalized.
     135        if self.normpath(path) == self._host.getcwd():
     136            return True
     137        try:
     138            stat_result = self._host.stat(
     139                            path, _exception_for_missing_path=False)
     140        except ftputil.error.RecursiveLinksError:
     141            return False
     142        except ftputil.error.RootDirError:
     143            return True
     144        else:
     145            if stat_result is None:
     146                # Non-existent path
     147                return False
     148            else:
     149                return stat.S_ISDIR(stat_result.st_mode)
     150
    125151    def isfile(self, path):
    126152        """
     
    148174            else:
    149175                return stat.S_ISREG(stat_result.st_mode)
    150 
    151     def isdir(self, path):
    152         """
    153         Return true if the `path` exists and corresponds to a
    154         directory (no link).
    155 
    156         A non-existing path does _not_ cause a `PermanentError`.
    157         """
    158         path = ftputil.tool.as_unicode(path)
    159         # Workaround if we can't go up from the current directory.
    160         # The result from `getcwd` should already be normalized.
    161         if self.normpath(path) == self._host.getcwd():
    162             return True
    163         try:
    164             stat_result = self._host.stat(
    165                             path, _exception_for_missing_path=False)
    166         except ftputil.error.RecursiveLinksError:
    167             return False
    168         except ftputil.error.RootDirError:
    169             return True
    170         else:
    171             if stat_result is None:
    172                 # Non-existent path
    173                 return False
    174             else:
    175                 return stat.S_ISDIR(stat_result.st_mode)
    176176
    177177    def islink(self, path):
Note: See TracChangeset for help on using the changeset viewer.