python类GetLastError()的实例源码

windows.py 文件源码 项目:My-Web-Server-Framework-With-Python2.7 作者: syjsu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:time2go 作者: twitchyliquid64 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
__init__.py 文件源码 项目:OpenXMolar 作者: debasishm89 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def WinError(code=None, descr=None):
        if code is None:
            code = ctypes.GetLastError()
        if descr is None:
            descr = ctypes.FormatError(code).strip()
        return WindowsError(code, descr)
windows.py 文件源码 项目:deprecated_thedap 作者: unitedvote 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
pipe_non_blocking.py 文件源码 项目:blender-addons 作者: scorpion81 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def pipe_non_blocking_is_error_blocking(ex):
        if not isinstance(ex, PortableBlockingIOError):
            return False
        from ctypes import GetLastError
        ERROR_NO_DATA = 232

        return (GetLastError() == ERROR_NO_DATA)
windows.py 文件源码 项目:get_started_with_respeaker 作者: respeaker 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:teleport 作者: eomsoft 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:projects-2017-2 作者: ncss 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
windows.py 文件源码 项目:PyQYT 作者: collinsctk 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set_close_exec(fd):
    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
    if not success:
        raise ctypes.GetLastError()
win32_utils.py 文件源码 项目:vim-clangd 作者: Chilledheart 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _bool_error_check(result, func, args):
    if not result:
        return GetLastError()
    return 0
cdefs.py 文件源码 项目:fibratus 作者: rabbitstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_last_error():
    return ctypes.GetLastError()
winamp.py 文件源码 项目:Packages 作者: Keypirinha 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, winerr=None):
            if not winerr:
                winerr = ctypes.GetLastError()
            super().__init__(0, ctypes.FormatError(winerr), None, winerr)
alttab.py 文件源码 项目:Packages 作者: Keypirinha 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_window_text(hwnd):
        """
        Wrapper over the GetWindowTextW() Win32 function
        Raises a OSError exception on error.
        """
        length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
        buff = ctypes.create_unicode_buffer(length + 1)
        ctypes.windll.kernel32.SetLastError(0)
        res = ctypes.windll.user32.GetWindowTextW(hwnd, buff, length + 1)
        if not res and ctypes.GetLastError() != 0:
            raise ctypes.WinError()
        return buff.value
funcs_win7.py 文件源码 项目:petronia 作者: groboclown 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def process__get_executable_filename(thread_pid):
    # This only finds processes, not services.

    GetProcessImageFileName = windll.kernel32.K32GetProcessImageFileNameW
    GetProcessImageFileName.restype = wintypes.DWORD
    OpenProcess = windll.kernel32.OpenProcess
    # OpenProcess.restype = wintypes.HANDLE

    hproc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, thread_pid)
    if hproc is None:
        raise WinError()
    try:
        filename = create_unicode_buffer(MAX_FILENAME_LENGTH + 1)

        # For some reason, this isn't found in Windows 10.
        res = GetProcessImageFileName(hproc, byref(filename), MAX_FILENAME_LENGTH + 1)
        if res <= 0:
            # raise ctypes.WinError()
            return None
        return str(filename.value[:res])
    finally:
        windll.kernel32.CloseHandle(hproc)


# def shell__open_start_menu():
#     # In Windows 7, the start button is part of the desktop?
#     desktop_hwnd = windll.user32.GetDesktopWindow()
#
#     # FIXME DEBUG
#     print("DEBUG desktop_hwnd: {0}".format(desktop_hwnd))
#
#     # Find the "start" button on the tray window
#     start_hwnd = windll.user32.FindWindowExW(desktop_hwnd, None, 'Button', 'Start')
#     if (start_hwnd is None or start_hwnd == 0) and GetLastError() != 0:
#         start_hwnd = windll.user32.FindWindowExW(desktop_hwnd, None, None, 'Start')
#         if (start_hwnd is None or start_hwnd == 0) and GetLastError() != 0:
#             # start_hwnd = windll.user32.FindWindowExW(desktop_hwnd, None, 'Button', None)
#             if start_hwnd is None or start_hwnd == 0:
#                 raise WinError()
#     print("Start button: {0}".format(start_hwnd))
#
#     # Send a click message to the button
#     res = windll.user32.SendMessageW(start_hwnd, BM_CLICK, 0, 0)
#     if res == 0:
#         raise WinError()
funcs_x86_win.py 文件源码 项目:petronia 作者: groboclown 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def window__set_style(hwnd, style_update):
    """
    Update a window's style.  "style_update" is a dictionary of style
    keys that map to either True or False, depending on how the style
    should be modified.  Style values not specified in the update
    will not be changed.

    :param hwnd:
    :param style_update:
    :return: the original style values (usable as input to this function).
    """
    assert isinstance(style_update, dict)

    SetWindowLongW = windll.user32.SetWindowLongW
    SetLastError = windll.kernel32.SetLastError

    original_style = window__get_style(hwnd)
    expected_style = dict(original_style)
    std_style_update = False
    std_bits = 0
    for k, mask in WS_STYLE_BIT_MAP.items():
        if k in style_update and original_style[k] != style_update[k]:
            std_style_update = True
            expected_style[k] = style_update[k]
            if style_update[k]:
                std_bits |= mask
        elif original_style[k]:
            std_bits |= mask
    if std_style_update:
        SetLastError(0)
        res = SetWindowLongW(hwnd, GWL_STYLE, std_bits)
        if res == 0 or GetLastError() != 0:
            raise WinError()

    ex_style_update = False
    ex_bits = 0
    for k, mask in WS_EX_STYLE_BIT_MAP.items():
        if k in style_update and original_style[k] != style_update[k]:
            ex_style_update = True
            expected_style[k] = style_update[k]
            if style_update[k]:
                ex_bits |= mask
        elif original_style[k]:
            ex_bits |= mask
    if ex_style_update:
        SetLastError(0)
        res = SetWindowLongW(hwnd, GWL_EXSTYLE, ex_bits)
        if res == 0 or GetLastError() != 0:
            raise WinError()

    # Sometimes, it only changed some of the values.
    # Double check.
    final_style = window__get_style(hwnd)
    if expected_style != final_style:
        # raise OSError("Did not fully set style to {0}; found {1}".format(
        #     expected_style, final_style))
        # print("Did not fully set style to {0}; found {1}".format(
        #      expected_style, final_style))
        pass

    return original_style
scandir.py 文件源码 项目:CrowdAnki 作者: Stvad 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _scandir_python(path=unicode('.')):
            """Like os.listdir(), but yield DirEntry objects instead of returning
            a list of names.
            """
            # Call FindFirstFile and handle errors
            if isinstance(path, bytes):
                is_bytes = True
                filename = join(path.decode('mbcs', 'strict'), '*.*')
            else:
                is_bytes = False
                filename = join(path, '*.*')
            data = wintypes.WIN32_FIND_DATAW()
            data_p = ctypes.byref(data)
            handle = FindFirstFile(filename, data_p)
            if handle == INVALID_HANDLE_VALUE:
                error = ctypes.GetLastError()
                if error == ERROR_FILE_NOT_FOUND:
                    # No files, don't yield anything
                    return
                raise win_error(error, path)

            # Call FindNextFile in a loop, stopping when no more files
            try:
                while True:
                    # Skip '.' and '..' (current and parent directory), but
                    # otherwise yield (filename, stat_result) tuple
                    name = data.cFileName
                    if name not in ('.', '..'):
                        if is_bytes:
                            name = name.encode('mbcs', 'replace')
                        yield Win32DirEntryPython(path, name, data)

                    data = wintypes.WIN32_FIND_DATAW()
                    data_p = ctypes.byref(data)
                    success = FindNextFile(handle, data_p)
                    if not success:
                        error = ctypes.GetLastError()
                        if error == ERROR_NO_MORE_FILES:
                            break
                        raise win_error(error, path)
            finally:
                if not FindClose(handle):
                    raise win_error(ctypes.GetLastError(), path)


问题


面经


文章

微信
公众号

扫码关注公众号