Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
interface and support all mandatory methods and properties.
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 8e90370..acae3ae 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -15,6 +15,8 @@
 from idlelib import RemoteObjectBrowser
 from idlelib import StackViewer
 from idlelib import rpc
+from idlelib import PyShell
+from idlelib import IOBinding
 
 import __main__
 
@@ -249,57 +251,19 @@
             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, basestring):
-                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):
-        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"))
-        from idlelib import IOBinding
-        sys.stdin.encoding = sys.stdout.encoding = \
-                             sys.stderr.encoding = IOBinding.encoding
+        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)
         self.interp = self.get_remote_proxy("interp")
         rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)