Просмотр исходного кода

Update contrib/python/prompt-toolkit/py3 to 3.0.41

robot-contrib 1 год назад
Родитель
Сommit
708e84a134

+ 3 - 1
contrib/python/prompt-toolkit/py3/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Metadata-Version: 2.1
 Name: prompt-toolkit
 Name: prompt-toolkit
-Version: 3.0.39
+Version: 3.0.41
 Summary: Library for building powerful interactive command lines in Python
 Summary: Library for building powerful interactive command lines in Python
 Home-page: https://github.com/prompt-toolkit/python-prompt-toolkit
 Home-page: https://github.com/prompt-toolkit/python-prompt-toolkit
 Author: Jonathan Slenders
 Author: Jonathan Slenders
@@ -13,6 +13,8 @@ Classifier: Programming Language :: Python :: 3.7
 Classifier: Programming Language :: Python :: 3.8
 Classifier: Programming Language :: Python :: 3.8
 Classifier: Programming Language :: Python :: 3.9
 Classifier: Programming Language :: Python :: 3.9
 Classifier: Programming Language :: Python :: 3.10
 Classifier: Programming Language :: Python :: 3.10
+Classifier: Programming Language :: Python :: 3.11
+Classifier: Programming Language :: Python :: 3.12
 Classifier: Programming Language :: Python :: 3 :: Only
 Classifier: Programming Language :: Python :: 3 :: Only
 Classifier: Programming Language :: Python
 Classifier: Programming Language :: Python
 Classifier: Topic :: Software Development
 Classifier: Topic :: Software Development

+ 1 - 1
contrib/python/prompt-toolkit/py3/prompt_toolkit/__init__.py

@@ -27,7 +27,7 @@ from .formatted_text import ANSI, HTML
 from .shortcuts import PromptSession, print_formatted_text, prompt
 from .shortcuts import PromptSession, print_formatted_text, prompt
 
 
 # Don't forget to update in `docs/conf.py`!
 # Don't forget to update in `docs/conf.py`!
-__version__ = "3.0.39"
+__version__ = "3.0.41"
 
 
 assert pep440.match(__version__)
 assert pep440.match(__version__)
 
 

+ 45 - 14
contrib/python/prompt-toolkit/py3/prompt_toolkit/application/application.py

@@ -40,7 +40,9 @@ from prompt_toolkit.cursor_shapes import AnyCursorShapeConfig, to_cursor_shape_c
 from prompt_toolkit.data_structures import Size
 from prompt_toolkit.data_structures import Size
 from prompt_toolkit.enums import EditingMode
 from prompt_toolkit.enums import EditingMode
 from prompt_toolkit.eventloop import (
 from prompt_toolkit.eventloop import (
+    InputHook,
     get_traceback_from_context,
     get_traceback_from_context,
+    new_eventloop_with_inputhook,
     run_in_executor_with_context,
     run_in_executor_with_context,
 )
 )
 from prompt_toolkit.eventloop.utils import call_soon_threadsafe
 from prompt_toolkit.eventloop.utils import call_soon_threadsafe
@@ -655,7 +657,7 @@ class Application(Generic[_AppResult]):
             # See: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1553
             # See: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1553
             handle_sigint = False
             handle_sigint = False
 
 
-        async def _run_async(f: "asyncio.Future[_AppResult]") -> _AppResult:
+        async def _run_async(f: asyncio.Future[_AppResult]) -> _AppResult:
             context = contextvars.copy_context()
             context = contextvars.copy_context()
             self.context = context
             self.context = context
 
 
@@ -898,13 +900,12 @@ class Application(Generic[_AppResult]):
         set_exception_handler: bool = True,
         set_exception_handler: bool = True,
         handle_sigint: bool = True,
         handle_sigint: bool = True,
         in_thread: bool = False,
         in_thread: bool = False,
+        inputhook: InputHook | None = None,
     ) -> _AppResult:
     ) -> _AppResult:
         """
         """
         A blocking 'run' call that waits until the UI is finished.
         A blocking 'run' call that waits until the UI is finished.
 
 
-        This will start the current asyncio event loop. If no loop is set for
-        the current thread, then it will create a new loop. If a new loop was
-        created, this won't close the new loop (if `in_thread=False`).
+        This will run the application in a fresh asyncio event loop.
 
 
         :param pre_run: Optional callable, which is called right after the
         :param pre_run: Optional callable, which is called right after the
             "reset" of the application.
             "reset" of the application.
@@ -937,6 +938,7 @@ class Application(Generic[_AppResult]):
                         set_exception_handler=set_exception_handler,
                         set_exception_handler=set_exception_handler,
                         # Signal handling only works in the main thread.
                         # Signal handling only works in the main thread.
                         handle_sigint=False,
                         handle_sigint=False,
+                        inputhook=inputhook,
                     )
                     )
                 except BaseException as e:
                 except BaseException as e:
                     exception = e
                     exception = e
@@ -954,17 +956,46 @@ class Application(Generic[_AppResult]):
             set_exception_handler=set_exception_handler,
             set_exception_handler=set_exception_handler,
             handle_sigint=handle_sigint,
             handle_sigint=handle_sigint,
         )
         )
-        try:
-            # See whether a loop was installed already. If so, use that. That's
-            # required for the input hooks to work, they are installed using
-            # `set_event_loop`.
-            loop = asyncio.get_event_loop()
-        except RuntimeError:
+
+        def _called_from_ipython() -> bool:
+            try:
+                return (
+                    "IPython/terminal/interactiveshell.py"
+                    in sys._getframe(3).f_code.co_filename
+                )
+            except BaseException:
+                return False
+
+        if inputhook is not None:
+            # Create new event loop with given input hook and run the app.
+            # In Python 3.12, we can use asyncio.run(loop_factory=...)
+            # For now, use `run_until_complete()`.
+            loop = new_eventloop_with_inputhook(inputhook)
+            result = loop.run_until_complete(coro)
+            loop.run_until_complete(loop.shutdown_asyncgens())
+            loop.close()
+            return result
+
+        elif _called_from_ipython():
+            # workaround to make input hooks work for IPython until
+            # https://github.com/ipython/ipython/pull/14241 is merged.
+            # IPython was setting the input hook by installing an event loop
+            # previously.
+            try:
+                # See whether a loop was installed already. If so, use that.
+                # That's required for the input hooks to work, they are
+                # installed using `set_event_loop`.
+                loop = asyncio.get_event_loop()
+            except RuntimeError:
+                # No loop installed. Run like usual.
+                return asyncio.run(coro)
+            else:
+                # Use existing loop.
+                return loop.run_until_complete(coro)
+
+        else:
             # No loop installed. Run like usual.
             # No loop installed. Run like usual.
             return asyncio.run(coro)
             return asyncio.run(coro)
-        else:
-            # Use existing loop.
-            return loop.run_until_complete(coro)
 
 
     def _handle_exception(
     def _handle_exception(
         self, loop: AbstractEventLoop, context: dict[str, Any]
         self, loop: AbstractEventLoop, context: dict[str, Any]
@@ -999,7 +1030,7 @@ class Application(Generic[_AppResult]):
         manager. (We will only install the hook if no other custom hook was
         manager. (We will only install the hook if no other custom hook was
         set.)
         set.)
         """
         """
-        if sys.version_info >= (3, 7) and sys.breakpointhook == sys.__breakpointhook__:
+        if sys.breakpointhook == sys.__breakpointhook__:
             sys.breakpointhook = self._breakpointhook
             sys.breakpointhook = self._breakpointhook
 
 
             try:
             try:

+ 1 - 6
contrib/python/prompt-toolkit/py3/prompt_toolkit/application/current.py

@@ -1,6 +1,5 @@
 from __future__ import annotations
 from __future__ import annotations
 
 
-import sys
 from contextlib import contextmanager
 from contextlib import contextmanager
 from contextvars import ContextVar
 from contextvars import ContextVar
 from typing import TYPE_CHECKING, Any, Generator
 from typing import TYPE_CHECKING, Any, Generator
@@ -145,12 +144,8 @@ def create_app_session(
     Create a separate AppSession.
     Create a separate AppSession.
 
 
     This is useful if there can be multiple individual `AppSession`s going on.
     This is useful if there can be multiple individual `AppSession`s going on.
-    Like in the case of an Telnet/SSH server. This functionality uses
-    contextvars and requires at least Python 3.7.
+    Like in the case of an Telnet/SSH server.
     """
     """
-    if sys.version_info <= (3, 6):
-        raise RuntimeError("Application sessions require Python 3.7.")
-
     # If no input/output is specified, fall back to the current input/output,
     # If no input/output is specified, fall back to the current input/output,
     # whatever that is.
     # whatever that is.
     if input is None:
     if input is None:

+ 2 - 0
contrib/python/prompt-toolkit/py3/prompt_toolkit/application/dummy.py

@@ -2,6 +2,7 @@ from __future__ import annotations
 
 
 from typing import Callable
 from typing import Callable
 
 
+from prompt_toolkit.eventloop import InputHook
 from prompt_toolkit.formatted_text import AnyFormattedText
 from prompt_toolkit.formatted_text import AnyFormattedText
 from prompt_toolkit.input import DummyInput
 from prompt_toolkit.input import DummyInput
 from prompt_toolkit.output import DummyOutput
 from prompt_toolkit.output import DummyOutput
@@ -28,6 +29,7 @@ class DummyApplication(Application[None]):
         set_exception_handler: bool = True,
         set_exception_handler: bool = True,
         handle_sigint: bool = True,
         handle_sigint: bool = True,
         in_thread: bool = False,
         in_thread: bool = False,
+        inputhook: InputHook | None = None,
     ) -> None:
     ) -> None:
         raise NotImplementedError("A DummyApplication is not supposed to run.")
         raise NotImplementedError("A DummyApplication is not supposed to run.")
 
 

+ 3 - 3
contrib/python/prompt-toolkit/py3/prompt_toolkit/auto_suggest.py

@@ -72,7 +72,7 @@ class AutoSuggest(metaclass=ABCMeta):
         """
         """
 
 
     async def get_suggestion_async(
     async def get_suggestion_async(
-        self, buff: "Buffer", document: Document
+        self, buff: Buffer, document: Document
     ) -> Suggestion | None:
     ) -> Suggestion | None:
         """
         """
         Return a :class:`.Future` which is set when the suggestions are ready.
         Return a :class:`.Future` which is set when the suggestions are ready.
@@ -96,7 +96,7 @@ class ThreadedAutoSuggest(AutoSuggest):
         return self.auto_suggest.get_suggestion(buff, document)
         return self.auto_suggest.get_suggestion(buff, document)
 
 
     async def get_suggestion_async(
     async def get_suggestion_async(
-        self, buff: "Buffer", document: Document
+        self, buff: Buffer, document: Document
     ) -> Suggestion | None:
     ) -> Suggestion | None:
         """
         """
         Run the `get_suggestion` function in a thread.
         Run the `get_suggestion` function in a thread.
@@ -170,7 +170,7 @@ class DynamicAutoSuggest(AutoSuggest):
         return auto_suggest.get_suggestion(buff, document)
         return auto_suggest.get_suggestion(buff, document)
 
 
     async def get_suggestion_async(
     async def get_suggestion_async(
-        self, buff: "Buffer", document: Document
+        self, buff: Buffer, document: Document
     ) -> Suggestion | None:
     ) -> Suggestion | None:
         auto_suggest = self.get_auto_suggest() or DummyAutoSuggest()
         auto_suggest = self.get_auto_suggest() or DummyAutoSuggest()
         return await auto_suggest.get_suggestion_async(buff, document)
         return await auto_suggest.get_suggestion_async(buff, document)

+ 14 - 12
contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py

@@ -15,7 +15,7 @@ import tempfile
 from collections import deque
 from collections import deque
 from enum import Enum
 from enum import Enum
 from functools import wraps
 from functools import wraps
-from typing import Any, Awaitable, Callable, Coroutine, Deque, Iterable, TypeVar, cast
+from typing import Any, Awaitable, Callable, Coroutine, Iterable, TypeVar, cast
 
 
 from .application.current import get_app
 from .application.current import get_app
 from .application.run_in_terminal import run_in_terminal
 from .application.run_in_terminal import run_in_terminal
@@ -56,6 +56,7 @@ class EditReadOnlyBuffer(Exception):
 
 
 class ValidationState(Enum):
 class ValidationState(Enum):
     "The validation state of a buffer. This is set after the validation."
     "The validation state of a buffer. This is set after the validation."
+
     VALID = "VALID"
     VALID = "VALID"
     INVALID = "INVALID"
     INVALID = "INVALID"
     UNKNOWN = "UNKNOWN"
     UNKNOWN = "UNKNOWN"
@@ -366,7 +367,7 @@ class Buffer:
         #: Ctrl-C should reset this, and copy the whole history back in here.
         #: Ctrl-C should reset this, and copy the whole history back in here.
         #: Enter should process the current command and append to the real
         #: Enter should process the current command and append to the real
         #: history.
         #: history.
-        self._working_lines: Deque[str] = deque([document.text])
+        self._working_lines: deque[str] = deque([document.text])
         self.__working_index = 0
         self.__working_index = 0
 
 
     def load_history_if_not_yet_loaded(self) -> None:
     def load_history_if_not_yet_loaded(self) -> None:
@@ -1936,18 +1937,18 @@ def indent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None:
     Indent text of a :class:`.Buffer` object.
     Indent text of a :class:`.Buffer` object.
     """
     """
     current_row = buffer.document.cursor_position_row
     current_row = buffer.document.cursor_position_row
+    current_col = buffer.document.cursor_position_col
     line_range = range(from_row, to_row)
     line_range = range(from_row, to_row)
 
 
     # Apply transformation.
     # Apply transformation.
-    new_text = buffer.transform_lines(line_range, lambda l: "    " * count + l)
+    indent_content = "    " * count
+    new_text = buffer.transform_lines(line_range, lambda l: indent_content + l)
     buffer.document = Document(
     buffer.document = Document(
         new_text, Document(new_text).translate_row_col_to_index(current_row, 0)
         new_text, Document(new_text).translate_row_col_to_index(current_row, 0)
     )
     )
 
 
-    # Go to the start of the line.
-    buffer.cursor_position += buffer.document.get_start_of_line_position(
-        after_whitespace=True
-    )
+    # Place cursor in the same position in text after indenting
+    buffer.cursor_position += current_col + len(indent_content)
 
 
 
 
 def unindent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None:
 def unindent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None:
@@ -1955,10 +1956,13 @@ def unindent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None
     Unindent text of a :class:`.Buffer` object.
     Unindent text of a :class:`.Buffer` object.
     """
     """
     current_row = buffer.document.cursor_position_row
     current_row = buffer.document.cursor_position_row
+    current_col = buffer.document.cursor_position_col
     line_range = range(from_row, to_row)
     line_range = range(from_row, to_row)
 
 
+    indent_content = "    " * count
+
     def transform(text: str) -> str:
     def transform(text: str) -> str:
-        remove = "    " * count
+        remove = indent_content
         if text.startswith(remove):
         if text.startswith(remove):
             return text[len(remove) :]
             return text[len(remove) :]
         else:
         else:
@@ -1970,10 +1974,8 @@ def unindent(buffer: Buffer, from_row: int, to_row: int, count: int = 1) -> None
         new_text, Document(new_text).translate_row_col_to_index(current_row, 0)
         new_text, Document(new_text).translate_row_col_to_index(current_row, 0)
     )
     )
 
 
-    # Go to the start of the line.
-    buffer.cursor_position += buffer.document.get_start_of_line_position(
-        after_whitespace=True
-    )
+    # Place cursor in the same position in text after dedent
+    buffer.cursor_position += current_col - len(indent_content)
 
 
 
 
 def reshape_text(buffer: Buffer, from_row: int, to_row: int) -> None:
 def reshape_text(buffer: Buffer, from_row: int, to_row: int) -> None:

+ 3 - 3
contrib/python/prompt-toolkit/py3/prompt_toolkit/cache.py

@@ -2,7 +2,7 @@ from __future__ import annotations
 
 
 from collections import deque
 from collections import deque
 from functools import wraps
 from functools import wraps
-from typing import Any, Callable, Deque, Dict, Generic, Hashable, Tuple, TypeVar, cast
+from typing import Any, Callable, Dict, Generic, Hashable, Tuple, TypeVar, cast
 
 
 __all__ = [
 __all__ = [
     "SimpleCache",
     "SimpleCache",
@@ -26,7 +26,7 @@ class SimpleCache(Generic[_T, _U]):
         assert maxsize > 0
         assert maxsize > 0
 
 
         self._data: dict[_T, _U] = {}
         self._data: dict[_T, _U] = {}
-        self._keys: Deque[_T] = deque()
+        self._keys: deque[_T] = deque()
         self.maxsize: int = maxsize
         self.maxsize: int = maxsize
 
 
     def get(self, key: _T, getter_func: Callable[[], _U]) -> _U:
     def get(self, key: _T, getter_func: Callable[[], _U]) -> _U:
@@ -86,7 +86,7 @@ class FastDictCache(Dict[_K, _V]):
     def __init__(self, get_value: Callable[..., _V], size: int = 1000000) -> None:
     def __init__(self, get_value: Callable[..., _V], size: int = 1000000) -> None:
         assert size > 0
         assert size > 0
 
 
-        self._keys: Deque[_K] = deque()
+        self._keys: deque[_K] = deque()
         self.get_value = get_value
         self.get_value = get_value
         self.size = size
         self.size = size
 
 

+ 1 - 2
contrib/python/prompt-toolkit/py3/prompt_toolkit/clipboard/in_memory.py

@@ -1,7 +1,6 @@
 from __future__ import annotations
 from __future__ import annotations
 
 
 from collections import deque
 from collections import deque
-from typing import Deque
 
 
 from .base import Clipboard, ClipboardData
 from .base import Clipboard, ClipboardData
 
 
@@ -22,7 +21,7 @@ class InMemoryClipboard(Clipboard):
         assert max_size >= 1
         assert max_size >= 1
 
 
         self.max_size = max_size
         self.max_size = max_size
-        self._ring: Deque[ClipboardData] = deque()
+        self._ring: deque[ClipboardData] = deque()
 
 
         if data is not None:
         if data is not None:
             self.set_data(data)
             self.set_data(data)

+ 1 - 1
contrib/python/prompt-toolkit/py3/prompt_toolkit/completion/filesystem.py

@@ -115,4 +115,4 @@ class ExecutableCompleter(PathCompleter):
             get_paths=lambda: os.environ.get("PATH", "").split(os.pathsep),
             get_paths=lambda: os.environ.get("PATH", "").split(os.pathsep),
             file_filter=lambda name: os.access(name, os.X_OK),
             file_filter=lambda name: os.access(name, os.X_OK),
             expanduser=True,
             expanduser=True,
-        ),
+        )

Некоторые файлы не были показаны из-за большого количества измененных файлов