mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-19 08:15:23 +00:00
Only use utf-8 encoding for now
This commit is contained in:
1 parent
34ad871b21
commit
6c7b2e9078
1 file changed
+2
-12
@@ -128,22 +128,12 @@ class FileUtils:
|
|||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
logger.log(f"File read '{file_path}' failed: File does not exist.", logging.ERROR)
|
logger.log(f"File read '{file_path}' failed: File does not exist.", logging.ERROR)
|
||||||
raise MultilspyException(f"File read '{file_path}' failed: File does not exist.")
|
raise MultilspyException(f"File read '{file_path}' failed: File does not exist.")
|
||||||
encodings = ["utf-8-sig", "utf-16", "utf-8", "latin-1"]
|
|
||||||
try:
|
try:
|
||||||
for encoding in encodings:
|
with open(file_path, "r", encoding="utf-8") as inp_file:
|
||||||
try:
|
|
||||||
with open(file_path, "r", encoding=encoding) as inp_file:
|
|
||||||
return inp_file.read()
|
|
||||||
except UnicodeError:
|
|
||||||
continue
|
|
||||||
# Try system default encoding as a last resort
|
|
||||||
with open(file_path, "r") as inp_file:
|
|
||||||
return inp_file.read()
|
return inp_file.read()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.log(f"File read '{file_path}' failed: {exc}", logging.ERROR)
|
logger.log(f"File read '{file_path}' failed to read with encoding 'utf-8': {exc}", logging.ERROR)
|
||||||
raise MultilspyException("File read failed.") from None
|
raise MultilspyException("File read failed.") from None
|
||||||
logger.log(f"File read '{file_path}' failed: Unsupported encoding.", logging.ERROR)
|
|
||||||
raise MultilspyException(f"File read '{file_path}' failed: Unsupported encoding.") from None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None:
|
def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None:
|
||||||
|
|||||||
Reference in new issue
Block a user