Skip to content

Commit

Permalink
Fix errors with get_coding and no-uft-8 files
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaverde committed Nov 25, 2016
1 parent 2bb47cf commit 86d7a21
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions spyder/utils/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ def get_coding(text):
@return coding string
"""
for line in text.splitlines()[:2]:
result = CODING_RE.search(to_text_string(line))
if result:
codec = result.group(1)
# sometimes we find a false encoding that can result in errors
if codec in CODECS:
return codec
try:
result = CODING_RE.search(to_text_string(line))
except UnicodeDecodeError:
# This could fail because to_text_string assume the text is utf8-like
# and we don't know the encoding to give it to to_text_string
pass
else:
if result:
codec = result.group(1)
# sometimes we find a false encoding that can result in errors
if codec in CODECS:
return codec

# Fallback using chardet
if is_binary_string(text):
Expand Down

0 comments on commit 86d7a21

Please sign in to comment.