Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fix log-reader for Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
thinker0 committed Jul 23, 2020
1 parent eb5090b commit 7747641
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions heron/shell/src/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,22 @@ def read_chunk(filename, offset=-1, length=-1, escape_data=False):
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)
except IOError:
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)

def _escape_data(data):
return escape(data.decode('utf8', 'replace'))
return escape(data)

def pipe(prev_proc, to_cmd):
"""
Expand Down

0 comments on commit 7747641

Please sign in to comment.