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: else:
kwargs[key] = couple[0] kwargs[key] = couple[0]
ret = calculate(callback, args, kwargs) ret = calculate(callback, args, kwargs)
try: if not option.impl_is_optiondescription() and callback_params != {} and isinstance(ret, list) and \
if callback_params != {} and isinstance(ret, list) and \
option.impl_is_master_slaves('slave'): option.impl_is_master_slaves('slave'):
raise SlaveError(_("callback cannot return a list for a " raise SlaveError(_("callback cannot return a list for a "
"slave option ({0})").format(path)) "slave option ({0})").format(path))
except AttributeError:
pass
return ret return ret

View File

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

View File

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

View File

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