[Python-checkins] r56294 - in python/branches/release25-maint/Lib: test/test_urllib2.py urllib2.py

georg.brandl python-checkins at python.org
Thu Jul 12 10:05:48 CEST 2007


Author: georg.brandl
Date: Thu Jul 12 10:05:48 2007
New Revision: 56294
Modified:
 python/branches/release25-maint/Lib/test/test_urllib2.py
 python/branches/release25-maint/Lib/urllib2.py
Log:
Patch #1752270, #1750931: complain if urllib2 add_handler called
without handler.
 (backport from rev. 56293)
Modified: python/branches/release25-maint/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_urllib2.py	(original)
+++ python/branches/release25-maint/Lib/test/test_urllib2.py	Thu Jul 12 10:05:48 2007
@@ -381,6 +381,12 @@
 
 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
Modified: python/branches/release25-maint/Lib/urllib2.py
==============================================================================
--- python/branches/release25-maint/Lib/urllib2.py	(original)
+++ python/branches/release25-maint/Lib/urllib2.py	Thu Jul 12 10:05:48 2007
@@ -298,6 +298,10 @@
 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"]:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /