diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-10-08 11:57:21 -0400 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-10-08 11:57:21 -0400 |
commit | 16687cba130ce249a4b69f7d6feb1e7c0336287d (patch) | |
tree | 4b0a981e73847ec148eda98ae7797c20690536c0 /morphlib/util.py | |
parent | e4ae3034041d10c8bd48ca39303735a5e7e6b969 (diff) | |
download | morph-16687cba130ce249a4b69f7d6feb1e7c0336287d.tar.gz |
Handle unicode in indented error messages.
Diffstat (limited to 'morphlib/util.py')
-rw-r--r-- | morphlib/util.py | 9 |
1 files changed, 7 insertions, 2 deletions
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) |