def clean_whitespaces(text):
    """
    Remove multiple whitespaces from text. Also removes leading and trailing \
    whitespaces.

    :param text: Text to remove multiple whitespaces from.
    :returns: A cleaned text.

    >>> clean_whitespaces("this  is    a text with    spaces")
    'this is a text with spaces'
    """
    return ' '.join(text.strip().split())