]> granicus.if.org Git - python/commitdiff
Issue #14200 — now displayhook for IDLE works in non-subprocess mode as well as subpr...
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Sun, 25 Mar 2012 08:43:02 +0000 (11:43 +0300)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Sun, 25 Mar 2012 08:43:02 +0000 (11:43 +0300)
Lib/idlelib/PyShell.py
Lib/idlelib/rpc.py
Lib/idlelib/run.py

index d7edce501f49430c7b778fc0860f0187bc7f97d1..c524d61e4ee89a6136b3bf873ec30abcbf910fa8 100644 (file)
@@ -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()
index 301305ee90865d40574179c36fcd3345cf23dd20..77cb3ac0a301253310e2f7201cdb411872a0d801 100644 (file)
@@ -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
index a161a93c4dad1d49c244710d163fffd15f4949cf..5e12f7eeb1ef07209e70225676bdc95c8b55206a 100644 (file)
@@ -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