mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 05:34:51 +08:00
Fix an issue with encoding detection
This commit is contained in:
@@ -96,7 +96,10 @@ def python_bytes_to_unicode(
|
|||||||
possible_encoding = re.search(br"coding[=:]\s*([-\w.]+)",
|
possible_encoding = re.search(br"coding[=:]\s*([-\w.]+)",
|
||||||
first_two_lines)
|
first_two_lines)
|
||||||
if possible_encoding:
|
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:
|
else:
|
||||||
# the default if nothing else has been set -> PEP 263
|
# the default if nothing else has been set -> PEP 263
|
||||||
return encoding
|
return encoding
|
||||||
|
|||||||
Reference in New Issue
Block a user