Changeset 260

Show
Ignore:
Timestamp:
2003-06-09 18:29:32 (6 years ago)
Author:
schwa
Message:
Moved `listdir` implementation from class `ftputil.FTPHost` to
    `ftp_stat._Stat`.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ftp_stat.py

    r258 r260  
    3434""" 
    3535 
    36 # $Id: ftp_stat.py,v 1.10 2003/06/09 18:16:45 schwa Exp $ 
     36# $Id: ftp_stat.py,v 1.11 2003/06/09 18:29:32 schwa Exp $ 
    3737 
    3838import stat 
     
    8989        stat_results = [ self.parse_line(line) for line in lines ] 
    9090        return stat_results 
     91 
     92    def _host_dir(self, path): 
     93        """Return a list of lines, as fetched by FTP's `DIR` command.""" 
     94        return self._host._dir(path) 
     95 
     96    def listdir(self, path): 
     97        """ 
     98        Return a list with directories, files etc. in the directory 
     99        named path. 
     100        """ 
     101        host_path = self._host.path 
     102        # we _can't_ put this check into `_dir`, s. a. 
     103        path = host_path.abspath(path) 
     104        if not host_path.isdir(path): 
     105            raise ftp_error.PermanentError("550 %s: no such directory" % path) 
     106        lines = self._host_dir(path) 
     107        names = [] 
     108        for line in lines: 
     109            try: 
     110                stat_result = self.parse_line(line) 
     111            except ftp_error.ParserError: 
     112                pass 
     113            else: 
     114                names.append(stat_result._st_name) 
     115        return names 
    91116 
    92117    def _stat_candidates(self, lines, wanted_name): 
     
    112137                  "can't invoke stat for remote root directory") 
    113138        dirname, basename = host_path.split(path) 
    114         lines = self._host._dir(dirname) 
     139        lines = self._host_dir(dirname) 
    115140        # search for name to be stat'ed without parsing the whole 
    116141        #  directory listing 
  • trunk/ftputil.py

    r258 r260  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: ftputil.py,v 1.125 2003/06/09 18:16:45 schwa Exp $ 
     32# $Id: ftputil.py,v 1.126 2003/06/09 18:29:32 schwa Exp $ 
    3333 
    3434""" 
     
    521521 
    522522    def listdir(self, path): 
    523         """ 
    524         Return a list with directories, files etc. in the directory 
    525         named path. 
    526         """ 
    527         # we _can't_ put this check into `_dir`, s. a. 
    528         path = self.path.abspath(path) 
    529         if not self.path.isdir(path): 
    530             raise ftp_error.PermanentError("550 %s: no such directory" % path) 
    531         lines = self._dir(path) 
    532         names = [] 
    533         for line in lines: 
    534             try: 
    535                 stat_result = self._stat.parse_line(line) 
    536             except ftp_error.ParserError: 
    537                 pass 
    538             else: 
    539                 names.append(stat_result._st_name) 
    540         return names 
     523        return self._stat.listdir(path) 
    541524 
    542525    def lstat(self, path):