Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit acfb82a

Browse files
committed
Use re instead of regex. Also remove bogus return statement from __init__().
1 parent 8566e47 commit acfb82a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Lib/ftplib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def __init__(self, host = '', user = '', passwd = '', acct = ''):
105105
if host:
106106
resp = self.connect(host)
107107
if user: resp = self.login(user, passwd, acct)
108-
return resp
109108

110109
def connect(self, host = '', port = 0):
111110
'''Connect to host. Arguments are:
@@ -469,8 +468,7 @@ def close(self):
469468
del self.file, self.sock
470469

471470

472-
import regex
473-
_150_re = regex.compile("150 .* (\([0-9][0-9]*\) bytes)", regex.casefold)
471+
_150_re = None
474472

475473
def parse150(resp):
476474
'''Parse the '150' response for a RETR request.
@@ -479,9 +477,13 @@ def parse150(resp):
479477
'''
480478
if resp[:3] != '150':
481479
raise error_reply, resp
482-
length = _150_re.match(resp)
483-
if length >= 0:
484-
return string.atoi(_150_re.group(1))
480+
global _150_re
481+
if _150_re is None:
482+
import re
483+
_150_re = re.compile("150 .* \(([0-9][0-9]*) bytes\)", re.IGNORECASE)
484+
m = _150_re.match(resp)
485+
if m:
486+
return string.atoi(m.group(1))
485487
return None
486488

487489

0 commit comments

Comments
 (0)