remove some try/except

This commit is contained in:
Emmanuel Garette 2015-12-30 22:32:07 +01:00
parent 729db2ceec
commit d0e2b5d8c4
6 changed files with 63 additions and 61 deletions

View File

@ -276,10 +276,12 @@ class SubConfig(object):
_setting_properties=_setting_properties,
index=index)
elif option.impl_is_optiondescription():
self.cfgimpl_get_settings().validate_properties(
props = self.cfgimpl_get_settings().validate_properties(
option, True, False, path=subpath,
force_permissive=force_permissive,
setting_properties=_setting_properties)
if props:
raise props
return SubConfig(option, self._impl_context, subpath)
else:
return self.cfgimpl_get_values()._get_cached_value(
@ -344,7 +346,6 @@ class SubConfig(object):
return byvalue in value
else:
return value == byvalue
# a property is a restriction upon the access of the value
except PropertiesOptionError: # pragma: optional cover
return False
@ -373,7 +374,6 @@ class SubConfig(object):
force_permissive=force_permissive,
_setting_properties=setting_properties)
except PropertiesOptionError: # pragma: optional cover
# a property restricts the access of the value
continue
if type_ == 'value':
retval = value

View File

@ -885,10 +885,7 @@ class SymLinkOption(OnlyOption):
return self._impl_getopt().impl_is_multi()
def _is_subdyn(self):
try:
return self._impl_getopt()._subdyn is not None
except AttributeError:
return False
return getattr(self._impl_getopt(), '_subdyn', None) is not None
class DynSymLinkOption(object):

View File

@ -143,12 +143,9 @@ class MasterSlaves(object):
if index is None and validate is True:
masterlen = len(value)
for slave in self.getslaves(opt):
try:
slave_path = slave.impl_getpath(values._getcontext())
slavelen = values._p_.get_max_length(slave_path)
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt)
except ConfigError: # pragma: optional cover
pass
slave_path = slave.impl_getpath(values._getcontext())
slavelen = values._p_.get_max_length(slave_path)
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt)
return value
def _getslave(self, values, opt, path, validate, force_permissive,
@ -185,12 +182,14 @@ class MasterSlaves(object):
multi = values._get_multi(opt, path)
if masterlen == 0:
if validate_properties:
context.cfgimpl_get_settings().validate_properties(opt, False,
False,
value=multi,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
props = context.cfgimpl_get_settings().validate_properties(opt, False,
False,
value=multi,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
if props:
raise props
else:
one_has_value = False
if index is None:

View File

@ -488,21 +488,21 @@ class Settings(object):
if properties != frozenset():
props = list(properties)
if 'frozen' in properties:
raise PropertiesOptionError(_('cannot change the value for '
'option {0} this option is'
' frozen').format(
opt_or_descr.impl_getname()),
props)
return PropertiesOptionError(_('cannot change the value for '
'option {0} this option is'
' frozen').format(
opt_or_descr.impl_getname()),
props)
else:
if is_descr:
opt_type = 'optiondescription'
else:
opt_type = 'option'
raise PropertiesOptionError(_("trying to access to an {0} "
"named: {1} with properties {2}"
"").format(opt_type,
opt_or_descr._name,
str(props)), props)
return PropertiesOptionError(_("trying to access to an {0} "
"named: {1} with properties {2}"
"").format(opt_type,
opt_or_descr._name,
str(props)), props)
def setpermissive(self, permissive, opt=None, path=None):
"""

View File

@ -278,7 +278,8 @@ class StorageBase(object):
self._state_informations = infos
self._state_readonly = self.impl_is_readonly()
else:
self._informations = self._state_informations
_setattr = object.__setattr__
_setattr(self, '_informations', self._state_informations)
del(self._state_informations)
if self._state_readonly:
self._set_readonly(True)
@ -296,7 +297,8 @@ class StorageBase(object):
else:
extra = getattr(self, '_state_extra', None)
if extra is not None:
self._extra = extra
_setattr = object.__setattr__
_setattr(self, '_extra', extra)
del(self._state_extra)
def _impl_getattributes(self):

View File

@ -230,12 +230,14 @@ class Values(object):
value = Multi(value, self.context, opt, path)
if not trusted_cached_properties:
# revalidate properties (because of not default properties)
settings.validate_properties(opt, False, False, value=value,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties,
self_properties=self_properties,
index=index)
props = settings.validate_properties(opt, False, False, value=value,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties,
self_properties=self_properties,
index=index)
if props:
raise props
return value
if not from_masterslave and opt.impl_is_master_slaves():
val = opt.impl_get_master_slaves().getitem(self, opt, path,
@ -346,12 +348,14 @@ class Values(object):
val_props = undefined
else:
val_props = value
setting.validate_properties(opt, False, check_frozen, value=val_props,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties,
self_properties=self_properties,
index=index)
props = setting.validate_properties(opt, False, check_frozen, value=val_props,
path=path,
force_permissive=force_permissive,
setting_properties=setting_properties,
self_properties=self_properties,
index=index)
if props:
raise props
if config_error is not None:
raise config_error
return value
@ -396,7 +400,9 @@ class Values(object):
for idx, val in enumerate(value):
if isinstance(val, SubMulti):
value[idx] = list(val)
owner = context.cfgimpl_get_settings().getowner()
setting = context.cfgimpl_get_settings()
owner = setting.getowner()
#FIXME pourquoi là et pas dans masterslaves ??
if opt.impl_is_master_slaves('slave') and index is None:
self._p_.resetvalue(path)
for idx, val in enumerate(value):
@ -404,11 +410,12 @@ class Values(object):
else:
self._p_.setvalue(path, value, owner, index)
if validate_properties:
setting = context.cfgimpl_get_settings()
setting.validate_properties(opt, False, check_frozen,
value=value, path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
props = setting.validate_properties(opt, False, check_frozen,
value=value, path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
if props:
raise props
def _is_meta(self, opt, path):
context = self._getcontext()
@ -487,11 +494,12 @@ class Values(object):
if not self._p_.hasvalue(path): # pragma: optional cover
raise ConfigError(_('no value for {0} cannot change owner to {1}'
'').format(path, owner))
self._getcontext().cfgimpl_get_settings().validate_properties(opt,
False,
True,
path)
props = self._getcontext().cfgimpl_get_settings().validate_properties(opt,
False,
True,
path)
if props:
raise props
self._p_.setowner(path, owner)
def is_default_owner(self, opt, validate_properties=True,
@ -566,13 +574,9 @@ class Values(object):
path = '.'.join(currpath + [name])
if opt.impl_is_optiondescription():
try:
settings.validate_properties(opt, True, False, path=path,
force_permissive=force_permissive,
setting_properties=setting_properties)
except PropertiesOptionError as err:
pass
else:
if not settings.validate_properties(opt, True, False, path=path,
force_permissive=force_permissive,
setting_properties=setting_properties):
for path in _mandatory_warnings(opt, currpath + [name]):
yield path
else: