围绕c代码编写python包装器的实用程序
cffi_utils的Python项目详细描述
cffi-utils.sowrapper模块
查找和加载共享库的实用程序函数
说明
推荐用法:
只需要使用get-lib-ffi-shared()或 获取lib_ffi_resource()
使用get-lib-ffi-shared加载具有 已知库文件名和/或路径
使用get-lib-ffi资源加载特定于模块的共享库 其中库文件名may根据pep3149被损坏,路径may 需要使用pkg_资源查找。在内部, get-lib-ffi-resource()调用get-lib-ffi-shared()
两者都返回一个元组:(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
课程
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
功能
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)
cffi-utils.ffi模块
扩展cffi.ffi添加一些实用方法
课程
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)
模块CFFI实用程序.py2to3
与py2/py3兼容的实用程序函数
功能
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)