diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-12-18 11:04:10 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-12-18 11:18:13 +0300 |
commit | dcbf444872b81248ce958f05d47abad6e8a237a7 (patch) | |
tree | a93610b3dd80f19c5116e4e5885ea2783f6166d3 /contrib/python/ipython/py3/IPython/terminal/interactiveshell.py | |
parent | e2c38d5aa55a58da33c1dc54792c131023bb7472 (diff) | |
download | ydb-dcbf444872b81248ce958f05d47abad6e8a237a7.tar.gz |
Intermediate changes
commit_hash:1f2ebe313aea1039145a9d68dcd511d5f22f383a
Diffstat (limited to 'contrib/python/ipython/py3/IPython/terminal/interactiveshell.py')
-rw-r--r-- | contrib/python/ipython/py3/IPython/terminal/interactiveshell.py | 33 |
1 files changed, 21 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") + ) ), ) ) |