Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
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
Closed
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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.
ContributorAuthor
barneygale commentedOct 30, 2024
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
ContributorAuthor
barneygale commentedMar 23, 2025
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
Adjust
urllib.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/hostsbecomes/etc/hosts. Furthermore,url2pathname()now ignores local hosts (like "localhost" or any alias) and raisesURLErrorfor non-local hosts.pathname2url()examples (star marks differences):pathname2url('foo/bar')foo/barfoo/barpathname2url('/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):url2pathname('foo/bar')foo/barfoo/barurl2pathname('/foo/bar')/foo/bar/foo/barurl2pathname('//foo/bar')(POSIX)//foo/barraise URLError*url2pathname('//foo/bar')(Windows)//foo/bar//foo/barurl2pathname('///foo/bar')///foo/bar/foo/bar*url2pathname('////foo/bar')(POSIX)////foo/bar//foo/bar*url2pathname('////foo/bar')(Windows)//foo/bar//foo/barurl2pathname('/////foo/bar')(Windows)///foo/bar//foo/bar*urllib.request#125866📚 Documentation preview 📚:https://cpython-previews--126148.org.readthedocs.build/