def parse_tuple(token, delimeter): token = token.strip() if token.startswith('('): return tuple(imap(str.strip, split_advanced(token[1:-1], do_emit=lambda tok: tok == delimeter, add_emit_token=lambda tok: False))) return (token,)
def parse_tuple(token, delimeter): token = token.strip() if token.startswith('('): return tuple( imap( str.strip, split_advanced(token[1:-1], do_emit=lambda tok: tok == delimeter, add_emit_token=lambda tok: False))) return (token, )
def parse_tuples(self, pconfig, varexpr, output_vn, value): # eg. '(A|11) (B|12) (C|13)' -> [('A', 11), ('B', 12), ('C', 13)] -> [11, 12, 13] tuple_delimeter = pconfig.get(varexpr, 'delimeter', ',') tuple_token_list = lmap( str.strip, split_advanced(value, do_emit=lambda tok: tok in ' \n', add_emit_token=lambda tok: False)) return lmap(lambda tuple_str: parse_tuple(tuple_str, tuple_delimeter), tuple_token_list)
def _parseParameterTuple(self, varName, tupleValue, tupleType, varType, varIndex): if tupleType == 'tuple': tupleDelimeter = self.get(self._getParameterOption(varName), 'delimeter', ',') tupleStrings = lmap(str.strip, split_advanced(tupleValue, lambda tok: tok in ' \n', lambda tok: False)) tupleList = lmap(lambda t: parseTuple(t, tupleDelimeter), tupleStrings) elif tupleType == 'binning': tupleList = lzip(tupleValue.split(), tupleValue.split()[1:]) result = [] for tupleEntry in tupleList: try: tmp = self._parseParameter(varName, tupleEntry[varIndex], varType) except Exception: raise ConfigError('Unable to parse %r' % repr((tupleEntry, tupleStrings))) if isinstance(tmp, list): if len(tmp) != 1: raise ConfigError('[Variable: %s] Tuple entry (%s) expands to multiple variable entries (%s)!' % (varName, tupleEntry[varIndex], tmp)) result.append(tmp[0]) else: result.append(tmp) return result
def parse_tuples(self, pconfig, varexpr, output_vn, value): # eg. '(A|11) (B|12) (C|13)' -> [('A', 11), ('B', 12), ('C', 13)] -> [11, 12, 13] tuple_delimeter = pconfig.get(varexpr, 'delimeter', ',') tuple_token_list = lmap(str.strip, split_advanced(value, do_emit=lambda tok: tok in ' \n', add_emit_token=lambda tok: False)) return lmap(lambda tuple_str: parse_tuple(tuple_str, tuple_delimeter), tuple_token_list)
def parseTuple(t, delimeter): t = t.strip() if t.startswith('('): return tuple(imap(str.strip, split_advanced(t[1:-1], lambda tok: tok == delimeter, lambda tok: False))) return (t,)