SWU: Fix issue with log output containing non ASCII characters
See #1586
This commit is contained in:
parent
b4215c885c
commit
2c6fb68544
1 changed files with 11 additions and 1 deletions
|
|
@ -27,7 +27,9 @@ def _log(lines, prefix=None, stream=None):
|
|||
output_stream = sys.stderr
|
||||
|
||||
for line in lines:
|
||||
print(u"{} {}".format(prefix, _to_unicode(line.rstrip(), errors="replace")), file=output_stream)
|
||||
to_print = _to_str(u"{} {}".format(prefix, _to_unicode(line.rstrip(), errors="replace")),
|
||||
errors="replace")
|
||||
print(to_print, file=output_stream)
|
||||
|
||||
|
||||
def _to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
|
|
@ -38,6 +40,14 @@ def _to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
|||
return s_or_u
|
||||
|
||||
|
||||
def _to_str(s_or_u, encoding="utf-8", errors="strict"):
|
||||
"""Make sure ``s_or_u`` is a str."""
|
||||
if isinstance(s_or_u, unicode):
|
||||
return s_or_u.encode(encoding, errors=errors)
|
||||
else:
|
||||
return s_or_u
|
||||
|
||||
|
||||
def _execute(command, **kwargs):
|
||||
import sarge
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue