def pythonize(self, val): """Convert value into a boolean :param val: value to convert :type val: bool, int, str :return: boolean corresponding to value :: {'1': True, 'yes': True, 'true': True, 'on': True, '0': False, 'no': False, 'false': False, 'off': False} :rtype: bool """ __boolean_states__ = { '1': True, 'yes': True, 'true': True, 'on': True, '0': False, 'no': False, 'false': False, 'off': False } if isinstance(val, bool): return val val = unique_value(val).lower() if val in list(__boolean_states__.keys()): return __boolean_states__[val] raise PythonizeError("Cannot convert '%s' to a boolean value" % val)
def pythonize(self, val): """Convert value into a string:: * If value is a list, try to take the last element :param val: value to convert :type val: :return: str corresponding to value :rtype: str """ return unique_value(val).strip()
def pythonize(self, val): """Convert value into a log level property:: * If value is a list, try to take the last element * get logging level base on the value :param val: value to convert :type val: :return: log level corresponding to value :rtype: str """ return logging.getLevelName(unique_value(val))
def pythonize(self, val): """Convert value into a char :: * If value is a list try, to take the last element * Then take the first char of val (first elem) :param val: value to convert :type val: :return: char corresponding to value :rtype: str """ return to_char(unique_value(val))
def pythonize(self, val): """Convert value into a float:: * If value is a list, try to take the last element * Then call float(val) :param val: value to convert :type val: :return: float corresponding to value :rtype: float """ return to_float(unique_value(val))
def pythonize(self, val): """Convert value into a address ip format:: * If value is a list, try to take the last element * match ip address and port (if available) :param val: value to convert :type val: :return: address/port corresponding to value :rtype: dict """ val = unique_value(val) matches = re.match(r"^([^:]*)(?::(\d+))?$", val) if matches is None: raise ValueError addr = {'address': matches.group(1)} if matches.group(2) is not None: addr['port'] = int(matches.group(2)) return addr
def pythonize(self, val): """Convert value into a dict:: * If value is a list, try to take the last element * split "key=value" string and convert to { key:value } :param val: value to convert :type val: :return: log level corresponding to value :rtype: str """ val = unique_value(val) def split(keyval): """Split key-value string into (key,value) :param keyval: key value string :return: key, value :rtype: tuple """ matches = re.match(r"^\s*([^\s]+)\s*=\s*([^\s]+)\s*$", keyval) if matches is None: raise ValueError return ( matches.group(1), # >2.4 only. we keep it for later. m.group(2) if self.elts_prop is None # else self.elts_prop.pythonize(m.group(2)) (self.elts_prop.pythonize(matches.group(2)), matches.group(2) )[self.elts_prop is None]) if val is None: return dict() if self.elts_prop is None: return val # val is in the form "key1=addr:[port],key2=addr:[port],..." return dict([split(kv) for kv in to_split(val)])