callback could raises (not only returns)
This commit is contained in:
parent
cb89c74201
commit
952c880d10
|
@ -211,7 +211,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
||||||
args.append(val)
|
args.append(val)
|
||||||
else:
|
else:
|
||||||
kwargs[key] = val
|
kwargs[key] = val
|
||||||
return calculate(callback, args, kwargs)
|
return calculate(callback, args, kwargs, returns_raise)
|
||||||
else:
|
else:
|
||||||
# no value is multi
|
# no value is multi
|
||||||
# return a single value
|
# return a single value
|
||||||
|
@ -224,7 +224,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
||||||
args.append(couple[0])
|
args.append(couple[0])
|
||||||
else:
|
else:
|
||||||
kwargs[key] = couple[0]
|
kwargs[key] = couple[0]
|
||||||
ret = calculate(callback, args, kwargs)
|
ret = calculate(callback, args, kwargs, returns_raise)
|
||||||
if not option.impl_is_optiondescription() and 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'):
|
option.impl_is_master_slaves('slave'):
|
||||||
raise SlaveError(_("callback cannot return a list for a "
|
raise SlaveError(_("callback cannot return a list for a "
|
||||||
|
@ -232,7 +232,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def calculate(callback, args, kwargs):
|
def calculate(callback, args, kwargs, returns_raise):
|
||||||
"""wrapper that launches the 'callback'
|
"""wrapper that launches the 'callback'
|
||||||
|
|
||||||
:param callback: callback function
|
:param callback: callback function
|
||||||
|
@ -240,4 +240,10 @@ def calculate(callback, args, kwargs):
|
||||||
:param kwargs: in the callback's arity, the named parameters
|
:param kwargs: in the callback's arity, the named parameters
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if returns_raise:
|
||||||
|
try:
|
||||||
|
return callback(*args, **kwargs)
|
||||||
|
except ValueError, err:
|
||||||
|
return err
|
||||||
|
else:
|
||||||
return callback(*args, **kwargs)
|
return callback(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue