mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15318: Prevent writing to sys.stdin.
Patch by Roger Serwy and myself.
This commit is contained in:
parent
7009845c62
commit
e2b5624ee8
3 changed files with 38 additions and 7 deletions
|
@ -11,6 +11,7 @@ import time
|
|||
import threading
|
||||
import traceback
|
||||
import types
|
||||
import io
|
||||
|
||||
import linecache
|
||||
from code import InteractiveInterpreter
|
||||
|
@ -422,6 +423,9 @@ class ModifiedInterpreter(InteractiveInterpreter):
|
|||
except socket.timeout, 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)
|
||||
|
@ -875,13 +879,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
|
||||
#
|
||||
self.history = self.History(self.text)
|
||||
#
|
||||
|
@ -1279,6 +1284,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 = """\
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue