Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea2b490

Browse files
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.
1 parent fef952a commit ea2b490

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

Doc/library/base64.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The modern interface provides:
103103
digit 0 is always mapped to the letter O). For security purposes the default is
104104
``None``, so that 0 and 1 are not allowed in the input.
105105

106-
The decoded byte string is returned. A :exc:`TypeError` is raised if *s* were
106+
The decoded byte string is returned. A :exc:`binascii.Error` is raised if *s* were
107107
incorrectly padded or if there are non-alphabet characters present in the
108108
string.
109109

Lib/base64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def b32decode(s, casefold=False, map01=None):
245245
for c in s:
246246
val = _b32rev.get(c)
247247
if val is None:
248-
raise TypeError('Non-base32 digit found')
248+
raise binascii.Error('Non-base32 digit found')
249249
acc += _b32rev[c] << shift
250250
shift -= 5
251251
if shift < 0:

Lib/test/test_base64.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def test_b32decode_casefold(self):
244244
eq(base64.b32decode(data, True), res)
245245
eq(base64.b32decode(data.decode('ascii'), True), res)
246246

247-
self.assertRaises(TypeError, base64.b32decode, b'me======')
248-
self.assertRaises(TypeError, base64.b32decode, 'me======')
247+
self.assertRaises(binascii.Error, base64.b32decode, b'me======')
248+
self.assertRaises(binascii.Error, base64.b32decode, 'me======')
249249

250250
# Mapping zero and one
251251
eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe')
@@ -262,9 +262,11 @@ def test_b32decode_casefold(self):
262262
eq(base64.b32decode(data_str, map01=map01), res)
263263
eq(base64.b32decode(data, map01=map01_str), res)
264264
eq(base64.b32decode(data_str, map01=map01_str), res)
265+
self.assertRaises(binascii.Error, base64.b32decode, data)
266+
self.assertRaises(binascii.Error, base64.b32decode, data_str)
265267

266268
def test_b32decode_error(self):
267-
for data in [b'abc', b'ABCDEF==']:
269+
for data in [b'abc', b'ABCDEF==', b'==ABCDEF']:
268270
with self.assertRaises(binascii.Error):
269271
base64.b32decode(data)
270272
with self.assertRaises(binascii.Error):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #18011: base64.b32decode() now raises a binascii.Error if there are
28+
non-alphabet characters present in the input string to conform a docstring.
29+
Updated the module documentation.
30+
2731
- Issue #13772: Restored directory detection of targets in ``os.symlink`` on
2832
Windows, which was temporarily removed in Python 3.2.3 due to an incomplete
2933
implementation. The implementation now works even if the symlink is created

0 commit comments

Comments
 (0)