Mercurial > cpython-lru_cache-weakref
comparison Lib/idlelib/PyShell.py @ 78273:a82fd35e28be 3.2
Issue #15318: Prevent writing to sys.stdin.
Patch by Roger Serwy and myself.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Wed, 25 Jul 2012 10:47:20 +0200 |
| parents | 422242dbce30 |
| children | f72965374b2a cffdb7d76691 |
comparison
equal
deleted
inserted
replaced
| 78269:0caff799e4bf | 78273:a82fd35e28be |
|---|---|
| 10 import threading | 10 import threading |
| 11 import time | 11 import time |
| 12 import tokenize | 12 import tokenize |
| 13 import traceback | 13 import traceback |
| 14 import types | 14 import types |
| 15 import io | |
| 15 | 16 |
| 16 import linecache | 17 import linecache |
| 17 from code import InteractiveInterpreter | 18 from code import InteractiveInterpreter |
| 18 | 19 |
| 19 try: | 20 try: |
| 408 try: | 409 try: |
| 409 self.rpcclt.accept() | 410 self.rpcclt.accept() |
| 410 except socket.timeout as err: | 411 except socket.timeout as err: |
| 411 self.display_no_subprocess_error() | 412 self.display_no_subprocess_error() |
| 412 return None | 413 return None |
| 414 # Can't regiter self.tkconsole.stdin, since run.py wants to | |
| 415 # call non-TextIO methods on it (such as getvar) | |
| 416 # XXX should be renamed to "console" | |
| 413 self.rpcclt.register("stdin", self.tkconsole) | 417 self.rpcclt.register("stdin", self.tkconsole) |
| 414 self.rpcclt.register("stdout", self.tkconsole.stdout) | 418 self.rpcclt.register("stdout", self.tkconsole.stdout) |
| 415 self.rpcclt.register("stderr", self.tkconsole.stderr) | 419 self.rpcclt.register("stderr", self.tkconsole.stderr) |
| 416 self.rpcclt.register("flist", self.tkconsole.flist) | 420 self.rpcclt.register("flist", self.tkconsole.flist) |
| 417 self.rpcclt.register("linecache", linecache) | 421 self.rpcclt.register("linecache", linecache) |
| 848 # | 852 # |
| 849 self.save_stdout = sys.stdout | 853 self.save_stdout = sys.stdout |
| 850 self.save_stderr = sys.stderr | 854 self.save_stderr = sys.stderr |
| 851 self.save_stdin = sys.stdin | 855 self.save_stdin = sys.stdin |
| 852 from idlelib import IOBinding | 856 from idlelib import IOBinding |
| 857 self.stdin = PseudoInputFile(self) | |
| 853 self.stdout = PseudoFile(self, "stdout", IOBinding.encoding) | 858 self.stdout = PseudoFile(self, "stdout", IOBinding.encoding) |
| 854 self.stderr = PseudoFile(self, "stderr", IOBinding.encoding) | 859 self.stderr = PseudoFile(self, "stderr", IOBinding.encoding) |
| 855 self.console = PseudoFile(self, "console", IOBinding.encoding) | 860 self.console = PseudoFile(self, "console", IOBinding.encoding) |
| 856 if not use_subprocess: | 861 if not use_subprocess: |
| 857 sys.stdout = self.stdout | 862 sys.stdout = self.stdout |
| 858 sys.stderr = self.stderr | 863 sys.stderr = self.stderr |
| 859 sys.stdin = self | 864 sys.stdin = self.stdin |
| 860 try: | 865 try: |
| 861 # page help() text to shell. | 866 # page help() text to shell. |
| 862 import pydoc # import must be done here to capture i/o rebinding. | 867 import pydoc # import must be done here to capture i/o rebinding. |
| 863 # XXX KBK 27Dec07 use a textView someday, but must work w/o subproc | 868 # XXX KBK 27Dec07 use a textView someday, but must work w/o subproc |
| 864 pydoc.pager = pydoc.plainpager | 869 pydoc.pager = pydoc.plainpager |
| 1253 def flush(self): | 1258 def flush(self): |
| 1254 pass | 1259 pass |
| 1255 | 1260 |
| 1256 def isatty(self): | 1261 def isatty(self): |
| 1257 return True | 1262 return True |
| 1263 | |
| 1264 class PseudoInputFile(object): | |
| 1265 def __init__(self, shell): | |
| 1266 self.readline = shell.readline | |
| 1267 self.isatty = shell.isatty | |
| 1268 | |
| 1269 def write(self, s): | |
| 1270 raise io.UnsupportedOperation("not writable") | |
| 1271 writelines = write | |
| 1258 | 1272 |
| 1259 | 1273 |
| 1260 usage_msg = """\ | 1274 usage_msg = """\ |
| 1261 | 1275 |
| 1262 USAGE: idle [-deins] [-t title] [file]* | 1276 USAGE: idle [-deins] [-t title] [file]* |
