Skip to content

Commit d1997ba

Browse files
author
atollk
committed
Cleaned up some redundant and unclear code.
In fs._ftp_parse._parse_time, a noop-line was removed. On request of code review, the loop to determine the suitable time format was also improved upon. See #439 (comment) for details.
1 parent 7b76fb1 commit d1997ba

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

fs/_ftp_parse.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,21 @@ def parse_line(line):
8484
return None
8585

8686

87-
def _parse_time(t, formats):
88-
t = " ".join(token.strip() for token in t.lower().split(" "))
89-
90-
_t = None
87+
def _find_suitable_format(t, formats):
9188
for frmt in formats:
9289
try:
93-
_t = time.strptime(t, frmt)
90+
if time.strptime(t, frmt):
91+
return frmt
9492
except ValueError:
9593
continue
96-
if not _t:
94+
return None
95+
96+
97+
def _parse_time(t, formats):
98+
frmt = _find_suitable_format(t, formats)
99+
if frmt is None:
97100
return None
101+
_t = time.strptime(t, frmt)
98102

99103
year = _t.tm_year if _t.tm_year != 1900 else time.localtime().tm_year
100104
month = _t.tm_mon

0 commit comments

Comments
 (0)