Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update according to feedback
  • Loading branch information
alanyee committed Aug 31, 2019
commit 737a260b98c6cd8435125a1f34922b539a442549
28 changes: 12 additions & 16 deletions Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def __init__(self, host='', user='', passwd='', acct='',
def __enter__(self):
return self

# Context management protocol: try to quit() if active
def __exit__(self, *args):
"""Context management protocol: try to quit() if active"""
if self.sock is not None:
try:
self.quit()
Expand Down Expand Up @@ -180,15 +180,15 @@ def set_pasv(self, val):
"""
self.passiveserver = val

# Internal: 'sanitize' a string for printing

@aeros aeros Aug 31, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another example of something that's exclusively a formatting change.

def sanitize(self, s):
"""Internal: 'sanitize' a string for printing"""
if s[:5] in {'pass ', 'PASS '}:
i = len(s.rstrip('\r\n'))
s = s[:5] + '*'*(i-5) + s[i:]
return repr(s)

# Internal: send one line to the server, appending CRLF
def putline(self, line):
"""Internal: send one line to the server, appending CRLF"""
if '\r' in line or '\n' in line:
raise ValueError('an illegal newline character should not be contained')
sys.audit("ftplib.sendcmd", self, line)
Expand All @@ -197,15 +197,14 @@ def putline(self, line):
print('*put*', self.sanitize(line))
self.sock.sendall(line.encode(self.encoding))

# Internal: send one command to the server (through putline())
def putcmd(self, line):
"""Internal: send one command to the server (through putline())"""
if self.debugging: print('*cmd*', self.sanitize(line))
self.putline(line)

# Internal: return one line from the server, stripping CRLF.
# Raise EOFError if the connection is closed
def getline(self):
"""Internal: return one line from the server, stripping CRLF.
Raise EOFError if the connection is closed
"""
line = self.file.readline(self.maxline + 1)
if len(line) > self.maxline:
raise Error("got more than %d bytes" % self.maxline)
Expand All @@ -219,13 +218,11 @@ def getline(self):
line = line[:-1]
return line

#
# Internal: get a response from the server, which may possibly
# consist of multiple lines. Return a single string with no
# trailing CRLF. If the response consists of multiple lines,
# these are separated by '\n' characters in the string
def getmultiline(self):
"""Internal: get a response from the server, which may possibly
consist of multiple lines. Return a single string with no
trailing CRLF. If the response consists of multiple lines,
these are separated by '\n' characters in the string
"""
line = self.getline()
if line[3:4] == '-':
code = line[:3]
Expand All @@ -237,10 +234,9 @@ def getmultiline(self):
break
return line

# Internal: get a response from the server.
# Raise various errors if the response indicates an error
def getresp(self):
"""Internal: get a response from the server.
Raise various errors if the response indicates an error
"""
resp = self.getmultiline()
if self.debugging:
print('*resp*', self.sanitize(resp))
Expand Down