mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Convert characters from the locale's encoding on output.
Reject characters outside the locale's encoding on input.
This commit is contained in:
parent
3ddb856ed1
commit
75ea1e11dc
2 changed files with 15 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
from EditorWindow import EditorWindow
|
from EditorWindow import EditorWindow
|
||||||
import re
|
import re
|
||||||
import tkMessageBox
|
import tkMessageBox
|
||||||
|
import IOBinding
|
||||||
|
|
||||||
class OutputWindow(EditorWindow):
|
class OutputWindow(EditorWindow):
|
||||||
|
|
||||||
|
|
@ -34,6 +35,14 @@ def maybesave(self):
|
||||||
# Act as output file
|
# Act as output file
|
||||||
|
|
||||||
def write(self, s, tags=(), mark="insert"):
|
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.insert(mark, s, tags)
|
||||||
self.text.see(mark)
|
self.text.see(mark)
|
||||||
self.text.update()
|
self.text.update()
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,12 @@ def runsource(self, source):
|
||||||
warnings.filterwarnings(action="error", category=SyntaxWarning)
|
warnings.filterwarnings(action="error", category=SyntaxWarning)
|
||||||
if isinstance(source, types.UnicodeType):
|
if isinstance(source, types.UnicodeType):
|
||||||
import IOBinding
|
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:
|
try:
|
||||||
return InteractiveInterpreter.runsource(self, source, filename)
|
return InteractiveInterpreter.runsource(self, source, filename)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue