]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18011: base64.b32decode() now raises a binascii.Error if there are
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 28 May 2013 12:27:29 +0000 (15:27 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 28 May 2013 12:27:29 +0000 (15:27 +0300)
non-alphabet characters present in the input string to conform a docstring.
Updated the module documentation.

Doc/library/base64.rst
Lib/base64.py
Lib/test/test_base64.py
Misc/NEWS

index ade0f07ca7a7929a0be6fe1934a259e4c8f6253d..3b23e795d4269f6a06c88c42d832c5247f1f891a 100644 (file)
@@ -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.
 
index 6bcdff63d4a5bed6bec8835bf35ce33d68b4ec6c..b6e82b69bdd49e8f2739f06338f042264efe4880 100755 (executable)
@@ -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:
index abba5bf775dc0d8bf1169a3de8e121dc257d71b4..13695de67e652f576d889f205ef664189b73d45b 100644 (file)
@@ -244,8 +244,8 @@ class BaseXYTestCase(unittest.TestCase):
             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 @@ class BaseXYTestCase(unittest.TestCase):
             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):
index 3090d9f0fc1a5fa7d1308419d5f90e16d53ba371..41bc85645a5ba0627543f5e7a7c55c1b7f876622 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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