mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
GH-85168: Use filesystem encoding when converting to/from file
URIs (#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.
This commit is contained in:
parent
2cdfb41d0c
commit
c9b399fbdb
4 changed files with 26 additions and 10 deletions
|
@ -1657,12 +1657,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)
|
||||
|
||||
|
||||
# Utility functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue