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


Python ctypes.FormatError方法代码示例

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


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

示例1: inet_pton

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def inet_pton(address_family, ip_string):
    addr = sockaddr()
    addr.sa_family = address_family
    addr_size = ctypes.c_int(ctypes.sizeof(addr))

    if WSAStringToAddressA(
            ip_string,
            address_family,
            None,
            ctypes.byref(addr),
            ctypes.byref(addr_size)
    ) != 0:
        raise socket.error(ctypes.FormatError())

    if address_family == socket.AF_INET:
        return ctypes.string_at(addr.ipv4_addr, 4)
    if address_family == socket.AF_INET6:
        return ctypes.string_at(addr.ipv6_addr, 16)

    raise socket.error('unknown address family') 
开发者ID:bakwc,项目名称:PySyncObj,代码行数:22,代码来源:win_inet_pton.py

示例2: pids

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def pids() -> Iterable[ProcessId]:
        _PROC_ID_T = DWORD
        list_size = 4096

        def try_get_pids(list_size: int) -> List[ProcessId]:
            result_size = DWORD()
            proc_id_list = (_PROC_ID_T * list_size)()

            if not windll.psapi.EnumProcesses(byref(proc_id_list), sizeof(proc_id_list), byref(result_size)):
                raise WinError(descr="Failed to get process ID list: %s" % FormatError())  # type: ignore

            return cast(List[ProcessId], proc_id_list[:int(result_size.value / sizeof(_PROC_ID_T()))])

        while True:
            proc_ids = try_get_pids(list_size)
            if len(proc_ids) < list_size:
                return proc_ids

            list_size *= 2 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:21,代码来源:proc_tools.py

示例3: _get_window_class

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def _get_window_class(hwnd):
  """Returns the class name of |hwnd|."""
  ctypes.windll.user32.GetClassNameW.restype = ctypes.c_int
  ctypes.windll.user32.GetClassNameW.argtypes = [
      ctypes.c_void_p,  # HWND
      ctypes.c_wchar_p,
      ctypes.c_int
  ]
  name = ctypes.create_unicode_buffer(257)
  name_len = ctypes.windll.user32.GetClassNameW(hwnd, name, len(name))
  if name_len <= 0 or name_len >= len(name):
    raise ctypes.WinError(descr='GetClassNameW failed; %s' %
                          ctypes.FormatError())
  return name.value


## Public API. 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:win.py

示例4: FormatError

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def FormatError(code):
        code = int(long(code))
        try:
            if GuessStringType.t_default == GuessStringType.t_ansi:
                FormatMessage = windll.kernel32.FormatMessageA
                FormatMessage.argtypes = [DWORD, LPVOID, DWORD, DWORD, LPSTR, DWORD]
                FormatMessage.restype  = DWORD
                lpBuffer = ctypes.create_string_buffer(1024)
            else:
                FormatMessage = windll.kernel32.FormatMessageW
                FormatMessage.argtypes = [DWORD, LPVOID, DWORD, DWORD, LPWSTR, DWORD]
                FormatMessage.restype  = DWORD
                lpBuffer = ctypes.create_unicode_buffer(1024)
            ##FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
            ##FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
            success = FormatMessage(0x1200, None, code, 0, lpBuffer, 1024)
            if success:
                return lpBuffer.value
        except Exception:
            pass
        if GuessStringType.t_default == GuessStringType.t_ansi:
            return "Error code 0x%.8X" % code
        return u"Error code 0x%.8X" % code 
开发者ID:debasishm89,项目名称:OpenXMolar,代码行数:25,代码来源:__init__.py

示例5: is_ipv6

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def is_ipv6(ip):
    try:
        if os.name == "nt":
            class sockaddr(ctypes.Structure):
                _fields_ = [("sa_family", ctypes.c_short),
                            ("__pad1", ctypes.c_ushort),
                            ("ipv4_addr", ctypes.c_byte * 4),
                            ("ipv6_addr", ctypes.c_byte * 16),
                            ("__pad2", ctypes.c_ulong)]

            WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
            addr = sockaddr()
            addr.sa_family = socket.AF_INET6
            addr_size = ctypes.c_int(ctypes.sizeof(addr))
            if WSAStringToAddressA(ip, socket.AF_INET6, None, ctypes.byref(addr), ctypes.byref(addr_size)) != 0:
                raise socket.error(ctypes.FormatError())
            return ctypes.string_at(addr.ipv6_addr, 16)
        else:
            return socket.inet_pton(socket.AF_INET6, ip)
    except:
        return False 
开发者ID:bwall,项目名称:ircsnapshot,代码行数:23,代码来源:ircsnapshot.py

示例6: StartYardServer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def StartYardServer(self):
        try:
            rkey = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Webers\\Y.A.R.D")
            path = RegQueryValueEx(rkey, "program")[0]
            if not os.path.exists(path):
                raise Exception
        except:
            raise self.Exception(
                "Please start Yards.exe first and configure it."
            )
        try:
            hProcess = CreateProcess(
                None,
                path,
                None,
                None,
                0,
                CREATE_NEW_CONSOLE,
                None,
                None,
                STARTUPINFO()
            )[0]
        except Exception, exc:
            raise eg.Exception(FormatError(exc[0])) 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:26,代码来源:__init__.py

示例7: _win_inet_pton

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def _win_inet_pton(address_family, ip_str):
        ip_str = safeencode(ip_str)
        addr = _sockaddr()
        addr.sa_family = address_family
        addr_size = ctypes.c_int(ctypes.sizeof(addr))

        if WSAStringToAddressA(
                ip_str,
                address_family,
                None,
                ctypes.byref(addr),
                ctypes.byref(addr_size)
        ) != 0:
            raise socket.error(ctypes.FormatError())

        if address_family == socket.AF_INET:
            return ctypes.string_at(addr.ipv4_addr, 4)
        if address_family == socket.AF_INET6:
            return ctypes.string_at(addr.ipv6_addr, 16)

        raise socket.error('unknown address family') 
开发者ID:flaggo,项目名称:pydu,代码行数:23,代码来源:network.py

示例8: _handle_errors

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def _handle_errors(rv, src):
        """Handle WinError. Internal use only"""
        if not rv:
            msg = ctypes.FormatError(ctypes.GetLastError())
            # if the MoveFileExW fails(e.g. fail to acquire file lock), removes the tempfile
            try:
                os.remove(src)
            except OSError:
                pass
            finally:
                raise OSError(msg) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:13,代码来源:utils.py

示例9: win_error

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def win_error(error, filename):
        exc = WindowsError(error, ctypes.FormatError(error))
        exc.filename = filename
        return exc 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:6,代码来源:scandir.py

示例10: get_error

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def get_error():
    error = ctypes.GetLastError()
    return (error, ctypes.FormatError(error)) 
开发者ID:wbond,项目名称:oscrypto,代码行数:5,代码来源:_crypt32_ctypes.py

示例11: get_exception_description

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def get_exception_description(self):
        """
        @rtype:  str
        @return: User-friendly name of the exception.
        """
        code = self.get_exception_code()
        description = self.__exceptionDescription.get(code, None)
        if description is None:
            try:
                description = 'Exception code %s (%s)'
                description = description % (HexDump.integer(code),
                                             ctypes.FormatError(code))
            except OverflowError:
                description = 'Exception code %s' % HexDump.integer(code)
        return description 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:17,代码来源:event.py

示例12: win_error

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def win_error(error, filename):
            exc = WindowsError(error, ctypes.FormatError(error))
            exc.filename = filename
            return exc 
开发者ID:pypa,项目名称:pipenv,代码行数:6,代码来源:scandir.py

示例13: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def __init__(self, msg="%r", error_code=None):
        if error_code is None:
            error_code = ctypes.GetLastError()
        description = ctypes.FormatError(error_code)
        try:
            formatted_msg = msg % description
        except TypeError:
            formatted_msg = msg
        super(WindowsCloudbaseInitException, self).__init__(formatted_msg) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:11,代码来源:exception.py

示例14: _lock_file

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def _lock_file(f, exclusive):
        overlapped = OVERLAPPED()
        overlapped.Offset = 0
        overlapped.OffsetHigh = 0
        overlapped.hEvent = 0
        f._lock_file_overlapped_p = ctypes.pointer(overlapped)
        handle = msvcrt.get_osfhandle(f.fileno())
        if not LockFileEx(handle, 0x2 if exclusive else 0x0, 0,
                          whole_low, whole_high, f._lock_file_overlapped_p):
            raise OSError('Locking file failed: %r' % ctypes.FormatError()) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:12,代码来源:utils.py

示例15: _unlock_file

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import FormatError [as 别名]
def _unlock_file(f):
        assert f._lock_file_overlapped_p
        handle = msvcrt.get_osfhandle(f.fileno())
        if not UnlockFileEx(handle, 0,
                            whole_low, whole_high, f._lock_file_overlapped_p):
            raise OSError('Unlocking file failed: %r' % ctypes.FormatError()) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:8,代码来源:utils.py


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