mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Close #17839: support bytes-like objects in base64 module
This mostly affected the encodebytes and decodebytes function (which are used by base64_codec) Also added a test to ensure all bytes-bytes codecs can handle memoryview input and tests for handling of multidimensional and non-bytes format input in the modern base64 API.
This commit is contained in:
parent
73c6ee0080
commit
fdf239a855
6 changed files with 171 additions and 68 deletions
|
@ -2285,6 +2285,24 @@ class TransformCodecTest(unittest.TestCase):
|
|||
sout = reader.readline()
|
||||
self.assertEqual(sout, b"\x80")
|
||||
|
||||
def test_buffer_api_usage(self):
|
||||
# We check all the transform codecs accept memoryview input
|
||||
# for encoding and decoding
|
||||
# and also that they roundtrip correctly
|
||||
original = b"12345\x80"
|
||||
for encoding in bytes_transform_encodings:
|
||||
data = original
|
||||
view = memoryview(data)
|
||||
data = codecs.encode(data, encoding)
|
||||
view_encoded = codecs.encode(view, encoding)
|
||||
self.assertEqual(view_encoded, data)
|
||||
view = memoryview(data)
|
||||
data = codecs.decode(data, encoding)
|
||||
self.assertEqual(data, original)
|
||||
view_decoded = codecs.decode(view, encoding)
|
||||
self.assertEqual(view_decoded, data)
|
||||
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'win32',
|
||||
'code pages are specific to Windows')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue