mpd: Install new commands helpers in _call_handler
This means we now tokenize every request, and then try in call the appropriate handler. If none is found we simply fall back to the old handlers.
This commit is contained in:
parent
066fed1522
commit
d3db5c4fe1
@ -5,7 +5,7 @@ import re
|
|||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
|
|
||||||
from mopidy.mpd import exceptions, protocol
|
from mopidy.mpd import exceptions, protocol, tokenize
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -164,6 +164,15 @@ class MpdDispatcher(object):
|
|||||||
raise exceptions.MpdSystemError(e)
|
raise exceptions.MpdSystemError(e)
|
||||||
|
|
||||||
def _call_handler(self, request):
|
def _call_handler(self, request):
|
||||||
|
tokens = tokenize.split(request)
|
||||||
|
try:
|
||||||
|
return protocol.commands.call(tokens, context=self.context)
|
||||||
|
except exceptions.MpdAckError as exc:
|
||||||
|
if exc.command is None:
|
||||||
|
exc.command = tokens[0]
|
||||||
|
raise
|
||||||
|
except LookupError:
|
||||||
|
pass # Command has not been converted, i.e. fallback...
|
||||||
(command_name, handler, kwargs) = self._find_handler(request)
|
(command_name, handler, kwargs) = self._find_handler(request)
|
||||||
try:
|
try:
|
||||||
return handler(self.context, **kwargs)
|
return handler(self.context, **kwargs)
|
||||||
|
|||||||
@ -150,7 +150,10 @@ class Commands(object):
|
|||||||
def call(self, args, context=None):
|
def call(self, args, context=None):
|
||||||
if not args:
|
if not args:
|
||||||
raise TypeError('No args provided')
|
raise TypeError('No args provided')
|
||||||
command = args.pop(0)
|
if args[0] not in self.handlers:
|
||||||
if command not in self.handlers:
|
|
||||||
raise LookupError('Unknown command')
|
raise LookupError('Unknown command')
|
||||||
return self.handlers[command](context, *args)
|
return self.handlers[args[0]](context, *args[1:])
|
||||||
|
|
||||||
|
|
||||||
|
#: Global instance to install commands into
|
||||||
|
commands = Commands()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user