Skip to content

Commit 9642eed

Browse files
committed
Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler.
Patch contributed by Chi Hsuan Yen.
1 parent c763589 commit 9642eed

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Lib/test/test_urllib2.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ class MockHTTPSHandler(urllib.request.AbstractHTTPHandler):
480480
# Useful for testing the Proxy-Authorization request by verifying the
481481
# properties of httpcon
482482

483-
def __init__(self):
484-
urllib.request.AbstractHTTPHandler.__init__(self)
483+
def __init__(self, debuglevel=0):
484+
urllib.request.AbstractHTTPHandler.__init__(self, debuglevel=debuglevel)
485485
self.httpconn = MockHTTPClass()
486486

487487
def https_open(self, req):
@@ -950,6 +950,13 @@ def iterable_body():
950950
newreq = h.do_request_(req)
951951
self.assertEqual(int(newreq.get_header('Content-length')),16)
952952

953+
def test_http_handler_debuglevel(self):
954+
o = OpenerDirector()
955+
h = MockHTTPSHandler(debuglevel=1)
956+
o.add_handler(h)
957+
o.open("https://www.example.com")
958+
self.assertEqual(h._debuglevel, 1)
959+
953960
def test_http_doubleslash(self):
954961
# Checks the presence of any unnecessary double slash in url does not
955962
# break anything. Previously, a double slash directly after the host

Lib/urllib/request.py

+1
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ def do_open(self, http_class, req, **http_conn_args):
12111211

12121212
# will parse host:port
12131213
h = http_class(host, timeout=req.timeout, **http_conn_args)
1214+
h.set_debuglevel(self._debuglevel)
12141215

12151216
headers = dict(req.unredirected_hdrs)
12161217
headers.update(dict((k, v) for k, v in req.headers.items()

Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ Core and Builtins
118118
Library
119119
-------
120120

121+
- Issue #26892: Honor debuglevel flag in urllib.request.HTTPHandler. Patch
122+
contributed by Chi Hsuan Yen.
123+
121124
- Issue #22274: In the subprocess module, allow stderr to be redirected to
122125
stdout even when stdout is not redirected. Patch by Akira Li.
123126

0 commit comments

Comments
 (0)