add type checking to config values (Closes: #353)

This commit is contained in:
Damien Churchill 2008-08-12 11:13:41 +00:00
parent 0ed48a6cd8
commit 8d05d4f2c5

View File

@ -114,7 +114,16 @@ class Config:
"""Set the 'key' with 'value'."""
# Sets the "key" with "value" in the config dict
if self.config[key] != value:
log.debug("Setting '%s' to %s of %s", key, value, type(value))
oldtype, newtype = type(self.config[key]), type(value)
if oldtype != newtype:
try:
value = oldtype(value)
except ValueError:
log.warning("Type '%s' invalid for '%s'", newtype, key)
return
log.debug("Setting '%s' to %s of %s", key, value, oldtype)
# Make a copy of the current config prior to changing it
self.previous_config = self.config.copy()
self.config[key] = value