Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-119357: Increase test coverage for keymap in _pyrepl#119358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from2 commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,7 +30,7 @@ | ||
| # types | ||
| Command = commands.Command | ||
| if False: | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. note: these two aren't used | ||
| from .types import KeySpec, CommandName | ||
| def prefix(wordlist: list[str], j: int = 0) -> str: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,38 +19,32 @@ | ||
| # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| """ | ||
| Keymap contains functions for parsing keyspecs and turning keyspecs into | ||
| appropriate sequences. | ||
| A keyspec is a string representing a sequence of key presses that can | ||
| be bound to a command. All characters other than the backslash represent | ||
| themselves. In the traditional manner, a backslash introduces an escape | ||
| sequence. | ||
| pyrepl uses its own keyspec format that is meant to be a strict superset of | ||
| readline's KEYSEQ format. This means that if a spec is found that readline | ||
| accepts that this doesn't, it should be logged as a bug. Note that this means | ||
| we're using the `\\C-o' style of readline's keyspec, not the `Control-o' sort. | ||
| The extension to readline is that the sequence \\<KEY> denotes the | ||
| sequence ofcharacters produced by hitting KEY. | ||
| Examples: | ||
| `a' - what you get when you hit the `a' key | ||
| `\\EOA' - Escape - O - A (up, on my terminal) | ||
| `\\<UP>' - the up arrow key | ||
| `\\<up>' - ditto (keynames are case-insensitive) | ||
| `\\C-o', `\\c-o' - control-o | ||
| `\\M-.' - meta-period | ||
| `\\E.' - ditto (that's how meta works for pyrepl) | ||
| `\\<tab>', `\\<TAB>', `\\t', `\\011', '\\x09', '\\X09', '\\C-i', '\\C-I' | ||
| - all of these are the tab character. | ||
| """ | ||
| _escapes = { | ||
| @@ -111,7 +105,17 @@ class KeySpecError(Exception): | ||
| pass | ||
| def parse_keys(keys: str) -> list[str]: | ||
| """Parse keys in keyspec format to a sequence of keys.""" | ||
| s = 0 | ||
| r = [] | ||
| while s < len(keys): | ||
| k, s = _parse_single_key_sequence(keys, s) | ||
| r.extend(k) | ||
| return r | ||
| def _parse_single_key_sequence(key: str, s: int) -> tuple[str, int]: | ||
| ctrl = 0 | ||
| meta = 0 | ||
| ret = "" | ||
| @@ -146,11 +150,11 @@ def _parse_key1(key, s): | ||
| meta = 1 | ||
| s += 3 | ||
| elif c.isdigit(): | ||
| n = key[s + 1: s + 4] | ||
eugenetriguba marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| ret = chr(int(n, 8)) | ||
| s += 4 | ||
| elif c == "x": | ||
| n = key[s + 2: s + 4] | ||
| ret = chr(int(n, 16)) | ||
| s += 4 | ||
| elif c == "<": | ||
| @@ -160,7 +164,7 @@ def _parse_key1(key, s): | ||
| "unterminated \\< starting at char %d of %s" | ||
| % (s + 1, repr(key)) | ||
| ) | ||
| ret = key[s + 2: t].lower() | ||
| if ret not in _keynames: | ||
| raise KeySpecError( | ||
| "unrecognised keyname `%s' at char %d of %s" | ||
| @@ -190,15 +194,6 @@ def _parse_key1(key, s): | ||
| return ret, s | ||
| def compile_keymap(keymap, empty=b""): | ||
| r = {} | ||
| for key, value in keymap.items(): | ||