no more restore_validation
This commit is contained in:
parent
26095734bf
commit
85e9e8d71a
|
@ -137,8 +137,6 @@ class OptionBag:
|
||||||
path,
|
path,
|
||||||
index,
|
index,
|
||||||
config_bag):
|
config_bag):
|
||||||
if self.option != None:
|
|
||||||
raise Exception('hu?')
|
|
||||||
if path is None:
|
if path is None:
|
||||||
path = config_bag.context.cfgimpl_get_description().impl_get_path_by_opt(option)
|
path = config_bag.context.cfgimpl_get_description().impl_get_path_by_opt(option)
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -157,18 +155,22 @@ class OptionBag:
|
||||||
return True
|
return True
|
||||||
raise KeyError('unknown key {} for OptionBag'.format(key))
|
raise KeyError('unknown key {} for OptionBag'.format(key))
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
kwargs = {}
|
||||||
|
option_bag = OptionBag()
|
||||||
|
for key in self.__slots__:
|
||||||
|
setattr(option_bag, key, getattr(self, key))
|
||||||
|
return option_bag
|
||||||
|
|
||||||
|
|
||||||
class ConfigBag:
|
class ConfigBag:
|
||||||
__slots__ = ('context', # link to the current context
|
__slots__ = ('context', # link to the current context
|
||||||
'properties', # properties for current context
|
'properties', # properties for current context
|
||||||
'permissives', # permissives for current context
|
'permissives', # permissives for current context
|
||||||
#'force_permissive', # force permissive
|
|
||||||
'_validate', # validate
|
|
||||||
)
|
)
|
||||||
def __init__(self, context, **kwargs):
|
def __init__(self, context, **kwargs):
|
||||||
#self.force_permissive = False
|
#self.force_permissive = False
|
||||||
self.context = context
|
self.context = context
|
||||||
self._validate = True
|
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
@ -182,14 +184,8 @@ class ConfigBag:
|
||||||
raise KeyError('unknown key {} for ConfigBag'.format(key))
|
raise KeyError('unknown key {} for ConfigBag'.format(key))
|
||||||
|
|
||||||
def remove_validation(self):
|
def remove_validation(self):
|
||||||
self._validate = 'validator' in self.properties
|
|
||||||
if self._validate:
|
|
||||||
self.properties = frozenset(self.properties - {'validator'})
|
self.properties = frozenset(self.properties - {'validator'})
|
||||||
|
|
||||||
def restore_validation(self):
|
|
||||||
if self._validate:
|
|
||||||
self.properties = frozenset(self.properties | {'validator'})
|
|
||||||
|
|
||||||
def set_permissive(self):
|
def set_permissive(self):
|
||||||
self.properties = frozenset(self.properties | {'permissive'})
|
self.properties = frozenset(self.properties | {'permissive'})
|
||||||
|
|
||||||
|
|
|
@ -291,17 +291,15 @@ class Values(object):
|
||||||
# set value to a fake config when option has dependency
|
# set value to a fake config when option has dependency
|
||||||
# validation will be complet in this case (consistency, ...)
|
# validation will be complet in this case (consistency, ...)
|
||||||
tested_context = context._gen_fake_values()
|
tested_context = context._gen_fake_values()
|
||||||
option_bag.config_bag.remove_validation()
|
config_bag = option_bag.config_bag.copy()
|
||||||
try:
|
config_bag.remove_validation()
|
||||||
|
soption_bag = option_bag.copy()
|
||||||
|
soption_bag.config_bag = config_bag
|
||||||
tested_context.cfgimpl_get_values().setvalue(value,
|
tested_context.cfgimpl_get_values().setvalue(value,
|
||||||
option_bag,
|
soption_bag,
|
||||||
True)
|
True)
|
||||||
option_bag.config_bag.restore_validation()
|
|
||||||
tested_context.getattr(option_bag.path,
|
tested_context.getattr(option_bag.path,
|
||||||
option_bag)
|
option_bag)
|
||||||
except Exception as exc:
|
|
||||||
option_bag.config_bag.restore_validation()
|
|
||||||
raise exc
|
|
||||||
else:
|
else:
|
||||||
self.setvalue_validation(value,
|
self.setvalue_validation(value,
|
||||||
option_bag)
|
option_bag)
|
||||||
|
@ -459,11 +457,13 @@ class Values(object):
|
||||||
hasvalue = self._p_.hasvalue(option_bag.path)
|
hasvalue = self._p_.hasvalue(option_bag.path)
|
||||||
|
|
||||||
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
||||||
option_bag.config_bag.remove_validation()
|
config_bag = option_bag.config_bag.copy()
|
||||||
|
config_bag.remove_validation()
|
||||||
|
soption_bag = option_bag.copy()
|
||||||
|
soption_bag.config_bag = config_bag
|
||||||
fake_context = context._gen_fake_values()
|
fake_context = context._gen_fake_values()
|
||||||
fake_value = fake_context.cfgimpl_get_values()
|
fake_value = fake_context.cfgimpl_get_values()
|
||||||
fake_value.reset(option_bag)
|
fake_value.reset(soption_bag)
|
||||||
option_bag.config_bag.restore_validation()
|
|
||||||
value = fake_value.getdefaultvalue(option_bag)
|
value = fake_value.getdefaultvalue(option_bag)
|
||||||
fake_value.setvalue_validation(value,
|
fake_value.setvalue_validation(value,
|
||||||
option_bag)
|
option_bag)
|
||||||
|
@ -496,16 +496,14 @@ class Values(object):
|
||||||
if 'validator' in option_bag.config_bag.properties:
|
if 'validator' in option_bag.config_bag.properties:
|
||||||
fake_context = context._gen_fake_values()
|
fake_context = context._gen_fake_values()
|
||||||
fake_value = fake_context.cfgimpl_get_values()
|
fake_value = fake_context.cfgimpl_get_values()
|
||||||
option_bag.config_bag.remove_validation()
|
config_bag = option_bag.config_bag.copy()
|
||||||
try:
|
config_bag.remove_validation()
|
||||||
fake_value.reset_slave(option_bag)
|
soption_bag = option_bag.copy()
|
||||||
value = fake_value.getdefaultvalue(option_bag)
|
soption_bag.config_bag = config_bag
|
||||||
|
fake_value.reset_slave(soption_bag)
|
||||||
|
value = fake_value.getdefaultvalue(soption_bag)
|
||||||
fake_value.setvalue_validation(value,
|
fake_value.setvalue_validation(value,
|
||||||
option_bag)
|
soption_bag)
|
||||||
option_bag.config_bag.restore_validation()
|
|
||||||
except Exception as err:
|
|
||||||
option_bag.config_bag.restore_validation()
|
|
||||||
raise err
|
|
||||||
self._p_.resetvalue_index(option_bag.path, option_bag.index)
|
self._p_.resetvalue_index(option_bag.path, option_bag.index)
|
||||||
context.cfgimpl_reset_cache(option_bag)
|
context.cfgimpl_reset_cache(option_bag)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue