Skip to content

Commit 4b4c6c5

Browse files
committed
Check error when calling SetConsoleMode and GetConsoleMode
1 parent f352fdd commit 4b4c6c5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Lib/_pyrepl/windows_console.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ def __init__(
146146

147147
# Save original console modes so we can recover on cleanup.
148148
original_input_mode = DWORD()
149-
GetConsoleMode(InHandle, original_input_mode)
149+
if not GetConsoleMode(InHandle, original_input_mode):
150+
raise WinError(get_last_error())
150151
trace(f'saved original input mode 0x{original_input_mode.value:x}')
151152
self.__original_input_mode = original_input_mode.value
152153

153-
SetConsoleMode(
154+
if not SetConsoleMode(
154155
OutHandle,
155156
ENABLE_WRAP_AT_EOL_OUTPUT
156157
| ENABLE_PROCESSED_OUTPUT
157158
| ENABLE_VIRTUAL_TERMINAL_PROCESSING,
158-
)
159+
):
160+
raise WinError(get_last_error())
159161

160162
self.screen: list[str] = []
161163
self.width = 80
@@ -347,14 +349,16 @@ def prepare(self) -> None:
347349
self.__offset = 0
348350

349351
if self.__vt_support:
350-
SetConsoleMode(InHandle, self.__original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT)
352+
if not SetConsoleMode(InHandle, self.__original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT):
353+
raise WinError(get_last_error())
351354
self._enable_bracketed_paste()
352355

353356
def restore(self) -> None:
354357
if self.__vt_support:
355358
# Recover to original mode before running REPL
356359
self._disable_bracketed_paste()
357-
SetConsoleMode(InHandle, self.__original_input_mode)
360+
if not SetConsoleMode(InHandle, self.__original_input_mode):
361+
raise WinError(get_last_error())
358362

359363
def _move_relative(self, x: int, y: int) -> None:
360364
"""Moves relative to the current posxy"""

0 commit comments

Comments
 (0)