mirror of
https://github.com/python/cpython.git
synced 2025-08-20 16:53:19 +00:00
[3.12] GH-85168: Use filesystem encoding when converting to/from file
URIs (GH-126852) (#127040)
GH-85168: Use filesystem encoding when converting to/from `file` URIs (GH-126852)
Adjust `urllib.request.url2pathname()` and `pathname2url()` to use the
filesystem encoding when quoting and unquoting file URIs, rather than
forcing use of UTF-8.
No changes are needed in the `nturl2path` module because Windows always
uses UTF-8, per PEP 529.
(cherry picked from commit c9b399fbdb
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
153221a1d0
commit
7735f58ea5
4 changed files with 26 additions and 10 deletions
|
@ -1685,12 +1685,16 @@ else:
|
|||
# URL has an empty authority section, so the path begins on the
|
||||
# third character.
|
||||
pathname = pathname[2:]
|
||||
return unquote(pathname)
|
||||
encoding = sys.getfilesystemencoding()
|
||||
errors = sys.getfilesystemencodeerrors()
|
||||
return unquote(pathname, encoding=encoding, errors=errors)
|
||||
|
||||
def pathname2url(pathname):
|
||||
"""OS-specific conversion from a file system path to a relative URL
|
||||
of the 'file' scheme; not recommended for general use."""
|
||||
return quote(pathname)
|
||||
encoding = sys.getfilesystemencoding()
|
||||
errors = sys.getfilesystemencodeerrors()
|
||||
return quote(pathname, encoding=encoding, errors=errors)
|
||||
|
||||
|
||||
ftpcache = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue