summaryrefslogtreecommitdiff
path: root/keyboardpython/key.py
diff options
context:
space:
mode:
Diffstat (limited to 'keyboardpython/key.py')
-rw-r--r--keyboardpython/key.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index e6592ab..237d92a 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -1,6 +1,6 @@
ESC = '\x1b'
-def assert_type(thing,_type):
+def _assert_type(thing,_type):
''' if thing is not of type _type raise an exception '''
if type(thing) is not _type:
raise(TypeError,
@@ -11,7 +11,7 @@ class Key:
''' a keyboard keypress object '''
def __init__(self,name,*modifiers):
- assert_type(name,str)
+ _assert_type(name,str)
for m in modifiers:
assert isinstance(m,Key), "Modifiers expected to be instances of Key"
self.name = name
@@ -49,7 +49,7 @@ class Key:
ALT = Key('Alt')
CTRL = Key('Control')
-table = {
+_table = {
ESC : Key('Escape'),
'\t': Key('Tab'),
' ': Key('Space'),
@@ -79,29 +79,29 @@ table = {
'%s[C' % ESC: Key('Right'),
}
-def is_alt(code):
+def _is_alt(code):
''' is this the code of a combination modified by Alt? '''
- assert_type(code,str)
+ _assert_type(code,str)
if len(code) == 2 and code[0] == ESC:
return True
return False
-def is_ctrl_alpha(code):
+def _is_ctrl_alpha(code):
''' is this the code of a combination modified by Ctrl? '''
- assert_type(code,str)
+ _assert_type(code,str)
if code < '\x20': return True
return False
-def get_ctrl_alpha(code):
+def _get_ctrl_alpha(code):
''' get alphabetic key modified by Ctrl '''
- assert_type(code,str)
+ _assert_type(code,str)
letter = chr(ord(code) + 0x40)
return Key(letter,CTRL)
def parse_code(code):
''' get Key object from code '''
- assert_type(code,str)
- if code in table.keys(): return table[code]
- elif is_alt(code): return parse_code(code[1:]).modify(ALT)
- elif is_ctrl_alpha(code): return get_ctrl_alpha(code)
+ _assert_type(code,str)
+ if code in _table.keys(): return _table[code]
+ elif _is_alt(code): return parse_code(code[1:]).modify(ALT)
+ elif _is_ctrl_alpha(code): return _get_ctrl_alpha(code)
else: return Key(code)