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
def test_not_state(self): self.assertFalse(state.is_replace(object()))
def test_not_replace(self): self.assertFalse(state.is_replace(state.done(None))) self.assertFalse(state.is_replace(state.next(None)))
def test_replace(self): self.assertTrue(state.is_replace(state.replace(None)))