diff --git a/mopidy/frontends/mpd/dispatcher.py b/mopidy/frontends/mpd/dispatcher.py index 996c3714..405ca03d 100644 --- a/mopidy/frontends/mpd/dispatcher.py +++ b/mopidy/frontends/mpd/dispatcher.py @@ -135,10 +135,10 @@ class MpdDispatcher(object): matches = re.match(pattern, request) if matches is not None: return (request_handlers[pattern], matches.groupdict()) - command = request.split(' ')[0] - if command in mpd_commands: - raise MpdArgError(u'incorrect arguments', command=command) - raise MpdUnknownCommand(command=command) + command_name = request.split(' ')[0] + if command_name in [command.name for command in mpd_commands]: + raise MpdArgError(u'incorrect arguments', command=command_name) + raise MpdUnknownCommand(command=command_name) def _format_response(self, response): formatted_response = [] diff --git a/mopidy/frontends/mpd/protocol/__init__.py b/mopidy/frontends/mpd/protocol/__init__.py index 6689f627..76aad687 100644 --- a/mopidy/frontends/mpd/protocol/__init__.py +++ b/mopidy/frontends/mpd/protocol/__init__.py @@ -10,6 +10,7 @@ implement our own MPD server which is compatible with the numerous existing `MPD clients `_. """ +from collections import namedtuple import re #: The MPD protocol uses UTF-8 for encoding all data. @@ -21,6 +22,7 @@ LINE_TERMINATOR = u'\n' #: The MPD protocol version is 0.16.0. VERSION = u'0.16.0' +MpdCommand = namedtuple('MpdCommand', ['name']) mpd_commands = set() request_handlers = {} @@ -45,7 +47,7 @@ def handle_pattern(pattern): def decorator(func): match = re.search('([a-z_]+)', pattern) if match is not None: - mpd_commands.add(match.group()) + mpd_commands.add(MpdCommand(name=match.group())) if pattern in request_handlers: raise ValueError(u'Tried to redefine handler for %s with %s' % ( pattern, func)) diff --git a/mopidy/frontends/mpd/protocol/reflection.py b/mopidy/frontends/mpd/protocol/reflection.py index 2b319c5e..6e0a2f6c 100644 --- a/mopidy/frontends/mpd/protocol/reflection.py +++ b/mopidy/frontends/mpd/protocol/reflection.py @@ -15,20 +15,20 @@ def commands(context): # have access to. To implement this we need access to the session object to # check if the client is authenticated or not. - sorted_commands = sorted(list(mpd_commands)) + command_names = [command.name for command in mpd_commands] # No permission to use - sorted_commands.remove('kill') + command_names.remove('kill') # Not shown by MPD in its command list - sorted_commands.remove('command_list_begin') - sorted_commands.remove('command_list_ok_begin') - sorted_commands.remove('command_list_end') - sorted_commands.remove('idle') - sorted_commands.remove('noidle') - sorted_commands.remove('sticker') + command_names.remove('command_list_begin') + command_names.remove('command_list_ok_begin') + command_names.remove('command_list_end') + command_names.remove('idle') + command_names.remove('noidle') + command_names.remove('sticker') - return [('command', c) for c in sorted_commands] + return [('command', command_name) for command_name in sorted(command_names)] @handle_pattern(r'^decoders$') def decoders(context): @@ -63,12 +63,12 @@ def notcommands(context): # not have access to. To implement this we need access to the session # object to check if the client is authenticated or not. - commands = [] + command_names = [] # No permission to use - commands.append('kill') + command_names.append('kill') - return [('command', c) for c in sorted(commands)] + return [('command', command_name) for command_name in sorted(command_names)] @handle_pattern(r'^tagtypes$') def tagtypes(context):