From: Amaury Forgeot d'Arc Date: Tue, 22 Apr 2008 21:14:41 +0000 (+0000) Subject: Issue #2670: urllib2.build_opener() failed when two handlers X-Git-Tag: v2.6a3~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9686585a82defca236da0e29f44137c491d9e980;p=python Issue #2670: urllib2.build_opener() failed when two handlers derive the same default base class. Will backport. --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 58cb2a8b5d..8d17e05725 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1063,6 +1063,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: diff --git a/Lib/urllib2.py b/Lib/urllib2.py index a20e5522c6..817c5a7d8b 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -446,14 +446,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) diff --git a/Misc/NEWS b/Misc/NEWS index 6a0e924629..3930929267 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,9 @@ Core and builtins Extensions Modules ------------------ +- Issue #2670: Fix a failure in urllib2.build_opener(), when passed two + handlers that derive the same default base class. + - Added kill, terminate and send_signal(sig) to subprocess.Popen. - Added phase(z) -> phi, polar(z) -> r, phi and rect(r, phi) -> z to the cmath