From acfb82a530c2fde7f708b93aac6a35504c207093 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 22 Oct 1997 20:49:52 +0000 Subject: [PATCH] Use re instead of regex. Also remove bogus return statement from __init__(). --- Lib/ftplib.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 0ebefa87b37..ec7d4791ddb 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -105,7 +105,6 @@ class FTP: if host: resp = self.connect(host) if user: resp = self.login(user, passwd, acct) - return resp def connect(self, host = '', port = 0): '''Connect to host. Arguments are: @@ -469,8 +468,7 @@ class FTP: del self.file, self.sock -import regex -_150_re = regex.compile("150 .* (\([0-9][0-9]*\) bytes)", regex.casefold) +_150_re = None def parse150(resp): '''Parse the '150' response for a RETR request. @@ -479,9 +477,13 @@ def parse150(resp): ''' if resp[:3] != '150': raise error_reply, resp - length = _150_re.match(resp) - if length >= 0: - return string.atoi(_150_re.group(1)) + global _150_re + if _150_re is None: + import re + _150_re = re.compile("150 .* \(([0-9][0-9]*) bytes\)", re.IGNORECASE) + m = _150_re.match(resp) + if m: + return string.atoi(m.group(1)) return None