本文整理匯總了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')
示例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
示例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.
示例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
示例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
示例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]))
示例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')
示例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)
示例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
示例10: get_error
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import FormatError [as 別名]
def get_error():
error = ctypes.GetLastError()
return (error, ctypes.FormatError(error))
示例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
示例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
示例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)
示例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())
示例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())