Fix an issue with encoding detection

This commit is contained in:
Dave Halter
2020-07-25 18:11:49 +02:00
parent 6a4bb35d80
commit d3c274afa0

View File

@@ -96,7 +96,10 @@ def python_bytes_to_unicode(
possible_encoding = re.search(br"coding[=:]\s*([-\w.]+)",
first_two_lines)
if possible_encoding:
return possible_encoding.group(1)
e = possible_encoding.group(1)
if not isinstance(e, str):
e = str(e, 'ascii', 'replace')
return e
else:
# the default if nothing else has been set -> PEP 263
return encoding