@@ -1010,23 +1010,30 @@ def _rc_params_in_file(fname, fail_on_error=False):
10101010 cnt = 0
10111011 rc_temp = {}
10121012 with _open_file_or_url (fname ) as fd :
1013- for line in fd :
1014- cnt += 1
1015- strippedline = line .split ('#' , 1 )[0 ].strip ()
1016- if not strippedline :
1017- continue
1018- tup = strippedline .split (':' , 1 )
1019- if len (tup ) != 2 :
1020- error_details = _error_details_fmt % (cnt , line , fname )
1021- warnings .warn ('Illegal %s' % error_details )
1022- continue
1023- key , val = tup
1024- key = key .strip ()
1025- val = val .strip ()
1026- if key in rc_temp :
1027- warnings .warn ('Duplicate key in file "%s", line #%d' %
1028- (fname , cnt ))
1029- rc_temp [key ] = (val , line , cnt )
1013+ try :
1014+ for line in fd :
1015+ cnt += 1
1016+ strippedline = line .split ('#' , 1 )[0 ].strip ()
1017+ if not strippedline :
1018+ continue
1019+ tup = strippedline .split (':' , 1 )
1020+ if len (tup ) != 2 :
1021+ error_details = _error_details_fmt % (cnt , line , fname )
1022+ warnings .warn ('Illegal %s' % error_details )
1023+ continue
1024+ key , val = tup
1025+ key = key .strip ()
1026+ val = val .strip ()
1027+ if key in rc_temp :
1028+ warnings .warn ('Duplicate key in file "%s", line #%d' %
1029+ (fname , cnt ))
1030+ rc_temp [key ] = (val , line , cnt )
1031+ except UnicodeDecodeError :
1032+ warnings .warn (
1033+ ('Cannot decode configuration file %s with '
1034+ 'encoding %s, check LANG and LC_* variables' )
1035+ % (fname , locale .getdefaultlocale ()[1 ] or 'utf-8 (default)' ))
1036+ raise
10301037
10311038 config = RcParams ()
10321039
0 commit comments