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:

This function cannot generate RFC 1738-compliant URLs for:

That leaves one case where the function could generate RFC 1738-compatible URLs, but doesn't:

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

#125866 (comment)

Linked PRs