import re


def cleanup_whitespace(text):
    """ Removes the empty whitespace before end of lines """

    out = []

    for line in text.split('\n'):
        line = re.sub(r'(\s+$)', '', line)
        out.append(line)

    return '\n'.join(out)