Changeset 252
- Timestamp:
- 2003-06-09 16:52:57 (6 years ago)
- Files:
-
- trunk/ftp_stat.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ftp_stat.py
r250 r252 34 34 """ 35 35 36 # $Id: ftp_stat.py,v 1. 6 2003/06/09 16:04:49schwa Exp $36 # $Id: ftp_stat.py,v 1.7 2003/06/09 16:52:57 schwa Exp $ 37 37 38 38 import stat … … 104 104 If the line can't be parsed, raise a `ParserError`. 105 105 """ 106 metadata, nlink, user, group, size, month, day, \ 107 year_or_time, name = line.split(None, 8) 106 try: 107 metadata, nlink, user, group, size, month, day, \ 108 year_or_time, name = line.split(None, 8) 109 except ValueError: 110 # "unpack list of wrong size" 111 raise ftp_error.ParserError("line '%s' can't be parsed" % line ) 108 112 # st_mode 109 113 st_mode = 0 114 if len(metadata) != 10: 115 raise ftp_error.ParserError("invalid metadata '%s'" % metadata) 110 116 for bit in metadata[1:10]: 111 117 bit = (bit != '-') … … 132 138 st_atime = None 133 139 # st_mtime 134 month = self._month_numbers[ month.lower() ] 140 try: 141 month = self._month_numbers[ month.lower() ] 142 except KeyError: 143 raise ftp_error.ParserError("invalid month name '%s'" % month) 135 144 day = int(day) 136 145 if year_or_time.find(':') == -1: … … 172 181 raise a `ParserError`. 173 182 """ 174 date, time_, dir_or_size, name = line.split(None, 3) 183 try: 184 date, time_, dir_or_size, name = line.split(None, 3) 185 except ValueError: 186 # "unpack list of wrong size" 187 raise ftp_error.ParserError("line '%s' can't be parsed" % line ) 175 188 # st_mode 176 189 st_mode = 0400 # default to read access only; … … 188 201 # st_size 189 202 if dir_or_size != '<DIR>': 190 st_size = int(dir_or_size) 203 try: 204 st_size = int(dir_or_size) 205 except ValueError: 206 raise ftp_error.ParserError("invalid size %s" % dir_or_size) 191 207 else: 192 208 st_size = None … … 194 210 st_atime = None 195 211 # st_mtime 196 month, day, year = map( int, date.split('-') ) 197 if year >= 70: 198 year = 1900 + year 199 else: 200 year = 2000 + year 201 hour, minute, am_pm = time_[0:2], time_[3:5], time_[5] 202 hour, minute = int(hour), int(minute) 212 try: 213 month, day, year = map( int, date.split('-') ) 214 if year >= 70: 215 year = 1900 + year 216 else: 217 year = 2000 + year 218 hour, minute, am_pm = time_[0:2], time_[3:5], time_[5] 219 hour, minute = int(hour), int(minute) 220 except (ValueError, IndexError): 221 raise ftp_error.ParserError("invalid time string '%s'" % time_) 203 222 if am_pm == 'P': 204 223 hour = 12 + hour
