Changeset 1000:4e6094ea32b7


Ignore:
Timestamp:
Nov 14, 2010, 11:32:01 PM (11 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Prepend underscore to `listdir`, `lstat` and `stat` in `ftp_stat.py`.

These have never been part of the documented ftputil API. The former
names without underscores might have misled developers to use the
seemingly public names.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ftp_stat.py

    r978 r1000  
    577577                raise
    578578
    579     def listdir(self, path):
     579    # Don't use these methods, but instead the corresponding methods
     580    #  in the `FTPHost` class.
     581    def _listdir(self, path):
    580582        """
    581583        Return a list of items in `path`.
     
    587589        return self.__call_with_parser_retry(self._real_listdir, path)
    588590
    589     def lstat(self, path, _exception_for_missing_path=True):
     591    def _lstat(self, path, _exception_for_missing_path=True):
    590592        """
    591593        Return a `StatResult` without following links.
     
    598600                                             _exception_for_missing_path)
    599601
    600     def stat(self, path, _exception_for_missing_path=True):
     602    def _stat(self, path, _exception_for_missing_path=True):
    601603        """
    602604        Return a `StatResult` with following links.
  • ftputil.py

    r997 r1000  
    817817        # Fail early if we get a unicode path which can't be encoded.
    818818        path = str(path)
    819         return self._stat.listdir(path)
     819        return self._stat._listdir(path)
    820820
    821821    def lstat(self, path, _exception_for_missing_path=True):
     
    833833        # Fail early if we get a unicode path which can't be encoded.
    834834        path = str(path)
    835         return self._stat.lstat(path, _exception_for_missing_path)
     835        return self._stat._lstat(path, _exception_for_missing_path)
    836836
    837837    def stat(self, path, _exception_for_missing_path=True):
     
    850850        # Fail early if we get a unicode path which can't be encoded.
    851851        path = str(path)
    852         return self._stat.stat(path, _exception_for_missing_path)
     852        return self._stat._stat(path, _exception_for_missing_path)
    853853
    854854    def walk(self, top, topdown=True, onerror=None):
  • test/test_ftp_stat.py

    r916 r1000  
    245245    def test_failing_lstat(self):
    246246        """Test whether lstat fails for a nonexistent path."""
    247         self.assertRaises(ftp_error.PermanentError, self.stat.lstat,
     247        self.assertRaises(ftp_error.PermanentError, self.stat._lstat,
    248248                          '/home/sschw/notthere')
    249         self.assertRaises(ftp_error.PermanentError, self.stat.lstat,
     249        self.assertRaises(ftp_error.PermanentError, self.stat._lstat,
    250250                          '/home/sschwarzer/notthere')
    251251
     
    256256        possible to do this for the root directory `/`.
    257257        """
    258         self.assertRaises(ftp_error.RootDirError, self.stat.lstat, '/')
     258        self.assertRaises(ftp_error.RootDirError, self.stat._lstat, '/')
    259259        try:
    260             self.stat.lstat('/')
     260            self.stat._lstat('/')
    261261        except ftp_error.RootDirError, exc_obj:
    262262            self.failIf(isinstance(exc_obj, ftp_error.FTPOSError))
     
    264264    def test_lstat_one_unix_file(self):
    265265        """Test `lstat` for a file described in Unix-style format."""
    266         stat_result = self.stat.lstat('/home/sschwarzer/index.html')
     266        stat_result = self.stat._lstat('/home/sschwarzer/index.html')
    267267        self.assertEqual(oct(stat_result.st_mode), '0100644')
    268268        self.assertEqual(stat_result.st_size, 4604)
     
    271271    def test_lstat_one_ms_file(self):
    272272        """Test `lstat` for a file described in DOS-style format."""
    273         stat_result = self.stat.lstat('/home/msformat/abcd.exe')
     273        stat_result = self.stat._lstat('/home/msformat/abcd.exe')
    274274        self.assertEqual(stat_result._st_mtime_precision, 60)
    275275
    276276    def test_lstat_one_unix_dir(self):
    277277        """Test `lstat` for a directory described in Unix-style format."""
    278         stat_result = self.stat.lstat('/home/sschwarzer/scios2')
     278        stat_result = self.stat._lstat('/home/sschwarzer/scios2')
    279279        self.assertEqual(oct(stat_result.st_mode), '042755')
    280280        self.assertEqual(stat_result.st_ino, None)
     
    295295    def test_lstat_one_ms_dir(self):
    296296        """Test `lstat` for a directory described in DOS-style format."""
    297         stat_result = self.stat.lstat('/home/msformat/WindowsXP')
     297        stat_result = self.stat._lstat('/home/msformat/WindowsXP')
    298298        self.assertEqual(stat_result._st_mtime_precision, 60)
    299299
    300300    def test_lstat_via_stat_module(self):
    301301        """Test `lstat` indirectly via `stat` module."""
    302         stat_result = self.stat.lstat('/home/sschwarzer/')
     302        stat_result = self.stat._lstat('/home/sschwarzer/')
    303303        self.failUnless(stat.S_ISDIR(stat_result.st_mode))
    304304
     
    306306        """Test `stat` when invoked on a link."""
    307307        # Simple link
    308         stat_result = self.stat.stat('/home/link')
     308        stat_result = self.stat._stat('/home/link')
    309309        self.assertEqual(stat_result.st_size, 4604)
    310310        # Link pointing to a link
    311         stat_result = self.stat.stat('/home/python/link_link')
     311        stat_result = self.stat._stat('/home/python/link_link')
    312312        self.assertEqual(stat_result.st_size, 4604)
    313         stat_result = self.stat.stat('../python/link_link')
     313        stat_result = self.stat._stat('../python/link_link')
    314314        self.assertEqual(stat_result.st_size, 4604)
    315315        # Recursive link structures
    316         self.assertRaises(ftp_error.PermanentError, self.stat.stat,
     316        self.assertRaises(ftp_error.PermanentError, self.stat._stat,
    317317                          '../python/bad_link')
    318         self.assertRaises(ftp_error.PermanentError, self.stat.stat,
     318        self.assertRaises(ftp_error.PermanentError, self.stat._stat,
    319319                          '/home/bad_link')
    320320
     
    329329        #  switched off no matter whether we got a `PermanentError`
    330330        #  or not.
    331         self.assertRaises(ftp_error.PermanentError, self.stat.lstat,
     331        self.assertRaises(ftp_error.PermanentError, self.stat._lstat,
    332332                          "/home/msformat/nonexistent")
    333333        self.assertEqual(self.stat._allow_parser_switching, False)
     
    337337        self.assertEqual(self.stat._allow_parser_switching, True)
    338338        self.failUnless(isinstance(self.stat._parser, ftp_stat.UnixParser))
    339         stat_result = self.stat.lstat("/home/sschwarzer/index.html")
     339        stat_result = self.stat._lstat("/home/sschwarzer/index.html")
    340340        self.failUnless(isinstance(self.stat._parser, ftp_stat.UnixParser))
    341341        self.assertEqual(self.stat._allow_parser_switching, False)
     
    345345        self.assertEqual(self.stat._allow_parser_switching, True)
    346346        self.failUnless(isinstance(self.stat._parser, ftp_stat.UnixParser))
    347         stat_result = self.stat.lstat("/home/msformat/abcd.exe")
     347        stat_result = self.stat._lstat("/home/msformat/abcd.exe")
    348348        self.failUnless(isinstance(self.stat._parser, ftp_stat.MSParser))
    349349        self.assertEqual(self.stat._allow_parser_switching, False)
     
    354354        """Test switching of parser if a directory is empty."""
    355355        self.assertEqual(self.stat._allow_parser_switching, True)
    356         result = self.stat.listdir("/home/msformat/XPLaunch/empty")
     356        result = self.stat._listdir("/home/msformat/XPLaunch/empty")
    357357        self.assertEqual(result, [])
    358358        self.assertEqual(self.stat._allow_parser_switching, True)
     
    368368        """Test failing `FTPHost.listdir`."""
    369369        self.assertRaises(ftp_error.PermanentError,
    370                           self.stat.listdir, 'notthere')
     370                          self.stat._listdir, 'notthere')
    371371
    372372    def test_succeeding_listdir(self):
    373373        """Test succeeding `FTPHost.listdir`."""
    374374        # Do we have all expected "files"?
    375         self.assertEqual(len(self.stat.listdir('.')), 9)
     375        self.assertEqual(len(self.stat._listdir('.')), 9)
    376376        # Have they the expected names?
    377377        expected = ('chemeng download image index.html os2 '
    378378                    'osup publications python scios2').split()
    379         remote_file_list = self.stat.listdir('.')
     379        remote_file_list = self.stat._listdir('.')
    380380        for file in expected:
    381381            self.failUnless(file in remote_file_list)
Note: See TracChangeset for help on using the changeset viewer.