# Buggy code
def translator(data):
    albumartist_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    track_kwargs = {}

    # 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.

    def _retrieve(source_key, target_key, target):
        if source_key in data:
            target[str(target_key)] = data[source_key]

    _retrieve(gst.TAG_ALBUM, "name", album_kwargs)
    _retrieve(gst.TAG_TRACK_COUNT, "num_tracks", album_kwargs)
    _retrieve(gst.TAG_ARTIST, "name", artist_kwargs)

    if gst.TAG_DATE in data and data[gst.TAG_DATE]:
        date = data[gst.TAG_DATE]
        try:
            date = datetime.date(date.year, date.month, date.day)
        except ValueError:
            pass  # Ignore invalid dates
        else:
            track_kwargs[b"date"] = date.isoformat()

    _retrieve(gst.TAG_TITLE, "name", track_kwargs)
    _retrieve(gst.TAG_TRACK_NUMBER, "track_no", track_kwargs)

    # Following keys don't seem to have TAG_* constant.
    _retrieve("album-artist", "name", albumartist_kwargs)
    _retrieve("musicbrainz-trackid", "musicbrainz_id", track_kwargs)
    _retrieve("musicbrainz-artistid", "musicbrainz_id", artist_kwargs)
    _retrieve("musicbrainz-albumid", "musicbrainz_id", album_kwargs)
    _retrieve("musicbrainz-albumartistid", "musicbrainz_id", albumartist_kwargs)

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

    track_kwargs[b"uri"] = data["uri"]
    track_kwargs[b"length"] = data[gst.TAG_DURATION]
    track_kwargs[b"album"] = Album(**album_kwargs)
    track_kwargs[b"artists"] = [Artist(**artist_kwargs)]

    return Track(**track_kwargs)


# 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 translator(data):
    albumartist_kwargs = {}
    album_kwargs = {}
    artist_kwargs = {}
    track_kwargs = {}

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

    def _retrieve(source_key, target_key, target):
        if source_key in data:
            target[str(target_key)] = data[source_key]

    _retrieve(gst.TAG_ALBUM, "name", album_kwargs)
    _retrieve(gst.TAG_TRACK_COUNT, "num_tracks", album_kwargs)
    _retrieve(gst.TAG_ARTIST, "name", artist_kwargs)

    if gst.TAG_DATE in data and data[gst.TAG_DATE]:
        date = data[gst.TAG_DATE]
        try:
            date = datetime.date(date.year, date.month, date.day)
        except ValueError:
            pass  # Ignore invalid dates
        else:
            track_kwargs[b"date"] = date.isoformat()

    _retrieve(gst.TAG_TITLE, "name", track_kwargs)
    _retrieve(gst.TAG_TRACK_NUMBER, "track_no", track_kwargs)

    # Following keys don't seem to have TAG_* constant.
    _retrieve("album-artist", "name", albumartist_kwargs)
    _retrieve("musicbrainz-trackid", "musicbrainz_id", track_kwargs)
    _retrieve("musicbrainz-artistid", "musicbrainz_id", artist_kwargs)
    _retrieve("musicbrainz-albumid", "musicbrainz_id", album_kwargs)
    _retrieve("musicbrainz-albumartistid", "musicbrainz_id", albumartist_kwargs)

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

    track_kwargs[b"uri"] = data["uri"]
    track_kwargs[b"length"] = data[gst.TAG_DURATION]
    track_kwargs[b"album"] = Album(**album_kwargs)
    track_kwargs[b"artists"] = [Artist(**artist_kwargs)]

    return Track(**track_kwargs)