constants: split C.bool in C.bool and C.str so:
- you can use them without caring about the input type
- you always know the output type
This commit is contained in:
parent
136395eb6d
commit
176512b013
1 changed files with 9 additions and 2 deletions
|
|
@ -202,7 +202,14 @@ class Const(object):
|
|||
|
||||
@classmethod
|
||||
def bool(cls, value):
|
||||
"""retour str text value for bool, or bool value for str"""
|
||||
"""@return: bool value for any type"""
|
||||
if isinstance(value, str) or isinstance(value, unicode): # dbus.String is unicode but not str
|
||||
return value.lower() == cls.BOOL_TRUE
|
||||
return bool(value)
|
||||
|
||||
@classmethod
|
||||
def str(cls, value):
|
||||
"""@return: str text value for any type"""
|
||||
if isinstance(value, bool):
|
||||
return cls.BOOL_TRUE if value else cls.BOOL_FALSE
|
||||
return value.lower() == cls.BOOL_TRUE
|
||||
return str(value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue