Fall back to latin-1 encoding when failed with UTF-8 while parsing manifest

This commit is contained in:
Ivan Kravets
2020-06-30 14:28:37 +03:00
parent 5cdca9d490
commit 2c24e9eff6

View File

@ -61,8 +61,14 @@ class ManifestFileType(object):
class ManifestParserFactory(object): class ManifestParserFactory(object):
@staticmethod @staticmethod
def read_manifest_contents(path): def read_manifest_contents(path):
with io.open(path, encoding="utf-8") as fp: last_err = None
return fp.read() for encoding in ("utf-8", "latin-1"):
try:
with io.open(path, encoding=encoding) as fp:
return fp.read()
except UnicodeDecodeError as e:
last_err = e
raise last_err
@classmethod @classmethod
def new_from_file(cls, path, remote_url=False): def new_from_file(cls, path, remote_url=False):