Skip to main content

Module cffi_utils.sowrapper

Utility functions to locate and load shared libraries

DESCRIPTION

Recommended usage:

Should only need to use get_lib_ffi_shared() or get_lib_ffi_resource()

Use get_lib_ffi_shared to load a system-wide shared library with a known library filename and / or path

Use get_lib_ffi_resource to load a module-specific shared library where library filename MAY be mangled as per PEP3149 and path MAY need to be looked up using pkg_resources. Internally, get_lib_ffi_resource() calls get_lib_ffi_shared()

Both return a tuple: (ffi, lib):

ffi-->FFIExt - should behave like cffi.FFI with some additional
    utility methods
lib-->SharedLibWrapper instance - use methods on this object to
    call methods in the shared library

CLASSES

class SharedLibWrapper(__builtin__.object)
 |  Methods defined here:
 |
 |  __init__(self, libpath, c_hdr, module_name=None)
 |      libpath-->str: library name; can also be full path
 |      c_hdr-->str: C-style header definitions for functions to wrap
 |      ffi-->FFIExt or cffi.FFI

FUNCTIONS

get_lib_ffi_resource(module_name, libpath, c_hdr)
    module_name-->str: module name to retrieve resource
    libpath-->str: shared library filename with optional path
    c_hdr-->str: C-style header definitions for functions to wrap
    Returns-->(ffi, lib)

    Use this method when you are loading a package-specific shared library
    If you want to load a system-wide shared library, use get_lib_ffi_shared
    instead

get_lib_ffi_shared(libpath, c_hdr)
    libpath-->str: shared library filename with optional path
    c_hdr-->str: C-style header definitions for functions to wrap
    Returns-->(ffi, lib)

Module cffi_utils.ffi

Extension of cffi.FFI adding a few utility methods

CLASSES

class FFIExt(cffi.api.FFI)
 |  FFIExt is an extension of cffi.FFI, adding a few utility methods
 |
 |  get_cdata(), get_buffer() and get_bytes() all operate on a variable
 |  list of arguments as a convenience.
 |
 |  Otherwise, get_cdata() and get_buffer() are equivalent to
 |  FFI.from_buffer() and FFI.buffer() respectively
 |
 |  get_bytes() is identical to get_buffer() except that outputs are
 |  converted to bytes
 |
 |  get_buffer(self, *args)
 |      all args-->_cffi_backend.CDataOwn
 |      Must be a pointer or an array
 |      Returns-->buffer (if a SINGLE argument was provided)
 |                LIST of buffer (if a args was a tuple or list)
 |
 |  get_bytes(self, *args)
 |      all args-->_cffi_backend.CDataOwn
 |      Must be a pointer or an array
 |      Returns-->bytes (if a SINGLE argument was provided)
 |                LIST of bytes (if a args was a tuple or list)
 |
 |  get_cdata(self, *args)
 |      all args-->_cffi_backend.buffer
 |      Returns-->cdata (if a SINGLE argument was provided)
 |                LIST of cdata (if a args was a tuple or list)
 |
 |  get_extension(self)

Module cffi_utils.py2to3

Utility functions for Py2/Py3 compatibility

FUNCTIONS

chr(x)
    x-->int / byte
    Returns-->byte / str of length 1
        Behaves like PY2 chr() in PY2 or PY3

decode(b, encoding='latin-1')
    b-->bytes
    encoding-->str: encoding to use. Recommended to use default
    Returns-->str: b decoded to str using encoding
        Works in PY2, PY3

encode(s, encoding='latin-1')
    s-->str
    encoding-->str: encoding to use. Recommended to use default
    Returns-->bytes: s encoded to bytes using encoding
        Works in PY2, PY3

fromBytes(b)
    s-->bytes (or str)
    Returns-->str (works in PY2, PY3)

inputFromBytes(func, *args, **kwargs)
    Descriptor that converts all arguments to str

inputToBytes(func, *args, **kwargs)
    Descriptor that converts all arguments to bytes

ord(x)
    x-->int / byte
    Returns-->int
        Behaves like PY2 ord() in PY2 or PY3

outputFromBytes(func, *args, **kwargs)
    Descriptor that converts all return values to str

outputToBytes(func, *args, **kwargs)
    Descriptor that converts all return values to bytes

toBytes(s)
    s-->str (or bytes)
    Returns-->bytes (works in PY2, PY3)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cffi_utils-0.79.tar.gz (21.2 kB view details)

Uploaded Source

File details

Details for the file cffi_utils-0.79.tar.gz.

File metadata

  • Download URL: cffi_utils-0.79.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cffi_utils-0.79.tar.gz
Algorithm Hash digest
SHA256 b0986b85e13b158af07c9a17f2fe353961c61b94342796ab4e96ca5e8e072a2c
MD5 6d85a905c0634c03ea14072ea30ea0b1
BLAKE2b-256 95bf4987402d94352b29e831f48e3a9669a1a39d9207aba8e247964c4fb9ef17

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.79 This release

1 file

0.78

1 file

0.77.15

1 file

0.77.14

1 file

0.77.13

1 file

0.77.12

1 file

0.77.11

1 file

0.77.10

1 file

0.77.9

1 file

0.77.8

1 file

0.77.7

1 file

0.77.6

1 file

0.77.5

1 file

0.77.4

1 file

0.77.3

1 file

0.77.2

1 file

0.77.1

1 file

0.77

1 file

0.76

1 file

0.75

1 file

0.74

1 file

0.73

1 file

0.72

1 file

0.71

1 file

0.70

1 file

0.69

1 file

0.68

1 file

0.67

1 file

0.66

1 file

0.65

1 file

0.64

1 file

0.63

1 file

0.62

1 file

0.61

1 file

0.60

1 file

0.59

1 file

0.58

1 file

0.57

1 file

0.56

1 file

0.55

1 file

0.54

1 file

0.53

1 file

0.52

1 file

0.51

1 file

0.50

1 file

0.40

1 file

0.39

1 file

0.38

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page