[pypy-commit] pypy py3.3: pep8/use oefmt

pjenvey noreply at buildbot.pypy.org
Sun Jul 27 20:40:06 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.3
Changeset: r72575:6704fc912ee1
Date: 2014-07-27 11:35 -0700
http://bitbucket.org/pypy/pypy/changeset/6704fc912ee1/

Log:	pep8/use oefmt

diff --git a/pypy/module/operator/test/test_tscmp.py b/pypy/module/operator/test/test_tscmp.py
--- a/pypy/module/operator/test/test_tscmp.py
+++ b/pypy/module/operator/test/test_tscmp.py
@@ -1,5 +1,4 @@
 from pypy.module.operator.tscmp import pypy_tscmp
-from rpython.rtyper.lltypesystem.rffi import scoped_nonmovingbuffer
 
 class TestTimingSafeCompare:
     def test_tscmp_neq(self):
diff --git a/pypy/module/operator/tscmp.py b/pypy/module/operator/tscmp.py
--- a/pypy/module/operator/tscmp.py
+++ b/pypy/module/operator/tscmp.py
@@ -3,9 +3,11 @@
 attacks for the hmac module.
 """
 import py
+
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.interpreter.error import OperationError
+
+from pypy.interpreter.error import OperationError, oefmt
 
 cwd = py.path.local(__file__).dirpath()
 eci = ExternalCompilationInfo(
@@ -13,15 +15,21 @@
     separate_module_files=[cwd.join('tscmp.c')],
     export_symbols=['pypy_tscmp'])
 
+
 def llexternal(*args, **kwargs):
     kwargs.setdefault('compilation_info', eci)
     kwargs.setdefault('sandboxsafe', True)
     return rffi.llexternal(*args, **kwargs)
 
-pypy_tscmp = llexternal('pypy_tscmp', [rffi.CCHARP, rffi.CCHARP, rffi.LONG, rffi.LONG], rffi.INT)
+
+pypy_tscmp = llexternal('pypy_tscmp',
+                        [rffi.CCHARP, rffi.CCHARP, rffi.LONG, rffi.LONG],
+                        rffi.INT)
+
 
 def compare_digest(space, w_a, w_b):
-    if space.isinstance_w(w_a, space.w_unicode) and space.isinstance_w(w_b, space.w_unicode):
+    if (space.isinstance_w(w_a, space.w_unicode) and
+        space.isinstance_w(w_b, space.w_unicode)):
         try:
             a_value = space.call_method(w_a, "encode", space.wrap("ascii"))
             b_value = space.call_method(w_b, "encode", space.wrap("ascii"))
@@ -29,14 +37,17 @@
         except OperationError as e:
             if not e.match(space, space.w_UnicodeEncodeError):
                 raise
-            raise OperationError(space.w_TypeError,
-                    space.wrap("comparing strings with non-ASCII characters is not supported"))
+            raise oefmt(space.w_TypeError,
+                        "comparing strings with non-ASCII characters is not "
+                        "supported")
     else:
         return compare_digest_buffer(space, w_a, w_b)
 
+
 def compare_digest_buffer(space, w_a, w_b):
     a = space.bufferstr_w(w_a)
     b = space.bufferstr_w(w_b)
     with rffi.scoped_nonmovingbuffer(a) as a_buffer:
         with rffi.scoped_nonmovingbuffer(b) as b_buffer:
-            return space.wrap(rffi.cast(lltype.Bool, pypy_tscmp(a_buffer, b_buffer, len(a), len(b))))
+            result = pypy_tscmp(a_buffer, b_buffer, len(a), len(b))
+            return space.wrap(rffi.cast(lltype.Bool, result))


More information about the pypy-commit mailing list