Kaydet (Commit) 40df67f7 authored tarafından Georg Brandl's avatar Georg Brandl

Patch #1752270, #1750931: complain if urllib2 add_handler called

without handler.
 (backport from rev. 56293)
üst ad4b263b
......@@ -381,6 +381,12 @@ class MockPasswordManager:
class OpenerDirectorTests(unittest.TestCase):
def test_add_non_handler(self):
class NonHandler(object):
pass
self.assertRaises(TypeError,
OpenerDirector().add_handler, NonHandler())
def test_badly_named_methods(self):
# test work-around for three methods that accidentally follow the
# naming conventions for handler methods
......
......@@ -298,6 +298,10 @@ class OpenerDirector:
self.process_request = {}
def add_handler(self, handler):
if not hasattr(handler, "add_parent"):
raise TypeError("expected BaseHandler instance, got %r" %
type(handler))
added = False
for meth in dir(handler):
if meth in ["redirect_request", "do_open", "proxy_open"]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment