def trimLines(lines, stats=False):
    """Remove leading and trailing blank lines from a seqence of lines.

    :Parameters:
      lines
        The lines to be trimmed. May be a sequences or generator.
      stats
        If supplied and true then trimmed lines statistics are include in the
        return value.

    :Return:
        If ``stats`` is true then a tuple of::

            ``(trimmed-lines, (before, after))``

        where ``before`` is the number of leading blank lines and ``after`` the
        number of trailing blank lines. Otherwise just the trimmed list of
        lines is returned.
    """
    lines = list(lines)
    before, after = 0, 0
    while lines and not lines[0].strip():
        lines.pop(0)
        before += 1
    while lines and not lines[-1].strip():
        lines.pop()
        after += 1
    if stats:
        return lines, (before, after)
    return lines