Skip to content

Commit

Permalink
Fix _ftp_retrlines_native chunk parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Apr 6, 2019
1 parent ba73f59 commit 7880c22
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ftpsync/ftp_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def _addline(status, line):
elif res_type in ("cdir", "pdir"):
pass
else:
write_error("Could not parse '{}'".format(line))
raise NotImplementedError(
"MLSD returned unsupported type: {!r}".format(res_type)
)
Expand Down Expand Up @@ -719,6 +720,7 @@ def _ftp_retrlines_native(self, command, callback, encoding):

def _on_read_line(line):
# Line is a byte string
# print(" line ", line)
status = 2 # fault
line_decoded = None
try:
Expand All @@ -731,7 +733,6 @@ def _on_read_line(line):
status = 1 # used fallback encoding
except UnicodeDecodeError:
raise
# pass # fault

if compat.PY2:
# line is a native binary `str`.
Expand All @@ -748,17 +749,19 @@ def _on_read_line(line):

def _on_read_chunk(chunk):
buffer = local_var["buffer"]
# print("read_c()", chunk, buffer)
# Normalize line endings
chunk = chunk.replace(b"\r\n", LF)
chunk = chunk.replace(b"\r", LF)
chunk = buffer + chunk
try:
# print("Add chunk ", chunk, "to buffer", buffer)
while True:
item, chunk = chunk.split(LF, 1)
_on_read_line(item) # + LF)
except ValueError:
buffer += chunk
# print("Add chunk ", chunk, "to buffer", buffer)
pass
# print("Rest chunk", chunk)
local_var["buffer"] = chunk

self.ftp.retrbinary(command, _on_read_chunk)

Expand Down

0 comments on commit 7880c22

Please sign in to comment.