[Python-checkins] CVS: python/dist/src/Lib urllib.py,1.107,1.107.2.1
Moshe Zadka
moshez@users.sourceforge.net
Sat, 31 Mar 2001 06:58:23 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv26992/Lib
Modified Files:
Tag: release20-maint
urllib.py
Log Message:
- #227562 - urllib.py - call URLopener.http_error_default when
an invalid 401 request is being handled.
- urllib.py - provide simple recovery/escape from apparent redirect recursion
- #129288 - urllib.py - chanign %02x to %02X in quoting
- urllib.py - HTTPS now works with string URLs
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.107
retrieving revision 1.107.2.1
diff -C2 -r1.107 -r1.107.2.1
*** urllib.py 2000/10/02 23:04:02 1.107
--- urllib.py 2001/03/31 14:58:20 1.107.2.1
***************
*** 513,516 ****
--- 513,518 ----
apply(URLopener.__init__, (self,) + args)
self.auth_cache = {}
+ self.tries = 0
+ self.maxtries = 10
def http_error_default(self, url, fp, errcode, errmsg, headers):
***************
*** 520,524 ****
def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 302 -- relocated (temporarily)."""
! # XXX The server can force infinite recursion here!
if headers.has_key('location'):
newurl = headers['location']
--- 522,540 ----
def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 302 -- relocated (temporarily)."""
! self.tries += 1
! if self.maxtries and self.tries >= self.maxtries:
! if hasattr(self, "http_error_500"):
! meth = self.http_error_500
! else:
! meth = self.http_error_default
! self.tries = 0
! return meth(url, fp, 500,
! "Internal Server Error: Redirect Recursion", headers)
! result = self.redirect_internal(url, fp, errcode, errmsg, headers,
! data)
! self.tries = 0
! return result
!
! def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if headers.has_key('location'):
newurl = headers['location']
***************
*** 556,559 ****
--- 572,577 ----
else:
return getattr(self,name)(url, realm, data)
+ return URLopener.http_error_default(self, url, fp,
+ errcode, errmsg, headers)
def retry_http_basic_auth(self, url, realm, data=None):
***************
*** 690,694 ****
conn = self.ftp.ntransfercmd(cmd)
except ftplib.error_perm, reason:
! if reason[:3] != '550':
raise IOError, ('ftp error', reason), sys.exc_info()[2]
if not conn:
--- 708,712 ----
conn = self.ftp.ntransfercmd(cmd)
except ftplib.error_perm, reason:
! if str(reason)[:3] != '550':
raise IOError, ('ftp error', reason), sys.exc_info()[2]
if not conn:
***************
*** 1037,1041 ****
c = res[i]
if not _fast_safe.has_key(c):
! res[i] = '%%%02x' % ord(c)
return string.join(res, '')
--- 1055,1059 ----
c = res[i]
if not _fast_safe.has_key(c):
! res[i] = '%%%02X' % ord(c)
return string.join(res, '')
***************
*** 1068,1072 ****
c = res[i]
if c not in safe:
! res[i] = '%%%02x' % ord(c)
return string.join(res, '')
--- 1086,1090 ----
c = res[i]
if c not in safe:
! res[i] = '%%%02X' % ord(c)
return string.join(res, '')