diff --git a/mopidy/frontends/mpd/protocol/__init__.py b/mopidy/frontends/mpd/protocol/__init__.py index 76aad687..24ce1cac 100644 --- a/mopidy/frontends/mpd/protocol/__init__.py +++ b/mopidy/frontends/mpd/protocol/__init__.py @@ -26,9 +26,9 @@ MpdCommand = namedtuple('MpdCommand', ['name']) mpd_commands = set() request_handlers = {} -def handle_pattern(pattern): +def handle_request(pattern): """ - Decorator for connecting command handlers to command patterns. + Decorator for connecting command handlers to command requests. If you use named groups in the pattern, the decorated method will get the groups as keyword arguments. If the group is optional, remember to give the @@ -37,7 +37,7 @@ def handle_pattern(pattern): For example, if the command is ``do that thing`` the ``what`` argument will be ``this thing``:: - @handle_pattern('^do (?P.+)$') + @handle_request('^do (?P.+)$') def do(what): ... diff --git a/mopidy/frontends/mpd/protocol/audio_output.py b/mopidy/frontends/mpd/protocol/audio_output.py index 6111332a..7147963a 100644 --- a/mopidy/frontends/mpd/protocol/audio_output.py +++ b/mopidy/frontends/mpd/protocol/audio_output.py @@ -1,7 +1,7 @@ -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNotImplemented -@handle_pattern(r'^disableoutput "(?P\d+)"$') +@handle_request(r'^disableoutput "(?P\d+)"$') def disableoutput(context, outputid): """ *musicpd.org, audio output section:* @@ -12,7 +12,7 @@ def disableoutput(context, outputid): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^enableoutput "(?P\d+)"$') +@handle_request(r'^enableoutput "(?P\d+)"$') def enableoutput(context, outputid): """ *musicpd.org, audio output section:* @@ -23,7 +23,7 @@ def enableoutput(context, outputid): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^outputs$') +@handle_request(r'^outputs$') def outputs(context): """ *musicpd.org, audio output section:* diff --git a/mopidy/frontends/mpd/protocol/command_list.py b/mopidy/frontends/mpd/protocol/command_list.py index f2c51578..37e5c93d 100644 --- a/mopidy/frontends/mpd/protocol/command_list.py +++ b/mopidy/frontends/mpd/protocol/command_list.py @@ -1,7 +1,7 @@ -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdUnknownCommand -@handle_pattern(r'^command_list_begin$') +@handle_request(r'^command_list_begin$') def command_list_begin(context): """ *musicpd.org, command list section:* @@ -21,7 +21,7 @@ def command_list_begin(context): context.dispatcher.command_list = [] context.dispatcher.command_list_ok = False -@handle_pattern(r'^command_list_end$') +@handle_request(r'^command_list_end$') def command_list_end(context): """See :meth:`command_list_begin()`.""" if context.dispatcher.command_list is False: @@ -43,7 +43,7 @@ def command_list_end(context): command_list_response.append(u'list_OK') return command_list_response -@handle_pattern(r'^command_list_ok_begin$') +@handle_request(r'^command_list_ok_begin$') def command_list_ok_begin(context): """See :meth:`command_list_begin()`.""" context.dispatcher.command_list = [] diff --git a/mopidy/frontends/mpd/protocol/connection.py b/mopidy/frontends/mpd/protocol/connection.py index 99944ac2..d5c2d80c 100644 --- a/mopidy/frontends/mpd/protocol/connection.py +++ b/mopidy/frontends/mpd/protocol/connection.py @@ -1,9 +1,9 @@ from mopidy import settings -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import (MpdPasswordError, MpdPermissionError) -@handle_pattern(r'^close$') +@handle_request(r'^close$') def close(context): """ *musicpd.org, connection section:* @@ -14,7 +14,7 @@ def close(context): """ context.session.close() -@handle_pattern(r'^kill$') +@handle_request(r'^kill$') def kill(context): """ *musicpd.org, connection section:* @@ -25,7 +25,7 @@ def kill(context): """ raise MpdPermissionError(command=u'kill') -@handle_pattern(r'^password "(?P[^"]+)"$') +@handle_request(r'^password "(?P[^"]+)"$') def password_(context, password): """ *musicpd.org, connection section:* @@ -40,7 +40,7 @@ def password_(context, password): else: raise MpdPasswordError(u'incorrect password', command=u'password') -@handle_pattern(r'^ping$') +@handle_request(r'^ping$') def ping(context): """ *musicpd.org, connection section:* diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index e73e0a9c..82e096a0 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -1,9 +1,9 @@ from mopidy.frontends.mpd.exceptions import (MpdArgError, MpdNoExistError, MpdNotImplemented) -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.translator import tracks_to_mpd_format -@handle_pattern(r'^add "(?P[^"]*)"$') +@handle_request(r'^add "(?P[^"]*)"$') def add(context, uri): """ *musicpd.org, current playlist section:* @@ -28,7 +28,7 @@ def add(context, uri): raise MpdNoExistError( u'directory or file not found', command=u'add') -@handle_pattern(r'^addid "(?P[^"]*)"( "(?P\d+)")*$') +@handle_request(r'^addid "(?P[^"]*)"( "(?P\d+)")*$') def addid(context, uri, songpos=None): """ *musicpd.org, current playlist section:* @@ -61,7 +61,7 @@ def addid(context, uri, songpos=None): at_position=songpos).get() return ('Id', cp_track[0]) -@handle_pattern(r'^delete "(?P\d+):(?P\d+)*"$') +@handle_request(r'^delete "(?P\d+):(?P\d+)*"$') def delete_range(context, start, end=None): """ *musicpd.org, current playlist section:* @@ -81,7 +81,7 @@ def delete_range(context, start, end=None): for (cpid, _) in cp_tracks: context.backend.current_playlist.remove(cpid=cpid) -@handle_pattern(r'^delete "(?P\d+)"$') +@handle_request(r'^delete "(?P\d+)"$') def delete_songpos(context, songpos): """See :meth:`delete_range`""" try: @@ -91,7 +91,7 @@ def delete_songpos(context, songpos): except IndexError: raise MpdArgError(u'Bad song index', command=u'delete') -@handle_pattern(r'^deleteid "(?P\d+)"$') +@handle_request(r'^deleteid "(?P\d+)"$') def deleteid(context, cpid): """ *musicpd.org, current playlist section:* @@ -108,7 +108,7 @@ def deleteid(context, cpid): except LookupError: raise MpdNoExistError(u'No such song', command=u'deleteid') -@handle_pattern(r'^clear$') +@handle_request(r'^clear$') def clear(context): """ *musicpd.org, current playlist section:* @@ -119,7 +119,7 @@ def clear(context): """ context.backend.current_playlist.clear() -@handle_pattern(r'^move "(?P\d+):(?P\d+)*" "(?P\d+)"$') +@handle_request(r'^move "(?P\d+):(?P\d+)*" "(?P\d+)"$') def move_range(context, start, to, end=None): """ *musicpd.org, current playlist section:* @@ -136,14 +136,14 @@ def move_range(context, start, to, end=None): to = int(to) context.backend.current_playlist.move(start, end, to) -@handle_pattern(r'^move "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^move "(?P\d+)" "(?P\d+)"$') def move_songpos(context, songpos, to): """See :meth:`move_range`.""" songpos = int(songpos) to = int(to) context.backend.current_playlist.move(songpos, songpos + 1, to) -@handle_pattern(r'^moveid "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^moveid "(?P\d+)" "(?P\d+)"$') def moveid(context, cpid, to): """ *musicpd.org, current playlist section:* @@ -161,7 +161,7 @@ def moveid(context, cpid, to): cp_track) context.backend.current_playlist.move(position, position + 1, to) -@handle_pattern(r'^playlist$') +@handle_request(r'^playlist$') def playlist(context): """ *musicpd.org, current playlist section:* @@ -176,8 +176,8 @@ def playlist(context): """ return playlistinfo(context) -@handle_pattern(r'^playlistfind (?P[^"]+) "(?P[^"]+)"$') -@handle_pattern(r'^playlistfind "(?P[^"]+)" "(?P[^"]+)"$') +@handle_request(r'^playlistfind (?P[^"]+) "(?P[^"]+)"$') +@handle_request(r'^playlistfind "(?P[^"]+)" "(?P[^"]+)"$') def playlistfind(context, tag, needle): """ *musicpd.org, current playlist section:* @@ -201,7 +201,7 @@ def playlistfind(context, tag, needle): return None raise MpdNotImplemented # TODO -@handle_pattern(r'^playlistid( "(?P\d+)")*$') +@handle_request(r'^playlistid( "(?P\d+)")*$') def playlistid(context, cpid=None): """ *musicpd.org, current playlist section:* @@ -226,9 +226,9 @@ def playlistid(context, cpid=None): return tracks_to_mpd_format( context.backend.current_playlist.tracks.get(), cpids=cpids) -@handle_pattern(r'^playlistinfo$') -@handle_pattern(r'^playlistinfo "(?P-?\d+)"$') -@handle_pattern(r'^playlistinfo "(?P\d+):(?P\d+)*"$') +@handle_request(r'^playlistinfo$') +@handle_request(r'^playlistinfo "(?P-?\d+)"$') +@handle_request(r'^playlistinfo "(?P\d+):(?P\d+)*"$') def playlistinfo(context, songpos=None, start=None, end=None): """ @@ -276,8 +276,8 @@ def playlistinfo(context, songpos=None, context.backend.current_playlist.tracks.get(), start, end, cpids=cpids) -@handle_pattern(r'^playlistsearch "(?P[^"]+)" "(?P[^"]+)"$') -@handle_pattern(r'^playlistsearch (?P\S+) "(?P[^"]+)"$') +@handle_request(r'^playlistsearch "(?P[^"]+)" "(?P[^"]+)"$') +@handle_request(r'^playlistsearch (?P\S+) "(?P[^"]+)"$') def playlistsearch(context, tag, needle): """ *musicpd.org, current playlist section:* @@ -294,8 +294,8 @@ def playlistsearch(context, tag, needle): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^plchanges (?P-?\d+)$') -@handle_pattern(r'^plchanges "(?P-?\d+)"$') +@handle_request(r'^plchanges (?P-?\d+)$') +@handle_request(r'^plchanges "(?P-?\d+)"$') def plchanges(context, version): """ *musicpd.org, current playlist section:* @@ -318,7 +318,7 @@ def plchanges(context, version): return tracks_to_mpd_format( context.backend.current_playlist.tracks.get(), cpids=cpids) -@handle_pattern(r'^plchangesposid "(?P\d+)"$') +@handle_request(r'^plchangesposid "(?P\d+)"$') def plchangesposid(context, version): """ *musicpd.org, current playlist section:* @@ -341,8 +341,8 @@ def plchangesposid(context, version): result.append((u'Id', cpid)) return result -@handle_pattern(r'^shuffle$') -@handle_pattern(r'^shuffle "(?P\d+):(?P\d+)*"$') +@handle_request(r'^shuffle$') +@handle_request(r'^shuffle "(?P\d+):(?P\d+)*"$') def shuffle(context, start=None, end=None): """ *musicpd.org, current playlist section:* @@ -358,7 +358,7 @@ def shuffle(context, start=None, end=None): end = int(end) context.backend.current_playlist.shuffle(start, end) -@handle_pattern(r'^swap "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^swap "(?P\d+)" "(?P\d+)"$') def swap(context, songpos1, songpos2): """ *musicpd.org, current playlist section:* @@ -379,7 +379,7 @@ def swap(context, songpos1, songpos2): context.backend.current_playlist.clear() context.backend.current_playlist.append(tracks) -@handle_pattern(r'^swapid "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^swapid "(?P\d+)" "(?P\d+)"$') def swapid(context, cpid1, cpid2): """ *musicpd.org, current playlist section:* diff --git a/mopidy/frontends/mpd/protocol/empty.py b/mopidy/frontends/mpd/protocol/empty.py index b84f08f4..0e418551 100644 --- a/mopidy/frontends/mpd/protocol/empty.py +++ b/mopidy/frontends/mpd/protocol/empty.py @@ -1,6 +1,6 @@ -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request -@handle_pattern(r'^$') +@handle_request(r'^$') def empty(context): """The original MPD server returns ``OK`` on an empty request.""" pass diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 0183d471..0343b3ab 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -1,7 +1,7 @@ import re import shlex -from mopidy.frontends.mpd.protocol import handle_pattern, stored_playlists +from mopidy.frontends.mpd.protocol import handle_request, stored_playlists from mopidy.frontends.mpd.exceptions import MpdArgError, MpdNotImplemented def _build_query(mpd_query): @@ -28,7 +28,7 @@ def _build_query(mpd_query): query[field] = [what] return query -@handle_pattern(r'^count "(?P[^"]+)" "(?P[^"]*)"$') +@handle_request(r'^count "(?P[^"]+)" "(?P[^"]*)"$') def count(context, tag, needle): """ *musicpd.org, music database section:* @@ -40,7 +40,7 @@ def count(context, tag, needle): """ return [('songs', 0), ('playtime', 0)] # TODO -@handle_pattern(r'^find ' +@handle_request(r'^find ' r'(?P("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ilename|' r'[Tt]itle|[Aa]ny)"? "[^"]+"\s?)+)$') def find(context, mpd_query): @@ -70,7 +70,7 @@ def find(context, mpd_query): query = _build_query(mpd_query) return context.backend.library.find_exact(**query).get().mpd_format() -@handle_pattern(r'^findadd ' +@handle_request(r'^findadd ' r'(?P("?([Aa]lbum|[Aa]rtist|[Ff]ilename|[Tt]itle|[Aa]ny)"? ' '"[^"]+"\s?)+)$') def findadd(context, query): @@ -86,7 +86,7 @@ def findadd(context, query): # TODO Add result to current playlist #result = context.find(query) -@handle_pattern(r'^list "?(?P([Aa]rtist|[Aa]lbum|[Dd]ate|[Gg]enre))"?' +@handle_request(r'^list "?(?P([Aa]rtist|[Aa]lbum|[Dd]ate|[Gg]enre))"?' '( (?P.*))?$') def list_(context, field, mpd_query=None): """ @@ -237,7 +237,7 @@ def _list_date(context, query): dates.add((u'Date', track.date.strftime('%Y-%m-%d'))) return dates -@handle_pattern(r'^listall "(?P[^"]+)"') +@handle_request(r'^listall "(?P[^"]+)"') def listall(context, uri): """ *musicpd.org, music database section:* @@ -248,7 +248,7 @@ def listall(context, uri): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^listallinfo "(?P[^"]+)"') +@handle_request(r'^listallinfo "(?P[^"]+)"') def listallinfo(context, uri): """ *musicpd.org, music database section:* @@ -260,8 +260,8 @@ def listallinfo(context, uri): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^lsinfo$') -@handle_pattern(r'^lsinfo "(?P[^"]*)"$') +@handle_request(r'^lsinfo$') +@handle_request(r'^lsinfo "(?P[^"]*)"$') def lsinfo(context, uri=None): """ *musicpd.org, music database section:* @@ -282,7 +282,7 @@ def lsinfo(context, uri=None): return stored_playlists.listplaylists(context) raise MpdNotImplemented # TODO -@handle_pattern(r'^rescan( "(?P[^"]+)")*$') +@handle_request(r'^rescan( "(?P[^"]+)")*$') def rescan(context, uri=None): """ *musicpd.org, music database section:* @@ -293,7 +293,7 @@ def rescan(context, uri=None): """ return update(context, uri, rescan_unmodified_files=True) -@handle_pattern(r'^search ' +@handle_request(r'^search ' r'(?P("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ilename|' r'[Tt]itle|[Aa]ny)"? "[^"]+"\s?)+)$') def search(context, mpd_query): @@ -326,7 +326,7 @@ def search(context, mpd_query): query = _build_query(mpd_query) return context.backend.library.search(**query).get().mpd_format() -@handle_pattern(r'^update( "(?P[^"]+)")*$') +@handle_request(r'^update( "(?P[^"]+)")*$') def update(context, uri=None, rescan_unmodified_files=False): """ *musicpd.org, music database section:* diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index b8646a8b..63cfe649 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -1,10 +1,10 @@ from mopidy.backends.base import PlaybackController -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import (MpdArgError, MpdNoExistError, MpdNotImplemented) -@handle_pattern(r'^consume (?P[01])$') -@handle_pattern(r'^consume "(?P[01])"$') +@handle_request(r'^consume (?P[01])$') +@handle_request(r'^consume "(?P[01])"$') def consume(context, state): """ *musicpd.org, playback section:* @@ -20,7 +20,7 @@ def consume(context, state): else: context.backend.playback.consume = False -@handle_pattern(r'^crossfade "(?P\d+)"$') +@handle_request(r'^crossfade "(?P\d+)"$') def crossfade(context, seconds): """ *musicpd.org, playback section:* @@ -32,7 +32,7 @@ def crossfade(context, seconds): seconds = int(seconds) raise MpdNotImplemented # TODO -@handle_pattern(r'^next$') +@handle_request(r'^next$') def next_(context): """ *musicpd.org, playback section:* @@ -89,8 +89,8 @@ def next_(context): """ return context.backend.playback.next().get() -@handle_pattern(r'^pause$') -@handle_pattern(r'^pause "(?P[01])"$') +@handle_request(r'^pause$') +@handle_request(r'^pause "(?P[01])"$') def pause(context, state=None): """ *musicpd.org, playback section:* @@ -115,7 +115,7 @@ def pause(context, state=None): else: context.backend.playback.resume() -@handle_pattern(r'^play$') +@handle_request(r'^play$') def play(context): """ The original MPD server resumes from the paused state on ``play`` @@ -123,8 +123,8 @@ def play(context): """ return context.backend.playback.play().get() -@handle_pattern(r'^playid "(?P\d+)"$') -@handle_pattern(r'^playid "(?P-1)"$') +@handle_request(r'^playid "(?P\d+)"$') +@handle_request(r'^playid "(?P-1)"$') def playid(context, cpid): """ *musicpd.org, playback section:* @@ -151,8 +151,8 @@ def playid(context, cpid): except LookupError: raise MpdNoExistError(u'No such song', command=u'playid') -@handle_pattern(r'^play (?P-?\d+)$') -@handle_pattern(r'^play "(?P-?\d+)"$') +@handle_request(r'^play (?P-?\d+)$') +@handle_request(r'^play "(?P-?\d+)"$') def playpos(context, songpos): """ *musicpd.org, playback section:* @@ -197,7 +197,7 @@ def _play_minus_one(context): else: return # Fail silently -@handle_pattern(r'^previous$') +@handle_request(r'^previous$') def previous(context): """ *musicpd.org, playback section:* @@ -243,8 +243,8 @@ def previous(context): """ return context.backend.playback.previous().get() -@handle_pattern(r'^random (?P[01])$') -@handle_pattern(r'^random "(?P[01])"$') +@handle_request(r'^random (?P[01])$') +@handle_request(r'^random "(?P[01])"$') def random(context, state): """ *musicpd.org, playback section:* @@ -258,8 +258,8 @@ def random(context, state): else: context.backend.playback.random = False -@handle_pattern(r'^repeat (?P[01])$') -@handle_pattern(r'^repeat "(?P[01])"$') +@handle_request(r'^repeat (?P[01])$') +@handle_request(r'^repeat "(?P[01])"$') def repeat(context, state): """ *musicpd.org, playback section:* @@ -273,7 +273,7 @@ def repeat(context, state): else: context.backend.playback.repeat = False -@handle_pattern(r'^replay_gain_mode "(?P(off|track|album))"$') +@handle_request(r'^replay_gain_mode "(?P(off|track|album))"$') def replay_gain_mode(context, mode): """ *musicpd.org, playback section:* @@ -289,7 +289,7 @@ def replay_gain_mode(context, mode): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^replay_gain_status$') +@handle_request(r'^replay_gain_status$') def replay_gain_status(context): """ *musicpd.org, playback section:* @@ -301,8 +301,8 @@ def replay_gain_status(context): """ return u'off' # TODO -@handle_pattern(r'^seek (?P\d+) (?P\d+)$') -@handle_pattern(r'^seek "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^seek (?P\d+) (?P\d+)$') +@handle_request(r'^seek "(?P\d+)" "(?P\d+)"$') def seek(context, songpos, seconds): """ *musicpd.org, playback section:* @@ -320,7 +320,7 @@ def seek(context, songpos, seconds): playpos(context, songpos) context.backend.playback.seek(int(seconds) * 1000) -@handle_pattern(r'^seekid "(?P\d+)" "(?P\d+)"$') +@handle_request(r'^seekid "(?P\d+)" "(?P\d+)"$') def seekid(context, cpid, seconds): """ *musicpd.org, playback section:* @@ -333,8 +333,8 @@ def seekid(context, cpid, seconds): playid(context, cpid) context.backend.playback.seek(int(seconds) * 1000) -@handle_pattern(r'^setvol (?P[-+]*\d+)$') -@handle_pattern(r'^setvol "(?P[-+]*\d+)"$') +@handle_request(r'^setvol (?P[-+]*\d+)$') +@handle_request(r'^setvol "(?P[-+]*\d+)"$') def setvol(context, volume): """ *musicpd.org, playback section:* @@ -354,8 +354,8 @@ def setvol(context, volume): volume = 100 context.mixer.volume = volume -@handle_pattern(r'^single (?P[01])$') -@handle_pattern(r'^single "(?P[01])"$') +@handle_request(r'^single (?P[01])$') +@handle_request(r'^single "(?P[01])"$') def single(context, state): """ *musicpd.org, playback section:* @@ -371,7 +371,7 @@ def single(context, state): else: context.backend.playback.single = False -@handle_pattern(r'^stop$') +@handle_request(r'^stop$') def stop(context): """ *musicpd.org, playback section:* diff --git a/mopidy/frontends/mpd/protocol/reflection.py b/mopidy/frontends/mpd/protocol/reflection.py index 6e0a2f6c..94d8ce83 100644 --- a/mopidy/frontends/mpd/protocol/reflection.py +++ b/mopidy/frontends/mpd/protocol/reflection.py @@ -1,7 +1,7 @@ -from mopidy.frontends.mpd.protocol import handle_pattern, mpd_commands +from mopidy.frontends.mpd.protocol import handle_request, mpd_commands from mopidy.frontends.mpd.exceptions import MpdNotImplemented -@handle_pattern(r'^commands$') +@handle_request(r'^commands$') def commands(context): """ *musicpd.org, reflection section:* @@ -30,7 +30,7 @@ def commands(context): return [('command', command_name) for command_name in sorted(command_names)] -@handle_pattern(r'^decoders$') +@handle_request(r'^decoders$') def decoders(context): """ *musicpd.org, reflection section:* @@ -49,7 +49,7 @@ def decoders(context): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^notcommands$') +@handle_request(r'^notcommands$') def notcommands(context): """ *musicpd.org, reflection section:* @@ -70,7 +70,7 @@ def notcommands(context): return [('command', command_name) for command_name in sorted(command_names)] -@handle_pattern(r'^tagtypes$') +@handle_request(r'^tagtypes$') def tagtypes(context): """ *musicpd.org, reflection section:* @@ -81,7 +81,7 @@ def tagtypes(context): """ pass # TODO -@handle_pattern(r'^urlhandlers$') +@handle_request(r'^urlhandlers$') def urlhandlers(context): """ *musicpd.org, reflection section:* diff --git a/mopidy/frontends/mpd/protocol/status.py b/mopidy/frontends/mpd/protocol/status.py index 4f9e00cd..58fefa11 100644 --- a/mopidy/frontends/mpd/protocol/status.py +++ b/mopidy/frontends/mpd/protocol/status.py @@ -1,8 +1,8 @@ from mopidy.backends.base import PlaybackController -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNotImplemented -@handle_pattern(r'^clearerror$') +@handle_request(r'^clearerror$') def clearerror(context): """ *musicpd.org, status section:* @@ -14,7 +14,7 @@ def clearerror(context): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^currentsong$') +@handle_request(r'^currentsong$') def currentsong(context): """ *musicpd.org, status section:* @@ -30,8 +30,8 @@ def currentsong(context): position=context.backend.playback.current_playlist_position.get(), cpid=current_cp_track[0]) -@handle_pattern(r'^idle$') -@handle_pattern(r'^idle (?P.+)$') +@handle_request(r'^idle$') +@handle_request(r'^idle (?P.+)$') def idle(context, subsystems=None): """ *musicpd.org, status section:* @@ -67,12 +67,12 @@ def idle(context, subsystems=None): """ pass # TODO -@handle_pattern(r'^noidle$') +@handle_request(r'^noidle$') def noidle(context): """See :meth:`_status_idle`.""" pass # TODO -@handle_pattern(r'^stats$') +@handle_request(r'^stats$') def stats(context): """ *musicpd.org, status section:* @@ -98,7 +98,7 @@ def stats(context): 'playtime': 0, # TODO } -@handle_pattern(r'^status$') +@handle_request(r'^status$') def status(context): """ *musicpd.org, status section:* diff --git a/mopidy/frontends/mpd/protocol/stickers.py b/mopidy/frontends/mpd/protocol/stickers.py index c1b7be16..c3663ff1 100644 --- a/mopidy/frontends/mpd/protocol/stickers.py +++ b/mopidy/frontends/mpd/protocol/stickers.py @@ -1,7 +1,7 @@ -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNotImplemented -@handle_pattern(r'^sticker delete "(?P[^"]+)" ' +@handle_request(r'^sticker delete "(?P[^"]+)" ' r'"(?P[^"]+)"( "(?P[^"]+)")*$') def sticker_delete(context, field, uri, name=None): """ @@ -14,7 +14,7 @@ def sticker_delete(context, field, uri, name=None): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^sticker find "(?P[^"]+)" "(?P[^"]+)" ' +@handle_request(r'^sticker find "(?P[^"]+)" "(?P[^"]+)" ' r'"(?P[^"]+)"$') def sticker_find(context, field, uri, name): """ @@ -28,7 +28,7 @@ def sticker_find(context, field, uri, name): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^sticker get "(?P[^"]+)" "(?P[^"]+)" ' +@handle_request(r'^sticker get "(?P[^"]+)" "(?P[^"]+)" ' r'"(?P[^"]+)"$') def sticker_get(context, field, uri, name): """ @@ -40,7 +40,7 @@ def sticker_get(context, field, uri, name): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^sticker list "(?P[^"]+)" "(?P[^"]+)"$') +@handle_request(r'^sticker list "(?P[^"]+)" "(?P[^"]+)"$') def sticker_list(context, field, uri): """ *musicpd.org, sticker section:* @@ -51,7 +51,7 @@ def sticker_list(context, field, uri): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^sticker set "(?P[^"]+)" "(?P[^"]+)" ' +@handle_request(r'^sticker set "(?P[^"]+)" "(?P[^"]+)" ' r'"(?P[^"]+)" "(?P[^"]+)"$') def sticker_set(context, field, uri, name, value): """ diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 764a8e12..0a157f66 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -1,9 +1,9 @@ import datetime as dt -from mopidy.frontends.mpd.protocol import handle_pattern +from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNoExistError, MpdNotImplemented -@handle_pattern(r'^listplaylist "(?P[^"]+)"$') +@handle_request(r'^listplaylist "(?P[^"]+)"$') def listplaylist(context, name): """ *musicpd.org, stored playlists section:* @@ -24,7 +24,7 @@ def listplaylist(context, name): except LookupError: raise MpdNoExistError(u'No such playlist', command=u'listplaylist') -@handle_pattern(r'^listplaylistinfo "(?P[^"]+)"$') +@handle_request(r'^listplaylistinfo "(?P[^"]+)"$') def listplaylistinfo(context, name): """ *musicpd.org, stored playlists section:* @@ -45,7 +45,7 @@ def listplaylistinfo(context, name): raise MpdNoExistError( u'No such playlist', command=u'listplaylistinfo') -@handle_pattern(r'^listplaylists$') +@handle_request(r'^listplaylists$') def listplaylists(context): """ *musicpd.org, stored playlists section:* @@ -79,7 +79,7 @@ def listplaylists(context): result.append((u'Last-Modified', last_modified)) return result -@handle_pattern(r'^load "(?P[^"]+)"$') +@handle_request(r'^load "(?P[^"]+)"$') def load(context, name): """ *musicpd.org, stored playlists section:* @@ -98,7 +98,7 @@ def load(context, name): except LookupError: raise MpdNoExistError(u'No such playlist', command=u'load') -@handle_pattern(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') +@handle_request(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') def playlistadd(context, name, uri): """ *musicpd.org, stored playlists section:* @@ -111,7 +111,7 @@ def playlistadd(context, name, uri): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^playlistclear "(?P[^"]+)"$') +@handle_request(r'^playlistclear "(?P[^"]+)"$') def playlistclear(context, name): """ *musicpd.org, stored playlists section:* @@ -122,7 +122,7 @@ def playlistclear(context, name): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^playlistdelete "(?P[^"]+)" "(?P\d+)"$') +@handle_request(r'^playlistdelete "(?P[^"]+)" "(?P\d+)"$') def playlistdelete(context, name, songpos): """ *musicpd.org, stored playlists section:* @@ -133,7 +133,7 @@ def playlistdelete(context, name, songpos): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^playlistmove "(?P[^"]+)" ' +@handle_request(r'^playlistmove "(?P[^"]+)" ' r'"(?P\d+)" "(?P\d+)"$') def playlistmove(context, name, from_pos, to_pos): """ @@ -152,7 +152,7 @@ def playlistmove(context, name, from_pos, to_pos): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^rename "(?P[^"]+)" "(?P[^"]+)"$') +@handle_request(r'^rename "(?P[^"]+)" "(?P[^"]+)"$') def rename(context, old_name, new_name): """ *musicpd.org, stored playlists section:* @@ -163,7 +163,7 @@ def rename(context, old_name, new_name): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^rm "(?P[^"]+)"$') +@handle_request(r'^rm "(?P[^"]+)"$') def rm(context, name): """ *musicpd.org, stored playlists section:* @@ -174,7 +174,7 @@ def rm(context, name): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^save "(?P[^"]+)"$') +@handle_request(r'^save "(?P[^"]+)"$') def save(context, name): """ *musicpd.org, stored playlists section:* diff --git a/tests/frontends/mpd/dispatcher_test.py b/tests/frontends/mpd/dispatcher_test.py index 7dd70834..7708ce31 100644 --- a/tests/frontends/mpd/dispatcher_test.py +++ b/tests/frontends/mpd/dispatcher_test.py @@ -3,7 +3,7 @@ import unittest from mopidy.backends.dummy import DummyBackend from mopidy.frontends.mpd.dispatcher import MpdDispatcher from mopidy.frontends.mpd.exceptions import MpdAckError -from mopidy.frontends.mpd.protocol import request_handlers, handle_pattern +from mopidy.frontends.mpd.protocol import request_handlers, handle_request from mopidy.mixers.dummy import DummyMixer class MpdDispatcherTest(unittest.TestCase): @@ -19,8 +19,8 @@ class MpdDispatcherTest(unittest.TestCase): def test_register_same_pattern_twice_fails(self): func = lambda: None try: - handle_pattern('a pattern')(func) - handle_pattern('a pattern')(func) + handle_request('a pattern')(func) + handle_request('a pattern')(func) self.fail('Registering a pattern twice shoulde raise ValueError') except ValueError: pass