From 335cf4e61246c706aabb2720e4dc64c223039039 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 21 Jan 2014 20:40:49 +0100 Subject: [PATCH] mpd: Return command name in find handler. --- mopidy/mpd/dispatcher.py | 10 +++++----- tests/mpd/test_dispatcher.py | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mopidy/mpd/dispatcher.py b/mopidy/mpd/dispatcher.py index 6aeace9d..69b5e839 100644 --- a/mopidy/mpd/dispatcher.py +++ b/mopidy/mpd/dispatcher.py @@ -164,21 +164,21 @@ class MpdDispatcher(object): raise exceptions.MpdSystemError(e) def _call_handler(self, request): - (handler, kwargs) = self._find_handler(request) + (command_name, handler, kwargs) = self._find_handler(request) try: return handler(self.context, **kwargs) except exceptions.MpdAckError as exc: if exc.command is None: - exc.command = handler.__name__.split('__', 1)[0] + exc.command = command_name raise def _find_handler(self, request): + command_name = request.split(' ')[0] 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] + handler = protocol.request_handlers[pattern] + return (command_name, handler, matches.groupdict()) if command_name in [command.name for command in protocol.mpd_commands]: raise exceptions.MpdArgError( 'incorrect arguments', command=command_name) diff --git a/tests/mpd/test_dispatcher.py b/tests/mpd/test_dispatcher.py index c4da1714..7ef4c13b 100644 --- a/tests/mpd/test_dispatcher.py +++ b/tests/mpd/test_dispatcher.py @@ -43,13 +43,14 @@ class MpdDispatcherTest(unittest.TestCase): e.get_mpd_ack(), 'ACK [5@0] {} unknown command "an_unknown_command"') - def test_find_handler_for_known_command_returns_handler_and_kwargs(self): + def test_find_handler_for_known_command_return_name_handler_and_args(self): expected_handler = lambda x: None request_handlers['known_command (?P.+)'] = \ expected_handler - (handler, kwargs) = self.dispatcher._find_handler( + (name, handler, kwargs) = self.dispatcher._find_handler( 'known_command an_arg') self.assertEqual(handler, expected_handler) + self.assertEqual('known_command', name) self.assertIn('arg1', kwargs) self.assertEqual(kwargs['arg1'], 'an_arg')