diff options
Diffstat (limited to 'lib/param/bool_.py')
| -rw-r--r-- | lib/param/bool_.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/param/bool_.py b/lib/param/bool_.py index acce969..394dea6 100644 --- a/lib/param/bool_.py +++ b/lib/param/bool_.py @@ -1,19 +1,24 @@ +"""Defines the bool param type""" from param import Param import re -import sys class Bool(Param): - def __init__(self, value, classname=""): - super(Bool, self).__init__(classname=classname) - if value: - self.value = self._bool_correct(value) - else: - self.value = False - def _bool_correct(self, b): - if type(b) == str or type(b) == unicode: - if re.match(r'true', b, re.IGNORECASE): - return True - elif re.match(r'false', b, re.IGNORECASE): - return False - elif type(b) == bool: - return b - self.err_warn("Not a bool: %s" % str(b)) + """Defines the bool param type + Args: + value: the value of the bool (string or python bool) + classname: the name of the class to which the param belongs + """ + def __init__(self, value, classname=""): + super(Bool, self).__init__(classname=classname) + if value: + self.value = self._bool_correct(value) + else: + self.value = False + def _bool_correct(self, b): + if isinstance(b, str) or isinstance(b, unicode): + if re.match(r'true', b, re.IGNORECASE): + return True + elif re.match(r'false', b, re.IGNORECASE): + return False + elif isinstance(b, bool): + return b + self.err_warn("Not a bool: %s" % str(b)) |
