From bc0061ca5b8d90efe11a9273024610a3a3585e32 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 4 Jul 2012 15:54:34 +0200 Subject: [PATCH] valdation against the default value with multi --- option.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/option.py b/option.py index acc9079..3848850 100644 --- a/option.py +++ b/option.py @@ -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