remove bytes casts from object/method resolution code

This commit is contained in:
Johnny Robeson 2016-05-30 03:15:45 -04:00
parent e6ab231f72
commit 330306bbe2
7 changed files with 33 additions and 34 deletions

View file

@ -1325,7 +1325,7 @@ class DefaultTemplateFunctions(object):
additional context to the functions -- specifically, the Item being
evaluated.
"""
_prefix = b'tmpl_'
_prefix = 'tmpl_'
def __init__(self, item=None, lib=None):
"""Parametrize the functions. If `item` or `lib` is None, then

View file

@ -28,7 +28,7 @@ import beets
from beets import logging
from beets import mediafile
PLUGIN_NAMESPACE = b'beetsplug'
PLUGIN_NAMESPACE = 'beetsplug'
# Plugins using the Last.fm API can share the same API key.
LASTFM_KEY = '2dc3914abf35f0d9c92d97d8f8e42b43'
@ -72,7 +72,7 @@ class BeetsPlugin(object):
def __init__(self, name=None):
"""Perform one-time plugin setup.
"""
self.name = name or self.__module__.decode('utf8').split('.')[-1]
self.name = name or self.__module__.split('.')[-1]
self.config = beets.config[self.name]
if not self.template_funcs:
self.template_funcs = {}
@ -247,8 +247,7 @@ def load_plugins(names=()):
BeetsPlugin subclasses desired.
"""
for name in names:
bname = name.encode('utf8')
modname = b'%s.%s' % (PLUGIN_NAMESPACE, bname)
modname = '{0}.{1}'.format(PLUGIN_NAMESPACE, name)
try:
try:
namespace = __import__(modname, None, None)
@ -259,7 +258,7 @@ def load_plugins(names=()):
else:
raise
else:
for obj in getattr(namespace, bname).__dict__.values():
for obj in getattr(namespace, name).__dict__.values():
if isinstance(obj, type) and issubclass(obj, BeetsPlugin) \
and obj != BeetsPlugin and obj not in _classes:
_classes.add(obj)
@ -313,7 +312,7 @@ def queries():
def types(model_cls):
# Gives us `item_types` and `album_types`
attr_name = b'{0}_types'.format(model_cls.__name__.lower())
attr_name = '{0}_types'.format(model_cls.__name__.lower())
types = {}
for plugin in find_plugins():
plugin_types = getattr(plugin, attr_name, {})

View file

@ -1132,7 +1132,7 @@ def _configure(options):
# Add any additional config files specified with --config. This
# special handling lets specified plugins get loaded before we
# finish parsing the command line.
if getattr(options, b'config', None) is not None:
if getattr(options, 'config', None) is not None:
config_path = options.config
del options.config
config.set_file(config_path)

View file

@ -713,7 +713,7 @@ def max_filename_length(path, limit=MAX_FILENAME_LENGTH):
misreports its capacity). If it cannot be determined (e.g., on
Windows), return `limit`.
"""
if hasattr(os, b'statvfs'):
if hasattr(os, 'statvfs'):
try:
res = os.statvfs(path)
except OSError:

View file

@ -43,8 +43,8 @@ GROUP_CLOSE = u'}'
ARG_SEP = u','
ESCAPE_CHAR = u'$'
VARIABLE_PREFIX = b'__var_'
FUNCTION_PREFIX = b'__func_'
VARIABLE_PREFIX = '__var_'
FUNCTION_PREFIX = '__func_'
class Environment(object):
@ -73,7 +73,7 @@ def ex_literal(val):
value.
"""
if val is None:
return ast.Name(b'None', ast.Load())
return ast.Name('None', ast.Load())
elif isinstance(val, NUMERIC_TYPES):
return ast.Num(val)
elif isinstance(val, bool):
@ -126,7 +126,7 @@ def compile_func(arg_names, statements, name='_the_func', debug=False):
mod = ast.Module([func_def])
ast.fix_missing_locations(mod)
prog = compile(mod, b'<generated>', b'exec')
prog = compile(mod, '<generated>', 'exec')
# Debug: show bytecode.
if debug:
@ -209,11 +209,11 @@ class Call(object):
# Create a subexpression that joins the result components of
# the arguments.
arg_exprs.append(ex_call(
ast.Attribute(ex_literal(u''), b'join', ast.Load()),
ast.Attribute(ex_literal(u''), 'join', ast.Load()),
[ex_call(
b'map',
'map',
[
ex_rvalue(b'unicode'),
ex_rvalue('unicode'),
ast.List(subexprs, ast.Load()),
]
)],

View file

@ -26,21 +26,21 @@ from beets import config
from beets import mediafile
_MUTAGEN_FORMATS = {
b'asf': b'ASF',
b'apev2': b'APEv2File',
b'flac': b'FLAC',
b'id3': b'ID3FileType',
b'mp3': b'MP3',
b'mp4': b'MP4',
b'oggflac': b'OggFLAC',
b'oggspeex': b'OggSpeex',
b'oggtheora': b'OggTheora',
b'oggvorbis': b'OggVorbis',
b'oggopus': b'OggOpus',
b'trueaudio': b'TrueAudio',
b'wavpack': b'WavPack',
b'monkeysaudio': b'MonkeysAudio',
b'optimfrog': b'OptimFROG',
'asf': 'ASF',
'apev2': 'APEv2File',
'flac': 'FLAC',
'id3': 'ID3FileType',
'mp3': 'MP3',
'mp4': 'MP4',
'oggflac': 'OggFLAC',
'oggspeex': 'OggSpeex',
'oggtheora': 'OggTheora',
'oggvorbis': 'OggVorbis',
'oggopus': 'OggOpus',
'trueaudio': 'TrueAudio',
'wavpack': 'WavPack',
'monkeysaudio': 'MonkeysAudio',
'optimfrog': 'OptimFROG',
}
@ -78,7 +78,7 @@ class ScrubPlugin(BeetsPlugin):
"""
classes = []
for modname, clsname in _MUTAGEN_FORMATS.items():
mod = __import__(b'mutagen.{0}'.format(modname),
mod = __import__('mutagen.{0}'.format(modname),
fromlist=[clsname])
classes.append(getattr(mod, clsname))
return classes

View file

@ -323,9 +323,9 @@ class ListenersTest(unittest.TestCase, TestHelper):
class DummyPlugin(plugins.BeetsPlugin):
def __init__(self):
super(DummyPlugin, self).__init__()
self.foo = Mock(__name__=b'foo')
self.foo = Mock(__name__='foo')
self.register_listener('event_foo', self.foo)
self.bar = Mock(__name__=b'bar')
self.bar = Mock(__name__='bar')
self.register_listener('event_bar', self.bar)
d = DummyPlugin()