[pypy-commit] pypy py3k: use binascii.Error

pjenvey noreply at buildbot.pypy.org
Tue Dec 11 21:04:52 CET 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r59406:03ef6fdf2d94
Date: 2012-12-11 12:01 -0800
http://bitbucket.org/pypy/pypy/changeset/03ef6fdf2d94/

Log:	use binascii.Error

diff --git a/pypy/module/binascii/interp_hexlify.py b/pypy/module/binascii/interp_hexlify.py
--- a/pypy/module/binascii/interp_hexlify.py
+++ b/pypy/module/binascii/interp_hexlify.py
@@ -2,6 +2,7 @@
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 from pypy.rlib.rarithmetic import ovfcheck
+from pypy.module.binascii.interp_binascii import raise_Error
 
 # ____________________________________________________________
 
@@ -38,8 +39,7 @@
     elif c <= 'f':
         if c >= 'a':
             return ord(c) - (ord('a')-10)
-    raise OperationError(space.w_TypeError,
-                         space.wrap('Non-hexadecimal digit found'))
+    raise_Error(space, 'Non-hexadecimal digit found')
 _char2value._always_inline_ = True
 
 @unwrap_spec(hexstr='bufferstr')
@@ -48,8 +48,7 @@
 hexstr must contain an even number of hex digits (upper or lower case).
 This function is also available as "unhexlify()".'''
     if len(hexstr) & 1:
-        raise OperationError(space.w_TypeError,
-                             space.wrap('Odd-length string'))
+        raise_Error(space, 'Odd-length string')
     res = StringBuilder(len(hexstr) >> 1)
     for i in range(0, len(hexstr), 2):
         a = _char2value(space, hexstr[i])
diff --git a/pypy/module/binascii/test/test_binascii.py b/pypy/module/binascii/test/test_binascii.py
--- a/pypy/module/binascii/test/test_binascii.py
+++ b/pypy/module/binascii/test/test_binascii.py
@@ -411,5 +411,8 @@
             assert self.binascii.unhexlify(input) == expected
             assert self.binascii.a2b_hex(input) == expected
 
-    def test_error(self):
-        assert issubclass(self.binascii.Error, ValueError)
+    def test_errors(self):
+        binascii = self.binascii
+        assert issubclass(binascii.Error, ValueError)
+        raises(binascii.Error, binascii.a2b_hex, b'u')
+        raises(binascii.Error, binascii.a2b_hex, b'bo')


More information about the pypy-commit mailing list