# Buggy code
def _convert_mpd_data(data, tracks, music_dir):
    if not data:
        return

    # NOTE: kwargs are explicitly made bytestrings to work on Python
    # 2.6.0/2.6.1. See https://github.com/mopidy/mopidy/issues/302 for details.

    track_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    albumartist_kwargs = {}

    if "track" in data:
        if "/" in data["track"]:
            album_kwargs[b"num_tracks"] = int(data["track"].split("/")[1])
            track_kwargs[b"track_no"] = int(data["track"].split("/")[0])
        else:
            track_kwargs[b"track_no"] = int(data["track"])

    if "artist" in data:
        artist_kwargs[b"name"] = data["artist"]
        albumartist_kwargs[b"name"] = data["artist"]

    if "albumartist" in data:
        albumartist_kwargs[b"name"] = data["albumartist"]

    if "album" in data:
        album_kwargs[b"name"] = data["album"]

    if "title" in data:
        track_kwargs[b"name"] = data["title"]

    if "date" in data:
        track_kwargs[b"date"] = data["date"]

    if "musicbrainz_trackid" in data:
        track_kwargs[b"musicbrainz_id"] = data["musicbrainz_trackid"]

    if "musicbrainz_albumid" in data:
        album_kwargs[b"musicbrainz_id"] = data["musicbrainz_albumid"]

    if "musicbrainz_artistid" in data:
        artist_kwargs[b"musicbrainz_id"] = data["musicbrainz_artistid"]

    if "musicbrainz_albumartistid" in data:
        albumartist_kwargs[b"musicbrainz_id"] = data["musicbrainz_albumartistid"]

    if data["file"][0] == "/":
        path = data["file"][1:]
    else:
        path = data["file"]
    path = urllib.unquote(path)

    if artist_kwargs:
        artist = Artist(**artist_kwargs)
        track_kwargs[b"artists"] = [artist]

    if albumartist_kwargs:
        albumartist = Artist(**albumartist_kwargs)
        album_kwargs[b"artists"] = [albumartist]

    if album_kwargs:
        album = Album(**album_kwargs)
        track_kwargs[b"album"] = album

    track_kwargs[b"uri"] = path_to_uri(music_dir, path)
    track_kwargs[b"length"] = int(data.get("time", 0)) * 1000

    track = Track(**track_kwargs)
    tracks.add(track)


# Traceback (TypeError)
erik@faust:~$  mopidy
Traceback (most recent call last):
File "/usr/local/bin/mopidy", line 5, in <module>
main()
File "/usr/local/lib64/python2.6/site-packages/mopidy/__main__.py", line 48, in main
options = parse_options()
File "/usr/local/lib64/python2.6/site-packages/mopidy/__main__.py", line 85, in parse_options
help='show GStreamer help options')
File "/usr/lib64/python2.6/optparse.py", line 1012, in add_option
raise TypeError, "invalid arguments"
TypeError: invalid arguments
erik@faust:~$  python --version
Python 2.6
erik@faust:~$  uname -a
Linux faust 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux
erik@faust:~$  cat /etc/SuSE-release
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 2
erik@faust:~$

# Fixed code
def _convert_mpd_data(data, tracks, music_dir):
    if not data:
        return

    # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5
    # See https://github.com/mopidy/mopidy/issues/302 for details.

    track_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    albumartist_kwargs = {}

    if "track" in data:
        if "/" in data["track"]:
            album_kwargs[b"num_tracks"] = int(data["track"].split("/")[1])
            track_kwargs[b"track_no"] = int(data["track"].split("/")[0])
        else:
            track_kwargs[b"track_no"] = int(data["track"])

    if "artist" in data:
        artist_kwargs[b"name"] = data["artist"]
        albumartist_kwargs[b"name"] = data["artist"]

    if "albumartist" in data:
        albumartist_kwargs[b"name"] = data["albumartist"]

    if "album" in data:
        album_kwargs[b"name"] = data["album"]

    if "title" in data:
        track_kwargs[b"name"] = data["title"]

    if "date" in data:
        track_kwargs[b"date"] = data["date"]

    if "musicbrainz_trackid" in data:
        track_kwargs[b"musicbrainz_id"] = data["musicbrainz_trackid"]

    if "musicbrainz_albumid" in data:
        album_kwargs[b"musicbrainz_id"] = data["musicbrainz_albumid"]

    if "musicbrainz_artistid" in data:
        artist_kwargs[b"musicbrainz_id"] = data["musicbrainz_artistid"]

    if "musicbrainz_albumartistid" in data:
        albumartist_kwargs[b"musicbrainz_id"] = data["musicbrainz_albumartistid"]

    if data["file"][0] == "/":
        path = data["file"][1:]
    else:
        path = data["file"]
    path = urllib.unquote(path)

    if artist_kwargs:
        artist = Artist(**artist_kwargs)
        track_kwargs[b"artists"] = [artist]

    if albumartist_kwargs:
        albumartist = Artist(**albumartist_kwargs)
        album_kwargs[b"artists"] = [albumartist]

    if album_kwargs:
        album = Album(**album_kwargs)
        track_kwargs[b"album"] = album

    track_kwargs[b"uri"] = path_to_uri(music_dir, path)
    track_kwargs[b"length"] = int(data.get("time", 0)) * 1000

    track = Track(**track_kwargs)
    tracks.add(track)