cpython: 688d32cdbc0c (original) (raw)
Mercurial > cpython
changeset 99759:688d32cdbc0c
Merge: #22709: Use stdin as-is if it does not have a buffer attribute. [#22709]
R David Murray rdmurray@bitdance.com | |
---|---|
date | Sat, 02 Jan 2016 15:43:44 -0500 |
parents | 3a6b1186745f(current diff)ded1336bff49(diff) |
children | 54b36229021a |
files | Misc/NEWS |
diffstat | 3 files changed, 15 insertions(+), 1 deletions(-)[+] [-] Lib/fileinput.py 2 Lib/test/test_fileinput.py 11 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -328,7 +328,7 @@ class FileInput: if self._filename == '-': self._filename = '' if 'b' in self._mode:
self._file = sys.stdin.buffer[](#l1.7)
self._file = getattr(sys.stdin, 'buffer', sys.stdin)[](#l1.8) else:[](#l1.9) self._file = sys.stdin[](#l1.10) self._isstdin = True[](#l1.11)
--- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -240,6 +240,17 @@ class FileInputTests(unittest.TestCase): lines = list(fi) self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])
- def test_detached_stdin_binary_mode(self):
orig_stdin = sys.stdin[](#l2.8)
try:[](#l2.9)
sys.stdin = BytesIO(b'spam, bacon, sausage, and spam')[](#l2.10)
self.assertFalse(hasattr(sys.stdin, 'buffer'))[](#l2.11)
fi = FileInput(files=['-'], mode='rb')[](#l2.12)
lines = list(fi)[](#l2.13)
self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])[](#l2.14)
finally:[](#l2.15)
sys.stdin = orig_stdin[](#l2.16)
+ def test_file_opening_hook(self): try: # cannot use openhook and inplace mode
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -128,6 +128,9 @@ Core and Builtins Library ------- +- Issue #25447: fileinput now uses sys.stdin as-is if it does not have a