summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-14 20:22:12 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-14 20:22:12 (GMT)
commit05bab93339308d330d6bd718575212ae2b3dc46d (patch)
treebb17df498b687ce4b5fafaa7f4629a5cfba84851 /Lib/idlelib/run.py
parentc5ceb0aaafa3064c8f301ebbedf44f421d3f3eba (diff)
downloadcpython-05bab93339308d330d6bd718575212ae2b3dc46d.zip
cpython-05bab93339308d330d6bd718575212ae2b3dc46d.tar.gz
cpython-05bab93339308d330d6bd718575212ae2b3dc46d.tar.bz2
Issue #14200: Idle shell crash on printing non-BMP unicode character.
UnicodeEncodeError is raised for strings contains non-BMP characters. For eval results unicode escaping is used, print() calls display exception with traceback as usual.
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r--Lib/idlelib/run.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 962c6c0..a161a93 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -6,6 +6,7 @@ import traceback
import _thread as thread
import threading
import queue
+import builtins
from idlelib import CallTips
from idlelib import AutoComplete
@@ -261,6 +262,25 @@ class MyRPCServer(rpc.RPCServer):
thread.interrupt_main()
+def displayhook(value):
+ """Override standard display hook to use non-locale encoding"""
+ if value is None:
+ return
+ # Set '_' to None to avoid recursion
+ builtins._ = None
+ text = repr(value)
+ try:
+ sys.stdout.write(text)
+ except UnicodeEncodeError:
+ # let's use ascii while utf8-bmp codec doesn't present
+ encoding = 'ascii'
+ bytes = text.encode(encoding, 'backslashreplace')
+ text = bytes.decode(encoding, 'strict')
+ sys.stdout.write(text)
+ sys.stdout.write("\n")
+ builtins._ = value
+
+
class MyHandler(rpc.RPCHandler):
def handle(self):
@@ -270,6 +290,7 @@ class MyHandler(rpc.RPCHandler):
sys.stdin = self.console = self.get_remote_proxy("stdin")
sys.stdout = self.get_remote_proxy("stdout")
sys.stderr = self.get_remote_proxy("stderr")
+ sys.displayhook = displayhook
# page help() text to shell.
import pydoc # import must be done here to capture i/o binding
pydoc.pager = pydoc.plainpager