Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
22 changes: 11 additions & 11 deletions Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,24 +787,24 @@ def abort(self):
all_errors = (Error, OSError, EOFError, ssl.SSLError)


_150_re = None

def parse150(resp):
'''Parse the '150' response for a RETR request.
Returns the expected transfer size or None; size is not guaranteed to
be present in the 150 message.
'''
if resp[:3] != '150':
if not resp.startswith('150'):
raise error_reply(resp)
global _150_re
if _150_re is None:
import re
_150_re = re.compile(
r"150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII)
m = _150_re.match(resp)
if not m:

start = resp.find('(')
end = resp.find(' bytes)')

if start == -1 or end == -1 or start >= end:
return None

try:
return int(resp[start + 1:end])
except ValueError:
return None
return int(m.group(1))


_227_re = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve speed of :func:`ftplib.parse150` by replacing :mod:`re` with
``.find()`` method. Patch by Semyon Moroz.
Loading