本文整理汇总了Python中pywincffi.core.checks.input_check函数的典型用法代码示例。如果您正苦于以下问题:Python input_check函数的具体用法?Python input_check怎么用?Python input_check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了input_check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetStdHandle
def GetStdHandle(nStdHandle):
"""
Retrieves a handle to the specified standard
device (standard input, standard output, or standard error).
.. seealso::
https://msdn.microsoft.com/en-us/library/ms683231
:param int nStdHandle:
The standard device to retrieve.
:rtype: pywincffi.wintypes.HANDLE
:return:
Returns a handle to the standard device retrieved.
"""
_, library = dist.load()
input_check("nStdHandle", nStdHandle,
allowed_values=(library.STD_INPUT_HANDLE,
library.STD_OUTPUT_HANDLE,
library.STD_ERROR_HANDLE))
handle = library.GetStdHandle(nStdHandle)
if handle == library.INVALID_HANDLE_VALUE: # pragma: no cover
raise WindowsAPIError(
"GetStdHandle", "Invalid Handle", library.INVALID_HANDLE_VALUE,
expected_return_code="not %r" % library.INVALID_HANDLE_VALUE)
return HANDLE(handle)
示例2: WaitForSingleObject
def WaitForSingleObject(hHandle, dwMilliseconds):
"""
Waits for the specified object to be in a signaled state
or for ``dwMiliseconds`` to elapse.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms687032
:param pywincffi.wintypes.HANDLE hHandle:
The handle to wait on.
:param int dwMilliseconds:
The time-out interval.
"""
input_check("hHandle", hHandle, HANDLE)
input_check("dwMilliseconds", dwMilliseconds, integer_types)
ffi, library = dist.load()
result = library.WaitForSingleObject(
wintype_to_cdata(hHandle), ffi.cast("DWORD", dwMilliseconds)
)
if result == library.WAIT_FAILED:
raise WindowsAPIError(
"WaitForSingleObject", "Wait Failed", ffi.getwinerror()[-1],
return_code=result, expected_return_code="not %s" % result)
error_check("WaitForSingleObject")
return result
示例3: SetConsoleTextAttribute
def SetConsoleTextAttribute(hConsoleOutput, wAttributes):
"""
Sets the attributes of characters written to a console buffer.
.. seealso::
https://docs.microsoft.com/en-us/windows/console/setconsoletextattribute
:param pywincffi.wintypes.HANDLE hConsoleOutput:
A handle to the console screen buffer. The handle must have the
``GENERIC_READ`` access right.
:param int wAttributes:
The character attribute(s) to set.
"""
input_check("hConsoleOutput", hConsoleOutput, HANDLE)
input_check("wAttributes", wAttributes, integer_types)
ffi, library = dist.load()
# raise Exception(type(wAttributes))
# info = ffi.new("PCHAR_INFO")
code = library.SetConsoleTextAttribute(
wintype_to_cdata(hConsoleOutput),
ffi.cast("ATOM", wAttributes)
)
error_check("SetConsoleTextAttribute", code=code, expected=NON_ZERO)
示例4: ClearCommError
def ClearCommError(hFile):
"""
Retrieves information about a communications error and reports the
current status of a communications device.
.. seealso::
https://msdn.microsoft.com/en-us/aa363180
:param pywincffi.wintypes.HANDLE hFile:
A handle to the communications device, typically created by
:func:`CreateFile`
:rtype: tuple
:return:
Returns a two element tuple containing the ``lpErrors`` and
``lpStat`` result objects.
* ``lpErrors`` - Contains the mast indicating the type of error
* ``lpStat`` - A ``COMSTAT`` structure which contains the device's
information.
"""
input_check("hFile", hFile, HANDLE)
ffi, library = dist.load()
lpErrors = ffi.new("LPDWORD")
lpStat = ffi.new("LPCOMSTAT")
code = library.ClearCommError(wintype_to_cdata(hFile), lpErrors, lpStat)
error_check("ClearCommError", code=code, expected=Enums.NON_ZERO)
# TODO: Build Python instance of COMSTAT here!
return lpErrors, lpStat
示例5: GetExitCodeProcess
def GetExitCodeProcess(hProcess):
"""
Retrieves the exit code of the given process handle. To retrieve
a process handle use :func:`OpenProcess`.
.. warning::
You may want to use :func:`process_exit_code` instead of this
function if you're just checking to see if a process has
exited at all.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms683189
:param pywincffi.wintypes.HANDLE hProcess:
The handle of the process to retrieve the exit code for.
:returns:
Returns the exit code of the requested process if one
can be found.
"""
input_check("hProcess", hProcess, HANDLE)
ffi, library = dist.load()
lpExitCode = ffi.new("LPDWORD")
code = library.GetExitCodeProcess(wintype_to_cdata(hProcess), lpExitCode)
error_check("GetExitCodeProcess", code=code, expected=Enums.NON_ZERO)
return lpExitCode[0]
示例6: LockFileEx
def LockFileEx(
hFile, dwFlags, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh,
lpOverlapped=None):
"""
Locks ``hFile`` for exclusive access by the calling process.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa365203
:param pywincffi.wintypes.HANDLE hFile:
The handle to the file to lock. This handle must have been
created with either the ``GENERIC_READ`` or ``GENERIC_WRITE``
right.
:param int dwFlags:
One or more of the following flags:
* ``LOCKFILE_EXCLUSIVE_LOCK`` - Request an exclusive lock.
* ``LOCKFILE_FAIL_IMMEDIATELY`` - Return immediately if the lock
could not be acquired. Otherwise :func:`LockFileEx` will wait.
:param int nNumberOfBytesToLockLow:
The start of the byte range to lock.
:param int nNumberOfBytesToLockHigh:
The end of the byte range to lock.
:keyword pywincffi.wintypes.OVERLAPPED lpOverlapped:
The underlying Windows API requires lpOverlapped, which acts both
an input argument and may contain results after calling. If None is
provided, a throw-away zero-filled instance will be created to
support such call. See Microsoft's documentation for intended usage.
"""
input_check("hFile", hFile, HANDLE)
input_check("dwFlags", dwFlags, integer_types)
input_check(
"nNumberOfBytesToLockLow", nNumberOfBytesToLockLow, integer_types)
input_check(
"nNumberOfBytesToLockHigh", nNumberOfBytesToLockHigh, integer_types)
ffi, library = dist.load()
if lpOverlapped is None:
# Required by Windows API, create a throw-away zero-filled instance.
lpOverlapped = OVERLAPPED()
else:
input_check("lpOverlapped", lpOverlapped, allowed_types=OVERLAPPED)
code = library.LockFileEx(
wintype_to_cdata(hFile),
ffi.cast("DWORD", dwFlags),
ffi.cast("DWORD", 0), # "_Reserveved_"
ffi.cast("DWORD", nNumberOfBytesToLockLow),
ffi.cast("DWORD", nNumberOfBytesToLockHigh),
wintype_to_cdata(lpOverlapped)
)
error_check("LockFileEx", code=code, expected=NON_ZERO)
示例7: CreateEvent
def CreateEvent(
bManualReset, bInitialState, lpEventAttributes=None, lpName=None):
"""
Creates or opens an named or unnamed event object.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms682396
:param bool bManualReset:
If True then this function will create a manual reset
event which must be manually reset with :func:`ResetEvent`. Refer
to the msdn documentation for full information.
:param bool bInitialState:
If True the initial state will be 'signaled'.
:keyword :class:`pywincffi.wintypes.SECURITY_ATTRIBUTES` lpEventAttributes:
If not provided then, by default, the handle cannot be inherited
by a subprocess.
:keyword str lpName:
Type is ``unicode`` on Python 2, ``str`` on Python 3.
The optional case-sensitive name of the event. If not provided then
the event will be created without an explicit name.
:returns:
Returns a :class:`pywincffi.wintypes.HANDLE` to the event. If an event
by the given name already exists then it will be returned instead of
creating a new event.
"""
input_check("bManualReset", bManualReset, bool)
input_check("bInitialState", bInitialState, bool)
ffi, library = dist.load()
if lpName is None:
lpName = ffi.NULL
else:
input_check("lpName", lpName, text_type)
input_check(
"lpEventAttributes", lpEventAttributes,
allowed_types=(SECURITY_ATTRIBUTES, NoneType)
)
handle = library.CreateEvent(
wintype_to_cdata(lpEventAttributes),
ffi.cast("BOOL", bManualReset),
ffi.cast("BOOL", bInitialState),
lpName
)
try:
error_check("CreateEvent")
except WindowsAPIError as error:
if error.errno != library.ERROR_ALREADY_EXISTS:
raise
return HANDLE(handle)
示例8: WriteFile
def WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite=None, lpOverlapped=None):
"""
Writes data to ``hFile`` which may be an I/O device for file.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa365747
:param pywincffi.wintypes.HANDLE hFile:
The handle to write to.
:type lpBuffer: str/bytes
:param lpBuffer:
Type is ``str`` on Python 2, ``bytes`` on Python 3.
The data to be written to the file or device.
:keyword int nNumberOfBytesToWrite:
The number of bytes to be written. Defaults to len(lpBuffer).
:keyword pywincffi.wintypes.OVERLAPPED lpOverlapped:
See Microsoft's documentation for intended usage and below for
an example.
>>> from pywincffi.core import dist
>>> from pywincffi.kernel32 import WriteFile, CreateEvent
>>> from pywincffi.wintypes import OVERLAPPED
>>> hEvent = CreateEvent(...)
>>> lpOverlapped = OVERLAPPED()
>>> lpOverlapped.hEvent = hEvent
>>> bytes_written = WriteFile(
... hFile, "Hello world", lpOverlapped=lpOverlapped)
:returns:
Returns the number of bytes written.
"""
ffi, library = dist.load()
input_check("hFile", hFile, HANDLE)
input_check("lpBuffer", lpBuffer, binary_type)
input_check(
"lpOverlapped", lpOverlapped,
allowed_types=(NoneType, OVERLAPPED)
)
if nNumberOfBytesToWrite is None:
nNumberOfBytesToWrite = len(lpBuffer)
else:
input_check(
"nNumberOfBytesToWrite", nNumberOfBytesToWrite,
integer_types
)
bytes_written = ffi.new("LPDWORD")
code = library.WriteFile(
wintype_to_cdata(hFile), lpBuffer, nNumberOfBytesToWrite,
bytes_written, wintype_to_cdata(lpOverlapped)
)
error_check("WriteFile", code=code, expected=Enums.NON_ZERO)
return bytes_written[0]
示例9: FlushFileBuffers
def FlushFileBuffers(hFile):
"""
Flushes the buffer of the specified file to disk.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa364439
:param pywincffi.wintypes.HANDLE hFile:
The handle to flush to disk.
"""
input_check("hFile", hFile, HANDLE)
_, library = dist.load()
code = library.FlushFileBuffers(wintype_to_cdata(hFile))
error_check("FlushFileBuffers", code=code, expected=NON_ZERO)
示例10: CreatePipe
def CreatePipe(nSize=0, lpPipeAttributes=None):
"""
Creates an anonymous pipe and returns the read and write handles.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa365152
https://msdn.microsoft.com/en-us/library/aa379560
>>> from pywincffi.core import dist
>>> from pywincffi.kernel32 import CreatePipe
>>> from pywincffi.wintypes import SECURITY_ATTRIBUTES
>>> lpPipeAttributes = SECURITY_ATTRIBUTES()
>>> lpPipeAttributes.bInheritHandle = True
>>> reader, writer = CreatePipe(lpPipeAttributes=lpPipeAttributes)
:keyword int nSize:
The size of the buffer in bytes. Passing in 0, which is the default
will cause the system to use the default buffer size.
:keyword pywincffi.wintypes.SECURITY_ATTRIBUTES lpPipeAttributes:
The security attributes to apply to the handle. By default
``NULL`` will be passed in, meaning the handle we create
cannot be inherited. For more detailed information see the links
below.
:return:
Returns a tuple of :class:`pywincffi.wintype.HANDLE` containing the
reader and writer ends of the pipe that was created. The user of this
function is responsible for calling CloseHandle at some point.
"""
input_check("nSize", nSize, integer_types)
input_check(
"lpPipeAttributes", lpPipeAttributes,
allowed_types=(NoneType, SECURITY_ATTRIBUTES)
)
lpPipeAttributes = wintype_to_cdata(lpPipeAttributes)
ffi, library = dist.load()
hReadPipe = ffi.new("PHANDLE")
hWritePipe = ffi.new("PHANDLE")
code = library.CreatePipe(hReadPipe, hWritePipe, lpPipeAttributes, nSize)
error_check("CreatePipe", code=code, expected=Enums.NON_ZERO)
return HANDLE(hReadPipe[0]), HANDLE(hWritePipe[0])
示例11: CloseHandle
def CloseHandle(hObject):
"""
Closes an open object handle.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms724211
:type hObject: pywincffi.wintypes.HANDLE or pywincffi.wintypes.SOCKET
:param hObject:
The handle object to close.
"""
input_check("hObject", hObject, (HANDLE, SOCKET))
_, library = dist.load()
code = library.CloseHandle(wintype_to_cdata(hObject))
error_check("CloseHandle", code=code, expected=Enums.NON_ZERO)
示例12: ResetEvent
def ResetEvent(hEvent):
"""
Sets the specified event object to the nonsignaled state.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms684305
:param pywincffi.wintypes.HANDLE hEvent:
A handle to the event object to be reset. The handle must
have the ``EVENT_MODIFY_STATE`` access right.
"""
input_check("hEvent", hEvent, HANDLE)
_, library = dist.load()
code = library.ResetEvent(wintype_to_cdata(hEvent))
error_check("ResetEvent", code=code, expected=Enums.NON_ZERO)
示例13: PeekNamedPipe
def PeekNamedPipe(hNamedPipe, nBufferSize):
"""
Copies data from a pipe into a buffer without removing it
from the pipe.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa365779
:param pywincffi.wintypes.HANDLE hNamedPipe:
The handele to the pipe object we want to peek into.
:param int nBufferSize:
The number of bytes to 'peek' into the pipe.
:rtype: PeekNamedPipeResult
:return:
Returns an instance of :class:`PeekNamedPipeResult` which
contains the buffer read, number of bytes read and the result.
"""
input_check("hNamedPipe", hNamedPipe, HANDLE)
input_check("nBufferSize", nBufferSize, integer_types)
ffi, library = dist.load()
# Outputs
lpBuffer = ffi.new("LPVOID[%d]" % nBufferSize)
lpBytesRead = ffi.new("LPDWORD")
lpTotalBytesAvail = ffi.new("LPDWORD")
lpBytesLeftThisMessage = ffi.new("LPDWORD")
code = library.PeekNamedPipe(
wintype_to_cdata(hNamedPipe),
lpBuffer,
nBufferSize,
lpBytesRead,
lpTotalBytesAvail,
lpBytesLeftThisMessage
)
error_check("PeekNamedPipe", code=code, expected=Enums.NON_ZERO)
return PeekNamedPipeResult(
lpBuffer=lpBuffer,
lpBytesRead=lpBytesRead[0],
lpTotalBytesAvail=lpTotalBytesAvail[0],
lpBytesLeftThisMessage=lpBytesLeftThisMessage[0]
)
示例14: GetProcessId
def GetProcessId(Process): # pylint: disable=invalid-name
"""
Returns the pid of the process handle provided in ``Process``.
.. seealso::
https://msdn.microsoft.com/en-us/library/ms683215
:param pywincffi.wintypes.HANDLE Process:
The handle of the process.
:return:
Returns an integer which represents the pid of the given
process handle.
"""
input_check("Process", Process, HANDLE)
_, library = dist.load()
pid = library.GetProcessId(wintype_to_cdata(Process))
error_check("GetProcessId")
return pid
示例15: UnlockFileEx
def UnlockFileEx(
hFile, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh,
lpOverlapped=None):
"""
Unlocks a region in the specified file.
.. seealso::
https://msdn.microsoft.com/en-us/library/aa365716
:param pywincffi.wintypes.HANDLE hFile:
The handle to the file to unlock. This handle must have been
created with either the ``GENERIC_READ`` or ``GENERIC_WRITE``
right.
:param int nNumberOfBytesToUnlockLow:
The start of the byte range to unlock.
:param int nNumberOfBytesToUnlockHigh:
The end of the byte range to unlock.
:keyword pywincffi.wintypes.OVERLAPPED lpOverlapped:
The underlying Windows API requires lpOverlapped, which acts both
an input argument and may contain results after calling. If None is
provided, a throw-away zero-filled instance will be created to
support such call. See Microsoft's documentation for intended usage.
"""
input_check("hFile", hFile, HANDLE)
input_check(
"nNumberOfBytesToUnlockLow",
nNumberOfBytesToUnlockLow, integer_types)
input_check(
"nNumberOfBytesToUnlockHigh",
nNumberOfBytesToUnlockHigh, integer_types)
ffi, library = dist.load()
if lpOverlapped is None:
# Required by Windows API, create a throw-away zero-filled instance.
lpOverlapped = OVERLAPPED()
else:
input_check("lpOverlapped", lpOverlapped, allowed_types=OVERLAPPED)
code = library.UnlockFileEx(
wintype_to_cdata(hFile),
ffi.cast("DWORD", 0), # "_Reserveved_"
ffi.cast("DWORD", nNumberOfBytesToUnlockLow),
ffi.cast("DWORD", nNumberOfBytesToUnlockHigh),
wintype_to_cdata(lpOverlapped)
)
error_check("UnlockFileEx", code=code, expected=NON_ZERO)