Issue #2670: urllib2.build_opener() failed when two handlers

derive the same default base class.

Backport of r62463.
This commit is contained in:
Amaury Forgeot d'Arc 2008-04-22 21:17:18 +00:00
parent f305bd3ea2
commit 8d904c3981
3 changed files with 12 additions and 3 deletions

View File

@ -1038,6 +1038,12 @@ class MiscTests(unittest.TestCase):
o = build_opener(urllib2.HTTPHandler()) o = build_opener(urllib2.HTTPHandler())
self.opener_has_handler(o, 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): def opener_has_handler(self, opener, handler_class):
for h in opener.handlers: for h in opener.handlers:
if h.__class__ == handler_class: if h.__class__ == handler_class:

View File

@ -447,14 +447,14 @@ def build_opener(*handlers):
FTPHandler, FileHandler, HTTPErrorProcessor] FTPHandler, FileHandler, HTTPErrorProcessor]
if hasattr(httplib, 'HTTPS'): if hasattr(httplib, 'HTTPS'):
default_classes.append(HTTPSHandler) default_classes.append(HTTPSHandler)
skip = [] skip = set()
for klass in default_classes: for klass in default_classes:
for check in handlers: for check in handlers:
if isclass(check): if isclass(check):
if issubclass(check, klass): if issubclass(check, klass):
skip.append(klass) skip.add(klass)
elif isinstance(check, klass): elif isinstance(check, klass):
skip.append(klass) skip.add(klass)
for klass in skip: for klass in skip:
default_classes.remove(klass) default_classes.remove(klass)

View File

@ -45,6 +45,9 @@ Core and builtins
Library 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 - Issue #2495: tokenize.untokenize now inserts a space between two consecutive
string literals; previously, ["" ""] was rendered as [""""], which is string literals; previously, ["" ""] was rendered as [""""], which is
incorrect python code. incorrect python code.