From 75ea1e11dcb90c768af6a222ae8e20a4f532617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sat, 10 Aug 2002 12:22:12 +0000 Subject: Convert characters from the locale's encoding on output. Reject characters outside the locale's encoding on input. --- Tools/idle/OutputWindow.py | 9 +++++++++ Tools/idle/PyShell.py | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Tools/idle/OutputWindow.py b/Tools/idle/OutputWindow.py index f429f2e..0e7fba2 100644 --- a/Tools/idle/OutputWindow.py +++ b/Tools/idle/OutputWindow.py @@ -2,6 +2,7 @@ from Tkinter import * from EditorWindow import EditorWindow import re import tkMessageBox +import IOBinding class OutputWindow(EditorWindow): @@ -34,6 +35,14 @@ class OutputWindow(EditorWindow): # Act as output file def write(self, s, tags=(), mark="insert"): + # Tk assumes that byte strings are Latin-1; + # we assume that they are in the locale's encoding + if isinstance(s, str): + try: + s = unicode(s, IOBinding.encoding) + except UnicodeError: + # some other encoding; let Tcl deal with it + pass self.text.insert(mark, s, tags) self.text.see(mark) self.text.update() diff --git a/Tools/idle/PyShell.py b/Tools/idle/PyShell.py index 31a8940..e71a9a1 100644 --- a/Tools/idle/PyShell.py +++ b/Tools/idle/PyShell.py @@ -191,7 +191,12 @@ class ModifiedInterpreter(InteractiveInterpreter): warnings.filterwarnings(action="error", category=SyntaxWarning) if isinstance(source, types.UnicodeType): import IOBinding - source = source.encode(IOBinding.encoding) + try: + source = source.encode(IOBinding.encoding) + except UnicodeError: + self.tkconsole.resetoutput() + self.write("Unsupported characters in input") + return try: return InteractiveInterpreter.runsource(self, source, filename) finally: -- cgit v0.12