summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r--Lib/idlelib/run.py54
1 files changed, 48 insertions, 6 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index fd2cc09..5365680 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,4 +1,5 @@
import sys
+import io
import linecache
import time
import socket
@@ -25,12 +26,13 @@ except ImportError:
pass
else:
def idle_formatwarning_subproc(message, category, filename, lineno,
- file=None, line=None):
+ line=None):
"""Format warnings the IDLE way"""
s = "\nWarning (from warnings module):\n"
s += ' File \"%s\", line %s\n' % (filename, lineno)
- line = linecache.getline(filename, lineno).strip() \
- if line is None else line
+ if line is None:
+ line = linecache.getline(filename, lineno)
+ line = line.strip()
if line:
s += " %s\n" % line
s += "%s: %s\n" % (category.__name__, message)
@@ -243,6 +245,45 @@ class MyRPCServer(rpc.RPCServer):
quitting = True
thread.interrupt_main()
+class _RPCFile(io.TextIOBase):
+ """Wrapper class for the RPC proxy to typecheck arguments
+ that may not support pickling. The base class is there only
+ to support type tests; all implementations come from the remote
+ object."""
+
+ def __init__(self, rpc):
+ super.__setattr__(self, 'rpc', rpc)
+
+ def __getattribute__(self, name):
+ # When accessing the 'rpc' attribute, or 'write', use ours
+ if name in ('rpc', 'write', 'writelines'):
+ return io.TextIOBase.__getattribute__(self, name)
+ # Else only look into the remote object only
+ return getattr(self.rpc, name)
+
+ def __setattr__(self, name, value):
+ return setattr(self.rpc, name, value)
+
+ @staticmethod
+ def _ensure_string(func):
+ def f(self, s):
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
+ return func(self, s)
+ return f
+
+class _RPCOutputFile(_RPCFile):
+ @_RPCFile._ensure_string
+ def write(self, s):
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
+ return self.rpc.write(s)
+
+class _RPCInputFile(_RPCFile):
+ @_RPCFile._ensure_string
+ def write(self, s):
+ raise io.UnsupportedOperation("not writable")
+ writelines = write
class MyHandler(rpc.RPCHandler):
@@ -250,9 +291,10 @@ class MyHandler(rpc.RPCHandler):
"""Override base method"""
executive = Executive(self)
self.register("exec", executive)
- sys.stdin = self.console = self.get_remote_proxy("stdin")
- sys.stdout = self.get_remote_proxy("stdout")
- sys.stderr = self.get_remote_proxy("stderr")
+ self.console = self.get_remote_proxy("stdin")
+ sys.stdin = _RPCInputFile(self.console)
+ sys.stdout = _RPCOutputFile(self.get_remote_proxy("stdout"))
+ sys.stderr = _RPCOutputFile(self.get_remote_proxy("stderr"))
# page help() text to shell.
import pydoc # import must be done here to capture i/o binding
pydoc.pager = pydoc.plainpager