Merge remote-tracking branch 'UncommonGoods/develop' into develop

This commit is contained in:
Thomas Adamcik 2014-01-24 19:31:25 +01:00
commit da724e6b77
4 changed files with 16 additions and 30 deletions

View File

@ -229,8 +229,8 @@ class MpdContext(object):
#: The current :class:`mopidy.mpd.MpdSession`. #: The current :class:`mopidy.mpd.MpdSession`.
session = None session = None
#: The Mopidy configuration. #: The MPD password
config = None password = None
#: The Mopidy core API. An instance of :class:`mopidy.core.Core`. #: The Mopidy core API. An instance of :class:`mopidy.core.Core`.
core = None core = None
@ -246,7 +246,8 @@ class MpdContext(object):
def __init__(self, dispatcher, session=None, config=None, core=None): def __init__(self, dispatcher, session=None, config=None, core=None):
self.dispatcher = dispatcher self.dispatcher = dispatcher
self.session = session self.session = session
self.config = config if config is not None:
self.password = config['mpd']['password']
self.core = core self.core = core
self.events = set() self.events = set()
self.subscriptions = set() self.subscriptions = set()

View File

@ -39,7 +39,7 @@ def password(context, password):
This is used for authentication with the server. ``PASSWORD`` is This is used for authentication with the server. ``PASSWORD`` is
simply the plaintext password. simply the plaintext password.
""" """
if password == context.config['mpd']['password']: if password == context.password:
context.dispatcher.authenticated = True context.dispatcher.authenticated = True
else: else:
raise MpdPasswordError('incorrect password') raise MpdPasswordError('incorrect password')

View File

@ -62,30 +62,15 @@ SEARCH_QUERY = r"""
$ $
""" """
# TODO Would be nice to get ("?)...\1 working for the quotes here SEARCH_PAIR_WITH_GROUPS = r"""
SEARCH_PAIR_WITHOUT_GROUPS = r""" ("?) # Optional quote around the field type
\b # Only begin matching at word bundaries \b # Only begin matching at word bundaries
"? # Optional quote around the field type ( # A capturing group for the field type
(?: # A non-capturing group for the field type
""" + SEARCH_FIELDS + """ """ + SEARCH_FIELDS + """
) )
"? # End of optional quote around the field type \\1 # End of optional quote around the field type
\ # A single space \ # A single space
"[^"]+" # Matching a quoted search string "([^"]+)" # Capturing a quoted search string
"""
SEARCH_PAIR_WITHOUT_GROUPS_RE = re.compile(
SEARCH_PAIR_WITHOUT_GROUPS, flags=(re.UNICODE | re.VERBOSE))
# TODO Would be nice to get ("?)...\1 working for the quotes here
SEARCH_PAIR_WITH_GROUPS = r"""
\b # Only begin matching at word bundaries
"? # Optional quote around the field type
(?P<field>( # A capturing group for the field type
""" + SEARCH_FIELDS + """
))
"? # End of optional quote around the field type
\ # A single space
"(?P<what>[^"]+)" # Capturing a quoted search string
""" """
SEARCH_PAIR_WITH_GROUPS_RE = re.compile( SEARCH_PAIR_WITH_GROUPS_RE = re.compile(
SEARCH_PAIR_WITH_GROUPS, flags=(re.UNICODE | re.VERBOSE)) SEARCH_PAIR_WITH_GROUPS, flags=(re.UNICODE | re.VERBOSE))
@ -99,18 +84,18 @@ def _query_from_mpd_search_format(mpd_query):
:param mpd_query: the MPD search query :param mpd_query: the MPD search query
:type mpd_query: string :type mpd_query: string
""" """
pairs = SEARCH_PAIR_WITHOUT_GROUPS_RE.findall(mpd_query) matches = SEARCH_PAIR_WITH_GROUPS_RE.findall(mpd_query)
query = {} query = {}
for pair in pairs: # discard first field, which just captures optional quote
m = SEARCH_PAIR_WITH_GROUPS_RE.match(pair) for _, field, what in matches:
field = m.groupdict()['field'].lower() field = field.lower()
if field == 'title': if field == 'title':
field = 'track_name' field = 'track_name'
elif field == 'track': elif field == 'track':
field = 'track_no' field = 'track_no'
elif field in ('file', 'filename'): elif field in ('file', 'filename'):
field = 'uri' field = 'uri'
what = m.groupdict()['what']
if not what: if not what:
raise ValueError raise ValueError
if field in query: if field in query:

View File

@ -12,7 +12,7 @@ from tests.mpd import protocol
class QueryFromMpdSearchFormatTest(unittest.TestCase): class QueryFromMpdSearchFormatTest(unittest.TestCase):
def test_dates_are_extracted(self): def test_dates_are_extracted(self):
result = music_db._query_from_mpd_search_format( result = music_db._query_from_mpd_search_format(
'Date "1974-01-02" Date "1975"') 'Date "1974-01-02" "Date" "1975"')
self.assertEqual(result['date'][0], '1974-01-02') self.assertEqual(result['date'][0], '1974-01-02')
self.assertEqual(result['date'][1], '1975') self.assertEqual(result['date'][1], '1975')