Skip to content

Commit

Permalink
Fixed the way boolean configuration values are converted to bools by
Browse files Browse the repository at this point in the history
replacing bool() usage with a function that checks for specific string
values in order to determine True or False.

bool() will evaluate to True for all non empty strings.

Reported-by: Leonid Veytser <veytser@ll.mit.edu>
See #14
  • Loading branch information
sgalgano committed Aug 27, 2014
1 parent ed125bc commit eb4c5e5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/emanesh/emanesh/emaneshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,17 @@ def do_set(self,args):
if len(args) > index:
for expression in args[index:]:
m = re.match('^([0-9A-Za-z]+)=(.+)', expression)

def toBool(val):
val = val.lower()

if val in ('yes','on','enable','true','1'):
return True
elif val in ('no','off','disable','false','0'):
return False
else:
raise ValueError()

convert = {'uint64' : (ControlPortClient.TYPE_UINT64,long),
'uint32' : (ControlPortClient.TYPE_UINT32,long),
'uint16' : (ControlPortClient.TYPE_UINT16,long),
Expand All @@ -760,7 +771,7 @@ def do_set(self,args):
'int32' : (ControlPortClient.TYPE_INT32,long),
'int16' : (ControlPortClient.TYPE_INT16,long),
'int8' : (ControlPortClient.TYPE_INT8,long),
'bool' : (ControlPortClient.TYPE_BOOLEAN,bool),
'bool' : (ControlPortClient.TYPE_BOOLEAN,toBool),
'string': (ControlPortClient.TYPE_STRING,str),
'inetaddr' : (ControlPortClient.TYPE_INETADDR,str),
'float' : (ControlPortClient.TYPE_FLOAT,float),
Expand Down

0 comments on commit eb4c5e5

Please sign in to comment.