def strip_spaces_and_quotes(value):
    """Remove invalid whitespace and/or single pair of dquotes and return None
    for empty strings.

    Used to prepare cookie values, path, and domain attributes in a way which
    tolerates simple formatting mistakes and standards variations.
    """
    value = value.strip() if value else ''
    if value and len(value) > 1 and value[0] == value[-1] == '"':
        value = value[1:-1]
    if not value:
        value = ''
    return value
