comparison src/core/constants.py @ 1298:e2f71b715708 frontends_multi_profiles

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
author Goffi <goffi@goffi.org>
date Fri, 06 Feb 2015 18:46:26 +0100
parents faa1129559b8
children f296a54af386
comparison
equal deleted inserted replaced
1293:0541cb64217e 1298:e2f71b715708
217 # XXX: we use a classmethod so we can use Const inheritance to change default options 217 # XXX: we use a classmethod so we can use Const inheritance to change default options
218 return(cls.LOG_OPT_COLORS, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT) 218 return(cls.LOG_OPT_COLORS, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT)
219 219
220 @classmethod 220 @classmethod
221 def bool(cls, value): 221 def bool(cls, value):
222 """@return: bool value for any type""" 222 """@return (bool): bool value for associated constant"""
223 if isinstance(value, str) or isinstance(value, unicode): # dbus.String is unicode but not str 223 assert isinstance(value, basestring)
224 return value.lower() == cls.BOOL_TRUE 224 return value.lower() == cls.BOOL_TRUE
225 return bool(value)
226 225
227 @classmethod 226 @classmethod
228 def str(cls, value): 227 def boolConst(cls, value):
229 """@return: str text value for any type""" 228 """@return (str): constant associated to bool value"""
230 if isinstance(value, bool): 229 assert isinstance(value, bool)
231 return cls.BOOL_TRUE if value else cls.BOOL_FALSE 230 return cls.BOOL_TRUE if value else cls.BOOL_FALSE
232 return str(value)