Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99352: Respecthttp.client.HTTPConnection.debuglevel inurllib.request.AbstractHTTPHandler#99353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

wheelerlaw
Copy link
Contributor

@wheelerlawwheelerlaw commentedNov 10, 2022
edited by AlexWaygood
Loading

Fixes#99352.

Some proposed changes to allow theAbstractHTTPHandler use the value ofhttp.client.HTTPConnection.debuglevel if nodebuglevel is passed toAbstractHTTPHandler's constructor. This has to be done in the constructor body because argument default values are evaluated at function definition evaluation time andhttp.client.HTTPConnection.debuglevel could be set afterurllib.request is imported.

With these proposed changes,AbstractHTTPHandler andHTTPSHandler now respect both sources ofdebuglevel. If the value is not set in the constructor arguments, the constructor will source the value fromhttp.client.HTTPConnection.debuglevel.

Using the globalhttp.client.HTTPConnection.debuglevel:

wheeler@fedora:~/cpython$ pythonPython 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>import http.client>>>import urllib.request>>> http.client.HTTPConnection.debuglevel=1>>> urllib.request.urlopen("http://example.com")send: b'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: example.com\r\nUser-Agent: Python-urllib/3.10\r\nConnection: close\r\n\r\n'reply: 'HTTP/1.1 200 OK\r\n'header: Age: 486527header: Cache-Control: max-age=604800header: Content-Type: text/html; charset=UTF-8header: Date: Thu, 10 Nov 2022 22:00:09 GMTheader: Etag: "3147526947+gzip+ident"header: Expires: Thu, 17 Nov 2022 22:00:09 GMTheader: Last-Modified: Thu, 17 Oct 2019 07:18:26 GMTheader: Server: ECS (cha/80C2)header: Vary: Accept-Encodingheader: X-Cache: HITheader: Content-Length: 1256header: Connection: close<http.client.HTTPResponse object at 0x7f322c674a00>>>>

Using thedebuglevel constructor parameter:

wheeler@fedora:~/cpython$ pythonPython 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>import urllib.request>>> handler= urllib.request.HTTPHandler(debuglevel=1)>>> opener= urllib.request.build_opener(handler)>>> opener.open("http://example.com")send: b'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: example.com\r\nUser-Agent: Python-urllib/3.10\r\nConnection: close\r\n\r\n'reply: 'HTTP/1.1 200 OK\r\n'header: Age: 567191header: Cache-Control: max-age=604800header: Content-Type: text/html; charset=UTF-8header: Date: Thu, 10 Nov 2022 22:06:43 GMTheader: Etag: "3147526947+ident"header: Expires: Thu, 17 Nov 2022 22:06:43 GMTheader: Last-Modified: Thu, 17 Oct 2019 07:18:26 GMTheader: Server: ECS (cha/8096)header: Vary: Accept-Encodingheader: X-Cache: HITheader: Content-Length: 1256header: Connection: close<http.client.HTTPResponse object at 0x7ff801e373d0>>>>

spezifant reacted with hooray emoji
@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@ghost
Copy link

ghost commentedNov 10, 2022
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@wheelerlawwheelerlawforce-pushed thebugfix/respect-http-connection-debuglevel branch from353519d to518d0e2CompareNovember 10, 2022 22:14
@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@wheelerlawwheelerlawforce-pushed thebugfix/respect-http-connection-debuglevel branch fromac4037b tocc7f8d9CompareNovember 10, 2022 22:28
@wheelerlaw
Copy link
ContributorAuthor

Who do I need to mention to get a review on this?

Copy link
Member

@gpsheadgpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

(be sure to pull first, i pushed an update to the news entry in the branch)

@@ -1048,7 +1057,30 @@ def test_http_body_array(self):
newreq = h.do_request_(req)
self.assertEqual(int(newreq.get_header('Content-length')),16)

def test_http_handler_debuglevel(self):
def test_http_handler_global_debuglevel(self):
http.client.HTTPConnection.debuglevel = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

use awith mock.patch.object(http.client.HTTPConnection, 'debuglevel, 1): style block to set this so that it is undone after the test. same below. I also suggest using a value other than 1 so that it is more obviously correlated with the specific test and not a default from elsewhere.

wheelerlaw reacted with thumbs up emoji
@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@gpsheadgpshead self-assigned thisFeb 7, 2023
wheelerlawand others added5 commitsApril 20, 2023 18:32
* Use mock.patch.object instead of settting the module level value.* Used test values to assert the debuglevel.
@orsenthilorsenthilforce-pushed thebugfix/respect-http-connection-debuglevel branch from031e8a9 toad096d4CompareApril 21, 2023 01:32
@orsenthilorsenthil requested a review fromgpsheadApril 21, 2023 01:32
Copy link
Member

@orsenthilorsenthil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM. I have addressed the review comments against this change.

@orsenthilorsenthil merged commit5c00a62 intopython:mainApr 21, 2023
@wheelerlawwheelerlaw deleted the bugfix/respect-http-connection-debuglevel branchApril 22, 2023 02:47
@ericsnowcurrently
Copy link
Member

This appears to have caused failures on several buildbots. For example,https://buildbot.python.org/all/#/builders/15/builds/4336.

@ericsnowcurrently
Copy link
Member

@orsenthil, this is the one I was talking about.

@orsenthil
Copy link
Member

Oh. I see the issue now. Didn't realize we were disabling ssl in some builds. I will fix it. Sorry.

gpshead and ericsnowcurrently reacted with thumbs up emoji

@orsenthil
Copy link
Member

Here we go -#103828 ; I can test against the failing buildbot before merging.

orsenthil added a commit that referenced this pull requestApr 26, 2023
…s tests. (#103828)gh-99352: Ensure HTTPSConnection is available before exercising httpstests.This will fix the buildbot issue mentioned in#99353
itamaro pushed a commit to itamaro/cpython that referenced this pull requestApr 26, 2023
…g https tests. (python#103828)pythongh-99352: Ensure HTTPSConnection is available before exercising httpstests.This will fix the buildbot issue mentioned inpython#99353
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@orsenthilorsenthilorsenthil approved these changes

@gpsheadgpsheadAwaiting requested review from gpshead

Assignees

@gpsheadgpshead

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

urllib.request.urlopen() no longer respects thehttp.client.HTTPConnection.debuglevel flag
5 participants
@wheelerlaw@bedevere-bot@ericsnowcurrently@orsenthil@gpshead

[8]ページ先頭

©2009-2025 Movatter.jp