aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-04-06 18:18:01 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-04-06 18:18:01 +0300
commit01fbacb386809436dfa331780875aed72cb76118 (patch)
tree04c911ad96ff0523bd4d3e7a45c23cf2f2d7607d /contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py
parent48fb997d7f820a474b9094a72d9798a95ec612b7 (diff)
downloadydb-01fbacb386809436dfa331780875aed72cb76118.tar.gz
intermediate changes
ref:b4f892f3c2b06a356c155f73c27efc5661a7fb89
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py')
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py
index fdbcb8ee83..ebee2075ed 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/input/win32_pipe.py
@@ -1,6 +1,11 @@
+import sys
+
+assert sys.platform == "win32"
+
+from contextlib import contextmanager
from ctypes import windll
from ctypes.wintypes import HANDLE
-from typing import Callable, ContextManager, List
+from typing import Callable, ContextManager, Iterator, List
from prompt_toolkit.eventloop.win32 import create_win32_event
@@ -31,7 +36,7 @@ class Win32PipeInput(_Win32InputBase, PipeInput):
_id = 0
- def __init__(self) -> None:
+ def __init__(self, _event: HANDLE) -> None:
super().__init__()
# Event (handle) for registering this input in the event loop.
# This event is set when there is data available to read from the pipe.
@@ -50,6 +55,15 @@ class Win32PipeInput(_Win32InputBase, PipeInput):
self.__class__._id += 1
self._id = self.__class__._id
+ @classmethod
+ @contextmanager
+ def create(cls) -> Iterator["Win32PipeInput"]:
+ event = create_win32_event()
+ try:
+ yield Win32PipeInput(_event=event)
+ finally:
+ windll.kernel32.CloseHandle(event)
+
@property
def closed(self) -> bool:
return self._closed
@@ -87,7 +101,9 @@ class Win32PipeInput(_Win32InputBase, PipeInput):
self._buffer = []
# Reset event.
- windll.kernel32.ResetEvent(self._event)
+ if not self._closed:
+ # (If closed, the event should not reset.)
+ windll.kernel32.ResetEvent(self._event)
return result
@@ -111,6 +127,9 @@ class Win32PipeInput(_Win32InputBase, PipeInput):
def send_text(self, text: str) -> None:
"Send text to the input."
+ if self._closed:
+ raise ValueError("Attempt to write into a closed pipe.")
+
# Pass it through our vt100 parser.
self.vt100_parser.feed(text)
@@ -124,9 +143,9 @@ class Win32PipeInput(_Win32InputBase, PipeInput):
return DummyContext()
def close(self) -> None:
- "Close pipe handles."
- windll.kernel32.CloseHandle(self._event)
+ "Close write-end of the pipe."
self._closed = True
+ windll.kernel32.SetEvent(self._event)
def typeahead_hash(self) -> str:
"""