[pypy-svn] r61080 - in pypy/trunk/pypy/lib: . app_test

fijal at codespeak.net fijal at codespeak.net
Sun Jan 18 16:40:41 CET 2009


Author: fijal
Date: Sun Jan 18 16:40:40 2009
New Revision: 61080

Modified:
   pypy/trunk/pypy/lib/app_test/test_binascii.py
   pypy/trunk/pypy/lib/binascii.py
Log:
An attempt to catch correctly wrong types, not sure how feasible it is...


Modified: pypy/trunk/pypy/lib/app_test/test_binascii.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/test_binascii.py	(original)
+++ pypy/trunk/pypy/lib/app_test/test_binascii.py	Sun Jan 18 16:40:40 2009
@@ -160,3 +160,7 @@
 def test_crap_after_padding():
     s = 'xxx=axxxx'
     assert binascii.a2b_base64(s) == '\xc7\x1c'
+
+def test_wrong_args():
+    # this should grow as a way longer list
+    raises(TypeError, binascii.a2b_base64, 42)

Modified: pypy/trunk/pypy/lib/binascii.py
==============================================================================
--- pypy/trunk/pypy/lib/binascii.py	(original)
+++ pypy/trunk/pypy/lib/binascii.py	Sun Jan 18 16:40:40 2009
@@ -135,6 +135,8 @@
 
 
 def a2b_base64(s):
+    if not isinstance(s, (str, unicode)):
+        raise TypeError("expected string or unicode, got %r" % (s,))
     s = s.rstrip()
     # clean out all invalid characters, this also strips the final '=' padding
     # check for correct padding



More information about the Pypy-commit mailing list