示例#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
示例#2
0
	def test_not_state(self):
		self.assertFalse(state.is_replace(object()))
示例#3
0
	def test_not_replace(self):
		self.assertFalse(state.is_replace(state.done(None)))
		self.assertFalse(state.is_replace(state.next(None)))
示例#4
0
	def test_replace(self):
		self.assertTrue(state.is_replace(state.replace(None)))