def __new__(cls, *, allow_credentials=False, expose_headers=(),
                allow_headers=(), max_age=None, allow_methods=None):
        """Normalize source parameters and store them in namedtuple."""

        if not isinstance(allow_credentials, bool):
            raise ValueError(
                "'allow_credentials' must be boolean, "
                "got '{!r}'".format(allow_credentials))
        _allow_credentials = allow_credentials

        # `expose_headers` is either "*", or sequence of strings.
        if expose_headers == "*":
            _expose_headers = expose_headers
        elif not _is_proper_sequence(expose_headers):
            raise ValueError(
                "'expose_headers' must be either '*', or sequence of strings, "
                "got '{!r}'".format(expose_headers))
        elif expose_headers:
            # "Access-Control-Expose-Headers" ":" #field-name
            # TODO: Check that headers are valid.
            # TODO: Remove headers that in the _SIMPLE_RESPONSE_HEADERS set
            # according to
            # <http://www.w3.org/TR/cors/#list-of-exposed-headers>.
            _expose_headers = frozenset(expose_headers)
        else:
            # No headers exposed.
            _expose_headers = frozenset()

        # `allow_headers` is either "*", or set of headers in upper case.
        if allow_headers == "*":
            _allow_headers = allow_headers
        elif not _is_proper_sequence(allow_headers):
            raise ValueError(
                "'allow_headers' must be either '*', or sequence of strings, "
                "got '{!r}'".format(allow_headers))
        else:
            # TODO: Check that headers are valid.
            _allow_headers = frozenset(h.upper() for h in allow_headers)

        if max_age is None:
            _max_age = None
        else:
            if not isinstance(max_age, numbers.Integral) or max_age < 0:
                raise ValueError(
                    "'max_age' must be non-negative integer, "
                    "got '{!r}'".format(max_age))
            _max_age = max_age

        if allow_methods is None or allow_methods == "*":
            _allow_methods = allow_methods
        elif not _is_proper_sequence(allow_methods):
            raise ValueError(
                "'allow_methods' must be either '*', or sequence of strings, "
                "got '{!r}'".format(allow_methods))
        else:
            # TODO: Check that methods are valid.
            _allow_methods = frozenset(m.upper() for m in allow_methods)

        return super().__new__(
            cls,
            allow_credentials=_allow_credentials,
            expose_headers=_expose_headers,
            allow_headers=_allow_headers,
            max_age=_max_age,
            allow_methods=_allow_methods)
def __new__ ( cls , * , allow_credentials = False , expose_headers = ( ) , allow_headers = ( ) , max_age = None , allow_methods = None ) : if not isinstance ( allow_credentials , bool ) : raise ValueError ( "'allow_credentials' must be boolean, " "got '{!r}'" . format ( allow_credentials ) ) _allow_credentials = allow_credentials if expose_headers == "*" : _expose_headers = expose_headers elif not _is_proper_sequence ( expose_headers ) : raise ValueError ( "'expose_headers' must be either '*', or sequence of strings, " "got '{!r}'" . format ( expose_headers ) ) elif expose_headers : _expose_headers = frozenset ( expose_headers ) else : _expose_headers = frozenset ( ) if allow_headers == "*" : _allow_headers = allow_headers elif not _is_proper_sequence ( allow_headers ) : raise ValueError ( "'allow_headers' must be either '*', or sequence of strings, " "got '{!r}'" . format ( allow_headers ) ) else : _allow_headers = frozenset ( h . upper ( ) for h in allow_headers ) if max_age is None : _max_age = None else : if not isinstance ( max_age , numbers . Integral ) or max_age < 0 : raise ValueError ( "'max_age' must be non-negative integer, " "got '{!r}'" . format ( max_age ) ) _max_age = max_age if allow_methods is None or allow_methods == "*" : _allow_methods = allow_methods elif not _is_proper_sequence ( allow_methods ) : raise ValueError ( "'allow_methods' must be either '*', or sequence of strings, " "got '{!r}'" . format ( allow_methods ) ) else : _allow_methods = frozenset ( m . upper ( ) for m in allow_methods ) return super ( ) . __new__ ( cls , allow_credentials = _allow_credentials , expose_headers = _expose_headers , allow_headers = _allow_headers , max_age = _max_age , allow_methods = _allow_methods )
Normalize source parameters and store them in namedtuple.