mirror of
https://github.com/beetbox/beets.git
synced 2026-02-22 07:14:24 +01:00
replace basestring with six.text_types
This commit is contained in:
parent
e8afcbe7ec
commit
e57b7faf69
13 changed files with 30 additions and 25 deletions
|
|
@ -110,7 +110,7 @@ def _flatten_artist_credit(credit):
|
|||
artist_sort_parts = []
|
||||
artist_credit_parts = []
|
||||
for el in credit:
|
||||
if isinstance(el, basestring):
|
||||
if isinstance(el, six.string_types):
|
||||
# Join phrase.
|
||||
artist_parts.append(el)
|
||||
artist_credit_parts.append(el)
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ class Model(object):
|
|||
separators will be added to the template.
|
||||
"""
|
||||
# Perform substitution.
|
||||
if isinstance(template, basestring):
|
||||
if isinstance(template, six.string_types):
|
||||
template = Template(template)
|
||||
return template.substitute(self.formatted(for_path),
|
||||
self._template_funcs())
|
||||
|
|
@ -464,7 +464,7 @@ class Model(object):
|
|||
def _parse(cls, key, string):
|
||||
"""Parse a string as a value for the given key.
|
||||
"""
|
||||
if not isinstance(string, basestring):
|
||||
if not isinstance(string, six.string_types):
|
||||
raise TypeError(u"_parse() argument must be a string")
|
||||
|
||||
return cls._type(key).parse(string)
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ class BooleanQuery(MatchQuery):
|
|||
"""
|
||||
def __init__(self, field, pattern, fast=True):
|
||||
super(BooleanQuery, self).__init__(field, pattern, fast)
|
||||
if isinstance(pattern, basestring):
|
||||
if isinstance(pattern, six.string_types):
|
||||
self.pattern = util.str2bool(pattern)
|
||||
self.pattern = int(self.pattern)
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ class NumericQuery(FieldQuery):
|
|||
if self.field not in item:
|
||||
return False
|
||||
value = item[self.field]
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, six.string_types):
|
||||
value = self._convert(value)
|
||||
|
||||
if self.point is not None:
|
||||
|
|
|
|||
|
|
@ -1258,7 +1258,7 @@ class Library(dbcore.Database):
|
|||
# Parse the query, if necessary.
|
||||
try:
|
||||
parsed_sort = None
|
||||
if isinstance(query, basestring):
|
||||
if isinstance(query, six.string_types):
|
||||
query, parsed_sort = parse_query_string(query, model_cls)
|
||||
elif isinstance(query, (list, tuple)):
|
||||
query, parsed_sort = parse_query_parts(query, model_cls)
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ def _safe_cast(out_type, val):
|
|||
return int(val)
|
||||
else:
|
||||
# Process any other type as a string.
|
||||
if not isinstance(val, basestring):
|
||||
if not isinstance(val, six.string_types):
|
||||
val = six.text_type(val)
|
||||
# Get a number from the front of the string.
|
||||
val = re.match(r'[0-9]*', val.strip()).group(0)
|
||||
|
|
@ -1196,7 +1196,7 @@ class DateField(MediaField):
|
|||
"""
|
||||
# Get the underlying data and split on hyphens and slashes.
|
||||
datestring = super(DateField, self).__get__(mediafile, None)
|
||||
if isinstance(datestring, basestring):
|
||||
if isinstance(datestring, six.string_types):
|
||||
datestring = re.sub(r'[Tt ].*$', '', six.text_type(datestring))
|
||||
items = re.split('[-/]', six.text_type(datestring))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from functools import wraps
|
|||
import beets
|
||||
from beets import logging
|
||||
from beets import mediafile
|
||||
import six
|
||||
|
||||
PLUGIN_NAMESPACE = 'beetsplug'
|
||||
|
||||
|
|
@ -54,10 +55,10 @@ class PluginLogFilter(logging.Filter):
|
|||
|
||||
def filter(self, record):
|
||||
if hasattr(record.msg, 'msg') and isinstance(record.msg.msg,
|
||||
basestring):
|
||||
six.string_types):
|
||||
# A _LogMessage from our hacked-up Logging replacement.
|
||||
record.msg.msg = self.prefix + record.msg.msg
|
||||
elif isinstance(record.msg, basestring):
|
||||
elif isinstance(record.msg, six.string_types):
|
||||
record.msg = self.prefix + record.msg
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ def input_options(options, require=False, prompt=None, fallback_prompt=None,
|
|||
# Mark the option's shortcut letter for display.
|
||||
if not require and (
|
||||
(default is None and not numrange and first) or
|
||||
(isinstance(default, basestring) and
|
||||
(isinstance(default, six.string_types) and
|
||||
found_letter.lower() == default.lower())):
|
||||
# The first option is the default; mark it.
|
||||
show_letter = '[%s]' % found_letter.upper()
|
||||
|
|
@ -544,7 +544,8 @@ def _colordiff(a, b, highlight='text_highlight',
|
|||
highlighted intelligently to show differences; other values are
|
||||
stringified and highlighted in their entirety.
|
||||
"""
|
||||
if not isinstance(a, basestring) or not isinstance(b, basestring):
|
||||
if not isinstance(a, six.string_types) \
|
||||
or not isinstance(b, six.string_types):
|
||||
# Non-strings: use ordinary equality.
|
||||
a = six.text_type(a)
|
||||
b = six.text_type(b)
|
||||
|
|
@ -674,7 +675,7 @@ def _field_diff(field, old, new):
|
|||
|
||||
# For strings, highlight changes. For others, colorize the whole
|
||||
# thing.
|
||||
if isinstance(oldval, basestring):
|
||||
if isinstance(oldval, six.string_types):
|
||||
oldstr, newstr = colordiff(oldval, newstr)
|
||||
else:
|
||||
oldstr = colorize('text_error', oldstr)
|
||||
|
|
@ -867,7 +868,7 @@ class CommonOptionsParser(optparse.OptionParser, object):
|
|||
"""
|
||||
kwargs = {}
|
||||
if target:
|
||||
if isinstance(target, basestring):
|
||||
if isinstance(target, six.string_types):
|
||||
target = {'item': library.Item,
|
||||
'album': library.Album}[target]
|
||||
kwargs['target'] = target
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ def ex_literal(val):
|
|||
return ast.Num(val)
|
||||
elif isinstance(val, bool):
|
||||
return ast.Name(bytes(val), ast.Load())
|
||||
elif isinstance(val, basestring):
|
||||
elif isinstance(val, six.string_types):
|
||||
return ast.Str(val)
|
||||
raise TypeError(u'no literal for {0}'.format(type(val)))
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ def ex_call(func, args):
|
|||
function may be an expression or the name of a function. Each
|
||||
argument may be an expression or a value to be used as a literal.
|
||||
"""
|
||||
if isinstance(func, basestring):
|
||||
if isinstance(func, six.string_types):
|
||||
func = ex_rvalue(func)
|
||||
|
||||
args = list(args)
|
||||
|
|
@ -243,7 +243,7 @@ class Expression(object):
|
|||
"""
|
||||
out = []
|
||||
for part in self.parts:
|
||||
if isinstance(part, basestring):
|
||||
if isinstance(part, six.string_types):
|
||||
out.append(part)
|
||||
else:
|
||||
out.append(part.evaluate(env))
|
||||
|
|
@ -257,7 +257,7 @@ class Expression(object):
|
|||
varnames = set()
|
||||
funcnames = set()
|
||||
for part in self.parts:
|
||||
if isinstance(part, basestring):
|
||||
if isinstance(part, six.string_types):
|
||||
expressions.append(ex_literal(part))
|
||||
else:
|
||||
e, v, f = part.translate()
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ class Connection(object):
|
|||
added after every string. Returns a Bluelet event that sends
|
||||
the data.
|
||||
"""
|
||||
if isinstance(lines, basestring):
|
||||
if isinstance(lines, six.string_types):
|
||||
lines = [lines]
|
||||
out = NEWLINE.join(lines) + NEWLINE
|
||||
log.debug('{}', out[:-1]) # Don't log trailing newline.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from beets.plugins import BeetsPlugin
|
|||
from beets.dbcore.query import StringFieldQuery
|
||||
from beets import config
|
||||
import difflib
|
||||
import six
|
||||
|
||||
|
||||
class FuzzyQuery(StringFieldQuery):
|
||||
|
|
@ -44,5 +45,5 @@ class FuzzyPlugin(BeetsPlugin):
|
|||
})
|
||||
|
||||
def queries(self):
|
||||
prefix = self.config['prefix'].get(basestring)
|
||||
prefix = self.config['prefix'].get(six.string_types)
|
||||
return {prefix: FuzzyQuery}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ from beets.library import Item, Album, parse_query_string
|
|||
from beets.dbcore import OrQuery
|
||||
from beets.dbcore.query import MultipleSort, ParsingError
|
||||
import os
|
||||
import six
|
||||
|
||||
|
||||
class SmartPlaylistPlugin(BeetsPlugin):
|
||||
|
|
@ -106,7 +107,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
qs = playlist.get(key)
|
||||
if qs is None:
|
||||
query_and_sort = None, None
|
||||
elif isinstance(qs, basestring):
|
||||
elif isinstance(qs, six.string_types):
|
||||
query_and_sort = parse_query_string(qs, Model)
|
||||
elif len(qs) == 1:
|
||||
query_and_sort = parse_query_string(qs[0], Model)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ from beetsplug import lastgenre
|
|||
from beets import config
|
||||
|
||||
from test.helper import TestHelper
|
||||
import six
|
||||
|
||||
|
||||
class LastGenrePluginTest(unittest.TestCase, TestHelper):
|
||||
|
|
@ -38,11 +39,11 @@ class LastGenrePluginTest(unittest.TestCase, TestHelper):
|
|||
def _setup_config(self, whitelist=False, canonical=False, count=1):
|
||||
config['lastgenre']['canonical'] = canonical
|
||||
config['lastgenre']['count'] = count
|
||||
if isinstance(whitelist, (bool, basestring)):
|
||||
if isinstance(whitelist, (bool, six.string_types)):
|
||||
# Filename, default, or disabled.
|
||||
config['lastgenre']['whitelist'] = whitelist
|
||||
self.plugin.setup()
|
||||
if not isinstance(whitelist, (bool, basestring)):
|
||||
if not isinstance(whitelist, (bool, six.string_types)):
|
||||
# Explicit list of genres.
|
||||
self.plugin.whitelist = whitelist
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def _normexpr(expr):
|
|||
"""
|
||||
textbuf = []
|
||||
for part in expr.parts:
|
||||
if isinstance(part, basestring):
|
||||
if isinstance(part, six.string_types):
|
||||
textbuf.append(part)
|
||||
else:
|
||||
if textbuf:
|
||||
|
|
@ -259,7 +259,7 @@ class EvalTest(unittest.TestCase):
|
|||
|
||||
def test_function_call_exception(self):
|
||||
res = self._eval(u"%lower{a,b,c,d,e}")
|
||||
self.assertTrue(isinstance(res, basestring))
|
||||
self.assertTrue(isinstance(res, six.string_types))
|
||||
|
||||
def test_function_returning_integer(self):
|
||||
self.assertEqual(self._eval(u"%len{foo}"), u"3")
|
||||
|
|
|
|||
Loading…
Reference in a new issue