Show More
@@ -52,6 +52,7 from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook | |||
|
52 | 52 | from .ptutils import IPythonPTCompleter, IPythonPTLexer |
|
53 | 53 | from .shortcuts import ( |
|
54 | 54 | KEY_BINDINGS, |
|
55 | UNASSIGNED_ALLOWED_COMMANDS, | |
|
55 | 56 | create_ipython_shortcuts, |
|
56 | 57 | create_identifier, |
|
57 | 58 | RuntimeBinding, |
@@ -508,19 +509,25 class TerminalInteractiveShell(InteractiveShell): | |||
|
508 | 509 | # rebuild the bindings list from scratch |
|
509 | 510 | key_bindings = create_ipython_shortcuts(self) |
|
510 | 511 | |
|
511 |
# for now we only allow adding shortcuts for |
|
|
512 |
# |
|
|
513 |
|
|
|
512 | # for now we only allow adding shortcuts for a specific set of | |
|
513 | # commands; this is a security precution. | |
|
514 | allowed_commands = { | |
|
514 | 515 | create_identifier(binding.command): binding.command |
|
515 | 516 | for binding in KEY_BINDINGS |
|
516 | 517 | } |
|
518 | allowed_commands.update( | |
|
519 | { | |
|
520 | create_identifier(command): command | |
|
521 | for command in UNASSIGNED_ALLOWED_COMMANDS | |
|
522 | } | |
|
523 | ) | |
|
517 | 524 | shortcuts_to_skip = [] |
|
518 | 525 | shortcuts_to_add = [] |
|
519 | 526 | |
|
520 | 527 | for shortcut in user_shortcuts: |
|
521 | 528 | command_id = shortcut["command"] |
|
522 |
if command_id not in |
|
|
523 |
allowed_commands = "\n - ".join( |
|
|
529 | if command_id not in allowed_commands: | |
|
530 | allowed_commands = "\n - ".join(allowed_commands) | |
|
524 | 531 | raise ValueError( |
|
525 | 532 | f"{command_id} is not a known shortcut command." |
|
526 | 533 | f" Allowed commands are: \n - {allowed_commands}" |
@@ -544,7 +551,7 class TerminalInteractiveShell(InteractiveShell): | |||
|
544 | 551 | new_keys = shortcut.get("new_keys", None) |
|
545 | 552 | new_filter = shortcut.get("new_filter", None) |
|
546 | 553 | |
|
547 |
command = |
|
|
554 | command = allowed_commands[command_id] | |
|
548 | 555 | |
|
549 | 556 | creating_new = shortcut.get("create", False) |
|
550 | 557 | modifying_existing = not creating_new and ( |
@@ -586,12 +593,14 class TerminalInteractiveShell(InteractiveShell): | |||
|
586 | 593 | RuntimeBinding( |
|
587 | 594 | command, |
|
588 | 595 | keys=new_keys or old_keys, |
|
589 |
filter= |
|
|
596 | filter=( | |
|
597 | filter_from_string(new_filter) | |
|
590 | 598 | if new_filter is not None |
|
591 | 599 | else ( |
|
592 | 600 | old_filter |
|
593 | 601 | if old_filter is not None |
|
594 | 602 | else filter_from_string("always") |
|
603 | ) | |
|
595 | 604 | ), |
|
596 | 605 | ) |
|
597 | 606 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now