Rename handle_pattern decorator to handle_request
This commit is contained in:
parent
a08885bb95
commit
e68d715d3e
@ -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<what>.+)$')
|
||||
@handle_request('^do (?P<what>.+)$')
|
||||
def do(what):
|
||||
...
|
||||
|
||||
|
||||
@ -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<outputid>\d+)"$')
|
||||
@handle_request(r'^disableoutput "(?P<outputid>\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<outputid>\d+)"$')
|
||||
@handle_request(r'^enableoutput "(?P<outputid>\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:*
|
||||
|
||||
@ -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 = []
|
||||
|
||||
@ -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<password>[^"]+)"$')
|
||||
@handle_request(r'^password "(?P<password>[^"]+)"$')
|
||||
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:*
|
||||
|
||||
@ -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<uri>[^"]*)"$')
|
||||
@handle_request(r'^add "(?P<uri>[^"]*)"$')
|
||||
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<uri>[^"]*)"( "(?P<songpos>\d+)")*$')
|
||||
@handle_request(r'^addid "(?P<uri>[^"]*)"( "(?P<songpos>\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<start>\d+):(?P<end>\d+)*"$')
|
||||
@handle_request(r'^delete "(?P<start>\d+):(?P<end>\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<songpos>\d+)"$')
|
||||
@handle_request(r'^delete "(?P<songpos>\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<cpid>\d+)"$')
|
||||
@handle_request(r'^deleteid "(?P<cpid>\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<start>\d+):(?P<end>\d+)*" "(?P<to>\d+)"$')
|
||||
@handle_request(r'^move "(?P<start>\d+):(?P<end>\d+)*" "(?P<to>\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<songpos>\d+)" "(?P<to>\d+)"$')
|
||||
@handle_request(r'^move "(?P<songpos>\d+)" "(?P<to>\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<cpid>\d+)" "(?P<to>\d+)"$')
|
||||
@handle_request(r'^moveid "(?P<cpid>\d+)" "(?P<to>\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<tag>[^"]+) "(?P<needle>[^"]+)"$')
|
||||
@handle_pattern(r'^playlistfind "(?P<tag>[^"]+)" "(?P<needle>[^"]+)"$')
|
||||
@handle_request(r'^playlistfind (?P<tag>[^"]+) "(?P<needle>[^"]+)"$')
|
||||
@handle_request(r'^playlistfind "(?P<tag>[^"]+)" "(?P<needle>[^"]+)"$')
|
||||
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<cpid>\d+)")*$')
|
||||
@handle_request(r'^playlistid( "(?P<cpid>\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<songpos>-?\d+)"$')
|
||||
@handle_pattern(r'^playlistinfo "(?P<start>\d+):(?P<end>\d+)*"$')
|
||||
@handle_request(r'^playlistinfo$')
|
||||
@handle_request(r'^playlistinfo "(?P<songpos>-?\d+)"$')
|
||||
@handle_request(r'^playlistinfo "(?P<start>\d+):(?P<end>\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<tag>[^"]+)" "(?P<needle>[^"]+)"$')
|
||||
@handle_pattern(r'^playlistsearch (?P<tag>\S+) "(?P<needle>[^"]+)"$')
|
||||
@handle_request(r'^playlistsearch "(?P<tag>[^"]+)" "(?P<needle>[^"]+)"$')
|
||||
@handle_request(r'^playlistsearch (?P<tag>\S+) "(?P<needle>[^"]+)"$')
|
||||
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<version>-?\d+)$')
|
||||
@handle_pattern(r'^plchanges "(?P<version>-?\d+)"$')
|
||||
@handle_request(r'^plchanges (?P<version>-?\d+)$')
|
||||
@handle_request(r'^plchanges "(?P<version>-?\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<version>\d+)"$')
|
||||
@handle_request(r'^plchangesposid "(?P<version>\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<start>\d+):(?P<end>\d+)*"$')
|
||||
@handle_request(r'^shuffle$')
|
||||
@handle_request(r'^shuffle "(?P<start>\d+):(?P<end>\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<songpos1>\d+)" "(?P<songpos2>\d+)"$')
|
||||
@handle_request(r'^swap "(?P<songpos1>\d+)" "(?P<songpos2>\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<cpid1>\d+)" "(?P<cpid2>\d+)"$')
|
||||
@handle_request(r'^swapid "(?P<cpid1>\d+)" "(?P<cpid2>\d+)"$')
|
||||
def swapid(context, cpid1, cpid2):
|
||||
"""
|
||||
*musicpd.org, current playlist section:*
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<tag>[^"]+)" "(?P<needle>[^"]*)"$')
|
||||
@handle_request(r'^count "(?P<tag>[^"]+)" "(?P<needle>[^"]*)"$')
|
||||
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<mpd_query>("?([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<query>("?([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<field>([Aa]rtist|[Aa]lbum|[Dd]ate|[Gg]enre))"?'
|
||||
@handle_request(r'^list "?(?P<field>([Aa]rtist|[Aa]lbum|[Dd]ate|[Gg]enre))"?'
|
||||
'( (?P<mpd_query>.*))?$')
|
||||
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<uri>[^"]+)"')
|
||||
@handle_request(r'^listall "(?P<uri>[^"]+)"')
|
||||
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<uri>[^"]+)"')
|
||||
@handle_request(r'^listallinfo "(?P<uri>[^"]+)"')
|
||||
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<uri>[^"]*)"$')
|
||||
@handle_request(r'^lsinfo$')
|
||||
@handle_request(r'^lsinfo "(?P<uri>[^"]*)"$')
|
||||
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<uri>[^"]+)")*$')
|
||||
@handle_request(r'^rescan( "(?P<uri>[^"]+)")*$')
|
||||
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<mpd_query>("?([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<uri>[^"]+)")*$')
|
||||
@handle_request(r'^update( "(?P<uri>[^"]+)")*$')
|
||||
def update(context, uri=None, rescan_unmodified_files=False):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
@ -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<state>[01])$')
|
||||
@handle_pattern(r'^consume "(?P<state>[01])"$')
|
||||
@handle_request(r'^consume (?P<state>[01])$')
|
||||
@handle_request(r'^consume "(?P<state>[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<seconds>\d+)"$')
|
||||
@handle_request(r'^crossfade "(?P<seconds>\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<state>[01])"$')
|
||||
@handle_request(r'^pause$')
|
||||
@handle_request(r'^pause "(?P<state>[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<cpid>\d+)"$')
|
||||
@handle_pattern(r'^playid "(?P<cpid>-1)"$')
|
||||
@handle_request(r'^playid "(?P<cpid>\d+)"$')
|
||||
@handle_request(r'^playid "(?P<cpid>-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<songpos>-?\d+)$')
|
||||
@handle_pattern(r'^play "(?P<songpos>-?\d+)"$')
|
||||
@handle_request(r'^play (?P<songpos>-?\d+)$')
|
||||
@handle_request(r'^play "(?P<songpos>-?\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<state>[01])$')
|
||||
@handle_pattern(r'^random "(?P<state>[01])"$')
|
||||
@handle_request(r'^random (?P<state>[01])$')
|
||||
@handle_request(r'^random "(?P<state>[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<state>[01])$')
|
||||
@handle_pattern(r'^repeat "(?P<state>[01])"$')
|
||||
@handle_request(r'^repeat (?P<state>[01])$')
|
||||
@handle_request(r'^repeat "(?P<state>[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<mode>(off|track|album))"$')
|
||||
@handle_request(r'^replay_gain_mode "(?P<mode>(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<songpos>\d+) (?P<seconds>\d+)$')
|
||||
@handle_pattern(r'^seek "(?P<songpos>\d+)" "(?P<seconds>\d+)"$')
|
||||
@handle_request(r'^seek (?P<songpos>\d+) (?P<seconds>\d+)$')
|
||||
@handle_request(r'^seek "(?P<songpos>\d+)" "(?P<seconds>\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<cpid>\d+)" "(?P<seconds>\d+)"$')
|
||||
@handle_request(r'^seekid "(?P<cpid>\d+)" "(?P<seconds>\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<volume>[-+]*\d+)$')
|
||||
@handle_pattern(r'^setvol "(?P<volume>[-+]*\d+)"$')
|
||||
@handle_request(r'^setvol (?P<volume>[-+]*\d+)$')
|
||||
@handle_request(r'^setvol "(?P<volume>[-+]*\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<state>[01])$')
|
||||
@handle_pattern(r'^single "(?P<state>[01])"$')
|
||||
@handle_request(r'^single (?P<state>[01])$')
|
||||
@handle_request(r'^single "(?P<state>[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:*
|
||||
|
||||
@ -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:*
|
||||
|
||||
@ -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<subsystems>.+)$')
|
||||
@handle_request(r'^idle$')
|
||||
@handle_request(r'^idle (?P<subsystems>.+)$')
|
||||
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:*
|
||||
|
||||
@ -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<field>[^"]+)" '
|
||||
@handle_request(r'^sticker delete "(?P<field>[^"]+)" '
|
||||
r'"(?P<uri>[^"]+)"( "(?P<name>[^"]+)")*$')
|
||||
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<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_request(r'^sticker find "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)"$')
|
||||
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<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_request(r'^sticker get "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)"$')
|
||||
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<field>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
@handle_request(r'^sticker list "(?P<field>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
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<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_request(r'^sticker set "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)" "(?P<value>[^"]+)"$')
|
||||
def sticker_set(context, field, uri, name, value):
|
||||
"""
|
||||
|
||||
@ -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<name>[^"]+)"$')
|
||||
@handle_request(r'^listplaylist "(?P<name>[^"]+)"$')
|
||||
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<name>[^"]+)"$')
|
||||
@handle_request(r'^listplaylistinfo "(?P<name>[^"]+)"$')
|
||||
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<name>[^"]+)"$')
|
||||
@handle_request(r'^load "(?P<name>[^"]+)"$')
|
||||
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<name>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
@handle_request(r'^playlistadd "(?P<name>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
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<name>[^"]+)"$')
|
||||
@handle_request(r'^playlistclear "(?P<name>[^"]+)"$')
|
||||
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<name>[^"]+)" "(?P<songpos>\d+)"$')
|
||||
@handle_request(r'^playlistdelete "(?P<name>[^"]+)" "(?P<songpos>\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<name>[^"]+)" '
|
||||
@handle_request(r'^playlistmove "(?P<name>[^"]+)" '
|
||||
r'"(?P<from_pos>\d+)" "(?P<to_pos>\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<old_name>[^"]+)" "(?P<new_name>[^"]+)"$')
|
||||
@handle_request(r'^rename "(?P<old_name>[^"]+)" "(?P<new_name>[^"]+)"$')
|
||||
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<name>[^"]+)"$')
|
||||
@handle_request(r'^rm "(?P<name>[^"]+)"$')
|
||||
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<name>[^"]+)"$')
|
||||
@handle_request(r'^save "(?P<name>[^"]+)"$')
|
||||
def save(context, name):
|
||||
"""
|
||||
*musicpd.org, stored playlists section:*
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user