compat: Replace basestring with compat.string_types

This commit is contained in:
Stein Magnus Jodal 2015-10-29 22:17:37 +01:00
parent 7b029bfcc4
commit 7e2d77ce0e
6 changed files with 14 additions and 7 deletions

View File

@ -195,7 +195,8 @@ def convert_taglist(taglist):
logger.debug('Ignoring invalid date: %r = %r', key, value)
elif isinstance(value, gst.Buffer):
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)
else:
logger.debug('Ignoring unknown data: %r = %r', key, value)

View File

@ -359,7 +359,7 @@ def _normalize_query(query):
broken_client = False
# TODO: this breaks if query is not a dictionary like object...
for (field, values) in query.items():
if isinstance(values, basestring):
if isinstance(values, compat.string_types):
broken_client = True
query[field] = [values]
if broken_client:

View File

@ -4,6 +4,9 @@ import contextlib
import re
import warnings
from mopidy import compat
# Messages used in deprecation warnings are collected here so we can target
# them easily when ignoring warnings.
_MESSAGES = {
@ -74,7 +77,7 @@ def warn(msg_id, pending=False):
@contextlib.contextmanager
def ignore(ids=None):
with warnings.catch_warnings():
if isinstance(ids, basestring):
if isinstance(ids, compat.string_types):
ids = [ids]
if ids:

View File

@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals
from mopidy import compat
from mopidy.models import fields
from mopidy.models.immutable import ImmutableObject, ValidatedImmutableObject
from mopidy.models.serialize import ModelJSONEncoder, model_json_decoder
@ -169,7 +170,7 @@ class Album(ValidatedImmutableObject):
musicbrainz_id = fields.Identifier()
#: 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()
# as it doesn't preserve order. I'm deferring this issue until we got
# actual usage of this field with more than one image.

View File

@ -1,5 +1,7 @@
from __future__ import absolute_import, unicode_literals
from mopidy import compat
class Field(object):
@ -69,7 +71,7 @@ class String(Field):
# TODO: normalize to unicode?
# TODO: only allow unicode?
# 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):
@ -144,7 +146,7 @@ class Collection(Field):
super(Collection, self).__init__(type=type, default=container())
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'
% (self._name, self._type.__name__, value))
for v in value:

View File

@ -33,5 +33,5 @@ class IsA(object):
any_int = IsA((int, long))
any_str = IsA(str)
any_str = IsA(compat.string_types)
any_unicode = IsA(compat.text_type)