6231: WARNING: configmanager.py: line 309: WARNING: ignoring key with wrong type

'behavior.autoload'


svn: r20790
This commit is contained in:
Benny Malengier 2012-12-18 11:53:42 +00:00
parent 2a1367ca51
commit a4b1518a04

View File

@ -290,6 +290,12 @@ class ConfigManager(object):
####################### Now, let's test and set: ####################### Now, let's test and set:
if (name in self.default and if (name in self.default and
setting in self.default[name]): setting in self.default[name]):
if isinstance(self.default[name][setting], bool):
#make sure 0 and 1 are False and True
if value == 0:
value = False
elif value == 1:
value = True
if self.check_type(self.default[name][setting], value): if self.check_type(self.default[name][setting], value):
self.data[name][setting] = value self.data[name][setting] = value
else: else:
@ -492,7 +498,7 @@ class ConfigManager(object):
(section, setting)) (section, setting))
# Check value to see if right type: # Check value to see if right type:
if self.has_default(key): if self.has_default(key):
if not self.check_type(self.get_default(key), value): if not self.check_type(self.get_default(key), value):
raise AttributeError("attempting to set '%s' to wrong type " raise AttributeError("attempting to set '%s' to wrong type "
"'%s'; should be '%s'" % "'%s'; should be '%s'" %
(key, type(value), (key, type(value),
@ -511,17 +517,17 @@ class ConfigManager(object):
def check_type(self, value1, value2): def check_type(self, value1, value2):
""" """
Check if value1 and value2 are different types. Check if value1 and value2 are different types.
""" """
type1 = type(value1) type1 = type(value1)
type2 = type(value2) type2 = type(value2)
if type1 == type2: if type1 == type2:
return True return True
elif (isinstance(value1, basestring) and elif (isinstance(value1, basestring) and
isinstance(value2, basestring)): isinstance(value2, basestring)):
return True return True
elif (type1 in [int, float, long] and elif (type1 in [int, float, long] and
type2 in [int, float, long]): type2 in [int, float, long]):
return True return True
else: else:
return False return False