Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65c32bb

Browse files
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 688722c) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 74ebbae commit 65c32bb

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Lib/idlelib/idle_test/test_textview.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_view_text(self):
112112
view.ok()
113113

114114
def test_view_file(self):
115-
view = tv.view_file(root, 'Title', __file__, modal=False)
115+
view = tv.view_file(root, 'Title', __file__, 'ascii', modal=False)
116116
self.assertIsInstance(view, tv.ViewWindow)
117117
self.assertIsInstance(view.viewframe, tv.ViewFrame)
118118
get = view.viewframe.textframe.text.get
@@ -121,7 +121,7 @@ def test_view_file(self):
121121

122122
def test_bad_file(self):
123123
# Mock showerror will be used; view_file will return None.
124-
view = tv.view_file(root, 'Title', 'abc.xyz', modal=False)
124+
view = tv.view_file(root, 'Title', 'abc.xyz', 'ascii', modal=False)
125125
self.assertIsNone(view)
126126
self.assertEqual(tv.showerror.title, 'File Load Error')
127127

@@ -161,7 +161,8 @@ def _command():
161161
def test_view_file_bind_with_button(self):
162162
def _command():
163163
self.called = True
164-
self.view = tv.view_file(root, 'TITLE_FILE', __file__, _utest=True)
164+
self.view = tv.view_file(root, 'TITLE_FILE', __file__,
165+
encoding='ascii', _utest=True)
165166
button = Button(root, text='BUTTON', command=_command)
166167
button.invoke()
167168
self.addCleanup(button.destroy)

Lib/idlelib/textview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def view_text(parent, title, text, modal=True, _utest=False):
107107
return ViewWindow(parent, title, text, modal, _utest=_utest)
108108

109109

110-
def view_file(parent, title, filename, encoding=None, modal=True, _utest=False):
110+
def view_file(parent, title, filename, encoding, modal=True, _utest=False):
111111
"""Create text viewer for text in filename.
112112
113113
Return error message if file cannot be read. Otherwise calls view_text
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Using the system and place-dependent default encoding for open() is a bad
2+
idea for IDLE's system and location-independent files.

0 commit comments

Comments
 (0)