urllib.request.pathname2url()
: generate RFC 1738 URLs where possible · Issue #127236 · python/cpython (original) (raw)
Feature or enhancement
Proposal:
urllib.request.pathname2url currently generates RFC 1738-compliant file:
URIs in the following cases:
- DOS drive paths (including drive-relative paths) on Windows.
- UNC paths on Windows.
- POSIX paths beginning
//
(since pathname2url() does not work if path starts with // #127217)
This function cannot generate RFC 1738-compliant URLs for:
- True relative paths, because of differing requirements for the first character of the path.
That leaves one case where the function could generate RFC 1738-compatible URLs, but doesn't:
- Paths beginning with exactly one slash (both POSIX and Windows)
from urllib.request import pathname2url pathname2url('/etc/hosts') '/etc/hosts' # expected: '///etc/hosts'
For consistency with pathname2url()
's handling of other paths, and consistency with pathlib.Path.as_uri(), I propose we prepend two slashes to any path beginning with precisely one slash to produce a URL authority section with a zero-length authority.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere