remove all try/except
This commit is contained in:
parent
e8764f6173
commit
b521c459ee
9 changed files with 236 additions and 180 deletions
|
@ -70,6 +70,10 @@ def test_network():
|
||||||
assert len(w) == 1
|
assert len(w) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_network_invalid():
|
||||||
|
raises(ValueError, "NetworkOption('a', '', default='toto')")
|
||||||
|
|
||||||
|
|
||||||
def test_netmask():
|
def test_netmask():
|
||||||
a = NetmaskOption('a', '')
|
a = NetmaskOption('a', '')
|
||||||
od = OptionDescription('od', '', [a])
|
od = OptionDescription('od', '', [a])
|
||||||
|
|
|
@ -25,7 +25,7 @@ from .setting import undefined
|
||||||
|
|
||||||
|
|
||||||
def carry_out_calculation(option, context, callback, callback_params,
|
def carry_out_calculation(option, context, callback, callback_params,
|
||||||
index=undefined):
|
index=undefined, returns_raise=False):
|
||||||
"""a function that carries out a calculation for an option's value
|
"""a function that carries out a calculation for an option's value
|
||||||
|
|
||||||
:param option: the option
|
:param option: the option
|
||||||
|
@ -160,20 +160,27 @@ def carry_out_calculation(option, context, callback, callback_params,
|
||||||
path = context.cfgimpl_get_description(
|
path = context.cfgimpl_get_description(
|
||||||
).impl_get_path_by_opt(opt)
|
).impl_get_path_by_opt(opt)
|
||||||
# get value
|
# get value
|
||||||
try:
|
|
||||||
value = context.getattr(path, force_permissive=True,
|
value = context.getattr(path, force_permissive=True,
|
||||||
validate=False)
|
validate=False,
|
||||||
|
returns_raise=True)
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
if isinstance(value, PropertiesOptionError):
|
||||||
|
if force_permissive:
|
||||||
|
continue
|
||||||
|
err = ConfigError(_('unable to carry out a calculation'
|
||||||
|
', option {0} has properties: {1} '
|
||||||
|
'for: {2}').format(opt.impl_getname(),
|
||||||
|
value.proptype,
|
||||||
|
option.impl_getname()))
|
||||||
|
if returns_raise:
|
||||||
|
return err
|
||||||
|
else:
|
||||||
|
raise err
|
||||||
|
else:
|
||||||
|
raise err
|
||||||
# convert to list, not modifie this multi
|
# convert to list, not modifie this multi
|
||||||
if value.__class__.__name__ == 'Multi':
|
if value.__class__.__name__ == 'Multi':
|
||||||
value = list(value)
|
value = list(value)
|
||||||
except PropertiesOptionError as err: # pragma: optional cover
|
|
||||||
if force_permissive:
|
|
||||||
continue
|
|
||||||
raise ConfigError(_('unable to carry out a calculation'
|
|
||||||
', option {0} has properties: {1} '
|
|
||||||
'for: {2}').format(opt.impl_getname(),
|
|
||||||
err.proptype,
|
|
||||||
option.impl_getname()))
|
|
||||||
|
|
||||||
if opt.impl_is_master_slaves() and \
|
if opt.impl_is_master_slaves() and \
|
||||||
opt.impl_get_master_slaves().in_same_group(option):
|
opt.impl_get_master_slaves().in_same_group(option):
|
||||||
|
|
|
@ -242,7 +242,8 @@ class SubConfig(object):
|
||||||
return subpath
|
return subpath
|
||||||
|
|
||||||
def getattr(self, name, force_permissive=False, validate=True,
|
def getattr(self, name, force_permissive=False, validate=True,
|
||||||
_setting_properties=undefined, index=None):
|
_setting_properties=undefined, index=None,
|
||||||
|
returns_raise=False):
|
||||||
"""
|
"""
|
||||||
attribute notation mechanism for accessing the value of an option
|
attribute notation mechanism for accessing the value of an option
|
||||||
:param name: attribute name
|
:param name: attribute name
|
||||||
|
@ -257,7 +258,7 @@ class SubConfig(object):
|
||||||
return homeconfig.getattr(name, force_permissive=force_permissive,
|
return homeconfig.getattr(name, force_permissive=force_permissive,
|
||||||
validate=validate,
|
validate=validate,
|
||||||
_setting_properties=_setting_properties,
|
_setting_properties=_setting_properties,
|
||||||
index=index)
|
index=index, returns_raise=returns_raise)
|
||||||
context = self._cfgimpl_get_context()
|
context = self._cfgimpl_get_context()
|
||||||
option = self.cfgimpl_get_description().__getattr__(name,
|
option = self.cfgimpl_get_description().__getattr__(name,
|
||||||
context=context)
|
context=context)
|
||||||
|
@ -267,20 +268,24 @@ class SubConfig(object):
|
||||||
option, path=subpath,
|
option, path=subpath,
|
||||||
validate=validate,
|
validate=validate,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=_setting_properties, index=index)
|
setting_properties=_setting_properties, index=index,
|
||||||
|
returns_raise=returns_raise)
|
||||||
elif isinstance(option, SymLinkOption): # pragma: no dynoptiondescription cover
|
elif isinstance(option, SymLinkOption): # pragma: no dynoptiondescription cover
|
||||||
path = context.cfgimpl_get_description().impl_get_path_by_opt(
|
path = context.cfgimpl_get_description().impl_get_path_by_opt(
|
||||||
option._impl_getopt())
|
option._impl_getopt())
|
||||||
return context.getattr(path, validate=validate,
|
return context.getattr(path, validate=validate,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
_setting_properties=_setting_properties,
|
_setting_properties=_setting_properties,
|
||||||
index=index)
|
index=index, returns_raise=returns_raise)
|
||||||
elif option.impl_is_optiondescription():
|
elif option.impl_is_optiondescription():
|
||||||
props = self.cfgimpl_get_settings().validate_properties(
|
props = self.cfgimpl_get_settings().validate_properties(
|
||||||
option, True, False, path=subpath,
|
option, True, False, path=subpath,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=_setting_properties)
|
setting_properties=_setting_properties)
|
||||||
if props:
|
if props:
|
||||||
|
if returns_raise:
|
||||||
|
return props
|
||||||
|
else:
|
||||||
raise props
|
raise props
|
||||||
return SubConfig(option, self._impl_context, subpath)
|
return SubConfig(option, self._impl_context, subpath)
|
||||||
else:
|
else:
|
||||||
|
@ -289,7 +294,7 @@ class SubConfig(object):
|
||||||
validate=validate,
|
validate=validate,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=_setting_properties,
|
setting_properties=_setting_properties,
|
||||||
index=index)
|
index=index, returns_raise=returns_raise)
|
||||||
|
|
||||||
def find(self, bytype=None, byname=None, byvalue=undefined, type_='option',
|
def find(self, bytype=None, byname=None, byvalue=undefined, type_='option',
|
||||||
check_properties=True, force_permissive=False):
|
check_properties=True, force_permissive=False):
|
||||||
|
@ -339,15 +344,17 @@ class SubConfig(object):
|
||||||
def _filter_by_value():
|
def _filter_by_value():
|
||||||
if byvalue is undefined:
|
if byvalue is undefined:
|
||||||
return True
|
return True
|
||||||
try:
|
|
||||||
value = self.getattr(path, force_permissive=force_permissive,
|
value = self.getattr(path, force_permissive=force_permissive,
|
||||||
_setting_properties=setting_properties)
|
_setting_properties=setting_properties,
|
||||||
if isinstance(value, Multi):
|
returns_raise=True)
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
if isinstance(value, PropertiesOptionError):
|
||||||
|
return False
|
||||||
|
raise value
|
||||||
|
elif isinstance(value, Multi):
|
||||||
return byvalue in value
|
return byvalue in value
|
||||||
else:
|
else:
|
||||||
return value == byvalue
|
return value == byvalue
|
||||||
except PropertiesOptionError: # pragma: optional cover
|
|
||||||
return False
|
|
||||||
|
|
||||||
if type_ not in ('option', 'path', 'value'): # pragma: optional cover
|
if type_ not in ('option', 'path', 'value'): # pragma: optional cover
|
||||||
raise ValueError(_('unknown type_ type {0}'
|
raise ValueError(_('unknown type_ type {0}'
|
||||||
|
@ -369,12 +376,15 @@ class SubConfig(object):
|
||||||
continue
|
continue
|
||||||
#remove option with propertyerror, ...
|
#remove option with propertyerror, ...
|
||||||
if byvalue is undefined and check_properties:
|
if byvalue is undefined and check_properties:
|
||||||
try:
|
|
||||||
value = self.getattr(path,
|
value = self.getattr(path,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
_setting_properties=setting_properties)
|
_setting_properties=setting_properties,
|
||||||
except PropertiesOptionError: # pragma: optional cover
|
returns_raise=True)
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
if isinstance(value, PropertiesOptionError):
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
raise value
|
||||||
if type_ == 'value':
|
if type_ == 'value':
|
||||||
retval = value
|
retval = value
|
||||||
elif type_ == 'path':
|
elif type_ == 'path':
|
||||||
|
@ -482,26 +492,25 @@ class SubConfig(object):
|
||||||
|
|
||||||
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten,
|
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten,
|
||||||
setting_properties, force_permissive=False):
|
setting_properties, force_permissive=False):
|
||||||
try:
|
value = self.getattr(path,
|
||||||
if opt.impl_is_optiondescription():
|
|
||||||
pathsvalues += self.getattr(path,
|
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
_setting_properties=setting_properties).make_dict(
|
_setting_properties=setting_properties,
|
||||||
flatten,
|
returns_raise=True)
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
if not isinstance(value, PropertiesOptionError):
|
||||||
|
raise value
|
||||||
|
else:
|
||||||
|
if opt.impl_is_optiondescription():
|
||||||
|
pathsvalues += value.make_dict(flatten,
|
||||||
_currpath + path.split('.'),
|
_currpath + path.split('.'),
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=setting_properties)
|
setting_properties=setting_properties)
|
||||||
else:
|
else:
|
||||||
value = self.getattr(opt.impl_getname(),
|
|
||||||
force_permissive=force_permissive,
|
|
||||||
_setting_properties=setting_properties)
|
|
||||||
if flatten:
|
if flatten:
|
||||||
name = opt.impl_getname()
|
name = opt.impl_getname()
|
||||||
else:
|
else:
|
||||||
name = '.'.join(_currpath + [opt.impl_getname()])
|
name = '.'.join(_currpath + [opt.impl_getname()])
|
||||||
pathsvalues.append((name, value))
|
pathsvalues.append((name, value))
|
||||||
except PropertiesOptionError: # pragma: optional cover
|
|
||||||
pass
|
|
||||||
|
|
||||||
def cfgimpl_get_path(self, dyn=True):
|
def cfgimpl_get_path(self, dyn=True):
|
||||||
descr = self.cfgimpl_get_description()
|
descr = self.cfgimpl_get_description()
|
||||||
|
@ -790,13 +799,15 @@ class GroupConfig(_CommonConfig):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def getattr(self, name, force_permissive=False, validate=True,
|
def getattr(self, name, force_permissive=False, validate=True,
|
||||||
_setting_properties=undefined):
|
_setting_properties=undefined,
|
||||||
|
returns_raise=False):
|
||||||
for child in self._impl_children:
|
for child in self._impl_children:
|
||||||
if name == child._impl_name:
|
if name == child._impl_name:
|
||||||
return child
|
return child
|
||||||
return super(GroupConfig, self).getattr(name, force_permissive,
|
return super(GroupConfig, self).getattr(name, force_permissive,
|
||||||
validate,
|
validate,
|
||||||
_setting_properties=_setting_properties)
|
_setting_properties=_setting_properties,
|
||||||
|
returns_raise=returns_raise)
|
||||||
|
|
||||||
|
|
||||||
class MetaConfig(GroupConfig):
|
class MetaConfig(GroupConfig):
|
||||||
|
|
|
@ -387,7 +387,6 @@ class Option(OnlyOption):
|
||||||
descr = context.cfgimpl_get_description()
|
descr = context.cfgimpl_get_description()
|
||||||
|
|
||||||
all_cons_vals = []
|
all_cons_vals = []
|
||||||
try:
|
|
||||||
for opt in all_cons_opts:
|
for opt in all_cons_opts:
|
||||||
#get value
|
#get value
|
||||||
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
|
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
|
||||||
|
@ -401,7 +400,17 @@ class Option(OnlyOption):
|
||||||
else:
|
else:
|
||||||
path = descr.impl_get_path_by_opt(opt)
|
path = descr.impl_get_path_by_opt(opt)
|
||||||
opt_value = context.getattr(path, validate=False,
|
opt_value = context.getattr(path, validate=False,
|
||||||
force_permissive=True)
|
force_permissive=True,
|
||||||
|
returns_raise=True)
|
||||||
|
if isinstance(opt_value, Exception):
|
||||||
|
if isinstance(opt_value, PropertiesOptionError):
|
||||||
|
log.debug('propertyerror in _launch_consistency: {0}'.format(opt_value))
|
||||||
|
if transitive:
|
||||||
|
raise opt_value
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise opt_value
|
||||||
else:
|
else:
|
||||||
opt_value = opt.impl_getdefault()
|
opt_value = opt.impl_getdefault()
|
||||||
|
|
||||||
|
@ -410,17 +419,11 @@ class Option(OnlyOption):
|
||||||
and option._dyn == opt._dyn) or \
|
and option._dyn == opt._dyn) or \
|
||||||
option == opt:
|
option == opt:
|
||||||
all_cons_vals.append(opt_value)
|
all_cons_vals.append(opt_value)
|
||||||
elif self.impl_is_submulti():
|
#consistency with submulti is now forbidden
|
||||||
print option._name, opt_value
|
#elif self.impl_is_submulti():
|
||||||
all_cons_vals.append(opt_value[index][submulti_index])
|
# all_cons_vals.append(opt_value[index][submulti_index])
|
||||||
else:
|
else:
|
||||||
all_cons_vals.append(opt_value[index])
|
all_cons_vals.append(opt_value[index])
|
||||||
except PropertiesOptionError as err:
|
|
||||||
log.debug('propertyerror in _launch_consistency: {0}'.format(err))
|
|
||||||
if transitive:
|
|
||||||
raise err
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
return getattr(self, func)(all_cons_opts, all_cons_vals, warnings_only)
|
return getattr(self, func)(all_cons_opts, all_cons_vals, warnings_only)
|
||||||
|
|
||||||
def impl_validate(self, value, context=undefined, validate=True,
|
def impl_validate(self, value, context=undefined, validate=True,
|
||||||
|
|
|
@ -120,7 +120,8 @@ class MasterSlaves(object):
|
||||||
def getitem(self, values, opt, path, validate, force_permissive,
|
def getitem(self, values, opt, path, validate, force_permissive,
|
||||||
trusted_cached_properties, validate_properties, slave_path=undefined,
|
trusted_cached_properties, validate_properties, slave_path=undefined,
|
||||||
slave_value=undefined, setting_properties=undefined,
|
slave_value=undefined, setting_properties=undefined,
|
||||||
self_properties=undefined, index=None):
|
self_properties=undefined, index=None,
|
||||||
|
returns_raise=False):
|
||||||
if self.is_master(opt):
|
if self.is_master(opt):
|
||||||
return self._getmaster(values, opt, path, validate,
|
return self._getmaster(values, opt, path, validate,
|
||||||
force_permissive,
|
force_permissive,
|
||||||
|
@ -130,7 +131,7 @@ class MasterSlaves(object):
|
||||||
return self._getslave(values, opt, path, validate,
|
return self._getslave(values, opt, path, validate,
|
||||||
force_permissive, trusted_cached_properties,
|
force_permissive, trusted_cached_properties,
|
||||||
validate_properties, setting_properties,
|
validate_properties, setting_properties,
|
||||||
self_properties, index)
|
self_properties, index, returns_raise)
|
||||||
|
|
||||||
def _getmaster(self, values, opt, path, validate, force_permissive,
|
def _getmaster(self, values, opt, path, validate, force_permissive,
|
||||||
validate_properties, c_slave_path,
|
validate_properties, c_slave_path,
|
||||||
|
@ -150,7 +151,7 @@ class MasterSlaves(object):
|
||||||
|
|
||||||
def _getslave(self, values, opt, path, validate, force_permissive,
|
def _getslave(self, values, opt, path, validate, force_permissive,
|
||||||
trusted_cached_properties, validate_properties, setting_properties,
|
trusted_cached_properties, validate_properties, setting_properties,
|
||||||
self_properties, index):
|
self_properties, index, returns_raise):
|
||||||
"""
|
"""
|
||||||
if master has length 0:
|
if master has length 0:
|
||||||
return []
|
return []
|
||||||
|
@ -190,6 +191,9 @@ class MasterSlaves(object):
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=setting_properties)
|
setting_properties=setting_properties)
|
||||||
if props:
|
if props:
|
||||||
|
if returns_raise:
|
||||||
|
return props
|
||||||
|
else:
|
||||||
raise props
|
raise props
|
||||||
else:
|
else:
|
||||||
one_has_value = False
|
one_has_value = False
|
||||||
|
@ -198,7 +202,6 @@ class MasterSlaves(object):
|
||||||
else:
|
else:
|
||||||
indexes = [index]
|
indexes = [index]
|
||||||
for idx in indexes:
|
for idx in indexes:
|
||||||
try:
|
|
||||||
value = values._get_cached_value(opt, path, validate,
|
value = values._get_cached_value(opt, path, validate,
|
||||||
force_permissive,
|
force_permissive,
|
||||||
trusted_cached_properties,
|
trusted_cached_properties,
|
||||||
|
@ -209,11 +212,16 @@ class MasterSlaves(object):
|
||||||
# depends to index
|
# depends to index
|
||||||
#self_properties=self_properties,
|
#self_properties=self_properties,
|
||||||
masterlen=masterlen,
|
masterlen=masterlen,
|
||||||
from_masterslave=True)
|
from_masterslave=True,
|
||||||
|
returns_raise=True)
|
||||||
|
if isinstance(value, PropertiesOptionError):
|
||||||
|
err = value
|
||||||
|
multi.append_properties_error(value)
|
||||||
|
elif isinstance(value, Exception):
|
||||||
|
raise value
|
||||||
|
else:
|
||||||
multi.append(value, setitem=False, force=True, validate=validate)
|
multi.append(value, setitem=False, force=True, validate=validate)
|
||||||
one_has_value = True
|
one_has_value = True
|
||||||
except PropertiesOptionError, err:
|
|
||||||
multi.append_properties_error(err)
|
|
||||||
if not one_has_value:
|
if not one_has_value:
|
||||||
#raise last err
|
#raise last err
|
||||||
raise err
|
raise err
|
||||||
|
|
|
@ -232,6 +232,7 @@ class PortOption(Option):
|
||||||
see: http://en.wikipedia.org/wiki/Port_numbers
|
see: http://en.wikipedia.org/wiki/Port_numbers
|
||||||
"""
|
"""
|
||||||
__slots__ = tuple()
|
__slots__ = tuple()
|
||||||
|
port_re = re.compile(r"^[0-9]*$")
|
||||||
|
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
requires=None, multi=False, callback=None,
|
requires=None, multi=False, callback=None,
|
||||||
|
@ -262,6 +263,7 @@ class PortOption(Option):
|
||||||
if extra['_max_value'] is None:
|
if extra['_max_value'] is None:
|
||||||
raise ValueError(_('max value is empty')) # pragma: optional cover
|
raise ValueError(_('max value is empty')) # pragma: optional cover
|
||||||
|
|
||||||
|
|
||||||
super(PortOption, self).__init__(name, doc, default=default,
|
super(PortOption, self).__init__(name, doc, default=default,
|
||||||
default_multi=default_multi,
|
default_multi=default_multi,
|
||||||
callback=callback,
|
callback=callback,
|
||||||
|
@ -292,10 +294,9 @@ class PortOption(Option):
|
||||||
value = [value]
|
value = [value]
|
||||||
|
|
||||||
for val in value:
|
for val in value:
|
||||||
try:
|
if not self.port_re.search(val):
|
||||||
val = int(val)
|
|
||||||
except ValueError: # pragma: optional cover
|
|
||||||
return ValueError(_('invalid port'))
|
return ValueError(_('invalid port'))
|
||||||
|
val = int(val)
|
||||||
if not self._get_extra('_min_value') <= val <= self._get_extra('_max_value'): # pragma: optional cover
|
if not self._get_extra('_min_value') <= val <= self._get_extra('_max_value'): # pragma: optional cover
|
||||||
return ValueError(_('invalid port, must be an integer between {0} '
|
return ValueError(_('invalid port, must be an integer between {0} '
|
||||||
'and {1}').format(self._get_extra('_min_value'),
|
'and {1}').format(self._get_extra('_min_value'),
|
||||||
|
|
|
@ -622,18 +622,18 @@ class Settings(object):
|
||||||
"imbrication detected for option:"
|
"imbrication detected for option:"
|
||||||
" '{0}' with requirement on: "
|
" '{0}' with requirement on: "
|
||||||
"'{1}'").format(path, reqpath))
|
"'{1}'").format(path, reqpath))
|
||||||
try:
|
|
||||||
if option.impl_is_multi():
|
if option.impl_is_multi():
|
||||||
idx = index
|
idx = index
|
||||||
else:
|
else:
|
||||||
idx = None
|
idx = None
|
||||||
value = context.getattr(reqpath, force_permissive=True,
|
value = context.getattr(reqpath, force_permissive=True,
|
||||||
_setting_properties=setting_properties,
|
_setting_properties=setting_properties,
|
||||||
index=idx)
|
index=idx, returns_raise=True)
|
||||||
except PropertiesOptionError as err:
|
if isinstance(value, Exception):
|
||||||
|
if isinstance(value, PropertiesOptionError):
|
||||||
if not transitive:
|
if not transitive:
|
||||||
continue
|
continue
|
||||||
properties = err.proptype
|
properties = value.proptype
|
||||||
if same_action and action not in properties: # pragma: optional cover
|
if same_action and action not in properties: # pragma: optional cover
|
||||||
raise RequirementError(_("option '{0}' has "
|
raise RequirementError(_("option '{0}' has "
|
||||||
"requirement's property "
|
"requirement's property "
|
||||||
|
@ -644,6 +644,8 @@ class Settings(object):
|
||||||
# transitive action, force expected
|
# transitive action, force expected
|
||||||
value = expected[0]
|
value = expected[0]
|
||||||
inverse = False
|
inverse = False
|
||||||
|
else:
|
||||||
|
raise value
|
||||||
if (not inverse and
|
if (not inverse and
|
||||||
value in expected or
|
value in expected or
|
||||||
inverse and value not in expected):
|
inverse and value not in expected):
|
||||||
|
|
|
@ -44,10 +44,8 @@ class Settings(Cache):
|
||||||
self._properties.clear()
|
self._properties.clear()
|
||||||
|
|
||||||
def delproperties(self, path):
|
def delproperties(self, path):
|
||||||
try:
|
if path in self._properties:
|
||||||
del(self._properties[path])
|
del(self._properties[path])
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def setpermissive(self, path, permissive):
|
def setpermissive(self, path, permissive):
|
||||||
self._permissives[path] = frozenset(permissive)
|
self._permissives[path] = frozenset(permissive)
|
||||||
|
|
|
@ -57,14 +57,16 @@ class Values(object):
|
||||||
def _get_multi(self, opt, path):
|
def _get_multi(self, opt, path):
|
||||||
return Multi([], self.context, opt, path)
|
return Multi([], self.context, opt, path)
|
||||||
|
|
||||||
def _getdefaultvalue(self, opt, path, with_meta, index, submulti_index):
|
def _getdefaultvalue(self, opt, path, with_meta, index, submulti_index,
|
||||||
|
returns_raise):
|
||||||
# if value has callback and is not set
|
# if value has callback and is not set
|
||||||
if opt.impl_has_callback():
|
if opt.impl_has_callback():
|
||||||
callback, callback_params = opt.impl_get_callback()
|
callback, callback_params = opt.impl_get_callback()
|
||||||
value = carry_out_calculation(opt, context=self._getcontext(),
|
value = carry_out_calculation(opt, context=self._getcontext(),
|
||||||
callback=callback,
|
callback=callback,
|
||||||
callback_params=callback_params,
|
callback_params=callback_params,
|
||||||
index=index)
|
index=index,
|
||||||
|
returns_raise=returns_raise)
|
||||||
if isinstance(value, list) and index is not None:
|
if isinstance(value, list) and index is not None:
|
||||||
#if return a list and index is set, return value only if
|
#if return a list and index is set, return value only if
|
||||||
#it's a submulti without submulti_index and without list of list
|
#it's a submulti without submulti_index and without list of list
|
||||||
|
@ -76,18 +78,19 @@ class Values(object):
|
||||||
if with_meta:
|
if with_meta:
|
||||||
meta = self._getcontext().cfgimpl_get_meta()
|
meta = self._getcontext().cfgimpl_get_meta()
|
||||||
if meta is not None:
|
if meta is not None:
|
||||||
try:
|
|
||||||
value = meta.cfgimpl_get_values(
|
value = meta.cfgimpl_get_values(
|
||||||
)._get_cached_value(opt, path, index=index, submulti_index=submulti_index,
|
)._get_cached_value(opt, path, index=index, submulti_index=submulti_index,
|
||||||
from_masterslave=True)
|
from_masterslave=True, returns_raise=True)
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
if not isinstance(value, PropertiesOptionError):
|
||||||
|
raise value
|
||||||
|
else:
|
||||||
if isinstance(value, Multi):
|
if isinstance(value, Multi):
|
||||||
if index is not None:
|
if index is not None:
|
||||||
value = value[index]
|
value = value[index]
|
||||||
else:
|
else:
|
||||||
value = list(value)
|
value = list(value)
|
||||||
return value
|
return value
|
||||||
except PropertiesOptionError:
|
|
||||||
pass
|
|
||||||
# now try to get default value
|
# now try to get default value
|
||||||
value = opt.impl_getdefault()
|
value = opt.impl_getdefault()
|
||||||
if opt.impl_is_multi() and index is not None:
|
if opt.impl_is_multi() and index is not None:
|
||||||
|
@ -102,7 +105,7 @@ class Values(object):
|
||||||
|
|
||||||
def _getvalue(self, opt, path, is_default, self_properties,
|
def _getvalue(self, opt, path, is_default, self_properties,
|
||||||
index=undefined, submulti_index=undefined, with_meta=True,
|
index=undefined, submulti_index=undefined, with_meta=True,
|
||||||
masterlen=undefined):
|
masterlen=undefined, returns_raise=False):
|
||||||
"""actually retrieves the value
|
"""actually retrieves the value
|
||||||
|
|
||||||
:param opt: the `option.Option()` object
|
:param opt: the `option.Option()` object
|
||||||
|
@ -123,7 +126,7 @@ class Values(object):
|
||||||
#so return default value
|
#so return default value
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
return self._getdefaultvalue(opt, path, with_meta, index, submulti_index)
|
return self._getdefaultvalue(opt, path, with_meta, index, submulti_index, returns_raise)
|
||||||
|
|
||||||
def get_modified_values(self):
|
def get_modified_values(self):
|
||||||
context = self._getcontext()
|
context = self._getcontext()
|
||||||
|
@ -209,7 +212,8 @@ class Values(object):
|
||||||
validate_properties=True,
|
validate_properties=True,
|
||||||
setting_properties=undefined, self_properties=undefined,
|
setting_properties=undefined, self_properties=undefined,
|
||||||
index=None, submulti_index=undefined, from_masterslave=False,
|
index=None, submulti_index=undefined, from_masterslave=False,
|
||||||
with_meta=True, masterlen=undefined, check_frozen=False):
|
with_meta=True, masterlen=undefined, check_frozen=False,
|
||||||
|
returns_raise=False):
|
||||||
context = self._getcontext()
|
context = self._getcontext()
|
||||||
settings = context.cfgimpl_get_settings()
|
settings = context.cfgimpl_get_settings()
|
||||||
if path is None:
|
if path is None:
|
||||||
|
@ -238,6 +242,9 @@ class Values(object):
|
||||||
self_properties=self_properties,
|
self_properties=self_properties,
|
||||||
index=index)
|
index=index)
|
||||||
if props:
|
if props:
|
||||||
|
if returns_raise:
|
||||||
|
return props
|
||||||
|
else:
|
||||||
raise props
|
raise props
|
||||||
return value
|
return value
|
||||||
if not from_masterslave and opt.impl_is_master_slaves():
|
if not from_masterslave and opt.impl_is_master_slaves():
|
||||||
|
@ -248,7 +255,10 @@ class Values(object):
|
||||||
validate_properties,
|
validate_properties,
|
||||||
setting_properties=setting_properties,
|
setting_properties=setting_properties,
|
||||||
index=index,
|
index=index,
|
||||||
self_properties=self_properties)
|
self_properties=self_properties,
|
||||||
|
returns_raise=returns_raise)
|
||||||
|
if isinstance(val, PropertiesOptionError):
|
||||||
|
return val
|
||||||
else:
|
else:
|
||||||
val = self._get_validated_value(opt, path, validate,
|
val = self._get_validated_value(opt, path, validate,
|
||||||
force_permissive,
|
force_permissive,
|
||||||
|
@ -259,7 +269,10 @@ class Values(object):
|
||||||
masterlen=masterlen,
|
masterlen=masterlen,
|
||||||
index=index,
|
index=index,
|
||||||
submulti_index=submulti_index,
|
submulti_index=submulti_index,
|
||||||
check_frozen=check_frozen)
|
check_frozen=check_frozen,
|
||||||
|
returns_raise=returns_raise)
|
||||||
|
if isinstance(val, PropertiesOptionError):
|
||||||
|
return val
|
||||||
# cache doesn't work with SubMulti yet
|
# cache doesn't work with SubMulti yet
|
||||||
if not isinstance(val, SubMulti) and 'cache' in setting_properties and \
|
if not isinstance(val, SubMulti) and 'cache' in setting_properties and \
|
||||||
validate and validate_properties and force_permissive is False \
|
validate and validate_properties and force_permissive is False \
|
||||||
|
@ -276,7 +289,7 @@ class Values(object):
|
||||||
index=None, submulti_index=undefined,
|
index=None, submulti_index=undefined,
|
||||||
with_meta=True, setting_properties=undefined,
|
with_meta=True, setting_properties=undefined,
|
||||||
self_properties=undefined, masterlen=undefined,
|
self_properties=undefined, masterlen=undefined,
|
||||||
check_frozen=False):
|
check_frozen=False, returns_raise=False):
|
||||||
"""same has getitem but don't touch the cache
|
"""same has getitem but don't touch the cache
|
||||||
index is None for slave value, if value returned is not a list, just return []
|
index is None for slave value, if value returned is not a list, just return []
|
||||||
"""
|
"""
|
||||||
|
@ -291,13 +304,14 @@ class Values(object):
|
||||||
validate_meta=False,
|
validate_meta=False,
|
||||||
self_properties=self_properties,
|
self_properties=self_properties,
|
||||||
index=index)
|
index=index)
|
||||||
try:
|
config_error = None
|
||||||
value = self._getvalue(opt, path, is_default, self_properties,
|
value = self._getvalue(opt, path, is_default, self_properties,
|
||||||
index=index, submulti_index=submulti_index,
|
index=index, submulti_index=submulti_index,
|
||||||
with_meta=with_meta,
|
with_meta=with_meta,
|
||||||
masterlen=masterlen)
|
masterlen=masterlen,
|
||||||
config_error = None
|
returns_raise=True)
|
||||||
except ConfigError as err:
|
if isinstance(value, Exception):
|
||||||
|
if isinstance(value, ConfigError):
|
||||||
# For calculating properties, we need value (ie for mandatory
|
# For calculating properties, we need value (ie for mandatory
|
||||||
# value).
|
# value).
|
||||||
# If value is calculating with a PropertiesOptionError's option
|
# If value is calculating with a PropertiesOptionError's option
|
||||||
|
@ -305,11 +319,12 @@ class Values(object):
|
||||||
# We can not raise ConfigError if this option should raise
|
# We can not raise ConfigError if this option should raise
|
||||||
# PropertiesOptionError too. So we get config_error and raise
|
# PropertiesOptionError too. So we get config_error and raise
|
||||||
# ConfigError if properties did not raise.
|
# ConfigError if properties did not raise.
|
||||||
# cannot assign config_err directly in python 3.3
|
config_error = value
|
||||||
config_error = err
|
|
||||||
# value is not set, for 'undefined' (cannot set None because of
|
# value is not set, for 'undefined' (cannot set None because of
|
||||||
# mandatory property)
|
# mandatory property)
|
||||||
value = undefined
|
value = undefined
|
||||||
|
else:
|
||||||
|
raise value
|
||||||
else:
|
else:
|
||||||
if index is undefined:
|
if index is undefined:
|
||||||
force_index = None
|
force_index = None
|
||||||
|
@ -356,8 +371,14 @@ class Values(object):
|
||||||
self_properties=self_properties,
|
self_properties=self_properties,
|
||||||
index=index)
|
index=index)
|
||||||
if props:
|
if props:
|
||||||
|
if returns_raise:
|
||||||
|
return props
|
||||||
|
else:
|
||||||
raise props
|
raise props
|
||||||
if config_error is not None:
|
if config_error is not None:
|
||||||
|
if returns_raise:
|
||||||
|
return config_error
|
||||||
|
else:
|
||||||
raise config_error
|
raise config_error
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -591,27 +612,29 @@ class Values(object):
|
||||||
else:
|
else:
|
||||||
true_opt = opt
|
true_opt = opt
|
||||||
true_path = path
|
true_path = path
|
||||||
#FIXME attention c'est réutilisé donc jamais complet ??
|
|
||||||
self_properties = settings._getproperties(true_opt, true_path,
|
self_properties = settings._getproperties(true_opt, true_path,
|
||||||
read_write=False,
|
read_write=False,
|
||||||
setting_properties=setting_properties)
|
setting_properties=setting_properties)
|
||||||
if 'mandatory' in self_properties:
|
if 'mandatory' in self_properties:
|
||||||
try:
|
err = self._get_cached_value(true_opt, path=true_path,
|
||||||
self._get_cached_value(true_opt, path=true_path,
|
|
||||||
trusted_cached_properties=False,
|
trusted_cached_properties=False,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
setting_properties=setting_properties,
|
setting_properties=setting_properties,
|
||||||
self_properties=self_properties,
|
self_properties=self_properties,
|
||||||
validate=validate)
|
validate=validate, returns_raise=True)
|
||||||
except PropertiesOptionError as err:
|
if not isinstance(err, Exception):
|
||||||
|
pass
|
||||||
|
elif isinstance(err, PropertiesOptionError):
|
||||||
if err.proptype == ['mandatory']:
|
if err.proptype == ['mandatory']:
|
||||||
yield path
|
yield path
|
||||||
except ConfigError as err:
|
elif isinstance(err, ConfigError):
|
||||||
if validate:
|
if validate:
|
||||||
raise err
|
raise err
|
||||||
else:
|
else:
|
||||||
#assume that uncalculated value is an empty value
|
#assume that uncalculated value is an empty value
|
||||||
yield path
|
yield path
|
||||||
|
else:
|
||||||
|
raise err
|
||||||
|
|
||||||
descr = self._getcontext().cfgimpl_get_description()
|
descr = self._getcontext().cfgimpl_get_description()
|
||||||
for path in _mandatory_warnings(descr):
|
for path in _mandatory_warnings(descr):
|
||||||
|
@ -628,10 +651,9 @@ class Values(object):
|
||||||
context.cfgimpl_reset_cache()
|
context.cfgimpl_reset_cache()
|
||||||
for path in context.cfgimpl_get_description().impl_getpaths(
|
for path in context.cfgimpl_get_description().impl_getpaths(
|
||||||
include_groups=True):
|
include_groups=True):
|
||||||
try:
|
err = context.getattr(path, returns_raise=True)
|
||||||
context.getattr(path)
|
if isinstance(err, Exception) and not isinstance(err, PropertiesOptionError):
|
||||||
except PropertiesOptionError:
|
raise err
|
||||||
pass
|
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
return {'_p_': self._p_}
|
return {'_p_': self._p_}
|
||||||
|
|
Loading…
Reference in a new issue