Encode to utf-8 before printing

When redirecting the output of openreviews to a file, if there are
utf-8 characters in, for example, a commit message, openreviews
will raise an exception because it tries to encode as ascii by
default.

This change explicitly encodes basestring output to utf-8 so it
doesn't matter what the encoding of the output stream is.

Change-Id: I581c1a98bdbbbfb17ccf33c59295d6fbf8729ab9
This commit is contained in:
Ben Nemec 2014-06-10 14:38:24 +00:00
parent 635aca577d
commit 8e363b81e0

View File

@ -175,7 +175,7 @@ def print_stats_txt(stats, f=sys.stdout):
def print_item_txt(item, level):
if isinstance(item, basestring):
f.write('%s\n' % item)
f.write('%s\n' % item.encode('utf-8'))
elif isinstance(item, list):
print_list_txt(item, level + 1)
elif isinstance(item, tuple):
@ -204,7 +204,7 @@ def print_stats_html(stats, f=sys.stdout):
def print_item_html(item, level):
if isinstance(item, basestring):
f.write('%s' % item)
f.write('%s' % item.encode('utf-8'))
elif isinstance(item, list):
print_list_html(item, level + 1)
elif isinstance(item, tuple):