comparison mercurial/config.py @ 31315:c920efa9d34b

config: guard against setconfig specifying unicode values on py3 This was leading to some difficult to trace problems because the values were set in one place, but then blew up much later in the program. Exploding violently with an assertion seems reasonable here.
author Augie Fackler <raf@durin42.com>
date Fri, 03 Mar 2017 14:42:56 -0500
parents 99c5843b228d
children d30fb3de4b40
comparison
equal deleted inserted replaced
31314:dc9842a7017c 31315:c920efa9d34b
11 import os 11 import os
12 12
13 from .i18n import _ 13 from .i18n import _
14 from . import ( 14 from . import (
15 error, 15 error,
16 pycompat,
16 util, 17 util,
17 ) 18 )
18 19
19 class config(object): 20 class config(object):
20 def __init__(self, data=None, includepaths=[]): 21 def __init__(self, data=None, includepaths=[]):
67 def sections(self): 68 def sections(self):
68 return sorted(self._data.keys()) 69 return sorted(self._data.keys())
69 def items(self, section): 70 def items(self, section):
70 return self._data.get(section, {}).items() 71 return self._data.get(section, {}).items()
71 def set(self, section, item, value, source=""): 72 def set(self, section, item, value, source=""):
73 if pycompat.ispy3:
74 assert not isinstance(value, str), (
75 'config values may not be unicode strings on Python 3')
72 if section not in self: 76 if section not in self:
73 self._data[section] = util.sortdict() 77 self._data[section] = util.sortdict()
74 self._data[section][item] = value 78 self._data[section][item] = value
75 if source: 79 if source:
76 self._source[(section, item)] = source 80 self._source[(section, item)] = source