summaryrefslogtreecommitdiff
path: root/Lib/idlelib/iomenu.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-10-08 14:32:25 +0300
committerGitHub <noreply@github.com>2019-10-08 14:32:25 +0300
commitb690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb (patch)
treeef8fa0a711cb3780ac5bb33147bea57378322c62 /Lib/idlelib/iomenu.py
parentd05b000c6bcd39dba4f4b2656e45954802649562 (diff)
downloadcpython-git-b690a2759e62d9ee0b6ea1b20e8f7e4b2cdbf8bb.tar.gz
bpo-36698: IDLE no longer fails when write non-encodable characters to stderr. (GH-16583)
It now escapes them with a backslash, as the regular Python interpreter. Added the "errors" field to the standard streams.
Diffstat (limited to 'Lib/idlelib/iomenu.py')
-rw-r--r--Lib/idlelib/iomenu.py41
1 files changed, 18 insertions, 23 deletions
diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py
index b9e813be06..b5533be79f 100644
--- a/Lib/idlelib/iomenu.py
+++ b/Lib/idlelib/iomenu.py
@@ -15,6 +15,7 @@ from idlelib.config import idleConf
if idlelib.testing: # Set True by test.test_idle to avoid setlocale.
encoding = 'utf-8'
+ errors = 'surrogateescape'
else:
# Try setting the locale, so that we can find out
# what encoding to use
@@ -24,15 +25,9 @@ else:
except (ImportError, locale.Error):
pass
- locale_decode = 'ascii'
if sys.platform == 'win32':
- # On Windows, we could use "mbcs". However, to give the user
- # a portable encoding name, we need to find the code page
- try:
- locale_encoding = locale.getdefaultlocale()[1]
- codecs.lookup(locale_encoding)
- except LookupError:
- pass
+ encoding = 'utf-8'
+ errors = 'surrogateescape'
else:
try:
# Different things can fail here: the locale module may not be
@@ -40,30 +35,30 @@ else:
# 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 is None or locale_encoding == '':
- # situation occurs on macOS
- locale_encoding = 'ascii'
- codecs.lookup(locale_encoding)
+ 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 is None or locale_encoding == '':
- # situation occurs on macOS
- locale_encoding = 'ascii'
- codecs.lookup(locale_encoding)
+ if locale_encoding:
+ codecs.lookup(locale_encoding)
except (ValueError, LookupError):
pass
- locale_encoding = locale_encoding.lower()
-
- encoding = locale_encoding
- # 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.
+ 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)