ca change default properties for a config

This commit is contained in:
2019-02-22 06:55:34 +01:00
parent 04b7d2bbc9
commit fd95c6dd4a
3 changed files with 147 additions and 25 deletions

View File

@ -87,7 +87,8 @@ warnings
demoting_error_warning
all value errors are convert to warning (ValueErrorWarning)
"""
default_properties = ('cache', 'validator', 'warnings')
DEFAULT_PROPERTIES = frozenset(['cache', 'validator', 'warnings'])
SPECIAL_PROPERTIES = {'frozen', 'mandatory', 'empty', 'force_store_value'}
"""Config can be in two defaut mode:
@ -101,12 +102,13 @@ read_write
you can get all variables not disabled and not hidden
you can set all variables not frozen
"""
ro_append = set(['frozen', 'disabled', 'validator', 'everything_frozen',
'mandatory', 'empty', 'force_store_value'])
ro_remove = set(['permissive', 'hidden'])
rw_append = set(['frozen', 'disabled', 'validator', 'hidden',
'force_store_value'])
rw_remove = set(['permissive', 'everything_frozen', 'mandatory', 'empty'])
RO_APPEND = frozenset(['frozen', 'disabled', 'validator', 'everything_frozen',
'mandatory', 'empty', 'force_store_value'])
RO_REMOVE = frozenset(['permissive', 'hidden'])
RW_APPEND = frozenset(['frozen', 'disabled', 'validator', 'hidden',
'force_store_value'])
RW_REMOVE = frozenset(['permissive', 'everything_frozen', 'mandatory',
'empty'])
FORBIDDEN_SET_PROPERTIES = frozenset(['force_store_value'])
@ -344,7 +346,12 @@ class Settings(object):
"``config.Config()``'s configuration options settings"
__slots__ = ('_p_',
'_pp_',
'__weakref__')
'__weakref__',
'ro_append',
'ro_remove',
'rw_append',
'rw_remove',
'default_properties')
def __init__(self,
properties,
@ -361,6 +368,11 @@ class Settings(object):
# generic owner
self._p_ = properties
self._pp_ = permissives
self.default_properties = DEFAULT_PROPERTIES
self.ro_append = RO_APPEND
self.ro_remove = RO_REMOVE
self.rw_append = RW_APPEND
self.rw_remove = RW_REMOVE
# ____________________________________________________________
# get properties and permissive methods
@ -374,7 +386,7 @@ class Settings(object):
'context_props')
if not is_cached:
props = self._p_.getproperties(None,
default_properties)
self.default_properties)
self._p_.setcache(None,
None,
props,
@ -711,10 +723,7 @@ class Settings(object):
option_properties,
config_properties,
config_permissives):
properties = option_properties & config_properties - {'frozen',
'mandatory',
'empty',
'force_store_value'}
properties = option_properties & config_properties - SPECIAL_PROPERTIES
# remove global permissive properties
if properties and ('permissive' in config_properties):
properties -= config_permissives
@ -783,7 +792,7 @@ class Settings(object):
append,
context):
props = self._p_.getproperties(None,
default_properties)
self.default_properties)
modified = False
if remove & props:
props = props - remove
@ -798,13 +807,13 @@ class Settings(object):
def read_only(self,
context):
"convenience method to freeze, hide and disable"
self._read(ro_remove,
ro_append,
self._read(self.ro_remove,
self.ro_append,
context)
def read_write(self,
context):
"convenience method to freeze, hide and disable"
self._read(rw_remove,
rw_append,
self._read(self.rw_remove,
self.rw_append,
context)