当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.util方法代码示例

本文整理汇总了Python中ctypes.util方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.util方法的具体用法?Python ctypes.util怎么用?Python ctypes.util使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.util方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [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() 
开发者ID:realityone,项目名称:libcet,代码行数:20,代码来源:cet.py

示例2: _set_proc_title

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def _set_proc_title(process_name: str) -> None:
  """
  BSD specific calls (should be compataible with both FreeBSD and OpenBSD:
  http://fxr.watson.org/fxr/source/gen/setproctitle.c?v=FREEBSD-LIBC
  http://www.rootr.net/man/man/setproctitle/3
  """

  libc = ctypes.CDLL(ctypes.util.find_library('c'))
  name_buffer = ctypes.create_string_buffer(len(process_name) + 1)
  name_buffer.value = process_name.encode()

  try:
    libc.setproctitle(ctypes.byref(name_buffer))
  except AttributeError:
    # Possible issue (seen on OSX):
    # AttributeError: dlsym(0x7fff6a41d1e0, setproctitle): symbol not found

    pass 
开发者ID:torproject,项目名称:stem,代码行数:20,代码来源:system.py

示例3: _load_libc

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def _load_libc():
    libc_path = None
    try:
        libc_path = ctypes.util.find_library('c')
    except (OSError, IOError):
        # Note: find_library will on some platforms raise these undocumented
        # errors, e.g.on android IOError "No usable temporary directory found"
        # will be raised.
        pass

    if libc_path is not None:
        return ctypes.CDLL(libc_path)

    # Fallbacks
    try:
        return ctypes.CDLL('libc.so')
    except (OSError, IOError):
        return ctypes.CDLL('libc.so.6') 
开发者ID:restran,项目名称:hacker-scripts,代码行数:20,代码来源:inotify_c.py

示例4: forget

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def forget(modname):
    """'Forget' a module was ever imported.

    This removes the module from sys.modules and deletes any PEP 3147/488 or
    legacy .pyc files.
    """
    unload(modname)
    for dirname in sys.path:
        source = os.path.join(dirname, modname + '.py')
        # It doesn't matter if they exist or not, unlink all possible
        # combinations of PEP 3147/488 and legacy pyc files.
        unlink(source + 'c')
        for opt in ('', 1, 2):
            unlink(importlib.util.cache_from_source(source, optimization=opt))

# Check whether a gui is actually available 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:__init__.py

示例5: test_ctypes

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [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") 
开发者ID:chaquo,项目名称:chaquopy,代码行数:27,代码来源:test_android.py

示例6: forget

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def forget(modname):
    """'Forget' a module was ever imported.

    This removes the module from sys.modules and deletes any PEP 3147 or
    legacy .pyc and .pyo files.
    """
    unload(modname)
    for dirname in sys.path:
        source = os.path.join(dirname, modname + '.py')
        # It doesn't matter if they exist or not, unlink all possible
        # combinations of PEP 3147 and legacy pyc and pyo files.
        unlink(source + 'c')
        unlink(source + 'o')
        unlink(importlib.util.cache_from_source(source, debug_override=True))
        unlink(importlib.util.cache_from_source(source, debug_override=False))

# Check whether a gui is actually available 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:__init__.py

示例7: load_libxkb_lookup

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [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 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:24,代码来源:key_names.py

示例8: find_library

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def find_library(self, path):

        # search first for local libs
        if _local_lib_paths:
            if not self._local_libs_cache:
                self._local_libs_cache = self._find_libs(_local_lib_paths)
            if path in self._local_libs_cache:
                return self._local_libs_cache[path]

        # ctypes tries ldconfig, gcc and objdump.  If none of these are
        # present, we implement the ld-linux.so search path as described in
        # the man page.

        result = ctypes.util.find_library(path)

        if result:
            return result

        if self._ld_so_cache is None:
            self._create_ld_so_cache()

        return self._ld_so_cache.get(path) 
开发者ID:pyglet,项目名称:pyglet,代码行数:24,代码来源:lib.py

示例9: find_lib

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def find_lib(libname, paths):
    spaths = ['%s/lib%s.so' % (path, libname) for path in paths]
    for path in spaths:
        if os.path.islink(path):
            libcname = os.readlink(path)
            return (libcname)
        elif os.path.isfile(path):
            for line in open(path, 'r').readlines():
                parts = line.split(' ')
                if parts[0] != 'GROUP':
                    continue
                libcname = parts[2]
                return (libcname)
    return ctypes.util.find_library(libname) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:16,代码来源:clock_dtime.py

示例10: libgl_workaround

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def libgl_workaround() -> None:
    """Work around QOpenGLShaderProgram issues, especially for Nvidia.

    See https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826
    """
    if os.environ.get('QUTE_SKIP_LIBGL_WORKAROUND'):
        return

    libgl = ctypes.util.find_library("GL")
    if libgl is not None:  # pragma: no branch
        ctypes.CDLL(libgl, mode=ctypes.RTLD_GLOBAL) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:13,代码来源:utils.py

示例11: _load_default

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def _load_default():
    global _lib
    try:
        if sys.platform == 'win32':
            _basedir = os.path.dirname(os.path.abspath(__file__))
            _bitness = 'x64' if sys.maxsize > 2**32 else 'x86'
            _filename = os.path.join(_basedir, 'bin', 'libopus-0.{}.dll'.format(_bitness))
            _lib = libopus_loader(_filename)
        else:
            _lib = libopus_loader(ctypes.util.find_library('opus'))
    except Exception:
        _lib = None

    return _lib is not None 
开发者ID:Rapptz,项目名称:discord.py,代码行数:16,代码来源:opus.py

示例12: load_opus

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def load_opus(name):
    """Loads the libopus shared library for use with voice.

    If this function is not called then the library uses the function
    :func:`ctypes.util.find_library` and then loads that one if available.

    Not loading a library and attempting to use PCM based AudioSources will
    lead to voice not working.

    This function propagates the exceptions thrown.

    .. warning::

        The bitness of the library must match the bitness of your python
        interpreter. If the library is 64-bit then your python interpreter
        must be 64-bit as well. Usually if there's a mismatch in bitness then
        the load will throw an exception.

    .. note::

        On Windows, this function should not need to be called as the binaries
        are automatically loaded.

    .. note::

        On Windows, the .dll extension is not necessary. However, on Linux
        the full extension is required to load the library, e.g. ``libopus.so.1``.
        On Linux however, :func:`ctypes.util.find_library` will usually find the library automatically
        without you having to call this.

    Parameters
    ----------
    name: :class:`str`
        The filename of the shared library.
    """
    global _lib
    _lib = libopus_loader(name) 
开发者ID:Rapptz,项目名称:discord.py,代码行数:39,代码来源:opus.py

示例13: is_loaded

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def is_loaded():
    """Function to check if opus lib is successfully loaded either
    via the :func:`ctypes.util.find_library` call of :func:`load_opus`.

    This must return ``True`` for voice to work.

    Returns
    -------
    :class:`bool`
        Indicates if the opus library has been loaded.
    """
    global _lib
    return _lib is not None 
开发者ID:Rapptz,项目名称:discord.py,代码行数:15,代码来源:opus.py

示例14: _class_setup

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def _class_setup(cls):
    if cls._libc:
      return

    libc_name = ctypes.util.find_library('c')
    cls._libc = ctypes.CDLL(libc_name, use_errno=True)
    cls._libc.inotify_init.argtypes = []
    cls._libc.inotify_init.restype = ctypes.c_int
    cls._libc.inotify_add_watch.argtypes = [ctypes.c_int,
                                            ctypes.c_char_p,
                                            ctypes.c_uint32]
    cls._libc.inotify_add_watch.restype = ctypes.c_int
    cls._libc.inotify_rm_watch.argtypes = [ctypes.c_int,
                                           ctypes.c_int]
    cls._libc.inotify_rm_watch.restype = ctypes.c_int 
开发者ID:elsigh,项目名称:browserscope,代码行数:17,代码来源:inotify_file_watcher.py

示例15: size_of

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import util [as 别名]
def size_of(obj: Any, exclude: Optional[Collection[int]] = None) -> int:
  """
  Provides the `approximate memory usage of an object
  <https://code.activestate.com/recipes/577504/>`_. This can recurse tuples,
  lists, deques, dicts, and sets. To teach this function to inspect additional
  object types expand SIZE_RECURSES...

  ::

    stem.util.system.SIZE_RECURSES[SomeClass] = SomeClass.get_elements

  .. versionadded:: 1.6.0

  :param obj: object to provide the size of
  :param exclude: object ids to exclude from size estimation

  :returns: **int** with the size of the object in bytes

  :raises: **NotImplementedError** if using PyPy
  """

  if platform.python_implementation() == 'PyPy':
    raise NotImplementedError('PyPy does not implement sys.getsizeof()')

  exclude = set(exclude) if exclude is not None else set()

  if id(obj) in exclude:
    return 0

  try:
    size = sys.getsizeof(obj)
  except TypeError:
    size = sys.getsizeof(0)  # estimate if object lacks a __sizeof__

  exclude.add(id(obj))

  if type(obj) in SIZE_RECURSES:
    for entry in SIZE_RECURSES[type(obj)](obj):
      size += size_of(entry, exclude)

  return size 
开发者ID:torproject,项目名称:stem,代码行数:43,代码来源:system.py


注:本文中的ctypes.util方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。