"""
This type stub file was generated by pyright.
"""

from typing import Any, Mapping, Union
from aiohttp import hdrs, web
from .abc import AbstractRouterAdapter
from .resource_options import ResourceOptions
from .preflight_handler import _PreflightHandler

"""CORS configuration container class definition.
"""
__all__ = ("CorsConfig", )
_TRUE = "true"
_SIMPLE_RESPONSE_HEADERS = frozenset([hdrs.CACHE_CONTROL, hdrs.CONTENT_LANGUAGE, hdrs.CONTENT_TYPE, hdrs.EXPIRES, hdrs.LAST_MODIFIED, hdrs.PRAGMA])
def _parse_config_options(config: Mapping[str, Union[ResourceOptions, Mapping[str, Any]]] = ...):
    """Parse CORS configuration (default or per-route)

    :param config:
        Mapping from Origin to Resource configuration (allowed headers etc)
        defined either as mapping or `ResourceOptions` instance.

    Raises `ValueError` if configuration is not correct.
    """
    ...

_ConfigType = Mapping[str, Union[ResourceOptions, Mapping[str, Any]]]
class _CorsConfigImpl(_PreflightHandler):
    def __init__(self, app: web.Application, router_adapter: AbstractRouterAdapter):
        ...
    
    def add(self, routing_entity, config: _ConfigType = ...):
        """Enable CORS for specific route or resource.

        If route is passed CORS is enabled for route's resource.

        :param routing_entity:
            Route or Resource for which CORS should be enabled.
        :param config:
            CORS options for the route.
        :return: `routing_entity`.
        """
        ...
    
    async def _on_response_prepare(self, request: web.Request, response: web.StreamResponse):
        """Non-preflight CORS request response processor.

        If request is done on CORS-enabled route, process request parameters
        and set appropriate CORS response headers.
        """
        ...
    
    async def _get_config(self, request, origin, request_method):
        ...
    


class CorsConfig:
    """CORS configuration instance.

    The instance holds default CORS parameters and per-route options specified
    in `add()` method.

    Each `aiohttp.web.Application` can have exactly one instance of this class.
    """
    def __init__(self, app: web.Application, *, defaults: _ConfigType = ..., router_adapter: AbstractRouterAdapter = ...):
        """Construct CORS configuration.

        :param app:
            Application for which CORS configuration is built.
        :param defaults:
            Default CORS settings for origins.
        :param router_adapter:
            Router adapter. Required if application uses non-default router.
        """
        self.defaults = ...
    
    def add(self, routing_entity, config: _ConfigType = ..., webview: bool = ...):
        """Enable CORS for specific route or resource.

        If route is passed CORS is enabled for route's resource.

        :param routing_entity:
            Route or Resource for which CORS should be enabled.
        :param config:
            CORS options for the route.
        :return: `routing_entity`.
        """
        ...
    


