remove some try/except

This commit is contained in:
Emmanuel Garette 2015-12-26 10:57:20 +01:00
parent 97d7352a5b
commit 14489c3ef5
4 changed files with 42 additions and 55 deletions

View File

@ -219,13 +219,10 @@ def carry_out_calculation(option, context, callback, callback_params,
else:
kwargs[key] = couple[0]
ret = calculate(callback, args, kwargs)
try:
if callback_params != {} and isinstance(ret, list) and \
if not option.impl_is_optiondescription() and callback_params != {} and isinstance(ret, list) and \
option.impl_is_master_slaves('slave'):
raise SlaveError(_("callback cannot return a list for a "
"slave option ({0})").format(path))
except AttributeError:
pass
return ret

View File

@ -142,7 +142,10 @@ class Base(StorageBase):
allow_empty_list)
if multi is not False and default is None:
default = []
try:
self.impl_validate(default, is_multi=is_multi)
except ContextError:
pass
self._set_default_values(default, default_multi, is_multi)
##callback is False in optiondescription
if callback is not False:
@ -429,8 +432,8 @@ class Option(OnlyOption):
descr = context.cfgimpl_get_description()
all_cons_vals = []
for opt in all_cons_opts:
try:
for opt in all_cons_opts:
#get value
if (isinstance(opt, DynSymLinkOption) and option._dyn == opt._dyn) or \
option == opt:
@ -453,15 +456,8 @@ class Option(OnlyOption):
option == opt:
all_cons_vals.append(opt_value)
elif self.impl_is_submulti():
try:
all_cons_vals.append(opt_value[index][submulti_index])
except IndexError, err:
log.debug('indexerror in submulti opt in _launch_consistency: {0}'.format(err))
#value is not already set, could be higher index
#so return if no value
return
else:
try:
all_cons_vals.append(opt_value[index])
except IndexError, err:
#value is not already set, could be higher index
@ -610,16 +606,14 @@ class Option(OnlyOption):
def impl_is_master_slaves(self, type_='both'):
"""FIXME
"""
try:
self._master_slaves
master_slaves = getattr(self, '_master_slaves', None)
if master_slaves is not None:
if type_ in ('both', 'master') and \
self._master_slaves.is_master(self):
master_slaves.is_master(self):
return True
if type_ in ('both', 'slave') and \
not self._master_slaves.is_master(self):
not master_slaves.is_master(self):
return True
except:
pass
return False
def impl_get_master_slaves(self):
@ -820,14 +814,14 @@ def validate_requires_arg(multi, requires, name):
unknown_keys,
valid_keys))
# prepare all attributes
try:
option = require['option']
expected = require['expected']
action = require['action']
except KeyError: # pragma: optional cover
if 'option' not in require or 'expected' not in require or \
'action' not in require:
raise ValueError(_("malformed requirements for option: {0}"
" require must have option, expected and"
" action keys").format(name))
option = require['option']
expected = require['expected']
action = require['action']
if action == 'force_store_value': # pragma: optional cover
raise ValueError(_("malformed requirements for option: {0}"
" action cannot be force_store_value"
@ -911,10 +905,7 @@ class SymLinkOption(OnlyOption):
def _impl_setstate(self, descr):
self._impl_setopt(descr.impl_get_opt_by_path(self._state_opt))
del(self._state_opt)
try:
del(self._stated)
except AttributeError: # pragma: optional cover
pass
self._set_readonly(True)
def impl_get_information(self, key, default=undefined):

View File

@ -89,15 +89,12 @@ class ChoiceOption(Option):
return values
def _validate(self, value, context=undefined, current_opt=undefined):
try:
values = self.impl_get_values(context, current_opt=current_opt)
if not value in values: # pragma: optional cover
raise ValueError(_('value {0} is not permitted, '
'only {1} is allowed'
'').format(value,
values))
except ContextError: # pragma: optional cover
log.debug('ChoiceOption validation, disabled because no context')
class BoolOption(Option):

View File

@ -19,7 +19,7 @@
# ____________________________________________________________
from ...i18n import _
from ...setting import undefined
from ...error import ConfigError
from ...error import ConfigError, ContextError
static_tuple = tuple()
static_set = frozenset()
@ -102,6 +102,8 @@ class StorageBase(object):
"for option {1}: {2}").format(
str(default_multi),
self.impl_getname(), str(err)))
except ContextError, err:
pass
_setattr(self, '_default_multi', default_multi)
# information