You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2020/07/23 01:29:30 UTC

[GitHub] [incubator-heron] thinker0 commented on a change in pull request #3580: Fix log-reader for Python3

thinker0 commented on a change in pull request #3580:
URL: https://github.com/apache/incubator-heron/pull/3580#discussion_r459171310



##########
File path: heron/shell/src/python/utils.py
##########
@@ -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'))

Review comment:
       The code is not working in python3 rather than python compatible. I am trying to modify it because the above error occurs.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org