mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-43733: netrc try to use UTF-8 before using locale encoding. (GH-25781)
This commit is contained in:
parent
49b26fa517
commit
fd0bc7e7f4
3 changed files with 12 additions and 2 deletions
|
@ -26,8 +26,12 @@ class netrc:
|
|||
file = os.path.join(os.path.expanduser("~"), ".netrc")
|
||||
self.hosts = {}
|
||||
self.macros = {}
|
||||
with open(file) as fp:
|
||||
self._parse(file, fp, default_netrc)
|
||||
try:
|
||||
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):
|
||||
lexer = shlex.shlex(fp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue