[Python-checkins] CVS: python/dist/src/Lib urllib.py,1.116,1.117
Skip Montanaro
montanaro@users.sourceforge.net
Thu, 15 Feb 2001 08:56:38 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv18706
Modified Files:
urllib.py
Log Message:
provide simple recovery/escape from apparent redirect recursion. If the
number of entries into http_error_302 exceeds the value set for the maxtries
attribute (which defaults to 10), the recursion is exited by calling
the http_error_500 method (or if that is not defined, http_error_default).
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.116
retrieving revision 1.117
diff -C2 -r1.116 -r1.117
*** urllib.py 2001/02/09 20:06:00 1.116
--- urllib.py 2001/02/15 16:56:36 1.117
***************
*** 514,517 ****
--- 514,519 ----
apply(URLopener.__init__, (self,) + args)
self.auth_cache = {}
+ self.tries = 0
+ self.maxtries = 10
def http_error_default(self, url, fp, errcode, errmsg, headers):
***************
*** 521,525 ****
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']
--- 523,541 ----
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']