valdation against the default value with multi
This commit is contained in:
parent
df7a7f2c29
commit
bc0061ca5b
13
option.py
13
option.py
|
@ -50,15 +50,15 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||||
if mode not in modes:
|
if mode not in modes:
|
||||||
raise ConfigError("mode {0} not available".format(mode))
|
raise ConfigError("mode {0} not available".format(mode))
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
_default = default
|
||||||
if default != None:
|
if default != None:
|
||||||
if self.multi == True and type(default) != list:
|
if self.multi == True and type(default) != list:
|
||||||
_default = [default]
|
raise ConfigError("invalid default value {0} "
|
||||||
else:
|
"for option {1} : not list type".format(str(default), name))
|
||||||
_default = default
|
|
||||||
if not self.validate(_default):
|
if not self.validate(_default):
|
||||||
raise ConfigError("invalid default value {0} "
|
raise ConfigError("invalid default value {0} "
|
||||||
"for option {1}".format(default, name))
|
"for option {1}".format(str(default), name))
|
||||||
self.default = default
|
self.default = _default
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if self.multi == False:
|
if self.multi == False:
|
||||||
|
@ -113,7 +113,10 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||||
|
|
||||||
if who == "default":
|
if who == "default":
|
||||||
# changes the default value (and therefore resets the previous value)
|
# changes the default value (and therefore resets the previous value)
|
||||||
|
if self._validate(value):
|
||||||
self.default = value
|
self.default = value
|
||||||
|
else:
|
||||||
|
raise ConfigError("invalid value %s for option %s" % (value, name))
|
||||||
apply_requires(self, config)
|
apply_requires(self, config)
|
||||||
# FIXME put the validation for the multi somewhere else
|
# FIXME put the validation for the multi somewhere else
|
||||||
# # it is a multi **and** it has requires
|
# # it is a multi **and** it has requires
|
||||||
|
|
Loading…
Reference in New Issue