From 09d7279b6ba44326af7778ee004571daab48e8d4 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 21 Nov 2012 01:13:05 +0100 Subject: [PATCH] mpd: Compile protocol matching regexpes This caused a single test failure, which was fixed. --- mopidy/frontends/mpd/protocol/__init__.py | 5 +++-- mopidy/frontends/mpd/protocol/current_playlist.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/__init__.py b/mopidy/frontends/mpd/protocol/__init__.py index 3a9f3674..ded65315 100644 --- a/mopidy/frontends/mpd/protocol/__init__.py +++ b/mopidy/frontends/mpd/protocol/__init__.py @@ -56,10 +56,11 @@ def handle_request(pattern, auth_required=True): if match is not None: mpd_commands.add( MpdCommand(name=match.group(), auth_required=auth_required)) - if pattern in request_handlers: + compiled_pattern = re.compile(pattern) + if compiled_pattern in request_handlers: raise ValueError('Tried to redefine handler for %s with %s' % ( pattern, func)) - request_handlers[pattern] = func + request_handlers[compiled_pattern] = func func.__doc__ = ' - *Pattern:* ``%s``\n\n%s' % ( pattern, func.__doc__ or '') return func diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index fbc92b46..f0d2e8f9 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -232,7 +232,6 @@ def playlistid(context, tlid=None): @handle_request(r'^playlistinfo$') -@handle_request(r'^playlistinfo "-1"$') @handle_request(r'^playlistinfo "(?P-?\d+)"$') @handle_request(r'^playlistinfo "(?P\d+):(?P\d+)*"$') def playlistinfo(context, songpos=None, start=None, end=None): @@ -250,6 +249,8 @@ def playlistinfo(context, songpos=None, start=None, end=None): - uses negative indexes, like ``playlistinfo "-1"``, to request the entire playlist """ + if songpos == '-1': + songpos = None if songpos is not None: songpos = int(songpos) tl_track = context.core.tracklist.tl_tracks.get()[songpos]