Skip to content

Commit 54f620c

Browse files
miss-islingtonyihong0618picnixzZeroIntensitygpshead
authored
[3.13] gh-138775: fix handle python -m base64 stdin correct with EOF signal (GH-138776) (#141433)
gh-138775: fix handle `python -m base64` stdin correct with EOF signal (GH-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. --------- (cherry picked from commit f5c2a41) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent b28ba31 commit 54f620c

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
@@ -607,7 +607,14 @@ def main():
607607
with open(args[0], 'rb') as f:
608608
func(f, sys.stdout.buffer)
609609
else:
610-
func(sys.stdin.buffer, sys.stdout.buffer)
610+
if sys.stdin.isatty():
611+
# gh-138775: read terminal input data all at once to detect EOF
612+
import io
613+
data = sys.stdin.buffer.read()
614+
buffer = io.BytesIO(data)
615+
else:
616+
buffer = sys.stdin.buffer
617+
func(buffer, sys.stdout.buffer)
611618

612619

613620
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)