Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
178bd642
Commit
178bd642
authored
May 14, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21075: fileinput.FileInput now reads bytes from standard stream if
binary mode is specified. Patch by Sam Kimbrel.
parent
7a765781
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
2 deletions
+17
-2
Lib/fileinput.py
Lib/fileinput.py
+4
-1
Lib/test/test_fileinput.py
Lib/test/test_fileinput.py
+9
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/fileinput.py
View file @
178bd642
...
...
@@ -320,6 +320,9 @@ class FileInput:
self
.
_backupfilename
=
0
if
self
.
_filename
==
'-'
:
self
.
_filename
=
'<stdin>'
if
'b'
in
self
.
_mode
:
self
.
_file
=
sys
.
stdin
.
buffer
else
:
self
.
_file
=
sys
.
stdin
self
.
_isstdin
=
True
else
:
...
...
Lib/test/test_fileinput.py
View file @
178bd642
...
...
@@ -19,11 +19,12 @@ try:
except
ImportError
:
gzip
=
None
from
io
import
StringIO
from
io
import
BytesIO
,
StringIO
from
fileinput
import
FileInput
,
hook_encoded
from
test.support
import
verbose
,
TESTFN
,
run_unittest
,
check_warnings
from
test.support
import
unlink
as
safe_unlink
from
unittest
import
mock
# The fileinput module has 2 interfaces: the FileInput class which does
...
...
@@ -232,6 +233,13 @@ class FileInputTests(unittest.TestCase):
finally
:
remove_tempfiles
(
t1
)
def
test_stdin_binary_mode
(
self
):
with
mock
.
patch
(
'sys.stdin'
)
as
m_stdin
:
m_stdin
.
buffer
=
BytesIO
(
b'spam, bacon, sausage, and spam'
)
fi
=
FileInput
(
files
=
[
'-'
],
mode
=
'rb'
)
lines
=
list
(
fi
)
self
.
assertEqual
(
lines
,
[
b'spam, bacon, sausage, and spam'
])
def
test_file_opening_hook
(
self
):
try
:
# cannot use openhook and inplace mode
...
...
Misc/ACKS
View file @
178bd642
...
...
@@ -674,6 +674,7 @@ Mads Kiilerich
Jason Killen
Jan Kim
Taek Joo Kim
Sam Kimbrel
W. Trevor King
Paul Kippes
Steve Kirsch
...
...
Misc/NEWS
View file @
178bd642
...
...
@@ -23,6 +23,9 @@ Core and Builtins
Library
-------
- Issue #21075: fileinput.FileInput now reads bytes from standard stream if
binary mode is specified. Patch by Sam Kimbrel.
- Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a
flush() on the underlying binary stream. Patch by akira.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment