Skip to content

Commit e8afcbe

Browse files
author
Johnny Robeson
committed
replace unicode with six.text_type
1 parent 7b66dfe commit e8afcbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+269
-203
lines changed

beets/autotag/hooks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from beets.autotag import mb
2828
from jellyfish import levenshtein_distance
2929
from unidecode import unidecode
30+
import six
3031

3132
log = logging.getLogger('beets')
3233

@@ -205,8 +206,8 @@ def _string_dist_basic(str1, str2):
205206
transliteration/lowering to ASCII characters. Normalized by string
206207
length.
207208
"""
208-
assert isinstance(str1, unicode)
209-
assert isinstance(str2, unicode)
209+
assert isinstance(str1, six.text_type)
210+
assert isinstance(str2, six.text_type)
210211
str1 = as_string(unidecode(str1))
211212
str2 = as_string(unidecode(str2))
212213
str1 = re.sub(r'[^a-z0-9]', '', str1.lower())

beets/autotag/mb.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import beets
2828
from beets import util
2929
from beets import config
30+
import six
3031

3132
VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377'
3233
BASE_URL = 'http://musicbrainz.org/'
@@ -69,7 +70,8 @@ def configure():
6970
"""Set up the python-musicbrainz-ngs module according to settings
7071
from the beets configuration. This should be called at startup.
7172
"""
72-
musicbrainzngs.set_hostname(config['musicbrainz']['host'].get(unicode))
73+
hostname = config['musicbrainz']['host'].get(six.text_type)
74+
musicbrainzngs.set_hostname(hostname)
7375
musicbrainzngs.set_rate_limit(
7476
config['musicbrainz']['ratelimit_interval'].as_number(),
7577
config['musicbrainz']['ratelimit'].get(int),
@@ -260,7 +262,7 @@ def album_info(release):
260262
)
261263
info.va = info.artist_id == VARIOUS_ARTISTS_ID
262264
if info.va:
263-
info.artist = config['va_name'].get(unicode)
265+
info.artist = config['va_name'].get(six.text_type)
264266
info.asin = release.get('asin')
265267
info.releasegroup_id = release['release-group']['id']
266268
info.country = release.get('country')
@@ -329,7 +331,7 @@ def match_album(artist, album, tracks=None):
329331
# Various Artists search.
330332
criteria['arid'] = VARIOUS_ARTISTS_ID
331333
if tracks is not None:
332-
criteria['tracks'] = unicode(tracks)
334+
criteria['tracks'] = six.text_type(tracks)
333335

334336
# Abort if we have no search terms.
335337
if not any(criteria.itervalues()):

beets/dbcore/db.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from beets.util.functemplate import Template
3030
from beets.dbcore import types
3131
from .query import MatchQuery, NullSort, TrueQuery
32+
import six
3233

3334

3435
class FormattedMapping(collections.Mapping):
@@ -69,7 +70,7 @@ def _get_formatted(self, model, key):
6970
value = value.decode('utf8', 'ignore')
7071

7172
if self.for_path:
72-
sep_repl = beets.config['path_sep_replace'].get(unicode)
73+
sep_repl = beets.config['path_sep_replace'].get(six.text_type)
7374
for sep in (os.path.sep, os.path.altsep):
7475
if sep:
7576
value = value.replace(sep, sep_repl)

beets/dbcore/query.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from datetime import datetime, timedelta
2424
import unicodedata
2525
from functools import reduce
26+
import six
2627

2728

2829
class ParsingError(ValueError):
@@ -246,8 +247,8 @@ def __init__(self, field, pattern):
246247
# Use a buffer representation of the pattern for SQLite
247248
# matching. This instructs SQLite to treat the blob as binary
248249
# rather than encoded Unicode.
249-
if isinstance(self.pattern, (unicode, bytes)):
250-
if isinstance(self.pattern, unicode):
250+
if isinstance(self.pattern, (six.text_type, bytes)):
251+
if isinstance(self.pattern, six.text_type):
251252
self.pattern = self.pattern.encode('utf8')
252253
self.buf_pattern = buffer(self.pattern)
253254
elif isinstance(self.pattern, buffer):
@@ -793,7 +794,7 @@ def sort(self, objs):
793794

794795
def key(item):
795796
field_val = item.get(self.field, '')
796-
if self.case_insensitive and isinstance(field_val, unicode):
797+
if self.case_insensitive and isinstance(field_val, six.text_type):
797798
field_val = field_val.lower()
798799
return field_val
799800

beets/dbcore/types.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from . import query
2121
from beets.util import str2bool
22+
import six
2223

2324

2425
# Abstract base.
@@ -37,7 +38,7 @@ class Type(object):
3738
"""The `Query` subclass to be used when querying the field.
3839
"""
3940

40-
model_type = unicode
41+
model_type = six.text_type
4142
"""The Python type that is used to represent the value in the model.
4243
4344
The model is guaranteed to return a value of this type if the field
@@ -63,7 +64,7 @@ def format(self, value):
6364
if isinstance(value, bytes):
6465
value = value.decode('utf8', 'ignore')
6566

66-
return unicode(value)
67+
return six.text_type(value)
6768

6869
def parse(self, string):
6970
"""Parse a (possibly human-written) string and return the
@@ -102,7 +103,7 @@ def from_sql(self, sql_value):
102103
"""
103104
if isinstance(sql_value, buffer):
104105
sql_value = bytes(sql_value).decode('utf8', 'ignore')
105-
if isinstance(sql_value, unicode):
106+
if isinstance(sql_value, six.text_type):
106107
return self.parse(sql_value)
107108
else:
108109
return self.normalize(sql_value)
@@ -194,7 +195,7 @@ class Boolean(Type):
194195
model_type = bool
195196

196197
def format(self, value):
197-
return unicode(bool(value))
198+
return six.text_type(bool(value))
198199

199200
def parse(self, string):
200201
return str2bool(string)

beets/importer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# included in all copies or substantial portions of the Software.
1515

1616
from __future__ import division, absolute_import, print_function
17+
import six
1718

1819
"""Provides the basic, interface-agnostic workflow for importing and
1920
autotagging music files.
@@ -640,7 +641,7 @@ def align_album_level_fields(self):
640641
changes['comp'] = False
641642
else:
642643
# VA.
643-
changes['albumartist'] = config['va_name'].get(unicode)
644+
changes['albumartist'] = config['va_name'].get(six.text_type)
644645
changes['comp'] = True
645646

646647
elif self.choice_flag in (action.APPLY, action.RETAG):

beets/library.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ class DateType(types.Float):
124124
query = dbcore.query.DateQuery
125125

126126
def format(self, value):
127-
return time.strftime(beets.config['time_format'].get(unicode),
127+
return time.strftime(beets.config['time_format'].get(six.text_type),
128128
time.localtime(value or 0))
129129

130130
def parse(self, string):
131131
try:
132132
# Try a formatted date string.
133133
return time.mktime(
134-
time.strptime(string, beets.config['time_format'].get(unicode))
134+
time.strptime(string,
135+
beets.config['time_format'].get(six.text_type))
135136
)
136137
except ValueError:
137138
# Fall back to a plain timestamp number.
@@ -153,7 +154,7 @@ def parse(self, string):
153154
return normpath(bytestring_path(string))
154155

155156
def normalize(self, value):
156-
if isinstance(value, unicode):
157+
if isinstance(value, six.text_type):
157158
# Paths stored internally as encoded bytes.
158159
return bytestring_path(value)
159160

@@ -281,11 +282,11 @@ def __unicode__(self):
281282
"""
282283
return u'{0}: {1}'.format(
283284
util.displayable_path(self.path),
284-
unicode(self.reason)
285+
six.text_type(self.reason)
285286
)
286287

287288
def __str__(self):
288-
return unicode(self).encode('utf8')
289+
return six.text_type(self).encode('utf8')
289290

290291

291292
class ReadError(FileOperationError):
@@ -331,7 +332,7 @@ def add(self, lib=None):
331332

332333
def __format__(self, spec):
333334
if not spec:
334-
spec = beets.config[self._format_config_key].get(unicode)
335+
spec = beets.config[self._format_config_key].get(six.text_type)
335336
result = self.evaluate_template(spec)
336337
if isinstance(spec, bytes):
337338
# if spec is a byte string then we must return a one as well
@@ -517,7 +518,7 @@ def __setitem__(self, key, value):
517518
"""
518519
# Encode unicode paths and read buffers.
519520
if key == 'path':
520-
if isinstance(value, unicode):
521+
if isinstance(value, six.text_type):
521522
value = bytestring_path(value)
522523
elif isinstance(value, buffer):
523524
value = bytes(value)
@@ -1061,7 +1062,8 @@ def art_destination(self, image, item_dir=None):
10611062
image = bytestring_path(image)
10621063
item_dir = item_dir or self.item_dir()
10631064

1064-
filename_tmpl = Template(beets.config['art_filename'].get(unicode))
1065+
filename_tmpl = Template(
1066+
beets.config['art_filename'].get(six.text_type))
10651067
subpath = self.evaluate_template(filename_tmpl, True)
10661068
if beets.config['asciify_paths']:
10671069
subpath = unidecode(subpath)
@@ -1179,7 +1181,8 @@ def parse_query_string(s, model_cls):
11791181
11801182
The string is split into components using shell-like syntax.
11811183
"""
1182-
assert isinstance(s, unicode), u"Query is not unicode: {0!r}".format(s)
1184+
message = u"Query is not unicode: {0!r}".format(s)
1185+
assert isinstance(s, six.text_type), message
11831186
try:
11841187
parts = util.shlex_split(s)
11851188
except ValueError as exc:
@@ -1405,7 +1408,7 @@ def tmpl_asciify(s):
14051408
def tmpl_time(s, fmt):
14061409
"""Format a time value using `strftime`.
14071410
"""
1408-
cur_fmt = beets.config['time_format'].get(unicode)
1411+
cur_fmt = beets.config['time_format'].get(six.text_type)
14091412
return time.strftime(fmt, time.strptime(s, cur_fmt))
14101413

14111414
def tmpl_aunique(self, keys=None, disam=None):

beets/logging.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from logging import * # noqa
2828
import subprocess
2929
import threading
30+
import six
3031

3132

3233
def logsafe(val):
@@ -42,7 +43,7 @@ def logsafe(val):
4243
example.
4344
"""
4445
# Already Unicode.
45-
if isinstance(val, unicode):
46+
if isinstance(val, six.text_type):
4647
return val
4748

4849
# Bytestring: needs decoding.
@@ -56,7 +57,7 @@ def logsafe(val):
5657
# A "problem" object: needs a workaround.
5758
elif isinstance(val, subprocess.CalledProcessError):
5859
try:
59-
return unicode(val)
60+
return six.text_type(val)
6061
except UnicodeDecodeError:
6162
# An object with a broken __unicode__ formatter. Use __str__
6263
# instead.

0 commit comments

Comments
 (0)