def parse_duration(duration):
_re_token = re.compile("<STR_LIT>")<EOL>def parse_token(time, multiplier):<EOL><INDENT>multipliers = {<EOL>'<STR_LIT:d>': <NUM_LIT>,<EOL>'<STR_LIT:h>': <NUM_LIT>,<EOL>'<STR_LIT:m>': <NUM_LIT>,<EOL>'<STR_LIT:s>': <NUM_LIT:1>,<EOL>}<EOL>if multiplier:<EOL><INDENT>if multiplier in multipliers:<EOL><INDENT>return int(float(time) * multipliers[multiplier] * <NUM_LIT:1000>)<EOL><DEDENT>else:<EOL><INDENT>raise StepperConfigurationError(<EOL>'<STR_LIT>' % duration)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return int(float(time) * <NUM_LIT:1000>)<EOL><DEDENT><DEDENT>return sum(parse_token(*token) for token in _re_token.findall(duration))<EOL>
Parse duration string, such as '3h2m3s' into milliseconds

>>> parse_duration('3h2m3s')
10923000

>>> parse_duration('0.3s')
300

>>> parse_duration('5')
5000