Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130167: Improve speed of ftplib.parse150 by replacing re #130243

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

Closed
wants to merge 5 commits into from
Closed
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
Next Next commit
Improve speed of ftplib.parse150 by replacing re
  • Loading branch information
donBarbos committed Feb 18, 2025
commit 4055dbed316e0a10b71ba6a8876d16fde8a0b98b
22 changes: 11 additions & 11 deletions 22 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)')
donBarbos marked this conversation as resolved.
Show resolved Hide resolved

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.