diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-05-28 12:30:38 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-05-28 12:30:38 (GMT) |
commit | 77a3ad743f604c11c23ec6c0100360675b5676f8 (patch) | |
tree | 3fbf73cc3974ee35ab3d431dc4c63eab156f02ab /Lib | |
parent | 3801f632dcbf5f4f2d0bfe9d5f55cf53da8df5db (diff) | |
parent | ea2b490f3dad99cfd677be9fd0c730622a723f38 (diff) | |
download | cpython-77a3ad743f604c11c23ec6c0100360675b5676f8.zip cpython-77a3ad743f604c11c23ec6c0100360675b5676f8.tar.gz cpython-77a3ad743f604c11c23ec6c0100360675b5676f8.tar.bz2 |
Issue #18011: base64.b32decode() now raises a binascii.Error if there are
non-alphabet characters present in the input string to conform a docstring.
Updated the module documentation.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/base64.py | 2 | ||||
-rw-r--r-- | Lib/test/test_base64.py | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/Lib/base64.py b/Lib/base64.py index 0f731fa..f923244 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -222,7 +222,7 @@ def b32decode(s, casefold=False, map01=None): for c in quanta: acc = (acc << 5) + b32rev[c] except KeyError: - raise TypeError('Non-base32 digit found') + raise binascii.Error('Non-base32 digit found') decoded += acc.to_bytes(5, 'big') # Process the last, partial quanta if padchars: diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index abba5bf..13695de 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -244,8 +244,8 @@ class BaseXYTestCase(unittest.TestCase): eq(base64.b32decode(data, True), res) eq(base64.b32decode(data.decode('ascii'), True), res) - self.assertRaises(TypeError, base64.b32decode, b'me======') - self.assertRaises(TypeError, base64.b32decode, 'me======') + self.assertRaises(binascii.Error, base64.b32decode, b'me======') + self.assertRaises(binascii.Error, base64.b32decode, 'me======') # Mapping zero and one eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe') @@ -262,9 +262,11 @@ class BaseXYTestCase(unittest.TestCase): eq(base64.b32decode(data_str, map01=map01), res) eq(base64.b32decode(data, map01=map01_str), res) eq(base64.b32decode(data_str, map01=map01_str), res) + self.assertRaises(binascii.Error, base64.b32decode, data) + self.assertRaises(binascii.Error, base64.b32decode, data_str) def test_b32decode_error(self): - for data in [b'abc', b'ABCDEF==']: + for data in [b'abc', b'ABCDEF==', b'==ABCDEF']: with self.assertRaises(binascii.Error): base64.b32decode(data) with self.assertRaises(binascii.Error): |