mpd: Compile protocol matching regexpes

This caused a single test failure, which was fixed.
This commit is contained in:
Stein Magnus Jodal 2012-11-21 01:13:05 +01:00
parent 39b9429dfc
commit 09d7279b6b
2 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -232,7 +232,6 @@ def playlistid(context, tlid=None):
@handle_request(r'^playlistinfo$')
@handle_request(r'^playlistinfo "-1"$')
@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):
@ -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]