From c91e7eff97d34be565e3e98b6935446144d4af58 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 10 May 2013 16:00:46 +0200 Subject: [PATCH] if not need, don't validate --- tiramisu/option.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/tiramisu/option.py b/tiramisu/option.py index 8598037..a22f7d7 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -258,30 +258,29 @@ class Option(BaseInformation): # generic calculation if context is not None: descr = context.cfgimpl_get_description() - if not self._multi: - if value is not None and ((validate and - self._validator is not None and - not val_validator()) or - not self._validate(value)): - raise ValueError(_("invalid value {0} for option {1}" - "").format(value, self._name)) - if context is not None: - descr._valid_consistency(self, value, context, None) - else: - if not isinstance(value, list): - raise ValueError(_("invalid value {0} for option {1} " - "which must be a list").format(value, - self._name)) - for index in range(0, len(value)): - val = value[index] - if val is not None and ((validate and - self._validator is not None and - not val_validator()) or - not self._validate(val)): - raise ValueError(_("invalid value {0} for option {1}" - "").format(value, self._name)) + if validate: + if not self._multi: + if value is not None and ((self._validator is not None and + not val_validator()) or + not self._validate(value)): + raise ValueError(_("invalid value {0} for option {1}" + "").format(value, self._name)) if context is not None: - descr._valid_consistency(self, val, context, index) + descr._valid_consistency(self, value, context, None) + else: + if not isinstance(value, list): + raise ValueError(_("invalid value {0} for option {1} " + "which must be a list").format(value, + self._name)) + for index in range(0, len(value)): + val = value[index] + if val is not None and ((self._validator is not None and + not val_validator()) or + not self._validate(val)): + raise ValueError(_("invalid value {0} for option {1}" + "").format(value, self._name)) + if context is not None: + descr._valid_consistency(self, val, context, index) def impl_getdefault(self, default_multi=False): "accessing the default value"