Fix log-reader for Python3 (#3580)
* Fix log-reader for Python3
Signed-off-by: thinker0 <thinker0@linecorp.com>
* typo
Signed-off-by: thinker0 <thinker0@linecorp.com>
* Revert commit
Co-authored-by: thinker0 <thinker0@linecorp.com>
diff --git a/heron/shell/src/python/utils.py b/heron/shell/src/python/utils.py
index e5e1cd8..8223d79 100644
--- a/heron/shell/src/python/utils.py
+++ b/heron/shell/src/python/utils.py
@@ -135,7 +135,7 @@
if length == -1:
length = fstat.st_size - offset
- with open(filename, "r") as fp:
+ with open(filename, "rb") as fp:
fp.seek(offset)
try:
data = fp.read(length)
@@ -143,7 +143,8 @@
return {}
if data:
- data = _escape_data(data) if escape_data else data
+ # use permissive decoding and escaping if escape_data is set, otherwise use strict decoding
+ data = _escape_data(data) if escape_data else data.decode()
return dict(offset=offset, length=len(data), data=data)
return dict(offset=offset, length=0)