def extract_hist_ranges(ranges_str):
for range_str in ranges_str.split():<EOL><INDENT>rmatch = range_re.match(range_str)<EOL>if not rmatch:<EOL><INDENT>continue<EOL><DEDENT>start = int(rmatch.group("<STR_LIT:start>"))<EOL>end = rmatch.group("<STR_LIT:end>")<EOL>end = int(end) if end else start+<NUM_LIT:1>   <EOL>if rmatch.group("<STR_LIT>") == "<STR_LIT:->":       <EOL><INDENT>end += <NUM_LIT:1><EOL><DEDENT>startsess = rmatch.group("<STR_LIT>") or "<STR_LIT:0>"<EOL>endsess = rmatch.group("<STR_LIT>") or startsess<EOL>startsess = int(startsess.replace("<STR_LIT>","<STR_LIT:->"))<EOL>endsess = int(endsess.replace("<STR_LIT>","<STR_LIT:->"))<EOL>assert endsess >= startsess<EOL>if endsess == startsess:<EOL><INDENT>yield (startsess, start, end)<EOL>continue<EOL><DEDENT>yield (startsess, start, None)<EOL>for sess in range(startsess+<NUM_LIT:1>, endsess):<EOL><INDENT>yield (sess, <NUM_LIT:1>, None)<EOL><DEDENT>yield (endsess, <NUM_LIT:1>, end)<EOL><DEDENT>
Turn a string of history ranges into 3-tuples of (session, start, stop).

    Examples
    --------
    list(extract_input_ranges("~8/5-~7/4 2"))
    [(-8, 5, None), (-7, 1, 4), (0, 2, 3)]