Use a MpdCommand namedtuple in the mopidy.frontends.mpd.protocol.mpd_commands list
This commit is contained in:
parent
e6294ec869
commit
a08885bb95
@ -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 = []
|
||||
|
||||
@ -10,6 +10,7 @@ implement our own MPD server which is compatible with the numerous existing
|
||||
`MPD clients <http://mpd.wikia.com/wiki/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))
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user