]> granicus.if.org Git - python/commitdiff
Patch #1752270, #1750931: complain if urllib2 add_handler called
authorGeorg Brandl <georg@python.org>
Thu, 12 Jul 2007 08:05:45 +0000 (08:05 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 12 Jul 2007 08:05:45 +0000 (08:05 +0000)
without handler.

Lib/test/test_urllib2.py
Lib/urllib2.py

index c9dcf5ef7be47d64a89563a41631aa7951ac5203..90e177173374933f376fa1d206618c14b42d57ee 100644 (file)
@@ -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
index 415c991ad32d8e6091fc9bbf5efac61acfd3223a..b2cec727fa782a4d8bf791aa90daceb03a4df534 100644 (file)
@@ -295,6 +295,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"]: