X Tutup
Skip to content

Commit 67bd4ac

Browse files
committed
KeyMap object to facilitate custom exceptions (now we need to check valid keys on startup)
1 parent 3ce306e commit 67bd4ac

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

bpython/keys.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@
2525

2626
import string
2727

28-
key_dispatch = {}
28+
class KeyMap:
29+
def __init__(self):
30+
self.map = {}
31+
32+
def __getitem__(self, key):
33+
if key in self.map:
34+
return self.map[key]
35+
else:
36+
raise Exception('Configured keymap (%s) does not exist in bpython.keys' % key)
37+
38+
def __setitem__(self, key, value):
39+
self.map[key] = value
40+
41+
key_dispatch = KeyMap()
2942

3043
# fill dispatch with letters
3144
for c in string.lowercase:

0 commit comments

Comments
 (0)
X Tutup