mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
#22709: Use stdin as-is if it does not have a buffer attribute.
This restores backward compatibility lost in the fix for #21075, and is better duck typing. Patch by Akira Li.
This commit is contained in:
parent
fcb6db50d3
commit
830207e8f3
3 changed files with 15 additions and 1 deletions
|
|
@ -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
|
||||
try:
|
||||
sys.stdin = BytesIO(b'spam, bacon, sausage, and spam')
|
||||
self.assertFalse(hasattr(sys.stdin, 'buffer'))
|
||||
fi = FileInput(files=['-'], mode='rb')
|
||||
lines = list(fi)
|
||||
self.assertEqual(lines, [b'spam, bacon, sausage, and spam'])
|
||||
finally:
|
||||
sys.stdin = orig_stdin
|
||||
|
||||
def test_file_opening_hook(self):
|
||||
try:
|
||||
# cannot use openhook and inplace mode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue