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

View File

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

View File

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

View File

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

View File

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

View File

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