[Python-checkins] bpo-41152: IDLE: always use UTF-8 for standard IO streams (GH-21214)
Miss Islington (bot)
webhook-mailer at python.org
Mon Jun 29 20:39:06 EDT 2020
https://github.com/python/cpython/commit/00fd04b9b7537c473c3f9396a861868b8ddd3bb2
commit: 00fd04b9b7537c473c3f9396a861868b8ddd3bb2
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-06-29T17:39:02-07:00
summary:
bpo-41152: IDLE: always use UTF-8 for standard IO streams (GH-21214)
(cherry picked from commit 2515a28230b1a011205f30263da6b01c6bd167a3)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
A Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/idle_test/test_outwin.py
M Lib/idlelib/iomenu.py
M Lib/idlelib/outwin.py
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 584fd4631fbc2..59b34b1519fdf 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,9 @@ Released on 2020-07-03?
======================================
+bpo-41152: The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE
+is now always UTF-8.
+
bpo-41144: Make Open Module open a special module such as os.path.
bpo-40723: Make test_idle pass when run after import.
diff --git a/Lib/idlelib/idle_test/test_outwin.py b/Lib/idlelib/idle_test/test_outwin.py
index cd099ecd841b3..e347bfca7f191 100644
--- a/Lib/idlelib/idle_test/test_outwin.py
+++ b/Lib/idlelib/idle_test/test_outwin.py
@@ -58,11 +58,6 @@ def test_write(self):
get = self.text.get
write = self.window.write
- # Test bytes.
- b = b'Test bytes.'
- eq(write(b), len(b))
- eq(get('1.0', '1.end'), b.decode())
-
# No new line - insert stays on same line.
delete('1.0', 'end')
test_text = 'test text'
diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py
index 4b2833b8ca56f..7f3f656ee2874 100644
--- a/Lib/idlelib/iomenu.py
+++ b/Lib/idlelib/iomenu.py
@@ -13,52 +13,12 @@
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)
diff --git a/Lib/idlelib/outwin.py b/Lib/idlelib/outwin.py
index 90272b6feb4af..5ab08bbaf4bc9 100644
--- a/Lib/idlelib/outwin.py
+++ b/Lib/idlelib/outwin.py
@@ -6,7 +6,6 @@
from tkinter import messagebox
from idlelib.editor import EditorWindow
-from idlelib import iomenu
file_line_pats = [
@@ -110,8 +109,7 @@ def write(self, s, tags=(), mark="insert"):
Return:
Length of text inserted.
"""
- if isinstance(s, bytes):
- s = s.decode(iomenu.encoding, "replace")
+ assert isinstance(s, str)
self.text.insert(mark, s, tags)
self.text.see(mark)
self.text.update()
diff --git a/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst b/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst
new file mode 100644
index 0000000000000..434be10b5309c
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2020-06-29-14-51-15.bpo-41152.d6mV0C.rst
@@ -0,0 +1,2 @@
+The encoding of ``stdin``, ``stdout`` and ``stderr`` in IDLE is now always
+UTF-8.
More information about the Python-checkins
mailing list