Skip to content

Commit 7287d26

Browse files
committed
Fix _ftp_parse._parse_time for Python ≥ 3.15
time.strptime processing of formats that contain %d but not %Y was deprecated in Python 3.13, and removed from Python 3.15 (python/cpython#70647). Deal with this by adding %Y and having it parse the current year, in line with prior semantics. This fixes these tests/test_ftp_parse.py TestFTPParse tests by restoring the ability to parse the '%b %d %H:%M' time format. - test_decode_linux - test_decode_linux_sticky - test_decode_linux_suid - test_parse_time
1 parent 77a8562 commit 7287d26

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎fs/_ftp_parse.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ def parse_line(line):
8686
def _parse_time(t, formats):
8787
for frmt in formats:
8888
try:
89-
_t = time.strptime(t, frmt)
89+
if "%d" in frmt and "%Y" not in frmt:
90+
# Cope with https://github.com/python/cpython/issues/70647
91+
# (deprecated in 3.13, removed in 3.15) by adding a year to
92+
# achieve prior semantics.
93+
_t = time.strptime(
94+
time.strftime("%Y!", time.localtime()) + t, "%Y!" + frmt
95+
)
96+
else:
97+
_t = time.strptime(t, frmt)
9098
break
9199
except ValueError:
92100
continue

0 commit comments

Comments
 (0)