Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r60362:f413409ca215
Date: 2013-01-22 19:22 -0800
http://bitbucket.org/pypy/pypy/changeset/f413409ca215/
Log: input must eat potential exceptions from fileno()
diff --git a/pypy/module/__builtin__/app_io.py
b/pypy/module/__builtin__/app_io.py
--- a/pypy/module/__builtin__/app_io.py
+++ b/pypy/module/__builtin__/app_io.py
@@ -14,6 +14,13 @@
else:
flush()
+def _is_std_tty(stdin, stdout):
+ try:
+ infileno, outfileno = stdin.fileno(), stdout.fileno()
+ except:
+ return False
+ return infileno == 0 and stdin.isatty() and outfileno == 1
+
def input(prompt=''):
"""input([prompt]) -> string
@@ -37,9 +44,7 @@
stderr.flush()
# hook for the readline module
- if (hasattr(sys, '__raw_input__') and
- stdin.fileno() == 0 and stdin.isatty() and
- stdout.fileno() == 1):
+ if hasattr(sys, '__raw_input__') and _is_std_tty(stdin, stdout):
_write_prompt(stdout, '')
return sys.__raw_input__(str(prompt))
diff --git a/pypy/module/__builtin__/test/test_rawinput.py
b/pypy/module/__builtin__/test/test_rawinput.py
--- a/pypy/module/__builtin__/test/test_rawinput.py
+++ b/pypy/module/__builtin__/test/test_rawinput.py
@@ -39,6 +39,19 @@
assert flushed[0]
assert got == gottext
+ def test_bad_fileno(self):
+ import io
+ import sys
+ class BadFileno(io.StringIO):
+ def fileno(self):
+ 1 / 0
+ stdin, sys.stdin = sys.stdin, BadFileno('foo')
+ try:
+ result = input()
+ finally:
+ sys.stdin = stdin
+ assert result == 'foo'
+
def test_softspace(self):
import sys
import io
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit