local: Add path_to_file_uri()
This commit is contained in:
parent
56cffa0089
commit
c59784c1e8
@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def local_uri_to_file_uri(uri, media_dir):
|
||||
"""Convert local track or directory URI to file URI."""
|
||||
return path.path_to_uri(local_uri_to_path(uri, media_dir))
|
||||
return path_to_file_uri(local_uri_to_path(uri, media_dir))
|
||||
|
||||
|
||||
def local_uri_to_path(uri, media_dir):
|
||||
@ -31,6 +31,12 @@ def local_track_uri_to_path(uri, media_dir):
|
||||
return local_uri_to_path(uri, media_dir)
|
||||
|
||||
|
||||
def path_to_file_uri(abspath):
|
||||
"""Convert absolute path to file URI."""
|
||||
# Re-export internal method for use by Mopidy-Local-* extensions.
|
||||
return path.path_to_uri(abspath)
|
||||
|
||||
|
||||
def path_to_local_track_uri(relpath):
|
||||
"""Convert path relative to media_dir to local track URI."""
|
||||
if isinstance(relpath, compat.text_type):
|
||||
|
||||
@ -68,6 +68,16 @@ def test_local_uri_to_path_errors(uri):
|
||||
translator.local_uri_to_path(uri, media_dir)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,uri', [
|
||||
('/foo', 'file:///foo'),
|
||||
(b'/foo', 'file:///foo'),
|
||||
('/æøå', 'file:///%C3%A6%C3%B8%C3%A5'),
|
||||
(b'/\x00\x01\x02', 'file:///%00%01%02'),
|
||||
])
|
||||
def test_path_to_file_uri(path, uri):
|
||||
assert translator.path_to_file_uri(path) == uri
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,uri', [
|
||||
('foo', 'local:track:foo'),
|
||||
(b'foo', 'local:track:foo'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user