aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/terminal
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-12-18 11:04:10 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-12-18 11:18:13 +0300
commitdcbf444872b81248ce958f05d47abad6e8a237a7 (patch)
treea93610b3dd80f19c5116e4e5885ea2783f6166d3 /contrib/python/ipython/py3/IPython/terminal
parente2c38d5aa55a58da33c1dc54792c131023bb7472 (diff)
downloadydb-dcbf444872b81248ce958f05d47abad6e8a237a7.tar.gz
Intermediate changes
commit_hash:1f2ebe313aea1039145a9d68dcd511d5f22f383a
Diffstat (limited to 'contrib/python/ipython/py3/IPython/terminal')
-rw-r--r--contrib/python/ipython/py3/IPython/terminal/interactiveshell.py33
-rw-r--r--contrib/python/ipython/py3/IPython/terminal/shortcuts/__init__.py8
-rw-r--r--contrib/python/ipython/py3/IPython/terminal/shortcuts/auto_match.py1
3 files changed, 30 insertions, 12 deletions
diff --git a/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py b/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py
index 40e2c9a669..ef4f5cd3f6 100644
--- a/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py
+++ b/contrib/python/ipython/py3/IPython/terminal/interactiveshell.py
@@ -52,6 +52,7 @@ from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
from .ptutils import IPythonPTCompleter, IPythonPTLexer
from .shortcuts import (
KEY_BINDINGS,
+ UNASSIGNED_ALLOWED_COMMANDS,
create_ipython_shortcuts,
create_identifier,
RuntimeBinding,
@@ -508,19 +509,25 @@ class TerminalInteractiveShell(InteractiveShell):
# rebuild the bindings list from scratch
key_bindings = create_ipython_shortcuts(self)
- # for now we only allow adding shortcuts for commands which are already
- # registered; this is a security precaution.
- known_commands = {
+ # for now we only allow adding shortcuts for a specific set of
+ # commands; this is a security precution.
+ allowed_commands = {
create_identifier(binding.command): binding.command
for binding in KEY_BINDINGS
}
+ allowed_commands.update(
+ {
+ create_identifier(command): command
+ for command in UNASSIGNED_ALLOWED_COMMANDS
+ }
+ )
shortcuts_to_skip = []
shortcuts_to_add = []
for shortcut in user_shortcuts:
command_id = shortcut["command"]
- if command_id not in known_commands:
- allowed_commands = "\n - ".join(known_commands)
+ if command_id not in allowed_commands:
+ allowed_commands = "\n - ".join(allowed_commands)
raise ValueError(
f"{command_id} is not a known shortcut command."
f" Allowed commands are: \n - {allowed_commands}"
@@ -544,7 +551,7 @@ class TerminalInteractiveShell(InteractiveShell):
new_keys = shortcut.get("new_keys", None)
new_filter = shortcut.get("new_filter", None)
- command = known_commands[command_id]
+ command = allowed_commands[command_id]
creating_new = shortcut.get("create", False)
modifying_existing = not creating_new and (
@@ -586,12 +593,14 @@ class TerminalInteractiveShell(InteractiveShell):
RuntimeBinding(
command,
keys=new_keys or old_keys,
- filter=filter_from_string(new_filter)
- if new_filter is not None
- else (
- old_filter
- if old_filter is not None
- else filter_from_string("always")
+ filter=(
+ filter_from_string(new_filter)
+ if new_filter is not None
+ else (
+ old_filter
+ if old_filter is not None
+ else filter_from_string("always")
+ )
),
)
)
diff --git a/contrib/python/ipython/py3/IPython/terminal/shortcuts/__init__.py b/contrib/python/ipython/py3/IPython/terminal/shortcuts/__init__.py
index 12890f4ab6..ba6d405526 100644
--- a/contrib/python/ipython/py3/IPython/terminal/shortcuts/__init__.py
+++ b/contrib/python/ipython/py3/IPython/terminal/shortcuts/__init__.py
@@ -628,3 +628,11 @@ KEY_BINDINGS = [
*SIMPLE_CONTROL_BINDINGS,
*ALT_AND_COMOBO_CONTROL_BINDINGS,
]
+
+UNASSIGNED_ALLOWED_COMMANDS = [
+ nc.beginning_of_buffer,
+ nc.end_of_buffer,
+ nc.end_of_line,
+ nc.forward_word,
+ nc.unix_line_discard,
+]
diff --git a/contrib/python/ipython/py3/IPython/terminal/shortcuts/auto_match.py b/contrib/python/ipython/py3/IPython/terminal/shortcuts/auto_match.py
index 6c2b1ef70c..6095558bbf 100644
--- a/contrib/python/ipython/py3/IPython/terminal/shortcuts/auto_match.py
+++ b/contrib/python/ipython/py3/IPython/terminal/shortcuts/auto_match.py
@@ -4,6 +4,7 @@ Utilities function for keybinding with prompt toolkit.
This will be bound to specific key press and filter modes,
like whether we are in edit mode, and whether the completer is open.
"""
+
import re
from prompt_toolkit.key_binding import KeyPressEvent