remove a try/except

This commit is contained in:
Emmanuel Garette 2015-12-31 18:35:31 +01:00
parent ce162280ad
commit cc6b4ad7c4
2 changed files with 23 additions and 18 deletions

View File

@ -197,27 +197,29 @@ class SubConfig(object):
"attribute notation mechanism for the setting of the value of an option" "attribute notation mechanism for the setting of the value of an option"
self._setattr(name, value) 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_'): if name.startswith('_impl_'):
object.__setattr__(self, name, value) object.__setattr__(self, name, value)
return return
if '.' in name: # pragma: optional cover if '.' in name: # pragma: optional cover
homeconfig, name = self.cfgimpl_get_home_by_path(name) 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() context = self._cfgimpl_get_context()
child = self.cfgimpl_get_description().__getattr__(name, child = self.cfgimpl_get_description().__getattr__(name,
context=context) 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 raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
elif isinstance(child, SymLinkOption) and \ elif isinstance(child, SymLinkOption) and \
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
path = context.cfgimpl_get_description().impl_get_path_by_opt( path = context.cfgimpl_get_description().impl_get_path_by_opt(
child._impl_getopt()) child._impl_getopt())
context._setattr(path, value, force_permissive=force_permissive) context._setattr(path, value, force_permissive, not_raises)
else: else:
subpath = self._get_subpath(name) subpath = self._get_subpath(name)
self.cfgimpl_get_values().setitem(child, value, subpath, self.cfgimpl_get_values().setitem(child, value, subpath,
force_permissive=force_permissive) force_permissive=force_permissive,
not_raises=not_raises)
def __delattr__(self, name): def __delattr__(self, name):
context = self._cfgimpl_get_context() context = self._cfgimpl_get_context()
@ -733,15 +735,12 @@ class GroupConfig(_CommonConfig):
"""Setattr not in current GroupConfig, but in each children """Setattr not in current GroupConfig, but in each children
""" """
for child in self._impl_children: for child in self._impl_children:
try:
if isinstance(child, MetaConfig): if isinstance(child, MetaConfig):
child.set_value(path, value, only_config=True) child.set_value(path, value, only_config=True)
elif isinstance(child, GroupConfig): elif isinstance(child, GroupConfig):
child.set_value(path, value) child.set_value(path, value)
else: else:
setattr(child, path, value) child._setattr(path, value, not_raises=True)
except PropertiesOptionError:
pass
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined, def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
byvalue=undefined, raise_if_not_found=True, _sub=False, byvalue=undefined, raise_if_not_found=True, _sub=False,

View File

@ -364,7 +364,7 @@ class Values(object):
raise ConfigError(_('you should only set value with config')) raise ConfigError(_('you should only set value with config'))
def setitem(self, opt, value, path, force_permissive=False, 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" # check_frozen is, for example, used with "force_store_value"
# user didn't change value, so not write # user didn't change value, so not write
# valid opt # valid opt
@ -373,8 +373,11 @@ class Values(object):
if 'validator' in setting_properties: if 'validator' in setting_properties:
fake_context = context._gen_fake_values() fake_context = context._gen_fake_values()
fake_values = fake_context.cfgimpl_get_values() fake_values = fake_context.cfgimpl_get_values()
fake_values.validate(opt, value, path, check_frozen, props = fake_values.validate(opt, value, path, check_frozen,
force_permissive, setting_properties) force_permissive, setting_properties,
not_raises=not_raises)
if props and not_raises:
return
fake_values._setvalue(opt, path, value) fake_values._setvalue(opt, path, value)
opt.impl_validate(value, fake_context) opt.impl_validate(value, fake_context)
self._setvalue(opt, path, value) self._setvalue(opt, path, value)
@ -399,7 +402,8 @@ class Values(object):
self._p_.setvalue(path, value, owner, None) self._p_.setvalue(path, value, owner, None)
def validate(self, opt, value, path, check_frozen=True, force_permissive=False, 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(): if valid_masterslave and opt.impl_is_master_slaves():
opt.impl_get_master_slaves().validate(self, opt, value, path) opt.impl_get_master_slaves().validate(self, opt, value, path)
props = self._getcontext().cfgimpl_get_settings().validate_properties(opt, props = self._getcontext().cfgimpl_get_settings().validate_properties(opt,
@ -410,6 +414,8 @@ class Values(object):
force_permissive=force_permissive, force_permissive=force_permissive,
setting_properties=setting_properties) setting_properties=setting_properties)
if props: if props:
if not_raises:
return props
raise props raise props
def _is_meta(self, opt, path): def _is_meta(self, opt, path):