[Python-checkins] cpython (merge 3.5 -> default): merge from 3.5

senthil.kumaran python-checkins at python.org
Fri May 13 04:35:37 EDT 2016


https://hg.python.org/cpython/rev/e0ec68d46464
changeset:   101316:e0ec68d46464
parent:      101313:5979e7aadd59
parent:      101315:63e23b2dedcc
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Fri May 13 01:35:29 2016 -0700
summary:
  merge from 3.5

Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler.

Patch contributed by Chi Hsuan Yen.

files:
  Lib/test/test_urllib2.py |  11 +++++++++--
  Lib/urllib/request.py    |   1 +
  Misc/NEWS                |   3 +++
  3 files changed, 13 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -480,8 +480,8 @@
     # 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 @@
             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
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1271,6 +1271,7 @@
 
         # 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()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -277,6 +277,9 @@
 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.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list