From 6818e202181838765ac0cf0673bef11982c406f1 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 9 Jul 2013 23:26:01 +0200 Subject: [PATCH] utils: Convert path_to_uri to single argument --- mopidy/backends/local/translator.py | 5 +++-- mopidy/utils/path.py | 3 +-- tests/utils/path_test.py | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index 4ae10af2..344e8ad7 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import logging +import os import urllib from mopidy.models import Track, Artist, Album @@ -50,7 +51,7 @@ def parse_m3u(file_path, media_dir): if line.startswith('file://'): uris.append(line) else: - path = path_to_uri(media_dir, line) + path = path_to_uri(os.path.join(media_dir, line)) uris.append(path) return uris @@ -167,7 +168,7 @@ def _convert_mpd_data(data, tracks, music_dir): # Make sure we only pass bytestrings to path_to_uri to avoid implicit # decoding of bytestrings to unicode strings - track_kwargs['uri'] = path_to_uri(music_dir, path) + track_kwargs['uri'] = path_to_uri(os.path.join(music_dir, path)) track_kwargs['length'] = int(data.get('time', 0)) * 1000 diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index dc769119..af1f38b1 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -51,7 +51,7 @@ def get_or_create_file(file_path): return file_path -def path_to_uri(*parts): +def path_to_uri(path): """ Convert OS specific path to file:// URI. @@ -61,7 +61,6 @@ def path_to_uri(*parts): Returns a file:// URI as an unicode string. """ - path = os.path.join(*parts) if isinstance(path, unicode): path = path.encode('utf-8') path = urllib.quote(path) diff --git a/tests/utils/path_test.py b/tests/utils/path_test.py index 0bead5b7..ed9f8044 100644 --- a/tests/utils/path_test.py +++ b/tests/utils/path_test.py @@ -119,10 +119,6 @@ class PathToFileURITest(unittest.TestCase): result = path.path_to_uri('/etc/fstab') self.assertEqual(result, 'file:///etc/fstab') - def test_dir_and_path(self): - result = path.path_to_uri('/etc', 'fstab') - self.assertEqual(result, 'file:///etc/fstab') - def test_space_in_path(self): result = path.path_to_uri('/tmp/test this') self.assertEqual(result, 'file:///tmp/test%20this')