add _second_level_validation (second's one return only warning almost _validator raise)

This commit is contained in:
2013-09-25 21:10:45 +02:00
parent 4e0f0a5b70
commit 329b9ac349
2 changed files with 31 additions and 1 deletions

View File

@ -473,7 +473,7 @@ class Option(BaseOption):
def do_validation(_value, _index=None):
if _value is None:
return True
return
ret_validation = None
try:
# valid with self._validator
@ -481,6 +481,7 @@ class Option(BaseOption):
# if not context launch consistency validation
if context is not None:
descr._valid_consistency(self, _value, context, _index)
self._second_level_validation(_value)
except ValueError as err:
msg = _("invalid value {0} for option {1}: {2}").format(
_value, self._name, err)
@ -610,6 +611,9 @@ class Option(BaseOption):
else:
self._state_callback = (callback, cllbck_prms)
def _second_level_validation(self, value):
pass
class ChoiceOption(Option):
"""represents a choice out of several objects.
@ -777,6 +781,9 @@ class IPOption(Option):
only_warning=only_warning)
def _validate(self, value):
IP('{0}/32'.format(value))
def _second_level_validation(self, value):
ip = IP('{0}/32'.format(value))
if not self._allow_reserved and ip.iptype() == 'RESERVED':
raise ValueError(_("IP mustn't not be in reserved class"))
@ -860,6 +867,9 @@ class NetworkOption(Option):
_opt_type = 'network'
def _validate(self, value):
IP(value)
def _second_level_validation(self, value):
ip = IP(value)
if ip.iptype() == 'RESERVED':
raise ValueError(_("network shall not be in reserved class"))