valdation against the default value with multi

This commit is contained in:
gwen 2012-07-04 15:54:34 +02:00
parent df7a7f2c29
commit bc0061ca5b
1 changed files with 9 additions and 6 deletions

View File

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