summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/PyShell.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-07-25 08:47:20 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-07-25 08:47:20 (GMT)
commitc882b7c51ab4b76bdf44cf4dab5ca1b55ccb2155 (patch)
tree5886ffcc7f01739b27f72b807c69601773d33ab7 /Lib/idlelib/PyShell.py
parent186396dce60feb6c215fbf5a3763baeebe8d8b0d (diff)
downloadcpython-c882b7c51ab4b76bdf44cf4dab5ca1b55ccb2155.zip
cpython-c882b7c51ab4b76bdf44cf4dab5ca1b55ccb2155.tar.gz
cpython-c882b7c51ab4b76bdf44cf4dab5ca1b55ccb2155.tar.bz2
Issue #15318: Prevent writing to sys.stdin.
Patch by Roger Serwy and myself.
Diffstat (limited to 'Lib/idlelib/PyShell.py')
-rw-r--r--Lib/idlelib/PyShell.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index a25ca87..83d40df 100644
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -12,6 +12,7 @@ import time
import tokenize
import traceback
import types
+import io
import linecache
from code import InteractiveInterpreter
@@ -410,6 +411,9 @@ class ModifiedInterpreter(InteractiveInterpreter):
except socket.timeout as err:
self.display_no_subprocess_error()
return None
+ # Can't regiter self.tkconsole.stdin, since run.py wants to
+ # call non-TextIO methods on it (such as getvar)
+ # XXX should be renamed to "console"
self.rpcclt.register("stdin", self.tkconsole)
self.rpcclt.register("stdout", self.tkconsole.stdout)
self.rpcclt.register("stderr", self.tkconsole.stderr)
@@ -850,13 +854,14 @@ class PyShell(OutputWindow):
self.save_stderr = sys.stderr
self.save_stdin = sys.stdin
from idlelib import IOBinding
+ self.stdin = PseudoInputFile(self)
self.stdout = PseudoFile(self, "stdout", IOBinding.encoding)
self.stderr = PseudoFile(self, "stderr", IOBinding.encoding)
self.console = PseudoFile(self, "console", IOBinding.encoding)
if not use_subprocess:
sys.stdout = self.stdout
sys.stderr = self.stderr
- sys.stdin = self
+ sys.stdin = self.stdin
try:
# page help() text to shell.
import pydoc # import must be done here to capture i/o rebinding.
@@ -1256,6 +1261,15 @@ class PseudoFile(object):
def isatty(self):
return True
+class PseudoInputFile(object):
+ def __init__(self, shell):
+ self.readline = shell.readline
+ self.isatty = shell.isatty
+
+ def write(self, s):
+ raise io.UnsupportedOperation("not writable")
+ writelines = write
+
usage_msg = """\