[Python-checkins] cpython (merge 3.3 -> default): Issue #18011: base64.b32decode() now raises a binascii.Error if there are

serhiy.storchaka python-checkins at python.org
Tue May 28 14:35:32 CEST 2013


http://hg.python.org/cpython/rev/7446f53ba2d2
changeset:   83950:7446f53ba2d2
parent:      83948:09b88b5bebd0
parent:      83949:0b9bcb2ac145
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue May 28 15:30:38 2013 +0300
summary:
  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.

files:
  Doc/library/base64.rst  |  2 +-
  Lib/base64.py           |  2 +-
  Lib/test/test_base64.py |  8 +++++---
  Misc/NEWS               |  4 ++++
  4 files changed, 11 insertions(+), 5 deletions(-)


diff --git a/Doc/library/base64.rst b/Doc/library/base64.rst
--- a/Doc/library/base64.rst
+++ b/Doc/library/base64.rst
@@ -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 --git a/Lib/base64.py b/Lib/base64.py
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -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 --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,10 @@
 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
   importlib.abc.ExecutionLoader.get_code().
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list