def _parser(self, line): """Parse line to tuple of prefix, command and message. Call a function due to command. :param line: string message received from server """ msg = myparser.parsingCommand(line) case = {'OK':self._recd_ok, 'ERROR':self._recd_error, 'MSG':self._recd_msg, 'SERVICE':self._recd_service_msg, 'NAMES':self._recd_names } action = case.get(msg[1]) if action: action(msg[2])
def lineReceived(self, line): """ Callback, calls each time when client recieved data from client Data must be the correct command Function calls parser for this command and than calls command handler fucntion If command is not correct, function raises exception :param line: line that received from client :type line: str """ prefix, cmd, args = myparser.parsingCommand(line) try: if cmd not in basecmd.commands: raise UnknownCommandException basecmd.commands[cmd](self, prefix, args) except UnknownCommandException, error: print error