cpython: 89878808f4ce (original) (raw)
Mercurial > cpython
changeset 75921:89878808f4ce
Issue #14200 — now displayhook for IDLE works in non-subprocess mode as well as subprecess. [#14200]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Sun, 25 Mar 2012 11:43:02 +0300 |
parents | 43f6a1078d67 |
children | 7d8339083cb3 |
files | Lib/idlelib/PyShell.py Lib/idlelib/rpc.py Lib/idlelib/run.py |
diffstat | 3 files changed, 22 insertions(+), 21 deletions(-)[+] [-] Lib/idlelib/PyShell.py 2 Lib/idlelib/rpc.py 19 Lib/idlelib/run.py 22 |
line wrap: on
line diff
--- 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[](#l1.7)
+ self.write("Python %s on %s\n%s\n%s" % (sys.version, sys.platform, self.COPYRIGHT, nosub)) self.showprompt()
--- 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).
- """Override standard display hook to use non-locale encoding"""
- if value is None:
return[](#l2.19)
Set '_' to None to avoid recursion
- builtins._ = None
- text = repr(value)
- try:
sys.stdout.write(text)[](#l2.24)
- except UnicodeEncodeError:
# let's use ascii while utf8-bmp codec doesn't present[](#l2.26)
encoding = 'ascii'[](#l2.27)
bytes = text.encode(encoding, 'backslashreplace')[](#l2.28)
text = bytes.decode(encoding, 'strict')[](#l2.29)
sys.stdout.write(text)[](#l2.30)
- sys.stdout.write("\n")
- builtins._ = value
--- 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[](#l3.18)
Set '_' to None to avoid recursion
- builtins._ = None
- text = repr(value)
- try:
sys.stdout.write(text)[](#l3.23)
- except UnicodeEncodeError:
# let's use ascii while utf8-bmp codec doesn't present[](#l3.25)
encoding = 'ascii'[](#l3.26)
bytes = text.encode(encoding, 'backslashreplace')[](#l3.27)
text = bytes.decode(encoding, 'strict')[](#l3.28)
sys.stdout.write(text)[](#l3.29)
- 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[](#l3.41)
sys.displayhook = rpc.displayhook[](#l3.42) # page help() text to shell.[](#l3.43) import pydoc # import must be done here to capture i/o binding[](#l3.44) pydoc.pager = pydoc.plainpager[](#l3.45)