]> granicus.if.org Git - python/commitdiff
- Issue #13532: Check that arguments to sys.stdout.write are strings.
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Jul 2012 19:01:49 +0000 (21:01 +0200)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Jul 2012 19:01:49 +0000 (21:01 +0200)
Lib/idlelib/NEWS.txt
Lib/idlelib/PyShell.py
Lib/idlelib/run.py

index 4da361816c6bedc1fc28e1e06fc3313ee518144d..55ae5adeaf63f605aa1730a8a7e6e53ca2c1891e 100644 (file)
@@ -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
index fa2e150933d2755ed7e61be9846667de9d0a2b5c..14f062e09de80e61b6d01f0ddf21d3eb96500ee7 100644 (file)
@@ -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):
index 642b979d8b91c65eb4024ce5a0f2844037cf7adc..82db38a781ca2ec0bc2c7162734f355f595ef665 100644 (file)
@@ -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