def iterlines(text):
    """
    Splits lines in string at '\n' while preserving line endings.
    """
    lines = text.split('\n')
    if text[-1] == '\n':
        lines = [line + '\n' for line in lines[:-1]]
        return lines
    else:
        lines = [line + '\n' for line in lines[:-1]] + [lines[-1]]
        return lines