Fix more unicode kwargs dict keys (#302)
This commit is contained in:
parent
42e84c8e2e
commit
358de3b088
@ -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',
|
||||
|
||||
@ -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 = {}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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'):
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user