[docs] Inconsistency between b32decode() documentation, docstring and code (issue 18011)
storchaka at gmail.com
storchaka at gmail.com
Mon May 20 20:53:23 CEST 2013
Reviewers: stoneleaf,
http://bugs.python.org/review/18011/diff/8191/Lib/base64.py
File Lib/base64.py (right):
http://bugs.python.org/review/18011/diff/8191/Lib/base64.py#newcode225
Lib/base64.py:225: raise binascii.Error('Non-base32 digit found')
On 2013/05/20 13:47:00, stoneleaf wrote:
> Should we add a `from None` here to suppress the double exception
traceback?
Indeed.
Please review this at http://bugs.python.org/review/18011/
Affected files:
Doc/library/base64.rst
Lib/base64.py
Lib/test/test_base64.py
diff -r 1b5ef05d6ced Doc/library/base64.rst
--- a/Doc/library/base64.rst Sun May 19 11:49:32 2013 +0300
+++ b/Doc/library/base64.rst Sun May 19 13:02:47 2013 +0300
@@ -103,7 +103,7 @@
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.
diff -r 1b5ef05d6ced Lib/base64.py
--- a/Lib/base64.py Sun May 19 11:49:32 2013 +0300
+++ b/Lib/base64.py Sun May 19 13:02:47 2013 +0300
@@ -222,7 +222,7 @@
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 -r 1b5ef05d6ced Lib/test/test_base64.py
--- a/Lib/test/test_base64.py Sun May 19 11:49:32 2013 +0300
+++ b/Lib/test/test_base64.py Sun May 19 13:02:47 2013 +0300
@@ -244,8 +244,8 @@
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 @@
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):
More information about the docs
mailing list