Changeset 244

Show
Ignore:
Timestamp:
2003-06-09 12:47:29 (6 years ago)
Author:
schwa
Message:
Module: Added `_StatParser` class with methods `parse_line` and
    `parse_directory_listing`. `_StatParser` is intended as a base class
    of the individual parsers for Unix and Microsoft servers.
Files:

Legend:

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

    r238 r244  
    3434""" 
    3535 
    36 # $Id: ftp_stat.py,v 1.2 2003/06/08 19:42:06 schwa Exp $ 
     36# $Id: ftp_stat.py,v 1.3 2003/06/09 12:47:29 schwa Exp $ 
    3737 
    3838import sys 
     
    6565 
    6666 
     67class _StatParser: 
     68    """ 
     69    Provide parsing of directory lines and full directory listings. 
     70    """ 
     71    def parse_line(self, line): 
     72        """ 
     73        Return a `_Stat` object as derived from the string `line`. 
     74        The parser code to use depends on the directory format the 
     75        FTP server delivers. 
     76        """ 
     77        raise NotImplementedError("must be defined by subclass") 
     78 
     79    def parse_directory_listing(self, listing): 
     80        """ 
     81        Return a list of `_Stat` objects with one `_Stat` object per 
     82        line in the listing. The order of the entries is kept. 
     83        """ 
     84        lines = listing.splitlines() 
     85        stat_results = [ self.parse_line( line.strip() ) 
     86                         for line in lines ] 
     87        return stat_results 
     88 
     89 
     90 
    6791# Unix format 
    6892# total 14