a
    h)                     @  s&  d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	m
Z
m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dddZ+edZ,G dd dZ-dS )    )annotationsN)	AwaitableMappingSequence)AnyCallableTypeVar)   
   )	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Sequence[BaseRoute] | NonezSequence[Middleware] | Nonez%Mapping[Any, ExceptionHandler] | Nonez"Sequence[Callable[[], 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+    r3   R/var/www/html/assistant/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   r1   r   r.   reversed)r$   r%   Zerror_handlerr(   keyvaluer'   appclsargskwargsr3   r3   r4   build_middleware_stackP   s"    
z Starlette.build_middleware_stackzlist[BaseRoute]c                 C  s   | j jS N)r.   r&   r$   r3   r3   r4   r&   f   s    zStarlette.routesstrr   r   )namepath_paramsr,   c                K  s   | j j|fi |S rB   )r.   url_path_for)r$   rE   rF   r3   r3   r4   rG   j   s    zStarlette.url_path_forr   r   r   )scopereceivesendr,   c                   s4   | |d< | j d u r|  | _ |  |||I d H  d S )Nr=   )r2   rA   )r$   rH   rI   rJ   r3   r3   r4   __call__m   s    

zStarlette.__call__r   )
event_typer,   c                 C  s   | j |S rB   )r.   on_event)r$   rL   r3   r3   r4   rM   s   s    zStarlette.on_eventz
str | None)pathr=   rE   r,   c                 C  s   | j j|||d d S N)r=   rE   )r.   mount)r$   rN   r=   rE   r3   r3   r4   rP   v   s    zStarlette.mount)hostr=   rE   r,   c                 C  s   | j j|||d d S rO   )r.   rQ   )r$   rQ   r=   rE   r3   r3   r4   rQ   y   s    zStarlette.hostz_MiddlewareFactory[P]zP.argszP.kwargs)middleware_classr?   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   )r2   RuntimeErrorr1   insertr   )r$   rR   r?   r@   r3   r3   r4   add_middleware|   s    
zStarlette.add_middlewarezint | type[Exception]r   )exc_class_or_status_coder6   r,   c                 C  s   || j |< d S rB   )r(   )r$   rV   r6   r3   r3   r4   add_exception_handler   s    zStarlette.add_exception_handler)rL   funcr,   c                 C  s   | j || d S rB   )r.   add_event_handler)r$   rL   rX   r3   r3   r4   rY      s    zStarlette.add_event_handlerTz3Callable[[Request], Awaitable[Response] | Response]zlist[str] | None)rN   routemethodsrE   include_in_schemar,   c                 C  s   | j j|||||d d S N)r[   rE   r\   r.   	add_route)r$   rN   rZ   r[   rE   r\   r3   r3   r4   r_      s    zStarlette.add_routez&Callable[[WebSocket], Awaitable[None]])rN   rZ   rE   r,   c                 C  s   | j j|||d d S N)rE   r.   add_websocket_route)r$   rN   rZ   rE   r3   r3   r4   rb      s    zStarlette.add_websocket_route)rV   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.r   rX   r,   c                   s     |  | S rB   )rW   rX   rV   r$   r3   r4   	decorator   s    z.Starlette.exception_handler.<locals>.decoratorwarningswarnDeprecationWarning)r$   rV   rf   r3   re   r4   exception_handler   s    zStarlette.exception_handler)rN   r[   rE   r\   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.r   rc   c                   s   j j|  d | S r]   r^   rd   r\   r[   rE   rN   r$   r3   r4   rf      s    z"Starlette.route.<locals>.decoratorrg   )r$   rN   r[   rE   r\   rf   r3   rl   r4   rZ      s    
zStarlette.route)rN   rE   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.r   rc   c                   s   j j|  d | S r`   ra   rd   rE   rN   r$   r3   r4   rf      s    z,Starlette.websocket_route.<locals>.decoratorrg   )r$   rN   rE   rf   r3   rm   r4   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.r   rc   c                   s    j t| d | S )N)dispatch)rU   r   rd   rC   r3   r4   rf      s    z'Starlette.middleware.<locals>.decoratorrg   )r$   ro   rf   r3   rC   r4   r'      s    zStarlette.middleware)FNNNNNN)N)N)NNT)N)NNT)N)__name__
__module____qualname____doc__r5   rA   propertyr&   rG   rK   rM   rP   rQ   rU   rW   rY   r_   rb   rk   rZ   rn   r'   r3   r3   r3   r4   r      sB           1
        ).
__future__r   sysrh   collections.abcr   r   r   typingr   r   r   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   r   r!   r   r3   r3   r3   r4   <module>   s(   
 