From 8bcede4f389592a98f7c49a12bd9a21e639f8856 Mon Sep 17 00:00:00 2001 From: ulif Date: Thu, 26 Sep 2013 12:47:43 +0200 Subject: [PATCH] Fix bug: allow non-ASCII chars in sources. --- src/z3c/coverage/coveragereport.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/z3c/coverage/coveragereport.py b/src/z3c/coverage/coveragereport.py index ba09baf..70a513b 100755 --- a/src/z3c/coverage/coveragereport.py +++ b/src/z3c/coverage/coveragereport.py @@ -56,6 +56,8 @@ '--language=html', '--highlight=python', '--color', '-o', '-'] +#: Expected encoding of highlight command (enscript). +HIGHLIGHT_CMD_ENCODING = 'latin1' class Lazy(object): """Descriptor for lazy evaluation""" @@ -412,7 +414,9 @@ def key(node_info): continue # skip root node print_table_row(html, node, file_index) print('
', file=html) - print(tree.get_at(my_index).html_source, file=html) + print( + (tree.get_at(my_index).html_source).encode(HIGHLIGHT_CMD_ENCODING), + file=html) print(FOOTER % footer, file=html) html.close() @@ -432,7 +436,7 @@ def syntax_highlight(filename): with open(filename, 'r') as file: text = cgi.escape(file.read()) else: - text = text.decode('ascii') + text = text.decode(HIGHLIGHT_CMD_ENCODING) text = text[text.find('
')+len('
'):]
         text = text[:text.find('
')] return text