[Python-checkins] r81534 - in python/branches/release31-maint: Lib/base64.py Lib/test/test_base64.py Misc/NEWS
victor.stinner
python-checkins at python.org
Tue May 25 23:32:42 CEST 2010
Author: victor.stinner
Date: Tue May 25 23:32:42 2010
New Revision: 81534
Log:
Merged revisions 81533 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r81533 | victor.stinner | 2010-05-25 23:12:34 +0200 (mar., 25 mai 2010) | 3 lines
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
sys.stdout.buffer (instead of sys.stdin and sys.stdout) to use the bytes API
........
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Lib/base64.py
python/branches/release31-maint/Lib/test/test_base64.py
python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/base64.py
==============================================================================
--- python/branches/release31-maint/Lib/base64.py (original)
+++ python/branches/release31-maint/Lib/base64.py Tue May 25 23:32:42 2010
@@ -383,9 +383,9 @@
if o == '-u': func = decode
if o == '-t': test(); return
if args and args[0] != '-':
- func(open(args[0], 'rb'), sys.stdout)
+ func(open(args[0], 'rb'), sys.stdout.buffer)
else:
- func(sys.stdin, sys.stdout)
+ func(sys.stdin.buffer, sys.stdout.buffer)
def test():
Modified: python/branches/release31-maint/Lib/test/test_base64.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_base64.py (original)
+++ python/branches/release31-maint/Lib/test/test_base64.py Tue May 25 23:32:42 2010
@@ -2,6 +2,8 @@
from test import support
import base64
import binascii
+import sys
+import subprocess
@@ -208,6 +210,38 @@
+class TestMain(unittest.TestCase):
+ def get_output(self, *args, **options):
+ args = (sys.executable, '-m', 'base64') + args
+ return subprocess.check_output(args, **options)
+
+ def test_encode_decode(self):
+ output = self.get_output('-t')
+ self.assertSequenceEqual(output.splitlines(), (
+ b"b'Aladdin:open sesame'",
+ br"b'QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n'",
+ b"b'Aladdin:open sesame'",
+ ))
+
+ def test_encode_file(self):
+ with open(support.TESTFN, 'wb') as fp:
+ fp.write(b'a\xffb\n')
+
+ output = self.get_output('-e', support.TESTFN)
+ self.assertEquals(output.rstrip(), b'Yf9iCg==')
+
+ with open(support.TESTFN, 'rb') as fp:
+ output = self.get_output('-e', stdin=fp)
+ self.assertEquals(output.rstrip(), b'Yf9iCg==')
+
+ def test_decode(self):
+ with open(support.TESTFN, 'wb') as fp:
+ fp.write(b'Yf9iCg==')
+ output = self.get_output('-d', support.TESTFN)
+ self.assertEquals(output, b'a\xffb\n')
+
+
+
def test_main():
support.run_unittest(__name__)
Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS (original)
+++ python/branches/release31-maint/Misc/NEWS Tue May 25 23:32:42 2010
@@ -54,6 +54,10 @@
Library
-------
+- Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer
+ and sys.stdout.buffer (instead of sys.stdin and sys.stdout) to use the bytes
+ API
+
- Issue #6662: Fix parsing of malformatted charref (&#bad;), patch written by
Fredrik Håård
More information about the Python-checkins
mailing list