setting_properties > properties
This commit is contained in:
@ -159,8 +159,9 @@ class OptionBag:
|
||||
|
||||
|
||||
class ConfigBag:
|
||||
__slots__ = ('context', # link to the current config (context)
|
||||
'setting_properties', # properties for current config
|
||||
__slots__ = ('context', # link to the current context
|
||||
'properties', # properties for current context
|
||||
#'permissives', # permissives for current context
|
||||
'force_permissive', # force permissive
|
||||
'_validate', # validate
|
||||
)
|
||||
@ -172,19 +173,19 @@ class ConfigBag:
|
||||
setattr(self, key, value)
|
||||
|
||||
def __getattr__(self, key):
|
||||
if key == 'setting_properties':
|
||||
self.setting_properties = self.context.cfgimpl_get_settings().get_context_properties()
|
||||
return self.setting_properties
|
||||
if key == 'properties':
|
||||
self.properties = self.context.cfgimpl_get_settings().get_context_properties()
|
||||
return self.properties
|
||||
raise KeyError('unknown key {} for ConfigBag'.format(key))
|
||||
|
||||
def remove_validation(self):
|
||||
self._validate = 'validator' in self.setting_properties
|
||||
self._validate = 'validator' in self.properties
|
||||
if self._validate:
|
||||
self.setting_properties = frozenset(self.setting_properties - {'validator'})
|
||||
self.properties = frozenset(self.properties - {'validator'})
|
||||
|
||||
def restore_validation(self):
|
||||
if self._validate:
|
||||
self.setting_properties = frozenset(self.setting_properties | {'validator'})
|
||||
self.properties = frozenset(self.properties | {'validator'})
|
||||
|
||||
def copy(self):
|
||||
kwargs = {}
|
||||
@ -341,7 +342,7 @@ class Settings(object):
|
||||
is_cached, props = self._p_.getcache(None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
{},
|
||||
None,
|
||||
'context_props')
|
||||
if not is_cached:
|
||||
@ -372,7 +373,7 @@ class Settings(object):
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
|
||||
if apply_requires:
|
||||
props = config_bag.setting_properties
|
||||
props = config_bag.properties
|
||||
is_cached, props = self._p_.getcache(path,
|
||||
expires_time,
|
||||
index,
|
||||
@ -398,8 +399,9 @@ class Settings(object):
|
||||
self._p_.setcache(path,
|
||||
index,
|
||||
props,
|
||||
config_bag.setting_properties,
|
||||
config_bag.setting_properties)
|
||||
config_bag.properties,
|
||||
#FIXME
|
||||
config_bag.properties)
|
||||
return props
|
||||
|
||||
def get_context_permissive(self):
|
||||
@ -502,7 +504,7 @@ class Settings(object):
|
||||
idx,
|
||||
config_bag)
|
||||
if option_bag.option == option:
|
||||
soption_bag.config_bag.setting_properties = frozenset()
|
||||
soption_bag.config_bag.properties = frozenset()
|
||||
soption_bag.config_bag.remove_validation()
|
||||
soption_bag.apply_requires = False
|
||||
try:
|
||||
@ -694,13 +696,15 @@ class Settings(object):
|
||||
:param force_permissive: behaves as if the permissive property
|
||||
was present
|
||||
"""
|
||||
# calc properties
|
||||
config_bag = option_bag.config_bag
|
||||
properties = option_bag.properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'}
|
||||
if not config_bag.properties:
|
||||
return
|
||||
# calc properties
|
||||
properties = option_bag.properties & config_bag.properties - {'frozen', 'mandatory', 'empty'}
|
||||
|
||||
# remove permissive properties
|
||||
if (config_bag.force_permissive is True or \
|
||||
'permissive' in config_bag.setting_properties) and properties:
|
||||
'permissive' in config_bag.properties) and properties:
|
||||
# remove global permissive if need
|
||||
properties -= self.get_context_permissive()
|
||||
# at this point an option should not remain in properties
|
||||
@ -712,11 +716,11 @@ class Settings(object):
|
||||
def validate_mandatory(self,
|
||||
value,
|
||||
option_bag):
|
||||
if 'mandatory' in option_bag.config_bag.setting_properties:
|
||||
if 'mandatory' in option_bag.config_bag.properties:
|
||||
values = self._getcontext().cfgimpl_get_values()
|
||||
is_mandatory = False
|
||||
if (option_bag.config_bag.force_permissive is True or \
|
||||
'permissive' in option_bag.config_bag.setting_properties) and \
|
||||
'permissive' in option_bag.config_bag.properties) and \
|
||||
'mandatory' in self.get_context_permissive():
|
||||
pass
|
||||
elif 'mandatory' in option_bag.properties and values.isempty(option_bag.option,
|
||||
@ -735,11 +739,11 @@ class Settings(object):
|
||||
|
||||
def validate_frozen(self,
|
||||
option_bag):
|
||||
if option_bag.config_bag.setting_properties and \
|
||||
('everything_frozen' in option_bag.config_bag.setting_properties or
|
||||
if option_bag.config_bag.properties and \
|
||||
('everything_frozen' in option_bag.config_bag.properties or
|
||||
'frozen' in option_bag.properties) and \
|
||||
not ((option_bag.config_bag.force_permissive is True or
|
||||
'permissive' in option_bag.config_bag.setting_properties) and
|
||||
'permissive' in option_bag.config_bag.properties) and
|
||||
'frozen' in self.get_context_permissive()):
|
||||
raise PropertiesOptionError(option_bag,
|
||||
['frozen'],
|
||||
|
Reference in New Issue
Block a user