config parser ignores extra items in config files now
This commit is contained in:
@@ -68,7 +68,7 @@ class MultiWorldParser(object):
|
|||||||
"""Validate and return the configuration"""
|
"""Validate and return the configuration"""
|
||||||
# Okay, this is okay, isn't it? We're going to create the validation
|
# Okay, this is okay, isn't it? We're going to create the validation
|
||||||
# routine right here, right now. I hope this works!
|
# 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...
|
# Woah. What just happened? No. WAIT, WHAT ARE YOU...
|
||||||
validated_config = validator(self._config_state)
|
validated_config = validator(self._config_state)
|
||||||
# WHAT HAVE YOU DONE?
|
# WHAT HAVE YOU DONE?
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ def make_dictValidator(keyvalidator, valuevalidator):
|
|||||||
return newd
|
return newd
|
||||||
return v
|
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
|
"""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
|
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
|
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.
|
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):
|
def configDictValidator(d):
|
||||||
newdict = {}
|
newdict = {}
|
||||||
@@ -177,6 +181,7 @@ def make_configDictValidator(config):
|
|||||||
|
|
||||||
# Now that all the defined keys have been accounted for, check to make
|
# Now that all the defined keys have been accounted for, check to make
|
||||||
# sure any unauthorized keys were not specified.
|
# sure any unauthorized keys were not specified.
|
||||||
|
if not ignore_undefined:
|
||||||
for key in d.iterkeys():
|
for key in d.iterkeys():
|
||||||
if key not in config:
|
if key not in config:
|
||||||
raise ValidationException("'%s' is not a configuration item" % key)
|
raise ValidationException("'%s' is not a configuration item" % key)
|
||||||
|
|||||||
Reference in New Issue
Block a user