Skip to content

Commit ecf71ef

Browse files
committed
fix: File.read() on Python3
File.read() was not working properly with Python3 and non utf-8 files.
1 parent 75c879b commit ecf71ef

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

core/utils/file_utils.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,18 @@ def get_size(folder):
8585
return total_size
8686

8787

88+
# noinspection PyUnresolvedReferences
8889
class File(object):
8990
@staticmethod
90-
def read(path, log_content=False):
91+
def read(path):
9192
if File.exists(path):
92-
with open(path, 'r') as file_to_read:
93-
output = file_to_read.read()
94-
if log_content:
95-
Log.info('Read ' + path + ':')
96-
Log.info(output)
9793
if Settings.PYTHON_VERSION < 3:
98-
# noinspection PyUnresolvedReferences
94+
with open(path, 'r') as file_to_read:
95+
output = file_to_read.read()
9996
return str(output.decode('utf8').encode('utf8'))
10097
else:
98+
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
99+
output = f.read()
101100
return output
102101
else:
103102
raise IOError("{0} not found!".format(path))

0 commit comments

Comments
 (0)