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-125866: RFC8089 file URIs inurllib.request#126148

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

Closed
barneygale wants to merge12 commits intopython:mainfrombarneygale:gh-125866

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commentedOct 29, 2024
edited
Loading

Adjusturllib.request.pathname2url() andurl2pathname() to generate and accept file URIs as described in RFC8089.

pathname2url() gains a newinclude_scheme argument, which defaults to false. When set to true, the returned URL includes afile: prefix.url2pathname() now automatically removes afile: prefix if present.

On Windows,pathname2url() now generates URIs that begin with two slashes rather than four when given a UNC path.

On other platforms,pathname2url() now generates URIs that begin with three slashes rather than one when given an absolute path.url2pathname() now performs the opposite transformation, sofile:///etc/hosts becomes/etc/hosts. Furthermore,url2pathname() now ignores local hosts (like "localhost" or any alias) and raisesURLError for non-local hosts.

pathname2url() examples (star marks differences):

previouslynow
pathname2url('foo/bar')foo/barfoo/bar
pathname2url('/foo/bar')/foo/bar///foo/bar *
pathname2url('//foo/bar') (POSIX)//foo/bar////foo/bar *
pathname2url('//foo/bar') (Windows)////foo/bar//foo/bar *

url2pathname() examples (star marks differences):

previouslynow
url2pathname('foo/bar')foo/barfoo/bar
url2pathname('/foo/bar')/foo/bar/foo/bar
url2pathname('//foo/bar') (POSIX)//foo/barraise URLError *
url2pathname('//foo/bar') (Windows)//foo/bar//foo/bar
url2pathname('///foo/bar')///foo/bar/foo/bar *
url2pathname('////foo/bar') (POSIX)////foo/bar//foo/bar *
url2pathname('////foo/bar') (Windows)//foo/bar//foo/bar
url2pathname('/////foo/bar') (Windows)///foo/bar//foo/bar *

📚 Documentation preview 📚:https://cpython-previews--126148.org.readthedocs.build/

nineteendo reacted with thumbs up emoji
Adjust `urllib.request.pathname2url` and `url2pathname()` to generate andaccept file URIs as described in RFC8089.`pathname2url()` gains a new *include_scheme* argument, which defaults tofalse. When set to true, the returned URL includes a `file:` prefix.`url2pathname()` now automatically removes a `file:` prefix if present.On Windows, `pathname2url()` now generates URIs that begin with two slashesrather than four when given a UNC path.On other platforms, `pathname2url()` now generates URIs that begin withthree slashes rather than one when given an absolute path. `url2pathname()`now performs the opposite transformation, so `file:///etc/hosts` becomes`/etc/hosts`. Furthermore, `url2pathname()` now ignores local hosts (like"localhost" or any alias) and raises `URLError` for non-local hosts.
@barneygale
Copy link
ContributorAuthor

Test failures will go away when#125739 lands

barneygale added a commit to barneygale/cpython that referenced this pull requestNov 23, 2024
… POSIX pathsWhen handed an absolute Windows path such as `C:\foo` or `//server/share`,the `urllib.request.pathname2url()` function returns a URL with anauthority section, such as `///C:/foo` or `//server/share` (or beforepythonGH-126205, `////server/share`). Only the `file:` prefix is omitted.But when handed an absolute POSIX path such as `/etc/hosts`, or a Windowspath of the same form (rooted but lacking a drive), the function returns aURL without an authority section, such as `/etc/hosts`.This patch corrects the discrepancy by adding a `//` prefix beforedrive-less, rooted paths when generating URLs.
barneygale added a commit to barneygale/cpython that referenced this pull requestNov 24, 2024
@barneygale
Copy link
ContributorAuthor

FWIW, I decided to do this in a more piecemeal fashion. The latest PR at time of writing is here:#126844

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner will be requested when the pull request is marked ready for reviewAA-Turner is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@barneygale

[8]ページ先頭

©2009-2025 Movatter.jp