summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/iomenu.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-30 00:36:46 (GMT)
committerGitHub <noreply@github.com>2020-06-30 00:36:46 (GMT)
commit01638ce51a63afe5af3f778e7403702703bb41b9 (patch)
treeba86e00c938703da400ecd6a0505235c4513545a /Lib/idlelib/iomenu.py
parent9a646aa82dfa62d70ca2a99ada901ee6cf9f82bd (diff)
downloadcpython-01638ce51a63afe5af3f778e7403702703bb41b9.zip
cpython-01638ce51a63afe5af3f778e7403702703bb41b9.tar.gz
cpython-01638ce51a63afe5af3f778e7403702703bb41b9.tar.bz2
bpo-41152: IDLE: always use UTF-8 for standard IO streams (GH-21214)
(cherry picked from commit 2515a28230b1a011205f30263da6b01c6bd167a3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/idlelib/iomenu.py')
-rw-r--r--Lib/idlelib/iomenu.py48
1 files changed, 4 insertions, 44 deletions
diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py
index 4b2833b..7f3f656 100644
--- a/Lib/idlelib/iomenu.py
+++ b/Lib/idlelib/iomenu.py
@@ -13,52 +13,12 @@ from tkinter.simpledialog import askstring
import idlelib
from idlelib.config import idleConf
-if idlelib.testing: # Set True by test.test_idle to avoid setlocale.
- encoding = 'utf-8'
- errors = 'surrogateescape'
+encoding = 'utf-8'
+if sys.platform == 'win32':
+ errors = 'surrogatepass'
else:
- # Try setting the locale, so that we can find out
- # what encoding to use
- try:
- import locale
- locale.setlocale(locale.LC_CTYPE, "")
- except (ImportError, locale.Error):
- pass
-
- if sys.platform == 'win32':
- encoding = 'utf-8'
- errors = 'surrogateescape'
- else:
- try:
- # Different things can fail here: the locale module may not be
- # loaded, it may not offer nl_langinfo, or CODESET, or the
- # resulting codeset may be unknown to Python. We ignore all
- # these problems, falling back to ASCII
- locale_encoding = locale.nl_langinfo(locale.CODESET)
- if locale_encoding:
- codecs.lookup(locale_encoding)
- except (NameError, AttributeError, LookupError):
- # Try getdefaultlocale: it parses environment variables,
- # which may give a clue. Unfortunately, getdefaultlocale has
- # bugs that can cause ValueError.
- try:
- locale_encoding = locale.getdefaultlocale()[1]
- if locale_encoding:
- codecs.lookup(locale_encoding)
- except (ValueError, LookupError):
- pass
+ errors = 'surrogateescape'
- if locale_encoding:
- encoding = locale_encoding.lower()
- errors = 'strict'
- else:
- # POSIX locale or macOS
- encoding = 'ascii'
- errors = 'surrogateescape'
- # Encoding is used in multiple files; locale_encoding nowhere.
- # The only use of 'encoding' below is in _decode as initial value
- # of deprecated block asking user for encoding.
- # Perhaps use elsewhere should be reviewed.
coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII)