Exemplo n.º 1
0
def simulate_press(self, string):
	for char in parse_keybinding(string):
		self.add(char)
		if self.done:
			return self.command
		if self.failure:
			break
	return self.command
Exemplo n.º 2
0
def simulate_press(self, string):
    for char in parse_keybinding(string):
        self.add(char)
        if self.done:
            return self.command
        if self.failure:
            break
    return self.command
Exemplo n.º 3
0
 def _try_to_finish(self):
     if self.max_alias_recursion <= 0:
         self.failure = True
         return None
     assert isinstance(self.tree_pointer, (Binding, dict, KeyMap))
     if isinstance(self.tree_pointer, KeyMap):
         self.tree_pointer = self.tree_pointer._tree
     if isinstance(self.tree_pointer, Binding):
         if self.tree_pointer.alias:
             keys = parse_keybinding(self.tree_pointer.alias)
             self.key_queue.extend(keys)
             self.tree_pointer = self.keymap._tree
             self.max_alias_recursion -= 1
         else:
             self.command = self.tree_pointer
             self.done = True
Exemplo n.º 4
0
	def _try_to_finish(self):
		if self.max_alias_recursion <= 0:
			self.failure = True
			return None
		assert isinstance(self.tree_pointer, (Binding, dict, KeyMap))
		if isinstance(self.tree_pointer, KeyMap):
			self.tree_pointer = self.tree_pointer._tree
		if isinstance(self.tree_pointer, Binding):
			if self.tree_pointer.alias:
				keys = parse_keybinding(self.tree_pointer.alias)
				self.key_queue.extend(keys)
				self.tree_pointer = self.keymap._tree
				self.max_alias_recursion -= 1
			else:
				self.command = self.tree_pointer
				self.done = True
Exemplo n.º 5
0
 def __init__(self, keys, actions):
     assert hasattr(keys, '__iter__')
     assert isinstance(actions, dict)
     self.actions = actions
     try:
         self.function = self.actions[FUNC]
     except KeyError:
         self.function = None
     try:
         self.direction = self.actions[DIRARG]
     except KeyError:
         self.direction = None
     try:
         alias = self.actions[ALIASARG]
     except KeyError:
         self.alias = None
     else:
         self.alias = tuple(parse_keybinding(alias))
Exemplo n.º 6
0
	def __init__(self, keys, actions):
		assert hasattr(keys, '__iter__')
		assert isinstance(actions, dict)
		self.actions = actions
		try:
			self.function = self.actions[FUNC]
		except KeyError:
			self.function = None
		try:
			self.direction = self.actions[DIRARG]
		except KeyError:
			self.direction = None
		try:
			alias = self.actions[ALIASARG]
		except KeyError:
			self.alias = None
		else:
			self.alias = tuple(parse_keybinding(alias))
Exemplo n.º 7
0
 def _direction_try_to_finish(self):
     if self.max_alias_recursion <= 0:
         self.failure = True
         return None
     match = self.dir_tree_pointer
     assert isinstance(match, (Binding, dict, KeyMap))
     if isinstance(match, KeyMap):
         self.dir_tree_pointer = self.dir_tree_pointer._tree
         match = self.dir_tree_pointer
     if isinstance(self.dir_tree_pointer, Binding):
         if match.alias:
             self.key_queue.extend(parse_keybinding(match.alias))
             self.dir_tree_pointer = self.direction_keys._tree
             self.max_alias_recursion -= 1
         else:
             direction = match.actions['dir'].copy()
             if self.direction_quant is not None:
                 direction.multiply(self.direction_quant)
             self.directions.append(direction)
             self.direction_quant = None
             self.eval_command = True
             self._try_to_finish()
Exemplo n.º 8
0
	def _direction_try_to_finish(self):
		if self.max_alias_recursion <= 0:
			self.failure = True
			return None
		match = self.dir_tree_pointer
		assert isinstance(match, (Binding, dict, KeyMap))
		if isinstance(match, KeyMap):
			self.dir_tree_pointer = self.dir_tree_pointer._tree
			match = self.dir_tree_pointer
		if isinstance(self.dir_tree_pointer, Binding):
			if match.alias:
				self.key_queue.extend(parse_keybinding(match.alias))
				self.dir_tree_pointer = self.direction_keys._tree
				self.max_alias_recursion -= 1
			else:
				direction = match.actions['dir'].copy()
				if self.direction_quant is not None:
					direction.multiply(self.direction_quant)
				self.directions.append(direction)
				self.direction_quant = None
				self.eval_command = True
				self._try_to_finish()
Exemplo n.º 9
0
    def test_corruptions(self):
        km = KeyMap()
        directions = KeyMap()
        kb = KeyBuffer(km, directions)
        press = self._mkpress(kb, km)
        directions.map('j', dir=Direction(down=1))
        directions.map('k', dir=Direction(down=-1))
        km.map('xxx', lambda _: 1)

        self.assertEqual(1, press('xxx'))

        # corrupt the tree
        tup = tuple(parse_keybinding('xxx'))
        x = ord('x')
        km._tree[x][x][x] = "Boo"

        self.assertPressFails(kb, 'xxy')
        self.assertPressFails(kb, 'xzy')
        self.assertPressIncomplete(kb, 'xx')
        self.assertPressIncomplete(kb, 'x')
        if not sys.flags.optimize:  # asserts are ignored with python -O
            self.assertRaises(AssertionError, simulate_press, kb, 'xxx')
        kb.clear()
Exemplo n.º 10
0
	def test_corruptions(self):
		km = KeyMap()
		directions = KeyMap()
		kb = KeyBuffer(km, directions)
		press = self._mkpress(kb, km)
		directions.map('j', dir=Direction(down=1))
		directions.map('k', dir=Direction(down=-1))
		km.map('xxx', lambda _: 1)

		self.assertEqual(1, press('xxx'))

		# corrupt the tree
		tup = tuple(parse_keybinding('xxx'))
		x = ord('x')
		km._tree[x][x][x] = "Boo"

		self.assertPressFails(kb, 'xxy')
		self.assertPressFails(kb, 'xzy')
		self.assertPressIncomplete(kb, 'xx')
		self.assertPressIncomplete(kb, 'x')
		if not sys.flags.optimize:  # asserts are ignored with python -O
			self.assertRaises(AssertionError, simulate_press, kb, 'xxx')
		kb.clear()
Exemplo n.º 11
0
 def __getitem__(self, key):
     return self.traverse(parse_keybinding(key))
Exemplo n.º 12
0
 def unmap(self, *keys):
     for key in keys:
         self.unset(parse_keybinding(key))
Exemplo n.º 13
0
 def _add_binding(self, *keys, **actions):
     assert keys
     bind = Binding(keys, actions)
     for key in keys:
         self.set(parse_keybinding(key), bind)
Exemplo n.º 14
0
	def __getitem__(self, key):
		return self.traverse(parse_keybinding(key))
Exemplo n.º 15
0
	def unmap(self, *keys):
		for key in keys:
			self.unset(parse_keybinding(key))
Exemplo n.º 16
0
	def _add_binding(self, *keys, **actions):
		assert keys
		bind = Binding(keys, actions)
		for key in keys:
			self.set(parse_keybinding(key), bind)
Exemplo n.º 17
0
 def test(string, *args):
     if not args:
         args = (string, )
     self.assertEqual(ordtuple(*args), tuple(parse_keybinding(string)))
Exemplo n.º 18
0
		def test(string, *args):
			if not args:
				args = (string, )
			self.assertEqual(ordtuple(*args), tuple(parse_keybinding(string)))