diff --git a/mopidy/__main__.py b/mopidy/__main__.py index e111fcef..2847497a 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -79,8 +79,7 @@ def main(): def parse_options(): parser = optparse.OptionParser( version='Mopidy %s' % versioning.get_version()) - # NOTE Python 2.6: To support Python versions < 2.6.2rc1 we must use - # bytestrings for the first argument to ``add_option`` + # NOTE First argument to add_option must be bytestrings on Python < 2.6.2 # See https://github.com/mopidy/mopidy/issues/302 for details parser.add_option( b'--help-gst', diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index 157804b4..b029d367 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -98,8 +98,8 @@ 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. + # 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 = {} diff --git a/mopidy/frontends/mpd/actor.py b/mopidy/frontends/mpd/actor.py index 33ccd077..8907fe22 100644 --- a/mopidy/frontends/mpd/actor.py +++ b/mopidy/frontends/mpd/actor.py @@ -19,8 +19,8 @@ class MpdFrontend(pykka.ThreadingActor, CoreListener): hostname = network.format_hostname(settings.MPD_SERVER_HOSTNAME) port = settings.MPD_SERVER_PORT - # NOTE: dict key must be bytestring to work on Python < 2.6.5 - # See https://github.com/mopidy/mopidy/issues/302 for details + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details. try: network.Server( hostname, port, diff --git a/mopidy/frontends/mpd/protocol/__init__.py b/mopidy/frontends/mpd/protocol/__init__.py index 55a1563b..2b2260ef 100644 --- a/mopidy/frontends/mpd/protocol/__init__.py +++ b/mopidy/frontends/mpd/protocol/__init__.py @@ -56,10 +56,10 @@ def handle_request(pattern, auth_required=True): if match is not None: mpd_commands.add( MpdCommand(name=match.group(), auth_required=auth_required)) - # NOTE: Make pattern a bytestring to get bytestring keys in the dict + # NOTE Make pattern a bytestring to get bytestring keys in the dict # returned from matches.groupdict(), which is again used as a **kwargs - # dict. This is needed to work on Python < 2.6.5. See - # https://github.com/mopidy/mopidy/issues/302 for details. + # dict. This is needed to work on Python < 2.6.5. + # See https://github.com/mopidy/mopidy/issues/302 for details. bytestring_pattern = pattern.encode('utf-8') compiled_pattern = re.compile(bytestring_pattern, flags=re.UNICODE) if compiled_pattern in request_handlers: diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index e26d7dce..15ca181d 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -140,6 +140,8 @@ def query_from_mpd_list_format(field, mpd_query): """ Converts an MPD ``list`` query to a Mopidy query. """ + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details if mpd_query is None: return {} try: @@ -155,15 +157,14 @@ def query_from_mpd_list_format(field, mpd_query): if field == 'album': if not tokens[0]: raise ValueError - return {'artist': [tokens[0]]} + return {b'artist': [tokens[0]]} # See above NOTE else: raise MpdArgError( 'should be "Album" for 3 arguments', command='list') elif len(tokens) % 2 == 0: query = {} while tokens: - key = tokens[0].lower() - key = str(key) # Needed for kwargs keys on OS X and Windows + key = str(tokens[0].lower()) # See above NOTE value = tokens[1] tokens = tokens[2:] if key not in ('artist', 'album', 'date', 'genre'): diff --git a/mopidy/models.py b/mopidy/models.py index 73209b6e..1fb3d7a7 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -66,13 +66,15 @@ class ImmutableObject(object): :type values: dict :rtype: new instance of the model being copied """ + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details data = {} for key in self.__dict__.keys(): public_key = key.lstrip('_') - data[public_key] = values.pop(public_key, self.__dict__[key]) + data[str(public_key)] = values.pop(public_key, self.__dict__[key]) for key in values.keys(): if hasattr(self, key): - data[key] = values.pop(key) + data[str(key)] = values.pop(key) if values: raise TypeError( 'copy() got an unexpected keyword argument "%s"' % key) @@ -186,7 +188,9 @@ class Album(ImmutableObject): musicbrainz_id = None def __init__(self, *args, **kwargs): - self.__dict__['artists'] = frozenset(kwargs.pop('artists', [])) + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details + self.__dict__[b'artists'] = frozenset(kwargs.pop('artists', [])) super(Album, self).__init__(*args, **kwargs) @@ -240,7 +244,9 @@ class Track(ImmutableObject): musicbrainz_id = None def __init__(self, *args, **kwargs): - self.__dict__['artists'] = frozenset(kwargs.pop('artists', [])) + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details + self.__dict__[b'artists'] = frozenset(kwargs.pop('artists', [])) super(Track, self).__init__(*args, **kwargs) @@ -272,9 +278,11 @@ class TlTrack(ImmutableObject): track = None def __init__(self, *args, **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 if len(args) == 2 and len(kwargs) == 0: - kwargs['tlid'] = args[0] - kwargs['track'] = args[1] + kwargs[b'tlid'] = args[0] + kwargs[b'track'] = args[1] args = [] super(TlTrack, self).__init__(*args, **kwargs) @@ -309,7 +317,9 @@ class Playlist(ImmutableObject): last_modified = None def __init__(self, *args, **kwargs): - self.__dict__['tracks'] = tuple(kwargs.pop('tracks', [])) + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details + self.__dict__[b'tracks'] = tuple(kwargs.pop('tracks', [])) super(Playlist, self).__init__(*args, **kwargs) # TODO: def insert(self, pos, track): ... ? @@ -345,7 +355,9 @@ class SearchResult(ImmutableObject): albums = tuple() def __init__(self, *args, **kwargs): - self.__dict__['tracks'] = tuple(kwargs.pop('tracks', [])) - self.__dict__['artists'] = tuple(kwargs.pop('artists', [])) - self.__dict__['albums'] = tuple(kwargs.pop('albums', [])) + # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 + # See https://github.com/mopidy/mopidy/issues/302 for details + self.__dict__[b'tracks'] = tuple(kwargs.pop('tracks', [])) + self.__dict__[b'artists'] = tuple(kwargs.pop('artists', [])) + self.__dict__[b'albums'] = tuple(kwargs.pop('albums', [])) super(SearchResult, self).__init__(*args, **kwargs) diff --git a/mopidy/scanner.py b/mopidy/scanner.py index 9f8c12f7..bfeb9fd1 100644 --- a/mopidy/scanner.py +++ b/mopidy/scanner.py @@ -79,8 +79,7 @@ def main(): def parse_options(): parser = optparse.OptionParser( version='Mopidy %s' % versioning.get_version()) - # NOTE Python 2.6: To support Python versions < 2.6.2rc1 we must use - # bytestrings for the first argument to ``add_option`` + # NOTE First argument to add_option must be bytestrings on Python < 2.6.2 # See https://github.com/mopidy/mopidy/issues/302 for details parser.add_option( b'-q', '--quiet', @@ -99,9 +98,8 @@ def translator(data): 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. + # 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: