diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-25 13:35:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-25 13:35:28 (GMT) |
commit | 4c9bae3d316956ffc566d4c28a2d48ec39e3cf12 (patch) | |
tree | 7a1da2d41ddd7bc9091ad5ce6becc47408b31753 /Lib/idlelib/run.py | |
parent | 3f50bf652bae5e3371972eb261973238c62cc17b (diff) | |
parent | b1b3c0dfef5fbbd6fb2247758216bb1cbc157dc5 (diff) | |
download | cpython-4c9bae3d316956ffc566d4c28a2d48ec39e3cf12.zip cpython-4c9bae3d316956ffc566d4c28a2d48ec39e3cf12.tar.gz cpython-4c9bae3d316956ffc566d4c28a2d48ec39e3cf12.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 41e4bf9..c66679c 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -16,6 +16,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__ @@ -277,63 +279,24 @@ 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) + 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 - 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) |