Skip to content

Commit

Permalink
Merge pull request #5032 from jkseppan/utf-8-warning
Browse files Browse the repository at this point in the history
ENH: More useful warning about locale errors
  • Loading branch information
tacaswell committed Sep 5, 2015
2 parents 27606b7 + 5ab34e7 commit fac0417
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions lib/matplotlib/__init__.py
Expand Up @@ -1010,23 +1010,30 @@ def _rc_params_in_file(fname, fail_on_error=False):
cnt = 0
rc_temp = {}
with _open_file_or_url(fname) as fd:
for line in fd:
cnt += 1
strippedline = line.split('#', 1)[0].strip()
if not strippedline:
continue
tup = strippedline.split(':', 1)
if len(tup) != 2:
error_details = _error_details_fmt % (cnt, line, fname)
warnings.warn('Illegal %s' % error_details)
continue
key, val = tup
key = key.strip()
val = val.strip()
if key in rc_temp:
warnings.warn('Duplicate key in file "%s", line #%d' %
(fname, cnt))
rc_temp[key] = (val, line, cnt)
try:
for line in fd:
cnt += 1
strippedline = line.split('#', 1)[0].strip()
if not strippedline:
continue
tup = strippedline.split(':', 1)
if len(tup) != 2:
error_details = _error_details_fmt % (cnt, line, fname)
warnings.warn('Illegal %s' % error_details)
continue
key, val = tup
key = key.strip()
val = val.strip()
if key in rc_temp:
warnings.warn('Duplicate key in file "%s", line #%d' %
(fname, cnt))
rc_temp[key] = (val, line, cnt)
except UnicodeDecodeError:
warnings.warn(
('Cannot decode configuration file %s with '
'encoding %s, check LANG and LC_* variables')
% (fname, locale.getdefaultlocale()[1] or 'utf-8 (default)'))
raise

config = RcParams()

Expand Down

0 comments on commit fac0417

Please sign in to comment.