[Python-checkins] CVS: python/dist/src/Lib ftplib.py,1.53,1.53.2.1
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年12月18日 06:17:07 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv26792
Modified Files:
Tag: release21-maint
ftplib.py
Log Message:
Backport patch 1.57 to 2.1.2. Apparently ftp servers that send 227
responses that the original parse227() routine can't handle are
becoming more common.
"""
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).
"""
Index: ftplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ftplib.py,v
retrieving revision 1.53
retrieving revision 1.53.2.1
diff -C2 -d -r1.53 -r1.53.2.1
*** ftplib.py 2001年04月09日 04:31:50 1.53
--- ftplib.py 2001年12月18日 14:17:02 1.53.2.1
***************
*** 504,507 ****
--- 504,509 ----
+ _227_re = None
+
def parse227(resp):
'''Parse the '227' response for a PASV request.
***************
*** 511,522 ****
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:
raise error_proto, resp
host = '.'.join(numbers[:4])
port = (int(numbers[4]) << 8) + int(numbers[5])
--- 513,524 ----
if resp[:3] != '227':
raise error_reply, resp
! 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])