-
-
Notifications
You must be signed in to change notification settings - Fork 180
Parsing compatibility of the FTP LIST
command for Windows servers
#439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If you're feeling generous, perhaps https://pydoc.net/grizzled/0.9.4/grizzled.net.ftp.parse/ and https://github.com/stevemayne/pyftpparser would appreciate similar patches? 🙂 |
…uggestions from a code review.
I created an issue for pyftpparser; I'll have to see whether I'll also do the PR there. |
Hey, any update on this? The PR seems to be ready to merge. |
@atollk I know it's not in code that you've modified in this PR, but I think it might be worth making these tweaks to the --- a/fs/_ftp_parse.py
+++ b/fs/_ftp_parse.py
@@ -85,12 +85,12 @@ def parse_line(line):
def _parse_time(t, formats):
- t = " ".join(token.strip() for token in t.lower().split(" "))
-
_t = None
for frmt in formats:
try:
_t = time.strptime(t, frmt)
+ if _t:
+ break
except ValueError:
continue
if not _t:
|
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.
@atollk I've looked into it a bit further, and it seems like >>> import time
>>> time.strptime("11-02-17 04:54".strip(), "%d-%m-%y %H:%M")
time.struct_time(tm_year=2017, tm_mon=2, tm_mday=11, tm_hour=4, tm_min=54, tm_sec=0, tm_wday=5, tm_yday=42, tm_isdst=-1)
>>> time.strptime("11-02-17 4:54".strip(), "%d-%m-%y %H:%M")
time.struct_time(tm_year=2017, tm_mon=2, tm_mday=11, tm_hour=4, tm_min=54, tm_sec=0, tm_wday=5, tm_yday=42, tm_isdst=-1) which makes your In fact, with this change: @@ -145,12 +145,8 @@ def decode_linux(line, match):
return raw_info
-def _decode_windowsnt_time(mdate, mtime):
- if len(mtime.split(":")[0]) == 1:
- mtime = "0" + mtime
- return _parse_time(
- mdate + " " + mtime, formats=["%d-%m-%y %I:%M%p", "%d-%m-%y %H:%M"]
- )
+def _decode_windowsnt_time(mtime):
+ return _parse_time(mtime, formats=["%d-%m-%y %I:%M%p", "%d-%m-%y %H:%M"])
def decode_windowsnt(line, match):
@@ -179,7 +170,7 @@ def decode_windowsnt(line, match):
raw_info["details"]["size"] = int(match.group("size"))
modified = _decode_windowsnt_time(
- match.group("modified_date"), match.group("modified_time")
+ match.group("modified_date") + " " + match.group("modified_time")
)
if modified is not None:
raw_info["details"]["modified"] = modified all the unit-tests still pass, and it has the benefit of making the |
…y due to incomplete documentation The standard library function `time.strptime` using the format "%H" was falsely assumed to require a two-digit number (00-23). As it turns out, one-digit numbers (0-9) are also valid, so we don't have to manually prepend a zero.
That's a fair point. I just followed the documentation there without actually trying it. |
See #439 (review) for details. The function `_find_suitable_format` was inlined into `_parse_time`.
Hi. Any update on this? |
…ng the reference in that line.
except ValueError: | ||
continue | ||
if not _t: | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, I've just learned about the for ... else ...
syntax in Python which I wasn't aware of before 🙂
LGTM 👍 ping @althonos |
Happy new year :) |
LGTM @atollk ! We should be able to get this in the next debug release (once we synchronize on how we want to manage releases there). Cheers! |
Type of changes
Checklist
Description
Extended parsing compatibility of the FTP
LIST
command for Windows servers. Fixes #438 .The parsing process now properly supports 24-hour time format, both with and without leading zeros. Unit tests were adapted accordingly.