From 8d05d4f2c52ed2101f7628c1e99bc0ae8427e230 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Tue, 12 Aug 2008 11:13:41 +0000 Subject: [PATCH] add type checking to config values (Closes: #353) --- deluge/config.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/deluge/config.py b/deluge/config.py index 6ec608f9b..4347c629f 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -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