summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-07-09 19:01:49 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-07-09 19:01:49 (GMT)
commite8e4e1456c8c168b5d1b5065280a50b3b5cf394f (patch)
tree12ffcdb972cc181e17b7aa2ec183dec791c59493 /Lib/idlelib
parent45ed012433443cc9d79729b91f01f4a5ffe28ba6 (diff)
downloadcpython-e8e4e1456c8c168b5d1b5065280a50b3b5cf394f.zip
cpython-e8e4e1456c8c168b5d1b5065280a50b3b5cf394f.tar.gz
cpython-e8e4e1456c8c168b5d1b5065280a50b3b5cf394f.tar.bz2
- Issue #13532: Check that arguments to sys.stdout.write are strings.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/NEWS.txt2
-rw-r--r--Lib/idlelib/PyShell.py2
-rw-r--r--Lib/idlelib/run.py24
3 files changed, 25 insertions, 3 deletions
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 4da3618..55ae5ad 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -1,6 +1,8 @@
What's New in IDLE 2.7.4?
=========================
+- Issue #13532: Check that arguments to sys.stdout.write are strings.
+
- Issue # 12510: Attempt to get certain tool tips no longer crashes IDLE.
- Issue10365: File open dialog now works instead of crashing even when
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index fa2e150..14f062e 100644
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -1265,6 +1265,8 @@ class PseudoFile(object):
self.encoding = encoding
def write(self, s):
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
self.shell.write(s, self.tags)
def writelines(self, lines):
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 642b979..82db38a 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,4 +1,5 @@
import sys
+import io
import linecache
import time
import socket
@@ -248,6 +249,23 @@ 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."""
+
+ def __init__(self, rpc):
+ super.__setattr__(self, 'rpc', rpc)
+
+ def __getattr__(self, name):
+ return getattr(self.rpc, name)
+
+ def __setattr__(self, name, value):
+ return setattr(self.rpc, name, value)
+
+ def write(self, s):
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
+ return self.rpc.write(s)
class MyHandler(rpc.RPCHandler):
@@ -255,9 +273,9 @@ class MyHandler(rpc.RPCHandler):
"""Override base method"""
executive = Executive(self)
self.register("exec", executive)
- sys.stdin = self.console = self.get_remote_proxy("stdin")
- sys.stdout = self.get_remote_proxy("stdout")
- sys.stderr = self.get_remote_proxy("stderr")
+ sys.stdin = self.console = _RPCFile(self.get_remote_proxy("stdin"))
+ sys.stdout = _RPCFile(self.get_remote_proxy("stdout"))
+ sys.stderr = _RPCFile(self.get_remote_proxy("stderr"))
from idlelib import IOBinding
sys.stdin.encoding = sys.stdout.encoding = \
sys.stderr.encoding = IOBinding.encoding