]> granicus.if.org Git - python/commitdiff
Issue #6500: Fixed infinite recursion in urllib2.Request.__getattr__().
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 18 Jan 2016 08:35:40 +0000 (10:35 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 18 Jan 2016 08:35:40 +0000 (10:35 +0200)
Lib/test/test_urllib2.py
Lib/urllib2.py
Misc/NEWS

index 32ffd0acefb2e2a16227352e06f2ebca4e1ceb89..5a631b3a5738da904e2a6d0e69d6553d5476d57f 100644 (file)
@@ -1350,6 +1350,11 @@ class RequestTests(unittest.TestCase):
         req = Request(url)
         self.assertEqual(req.get_full_url(), url)
 
+    def test_private_attributes(self):
+        self.assertFalse(hasattr(self.get, '_Request__r_xxx'))
+        # Issue #6500: infinite recursion
+        self.assertFalse(hasattr(self.get, '_Request__r_method'))
+
     def test_HTTPError_interface(self):
         """
         Issue 13211 reveals that HTTPError didn't implement the URLError
index 9277b1d1cdc89cb9d99892b6dc783b90b5c7ce7e..8ec5e2aefed9d05ab1c5711598f6da2df6c1fa35 100644 (file)
@@ -248,11 +248,9 @@ class Request:
         # methods getting called in a non-standard order.  this may be
         # too complicated and/or unnecessary.
         # XXX should the __r_XXX attributes be public?
-        if attr[:12] == '_Request__r_':
-            name = attr[12:]
-            if hasattr(Request, 'get_' + name):
-                getattr(self, 'get_' + name)()
-                return getattr(self, attr)
+        if attr in ('_Request__r_type', '_Request__r_host'):
+            getattr(self, 'get_' + attr[12:])()
+            return self.__dict__[attr]
         raise AttributeError, attr
 
     def get_method(self):
index 6b5c418b1c85fd2bbcee93c210fb3530df111ca1..3117809eccd5ebc803ec53c58e480d108a3030ff 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -39,6 +39,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #6500: Fixed infinite recursion in urllib2.Request.__getattr__().
+
 - Issue #26083: Workaround a subprocess bug that raises an incorrect
   "ValueError: insecure string pickle" exception instead of the actual
   exception on some platforms such as Mac OS X when an exception raised