Skip to content

Commit

Permalink
Merge pull request #2219 from vasily-smirnov/non_ascii_user_home
Browse files Browse the repository at this point in the history
Open configuration file with utf-8 encoding on Windows and Python 2
  • Loading branch information
ccordoba12 committed Mar 10, 2015
2 parents 2dc59d7 + 1bfcb54 commit 66ee1f8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spyderlib/userconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
from spyderlib.py3compat import configparser as cp
from spyderlib.py3compat import PY2, is_text_string, to_text_string

if PY2:
import codecs

#==============================================================================
# Auxiliary classes
Expand Down Expand Up @@ -113,7 +115,7 @@ def _save(self):
def _write_file(fname):
if PY2:
# Python 2
with open(fname, 'w') as configfile:
with codecs.open(fname, 'w', encoding='utf-8') as configfile:
self._write(configfile)
else:
# Python 3
Expand Down Expand Up @@ -251,7 +253,13 @@ def load_from_ini(self):
try:
if PY2:
# Python 2
self.read(self.filename())
fname = self.filename()
if osp.isfile(fname):
try:
with codecs.open(fname, encoding='utf-8') as configfile:
self.readfp(configfile)
except IOError:
print("Failed reading file", fname)
else:
# Python 3
self.read(self.filename(), encoding='utf-8')
Expand Down

0 comments on commit 66ee1f8

Please sign in to comment.