0

config parser ignores extra items in config files now

This commit is contained in:
Andrew Brown
2012-02-11 16:01:16 -05:00
parent c60936efbd
commit e7995e19b2
2 changed files with 10 additions and 5 deletions

View File

@@ -68,7 +68,7 @@ class MultiWorldParser(object):
"""Validate and return the configuration"""
# Okay, this is okay, isn't it? We're going to create the validation
# routine right here, right now. I hope this works!
validator = settingsValidators.make_configDictValidator(self._settings)
validator = settingsValidators.make_configDictValidator(self._settings, ignore_undefined=True)
# Woah. What just happened? No. WAIT, WHAT ARE YOU...
validated_config = validator(self._config_state)
# WHAT HAVE YOU DONE?

View File

@@ -148,7 +148,7 @@ def make_dictValidator(keyvalidator, valuevalidator):
return newd
return v
def make_configDictValidator(config):
def make_configDictValidator(config, ignore_undefined=False):
"""Okay, stay with me here, this may get confusing. This function returns a
validator that validates a "configdict". This is a term I just made up to
refer to a dict that holds config information: keys are strings and values
@@ -160,6 +160,10 @@ def make_configDictValidator(config):
I hope that makes sense.
ignore_undefined, if True, will ignore any items in the dict to be
validated which don't have a corresponding definition in the config.
Otherwise, undefined entries will raise an error.
"""
def configDictValidator(d):
newdict = {}
@@ -177,9 +181,10 @@ def make_configDictValidator(config):
# Now that all the defined keys have been accounted for, check to make
# sure any unauthorized keys were not specified.
for key in d.iterkeys():
if key not in config:
raise ValidationException("'%s' is not a configuration item" % key)
if not ignore_undefined:
for key in d.iterkeys():
if key not in config:
raise ValidationException("'%s' is not a configuration item" % key)
return newdict
return configDictValidator