From c5f64648de015997f81a75095da906b3146711e5 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 18 Nov 2013 00:48:58 +0100 Subject: [PATCH] mpd: Rename constants --- mopidy/frontends/mpd/protocol/music_db.py | 42 +++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index b94448b0..faa0af5e 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -10,7 +10,7 @@ from mopidy.frontends.mpd.exceptions import MpdArgError, MpdNotImplemented from mopidy.frontends.mpd.protocol import handle_request, stored_playlists -QUERY_FIELDS = r""" +SEARCH_FIELDS = r""" [Aa]lbum | [Aa]rtist | [Aa]lbumartist @@ -26,12 +26,12 @@ QUERY_FIELDS = r""" | [Aa]ny """ -QUERY_RE = r""" +SEARCH_QUERY = r""" (?P ( "? # Optional quote around the field type - ( -""" + QUERY_FIELDS + """ + (?: +""" + SEARCH_FIELDS + """ ) "? # End of optional quote around the field type \ # A single space @@ -42,27 +42,31 @@ QUERY_RE = r""" $ """ -MPD_SEARCH_QUERY_RE = re.compile(r""" +SEARCH_PAIR_WITHOUT_GROUPS = r""" \b # Only begin matching at word bundaries "? # Optional quote around the field type (?: # A non-capturing group for the field type -""" + QUERY_FIELDS + """ +""" + SEARCH_FIELDS + """ ) "? # End of optional quote around the field type \ # A single space "[^"]+" # Matching a quoted search string -""", flags=(re.UNICODE | re.VERBOSE)) +""" +SEARCH_PAIR_WITHOUT_GROUPS_RE = re.compile( + SEARCH_PAIR_WITHOUT_GROUPS, flags=(re.UNICODE | re.VERBOSE)) -MPD_SEARCH_QUERY_PART_RE = re.compile(r""" +SEARCH_PAIR_WITH_GROUPS = r""" \b # Only begin matching at word bundaries "? # Optional quote around the field type (?P( # A capturing group for the field type -""" + QUERY_FIELDS + """ +""" + SEARCH_FIELDS + """ )) "? # End of optional quote around the field type \ # A single space "(?P[^"]+)" # Capturing a quoted search string -""", flags=(re.UNICODE | re.VERBOSE)) +""" +SEARCH_PAIR_WITH_GROUPS_RE = re.compile( + SEARCH_PAIR_WITH_GROUPS, flags=(re.UNICODE | re.VERBOSE)) def _query_from_mpd_search_format(mpd_query): @@ -73,10 +77,10 @@ def _query_from_mpd_search_format(mpd_query): :param mpd_query: the MPD search query :type mpd_query: string """ - query_parts = MPD_SEARCH_QUERY_RE.findall(mpd_query) + pairs = SEARCH_PAIR_WITHOUT_GROUPS_RE.findall(mpd_query) query = {} - for query_part in query_parts: - m = MPD_SEARCH_QUERY_PART_RE.match(query_part) + for pair in pairs: + m = SEARCH_PAIR_WITH_GROUPS_RE.match(pair) field = m.groupdict()['field'].lower() if field == 'title': field = 'track_name' @@ -119,7 +123,7 @@ def _artist_as_track(artist): artists=[artist]) -@handle_request(r'count\ ' + QUERY_RE) +@handle_request(r'count\ ' + SEARCH_QUERY) def count(context, mpd_query): """ *musicpd.org, music database section:* @@ -146,7 +150,7 @@ def count(context, mpd_query): ] -@handle_request(r'find\ ' + QUERY_RE) +@handle_request(r'find\ ' + SEARCH_QUERY) def find(context, mpd_query): """ *musicpd.org, music database section:* @@ -191,7 +195,7 @@ def find(context, mpd_query): return translator.tracks_to_mpd_format(result_tracks) -@handle_request(r'findadd\ ' + QUERY_RE) +@handle_request(r'findadd\ ' + SEARCH_QUERY) def findadd(context, mpd_query): """ *musicpd.org, music database section:* @@ -446,7 +450,7 @@ def rescan(context, uri=None): return update(context, uri, rescan_unmodified_files=True) -@handle_request(r'search\ ' + QUERY_RE) +@handle_request(r'search\ ' + SEARCH_QUERY) def search(context, mpd_query): """ *musicpd.org, music database section:* @@ -485,7 +489,7 @@ def search(context, mpd_query): return translator.tracks_to_mpd_format(artists + albums + tracks) -@handle_request(r'searchadd\ ' + QUERY_RE) +@handle_request(r'searchadd\ ' + SEARCH_QUERY) def searchadd(context, mpd_query): """ *musicpd.org, music database section:* @@ -506,7 +510,7 @@ def searchadd(context, mpd_query): context.core.tracklist.add(_get_tracks(results)) -@handle_request(r'searchaddpl\ "(?P[^"]+)"\ ' + QUERY_RE) +@handle_request(r'searchaddpl\ "(?P[^"]+)"\ ' + SEARCH_QUERY) def searchaddpl(context, playlist_name, mpd_query): """ *musicpd.org, music database section:*