From 97c6b8812dc140e95eac01ba04a5bf6815bac90c Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Thu, 29 Oct 2015 22:44:36 +0100 Subject: [PATCH] xdg: Read .dirs file as text for py3 compat Py3's configparser isn't able to work with bytes. --- mopidy/internal/xdg.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mopidy/internal/xdg.py b/mopidy/internal/xdg.py index 3e658c01..4b5855f1 100644 --- a/mopidy/internal/xdg.py +++ b/mopidy/internal/xdg.py @@ -53,15 +53,15 @@ def _get_user_dirs(xdg_config_dir): return {} with open(dirs_file, 'rb') as fh: - data = fh.read() + data = fh.read().decode('utf-8') - data = b'[XDG_USER_DIRS]\n' + data - data = data.replace(b'$HOME', os.path.expanduser(b'~')) - data = data.replace(b'"', b'') + data = '[XDG_USER_DIRS]\n' + data + data = data.replace('$HOME', os.path.expanduser('~')) + data = data.replace('"', '') config = configparser.RawConfigParser() - config.readfp(io.BytesIO(data)) + config.readfp(io.StringIO(data)) return { - k.decode('utf-8').upper(): os.path.abspath(v) + k.upper(): os.path.abspath(v) for k, v in config.items('XDG_USER_DIRS') if v is not None}