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
01759d55
Commit
01759d55
authored
Jan 02, 2016
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Merge: #22709: Use stdin as-is if it does not have a buffer attribute.
parents
5b3455c7
830207e8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
Lib/fileinput.py
Lib/fileinput.py
+1
-1
Lib/test/test_fileinput.py
Lib/test/test_fileinput.py
+11
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/fileinput.py
View file @
01759d55
...
...
@@ -328,7 +328,7 @@ class FileInput:
if
self
.
_filename
==
'-'
:
self
.
_filename
=
'<stdin>'
if
'b'
in
self
.
_mode
:
self
.
_file
=
sys
.
stdin
.
buffer
self
.
_file
=
getattr
(
sys
.
stdin
,
'buffer'
,
sys
.
stdin
)
else
:
self
.
_file
=
sys
.
stdin
self
.
_isstdin
=
True
...
...
Lib/test/test_fileinput.py
View file @
01759d55
...
...
@@ -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
...
...
Misc/NEWS
View file @
01759d55
...
...
@@ -128,6 +128,9 @@ Core and Builtins
Library
-------
- Issue #25447: fileinput now uses sys.stdin as-is if it does not have a
buffer attribute (restores backward compatibility).
- Issue #25971: Optimized creating Fractions from floats by 2 times and from
Decimals by 3 times.
...
...
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