https://github.com/python/cpython/commit/54f620cc7fb8aa75e5526589322a6580c6446a22
commit: 54f620cc7fb8aa75e5526589322a6580c6446a22
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: gpshead <[email protected]>
date: 2025-11-12T00:10:07Z
summary:

[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 f5c2a41f9a6b3be95c5be9dbae0a4a3342d356dc)

Signed-off-by: yihong0618 <[email protected]>
Co-authored-by: yihong <[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]>

files:
A Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst
M Lib/base64.py

diff --git a/Lib/base64.py b/Lib/base64.py
index e8bc252ecfa638..6636e06382f4de 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -607,7 +607,14 @@ def main():
         with open(args[0], 'rb') as f:
             func(f, sys.stdout.buffer)
     else:
-        func(sys.stdin.buffer, sys.stdout.buffer)
+        if sys.stdin.isatty():
+            # gh-138775: read terminal input data all at once to detect EOF
+            import io
+            data = sys.stdin.buffer.read()
+            buffer = io.BytesIO(data)
+        else:
+            buffer = sys.stdin.buffer
+        func(buffer, sys.stdout.buffer)
 
 
 if __name__ == '__main__':
diff --git 
a/Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst 
b/Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst
new file mode 100644
index 00000000000000..455c1a9925a5e1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst
@@ -0,0 +1,2 @@
+Use of ``python -m`` with :mod:`base64` has been fixed to detect input from a
+terminal so that it properly notices EOF.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to