mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
GH-127236: pathname2url()
: generate RFC 1738 URL for absolute POSIX path (#127194)
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 GH-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.
This commit is contained in:
parent
a2ee899682
commit
5bb059fe60
5 changed files with 33 additions and 20 deletions
|
@ -159,12 +159,14 @@ The :mod:`urllib.request` module defines the following functions:
|
|||
'file:///C:/Program%20Files'
|
||||
|
||||
.. versionchanged:: 3.14
|
||||
Windows drive letters are no longer converted to uppercase.
|
||||
Paths beginning with a slash are converted to URLs with authority
|
||||
sections. For example, the path ``/etc/hosts`` is converted to
|
||||
the URL ``///etc/hosts``.
|
||||
|
||||
.. versionchanged:: 3.14
|
||||
On Windows, ``:`` characters not following a drive letter are quoted. In
|
||||
previous versions, :exc:`OSError` was raised if a colon character was
|
||||
found in any position other than the second character.
|
||||
Windows drive letters are no longer converted to uppercase, and ``:``
|
||||
characters not following a drive letter no longer cause an
|
||||
:exc:`OSError` exception to be raised on Windows.
|
||||
|
||||
|
||||
.. function:: url2pathname(url)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue