0

changed the semantics of required and default in settings definitions.

I think it makes more logical sense now. Essentially, the default is
always used if the user doesn't specify a value. If there is no user
specified value and the default is None, then the action depends on the
value of required. required=True means raise an error. required=False
means silently omit that setting.
This commit is contained in:
Andrew Brown
2012-02-04 22:06:29 -05:00
parent 6d95d80a73
commit 324100206b
3 changed files with 61 additions and 45 deletions

View File

@@ -162,13 +162,13 @@ def make_configdictvalidator(config):
if configkey in d:
# This key /was/ specified in the user's dict. Make sure it validates.
newdict[configkey] = configsetting.validator(d[configkey])
else:
# The user did not give us this key. If it's required, send up
# an error. Otherwise, just return the default.
if configsetting.required:
raise ValidationException("Required key '%s' was not specified" % configkey)
elif configsetting.default is not None:
newdict[configkey] = configsetting.validator(configsetting.default)
elif configsetting.default is not None:
# There is a default, use that instead
newdict[configkey] = configsetting.validator(configsetting.default)
elif configsetting.required:
# The user did not give us this key, there is no default, AND
# it's required. This is an error.
raise ValidationException("Required key '%s' was not specified. You must give a value for this setting" % configkey)
# Now that all the defined keys have been accounted for, check to make
# sure any unauthorized keys were not specified.