feat: return propertyerror in function
This commit is contained in:
parent
54ac0c980a
commit
b5d477a439
3 changed files with 19 additions and 2 deletions
|
@ -16,7 +16,7 @@
|
||||||
"""
|
"""
|
||||||
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
||||||
valid_network_netmask, valid_in_network, valid_broadcast, \
|
valid_network_netmask, valid_in_network, valid_broadcast, \
|
||||||
valid_not_equal, function_waiting_for_dict
|
valid_not_equal, function_waiting_for_dict, function_waiting_for_error
|
||||||
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
|
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
|
||||||
ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
|
ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
|
||||||
from .option import *
|
from .option import *
|
||||||
|
@ -51,6 +51,7 @@ allfuncs = ['Calculation',
|
||||||
'valid_in_network',
|
'valid_in_network',
|
||||||
'valid_broadcast',
|
'valid_broadcast',
|
||||||
'function_waiting_for_dict',
|
'function_waiting_for_dict',
|
||||||
|
'function_waiting_for_error',
|
||||||
]
|
]
|
||||||
allfuncs.extend(all_options)
|
allfuncs.extend(all_options)
|
||||||
del(all_options)
|
del(all_options)
|
||||||
|
|
|
@ -25,7 +25,7 @@ import weakref
|
||||||
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning
|
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .setting import undefined, ConfigBag
|
from .setting import undefined, ConfigBag
|
||||||
from .function import FUNCTION_WAITING_FOR_DICT
|
from .function import FUNCTION_WAITING_FOR_DICT, FUNCTION_WAITING_FOR_ERROR
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
@ -662,6 +662,11 @@ def carry_out_calculation(subconfig: 'SubConfig',
|
||||||
args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)})
|
args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)})
|
||||||
else:
|
else:
|
||||||
kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}
|
kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}
|
||||||
|
if callback.__name__ in FUNCTION_WAITING_FOR_ERROR:
|
||||||
|
if key is None:
|
||||||
|
args.append(err)
|
||||||
|
else:
|
||||||
|
kwargs[key] = err
|
||||||
ret = calculate(subconfig,
|
ret = calculate(subconfig,
|
||||||
callback,
|
callback,
|
||||||
allow_value_error,
|
allow_value_error,
|
||||||
|
|
|
@ -23,6 +23,7 @@ from .error import display_list
|
||||||
|
|
||||||
|
|
||||||
FUNCTION_WAITING_FOR_DICT = []
|
FUNCTION_WAITING_FOR_DICT = []
|
||||||
|
FUNCTION_WAITING_FOR_ERROR = []
|
||||||
|
|
||||||
|
|
||||||
def function_waiting_for_dict(function):
|
def function_waiting_for_dict(function):
|
||||||
|
@ -36,6 +37,16 @@ def function_waiting_for_dict(function):
|
||||||
return function
|
return function
|
||||||
|
|
||||||
|
|
||||||
|
def function_waiting_for_error(function):
|
||||||
|
"""functions (calculation or validation) receive by default only the value of other options
|
||||||
|
set PropertyError too
|
||||||
|
"""
|
||||||
|
name = function.__name__
|
||||||
|
if name not in FUNCTION_WAITING_FOR_ERROR:
|
||||||
|
FUNCTION_WAITING_FOR_ERROR.append(name)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
@function_waiting_for_dict
|
@function_waiting_for_dict
|
||||||
def valid_network_netmask(network: dict,
|
def valid_network_netmask(network: dict,
|
||||||
netmask: dict,
|
netmask: dict,
|
||||||
|
|
Loading…
Reference in a new issue