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

Fix log-reader for Python3 #3580

Merged
merged 3 commits into from
Jul 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions heron/shell/src/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ 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:
Copy link
Contributor

@Code0x58 Code0x58 Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with the previous behaviour (not sure it still makes sense), I think the whole PR change would be something like:

with open(filename, "rb") as fp:
   ...
   if 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()
       ....

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)
Expand Down