mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
fix issue #6822: ftplib's storline method doesn't work with text files
This commit is contained in:
parent
b5c23761d3
commit
b939235c6a
4 changed files with 52 additions and 12 deletions
|
@ -493,9 +493,15 @@ class FTP:
|
|||
while 1:
|
||||
buf = fp.readline()
|
||||
if not buf: break
|
||||
if buf[-2:] != B_CRLF:
|
||||
if buf[-1] in B_CRLF: buf = buf[:-1]
|
||||
buf = buf + B_CRLF
|
||||
if isinstance(buf, str):
|
||||
if not buf.endswith(CRLF):
|
||||
if buf[-1] in CRLF: buf = buf[:-1]
|
||||
buf = buf + CRLF
|
||||
buf = bytes(buf, self.encoding)
|
||||
else:
|
||||
if not buf.endswith(B_CRLF):
|
||||
if buf[-1:] in B_CRLF: buf = buf[:-1]
|
||||
buf = buf + B_CRLF
|
||||
conn.sendall(buf)
|
||||
if callback: callback(buf)
|
||||
conn.close()
|
||||
|
@ -771,9 +777,15 @@ else:
|
|||
while 1:
|
||||
buf = fp.readline()
|
||||
if not buf: break
|
||||
if buf[-2:] != B_CRLF:
|
||||
if buf[-1] in B_CRLF: buf = buf[:-1]
|
||||
buf = buf + B_CRLF
|
||||
if isinstance(buf, str):
|
||||
if not buf.endswith(CRLF):
|
||||
if buf[-1] in CRLF: buf = buf[:-1]
|
||||
buf = buf + CRLF
|
||||
buf = bytes(buf, self.encoding)
|
||||
else:
|
||||
if not buf.endswith(B_CRLF):
|
||||
if buf[-1:] in B_CRLF: buf = buf[:-1]
|
||||
buf = buf + B_CRLF
|
||||
conn.sendall(buf)
|
||||
if callback: callback(buf)
|
||||
# shutdown ssl layer
|
||||
|
@ -783,6 +795,7 @@ else:
|
|||
conn.close()
|
||||
return self.voidresp()
|
||||
|
||||
|
||||
__all__.append('FTP_TLS')
|
||||
all_errors = (Error, IOError, EOFError, ssl.SSLError)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue