def section(iterator, end, firstline=None):
    """
    Generates lines from the iterator until `end` is matched or iterator stops
    
    :param:

     - `iterator`: An iterator of lines
     - `end`: A regular expression to match the last line in the section

    :yield: lines up to and including the end match
    """
    ended = False
    if firstline is not None:
        yield firstline
    while not ended:
        try:
            line = iterator.next()
            if end.search(line):
                ended = True
            yield line
        except StopIteration:
            return
