]> granicus.if.org Git - python/commitdiff
Issue #2670: urllib2.build_opener() failed when two handlers
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 22 Apr 2008 21:17:18 +0000 (21:17 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 22 Apr 2008 21:17:18 +0000 (21:17 +0000)
derive the same default base class.

Backport of r62463.

Lib/test/test_urllib2.py
Lib/urllib2.py
Misc/NEWS

index 9934d3778bf4b73a36ab3a832968f929374acb0f..96a7db9e340f1b2ec3ab9cd6e371fb7f8c0ab4bc 100644 (file)
@@ -1038,6 +1038,12 @@ class MiscTests(unittest.TestCase):
         o = build_opener(urllib2.HTTPHandler())
         self.opener_has_handler(o, urllib2.HTTPHandler)
 
+        # Issue2670: multiple handlers sharing the same base class
+        class MyOtherHTTPHandler(urllib2.HTTPHandler): pass
+        o = build_opener(MyHTTPHandler, MyOtherHTTPHandler)
+        self.opener_has_handler(o, MyHTTPHandler)
+        self.opener_has_handler(o, MyOtherHTTPHandler)
+
     def opener_has_handler(self, opener, handler_class):
         for h in opener.handlers:
             if h.__class__ == handler_class:
index 3578e7a0b97ba90a9c813697bfd49fa996b1a567..50d7aaf204d45ec15c476531626f07cf3db6901c 100644 (file)
@@ -447,14 +447,14 @@ def build_opener(*handlers):
                        FTPHandler, FileHandler, HTTPErrorProcessor]
     if hasattr(httplib, 'HTTPS'):
         default_classes.append(HTTPSHandler)
-    skip = []
+    skip = set()
     for klass in default_classes:
         for check in handlers:
             if isclass(check):
                 if issubclass(check, klass):
-                    skip.append(klass)
+                    skip.add(klass)
             elif isinstance(check, klass):
-                skip.append(klass)
+                skip.add(klass)
     for klass in skip:
         default_classes.remove(klass)
 
index b9ce278e3e0d1d30d8e70c550f519faf4daee834..d66e26ce93c88de15d91e5f0e6da6e93119c1e04 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,9 @@ Core and builtins
 Library
 -------
 
+- Issue #2670:  Fix a failure in urllib2.build_opener(), when passed two
+  handlers that derive the same default base class.
+
 - Issue #2495: tokenize.untokenize now inserts a space between two consecutive
   string literals; previously, ["" ""] was rendered as [""""], which is
   incorrect python code.