def quoted(text):
    """Quoted `text`, if it contains whitespaces

    >>> quoted("foo")
    'foo'
    >>> quoted("foo bar")
    '"foo bar"'

    Args:
        text (str | unicode | None): Text to optionally quote

    Returns:
        (str): Quoted if 'text' contains spaces
    """
    if text and ' ' in text:
        sep = "'" if '"' in text else '"'
        return '%s%s%s' % (sep, text, sep)
    return text
