summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-25 08:43:02 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-25 08:43:02 (GMT)
commitcd49d5323833ff15cc10a918bdb2afcb02e500a4 (patch)
tree49580ece73a971a467b39ed4fbfc1af6fd71d7cf /Lib/idlelib
parent1a7742eb4d7960c72fc1be794c988d648e5ef139 (diff)
downloadcpython-cd49d5323833ff15cc10a918bdb2afcb02e500a4.zip
cpython-cd49d5323833ff15cc10a918bdb2afcb02e500a4.tar.gz
cpython-cd49d5323833ff15cc10a918bdb2afcb02e500a4.tar.bz2
Issue #14200 — now displayhook for IDLE works in non-subprocess mode as well as subprecess.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/PyShell.py2
-rw-r--r--Lib/idlelib/rpc.py19
-rw-r--r--Lib/idlelib/run.py22
3 files changed, 22 insertions, 21 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index d7edce5..c524d61 100644
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -999,6 +999,8 @@ class PyShell(OutputWindow):
return False
else:
nosub = "==== No Subprocess ===="
+ sys.displayhook = rpc.displayhook
+
self.write("Python %s on %s\n%s\n%s" %
(sys.version, sys.platform, self.COPYRIGHT, nosub))
self.showprompt()
diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py
index 301305e..77cb3ac 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
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index a161a93..5e12f7e 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -6,7 +6,6 @@ import traceback
import _thread as thread
import threading
import queue
-import builtins
from idlelib import CallTips
from idlelib import AutoComplete
@@ -262,25 +261,6 @@ 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):
@@ -290,7 +270,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
+ sys.displayhook = rpc.displayhook
# page help() text to shell.
import pydoc # import must be done here to capture i/o binding
pydoc.pager = pydoc.plainpager