Module: check_mk
Branch: master
Commit: a43e24cd82d6369754acf1ba2ff7e8c382e67523
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a43e24cd82d636…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 27 11:08:43 2018 +0200
6373 FIX Fixed UnicodeEncodeError when piping "cmk -M" to stream or file
The output of e.g. "cmk -M" was not correctly encoded when the output
was written to streams or files leading to a "UnicodeEncodeError: 'ascii'
codec can't encode character" error.
Change-Id: Iff3d9bc0a63ca78c4e7e24bf5f909ebfbcd616ca
---
.werks/6373 | 12 ++++++++++++
cmk/tty.py | 8 ++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/.werks/6373 b/.werks/6373
new file mode 100644
index 0000000..73c7352
--- /dev/null
+++ b/.werks/6373
@@ -0,0 +1,12 @@
+Title: Fixed UnicodeEncodeError when piping "cmk -M" to stream or file
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1532682455
+
+The output of e.g. "cmk -M" was not correctly encoded when the output
+was written to streams or files leading to a "UnicodeEncodeError: 'ascii'
codec can't encode character" error.
diff --git a/cmk/tty.py b/cmk/tty.py
index 42ae84e..63e9be7 100644
--- a/cmk/tty.py
+++ b/cmk/tty.py
@@ -115,10 +115,10 @@ def print_table(headers, colors, rows, indent = ""):
if type(x) == unicode:
return x.encode('utf-8')
else:
- return x
+ return "%s" % x
for row in rows:
- lengths = [ max(len(str(make_utf8(c))), l) for c, l in zip(row, lengths) ]
+ lengths = [ max(len(make_utf8(c)), l) for c, l in zip(row, lengths) ]
fmt = indent
sep = ""
@@ -129,7 +129,7 @@ def print_table(headers, colors, rows, indent = ""):
first = True
fmt += "\n"
for row in [ headers ] + rows:
- sys.stdout.write(fmt % tuple(row[:len(headers)]))
+ sys.stdout.write(fmt % tuple(make_utf8(c) for c in row[:len(headers)]))
if first:
first = False
- sys.stdout.write(fmt % tuple([ "-" * l for l in lengths ]))
+ sys.stdout.write(fmt % tuple("-" * l for l in lengths))