is_default in _getattr
This commit is contained in:
parent
ede518428a
commit
426e64ca39
|
@ -81,7 +81,7 @@ class Config(object):
|
||||||
childdef = child.getdefault()
|
childdef = child.getdefault()
|
||||||
self._cfgimpl_values[child._name] = childdef
|
self._cfgimpl_values[child._name] = childdef
|
||||||
self._cfgimpl_previous_values[child._name] = childdef
|
self._cfgimpl_previous_values[child._name] = childdef
|
||||||
self._cfgimpl_value_owners[child._name] = 'default'
|
child.setowner(self, 'default')
|
||||||
elif isinstance(child, OptionDescription):
|
elif isinstance(child, OptionDescription):
|
||||||
self._validate_duplicates(child._children)
|
self._validate_duplicates(child._children)
|
||||||
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
||||||
|
@ -100,7 +100,7 @@ class Config(object):
|
||||||
copy(child.getdefault()), config=self, child=child)
|
copy(child.getdefault()), config=self, child=child)
|
||||||
else:
|
else:
|
||||||
self._cfgimpl_values[child._name] = copy(child.getdefault())
|
self._cfgimpl_values[child._name] = copy(child.getdefault())
|
||||||
self._cfgimpl_value_owners[child._name] = 'default'
|
child.setowner(self, 'default')
|
||||||
elif isinstance(child, OptionDescription):
|
elif isinstance(child, OptionDescription):
|
||||||
if child._name not in self._cfgimpl_values:
|
if child._name not in self._cfgimpl_values:
|
||||||
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
||||||
|
@ -188,16 +188,12 @@ class Config(object):
|
||||||
raise AttributeError("%s object has no attribute %s" %
|
raise AttributeError("%s object has no attribute %s" %
|
||||||
(self.__class__, name))
|
(self.__class__, name))
|
||||||
if not isinstance(opt_or_descr, OptionDescription):
|
if not isinstance(opt_or_descr, OptionDescription):
|
||||||
# options with callbacks (fill or auto)
|
# options with callbacks
|
||||||
if opt_or_descr.has_callback():
|
if opt_or_descr.has_callback():
|
||||||
value = self._cfgimpl_values[name]
|
value = self._cfgimpl_values[name]
|
||||||
if (not opt_or_descr.is_frozen() or \
|
if (not opt_or_descr.is_frozen() or \
|
||||||
not opt_or_descr.is_forced_on_freeze()) and \
|
not opt_or_descr.is_forced_on_freeze()) and \
|
||||||
not opt_or_descr.is_default_owner(self):
|
not opt_or_descr.is_default_owner(self):
|
||||||
if opt_or_descr.is_multi():
|
|
||||||
if None not in value:
|
|
||||||
return value
|
|
||||||
else:
|
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
result = opt_or_descr.getcallback_value(
|
result = opt_or_descr.getcallback_value(
|
||||||
|
@ -220,12 +216,11 @@ class Config(object):
|
||||||
raise ConfigError('invalid calculated value returned'
|
raise ConfigError('invalid calculated value returned'
|
||||||
' for option {0}'.format(name))
|
' for option {0}'.format(name))
|
||||||
self._cfgimpl_values[name] = _result
|
self._cfgimpl_values[name] = _result
|
||||||
self._cfgimpl_value_owners[name] = 'default'
|
opt_or_descr.setowner(self, 'default')
|
||||||
self._test_mandatory(name, opt_or_descr)
|
|
||||||
# frozen and force default
|
|
||||||
if not opt_or_descr.has_callback() and opt_or_descr.is_forced_on_freeze():
|
if not opt_or_descr.has_callback() and opt_or_descr.is_forced_on_freeze():
|
||||||
return opt_or_descr.getdefault()
|
return opt_or_descr.getdefault()
|
||||||
|
self._test_mandatory(name, opt_or_descr)
|
||||||
|
# frozen and force default
|
||||||
return self._cfgimpl_values[name]
|
return self._cfgimpl_values[name]
|
||||||
|
|
||||||
def unwrap_from_name(self, name):
|
def unwrap_from_name(self, name):
|
||||||
|
@ -254,17 +249,6 @@ class Config(object):
|
||||||
return getattr(homeconfig._cfgimpl_descr, path)
|
return getattr(homeconfig._cfgimpl_descr, path)
|
||||||
return getattr(self._cfgimpl_descr, path)
|
return getattr(self._cfgimpl_descr, path)
|
||||||
|
|
||||||
#def __delattr__(self, name):
|
|
||||||
# "if you use delattr you are responsible for all bad things happening"
|
|
||||||
# if name.startswith('_cfgimpl_'):
|
|
||||||
# del self.__dict__[name]
|
|
||||||
# return
|
|
||||||
# self._cfgimpl_value_owners[name] = 'default'
|
|
||||||
# opt = getattr(self._cfgimpl_descr, name)
|
|
||||||
# if isinstance(opt, OptionDescription):
|
|
||||||
# raise AttributeError("can't option subgroup")
|
|
||||||
# self._cfgimpl_values[name] = getattr(opt, 'default', None)
|
|
||||||
|
|
||||||
def setoption(self, name, value, who=None):
|
def setoption(self, name, value, who=None):
|
||||||
"""effectively modifies the value of an Option()
|
"""effectively modifies the value of an Option()
|
||||||
(typically called by the __setattr__)
|
(typically called by the __setattr__)
|
||||||
|
|
|
@ -45,7 +45,6 @@ master~slave group, the name of the group and the name of the
|
||||||
master option are identical.
|
master option are identical.
|
||||||
"""
|
"""
|
||||||
group_types = ['default', 'family', 'group', 'master']
|
group_types = ['default', 'family', 'group', 'master']
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
# multi types
|
# multi types
|
||||||
|
|
||||||
|
@ -79,8 +78,10 @@ class Multi(list):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def pop(self, key):
|
def pop(self, key):
|
||||||
|
oldvalue = list(self)
|
||||||
self.child.setowner(self.config, settings.owner)
|
self.child.setowner(self.config, settings.owner)
|
||||||
super(Multi, self).pop(key)
|
self.config._cfgimpl_previous_values[self.child._name] = oldvalue
|
||||||
|
return super(Multi, self).pop(key)
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
#
|
#
|
||||||
class Option(HiddenBaseType, DisabledBaseType):
|
class Option(HiddenBaseType, DisabledBaseType):
|
||||||
|
@ -196,7 +197,7 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
def is_empty_by_default(self):
|
def is_empty_by_default(self):
|
||||||
"no default value has been set yet"
|
"no default value has been set yet"
|
||||||
if ((not self.is_multi() and self.default == None) or
|
if ((not self.is_multi() and self.default == None) or
|
||||||
(self.is_multi() and self.default == []) or None in self.default):
|
(self.is_multi() and (self.default == [] or None in self.default))):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue