mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 01:25:47 +01:00
Require Unicode format strings
Fallout from #2188. Following @jrobeson's suggestion, I just turned the check in LibModel.__format__ into an assert. This turned up a few badly-behaved clients, which are also fixed.
This commit is contained in:
parent
ed8d04f594
commit
15a5512ea5
4 changed files with 10 additions and 14 deletions
|
|
@ -338,12 +338,8 @@ class LibModel(dbcore.Model):
|
|||
def __format__(self, spec):
|
||||
if not spec:
|
||||
spec = beets.config[self._format_config_key].as_str()
|
||||
result = self.evaluate_template(spec)
|
||||
if isinstance(spec, bytes):
|
||||
# if spec is a byte string then we must return a one as well
|
||||
return result.encode('utf-8')
|
||||
else:
|
||||
return result
|
||||
assert isinstance(spec, six.text_type)
|
||||
return self.evaluate_template(spec)
|
||||
|
||||
def __str__(self):
|
||||
return format(self)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ from __future__ import division, absolute_import, print_function
|
|||
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
|
|
@ -92,7 +91,7 @@ def print_data(data, item=None, fmt=None):
|
|||
"""
|
||||
if fmt:
|
||||
# use fmt specified by the user
|
||||
ui.print_(six.text_type(format(item, fmt)))
|
||||
ui.print_(format(item, fmt))
|
||||
return
|
||||
|
||||
path = displayable_path(item.path) if item else None
|
||||
|
|
@ -205,7 +204,8 @@ class InfoPlugin(BeetsPlugin):
|
|||
if opts.keys_only:
|
||||
print_data_keys(data, item)
|
||||
else:
|
||||
print_data(data, item, opts.format)
|
||||
fmt = ui.decargs([opts.format])[0]
|
||||
print_data(data, item, fmt)
|
||||
first = False
|
||||
|
||||
if opts.summarize:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class MBSubmitPlugin(BeetsPlugin):
|
|||
super(MBSubmitPlugin, self).__init__()
|
||||
|
||||
self.config.add({
|
||||
'format': '$track. $title - $artist ($length)',
|
||||
'format': u'$track. $title - $artist ($length)',
|
||||
'threshold': 'medium',
|
||||
})
|
||||
|
||||
|
|
@ -57,4 +57,4 @@ class MBSubmitPlugin(BeetsPlugin):
|
|||
|
||||
def print_tracks(self, session, task):
|
||||
for i in task.items:
|
||||
print_data(None, i, self.config['format'].get())
|
||||
print_data(None, i, self.config['format'].as_str())
|
||||
|
|
|
|||
|
|
@ -1055,12 +1055,12 @@ class TemplateTest(_common.LibTestCase):
|
|||
self.assertEqual(six.text_type(album), u"foö bar")
|
||||
self.assertEqual(bytes(album), b"fo\xc3\xb6 bar")
|
||||
|
||||
config['format_item'] = 'bar $foo'
|
||||
config['format_item'] = u'bar $foo'
|
||||
item = beets.library.Item()
|
||||
item.foo = u'bar'
|
||||
item.tagada = u'togodo'
|
||||
self.assertEqual("{0}".format(item), u"bar bar")
|
||||
self.assertEqual("{0:$tagada}".format(item), u"togodo")
|
||||
self.assertEqual(u"{0}".format(item), u"bar bar")
|
||||
self.assertEqual(u"{0:$tagada}".format(item), u"togodo")
|
||||
|
||||
|
||||
class UnicodePathTest(_common.LibTestCase):
|
||||
|
|
|
|||
Loading…
Reference in a new issue