summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2021-05-02 05:01:02 (GMT)
committerGitHub <noreply@github.com>2021-05-02 05:01:02 (GMT)
commitfd0bc7e7f4f2c7de98a1ebc7ad1ef65b8f8f7ad6 (patch)
tree7b29d646ed11327975d742a34510a85de403e5d7 /Lib
parent49b26fa517165f991c35a4afcbef1fcb26836bec (diff)
downloadcpython-fd0bc7e7f4f2c7de98a1ebc7ad1ef65b8f8f7ad6.zip
cpython-fd0bc7e7f4f2c7de98a1ebc7ad1ef65b8f8f7ad6.tar.gz
cpython-fd0bc7e7f4f2c7de98a1ebc7ad1ef65b8f8f7ad6.tar.bz2
bpo-43733: netrc try to use UTF-8 before using locale encoding. (GH-25781)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/netrc.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/netrc.py b/Lib/netrc.py
index f0ae48c..734d94c 100644
--- a/Lib/netrc.py
+++ b/Lib/netrc.py
@@ -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)