From c8b4c9fe1a1e46e3c098fdafe2b0eb9c85df88c8 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 23 Sep 2002 14:30:24 +0000 Subject: [PATCH] Backport: Convert characters from the locale's encoding on output. Reject characters outside the locale's encoding on input. --- Tools/idle/OutputWindow.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tools/idle/OutputWindow.py b/Tools/idle/OutputWindow.py index f429f2e8bfb6..0e7fba231ab5 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() -- 2.47.3