summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-09-23 14:30:24 +0000
committerRaymond Hettinger <python@rcn.com>2002-09-23 14:30:24 +0000
commitc8b4c9fe1a1e46e3c098fdafe2b0eb9c85df88c8 (patch)
tree04bd78b39bd981a9c2e21b7ec0d4270f56fc27b2 /Tools
parent1124a3b50b7d47b05b93526b62d3118283c6921c (diff)
downloadcpython-git-c8b4c9fe1a1e46e3c098fdafe2b0eb9c85df88c8.tar.gz
Backport:
Convert characters from the locale's encoding on output. Reject characters outside the locale's encoding on input.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/idle/OutputWindow.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Tools/idle/OutputWindow.py b/Tools/idle/OutputWindow.py
index f429f2e8bf..0e7fba231a 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()