summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-07-25 08:49:32 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-07-25 08:49:32 (GMT)
commitf4b341b0e6fa19e2ae88df754081a24ef1eaf033 (patch)
tree05ee195c100994bf716cc7788a964b0dc1824566 /Lib/idlelib
parentf3923e9dd7a49bc2bc8600b3e0bb147b70e2de28 (diff)
parentc882b7c51ab4b76bdf44cf4dab5ca1b55ccb2155 (diff)
downloadcpython-f4b341b0e6fa19e2ae88df754081a24ef1eaf033.zip
cpython-f4b341b0e6fa19e2ae88df754081a24ef1eaf033.tar.gz
cpython-f4b341b0e6fa19e2ae88df754081a24ef1eaf033.tar.bz2
merge 3.2
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/NEWS.txt2
-rw-r--r--Lib/idlelib/PyShell.py16
-rw-r--r--Lib/idlelib/run.py25
3 files changed, 38 insertions, 5 deletions
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 0cdf7a6..6b430b5 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -1,6 +1,8 @@
What's New in IDLE 3.3.0?
=========================
+- Issue #15318: Prevent writing to sys.stdin.
+
- Issue #4832: Modify IDLE to save files with .py extension by
default on Windows and OS X (Tk 8.5) as it already does with X11 Tk.
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index f692a54..0a05d78 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)
@@ -854,13 +858,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.
@@ -1272,6 +1277,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 = """\
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 464861f..9872af4 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -269,7 +269,7 @@ class _RPCFile(io.TextIOBase):
def __getattribute__(self, name):
# When accessing the 'rpc' attribute, or 'write', use ours
- if name in ('rpc', 'write'):
+ 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)
@@ -277,20 +277,37 @@ class _RPCFile(io.TextIOBase):
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)
- sys.stdin = self.console = self.get_remote_proxy("stdin")
- sys.stdout = _RPCFile(self.get_remote_proxy("stdout"))
- sys.stderr = _RPCFile(self.get_remote_proxy("stderr"))
+ 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"))
sys.displayhook = rpc.displayhook
# page help() text to shell.
import pydoc # import must be done here to capture i/o binding