diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-25 13:30:58 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-25 13:30:58 (GMT) |
commit | 39e70a4e837a4ebfae009bc202ac274aa9005fb6 (patch) | |
tree | 9327ac4ae34b55d631f7d22cc26c90029985c2a4 /Lib/idlelib/run.py | |
parent | 3e6e2ac31d8b847f65240f333e54322880adc914 (diff) | |
download | cpython-39e70a4e837a4ebfae009bc202ac274aa9005fb6.zip cpython-39e70a4e837a4ebfae009bc202ac274aa9005fb6.tar.gz cpython-39e70a4e837a4ebfae009bc202ac274aa9005fb6.tar.bz2 |
Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
interface and support all mandatory methods and properties.
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r-- | Lib/idlelib/run.py | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index b0a4794..7d0941e 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -15,6 +15,8 @@ from idlelib import RemoteDebugger from idlelib import RemoteObjectBrowser from idlelib import StackViewer from idlelib import rpc +from idlelib import PyShell +from idlelib import IOBinding import __main__ @@ -262,62 +264,23 @@ 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): def handle(self): """Override base method""" executive = Executive(self) self.register("exec", executive) - 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")) + self.console = self.get_remote_proxy("console") + sys.stdin = PyShell.PseudoInputFile(self.console, "stdin", + IOBinding.encoding) + sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout", + IOBinding.encoding) + sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr", + IOBinding.encoding) + # page help() text to shell. import pydoc # import must be done here to capture i/o binding pydoc.pager = pydoc.plainpager - from idlelib import IOBinding - sys.stdin.encoding = sys.stdout.encoding = \ - sys.stderr.encoding = IOBinding.encoding self.interp = self.get_remote_proxy("interp") rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05) |