From 7674775718f54b49b765f19d45202637ec41c569 Mon Sep 17 00:00:00 2001 From: Johannes Knutsen Date: Mon, 16 Aug 2010 22:34:00 +0200 Subject: [PATCH] Don't call lookup on backends with uris they don't support --- mopidy/frontends/mpd/protocol/current_playlist.py | 14 +++++++++----- tests/frontends/mpd/current_playlist_test.py | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 17b019e9..0dab4b79 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -11,11 +11,15 @@ def add(frontend, uri): Adds the file ``URI`` to the playlist (directories add recursively). ``URI`` can also be a single file. """ - track = frontend.backend.library.lookup(uri) - if track is None: - raise MpdNoExistError( - u'directory or file not found', command=u'add') - frontend.backend.current_playlist.add(track) + for handler_prefix in frontend.backend.uri_handlers: + if uri.startswith(handler_prefix): + track = frontend.backend.library.lookup(uri) + if track is not None: + frontend.backend.current_playlist.add(track) + return + + raise MpdNoExistError( + u'directory or file not found', command=u'add') @handle_pattern(r'^addid "(?P[^"]*)"( "(?P\d+)")*$') def addid(frontend, uri, songpos=None): diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index 6b5c822e..5bd110e0 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -22,6 +22,12 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assertEqual(len(result), 1) self.assert_(u'OK' in result) + def test_add_with_uri_not_found_in_library_should_not_call_lookup(self): + self.b.library.lookup = lambda uri: self.fail("Shouldn't run") + result = self.h.handle_request(u'add "foo"') + self.assertEqual(result[0], + u'ACK [50@0] {add} directory or file not found') + def test_add_with_uri_not_found_in_library_should_ack(self): result = self.h.handle_request(u'add "dummy://foo"') self.assertEqual(result[0],