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

Skip to content

bpo-32837: IDLE - require encoding argument for textview.view_file. #5646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Lib/idlelib/idle_test/test_textview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/textview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.