[tor-commits] [bridgedb/master] Raise ValueError rather than logging in parse.padBase64().

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:34 UTC 2014


commit e2ff03d8680c5298ee86f845f5f3ff3eb74bf87c
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Dec 11 10:37:48 2013 +0000

    Raise ValueError rather than logging in parse.padBase64().
---
 lib/bridgedb/parse/__init__.py |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/bridgedb/parse/__init__.py b/lib/bridgedb/parse/__init__.py
index 1fdbd8a..21cfe30 100644
--- a/lib/bridgedb/parse/__init__.py
+++ b/lib/bridgedb/parse/__init__.py
@@ -32,17 +32,20 @@ def padBase64(b64string):
 
     :param string b64string: A base64-encoded string which might have had its
         trailing equals sign padding removed.
+    :raises: :exc:`ValueError` if there was any error while manipulating the
+        string.
+    :returns: A properly-padded (according to base64) string.
     """
+    addchars  = 0
     try:
         b64string = b64string.strip()
-    except AttributeError:
-        logging.error("Cannot pad base64 string %r: not a string." % b64string)
-    else:
-        addchars  = 0
         remainder = len(b64string) % 4
         if 2 <= remainder <= 3:
             addchars = 4 - remainder
-        else:
+    except AttributeError as error:
+        raise ValueError(error)
+    else:
+        if not addchars:
             raise ValueError("Invalid base64-encoded string: %r" % b64string)
         b64string += '=' * addchars
     finally:





More information about the tor-commits mailing list