Kaydet (Commit) 75ea1e11 authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Convert characters from the locale's encoding on output.

Reject characters outside the locale's encoding on input.
üst 3ddb856e
......@@ -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()
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment