本文整理汇总了Python中ctypes.LibraryLoader方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.LibraryLoader方法的具体用法?Python ctypes.LibraryLoader怎么用?Python ctypes.LibraryLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.LibraryLoader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import LibraryLoader [as 别名]
def __init__(self, command, maximized=False, title=None):
"""Constructor.
:param iter command: Command to run.
:param bool maximized: Start process in new console window, maximized.
:param bytes title: Set new window title to this. Needed by user32.FindWindow.
"""
if title is None:
title = 'pytest-{0}-{1}'.format(os.getpid(), random.randint(1000, 9999)).encode('ascii')
self.startup_info = StartupInfo(maximize=maximized, title=title)
self.process_info = ProcessInfo()
self.command_str = subprocess.list2cmdline(command).encode('ascii')
self._handles = list()
self._kernel32 = ctypes.LibraryLoader(ctypes.WinDLL).kernel32
self._kernel32.GetExitCodeProcess.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ulong)]
self._kernel32.GetExitCodeProcess.restype = ctypes.c_long
示例2: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import LibraryLoader [as 别名]
def __init__(self, command, maximized=False, title=None, white_bg=False):
"""Constructor.
:param iter command: Command to run.
:param bool maximized: Start process in new console window, maximized.
:param bytes title: Set new window title to this. Needed by user32.FindWindow.
:param bool white_bg: New console window will be black text on white background.
"""
if title is None:
title = 'pytest-{0}-{1}'.format(os.getpid(), random.randint(1000, 9999)).encode('ascii')
self.startup_info = StartupInfo(maximize=maximized, title=title, white_bg=white_bg)
self.process_info = ProcessInfo()
self.command_str = subprocess.list2cmdline(command).encode('ascii')
self._handles = list()
self._kernel32 = ctypes.LibraryLoader(ctypes.WinDLL).kernel32
self._kernel32.GetExitCodeProcess.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ulong)]
self._kernel32.GetExitCodeProcess.restype = ctypes.c_long
示例3: init_kernel32
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import LibraryLoader [as 别名]
def init_kernel32(kernel32=None):
"""Load a unique instance of WinDLL into memory, set arg/return types, and get stdout/err handles.
1. Since we are setting DLL function argument types and return types, we need to maintain our own instance of
kernel32 to prevent overriding (or being overwritten by) user's own changes to ctypes.windll.kernel32.
2. While we're doing all this we might as well get the handles to STDOUT and STDERR streams.
3. If either stream has already been replaced set return value to INVALID_HANDLE_VALUE to indicate it shouldn't be
replaced.
:raise AttributeError: When called on a non-Windows platform.
:param kernel32: Optional mock kernel32 object. For testing.
:return: Loaded kernel32 instance, stderr handle (int), stdout handle (int).
:rtype: tuple
"""
if not kernel32:
kernel32 = ctypes.LibraryLoader(ctypes.WinDLL).kernel32 # Load our own instance. Unique memory address.
kernel32.GetStdHandle.argtypes = [ctypes.c_ulong]
kernel32.GetStdHandle.restype = ctypes.c_void_p
kernel32.GetConsoleScreenBufferInfo.argtypes = [
ctypes.c_void_p,
ctypes.POINTER(ConsoleScreenBufferInfo),
]
kernel32.GetConsoleScreenBufferInfo.restype = ctypes.c_long
# Get handles.
if hasattr(sys.stderr, '_original_stream'):
stderr = INVALID_HANDLE_VALUE
else:
stderr = kernel32.GetStdHandle(STD_ERROR_HANDLE)
if hasattr(sys.stdout, '_original_stream'):
stdout = INVALID_HANDLE_VALUE
else:
stdout = kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
return kernel32, stderr, stdout
示例4: test_init_kernel32_unique
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import LibraryLoader [as 别名]
def test_init_kernel32_unique():
"""Make sure function doesn't override other LibraryLoaders."""
k32_a = ctypes.LibraryLoader(ctypes.WinDLL).kernel32
k32_a.GetStdHandle.argtypes = [ctypes.c_void_p]
k32_a.GetStdHandle.restype = ctypes.c_ulong
k32_b, stderr_b, stdout_b = windows.init_kernel32()
k32_c = ctypes.LibraryLoader(ctypes.WinDLL).kernel32
k32_c.GetStdHandle.argtypes = [ctypes.c_long]
k32_c.GetStdHandle.restype = ctypes.c_short
k32_d, stderr_d, stdout_d = windows.init_kernel32()
# Verify external.
assert k32_a.GetStdHandle.argtypes == [ctypes.c_void_p]
assert k32_a.GetStdHandle.restype == ctypes.c_ulong
assert k32_c.GetStdHandle.argtypes == [ctypes.c_long]
assert k32_c.GetStdHandle.restype == ctypes.c_short
# Verify ours.
assert k32_b.GetStdHandle.argtypes == [ctypes.c_ulong]
assert k32_b.GetStdHandle.restype == ctypes.c_void_p
assert k32_d.GetStdHandle.argtypes == [ctypes.c_ulong]
assert k32_d.GetStdHandle.restype == ctypes.c_void_p
assert stderr_b == stderr_d
assert stdout_b == stdout_d