is_default in _getattr

This commit is contained in:
gwen 2012-11-22 10:19:13 +01:00
parent ede518428a
commit 426e64ca39
2 changed files with 11 additions and 26 deletions

View File

@ -81,7 +81,7 @@ class Config(object):
childdef = child.getdefault()
self._cfgimpl_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):
self._validate_duplicates(child._children)
self._cfgimpl_values[child._name] = Config(child, parent=self)
@ -100,7 +100,7 @@ class Config(object):
copy(child.getdefault()), config=self, child=child)
else:
self._cfgimpl_values[child._name] = copy(child.getdefault())
self._cfgimpl_value_owners[child._name] = 'default'
child.setowner(self, 'default')
elif isinstance(child, OptionDescription):
if child._name not in self._cfgimpl_values:
self._cfgimpl_values[child._name] = Config(child, parent=self)
@ -188,16 +188,12 @@ class Config(object):
raise AttributeError("%s object has no attribute %s" %
(self.__class__, name))
if not isinstance(opt_or_descr, OptionDescription):
# options with callbacks (fill or auto)
# options with callbacks
if opt_or_descr.has_callback():
value = self._cfgimpl_values[name]
if (not opt_or_descr.is_frozen() or \
not opt_or_descr.is_forced_on_freeze()) and \
not opt_or_descr.is_default_owner(self):
if opt_or_descr.is_multi():
if None not in value:
return value
else:
return value
try:
result = opt_or_descr.getcallback_value(
@ -220,12 +216,11 @@ class Config(object):
raise ConfigError('invalid calculated value returned'
' for option {0}'.format(name))
self._cfgimpl_values[name] = _result
self._cfgimpl_value_owners[name] = 'default'
self._test_mandatory(name, opt_or_descr)
# frozen and force default
opt_or_descr.setowner(self, 'default')
if not opt_or_descr.has_callback() and opt_or_descr.is_forced_on_freeze():
return opt_or_descr.getdefault()
self._test_mandatory(name, opt_or_descr)
# frozen and force default
return self._cfgimpl_values[name]
def unwrap_from_name(self, name):
@ -254,17 +249,6 @@ class Config(object):
return getattr(homeconfig._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):
"""effectively modifies the value of an Option()
(typically called by the __setattr__)

View File

@ -45,7 +45,6 @@ master~slave group, the name of the group and the name of the
master option are identical.
"""
group_types = ['default', 'family', 'group', 'master']
# ____________________________________________________________
# multi types
@ -79,8 +78,10 @@ class Multi(list):
return ret
def pop(self, key):
oldvalue = list(self)
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):
@ -196,7 +197,7 @@ class Option(HiddenBaseType, DisabledBaseType):
def is_empty_by_default(self):
"no default value has been set yet"
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 False