diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-28 14:46:28 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-28 14:46:28 +0300 |
commit | 86568a9d1590ec529af95a7e16fb889b09162ed9 (patch) | |
tree | dbad39b76dcca72fd5551a0f782f6ad2a2bcd199 | |
parent | e6eedf7496d3741c2226a52ac25b12851b331112 (diff) | |
download | ydb-86568a9d1590ec529af95a7e16fb889b09162ed9.tar.gz |
intermediate changes
ref:8cc96053e249b790770c75de97ccbea86351cff2
18 files changed, 76 insertions, 56 deletions
diff --git a/contrib/python/prompt-toolkit/py3/.dist-info/METADATA b/contrib/python/prompt-toolkit/py3/.dist-info/METADATA index bc64b6812b..16bec365bb 100644 --- a/contrib/python/prompt-toolkit/py3/.dist-info/METADATA +++ b/contrib/python/prompt-toolkit/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: prompt-toolkit -Version: 3.0.29 +Version: 3.0.30 Summary: Library for building powerful interactive command lines in Python Home-page: https://github.com/prompt-toolkit/python-prompt-toolkit Author: Jonathan Slenders diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/__init__.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/__init__.py index 4b36db1a64..a66c10f3f5 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/__init__.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/__init__.py @@ -18,7 +18,7 @@ from .formatted_text import ANSI, HTML from .shortcuts import PromptSession, print_formatted_text, prompt # Don't forget to update in `docs/conf.py`! -__version__ = "3.0.29" +__version__ = "3.0.30" # Version tuple. VERSION = tuple(__version__.split(".")) diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/application/application.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/application/application.py index b00c2c2a73..5a09918da5 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/application/application.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/application/application.py @@ -22,6 +22,7 @@ from typing import ( Any, Awaitable, Callable, + Coroutine, Dict, FrozenSet, Generator, @@ -1017,7 +1018,7 @@ class Application(Generic[_AppResult]): CustomPdb(stdout=sys.__stdout__).set_trace(frame) def create_background_task( - self, coroutine: Awaitable[None] + self, coroutine: Coroutine[Any, Any, None] ) -> "asyncio.Task[None]": """ Start a background task (coroutine) for the running application. When @@ -1029,7 +1030,7 @@ class Application(Generic[_AppResult]): Not threadsafe. """ - task = get_event_loop().create_task(coroutine) + task: asyncio.Task[None] = get_event_loop().create_task(coroutine) self.background_tasks.append(task) return task diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py index ec2d3ba91c..6c006a258b 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py @@ -17,6 +17,7 @@ from typing import ( Any, Awaitable, Callable, + Coroutine, Deque, Iterable, List, @@ -1692,7 +1693,7 @@ class Buffer: ) ) - def _create_completer_coroutine(self) -> Callable[..., Awaitable[None]]: + def _create_completer_coroutine(self) -> Callable[..., Coroutine[Any, Any, None]]: """ Create function for asynchronous autocompletion. @@ -1822,7 +1823,7 @@ class Buffer: return async_completer - def _create_auto_suggest_coroutine(self) -> Callable[[], Awaitable[None]]: + def _create_auto_suggest_coroutine(self) -> Callable[[], Coroutine[Any, Any, None]]: """ Create function for asynchronous auto suggestion. (This can be in another thread.) @@ -1849,7 +1850,9 @@ class Buffer: return async_suggestor - def _create_auto_validate_coroutine(self) -> Callable[[], Awaitable[None]]: + def _create_auto_validate_coroutine( + self, + ) -> Callable[[], Coroutine[Any, Any, None]]: """ Create a function for asynchronous validation while typing. (This can be in another thread.) diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/ssh/server.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/ssh/server.py index 2b5935557d..98f3b68177 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/ssh/server.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/ssh/server.py @@ -85,9 +85,8 @@ class PromptToolkitSSHSession(asyncssh.SSHServerSession): # type: ignore term = self._chan.get_terminal_type() - self._output = Vt100_Output( - self.stdout, self._get_size, term=term, write_binary=False - ) + self._output = Vt100_Output(self.stdout, self._get_size, term=term) + with create_pipe_input() as self._input: with create_app_session(input=self._input, output=self._output) as session: self.app_session = session diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/telnet/server.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/telnet/server.py index 4dfeb7fe05..b6248cd3e5 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/telnet/server.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/contrib/telnet/server.py @@ -169,9 +169,7 @@ class TelnetConnection: def ttype_received(ttype: str) -> None: """TelnetProtocolParser 'ttype_received' callback""" - self.vt100_output = Vt100_Output( - self.stdout, get_size, term=ttype, write_binary=False - ) + self.vt100_output = Vt100_Output(self.stdout, get_size, term=ttype) self._ready.set() self.parser = TelnetProtocolParser(data_received, size_received, ttype_received) @@ -245,7 +243,7 @@ class TelnetConnection: # Make sure that when an application was active for this connection, # that we print the text above the application. if self.context: - self.context.run(run_in_terminal, func) + self.context.run(run_in_terminal, func) # type: ignore else: raise RuntimeError("Called _run_in_terminal outside `run_application`.") diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py index 2b20d69b42..3fcd260551 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py @@ -4,18 +4,25 @@ Dummy contextvars implementation, to make prompt_toolkit work on Python 3.6. As long as there is only one application running at a time, we don't need the real contextvars. So, stuff like the telnet-server and so on requires 3.7. """ -from typing import Any, Callable, Generic, Optional, TypeVar +from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar + +if TYPE_CHECKING: + from typing_extensions import ParamSpec def copy_context() -> "Context": return Context() +if TYPE_CHECKING: + _P = ParamSpec("_P") _T = TypeVar("_T") class Context: - def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: + def run( + self, callable: "Callable[_P, _T]", *args: "_P.args", **kwargs: "_P.kwargs" + ) -> _T: return callable(*args, **kwargs) def copy(self) -> "Context": diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/filters/app.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/filters/app.py index 767ec492d5..dcc3fc0c6e 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/filters/app.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/filters/app.py @@ -20,6 +20,7 @@ __all__ = [ "has_focus", "buffer_has_focus", "has_selection", + "has_suggestion", "has_validation_error", "is_done", "is_read_only", @@ -115,6 +116,15 @@ def has_selection() -> bool: @Condition +def has_suggestion() -> bool: + """ + Enable when the current buffer has a suggestion. + """ + buffer = get_app().current_buffer + return buffer.suggestion is not None and buffer.suggestion.text != "" + + +@Condition def has_completions() -> bool: """ Enable when the current buffer has completions. diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/menus.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/menus.py index 8218f74107..24d6e46af0 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/menus.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/menus.py @@ -7,6 +7,7 @@ from typing import ( Iterable, List, Optional, + Sequence, Tuple, TypeVar, Union, @@ -406,7 +407,7 @@ class MultiColumnCompletionMenuControl(UIControl): def grouper( n: int, iterable: Iterable[_T], fillvalue: Optional[_T] = None - ) -> Iterable[List[_T]]: + ) -> Iterable[Sequence[Optional[_T]]]: "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/screen.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/screen.py index 5d27ab26c9..8874fba6f8 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/screen.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/screen.py @@ -61,6 +61,7 @@ class Char: "\x1b": "^[", # Escape "\x1c": "^\\", "\x1d": "^]", + "\x1e": "^^", "\x1f": "^_", "\x7f": "^?", # ASCII Delete (backspace). # Special characters. All visualized like Vim does. diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/flush_stdout.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/flush_stdout.py index 05a342312d..805a81e010 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/flush_stdout.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/flush_stdout.py @@ -7,7 +7,15 @@ from typing import IO, Iterator, TextIO, cast __all__ = ["flush_stdout"] -def flush_stdout(stdout: TextIO, data: str, write_binary: bool) -> None: +def flush_stdout(stdout: TextIO, data: str) -> None: + # If the IO object has an `encoding` and `buffer` attribute, it means that + # we can access the underlying BinaryIO object and write into it in binary + # mode. This is preferred if possible. + # NOTE: When used in a Jupyter notebook, don't write binary. + # `ipykernel.iostream.OutStream` has an `encoding` attribute, but not + # a `buffer` attribute, so we can't write binary in it. + has_binary_io = hasattr(stdout, "encoding") and hasattr(stdout, "buffer") + try: # Ensure that `stdout` is made blocking when writing into it. # Otherwise, when uvloop is activated (which makes stdout @@ -20,14 +28,8 @@ def flush_stdout(stdout: TextIO, data: str, write_binary: bool) -> None: # My Arch Linux installation of july 2015 reported 'ANSI_X3.4-1968' # for sys.stdout.encoding in xterm. out: IO[bytes] - if write_binary: - if hasattr(stdout, "buffer"): - out = stdout.buffer - else: - # IO[bytes] was given to begin with. - # (Used in the unit tests, for instance.) - out = cast(IO[bytes], stdout) - out.write(data.encode(stdout.encoding or "utf-8", "replace")) + if has_binary_io: + stdout.buffer.write(data.encode(stdout.encoding or "utf-8", "replace")) else: stdout.write(data) diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/plain_text.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/plain_text.py index 23c1e9453f..4360355f4f 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/plain_text.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/plain_text.py @@ -23,14 +23,10 @@ class PlainTextOutput(Output): formatting.) """ - def __init__(self, stdout: TextIO, write_binary: bool = True) -> None: + def __init__(self, stdout: TextIO) -> None: assert all(hasattr(stdout, a) for a in ("write", "flush")) - if write_binary: - assert hasattr(stdout, "encoding") - self.stdout: TextIO = stdout - self.write_binary = write_binary self._buffer: List[str] = [] def fileno(self) -> int: @@ -58,7 +54,7 @@ class PlainTextOutput(Output): data = "".join(self._buffer) self._buffer = [] - flush_stdout(self.stdout, data, write_binary=self.write_binary) + flush_stdout(self.stdout, data) def erase_screen(self) -> None: pass diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/vt100.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/vt100.py index 0586267286..3a03de6fa5 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/vt100.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/output/vt100.py @@ -400,8 +400,6 @@ class Vt100_Output(Output): :param get_size: A callable which returns the `Size` of the output terminal. :param stdout: Any object with has a `write` and `flush` method + an 'encoding' property. :param term: The terminal environment variable. (xterm, xterm-256color, linux, ...) - :param write_binary: Encode the output before writing it. If `True` (the - default), the `stdout` object is supposed to expose an `encoding` attribute. """ # For the error messages. Only display "Output is not a terminal" once per @@ -413,19 +411,14 @@ class Vt100_Output(Output): stdout: TextIO, get_size: Callable[[], Size], term: Optional[str] = None, - write_binary: bool = True, default_color_depth: Optional[ColorDepth] = None, enable_bell: bool = True, ) -> None: assert all(hasattr(stdout, a) for a in ("write", "flush")) - if write_binary: - assert hasattr(stdout, "encoding") - self._buffer: List[str] = [] self.stdout: TextIO = stdout - self.write_binary = write_binary self.default_color_depth = default_color_depth self._get_size = get_size self.term = term @@ -699,7 +692,7 @@ class Vt100_Output(Output): data = "".join(self._buffer) self._buffer = [] - flush_stdout(self.stdout, data, write_binary=self.write_binary) + flush_stdout(self.stdout, data) def ask_for_cpr(self) -> None: """ diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/renderer.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/renderer.py index e40fc9e875..463555c9dd 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/renderer.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/renderer.py @@ -799,12 +799,16 @@ def print_formatted_text( output.reset_attributes() last_attrs = attrs - # Eliminate carriage returns - text = text.replace("\r", "") - - # Assume that the output is raw, and insert a carriage return before - # every newline. (Also important when the front-end is a telnet client.) - output.write(text.replace("\n", "\r\n")) + # Print escape sequences as raw output + if "[ZeroWidthEscape]" in style_str: + output.write_raw(text) + else: + # Eliminate carriage returns + text = text.replace("\r", "") + # Insert a carriage return before every newline (important when the + # front-end is a telnet client). + text = text.replace("\n", "\r\n") + output.write(text) # Reset again. output.reset_attributes() diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/shortcuts/dialogs.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/shortcuts/dialogs.py index 9140f86ab3..eacb05a00c 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/shortcuts/dialogs.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/shortcuts/dialogs.py @@ -109,6 +109,7 @@ def input_dialog( validator: Optional[Validator] = None, password: FilterOrBool = False, style: Optional[BaseStyle] = None, + default: str = "", ) -> Application[str]: """ Display a text input box. @@ -126,6 +127,7 @@ def input_dialog( cancel_button = Button(text=cancel_text, handler=_return_none) textfield = TextArea( + text=default, multiline=False, password=password, completer=completer, diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py index 885d23a889..bd2d332209 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py @@ -344,6 +344,9 @@ class Label: dont_extend_height: bool = True, dont_extend_width: bool = False, align: Union[WindowAlign, Callable[[], WindowAlign]] = WindowAlign.LEFT, + # There is no cursor navigation in a label, so it makes sense to always + # wrap lines by default. + wrap_lines: FilterOrBool = True, ) -> None: self.text = text @@ -370,6 +373,7 @@ class Label: dont_extend_height=dont_extend_height, dont_extend_width=dont_extend_width, align=align, + wrap_lines=wrap_lines, ) def __pt_container__(self) -> Container: @@ -888,7 +892,7 @@ class Checkbox(CheckboxList[str]): def __init__(self, text: AnyFormattedText = "", checked: bool = False) -> None: values = [("value", text)] - CheckboxList.__init__(self, values=values) + super().__init__(values=values) self.checked = checked @property diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/toolbars.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/toolbars.py index e464be04ac..402ecaa982 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/toolbars.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/toolbars.py @@ -152,7 +152,7 @@ class SystemToolbar: async def _accept_vi(event: E) -> None: "Run system command." event.app.vi_state.input_mode = InputMode.NAVIGATION - event.app.run_system_command( + await event.app.run_system_command( self.system_buffer.text, display_before_text=self._get_display_before_text(), ) diff --git a/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py b/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py index 0e8bdd80d3..6a344a732d 100644 --- a/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py +++ b/contrib/python/prompt-toolkit/py3/tests/test_print_formatted_text.py @@ -12,7 +12,6 @@ from prompt_toolkit.utils import is_windows class _Capture: "Emulate an stdout object." - encoding = "utf-8" def __init__(self): self._data = [] @@ -22,7 +21,7 @@ class _Capture: @property def data(self): - return b"".join(self._data) + return "".join(self._data) def flush(self): pass @@ -40,15 +39,15 @@ class _Capture: def test_print_formatted_text(): f = _Capture() pt_print([("", "hello"), ("", "world")], file=f) - assert b"hello" in f.data - assert b"world" in f.data + assert "hello" in f.data + assert "world" in f.data @pytest.mark.skipif(is_windows(), reason="Doesn't run on Windows yet.") def test_print_formatted_text_backslash_r(): f = _Capture() pt_print("hello\r\n", file=f) - assert b"hello" in f.data + assert "hello" in f.data @pytest.mark.skipif(is_windows(), reason="Doesn't run on Windows yet.") @@ -70,8 +69,8 @@ def test_formatted_text_with_style(): # NOTE: We pass the default (8bit) color depth, so that the unit tests # don't start failing when environment variables change. pt_print(tokens, style=style, file=f, color_depth=ColorDepth.DEFAULT) - assert b"\x1b[0;38;5;197mHello" in f.data - assert b"\x1b[0;38;5;83;3mworld" in f.data + assert "\x1b[0;38;5;197mHello" in f.data + assert "\x1b[0;38;5;83;3mworld" in f.data @pytest.mark.skipif(is_windows(), reason="Doesn't run on Windows yet.") @@ -87,5 +86,5 @@ def test_html_with_style(): assert ( f.data - == b"\x1b[0m\x1b[?7h\x1b[0;32mhello\x1b[0m \x1b[0;1mworld\x1b[0m\r\n\x1b[0m" + == "\x1b[0m\x1b[?7h\x1b[0;32mhello\x1b[0m \x1b[0;1mworld\x1b[0m\r\n\x1b[0m" ) |