def parselinenos(spec, nlines=None):
    """Parse a line class spec into a dict of line no: class name

    """

    items = {}
    parts = spec.split(',')

    for part in parts:
        line_class = LINECLASS_RE.match(part)
        start = int(line_class.group('start'))

        if line_class.group('range'):
            if line_class.group('end'):
                end = int(line_class.group('end'))
            else:
                end = nlines

            for line_no in range(start, end + 1):
                items[line_no] = line_class.group('class')

        else:
            items[start] = line_class.group('class')

    return items
Parse a line class spec into a dict of line no: class name