8000 GH-123599: `url2pathname()`: don't call `gethostbyname()` by default by barneygale · Pull Request #132610 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-123599: url2pathname(): don't call gethostbyname() by default #132610

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 5, 2025

Conversation

barneygale
Copy link
Contributor
@barneygale barneygale commented Apr 16, 2025

Follow-up to 66cdb2b.

Add resolve_host keyword-only argument to url2pathname(), defaulting to false. When set to true, we call socket.gethostbyname() to resolve the URL authority (netloc).

…fault

Follow-up to 0879ebc.

Add *resolve_netloc* keyword-only argument to `url2pathname()`, defaulting
to false. When set to true, we call `socket.gethostbyname()` to resolve
the URL authority (netloc).
@barneygale barneygale marked this pull request as ready for review April 16, 2025 19:58
@@ -1494,6 +1494,8 @@ def _is_local_authority(authority):
if authority == hostname:
return True
# Compare IP addresses
if not resolve:
Copy link
Member

Choose a reason for hiding this comment

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

I wonder, should we check this before calling gethostname() which can fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm struggling to come up with firm info on when gethostname() fails (or whether it can perform network access). Do you have any pointers? Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

I do not know.

But I was thinking about this case: processing the "file:" URL on different computer. We cannot use gethostname(), because it returns a different result. If we want to get a path on other computer, we should ignore the host name. There will still be problem with processing Windows paths on Posix and Posix paths on Windows.

I do not know how common this case, and how common the opposite case, when we only use gethostname(), but not gethostbyname(). We should guess what would be more useful for users without having any data.

barneygale and others added 2 commits April 28, 2025 17:48
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@barneygale
Copy link
Contributor Author

Thanks for the reviews - sorry for my slow response

barneygale and others added 2 commits May 5, 2025 12:52
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
@barneygale
Copy link
Contributor Author
barneygale commented May 5, 2025 8000

@serhiy-storchaka sorry for the short notice, but would you mind if I merge this in time for 3.14 beta 1? I can log your outstanding feedback as a follow-up issue; I suspect we can address it during the 3.14 beta period without affecting the API.

Copy link
Member
@serhiy-storchaka serhiy-storchaka 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 do not actually know what to do when we want to parse the "file:" URL on different machine, especially if they are Windows and Posix. On Windows, we can always interpret the host name as a UNC path. On Posix we can only ignore it or raise an exception if it is not localhost.

@barneygale barneygale added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 5, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @barneygale for commit 2a42d88 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132610%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

8000

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 5, 2025
@barneygale barneygale enabled auto-merge (squash) May 5, 2025 16:41
@barneygale barneygale merged commit 8e08ac9 into python:main May 5, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0