From 16687cba130ce249a4b69f7d6feb1e7c0336287d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 8 Oct 2011 11:57:21 -0400 Subject: Handle unicode in indented error messages. --- morphlib/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'morphlib/util.py') diff --git a/morphlib/util.py b/morphlib/util.py index 355fcd16..850d943f 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -25,8 +25,13 @@ def indent(string, spaces=4): logging library adds a newline, so not including it in the indented text avoids a spurious empty line in the log file. + This also makes the result be a plain ASCII encoded string. + ''' - return '\n'.join('%*s%s' % (spaces, '', line) - for line in string.splitlines()) + if type(string) == unicode: # pragma: no cover + string = string.decode('utf-8') + lines = string.splitlines() + lines = ['%*s%s' % (spaces, '', line) for line in lines] + return '\n'.join(lines) -- cgit v1.2.1