mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 04:55:10 +01:00
Merge pull request #2094 from jrobeson/ui-print_-args-must-be-unicode
make sure ui.print_() only accepts unicode strings
This commit is contained in:
commit
dc0fff0ca0
4 changed files with 24 additions and 22 deletions
|
|
@ -135,25 +135,25 @@ def print_(*strings, **kwargs):
|
|||
is not in the terminal's encoding's character set, just silently
|
||||
replaces it.
|
||||
|
||||
If the arguments are strings then they're expected to share the same
|
||||
type: either bytes or unicode.
|
||||
The arguments must be unicode strings
|
||||
|
||||
The `end` keyword argument behaves similarly to the built-in `print`
|
||||
(it defaults to a newline). The value should have the same string
|
||||
type as the arguments.
|
||||
"""
|
||||
if not strings:
|
||||
strings = [u'']
|
||||
|
||||
end = kwargs.get('end')
|
||||
assert isinstance(strings[0], six.text_type)
|
||||
|
||||
if not strings or isinstance(strings[0], six.text_type):
|
||||
txt = u' '.join(strings)
|
||||
txt += u'\n' if end is None else end
|
||||
else:
|
||||
txt = b' '.join(strings)
|
||||
txt += b'\n' if end is None else end
|
||||
txt = u' '.join(strings)
|
||||
txt += u'\n' if end is None else end
|
||||
|
||||
# Always send bytes to the stdout stream.
|
||||
if isinstance(txt, six.text_type):
|
||||
txt = txt.encode(_out_encoding(), 'replace')
|
||||
# Always send bytes to the stdout stream on python 2.
|
||||
if six.PY2:
|
||||
if isinstance(txt, six.text_type):
|
||||
txt = txt.encode(_out_encoding(), 'replace')
|
||||
|
||||
sys.stdout.write(txt)
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ def input_(prompt=None):
|
|||
# use print_() explicitly to display prompts.
|
||||
# http://bugs.python.org/issue1927
|
||||
if prompt:
|
||||
print_(prompt, end=' ')
|
||||
print_(prompt, end=u' ')
|
||||
|
||||
try:
|
||||
resp = input()
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@ def _print_keys(query):
|
|||
returned row, with identation of 2 spaces.
|
||||
"""
|
||||
for row in query:
|
||||
print_(' ' * 2 + row['key'])
|
||||
print_(u' ' * 2 + six.text_type(row['key']))
|
||||
|
||||
|
||||
def fields_func(lib, opts, args):
|
||||
def _print_rows(names):
|
||||
names.sort()
|
||||
print_(" " + "\n ".join(names))
|
||||
print_(six.text_type(' ' + '\n '.join(names)))
|
||||
|
||||
print_(u"Item fields:")
|
||||
_print_rows(library.Item.all_keys())
|
||||
|
|
@ -1060,10 +1060,10 @@ def list_items(lib, query, album, fmt=''):
|
|||
"""
|
||||
if album:
|
||||
for album in lib.albums(query):
|
||||
ui.print_(format(album, fmt))
|
||||
ui.print_(six.text_type(format(album, fmt)))
|
||||
else:
|
||||
for item in lib.items(query):
|
||||
ui.print_(format(item, fmt))
|
||||
ui.print_(six.text_type(format(item, fmt)))
|
||||
|
||||
|
||||
def list_func(lib, opts, args):
|
||||
|
|
@ -1211,7 +1211,7 @@ def remove_items(lib, query, album, delete, force):
|
|||
prompt = u'Really DELETE %i file%s (y/n)?' % \
|
||||
(len(items), 's' if len(items) > 1 else '')
|
||||
else:
|
||||
fmt = ''
|
||||
fmt = u''
|
||||
prompt = u'Really remove %i item%s from the library (y/n)?' % \
|
||||
(len(items), 's' if len(items) > 1 else '')
|
||||
|
||||
|
|
@ -1608,7 +1608,7 @@ def config_func(lib, opts, args):
|
|||
filenames.insert(0, user_path)
|
||||
|
||||
for filename in filenames:
|
||||
print_(filename)
|
||||
print_(displayable_path(filename))
|
||||
|
||||
# Open in editor.
|
||||
elif opts.edit:
|
||||
|
|
@ -1616,7 +1616,8 @@ def config_func(lib, opts, args):
|
|||
|
||||
# Dump configuration.
|
||||
else:
|
||||
print_(config.dump(full=opts.defaults, redact=opts.redact))
|
||||
config_out = config.dump(full=opts.defaults, redact=opts.redact)
|
||||
print_(six.text_type(config_out))
|
||||
|
||||
|
||||
def config_edit():
|
||||
|
|
@ -1662,7 +1663,7 @@ default_commands.append(config_cmd)
|
|||
|
||||
def print_completion(*args):
|
||||
for line in completion_script(default_commands + plugins.commands()):
|
||||
print_(line, end='')
|
||||
print_(six.text_type(line), end=u'')
|
||||
if not any(map(os.path.isfile, BASH_COMPLETION_PATHS)):
|
||||
log.warn(u'Warning: Unable to find the bash-completion package. '
|
||||
u'Command line completion might not work.')
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from __future__ import division, absolute_import, print_function
|
|||
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
|
|
@ -91,7 +92,7 @@ def print_data(data, item=None, fmt=None):
|
|||
"""
|
||||
if fmt:
|
||||
# use fmt specified by the user
|
||||
ui.print_(format(item, fmt))
|
||||
ui.print_(six.text_type(format(item, fmt)))
|
||||
return
|
||||
|
||||
path = displayable_path(item.path) if item else None
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class PlayPlugin(BeetsPlugin):
|
|||
u'You are about to queue {0} {1}.'.format(
|
||||
len(selection), item_type)))
|
||||
|
||||
if ui.input_options(('Continue', 'Abort')) == 'a':
|
||||
if ui.input_options((u'Continue', u'Abort')) == 'a':
|
||||
return
|
||||
|
||||
ui.print_(u'Playing {0} {1}.'.format(len(selection), item_type))
|
||||
|
|
|
|||
Loading…
Reference in a new issue