remove a try/except
This commit is contained in:
parent
ce162280ad
commit
cc6b4ad7c4
2 changed files with 23 additions and 18 deletions
|
@ -197,27 +197,29 @@ class SubConfig(object):
|
|||
"attribute notation mechanism for the setting of the value of an option"
|
||||
self._setattr(name, value)
|
||||
|
||||
def _setattr(self, name, value, force_permissive=False):
|
||||
def _setattr(self, name, value, force_permissive=False, not_raises=False):
|
||||
if name.startswith('_impl_'):
|
||||
object.__setattr__(self, name, value)
|
||||
return
|
||||
if '.' in name: # pragma: optional cover
|
||||
homeconfig, name = self.cfgimpl_get_home_by_path(name)
|
||||
return homeconfig._setattr(name, value, force_permissive)
|
||||
return homeconfig._setattr(name, value, force_permissive,
|
||||
not_raises)
|
||||
context = self._cfgimpl_get_context()
|
||||
child = self.cfgimpl_get_description().__getattr__(name,
|
||||
context=context)
|
||||
if isinstance(child, OptionDescription):
|
||||
if isinstance(child, OptionDescription) or isinstance(child, SynDynOptionDescription):
|
||||
raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
|
||||
elif isinstance(child, SymLinkOption) and \
|
||||
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
|
||||
path = context.cfgimpl_get_description().impl_get_path_by_opt(
|
||||
child._impl_getopt())
|
||||
context._setattr(path, value, force_permissive=force_permissive)
|
||||
context._setattr(path, value, force_permissive, not_raises)
|
||||
else:
|
||||
subpath = self._get_subpath(name)
|
||||
self.cfgimpl_get_values().setitem(child, value, subpath,
|
||||
force_permissive=force_permissive)
|
||||
force_permissive=force_permissive,
|
||||
not_raises=not_raises)
|
||||
|
||||
def __delattr__(self, name):
|
||||
context = self._cfgimpl_get_context()
|
||||
|
@ -733,15 +735,12 @@ class GroupConfig(_CommonConfig):
|
|||
"""Setattr not in current GroupConfig, but in each children
|
||||
"""
|
||||
for child in self._impl_children:
|
||||
try:
|
||||
if isinstance(child, MetaConfig):
|
||||
child.set_value(path, value, only_config=True)
|
||||
elif isinstance(child, GroupConfig):
|
||||
child.set_value(path, value)
|
||||
else:
|
||||
setattr(child, path, value)
|
||||
except PropertiesOptionError:
|
||||
pass
|
||||
if isinstance(child, MetaConfig):
|
||||
child.set_value(path, value, only_config=True)
|
||||
elif isinstance(child, GroupConfig):
|
||||
child.set_value(path, value)
|
||||
else:
|
||||
child._setattr(path, value, not_raises=True)
|
||||
|
||||
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
|
||||
byvalue=undefined, raise_if_not_found=True, _sub=False,
|
||||
|
|
|
@ -364,7 +364,7 @@ class Values(object):
|
|||
raise ConfigError(_('you should only set value with config'))
|
||||
|
||||
def setitem(self, opt, value, path, force_permissive=False,
|
||||
check_frozen=True):
|
||||
check_frozen=True, not_raises=False):
|
||||
# check_frozen is, for example, used with "force_store_value"
|
||||
# user didn't change value, so not write
|
||||
# valid opt
|
||||
|
@ -373,8 +373,11 @@ class Values(object):
|
|||
if 'validator' in setting_properties:
|
||||
fake_context = context._gen_fake_values()
|
||||
fake_values = fake_context.cfgimpl_get_values()
|
||||
fake_values.validate(opt, value, path, check_frozen,
|
||||
force_permissive, setting_properties)
|
||||
props = fake_values.validate(opt, value, path, check_frozen,
|
||||
force_permissive, setting_properties,
|
||||
not_raises=not_raises)
|
||||
if props and not_raises:
|
||||
return
|
||||
fake_values._setvalue(opt, path, value)
|
||||
opt.impl_validate(value, fake_context)
|
||||
self._setvalue(opt, path, value)
|
||||
|
@ -399,7 +402,8 @@ class Values(object):
|
|||
self._p_.setvalue(path, value, owner, None)
|
||||
|
||||
def validate(self, opt, value, path, check_frozen=True, force_permissive=False,
|
||||
setting_properties=undefined, valid_masterslave=True):
|
||||
setting_properties=undefined, valid_masterslave=True,
|
||||
not_raises=False):
|
||||
if valid_masterslave and opt.impl_is_master_slaves():
|
||||
opt.impl_get_master_slaves().validate(self, opt, value, path)
|
||||
props = self._getcontext().cfgimpl_get_settings().validate_properties(opt,
|
||||
|
@ -410,6 +414,8 @@ class Values(object):
|
|||
force_permissive=force_permissive,
|
||||
setting_properties=setting_properties)
|
||||
if props:
|
||||
if not_raises:
|
||||
return props
|
||||
raise props
|
||||
|
||||
def _is_meta(self, opt, path):
|
||||
|
|
Loading…
Reference in a new issue