From 8e363b81e0284712a553a89c0e51d7b1070e3a6a Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 10 Jun 2014 14:38:24 +0000 Subject: [PATCH] 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 --- reviewstats/cmd/openreviews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reviewstats/cmd/openreviews.py b/reviewstats/cmd/openreviews.py index c282b0d..498bb36 100755 --- a/reviewstats/cmd/openreviews.py +++ b/reviewstats/cmd/openreviews.py @@ -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):