utils: Convert path_to_uri to single argument
This commit is contained in:
parent
af707dfdbb
commit
6818e20218
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user