summaryrefslogtreecommitdiff
path: root/testtools/utils.py
diff options
context:
space:
mode:
authorMartin <gzlist@googlemail.com>2010-06-18 19:09:32 +0100
committerMartin <gzlist@googlemail.com>2010-06-18 19:09:32 +0100
commitd74cc07384d54575c5c0b9d60a029626db7d7714 (patch)
treef6c62ce8636c1cf7e6bcf8c2b9a786053715237e /testtools/utils.py
parente2bcd5c8c8829e43838bdec4f8475d498d3ce0fc (diff)
downloadtesttools-d74cc07384d54575c5c0b9d60a029626db7d7714.tar.gz
Fix and test a bug with encoding of SyntaxError lines
Diffstat (limited to 'testtools/utils.py')
-rw-r--r--testtools/utils.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/testtools/utils.py b/testtools/utils.py
index 51997df..0d89061 100644
--- a/testtools/utils.py
+++ b/testtools/utils.py
@@ -205,7 +205,13 @@ def _format_exc_info(eclass, evalue, tb, limit=None):
if filename:
filename = filename.decode(fs_enc, "replace")
if line:
- line = line.decode(_get_source_encoding(filename), "replace")
+ # Errors during parsing give the line from buffer encoded as
+ # latin-1 if the given coding or utf-8 for all other codings
+ # Can't know which was used, so just try utf-8 first
+ try:
+ line = line.decode("utf-8")
+ except UnicodeDecodeError:
+ line = line.decode("latin-1")
evalue = eclass(evalue.args[0], (filename, lineno, offset, line))
list.extend(traceback.format_exception_only(eclass, evalue))
else: