Commits

Anonymous committed c0114ed

- #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

  • Participants
  • Parent commits 76b89fa
  • Branches 2.0

Comments (0)

Files changed (2)

File Lib/urllib.py

     def __init__(self, *args):
         apply(URLopener.__init__, (self,) + args)
         self.auth_cache = {}
+        self.tries = 0
+        self.maxtries = 10
 
     def http_error_default(self, url, fp, errcode, errmsg, headers):
         """Default error handling -- don't raise an exception."""
 
     def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
         """Error 302 -- relocated (temporarily)."""
-        # XXX The server can force infinite recursion here!
+        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']
         elif headers.has_key('uri'):
                        return getattr(self,name)(url, realm)
                    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):
         host, selector = splithost(url)
                 cmd = 'RETR ' + file
                 conn = self.ftp.ntransfercmd(cmd)
             except ftplib.error_perm, reason:
-                if reason[:3] != '550':
+                if str(reason)[:3] != '550':
                     raise IOError, ('ftp error', reason), sys.exc_info()[2]
         if not conn:
             # Set transfer mode to ASCII!
     for i in range(len(res)):
         c = res[i]
         if not _fast_safe.has_key(c):
-            res[i] = '%%%02x' % ord(c)
+            res[i] = '%%%02X' % ord(c)
     return string.join(res, '')
 
 def quote(s, safe = '/'):
     for i in range(len(res)):
         c = res[i]
         if c not in safe:
-            res[i] = '%%%02x' % ord(c)
+            res[i] = '%%%02X' % ord(c)
     return string.join(res, '')
 
 def quote_plus(s, safe = ''):
 
 - #117606 - configure.in, configure - use gcc -shared and gcc -fPIC
 
+- #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
+
 What's New in Python 2.0?
 =========================