compat: Replace basestring with compat.string_types
This commit is contained in:
parent
7b029bfcc4
commit
7e2d77ce0e
@ -195,7 +195,8 @@ def convert_taglist(taglist):
|
|||||||
logger.debug('Ignoring invalid date: %r = %r', key, value)
|
logger.debug('Ignoring invalid date: %r = %r', key, value)
|
||||||
elif isinstance(value, gst.Buffer):
|
elif isinstance(value, gst.Buffer):
|
||||||
result[key].append(bytes(value))
|
result[key].append(bytes(value))
|
||||||
elif isinstance(value, (basestring, bool, numbers.Number)):
|
elif isinstance(
|
||||||
|
value, (compat.string_types, bool, numbers.Number)):
|
||||||
result[key].append(value)
|
result[key].append(value)
|
||||||
else:
|
else:
|
||||||
logger.debug('Ignoring unknown data: %r = %r', key, value)
|
logger.debug('Ignoring unknown data: %r = %r', key, value)
|
||||||
|
|||||||
@ -359,7 +359,7 @@ def _normalize_query(query):
|
|||||||
broken_client = False
|
broken_client = False
|
||||||
# TODO: this breaks if query is not a dictionary like object...
|
# TODO: this breaks if query is not a dictionary like object...
|
||||||
for (field, values) in query.items():
|
for (field, values) in query.items():
|
||||||
if isinstance(values, basestring):
|
if isinstance(values, compat.string_types):
|
||||||
broken_client = True
|
broken_client = True
|
||||||
query[field] = [values]
|
query[field] = [values]
|
||||||
if broken_client:
|
if broken_client:
|
||||||
|
|||||||
@ -4,6 +4,9 @@ import contextlib
|
|||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from mopidy import compat
|
||||||
|
|
||||||
|
|
||||||
# Messages used in deprecation warnings are collected here so we can target
|
# Messages used in deprecation warnings are collected here so we can target
|
||||||
# them easily when ignoring warnings.
|
# them easily when ignoring warnings.
|
||||||
_MESSAGES = {
|
_MESSAGES = {
|
||||||
@ -74,7 +77,7 @@ def warn(msg_id, pending=False):
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def ignore(ids=None):
|
def ignore(ids=None):
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
if isinstance(ids, basestring):
|
if isinstance(ids, compat.string_types):
|
||||||
ids = [ids]
|
ids = [ids]
|
||||||
|
|
||||||
if ids:
|
if ids:
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from mopidy import compat
|
||||||
from mopidy.models import fields
|
from mopidy.models import fields
|
||||||
from mopidy.models.immutable import ImmutableObject, ValidatedImmutableObject
|
from mopidy.models.immutable import ImmutableObject, ValidatedImmutableObject
|
||||||
from mopidy.models.serialize import ModelJSONEncoder, model_json_decoder
|
from mopidy.models.serialize import ModelJSONEncoder, model_json_decoder
|
||||||
@ -169,7 +170,7 @@ class Album(ValidatedImmutableObject):
|
|||||||
musicbrainz_id = fields.Identifier()
|
musicbrainz_id = fields.Identifier()
|
||||||
|
|
||||||
#: The album image URIs. Read-only.
|
#: The album image URIs. Read-only.
|
||||||
images = fields.Collection(type=basestring, container=frozenset)
|
images = fields.Collection(type=compat.string_types, container=frozenset)
|
||||||
# XXX If we want to keep the order of images we shouldn't use frozenset()
|
# XXX If we want to keep the order of images we shouldn't use frozenset()
|
||||||
# as it doesn't preserve order. I'm deferring this issue until we got
|
# as it doesn't preserve order. I'm deferring this issue until we got
|
||||||
# actual usage of this field with more than one image.
|
# actual usage of this field with more than one image.
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from mopidy import compat
|
||||||
|
|
||||||
|
|
||||||
class Field(object):
|
class Field(object):
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ class String(Field):
|
|||||||
# TODO: normalize to unicode?
|
# TODO: normalize to unicode?
|
||||||
# TODO: only allow unicode?
|
# TODO: only allow unicode?
|
||||||
# TODO: disallow empty strings?
|
# TODO: disallow empty strings?
|
||||||
super(String, self).__init__(type=basestring, default=default)
|
super(String, self).__init__(type=compat.string_types, default=default)
|
||||||
|
|
||||||
|
|
||||||
class Date(String):
|
class Date(String):
|
||||||
@ -144,7 +146,7 @@ class Collection(Field):
|
|||||||
super(Collection, self).__init__(type=type, default=container())
|
super(Collection, self).__init__(type=type, default=container())
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, compat.string_types):
|
||||||
raise TypeError('Expected %s to be a collection of %s, not %r'
|
raise TypeError('Expected %s to be a collection of %s, not %r'
|
||||||
% (self._name, self._type.__name__, value))
|
% (self._name, self._type.__name__, value))
|
||||||
for v in value:
|
for v in value:
|
||||||
|
|||||||
@ -33,5 +33,5 @@ class IsA(object):
|
|||||||
|
|
||||||
|
|
||||||
any_int = IsA((int, long))
|
any_int = IsA((int, long))
|
||||||
any_str = IsA(str)
|
any_str = IsA(compat.string_types)
|
||||||
any_unicode = IsA(compat.text_type)
|
any_unicode = IsA(compat.text_type)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user