Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse(result, flatten=False, join=False):
def parse_opt(opt, join=False):
if join:
return [u for u in re.findall(tag_re, opt.strip())]
else:
return [tuple(u.rsplit('/', 1)) for u in re.findall(tag_re, opt.strip())]
if not result:
return []
elems = result.strip().splitlines()
index = [i for i, e in enumerate(elems) if not e]
parts = utils.partition(elems, index)
if flatten:
return sum([parse_opt(opt, join=join) for part in parts
for opt in list(filter(None, part))[1:]], [])
else:
return [[parse_opt(opt, join=join) for opt in list(filter(None, part))[1:]]
for part in parts]