Skip to content

Commit

Permalink
Merge pull request #3929 from rlaverde/save-original-encoding
Browse files Browse the repository at this point in the history
PR:  Save file with original encoding if possible
  • Loading branch information
ccordoba12 authored Jan 7, 2017
2 parents d7dd020 + ccacab3 commit aaf345c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spyder/utils/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ def encode(text, orig_coding):
if orig_coding == 'utf-8-bom':
return BOM_UTF8 + text.encode("utf-8"), 'utf-8-bom'

# Try saving with original encoding
if orig_coding:
try:
return text.encode(orig_coding), orig_coding
except UnicodeError:
pass

# Try declared coding spec
coding = get_coding(text)
if coding:
Expand Down

0 comments on commit aaf345c

Please sign in to comment.