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


Python ctypes.py_object方法代码示例

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


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

示例1: storeFrameLocals

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def storeFrameLocals(self, frmnr=0):
        """Stores the locals into the frame.

        Thus an access to frame.f_locals returns the last data
        """
        cf = self.currentFrame
        while cf is not None and frmnr > 0:
            cf = cf.f_back
            frmnr -= 1

        try:
            if '__pypy__' in sys.builtin_module_names:
                import __pypy__
                __pypy__.locals_to_fast(cf)
                return
        except Exception:
            pass

        ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(cf),
                                              ctypes.c_int(0)) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:22,代码来源:base_cdm_dbg.py

示例2: async_raise

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed.

    tid is the value given by thread.get_ident() (an integer).
    Raise SystemExit to kill a thread."""
    if not isinstance(exctype, (types.ClassType, type)):
        raise TypeError("Only types can be raised (not instances)")
    if not isinstance(tid, int):
        raise TypeError("tid must be an integer")
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble, 
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
        raise SystemError("PyThreadState_SetAsyncExc failed") 
开发者ID:linuxscout,项目名称:mishkal,代码行数:19,代码来源:killthread.py

示例3: send

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def send(self, item):
        res = LIBRARY.call(
            "incoming_batch_sender_send",
            self._ptr,
            ctypes.py_object(item))

        if res == IncomingBatchSenderErrorCode.Success:
            return

        if res == IncomingBatchSenderErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        if res == IncomingBatchSenderErrorCode.InvalidInput:
            raise ValueError("Input was not valid ")
        if res == IncomingBatchSenderErrorCode.Disconnected:
            raise Disconnected()

        raise ValueError("An unknown error occurred: {}".format(res)) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:19,代码来源:publisher.py

示例4: make_set_closure_cell

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def make_set_closure_cell():
    """
    Moved into a function for testability.
    """
    if PYPY:  # pragma: no cover

        def set_closure_cell(cell, value):
            cell.__setstate__((value,))

    else:
        try:
            ctypes = import_ctypes()

            set_closure_cell = ctypes.pythonapi.PyCell_Set
            set_closure_cell.argtypes = (ctypes.py_object, ctypes.py_object)
            set_closure_cell.restype = ctypes.c_int
        except Exception:
            # We try best effort to set the cell, but sometimes it's not
            # possible.  For example on Jython or on GAE.
            set_closure_cell = just_warn
    return set_closure_cell 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:23,代码来源:_compat.py

示例5: zerome

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def zerome(bufferObject):
    '''
    clear a string value from memory

    :param bufferObject: the string variable, which should be cleared
    :type  bufferObject: string or key buffer

    :return:    - nothing -
    '''
    data = ctypes.POINTER(ctypes.c_char)()
    size = ctypes.c_int()  # Note, int only valid for python 2.5
    ctypes.pythonapi.PyObject_AsCharBuffer(ctypes.py_object(bufferObject),
                                           ctypes.pointer(data),
                                           ctypes.pointer(size))
    ctypes.memset(data, 0, size.value)

    return 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:19,代码来源:crypto.py

示例6: getWindowByTitle

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def getWindowByTitle(self, wildcard, order=0):
        """ Returns a handle for the first window that matches the provided "wildcard" regex """
        EnumWindowsProc = ctypes.WINFUNCTYPE(
            ctypes.c_bool,
            ctypes.POINTER(ctypes.c_int),
            ctypes.py_object)
        def callback(hwnd, context):
            if ctypes.windll.user32.IsWindowVisible(hwnd):
                length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                ctypes.windll.user32.GetWindowTextW(hwnd, buff, length + 1)
                if re.search(context["wildcard"], buff.value, flags=re.I) != None and not context["handle"]:
                    if context["order"] > 0:
                        context["order"] -= 1
                    else:
                        context["handle"] = hwnd
            return True
        data = {"wildcard": wildcard, "handle": None, "order": order}
        ctypes.windll.user32.EnumWindows(EnumWindowsProc(callback), ctypes.py_object(data))
        return data["handle"] 
开发者ID:glitchassassin,项目名称:lackey,代码行数:22,代码来源:PlatformManagerWindows.py

示例7: getWindowByPID

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def getWindowByPID(self, pid, order=0):
        """ Returns a handle for the first window that matches the provided PID """
        if pid <= 0:
            return None
        EnumWindowsProc = ctypes.WINFUNCTYPE(
            ctypes.c_bool,
            ctypes.POINTER(ctypes.c_int),
            ctypes.py_object)
        def callback(hwnd, context):
            if ctypes.windll.user32.IsWindowVisible(hwnd):
                pid = ctypes.c_ulong()
                ctypes.windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
                if context["pid"] == int(pid.value) and not context["handle"]:
                    if context["order"] > 0:
                        context["order"] -= 1
                    else:
                        context["handle"] = hwnd
            return True
        data = {"pid": pid, "handle": None, "order": order}
        ctypes.windll.user32.EnumWindows(EnumWindowsProc(callback), ctypes.py_object(data))
        return data["handle"] 
开发者ID:glitchassassin,项目名称:lackey,代码行数:23,代码来源:PlatformManagerWindows.py

示例8: tb_set_next

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def tb_set_next(tb, tb_next):
        c_tb = _CTraceback.from_address(id(tb))

        # Clear out the old tb_next.
        if tb.tb_next is not None:
            c_tb_next = ctypes.py_object(tb.tb_next)
            c_tb.tb_next = ctypes.py_object()
            ctypes.pythonapi.Py_DecRef(c_tb_next)

        # Assign the new tb_next.
        if tb_next is not None:
            c_tb_next = ctypes.py_object(tb_next)
            ctypes.pythonapi.Py_IncRef(c_tb_next)
            c_tb.tb_next = c_tb_next

        return tb 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:debug.py

示例9: np_array_as_bgl_Buffer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def np_array_as_bgl_Buffer(array):
    type = array.dtype
    if   type == np.int8:    type = bgl.GL_BYTE
    elif type == np.int16:   type = bgl.GL_SHORT
    elif type == np.int32:   type = bgl.GL_INT
    elif type == np.float32: type = bgl.GL_FLOAT
    elif type == np.float64: type = bgl.GL_DOUBLE
    else: raise

    _decref = ctypes.pythonapi.Py_DecRef
    _incref = ctypes.pythonapi.Py_IncRef

    _decref.argtypes = _incref.argtypes = [ctypes.py_object]
    _decref.restype = _incref.restype = None

    buf = bgl.Buffer(bgl.GL_BYTE, (1, *array.shape))[0]
    c_buf = C_Buffer.from_address(id(buf))

    _decref(c_buf.parent)
    _incref(array)

    c_buf.parent = array # Prevents MEM_freeN
    c_buf.type = type
    c_buf.buf = array.ctypes.data
    return buf 
开发者ID:CGCookie,项目名称:addon_common,代码行数:27,代码来源:bgl_ext.py

示例10: get_window_handle

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def get_window_handle(window):
    """ Uses ctypes to call gdk_win32_window_get_handle which is not available in python gobject introspection porting.

    Solution from http://stackoverflow.com/a/27236258/1387346

    Args:
        window (:class:`~Gdk.Window`): The window for which we want to get the handle

    Returns:
        The handle to the win32 window
    """
    # get the c gpointer of the gdk window
    ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
    ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object]
    drawingarea_gpointer = ctypes.pythonapi.PyCapsule_GetPointer(window.__gpointer__, None)
    # get the win32 handle
    gdkdll = ctypes.CDLL('libgdk-3-0.dll')
    return gdkdll.gdk_win32_window_get_handle(drawingarea_gpointer) 
开发者ID:Cimbali,项目名称:pympress,代码行数:20,代码来源:base.py

示例11: getHandle

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def getHandle(self):
        if self.hidden_window:
            # PyQt5 on Linux
            return int(self.hidden_window.winId())
        try:
            # PyQt4 and PyQt5
            return int(self.winId())
        except:
            # PySide:
            # | QWidget.winId() returns <PyCObject object at 0x02FD8788>
            # | Converting it to int using ctypes.
            ctypes.pythonapi.PyCapsule_GetPointer.restype = (ctypes.c_void_p)
            ctypes.pythonapi.PyCapsule_GetPointer.argtypes = ([
                ctypes.py_object
            ])
            return ctypes.pythonapi.PyCapsule_GetPointer(self.winId(), None) 
开发者ID:RimoChan,项目名称:Librian,代码行数:18,代码来源:qtcef.py

示例12: _make_skel_func

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def _make_skel_func(code, num_closures, base_globals = None):
    """ Creates a skeleton function object that contains just the provided
        code and the correct number of cells in func_closure.  All other
        func attributes (e.g. func_globals) are empty.
    """
    #build closure (cells):
    if not ctypes:
        raise Exception('ctypes failed to import; cannot build function')

    cellnew = ctypes.pythonapi.PyCell_New
    cellnew.restype = ctypes.py_object
    cellnew.argtypes = (ctypes.py_object,)
    dummy_closure = tuple(map(lambda i: cellnew(None), range(num_closures)))

    if base_globals is None:
        base_globals = {}
    base_globals['__builtins__'] = __builtins__

    return types.FunctionType(code, base_globals,
                              None, None, dummy_closure)

# this piece of opaque code is needed below to modify 'cell' contents 
开发者ID:adobe-research,项目名称:spark-cluster-deployment,代码行数:24,代码来源:cloudpickle.py

示例13: async_raise

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def async_raise(target_tid, exception):
    """Raises an asynchronous exception in another thread.
    Read http://docs.python.org/c-api/init.html#PyThreadState_SetAsyncExc
    for further enlightenments.

    :param target_tid: target thread identifier
    :param exception: Exception class to be raised in that thread
    """
    # Ensuring and releasing GIL are useless since we're not in C
    # gil_state = ctypes.pythonapi.PyGILState_Ensure()
    ret = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(target_tid),
                                                     ctypes.py_object(exception))
    # ctypes.pythonapi.PyGILState_Release(gil_state)
    if ret == 0:
        raise ValueError("Invalid thread ID {}".format(target_tid))
    elif ret > 1:
        ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(target_tid), None)
        raise SystemError("PyThreadState_SetAsyncExc failed") 
开发者ID:glenfant,项目名称:stopit,代码行数:20,代码来源:threadstop.py

示例14: _async_raise

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def _async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""
    if not inspect.isclass(exctype):
        raise TypeError("Only types can be raised (not instances)")
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble, 
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
        raise SystemError("PyThreadState_SetAsyncExc failed") 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:14,代码来源:thread.py

示例15: _async_raise

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import py_object [as 别名]
def _async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""
    if not inspect.isclass(exctype):
        raise TypeError("Only types can be raised (not instances)")
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
        raise SystemError("PyThreadState_SetAsyncExc failed") 
开发者ID:fitoprincipe,项目名称:ipygee,代码行数:14,代码来源:threading.py


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