py3: Fix calibredb list

Fixes #1863470 [[python3] calibredb list fails](https://bugs.launchpad.net/calibre/+bug/1863470)
This commit is contained in:
Kovid Goyal 2020-02-16 16:54:57 +05:30
parent 14a803229f
commit 1d35b78601
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -203,6 +203,7 @@ def do_list(
) )
with ColoredStream(sys.stdout, fg='green'): with ColoredStream(sys.stdout, fg='green'):
prints(''.join(titles)) prints(''.join(titles))
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
wrappers = [TextWrapper(x - 1).wrap if x > 1 else lambda y: y for x in widths] wrappers = [TextWrapper(x - 1).wrap if x > 1 else lambda y: y for x in widths]
@ -214,10 +215,10 @@ def do_list(
for l in range(lines): for l in range(lines):
for i, field in enumerate(text): for i, field in enumerate(text):
ft = text[i][l] if l < len(text[i]) else u'' ft = text[i][l] if l < len(text[i]) else u''
sys.stdout.write(ft.encode('utf-8')) stdout.write(ft.encode('utf-8'))
if i < len(text) - 1: if i < len(text) - 1:
filler = (u'%*s' % (widths[i] - str_width(ft) - 1, u'')) filler = (u'%*s' % (widths[i] - str_width(ft) - 1, u''))
sys.stdout.write((filler + separator).encode('utf-8')) stdout.write((filler + separator).encode('utf-8'))
print() print()