def _find_handler(self, request): for pattern in protocol.request_handlers: matches = re.match(pattern, request) if matches is not None: return (protocol.request_handlers[pattern], matches.groupdict()) command_name = request.split(' ')[0] if command_name in [command.name for command in protocol.mpd_commands]: raise exceptions.MpdArgError('incorrect arguments', command=command_name) raise exceptions.MpdUnknownCommand(command=command_name)
def call(self, tokens, context=None): """Find and run the handler registered for the given command. If the handler was registered with any converters/validators they will be run before calling the real handler. :param list tokens: List of tokens to process :param context: MPD context. :type context: :class:`~mopidy.mpd.dispatcher.MpdContext` """ if not tokens: raise exceptions.MpdNoCommand() if tokens[0] not in self.handlers: raise exceptions.MpdUnknownCommand(command=tokens[0]) return self.handlers[tokens[0]](context, *tokens[1:])
def command_list_end(context): """See :meth:`command_list_begin()`.""" # TODO: batch consecutive add commands if not context.dispatcher.command_list_receiving: raise exceptions.MpdUnknownCommand(command='command_list_end') context.dispatcher.command_list_receiving = False (command_list, context.dispatcher.command_list) = (context.dispatcher.command_list, []) (command_list_ok, context.dispatcher.command_list_ok) = (context.dispatcher.command_list_ok, False) command_list_response = [] for index, command in enumerate(command_list): response = context.dispatcher.handle_request( command, current_command_list_index=index) command_list_response.extend(response) if (command_list_response and command_list_response[-1].startswith('ACK')): return command_list_response if command_list_ok: command_list_response.append('list_OK') return command_list_response