diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-26 16:31:31 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-26 16:31:31 +0200 |
commit | df608fa858819f84924451b6a97559671303e8b0 (patch) | |
tree | 931f0ae1302ff7d45e41a1aa4b6dbc96be174744 /QMTest/TestCmd.py | |
parent | 9d8eae9f5bf53a4a80e29d7a3a1d2c7d7197688a (diff) | |
parent | 78989ebb445af2c6462ae2bf05ffd588d76610e4 (diff) |
Merge tag 'upstream/2.3.2'
Upstream version 2.3.2
Diffstat (limited to 'QMTest/TestCmd.py')
-rw-r--r-- | QMTest/TestCmd.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 38e9cd3..b51d90f 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -672,8 +672,35 @@ except AttributeError: PIPE = subprocess.PIPE if subprocess.mswindows: - from win32file import ReadFile, WriteFile - from win32pipe import PeekNamedPipe + try: + from win32file import ReadFile, WriteFile + from win32pipe import PeekNamedPipe + except ImportError: + # If PyWin32 is not available, try ctypes instead + # XXX These replicate _just_enough_ PyWin32 behaviour for our purposes + import ctypes; from ctypes.wintypes import DWORD + def ReadFile(hFile, bufSize, ol=None): + assert ol is None + lpBuffer = ctypes.create_string_buffer(bufSize) + bytesRead = DWORD() + bErr = ctypes.windll.kernel32.ReadFile( + hFile, lpBuffer, bufSize, ctypes.byref(bytesRead), ol) + if not bErr: raise ctypes.WinError() + return (0, ctypes.string_at(lpBuffer, bytesRead.value)) + def WriteFile(hFile, data, ol=None): + assert ol is None + bytesWritten = DWORD() + bErr = ctypes.windll.kernel32.WriteFile( + hFile, data, len(data), ctypes.byref(bytesWritten), ol) + if not bErr: raise ctypes.WinError() + return (0, bytesWritten.value) + def PeekNamedPipe(hPipe, size): + assert size == 0 + bytesAvail = DWORD() + bErr = ctypes.windll.kernel32.PeekNamedPipe( + hPipe, None, size, None, ctypes.byref(bytesAvail), None) + if not bErr: raise ctypes.WinError() + return ("", bytesAvail.value, None) import msvcrt else: import select |