modification of reset's arity

This commit is contained in:
gwen 2012-11-16 10:04:25 +01:00
parent e0bf9faf5c
commit b353c6ba60

View file

@ -216,27 +216,10 @@ class Option(HiddenBaseType, DisabledBaseType):
"config *must* be only the **parent** config (not the toplevel config)"
return config._cfgimpl_value_owners[self._name]
def reset(self, config, idx=None):
def reset(self, config):
"""resets the default value and owner
:param idx: if not None, resets only the element at index idx
"""
if self.is_multi():
if idx is not None:
defval = self.getdefault()
value = getattr(config, self._name)
# if the default is ['a', 'b', 'c']
if len(defval) > idx:
# and idx = 2 -> there is a value in the default
value.setoption(defval[idx], idx, who='default')
else:
# and idx = 4 -> there is actually no such value in the default
value.setoption(self.default_multi, idx, who='default')
else:
value = Multi(self.getdefault(), config, self)
config.setoption(self._name, value, 'default')
else:
value = self.getdefault()
config.setoption(self._name, value, 'default')
config.setoption(self._name, self.getdefault(), 'default')
def is_default_owner(self, config):
"""
@ -298,17 +281,18 @@ class Option(HiddenBaseType, DisabledBaseType):
class ChoiceOption(Option):
opt_type = 'string'
def __init__(self, name, doc, values, default=None,
requires=None, callback=None, callback_params=None,
multi=False, mandatory=False, open_values=False):
def __init__(self, name, doc, values, default=None, default_multi=None,
requires=None, mandatory=False, multi=False, callback=None,
callback_params=None, open_values=False):
self.values = values
if open_values not in [True, False]:
raise ConfigError('Open_values must be a boolean for '
'{0}'.format(name))
self.open_values = open_values
super(ChoiceOption, self).__init__(name, doc, default=default,
callback=callback, callback_params=callback_params,
requires=requires, multi=multi, mandatory=mandatory)
default_multi=default_multi, callback=callback,
callback_params=callback_params, requires=requires,
multi=multi, mandatory=mandatory)
def _validate(self, value):
if not self.open_values: