# Buggy code
def _get_user_dirs(xdg_config_dir):
    """Returns a dict of XDG dirs read from
    ``$XDG_CONFIG_HOME/user-dirs.dirs``.

    This is used at import time for most users of :mod:`mopidy`. By rolling our
    own implementation instead of using :meth:`glib.get_user_special_dir` we
    make it possible for many extensions to run their test suites, which are
    importing parts of :mod:`mopidy`, in a virtualenv with global site-packages
    disabled, and thus no :mod:`glib` available.
    """

    dirs_file = os.path.join(xdg_config_dir, b"user-dirs.dirs")

    if not os.path.exists(dirs_file):
        return {}

    with open(dirs_file, "rb") as fh:
        data = fh.read().decode("utf-8")

    data = "[XDG_USER_DIRS]\n" + data
    data = data.replace("$HOME", os.path.expanduser("~"))
    data = data.replace('"', "")

    config = configparser.RawConfigParser()
    config.readfp(io.StringIO(data))

    return {
        k.upper(): os.path.abspath(v)
        for k, v in config.items("XDG_USER_DIRS")
        if v is not None
    }


# Traceback (ValueError)
ERROR    FileBackend backend caused an exception.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/mopidy/core/library.py", line 19, in _backend_error_handling
yield
File "/usr/lib/python2.7/dist-packages/mopidy/core/library.py", line 112, in _browse
result = backend.library.browse(uri).get()
File "/usr/lib/python2.7/dist-packages/pykka/threading.py", line 52, in get
compat.reraise(*self._data['exc_info'])
File "/usr/lib/python2.7/dist-packages/pykka/compat.py", line 12, in reraise
exec('raise tp, value, tb')
File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 201, in _actor_loop
response = self._handle_receive(message)
File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 295, in _handle_receive
return callee(*message['args'], **message['kwargs'])
File "/usr/lib/python2.7/dist-packages/mopidy/file/library.py", line 53, in browse
if not self._is_in_basedir(os.path.realpath(local_path)):
File "/usr/lib/python2.7/dist-packages/mopidy/file/library.py", line 146, in _is_in_basedir
for media_dir in self._media_dirs)
File "/usr/lib/python2.7/dist-packages/mopidy/file/library.py", line 146, in <genexpr>
for media_dir in self._media_dirs)
File "/usr/lib/python2.7/dist-packages/mopidy/internal/path.py", line
210, in is_path_inside_base_dir
raise ValueError('base_path is not a bytestring')
ValueError: base_path is not a bytestring

# Fixed code
def _get_user_dirs(xdg_config_dir):
    """Returns a dict of XDG dirs read from
    ``$XDG_CONFIG_HOME/user-dirs.dirs``.

    This is used at import time for most users of :mod:`mopidy`. By rolling our
    own implementation instead of using :meth:`glib.get_user_special_dir` we
    make it possible for many extensions to run their test suites, which are
    importing parts of :mod:`mopidy`, in a virtualenv with global site-packages
    disabled, and thus no :mod:`glib` available.
    """

    dirs_file = os.path.join(xdg_config_dir, b"user-dirs.dirs")

    if not os.path.exists(dirs_file):
        return {}

    with open(dirs_file, "rb") as fh:
        data = fh.read()

    data = b"[XDG_USER_DIRS]\n" + data
    data = data.replace(b"$HOME", os.path.expanduser(b"~"))
    data = data.replace(b'"', b"")

    config = configparser.RawConfigParser()
    config.readfp(io.BytesIO(data))

    return {
        k.upper().decode("utf-8"): os.path.abspath(v)
        for k, v in config.items("XDG_USER_DIRS")
        if v is not None
    }