def collapse_whitespace(message):
    """Collapses consecutive whitespace into a single space"""
    return u' '.join(map(lambda s: s.strip(),
                         filter(None, message.strip().splitlines())))
Collapses consecutive whitespace into a single space