Commits

Alex Gaynor committed e921c3c

some pep8 and dead import cleanups to _cffi_backend

Comments (0)

Files changed (14)

pypy/module/_cffi_backend/cbuffer.py

-from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.buffer import RWBuffer
+from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.gateway import unwrap_spec, interp2app
 from pypy.interpreter.typedef import TypeDef, make_weakref_descr
+from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
+
 from rpython.rtyper.lltypesystem import rffi
-from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
 
 
 class LLBuffer(RWBuffer):

pypy/module/_cffi_backend/ccallback.py

 Callbacks.
 """
 import os
+
+from rpython.rlib import clibffi, rweakref, jit
+from rpython.rlib.objectmodel import compute_unique_id, keepalive_until_here
+from rpython.rtyper.lltypesystem import lltype, rffi
+
 from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib.objectmodel import compute_unique_id, keepalive_until_here
-from rpython.rlib import clibffi, rweakref
-from rpython.rlib import jit
-
+from pypy.module._cffi_backend import cerrno, misc
 from pypy.module._cffi_backend.cdataobj import W_CData
-from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN
-from pypy.module._cffi_backend.ctypefunc import W_CTypeFunc
+from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN, W_CTypeFunc
 from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
 from pypy.module._cffi_backend.ctypevoid import W_CTypeVoid
-from pypy.module._cffi_backend import cerrno, misc
 
 # ____________________________________________________________
 
 
 STDERR = 2
 
+
 @jit.jit_callback("CFFI")
 def invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata):
     """ Callback specification.

pypy/module/_cffi_backend/cdataobj.py

 import operator
+
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef, make_weakref_descr
+
+from rpython.rlib import objectmodel, rgc
+from rpython.rlib.objectmodel import keepalive_until_here, specialize
 from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.objectmodel import keepalive_until_here, specialize
-from rpython.rlib import objectmodel, rgc
 from rpython.tool.sourcetools import func_with_new_name
 
 from pypy.module._cffi_backend import misc

pypy/module/_cffi_backend/cerrno.py

 import sys
+
 from rpython.rlib import rposix
+
 from pypy.interpreter.executioncontext import ExecutionContext
 from pypy.interpreter.gateway import unwrap_spec
 

pypy/module/_cffi_backend/ctypearray.py

 Arrays.
 """
 
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef
+
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import ovfcheck
 
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveChar
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUniChar
+from pypy.module._cffi_backend import cdataobj
 from pypy.module._cffi_backend.ctypeptr import W_CTypePtrOrArray
-from pypy.module._cffi_backend import cdataobj
 
 
 class W_CTypeArray(W_CTypePtrOrArray):

pypy/module/_cffi_backend/ctypeenum.py

 Enums.
 """
 
-from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.rarithmetic import intmask, r_ulonglong
 from rpython.rlib.objectmodel import keepalive_until_here
-from rpython.rlib.objectmodel import specialize
 
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUnsigned
 from pypy.module._cffi_backend import misc
+from pypy.module._cffi_backend.ctypeprim import (W_CTypePrimitiveSigned,
+    W_CTypePrimitiveUnsigned)
 
 
 class _Mixin_Enum(object):

pypy/module/_cffi_backend/ctypefunc.py

 
 import sys
 from pypy.interpreter.error import OperationError, operationerrfmt
+
+from rpython.rlib import jit, clibffi, jit_libffi
+from rpython.rlib.jit_libffi import (CIF_DESCRIPTION, CIF_DESCRIPTION_P,
+    FFI_TYPE, FFI_TYPE_P, FFI_TYPE_PP, SIZE_OF_FFI_ARG)
+from rpython.rlib.objectmodel import we_are_translated, instantiate
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rlib import jit, clibffi, jit_libffi
-from rpython.rlib.jit_libffi import CIF_DESCRIPTION, CIF_DESCRIPTION_P
-from rpython.rlib.jit_libffi import FFI_TYPE, FFI_TYPE_P, FFI_TYPE_PP
-from rpython.rlib.jit_libffi import SIZE_OF_FFI_ARG
-from rpython.rlib.objectmodel import we_are_translated, instantiate
-from rpython.rlib.objectmodel import keepalive_until_here
 
+from pypy.module._cffi_backend import ctypearray, cdataobj, cerrno
 from pypy.module._cffi_backend.ctypeobj import W_CType
 from pypy.module._cffi_backend.ctypeptr import W_CTypePtrBase, W_CTypePointer
 from pypy.module._cffi_backend.ctypevoid import W_CTypeVoid
 from pypy.module._cffi_backend.ctypestruct import W_CTypeStruct
-from pypy.module._cffi_backend.ctypestruct import W_CTypeStructOrUnion
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveUnsigned
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveCharOrUniChar
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveFloat
-from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveLongDouble
-from pypy.module._cffi_backend import ctypearray, cdataobj, cerrno
+from pypy.module._cffi_backend.ctypeprim import (W_CTypePrimitiveSigned,
+    W_CTypePrimitiveUnsigned, W_CTypePrimitiveCharOrUniChar,
+    W_CTypePrimitiveFloat, W_CTypePrimitiveLongDouble)
 
 
 class W_CTypeFunc(W_CTypePtrBase):
             return self.space.wrap(clibffi.FFI_DEFAULT_ABI)     # XXX
         return W_CTypePtrBase._fget(self, attrchar)
 
-
     def call(self, funcaddr, args_w):
         if self.cif_descr:
             # regular case: this function does not take '...' arguments
             self.bufferp = rffi.ptradd(result, size)
             return result
 
-
     def fb_fill_type(self, ctype, is_result_type):
         return ctype._get_ffi_type(self, is_result_type)
 
 
         return ffistruct
 
-
     def fb_build(self):
         # Build a CIF_DESCRIPTION.  Actually this computes the size and
         # allocates a larger amount of data.  It starts with a
             if self.atypes:
                 self.atypes[i] = atype
 
-
     def align_arg(self, n):
         return (n + 7) & ~7
 

pypy/module/_cffi_backend/ctypeobj.py

+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.typedef import make_weakref_descr
-from pypy.interpreter.typedef import GetSetProperty, interp_attrproperty
+from pypy.interpreter.typedef import TypeDef, make_weakref_descr, GetSetProperty
+
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rlib.objectmodel import we_are_translated
 

pypy/module/_cffi_backend/ctypeprim.py

 """
 
 from pypy.interpreter.error import operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, rffi
+
 from rpython.rlib.rarithmetic import r_uint, r_ulonglong, intmask
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import lltype, rffi
 
+from pypy.module._cffi_backend import cdataobj, misc
 from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, misc
 
 
 class W_CTypePrimitive(W_CType):

pypy/module/_cffi_backend/ctypeptr.py

 Pointers.
 """
 
-from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import wrap_oserror
-from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.interpreter.error import OperationError, operationerrfmt, wrap_oserror
+
+from rpython.rlib import rposix
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import ovfcheck
-from rpython.rlib import rposix
+from rpython.rtyper.lltypesystem import lltype, rffi
 
+from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
 from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
 
 
 class W_CTypePtrOrArray(W_CType):
 
 
 rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP)
-rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP,rffi.CCHARP], lltype.Void)
+rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP, rffi.CCHARP], lltype.Void)
 rffi_fclose = rffi.llexternal("fclose", [rffi.CCHARP], rffi.INT)
 
 class CffiFileObj(object):
     _immutable_ = True
+
     def __init__(self, fd, mode):
         self.llf = rffi_fdopen(fd, mode)
         if not self.llf:
             raise OSError(rposix.get_errno(), "fdopen failed")
         rffi_setbuf(self.llf, lltype.nullptr(rffi.CCHARP.TO))
+
     def close(self):
         rffi_fclose(self.llf)
 
+
 def prepare_file_argument(space, fileobj):
     fileobj.direct_flush()
     if fileobj.cffi_fileobj is None:

pypy/module/_cffi_backend/ctypestruct.py

 """
 
 from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, rffi
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+
+from rpython.rlib import jit
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask
-from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import rffi
 
+from pypy.module._cffi_backend import cdataobj, ctypeprim, misc
 from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, ctypeprim, misc
 
 
 class W_CTypeStructOrUnion(W_CType):
 class W_CTypeStruct(W_CTypeStructOrUnion):
     kind = "struct"
 
+
 class W_CTypeUnion(W_CTypeStructOrUnion):
     kind = "union"
 
         #
         value = misc.as_long_long(space, w_ob)
         if isinstance(ctype, ctypeprim.W_CTypePrimitiveSigned):
-            fmin = -(r_longlong(1) << (self.bitsize-1))
-            fmax = (r_longlong(1) << (self.bitsize-1)) - 1
+            fmin = -(r_longlong(1) << (self.bitsize - 1))
+            fmax = (r_longlong(1) << (self.bitsize - 1)) - 1
             if fmax == 0:
                 fmax = 1      # special case to let "int x:1" receive "1"
         else:

pypy/module/_cffi_backend/libraryobj.py

 from __future__ import with_statement
-from pypy.interpreter.error import OperationError, operationerrfmt
+
 from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef
-from rpython.rtyper.lltypesystem import lltype, rffi
+
+from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib.rdynload import DLLHANDLE, dlopen, dlsym, dlclose, DLOpenError
 
 from pypy.module._cffi_backend.cdataobj import W_CData

pypy/module/_cffi_backend/misc.py

 from __future__ import with_statement
-from pypy.interpreter.error import OperationError, operationerrfmt
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+
+from pypy.interpreter.error import OperationError
+
+from rpython.rlib import jit
+from rpython.rlib.objectmodel import keepalive_until_here, specialize
 from rpython.rlib.rarithmetic import r_uint, r_ulonglong, is_signed_integer_type
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.objectmodel import keepalive_until_here, specialize
-from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
 # ____________________________________________________________
 def read_raw_unsigned_data(target, size):
     for TP, TPP in _prim_unsigned_types:
         if size == rffi.sizeof(TP):
-            return rffi.cast(lltype.UnsignedLongLong, rffi.cast(TPP,target)[0])
+            return rffi.cast(lltype.UnsignedLongLong, rffi.cast(TPP, target)[0])
     raise NotImplementedError("bad integer size")
 
 def read_raw_ulong_data(target, size):
     for TP, TPP in _prim_unsigned_types:
         if size == rffi.sizeof(TP):
             assert rffi.sizeof(TP) <= rffi.sizeof(lltype.Unsigned)
-            return rffi.cast(lltype.Unsigned, rffi.cast(TPP,target)[0])
+            return rffi.cast(lltype.Unsigned, rffi.cast(TPP, target)[0])
     raise NotImplementedError("bad integer size")
 
 def read_raw_float_data(target, size):

pypy/module/_cffi_backend/newtype.py

 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import unwrap_spec
+
+from rpython.rlib.objectmodel import specialize
+from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from rpython.rlib.rarithmetic import most_neg_value_of, most_pos_value_of
-from rpython.rlib.objectmodel import specialize
 
-from pypy.module._cffi_backend import ctypeobj, ctypeprim, ctypeptr, ctypearray
-from pypy.module._cffi_backend import ctypestruct, ctypevoid, ctypeenum
+from pypy.module._cffi_backend import (ctypeobj, ctypeprim, ctypeptr,
+    ctypearray, ctypestruct, ctypevoid, ctypeenum)
 
 
 @specialize.memo()
         #
         if foffset < 0:
             # align this field to its own 'falign' by inserting padding
-            offset = (offset + falign - 1) & ~(falign-1)
+            offset = (offset + falign - 1) & ~(falign - 1)
         else:
             # a forced field position: ignore the offset just computed,
             # except to know if we must set 'custom_field_pos'
                 fbitsize == 8 * ftype.size and not
                 isinstance(ftype, ctypeprim.W_CTypePrimitiveCharOrUniChar)):
             fbitsize = -1
-            if isinstance(ftype, ctypearray.W_CTypeArray) and ftype.length==0:
+            if isinstance(ftype, ctypearray.W_CTypeArray) and ftype.length == 0:
                 bitshift = ctypestruct.W_CField.BS_EMPTY_ARRAY
             else:
                 bitshift = ctypestruct.W_CField.BS_REGULAR
     # as 1 instead.  But for ctypes support, we allow the manually-
     # specified totalsize to be zero in this case.
     if totalsize < 0:
-        offset = (offset + alignment - 1) & ~(alignment-1)
+        offset = (offset + alignment - 1) & ~(alignment - 1)
         totalsize = offset or 1
     elif totalsize < offset:
         raise operationerrfmt(space.w_TypeError,