mirror of https://github.com/python/cpython.git
bpo-43733: netrc try to use UTF-8 before using locale encoding. (GH-25781)
This commit is contained in:
parent
49b26fa517
commit
fd0bc7e7f4
|
@ -38,6 +38,10 @@ the Unix :program:`ftp` program and other FTP clients.
|
||||||
:func:`os.path.expanduser` is used to find the location of the
|
:func:`os.path.expanduser` is used to find the location of the
|
||||||
:file:`.netrc` file when *file* is not passed as argument.
|
:file:`.netrc` file when *file* is not passed as argument.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.10
|
||||||
|
:class:`netrc` try UTF-8 encoding before using locale specific
|
||||||
|
encoding.
|
||||||
|
|
||||||
|
|
||||||
.. exception:: NetrcParseError
|
.. exception:: NetrcParseError
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,12 @@ def __init__(self, file=None):
|
||||||
file = os.path.join(os.path.expanduser("~"), ".netrc")
|
file = os.path.join(os.path.expanduser("~"), ".netrc")
|
||||||
self.hosts = {}
|
self.hosts = {}
|
||||||
self.macros = {}
|
self.macros = {}
|
||||||
with open(file) as fp:
|
try:
|
||||||
self._parse(file, fp, default_netrc)
|
with open(file, encoding="utf-8") as fp:
|
||||||
|
self._parse(file, fp, default_netrc)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
with open(file, encoding="locale") as fp:
|
||||||
|
self._parse(file, fp, default_netrc)
|
||||||
|
|
||||||
def _parse(self, file, fp, default_netrc):
|
def _parse(self, file, fp, default_netrc):
|
||||||
lexer = shlex.shlex(fp)
|
lexer = shlex.shlex(fp)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Change :class:`netrc.netrc` to use UTF-8 encoding before using locale
|
||||||
|
encoding.
|
Loading…
Reference in New Issue