Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler.
authorSenthil Kumaran <senthil@uthcode.com>
Fri, 13 May 2016 08:32:42 +0000 (01:32 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Fri, 13 May 2016 08:32:42 +0000 (01:32 -0700)
Patch contributed by Chi Hsuan Yen.

Lib/test/test_urllib2.py
Lib/urllib/request.py
Misc/NEWS

index 008c751f9c6f16522e46fa2fb718028836dec606..b5bba55a97711dea7126a8ae6bc16d5bfbb19e82 100644 (file)
@@ -480,8 +480,8 @@ class MockHTTPSHandler(urllib.request.AbstractHTTPHandler):
     # Useful for testing the Proxy-Authorization request by verifying the
     # properties of httpcon
 
-    def __init__(self):
-        urllib.request.AbstractHTTPHandler.__init__(self)
+    def __init__(self, debuglevel=0):
+        urllib.request.AbstractHTTPHandler.__init__(self, debuglevel=debuglevel)
         self.httpconn = MockHTTPClass()
 
     def https_open(self, req):
@@ -950,6 +950,13 @@ class HandlerTests(unittest.TestCase):
             newreq = h.do_request_(req)
             self.assertEqual(int(newreq.get_header('Content-length')),16)
 
+    def test_http_handler_debuglevel(self):
+        o = OpenerDirector()
+        h = MockHTTPSHandler(debuglevel=1)
+        o.add_handler(h)
+        o.open("https://www.example.com")
+        self.assertEqual(h._debuglevel, 1)
+
     def test_http_doubleslash(self):
         # Checks the presence of any unnecessary double slash in url does not
         # break anything. Previously, a double slash directly after the host
index b28cd60158397648bf1dc82b267c23cb4654086b..5f40729fca5debae62349f62ca55c6eda9a055fd 100644 (file)
@@ -1211,6 +1211,7 @@ class AbstractHTTPHandler(BaseHandler):
 
         # will parse host:port
         h = http_class(host, timeout=req.timeout, **http_conn_args)
+        h.set_debuglevel(self._debuglevel)
 
         headers = dict(req.unredirected_hdrs)
         headers.update(dict((k, v) for k, v in req.headers.items()
index 1f4daccb8dd87505fa71f0eb5e2dffd14cddb42c..5fa4a05516eaa2c33abff5f5ab95ef2a1a253027 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -118,6 +118,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler. Patch
+  contributed by Chi Hsuan Yen.
+
 - Issue #22274: In the subprocess module, allow stderr to be redirected to
   stdout even when stdout is not redirected.  Patch by Akira Li.