From 176512b013d39d65dc421954a9919d94f7e3da1b Mon Sep 17 00:00:00 2001 From: souliane Date: Mon, 6 Oct 2014 12:22:14 +0200 Subject: [PATCH] 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 --- src/core/constants.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/constants.py b/src/core/constants.py index b00fbdc2..664d1099 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -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)