def format_result(result): if list_re: x = [] for l in result.splitlines(): match = list_re.match(l.strip()) if match: x += [match.groupdict()] return x else: return result
def match_lines(cls, rx, s): k = id(rx) if k not in cls._match_lines_cache: _rx = [re.compile(line, re.IGNORECASE) for line in rx] cls._match_lines_cache[k] = _rx else: _rx = cls._match_lines_cache[k] ctx = {} idx = 0 r = _rx[0] for line in s.splitlines(): line = line.strip() match = r.search(line) if match: ctx.update(match.groupdict()) idx += 1 if idx == len(_rx): return ctx r = _rx[idx] return None