core: better use of C.bool: C.bool only accept basestring subclasses and return the associated constant, C.boolConst return the associated constant for a boolean value
This commit is contained in:
parent
e134c36aa7
commit
983dcf926e
1 changed files with 7 additions and 9 deletions
|
|
@ -219,14 +219,12 @@ class Const(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bool(cls, value):
|
def bool(cls, value):
|
||||||
"""@return: bool value for any type"""
|
"""@return (bool): bool value for associated constant"""
|
||||||
if isinstance(value, str) or isinstance(value, unicode): # dbus.String is unicode but not str
|
assert isinstance(value, basestring)
|
||||||
return value.lower() == cls.BOOL_TRUE
|
return value.lower() == cls.BOOL_TRUE
|
||||||
return bool(value)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def str(cls, value):
|
def boolConst(cls, value):
|
||||||
"""@return: str text value for any type"""
|
"""@return (str): constant associated to bool value"""
|
||||||
if isinstance(value, bool):
|
assert isinstance(value, bool)
|
||||||
return cls.BOOL_TRUE if value else cls.BOOL_FALSE
|
return cls.BOOL_TRUE if value else cls.BOOL_FALSE
|
||||||
return str(value)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue