From 0f603c3eded58cef063f1f033f3c7a29a0c8e7b3 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 12 Dec 2012 23:13:52 +0100 Subject: [PATCH] Use urllib.{quote,unquote} instead of {pathname2url,url2pathname} --- mopidy/backends/local/translator.py | 2 +- mopidy/frontends/mpd/translator.py | 6 +++--- mopidy/utils/path.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index 00500ef7..ff58a16e 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -140,7 +140,7 @@ def _convert_mpd_data(data, tracks, music_dir): path = data['file'][1:] else: path = data['file'] - path = urllib.url2pathname(path) + path = urllib.unquote(path) if artist_kwargs: artist = Artist(**artist_kwargs) diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index b2113dda..0c95f044 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -160,7 +160,7 @@ def _add_to_tag_cache(result, folders, files): try: text_path = path.decode('utf-8') except UnicodeDecodeError: - text_path = urllib.pathname2url(path).decode('utf-8') + text_path = urllib.quote(path).decode('utf-8') name = os.path.split(text_path)[1] result.append(('directory', text_path)) result.append(('mtime', get_mtime(os.path.join(base_path, path)))) @@ -177,9 +177,9 @@ def _add_to_tag_cache(result, folders, files): try: text_path = path.decode('utf-8') except UnicodeDecodeError: - text_path = urllib.pathname2url(path).decode('utf-8') + text_path = urllib.quote(path).decode('utf-8') relative_path = os.path.relpath(path, base_path) - relative_uri = urllib.pathname2url(relative_path) + relative_uri = urllib.quote(relative_path) track_result['file'] = relative_uri track_result['mtime'] = get_mtime(path) diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index 8ef5e187..c4fa0ce2 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -64,8 +64,8 @@ def path_to_uri(*paths): if isinstance(path, unicode): path = path.encode('utf-8') if sys.platform == 'win32': - return 'file:' + urllib.pathname2url(path) - return 'file://' + urllib.pathname2url(path) + return 'file:' + urllib.quote(path) + return 'file://' + urllib.quote(path) def uri_to_path(uri): @@ -82,9 +82,9 @@ def uri_to_path(uri): if isinstance(uri, unicode): uri = uri.encode('utf-8') if sys.platform == 'win32': - return urllib.url2pathname(re.sub(b'^file:', b'', uri)) + return urllib.unquote(re.sub(b'^file:', b'', uri)) else: - return urllib.url2pathname(re.sub(b'^file://', b'', uri)) + return urllib.unquote(re.sub(b'^file://', b'', uri)) def split_path(path):