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

Skip to content

Commit 77a3ad7

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.
2 parents 3801f63 + ea2b490 commit 77a3ad7

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
@@ -222,7 +222,7 @@ def b32decode(s, casefold=False, map01=None):
222222
for c in quanta:
223223
acc = (acc << 5) + b32rev[c]
224224
except KeyError:
225-
raise TypeError('Non-base32 digit found')
225+
raise binascii.Error('Non-base32 digit found')
226226
decoded += acc.to_bytes(5, 'big')
227227
# Process the last, partial quanta
228228
if padchars:

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
@@ -103,6 +103,10 @@ Core and Builtins
103103
Library
104104
-------
105105

106+
- Issue #18011: base64.b32decode() now raises a binascii.Error if there are
107+
non-alphabet characters present in the input string to conform a docstring.
108+
Updated the module documentation.
109+
106110
- Issue #18072: Implement importlib.abc.InspectLoader.get_code() and
107111
importlib.abc.ExecutionLoader.get_code().
108112

0 commit comments

Comments
 (0)