]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- #227562 - urllib.py - call URLopener.http_error_default when
authorMoshe Zadka <moshez@math.huji.ac.il>
Sat, 31 Mar 2001 14:58:20 +0000 (14:58 +0000)
committerMoshe Zadka <moshez@math.huji.ac.il>
Sat, 31 Mar 2001 14:58:20 +0000 (14:58 +0000)
                        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

Lib/urllib.py
Misc/NEWS

index 8b3c9240dbefed5b1d6f582e1e2faeefb2126c4e..1946a971ab897c291fe5af57fac7bd83c30c44c1 100644 (file)
@@ -512,6 +512,8 @@ class FancyURLopener(URLopener):
     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."""
@@ -519,7 +521,21 @@ class FancyURLopener(URLopener):
 
     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'):
@@ -555,6 +571,8 @@ class FancyURLopener(URLopener):
                        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)
@@ -689,7 +707,7 @@ class ftpwrapper:
                 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!
@@ -1036,7 +1054,7 @@ def _fast_quote(s):
     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 = '/'):
@@ -1067,7 +1085,7 @@ 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 = ''):
index a4e68f51e9ea6aadd475affe8b3da897577c1936..6b3450e70b4f34526bfd26a0300b3239c3b0ec73 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -141,6 +141,15 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=<id>&group_id=5470&atid
 
 - #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?
 =========================