From cd49d5323833ff15cc10a918bdb2afcb02e500a4 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 25 Mar 2012 11:43:02 +0300 Subject: =?UTF-8?q?Issue=20#14200=20=E2=80=94=20now=20displayhook=20for=20?= =?UTF-8?q?IDLE=20works=20in=20non-subprocess=20mode=20as=20well=20as=20su?= =?UTF-8?q?bprecess.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/idlelib/rpc.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Lib/idlelib/rpc.py') diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index 301305ee90..77cb3ac0a3 100644 --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -40,6 +40,7 @@ import traceback import copyreg import types import marshal +import builtins def unpickle_code(ms): @@ -603,3 +604,21 @@ class MethodProxy(object): # XXX KBK 09Sep03 We need a proper unit test for this module. Previously # existing test code was removed at Rev 1.27 (r34098). + +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 -- cgit v1.2.1