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],..." print ">>>", dict([split(kv) for kv in to_split(val)]) return dict([split(kv) for kv in to_split(val)])
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],..." print ">>>", dict([split(kv) for kv in to_split(val)]) return dict([split(kv) for kv in to_split(val)])
def pythonize(self, val): """Convert value into a list:: * split value (or each element if value is a list) on coma char * strip split values :param val: value to convert :type val: :return: list corresponding to value :rtype: list """ if isinstance(val, list): return [s.strip() for s in list_split(val, self.split_on_coma) if s.strip() != '' or self.keep_empty] else: return [s.strip() for s in to_split(val, self.split_on_coma) if s.strip() != '' or self.keep_empty]
def pythonize(self, val): """Convert value into a list:: * split value (or each element if value is a list) on coma char * strip split values :param val: value to convert :type val: :return: list corresponding to value :rtype: list """ if isinstance(val, list): return [ s.strip() for s in list_split(val, self.split_on_coma) if s.strip() != '' or self.keep_empty ] else: return [ s.strip() for s in to_split(val, self.split_on_coma) if s.strip() != '' or self.keep_empty ]