Get rid of FILE_TYPE_REMOTE

This commit is contained in:
Jean-Paul Calderone 2021-01-11 13:56:42 -05:00
parent ad48e6c005
commit 9d7b12292c
1 changed files with 10 additions and 9 deletions

View File

@ -30,9 +30,6 @@ from win32file import (
GetFileType, GetFileType,
) )
# This one not exposed by pywin32 as far as I can tell.
FILE_TYPE_REMOTE = 0x8000
# <https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401%28v=vs.85%29.aspx> # <https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401%28v=vs.85%29.aspx>
# BOOL WINAPI WriteConsoleW(HANDLE hOutput, LPWSTR lpBuffer, DWORD nChars, # BOOL WINAPI WriteConsoleW(HANDLE hOutput, LPWSTR lpBuffer, DWORD nChars,
# LPDWORD lpCharsWritten, LPVOID lpReserved); # LPDWORD lpCharsWritten, LPVOID lpReserved);
@ -126,11 +123,15 @@ def initialize():
use_last_error=True use_last_error=True
)(("GetConsoleMode", windll.kernel32)) )(("GetConsoleMode", windll.kernel32))
def not_a_console(handle): def a_console(handle):
if handle == INVALID_HANDLE_VALUE: if handle == INVALID_HANDLE_VALUE:
return True return False
return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR return (
or GetConsoleMode(handle, byref(DWORD())) == 0) # It's a character file (eg a printer or a console)
GetFileType(handle) == FILE_TYPE_CHAR and
# Checking the console mode doesn't fail (thus it's a console)
GetConsoleMode(handle, byref(DWORD())) != 0
)
old_stdout_fileno = None old_stdout_fileno = None
old_stderr_fileno = None old_stderr_fileno = None
@ -144,12 +145,12 @@ def initialize():
if real_stdout: if real_stdout:
hStdout = GetStdHandle(STD_OUTPUT_HANDLE) hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
if not_a_console(hStdout): if not a_console(hStdout):
real_stdout = False real_stdout = False
if real_stderr: if real_stderr:
hStderr = GetStdHandle(STD_ERROR_HANDLE) hStderr = GetStdHandle(STD_ERROR_HANDLE)
if not_a_console(hStderr): if not a_console(hStderr):
real_stderr = False real_stderr = False
if real_stdout: if real_stdout: