returns_raise is now mandatory in core

This commit is contained in:
2016-10-14 22:20:14 +02:00
parent 24ec5a9112
commit 4d02254234
8 changed files with 136 additions and 171 deletions

View File

@ -477,8 +477,7 @@ class Option(OnlyOption):
# Raise ValueError if not valid
value = carry_out_calculation(current_opt, context=context,
callback=validator,
callback_params=validator_params_,
returns_raise=True)
callback_params=validator_params_)
if isinstance(value, Exception):
return value
@ -487,8 +486,7 @@ class Option(OnlyOption):
error = warning = None
else:
# option validation
err = self._validate(_value, context, current_opt,
returns_raise=True)
err = self._validate(_value, context, current_opt)
if err:
if debug:
log.debug('do_validation: value: {0}, index: {1}, '

View File

@ -106,39 +106,39 @@ class MasterSlaves(object):
for slave in self.getslaves(opt):
if not values.is_default_owner(slave, validate_properties=False,
validate_meta=False, index=index):
values._get_cached_value(slave, validate=False,
validate_properties=False
).pop(index, force=True)
pass
multi = values._get_cached_value(slave, validate=False,
validate_properties=False,
)
if isinstance(multi, Exception):
raise multi
multi.pop(index, force=True)
def getitem(self, values, opt, path, validate, force_permissive,
trusted_cached_properties, validate_properties, session,
slave_path=undefined, slave_value=undefined,
setting_properties=undefined, self_properties=undefined, index=None,
returns_raise=False):
setting_properties=undefined, self_properties=undefined, index=None):
if self.is_master(opt):
return self._getmaster(values, opt, path, validate,
force_permissive,
validate_properties, slave_path,
slave_value, self_properties, index,
returns_raise, setting_properties, session)
setting_properties, session)
else:
return self._getslave(values, opt, path, validate,
force_permissive, trusted_cached_properties,
validate_properties, setting_properties,
self_properties, index, returns_raise,
self_properties, index,
session)
def _getmaster(self, values, opt, path, validate, force_permissive,
validate_properties, c_slave_path,
c_slave_value, self_properties, index, returns_raise,
c_slave_value, self_properties, index,
setting_properties, session):
value = values._get_cached_value(opt, path=path, validate=validate,
force_permissive=force_permissive,
validate_properties=validate_properties,
self_properties=self_properties,
from_masterslave=True, index=index,
returns_raise=True,
setting_properties=setting_properties)
if isinstance(value, Exception):
return value
@ -152,7 +152,7 @@ class MasterSlaves(object):
def _getslave(self, values, opt, path, validate, force_permissive,
trusted_cached_properties, validate_properties, setting_properties,
self_properties, index, returns_raise, session):
self_properties, index, session):
"""
if master has length 0:
return []
@ -179,7 +179,7 @@ class MasterSlaves(object):
masterp = master.impl_getpath(context)
masterlen = self.get_length(values, opt, session, validate, undefined,
undefined, force_permissive,
master=master, returns_raise=returns_raise)
master=master)
if isinstance(masterlen, Exception):
return masterlen
master_is_meta = values._is_meta(master, masterp, session)
@ -194,10 +194,7 @@ class MasterSlaves(object):
force_permissive=force_permissive,
setting_properties=setting_properties)
if props:
if returns_raise:
return props
else:
raise props
return props
else:
one_has_value = False
if index is None:
@ -216,8 +213,7 @@ class MasterSlaves(object):
#self_properties=self_properties,
setting_properties=setting_properties,
masterlen=masterlen,
from_masterslave=True,
returns_raise=True)
from_masterslave=True)
if isinstance(value, Exception):
if isinstance(value, PropertiesOptionError):
err = value
@ -233,13 +229,10 @@ class MasterSlaves(object):
one_has_value = True
if not one_has_value:
#raise last err
if returns_raise:
return err
else:
raise err
return err
return multi
def validate(self, values, opt, value, path, returns_raise, session):
def validate(self, values, opt, value, path, session):
if self.is_master(opt):
masterlen = len(value)
#for regen slave path
@ -249,7 +242,7 @@ class MasterSlaves(object):
slavelen = values._p_.get_max_length(slave_path, session)
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt)
else:
val_len = self.get_length(values, opt, session, slave_path=path, returns_raise=returns_raise)
val_len = self.get_length(values, opt, session, slave_path=path)
if isinstance(val_len, Exception):
return val_len
self.validate_slave_length(val_len,
@ -258,7 +251,7 @@ class MasterSlaves(object):
def get_length(self, values, opt, session, validate=True, slave_path=undefined,
slave_value=undefined, force_permissive=False, master=None,
masterp=None, returns_raise=False):
masterp=None):
"""get master len with slave option"""
if master is None:
master = self.getmaster(opt)
@ -268,7 +261,7 @@ class MasterSlaves(object):
slave_path = undefined
value = self.getitem(values, master, masterp, validate,
force_permissive, None, True, session, slave_path=slave_path,
slave_value=slave_value, returns_raise=returns_raise)
slave_value=slave_value)
if isinstance(value, Exception):
return value
return len(value)

View File

@ -70,8 +70,7 @@ class ChoiceOption(Option):
session=session)
self.commit(session)
def impl_get_values(self, context, current_opt=undefined,
returns_raise=False):
def impl_get_values(self, context, current_opt=undefined):
if current_opt is undefined:
current_opt = self
params = undefined
@ -87,8 +86,7 @@ class ChoiceOption(Option):
values_params = self.impl_get_choice_values_params()
values = carry_out_calculation(current_opt, context=context,
callback=values,
callback_params=values_params,
returns_raise=returns_raise)
callback_params=values_params)
if isinstance(values, Exception):
return values
if values is not undefined and not isinstance(values, list): # pragma: optional cover
@ -97,10 +95,8 @@ class ChoiceOption(Option):
return values
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
values = self.impl_get_values(context, current_opt=current_opt,
returns_raise=returns_raise)
def _validate(self, value, context=undefined, current_opt=undefined):
values = self.impl_get_values(context, current_opt=current_opt)
if isinstance(values, Exception):
return values
if values is not undefined and not value in values: # pragma: optional cover
@ -117,8 +113,7 @@ class BoolOption(Option):
__slots__ = tuple()
_display_name = _('boolean')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if not isinstance(value, bool):
return ValueError() # pragma: optional cover
@ -128,8 +123,7 @@ class IntOption(Option):
__slots__ = tuple()
_display_name = _('integer')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if not isinstance(value, int):
return ValueError() # pragma: optional cover
@ -139,8 +133,7 @@ class FloatOption(Option):
__slots__ = tuple()
_display_name = _('float')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if not isinstance(value, float):
return ValueError() # pragma: optional cover
@ -150,8 +143,7 @@ class StrOption(Option):
__slots__ = tuple()
_display_name = _('string')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if not isinstance(value, str):
return ValueError() # pragma: optional cover
@ -168,8 +160,7 @@ else:
_empty = u''
_display_name = _('unicode string')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if not isinstance(value, unicode):
return ValueError() # pragma: optional cover
@ -179,8 +170,7 @@ class PasswordOption(Option):
__slots__ = tuple()
_display_name = _('password')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -210,8 +200,7 @@ class IPOption(Option):
warnings_only=warnings_only,
extra=extra)
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
# sometimes an ip term starts with a zero
# but this does not fit in some case, for example bind does not like it
err = self._impl_valid_unicode(value)
@ -315,8 +304,7 @@ class PortOption(Option):
warnings_only=warnings_only,
extra=extra)
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
if isinstance(value, int):
if sys.version_info[0] >= 3: # pragma: optional cover
value = str(value)
@ -350,8 +338,7 @@ class NetworkOption(Option):
__slots__ = tuple()
_display_name = _('network address')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -380,8 +367,7 @@ class NetmaskOption(Option):
__slots__ = tuple()
_display_name = _('netmask address')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -434,8 +420,7 @@ class BroadcastOption(Option):
__slots__ = tuple()
_display_name = _('broadcast address')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -494,8 +479,7 @@ class DomainnameOption(Option):
warnings_only=warnings_only,
extra=extra)
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -564,8 +548,7 @@ class EmailOption(DomainnameOption):
username_re = re.compile(r"^[\w!#$%&'*+\-/=?^`{|}~.]+$")
_display_name = _('email address')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -590,8 +573,7 @@ class URLOption(DomainnameOption):
path_re = re.compile(r"^[A-Za-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]+$")
_display_name = _('URL')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -638,8 +620,7 @@ class UsernameOption(Option):
username_re = re.compile(r"^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$")
_display_name = _('username')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err
@ -653,8 +634,7 @@ class FilenameOption(Option):
path_re = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
_display_name = _('file name')
def _validate(self, value, context=undefined, current_opt=undefined,
returns_raise=False):
def _validate(self, value, context=undefined, current_opt=undefined):
err = self._impl_valid_unicode(value)
if err:
return err

View File

@ -305,6 +305,8 @@ class OptionDescription(BaseOption, StorageOptionDescription):
values = carry_out_calculation(self, context=context,
callback=callback,
callback_params=callback_params)
if isinstance(values, Exception):
raise values
if len(values) > len(set(values)):
raise ConfigError(_('DynOptionDescription callback return not uniq value'))
for val in values: