diff options
author | Guido van Rossum <guido@python.org> | 2001-08-17 17:24:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-17 17:24:29 (GMT) |
commit | 70297d3bd4e33c704f5de976684b46ba796fbf51 (patch) | |
tree | a1987324d4ad93381bd4d6804c1d446fe0e861c4 /Lib/ftplib.py | |
parent | 2dc07946bfacd57b27ae6d180a9e3a5d7cbe8b58 (diff) | |
download | cpython-70297d3bd4e33c704f5de976684b46ba796fbf51.zip cpython-70297d3bd4e33c704f5de976684b46ba796fbf51.tar.gz cpython-70297d3bd4e33c704f5de976684b46ba796fbf51.tar.bz2 |
Change the 227 response parser to use a more liberal regular
expression. This is needed for certain servers that (in violation of
the standard) don't return the parentheses in the response.
This fixes SF bug #441712 by Henrik Weber (not exactly using his
patch).
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r-- | Lib/ftplib.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py index fda7864..4aa6244 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -551,6 +551,8 @@ def parse150(resp): return None +_227_re = None + def parse227(resp): '''Parse the '227' response for a PASV request. Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)' @@ -558,14 +560,14 @@ def parse227(resp): if resp[:3] != '227': raise error_reply, resp - left = resp.find('(') - if left < 0: raise error_proto, resp - right = resp.find(')', left + 1) - if right < 0: - raise error_proto, resp # should contain '(h1,h2,h3,h4,p1,p2)' - numbers = resp[left+1:right].split(',') - if len(numbers) != 6: + global _227_re + if _227_re is None: + import re + _227_re = re.compile(r'(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)') + m = _227_re.search(resp) + if not m: raise error_proto, resp + numbers = m.groups() host = '.'.join(numbers[:4]) port = (int(numbers[4]) << 8) + int(numbers[5]) return host, port |