[Python-checkins] cpython: Issue #14200 — now displayhook for IDLE works in non-subprocess mode as well
andrew.svetlov
python-checkins at python.org
Sun Mar 25 10:44:40 CEST 2012
http://hg.python.org/cpython/rev/89878808f4ce
changeset: 75921:89878808f4ce
user: Andrew Svetlov <andrew.svetlov at gmail.com>
date: Sun Mar 25 11:43:02 2012 +0300
summary:
Issue #14200 — now displayhook for IDLE works in non-subprocess mode as well as subprecess.
files:
Lib/idlelib/PyShell.py | 2 ++
Lib/idlelib/rpc.py | 19 +++++++++++++++++++
Lib/idlelib/run.py | 22 +---------------------
3 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -999,6 +999,8 @@
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
--- a/Lib/idlelib/rpc.py
+++ b/Lib/idlelib/rpc.py
@@ -40,6 +40,7 @@
import copyreg
import types
import marshal
+import builtins
def unpickle_code(ms):
@@ -603,3 +604,21 @@
# 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
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -6,7 +6,6 @@
import _thread as thread
import threading
import queue
-import builtins
from idlelib import CallTips
from idlelib import AutoComplete
@@ -262,25 +261,6 @@
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 @@
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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list