Skip to content

Commit 9ecdcb0

Browse files
yihong0618picnixzZeroIntensitygpshead
authored andcommitted
pythongh-138775: fix handle python -m base64 stdin correct with EOF signal (pythonGH-138776)
* fix: handle stdin correct with EOF single. * fix: flollow the comments when pipe stdin use buffer * Apply suggestions from code review * fix: apply review comments in Lib/base64.py * fix: address comments * Reword comment and NEWS entry. --------- Signed-off-by: yihong0618 <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Gregory P. Smith <[email protected]>
1 parent 0fb325c commit 9ecdcb0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/base64.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,14 @@ def main():
604604
with open(args[0], 'rb') as f:
605605
func(f, sys.stdout.buffer)
606606
else:
607-
func(sys.stdin.buffer, sys.stdout.buffer)
607+
if sys.stdin.isatty():
608+
# gh-138775: read terminal input data all at once to detect EOF
609+
import io
610+
data = sys.stdin.buffer.read()
611+
buffer = io.BytesIO(data)
612+
else:
613+
buffer = sys.stdin.buffer
614+
func(buffer, sys.stdout.buffer)
608615

609616

610617
if __name__ == '__main__':
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use of ``python -m`` with :mod:`base64` has been fixed to detect input from a
2+
terminal so that it properly notices EOF.

0 commit comments

Comments
 (0)