mandatory or type error raised

This commit is contained in:
gwen
2012-09-12 10:38:41 +02:00
parent c6ad86bd81
commit e2bcac1c01
5 changed files with 237 additions and 234 deletions

View File

@ -189,10 +189,10 @@ class Config(object):
if self.is_frozen() and getattr(self, name) != value:
raise TypeError("trying to change a value in a frozen config"
": {0} {1}".format(name, value))
if self.is_mandatory() and value == None:
raise MandatoryError("trying to reset option: {0} wich lives in a"
" mandatory group: {1}".format(name,
self._cfgimpl_descr._name))
# if self.is_mandatory() and value == None:
# raise MandatoryError("trying to reset option: {0} wich lives in a"
# " mandatory group: {1}".format(name,
# self._cfgimpl_descr._name))
if type(getattr(self._cfgimpl_descr, name)) != SymLinkOption:
self._validate(name, getattr(self._cfgimpl_descr, name))
self.setoption(name, value, self._cfgimpl_owner)

View File

@ -190,12 +190,11 @@ class Option(HiddenBaseType, DisabledBaseType):
def setoption(self, config, value, who):
"who is **not necessarily** a owner because it cannot be a list"
name = self._name
# the value cannot be changed if a callback is defined
if self.has_callback():
raise TypeError("trying to change an option with callback: %s" % name)
# we want the possibility to reset everything
if who == "default" and value is None:
self.default = None
return
if not self.validate(value):
if not (who == "default" and value is None) and not self.validate(value):
raise ConfigError('invalid value %s for option %s' % (value, name))
if self.is_mandatory():
# value shall not be '' for a mandatory option
@ -208,6 +207,9 @@ class Option(HiddenBaseType, DisabledBaseType):
(not self.is_multi() and value is None)):
raise MandatoryError('cannot override value to %s for '
'option %s' % (value, name))
if who == "default" and value is None:
self.default = None
return
if name not in config._cfgimpl_values:
raise AttributeError('unknown option %s' % (name))
if config.is_frozen() and (self.has_callback() or self.isfrozen()):