a
    ^g)                     @  s  d dl mZ d dlZd dlZd dlZejdkr<d dlmZ nd dlmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZ d dlmZmZmZmZm Z m!Z! d dl"m#Z# ej$dddZ%edZ&G dd dZ'dS )    )annotationsN)   
   )	ParamSpec)StateURLPath)
Middleware_MiddlewareFactory)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppExceptionHandlerLifespanReceiveScopeSend)	WebSocketAppType	Starlette)boundPc                   @  sf  e Zd ZdZdQdddddd	d	d
dd	ddZddddZeddddZddddddZdddddd d!Z	dd"d#d$d%Z
dRddd&dd'd(d)ZdSddd&dd*d+d,Zd-d.d/dd0d1d2Zd3d4dd5d6d7Zdd"dd8d9d:ZdTdd<d=d&ddd>d?d@ZdUddAd&ddBdCdDZd3d"dEdFdGZdVdd=d&dd"dHdIdJZdWdd&d"dKdLdMZdd"dNdOdPZdS )Xr   z!Creates an Starlette application.FNr   boolz!typing.Sequence[BaseRoute] | Nonez"typing.Sequence[Middleware] | Nonez3typing.Mapping[typing.Any, ExceptionHandler] | Nonez7typing.Sequence[typing.Callable[[], typing.Any]] | NonezLifespan[AppType] | NoneNone)	selfdebugroutes
middlewareexception_handlers
on_startupon_shutdownlifespanreturnc                 C  sv   |du s |du r|du s J d|| _ t | _t||||d| _|du rLi nt|| _|du rbg nt|| _d| _	dS )a  Initializes the application.

        Parameters:
            debug: Boolean indicating if debug tracebacks should be returned on errors.
            routes: A list of routes to serve incoming HTTP and WebSocket requests.
            middleware: A list of middleware to run for every request. A starlette
                application will always automatically include two middleware classes.
                `ServerErrorMiddleware` is added as the very outermost middleware, to handle
                any uncaught errors occurring anywhere in the entire stack.
                `ExceptionMiddleware` is added as the very innermost middleware, to deal
                with handled exception cases occurring in the routing or endpoints.
            exception_handlers: A mapping of either integer status codes,
                or exception class types onto callables which handle the exceptions.
                Exception handler callables should be of the form
                `handler(request, exc) -> response` and may be either standard functions, or
                async functions.
            on_startup: A list of callables to run on application startup.
                Startup handler callables do not take any arguments, and may be either
                standard functions, or async functions.
            on_shutdown: A list of callables to run on application shutdown.
                Shutdown handler callables do not take any arguments, and may be either
                standard functions, or async functions.
            lifespan: A lifespan context function, which can be used to perform
                startup and shutdown tasks. This is a newer style that replaces the
                `on_startup` and `on_shutdown` handlers. Use one or the other, not both.
        Nz>Use either 'lifespan' or 'on_startup'/'on_shutdown', not both.)r#   r$   r%   )
r   r   stater   routerdictr"   listuser_middlewaremiddleware_stack)r   r   r    r!   r"   r#   r$   r%    r-   d/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/starlette/applications.py__init__   s    &zStarlette.__init__r   )r&   c                 C  s   | j }d }i }| j D ]"\}}|dtfv r2|}q|||< qtt||dg| j tt||dg }| j}t	|D ] \}}	}
||g|	R i |
}qp|S )Ni  )handlerr   )handlersr   )
r   r"   items	Exceptionr   r   r+   r   r(   reversed)r   r   Zerror_handlerr"   keyvaluer!   appclsargskwargsr-   r-   r.   build_middleware_stackO   s"    
z Starlette.build_middleware_stackzlist[BaseRoute]c                 C  s   | j jS N)r(   r    r   r-   r-   r.   r    e   s    zStarlette.routesstrz
typing.Anyr   )namepath_paramsr&   c                K  s   | j j|fi |S r<   )r(   url_path_for)r   r?   r@   r-   r-   r.   rA   i   s    zStarlette.url_path_forr   r   r   )scopereceivesendr&   c                   s4   | |d< | j d u r|  | _ |  |||I d H  d S )Nr7   )r,   r;   )r   rB   rC   rD   r-   r-   r.   __call__l   s    

zStarlette.__call__typing.Callable)
event_typer&   c                 C  s   | j |S r<   )r(   on_event)r   rG   r-   r-   r.   rH   r   s    zStarlette.on_eventz
str | None)pathr7   r?   r&   c                 C  s   | j j|||d d S N)r7   r?   )r(   mount)r   rI   r7   r?   r-   r-   r.   rK   u   s    zStarlette.mount)hostr7   r?   r&   c                 C  s   | j j|||d d S rJ   )r(   rL   )r   rL   r7   r?   r-   r-   r.   rL   x   s    zStarlette.hostz_MiddlewareFactory[P]zP.argszP.kwargs)middleware_classr9   r:   r&   c                 O  s6   | j d urtd| jdt|g|R i | d S )Nz6Cannot add middleware after an application has startedr   )r,   RuntimeErrorr+   insertr   )r   rM   r9   r:   r-   r-   r.   add_middleware{   s    
zStarlette.add_middlewarezint | type[Exception]r   )exc_class_or_status_coder0   r&   c                 C  s   || j |< d S r<   )r"   )r   rQ   r0   r-   r-   r.   add_exception_handler   s    zStarlette.add_exception_handler)rG   funcr&   c                 C  s   | j || d S r<   )r(   add_event_handler)r   rG   rS   r-   r-   r.   rT      s    zStarlette.add_event_handlerTzAtyping.Callable[[Request], typing.Awaitable[Response] | Response]zlist[str] | None)rI   routemethodsr?   include_in_schemar&   c                 C  s   | j j|||||d d S N)rV   r?   rW   r(   	add_route)r   rI   rU   rV   r?   rW   r-   r-   r.   rZ      s    zStarlette.add_routez4typing.Callable[[WebSocket], typing.Awaitable[None]])rI   rU   r?   r&   c                 C  s   | j j|||d d S N)r?   r(   add_websocket_route)r   rI   rU   r?   r-   r-   r.   r]      s    zStarlette.add_websocket_route)rQ   r&   c                   s&   t dt ddd fdd}|S )NzThe `exception_handler` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/exceptions/ for the recommended approach.rF   rS   r&   c                   s     |  | S r<   )rR   rS   rQ   r   r-   r.   	decorator   s    z.Starlette.exception_handler.<locals>.decoratorwarningswarnDeprecationWarning)r   rQ   ra   r-   r`   r.   exception_handler   s    zStarlette.exception_handler)rI   rV   r?   rW   r&   c                   s,   t dt ddd fdd}|S )z
        We no longer document this decorator style API, and its usage is discouraged.
        Instead you should use the following approach:

        >>> routes = [Route(path, endpoint=...), ...]
        >>> app = Starlette(routes=routes)
        zThe `route` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/routing/ for the recommended approach.rF   r^   c                   s   j j|  d | S rX   rY   r_   rW   rV   r?   rI   r   r-   r.   ra      s    z"Starlette.route.<locals>.decoratorrb   )r   rI   rV   r?   rW   ra   r-   rg   r.   rU      s    
zStarlette.route)rI   r?   r&   c                   s(   t dt ddd fdd}|S )a  
        We no longer document this decorator style API, and its usage is discouraged.
        Instead you should use the following approach:

        >>> routes = [WebSocketRoute(path, endpoint=...), ...]
        >>> app = Starlette(routes=routes)
        zThe `websocket_route` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/routing/#websocket-routing for the recommended approach.rF   r^   c                   s   j j|  d | S r[   r\   r_   r?   rI   r   r-   r.   ra      s    z,Starlette.websocket_route.<locals>.decoratorrb   )r   rI   r?   ra   r-   rh   r.   websocket_route   s    zStarlette.websocket_route)middleware_typer&   c                   s4   t dt |dksJ dddd fdd}|S )z
        We no longer document this decorator style API, and its usage is discouraged.
        Instead you should use the following approach:

        >>> middleware = [Middleware(...), ...]
        >>> app = Starlette(middleware=middleware)
        zThe `middleware` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/middleware/#using-middleware for recommended approach.httpz/Currently only middleware("http") is supported.rF   r^   c                   s    j t| d | S )N)dispatch)rP   r
   r_   r=   r-   r.   ra      s    z'Starlette.middleware.<locals>.decoratorrb   )r   rj   ra   r-   r=   r.   r!      s    zStarlette.middleware)FNNNNNN)N)N)NNT)N)NNT)N)__name__
__module____qualname____doc__r/   r;   propertyr    rA   rE   rH   rK   rL   rP   rR   rT   rZ   r]   rf   rU   ri   r!   r-   r-   r-   r.   r      sB           1
        )(
__future__r   systypingrc   version_infor   Ztyping_extensionsZstarlette.datastructuresr   r   Zstarlette.middlewarer   r	   Zstarlette.middleware.baser
   Zstarlette.middleware.errorsr   Zstarlette.middleware.exceptionsr   Zstarlette.requestsr   Zstarlette.responsesr   Zstarlette.routingr   r   Zstarlette.typesr   r   r   r   r   r   Zstarlette.websocketsr   TypeVarr   r   r   r-   r-   r-   r.   <module>   s&   
 