-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement
Description
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
Links to previous discussion of this feature:
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement