mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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.
This commit is contained in:
commit
77a3ad743f
4 changed files with 11 additions and 5 deletions
|
@ -103,7 +103,7 @@ The modern interface provides:
|
||||||
digit 0 is always mapped to the letter O). For security purposes the default is
|
digit 0 is always mapped to the letter O). For security purposes the default is
|
||||||
``None``, so that 0 and 1 are not allowed in the input.
|
``None``, so that 0 and 1 are not allowed in the input.
|
||||||
|
|
||||||
The decoded byte string is returned. A :exc:`TypeError` is raised if *s* were
|
The decoded byte string is returned. A :exc:`binascii.Error` is raised if *s* were
|
||||||
incorrectly padded or if there are non-alphabet characters present in the
|
incorrectly padded or if there are non-alphabet characters present in the
|
||||||
string.
|
string.
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ def b32decode(s, casefold=False, map01=None):
|
||||||
for c in quanta:
|
for c in quanta:
|
||||||
acc = (acc << 5) + b32rev[c]
|
acc = (acc << 5) + b32rev[c]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise TypeError('Non-base32 digit found')
|
raise binascii.Error('Non-base32 digit found')
|
||||||
decoded += acc.to_bytes(5, 'big')
|
decoded += acc.to_bytes(5, 'big')
|
||||||
# Process the last, partial quanta
|
# Process the last, partial quanta
|
||||||
if padchars:
|
if padchars:
|
||||||
|
|
|
@ -244,8 +244,8 @@ class BaseXYTestCase(unittest.TestCase):
|
||||||
eq(base64.b32decode(data, True), res)
|
eq(base64.b32decode(data, True), res)
|
||||||
eq(base64.b32decode(data.decode('ascii'), True), res)
|
eq(base64.b32decode(data.decode('ascii'), True), res)
|
||||||
|
|
||||||
self.assertRaises(TypeError, base64.b32decode, b'me======')
|
self.assertRaises(binascii.Error, base64.b32decode, b'me======')
|
||||||
self.assertRaises(TypeError, base64.b32decode, 'me======')
|
self.assertRaises(binascii.Error, base64.b32decode, 'me======')
|
||||||
|
|
||||||
# Mapping zero and one
|
# Mapping zero and one
|
||||||
eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe')
|
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_str, map01=map01), res)
|
||||||
eq(base64.b32decode(data, map01=map01_str), res)
|
eq(base64.b32decode(data, map01=map01_str), res)
|
||||||
eq(base64.b32decode(data_str, 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):
|
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):
|
with self.assertRaises(binascii.Error):
|
||||||
base64.b32decode(data)
|
base64.b32decode(data)
|
||||||
with self.assertRaises(binascii.Error):
|
with self.assertRaises(binascii.Error):
|
||||||
|
|
|
@ -103,6 +103,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
|
||||||
- Issue #18072: Implement importlib.abc.InspectLoader.get_code() and
|
- Issue #18072: Implement importlib.abc.InspectLoader.get_code() and
|
||||||
importlib.abc.ExecutionLoader.get_code().
|
importlib.abc.ExecutionLoader.get_code().
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue