changeset 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 03661d1b216a
files src/core/constants.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/constants.py	Mon Oct 06 11:20:43 2014 +0200
+++ b/src/core/constants.py	Mon Oct 06 12:22:14 2014 +0200
@@ -202,7 +202,14 @@
 
     @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)