| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Adjust `urllib.request.pathname2url` and `url2pathname()` to generate and accept file URIs as described in RFC8089. `pathname2url()` gains a new *include_scheme* argument, which defaults to false. 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 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, 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.
|
Test failures will go away when #125739 lands |
Sorry, something went wrong.
… POSIX paths When handed an absolute Windows path such as `C:\foo` or `//server/share`, the `urllib.request.pathname2url()` function returns a URL with an authority section, such as `///C:/foo` or `//server/share` (or before pythonGH-126205, `////server/share`). Only the `file:` prefix is omitted. But when handed an absolute POSIX path such as `/etc/hosts`, or a Windows path of the same form (rooted but lacking a drive), the function returns a URL without an authority section, such as `/etc/hosts`. This patch corrects the discrepancy by adding a `//` prefix before drive-less, rooted paths when generating URLs.
|
FWIW, I decided to do this in a more piecemeal fashion. The latest PR at time of writing is here: #126844 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Adjust urllib.request.pathname2url() and url2pathname() to generate and accept file URIs as described in RFC8089.
pathname2url() gains a new include_scheme argument, which defaults to false. 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 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, 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.
pathname2url() examples (star marks differences):
url2pathname() examples (star marks differences):
📚 Documentation preview 📚: https://cpython-previews--126148.org.readthedocs.build/