當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。