def striplines(chars):
    """Strip leading blank lines, trailing blank lines, and trailing blank spaces from every line"""

    lines = chars.splitlines()
    lines = list(_.rstrip() for _ in lines)
    while lines and not lines[0]:
        lines = lines[1:]
    while lines and not lines[-1]:
        lines = lines[:-1]

    stripped = "\n".join(lines) + "\n"
    return stripped