[Python-checkins] bpo-32837: IDLE - require encoding argument for textview.view_file. (GH-5646)
Miss Islington (bot)
webhook-mailer at python.org
Mon Feb 12 18:15:05 EST 2018
https://github.com/python/cpython/commit/65c32bbe85862ab5eb52a0d4340e844e13d0f7ee
commit: 65c32bbe85862ab5eb52a0d4340e844e13d0f7ee
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-02-12T15:15:01-08:00
summary:
bpo-32837: IDLE - require encoding argument for textview.view_file. (GH-5646)
Using the system and place-dependent default encoding for open()
is a bad idea for IDLE's system and location-independent files.
(cherry picked from commit 688722cedd6437910ff185ecf94fb3b749ad37f2)
Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>
files:
A Misc/NEWS.d/next/IDLE/2018-02-12-17-22-48.bpo-32837.-33QPl.rst
M Lib/idlelib/idle_test/test_textview.py
M Lib/idlelib/textview.py
diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py
index c129c2f0819a..dfd4063eb08d 100644
--- a/Lib/idlelib/idle_test/test_textview.py
+++ b/Lib/idlelib/idle_test/test_textview.py
@@ -112,7 +112,7 @@ def test_view_text(self):
view.ok()
def test_view_file(self):
- view = tv.view_file(root, 'Title', __file__, modal=False)
+ view = tv.view_file(root, 'Title', __file__, 'ascii', modal=False)
self.assertIsInstance(view, tv.ViewWindow)
self.assertIsInstance(view.viewframe, tv.ViewFrame)
get = view.viewframe.textframe.text.get
@@ -121,7 +121,7 @@ def test_view_file(self):
def test_bad_file(self):
# Mock showerror will be used; view_file will return None.
- view = tv.view_file(root, 'Title', 'abc.xyz', modal=False)
+ view = tv.view_file(root, 'Title', 'abc.xyz', 'ascii', modal=False)
self.assertIsNone(view)
self.assertEqual(tv.showerror.title, 'File Load Error')
@@ -161,7 +161,8 @@ def _command():
def test_view_file_bind_with_button(self):
def _command():
self.called = True
- self.view = tv.view_file(root, 'TITLE_FILE', __file__, _utest=True)
+ self.view = tv.view_file(root, 'TITLE_FILE', __file__,
+ encoding='ascii', _utest=True)
button = Button(root, text='BUTTON', command=_command)
button.invoke()
self.addCleanup(button.destroy)
diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py
index e3b55065c6d9..662013440610 100644
--- a/Lib/idlelib/textview.py
+++ b/Lib/idlelib/textview.py
@@ -107,7 +107,7 @@ def view_text(parent, title, text, modal=True, _utest=False):
return ViewWindow(parent, title, text, modal, _utest=_utest)
-def view_file(parent, title, filename, encoding=None, modal=True, _utest=False):
+def view_file(parent, title, filename, encoding, modal=True, _utest=False):
"""Create text viewer for text in filename.
Return error message if file cannot be read. Otherwise calls view_text
diff --git a/Misc/NEWS.d/next/IDLE/2018-02-12-17-22-48.bpo-32837.-33QPl.rst b/Misc/NEWS.d/next/IDLE/2018-02-12-17-22-48.bpo-32837.-33QPl.rst
new file mode 100644
index 000000000000..258536a1cd0c
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2018-02-12-17-22-48.bpo-32837.-33QPl.rst
@@ -0,0 +1,2 @@
+Using the system and place-dependent default encoding for open() is a bad
+idea for IDLE's system and location-independent files.
More information about the Python-checkins
mailing list