remove _getcontext in Settings
This commit is contained in:
@ -319,9 +319,11 @@ undefined = Undefined()
|
||||
#____________________________________________________________
|
||||
class Settings(object):
|
||||
"``config.Config()``'s configuration options settings"
|
||||
__slots__ = ('context', '_owner', '_p_', '_pp_', '__weakref__')
|
||||
__slots__ = ('_owner', '_p_', '_pp_', '__weakref__')
|
||||
|
||||
def __init__(self, context, properties, permissives):
|
||||
def __init__(self,
|
||||
properties,
|
||||
permissives):
|
||||
"""
|
||||
initializer
|
||||
|
||||
@ -333,21 +335,9 @@ class Settings(object):
|
||||
"""
|
||||
# generic owner
|
||||
self._owner = owners.user
|
||||
self.context = weakref.ref(context)
|
||||
self._p_ = properties
|
||||
self._pp_ = permissives
|
||||
|
||||
def _getcontext(self):
|
||||
"""context could be None, we need to test it
|
||||
context is None only if all reference to `Config` object is deleted
|
||||
(for example we delete a `Config` and we manipulate a reference to
|
||||
old `SubConfig`, `Values`, `Multi` or `Settings`)
|
||||
"""
|
||||
context = self.context()
|
||||
if context is None: # pragma: no cover
|
||||
raise ConfigError(_('the context does not exist anymore'))
|
||||
return context
|
||||
|
||||
#____________________________________________________________
|
||||
# get properties and permissive methods
|
||||
|
||||
@ -475,7 +465,7 @@ class Settings(object):
|
||||
if not current_requires:
|
||||
return calc_properties
|
||||
|
||||
context = self._getcontext()
|
||||
context = option_bag.config_bag.context
|
||||
all_properties = None
|
||||
for requires in current_requires:
|
||||
for require in requires:
|
||||
@ -574,15 +564,18 @@ class Settings(object):
|
||||
#____________________________________________________________
|
||||
# set methods
|
||||
def set_context_properties(self,
|
||||
properties):
|
||||
properties,
|
||||
context):
|
||||
self.setproperties(None,
|
||||
properties,
|
||||
None)
|
||||
None,
|
||||
context)
|
||||
|
||||
def setproperties(self,
|
||||
path,
|
||||
properties,
|
||||
option_bag):
|
||||
option_bag,
|
||||
context):
|
||||
"""save properties for specified path
|
||||
(never save properties if same has option properties)
|
||||
"""
|
||||
@ -611,7 +604,7 @@ class Settings(object):
|
||||
self._p_.setproperties(path,
|
||||
properties)
|
||||
#values too because of slave values could have a PropertiesOptionError has value
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
if option_bag is not None:
|
||||
try:
|
||||
del option_bag.properties
|
||||
@ -651,14 +644,14 @@ class Settings(object):
|
||||
' '.join(forbidden_permissives)))
|
||||
self._pp_.setpermissives(path, permissives)
|
||||
if option_bag is not None:
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
#____________________________________________________________
|
||||
# reset methods
|
||||
|
||||
def reset(self,
|
||||
option_bag):
|
||||
# all_properties=False):
|
||||
option_bag,
|
||||
context):
|
||||
if option_bag is None:
|
||||
opt = None
|
||||
else:
|
||||
@ -677,7 +670,7 @@ class Settings(object):
|
||||
else:
|
||||
path = None
|
||||
self._p_.delproperties(path)
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
#____________________________________________________________
|
||||
# validate properties
|
||||
@ -716,7 +709,7 @@ class Settings(object):
|
||||
value,
|
||||
option_bag):
|
||||
if 'mandatory' in option_bag.config_bag.properties:
|
||||
values = self._getcontext().cfgimpl_get_values()
|
||||
values = option_bag.config_bag.context.cfgimpl_get_values()
|
||||
is_mandatory = False
|
||||
if ('permissive' in option_bag.config_bag.properties) and \
|
||||
'mandatory' in option_bag.config_bag.permissives:
|
||||
@ -751,7 +744,8 @@ class Settings(object):
|
||||
|
||||
def _read(self,
|
||||
remove,
|
||||
append):
|
||||
append,
|
||||
context):
|
||||
props = self._p_.getproperties(None,
|
||||
default_properties)
|
||||
modified = False
|
||||
@ -762,17 +756,22 @@ class Settings(object):
|
||||
props = props | append
|
||||
modified = True
|
||||
if modified:
|
||||
self.set_context_properties(frozenset(props))
|
||||
self.set_context_properties(frozenset(props),
|
||||
context)
|
||||
|
||||
def read_only(self):
|
||||
def read_only(self,
|
||||
context):
|
||||
"convenience method to freeze, hide and disable"
|
||||
self._read(ro_remove,
|
||||
ro_append)
|
||||
ro_append,
|
||||
context)
|
||||
|
||||
def read_write(self):
|
||||
def read_write(self,
|
||||
context):
|
||||
"convenience method to freeze, hide and disable"
|
||||
self._read(rw_remove,
|
||||
rw_append)
|
||||
rw_append,
|
||||
context)
|
||||
|
||||
#____________________________________________________________
|
||||
# default owner methods
|
||||
|
Reference in New Issue
Block a user