本文整理匯總了Python中ctypes.util.find_library方法的典型用法代碼示例。如果您正苦於以下問題:Python util.find_library方法的具體用法?Python util.find_library怎麽用?Python util.find_library使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes.util
的用法示例。
在下文中一共展示了util.find_library方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def __init__(self, ticket_number_key, request_data_key,
libcrypto_path=None):
self.check_des_key(ticket_number_key)
self.check_des_key(request_data_key)
self.ticket_number_key = ticket_number_key
self.request_data_key = request_data_key
if not libcrypto_path:
from ctypes.util import find_library
libcrypto_path = find_library('crypto')
if not libcrypto_path:
raise Exception('libcrypto(OpenSSL) not found')
self.libcrypto = ctypes.CDLL(libcrypto_path)
if hasattr(self.libcrypto, 'OpenSSL_add_all_ciphers'):
self.libcrypto.OpenSSL_add_all_ciphers()
示例2: get_capability
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def get_capability(filename):
"""
Get names of capabilities and the corresponding capability set for given filename.
@filename: The complete path to the file
"""
res = {"capabilities": [], "set": [], "error": False}
try:
libcap_path = find_library("cap")
libcap = ctypes.cdll.LoadLibrary(libcap_path)
except OSError:
res["error"] = True
logging.warning("Unable to find capabilities for {0}".format(filename))
return res
cap_t = libcap.cap_get_file(ctypes.create_string_buffer(filename.encode("utf-8")))
libcap.cap_to_text.restype = ctypes.c_char_p
cap_object = libcap.cap_to_text(cap_t, None)
libcap.cap_free(cap_t)
if cap_object is not None:
cap_string = cap_object.decode("utf-8")
res["capabilities"] = (cap_string.split("+")[0])[2:].split(",")
res["set"] = list(cap_string.split("+")[1])
return res
示例3: test_load_library
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_load_library(self):
self.assertIsNotNone(libc_name)
if is_resource_enabled("printing"):
print find_library("kernel32")
print find_library("user32")
if os.name == "nt":
windll.kernel32.GetModuleHandleW
windll["kernel32"].GetModuleHandleW
windll.LoadLibrary("kernel32").GetModuleHandleW
WinDLL("kernel32").GetModuleHandleW
elif os.name == "ce":
windll.coredll.GetModuleHandleW
windll["coredll"].GetModuleHandleW
windll.LoadLibrary("coredll").GetModuleHandleW
WinDLL("coredll").GetModuleHandleW
示例4: _load
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def _load(self):
library_path = find_library(self.name)
if library_path is None:
env_var_name = "PATH" if sys.platform == 'win32' else "LD_LIBRARY_PATH"
raise CannotFindPicoSDKError("PicoSDK (%s) not found, check %s" % (self.name, env_var_name))
try:
if sys.platform == 'win32':
from ctypes import WinDLL
result = WinDLL(library_path)
else:
from ctypes import cdll
result = cdll.LoadLibrary(library_path)
except OSError as e:
raise CannotOpenPicoSDKError("PicoSDK (%s) not compatible (check 32 vs 64-bit): %s" % (self.name, e))
return result
示例5: __init__
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def __init__(self):
v_posix.PosixMixin.__init__(self)
v_posix.PtraceMixin.__init__(self)
self.libc = ctypes.CDLL(c_util.find_library('c'))
self.myport = self.libc.mach_task_self()
self.libc.mach_port_allocate.argtypes = [ipc_space_t, mach_port_right_t, ctypes.POINTER(mach_port_name_t)]
self.libc.mach_port_allocate.restype = kern_return_t
self.libc.mach_vm_read.argtypes = [ mach_port_t, size_t, size_t, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_uint32)]
self.libc.mach_vm_read.restype = kern_return_t
#FIXME mach_port_insert_right
self.portset = self.newMachPort(MACH_PORT_RIGHT_PORT_SET)
self.excport = self.newMachRWPort()
self.addPortToSet(self.excport)
示例6: test_load_library
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_load_library(self):
self.assertFalse(libc_name is None)
if is_resource_enabled("printing"):
print find_library("kernel32")
print find_library("user32")
if os.name == "nt":
windll.kernel32.GetModuleHandleW
windll["kernel32"].GetModuleHandleW
windll.LoadLibrary("kernel32").GetModuleHandleW
WinDLL("kernel32").GetModuleHandleW
elif os.name == "ce":
windll.coredll.GetModuleHandleW
windll["coredll"].GetModuleHandleW
windll.LoadLibrary("coredll").GetModuleHandleW
WinDLL("coredll").GetModuleHandleW
示例7: find_yajl_ctypes
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def find_yajl_ctypes(required):
'''
Finds and loads yajl shared object of the required major
version (1, 2, ...) using ctypes.
'''
# Importing ``ctypes`` should be in scope of this function to prevent failure
# of `backends`` package load in a runtime where ``ctypes`` is not available.
# Example of such environment is Google App Engine (GAE).
from ctypes import util, cdll
so_name = util.find_library('yajl')
if so_name is None:
raise YAJLImportError('YAJL shared object not found.')
yajl = cdll.LoadLibrary(so_name)
require_version(yajl.yajl_version(), required)
return yajl
示例8: test_load_library
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_load_library(self):
# CRT is no longer directly loadable. See issue23606 for the
# discussion about alternative approaches.
#self.assertIsNotNone(libc_name)
if test.support.verbose:
print(find_library("kernel32"))
print(find_library("user32"))
if os.name == "nt":
windll.kernel32.GetModuleHandleW
windll["kernel32"].GetModuleHandleW
windll.LoadLibrary("kernel32").GetModuleHandleW
WinDLL("kernel32").GetModuleHandleW
elif os.name == "ce":
windll.coredll.GetModuleHandleW
windll["coredll"].GetModuleHandleW
windll.LoadLibrary("coredll").GetModuleHandleW
WinDLL("coredll").GetModuleHandleW
示例9: test_ctypes
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_ctypes(self):
from ctypes.util import find_library
libc = ctypes.CDLL(find_library("c"))
liblog = ctypes.CDLL(find_library("log"))
self.assertIsNone(find_library("nonexistent"))
# Work around double-underscore mangling of __android_log_write.
def assertHasSymbol(dll, name):
self.assertIsNotNone(getattr(dll, name))
def assertNotHasSymbol(dll, name):
with self.assertRaises(AttributeError):
getattr(dll, name)
assertHasSymbol(libc, "printf")
assertHasSymbol(liblog, "__android_log_write")
assertNotHasSymbol(libc, "__android_log_write")
# Global search (https://bugs.python.org/issue34592): only works on newer API levels.
if API_LEVEL >= 21:
main = ctypes.CDLL(None)
assertHasSymbol(main, "printf")
assertHasSymbol(main, "__android_log_write")
assertNotHasSymbol(main, "nonexistent")
assertHasSymbol(ctypes.pythonapi, "PyObject_Str")
示例10: test_load_library
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_load_library(self):
self.assertIsNotNone(libc_name)
if test.support.verbose:
print(find_library("kernel32"))
print(find_library("user32"))
if os.name == "nt":
windll.kernel32.GetModuleHandleW
windll["kernel32"].GetModuleHandleW
windll.LoadLibrary("kernel32").GetModuleHandleW
WinDLL("kernel32").GetModuleHandleW
elif os.name == "ce":
windll.coredll.GetModuleHandleW
windll["coredll"].GetModuleHandleW
windll.LoadLibrary("coredll").GetModuleHandleW
WinDLL("coredll").GetModuleHandleW
示例11: load_libxkb_lookup
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def load_libxkb_lookup() -> LookupFunc:
import ctypes
for suffix in ('.0', ''):
with suppress(Exception):
lib = ctypes.CDLL('libxkbcommon.so' + suffix)
break
else:
from ctypes.util import find_library
lname = find_library('xkbcommon')
if lname is None:
raise RuntimeError('Failed to find libxkbcommon')
lib = ctypes.CDLL(lname)
f = lib.xkb_keysym_from_name
f.argtypes = [ctypes.c_char_p, ctypes.c_int]
f.restype = ctypes.c_int
def xkb_lookup(name: str, case_sensitive: bool = False) -> Optional[int]:
q = name.encode('utf-8')
return f(q, int(case_sensitive)) or None
return xkb_lookup
示例12: psloadlib
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def psloadlib(name):
""" Loads driver library
:param name: driver name
:type name: str
:returns: ctypes reference to the library
:rtype: object
"""
result = None
try:
if sys.platform == 'win32':
result = ctypes.WinDLL(find_library(name))
else:
result = cdll.LoadLibrary(find_library(name))
except OSError as ex:
print name, "import(%d): Library not found" % sys.exc_info()[-1].tb_lineno
return result
示例13: load_ctypes_library
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def load_ctypes_library(name, signatures, error_checkers):
"""
Load library ``name`` and return a :class:`ctypes.CDLL` object for it.
:param str name: the library name
:param signatures: signatures of methods
:type signatures: dict of str * (tuple of (list of type) * type)
:param error_checkers: error checkers for methods
:type error_checkers: dict of str * ((int * ptr * arglist) -> int)
The library has errno handling enabled.
Important functions are given proper signatures and return types to support
type checking and argument conversion.
:returns: a loaded library
:rtype: ctypes.CDLL
:raises ImportError: if the library is not found
"""
library_name = find_library(name)
if not library_name:
raise ImportError('No library named %s' % name)
lib = CDLL(library_name, use_errno=True)
# Add function signatures
for funcname, signature in signatures.items():
function = getattr(lib, funcname, None)
if function:
argtypes, restype = signature
function.argtypes = argtypes
function.restype = restype
errorchecker = error_checkers.get(funcname)
if errorchecker:
function.errcheck = errorchecker
return lib
示例14: check_tensorrt_installation
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def check_tensorrt_installation():
assert find_library('nvinfer') is not None, "Can't find the TensorRT shared library"
示例15: test_find
# 需要導入模塊: from ctypes import util [as 別名]
# 或者: from ctypes.util import find_library [as 別名]
def test_find(self):
for name in ("c", "m"):
lib = find_library(name)
if lib:
cdll.LoadLibrary(lib)
CDLL(lib)