def parse(s):
parts = s.replace('<STR_LIT:U+002C>', '<STR_LIT:U+0020>').split()<EOL>if not parts:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>pieces = []<EOL>for part in parts:<EOL><INDENT>m = PART_MATCH(part)<EOL>pieces.extend(m.groups() if m else [part])<EOL><DEDENT>if len(pieces) == <NUM_LIT:1>:<EOL><INDENT>pieces.append('<STR_LIT:s>')<EOL><DEDENT>if len(pieces) % <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>' % (s, parts, pieces))<EOL><DEDENT>result = <NUM_LIT:0><EOL>for number, units in zip(*[iter(pieces)] * <NUM_LIT:2>):<EOL><INDENT>number = float(number)<EOL>if number < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>result += number * _get_units(units)<EOL><DEDENT>return result<EOL>
Parse a string representing a time interval or duration into seconds,
or raise an exception

:param str s: a string representation of a time interval
:raises ValueError: if ``s`` can't be interpreted as a duration