Skip to content

Commit

Permalink
Issue python#18011: base64.b32decode() now raises a binascii.Error if…
Browse files Browse the repository at this point in the history
… there are

non-alphabet characters present in the input string to conform a docstring.
Updated the module documentation.
  • Loading branch information
serhiy-storchaka committed May 28, 2013
1 parent fef952a commit ea2b490
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Doc/library/base64.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The modern interface provides:
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.

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
string.

Expand Down
2 changes: 1 addition & 1 deletion Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def b32decode(s, casefold=False, map01=None):
for c in s:
val = _b32rev.get(c)
if val is None:
raise TypeError('Non-base32 digit found')
raise binascii.Error('Non-base32 digit found')
acc += _b32rev[c] << shift
shift -= 5
if shift < 0:
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def test_b32decode_casefold(self):
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')
Expand All @@ -262,9 +262,11 @@ def test_b32decode_casefold(self):
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):
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Core and Builtins
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 #13772: Restored directory detection of targets in ``os.symlink`` on
Windows, which was temporarily removed in Python 3.2.3 due to an incomplete
implementation. The implementation now works even if the symlink is created
Expand Down

0 comments on commit ea2b490

Please sign in to comment.