comparison src/core/constants.py @ 1228:2e1b4e7c8eb8

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
author souliane <souliane@mailoo.org>
date Mon, 06 Oct 2014 12:22:14 +0200
parents 4da2e4d58bd0
children cfd636203e8f
comparison
equal deleted inserted replaced
1227:4da2e4d58bd0 1228:2e1b4e7c8eb8
200 # XXX: we use a classmethod so we can use Const inheritance to change default options 200 # XXX: we use a classmethod so we can use Const inheritance to change default options
201 return(cls.LOG_OPT_COLORS, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT) 201 return(cls.LOG_OPT_COLORS, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT)
202 202
203 @classmethod 203 @classmethod
204 def bool(cls, value): 204 def bool(cls, value):
205 """retour str text value for bool, or bool value for str""" 205 """@return: bool value for any type"""
206 if isinstance(value, str) or isinstance(value, unicode): # dbus.String is unicode but not str
207 return value.lower() == cls.BOOL_TRUE
208 return bool(value)
209
210 @classmethod
211 def str(cls, value):
212 """@return: str text value for any type"""
206 if isinstance(value, bool): 213 if isinstance(value, bool):
207 return cls.BOOL_TRUE if value else cls.BOOL_FALSE 214 return cls.BOOL_TRUE if value else cls.BOOL_FALSE
208 return value.lower() == cls.BOOL_TRUE 215 return str(value)