Beispiel #1
0
def parse(msg):
	"""
	Parses given input.

	@param msg: input message to parse
	@type msg: str
	@return: return message processed with associated commands and filters
	@rtype: str
	"""
	try:
		cmd, args = msg.split(" ", 1)
	except ValueError:
		cmd, args = msg.rstrip(), ""

	if cmd in COMMANDS:
		ret = COMMANDS[cmd](args)

		if state.is_done(ret):
			return ret.value
		elif state.is_next(ret):
			pass
		else:
			raise Exception("Illegal state of command.")

	for filter in FILTERS:
		ret = filter(msg)

		if state.is_done(ret):
			return ret.value

		if state.is_replace(ret):
			msg = ret.value

	return msg
Beispiel #2
0
	def test_not_state(self):
		self.assertFalse(state.is_replace(object()))
Beispiel #3
0
	def test_not_replace(self):
		self.assertFalse(state.is_replace(state.done(None)))
		self.assertFalse(state.is_replace(state.next(None)))
Beispiel #4
0
	def test_replace(self):
		self.assertTrue(state.is_replace(state.replace(None)))