summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2016-05-13 08:32:42 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2016-05-13 08:32:42 (GMT)
commit9642eedc0a6d90d9502658a6569518741eea9ef3 (patch)
treeb148ccc6a8942cb968ab80edbd7711be2ec7e3da /Lib
parentc76358924f5d750460f8693c05987dd866cb9e8a (diff)
downloadcpython-9642eedc0a6d90d9502658a6569518741eea9ef3.zip
cpython-9642eedc0a6d90d9502658a6569518741eea9ef3.tar.gz
cpython-9642eedc0a6d90d9502658a6569518741eea9ef3.tar.bz2
Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler.
Patch contributed by Chi Hsuan Yen.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_urllib2.py11
-rw-r--r--Lib/urllib/request.py1
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 008c751..b5bba55 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -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
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index b28cd60..5f40729 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -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()