
    vh)                    P   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      Z+ ed      Z, G d d      Z-y)    )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                  L   e Zd ZdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZedd       ZddZddZ	ddZ
ddd	Zddd
Z	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 d dZ	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d"dZ	 d	 	 	 	 	 	 	 d#dZd$dZ	 	 	 d!	 	 	 	 	 	 	 	 	 d%dZdd&dZd'dZy)(r    z!Creates an Starlette application.Nc                    |||J d       || _         t               | _        t        ||||      | _        |i n
t        |      | _        |g n
t        |      | _        d| _	        y)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.)
on_startupon_shutdownlifespan)
debugr   stater   routerdictexception_handlerslistuser_middlewaremiddleware_stack)selfr(   routes
middlewarer,   r%   r&   r'   s           N/var/www/html/luna/venv/lib/python3.12/site-packages/starlette/applications.py__init__zStarlette.__init__   s{    L J$6;;N 	
L	
O 
W
V
^fg(:(B"M_H`%/%7rT*=M04    c                N   | j                   }d }i }| j                  j                         D ]  \  }}|dt        fv r|}|||<    t	        t
        ||      g| j                  z   t	        t        ||      gz   }| j                  }t        |      D ]  \  }}	}
 ||g|	i |
} |S )Ni  )handlerr(   )handlersr(   )
r(   r,   items	Exceptionr   r   r.   r   r*   reversed)r0   r(   error_handlerr,   keyvaluer2   appclsargskwargss              r3   build_middleware_stackz Starlette.build_middleware_stackP   s    

:<11779 	0JCsI&& %*/"3'		0 -}ERS""#-8JRWXYZ 	 kk!)*!5 	,Cvc+D+F+C	,
r5   c                .    | j                   j                  S N)r*   r1   )r0   s    r3   r1   zStarlette.routesf   s    {{!!!r5   c               <     | j                   j                  |fi |S rE   )r*   url_path_for)r0   namepath_paramss      r3   rG   zStarlette.url_path_forj   s    't{{''<<<r5   c                   K   | |d<   | j                   | j                         | _         | j                  |||       d {    y 7 w)Nr?   )r/   rC   )r0   scopereceivesends       r3   __call__zStarlette.__call__m   sD     e  ($($?$?$AD!##E7D999s   =AA Ac                8    | j                   j                  |      S rE   )r*   on_event)r0   
event_types     r3   rP   zStarlette.on_events   s    {{##J//r5   c                @    | j                   j                  |||       y N)r?   rH   )r*   mount)r0   pathr?   rH   s       r3   rT   zStarlette.mountv   s    $Cd3r5   c                @    | j                   j                  |||       y rS   )r*   host)r0   rW   r?   rH   s       r3   rW   zStarlette.hosty   s    3T2r5   c                    | j                   t        d      | j                  j                  dt	        |g|i |       y )Nz6Cannot add middleware after an application has startedr   )r/   RuntimeErrorr.   insertr   )r0   middleware_classrA   rB   s       r3   add_middlewarezStarlette.add_middleware|   sB       ,WXX##Az2B'TT'TV'TUr5   c                "    || j                   |<   y rE   )r,   )r0   exc_class_or_status_coder7   s      r3   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 89r5   c                <    | j                   j                  ||       y rE   )r*   add_event_handler)r0   rQ   funcs      r3   ra   zStarlette.add_event_handler   s    
 	%%j$7r5   c                D    | j                   j                  |||||       y N)methodsrH   include_in_schemar*   	add_route)r0   rU   routere   rH   rf   s         r3   rh   zStarlette.add_route   s"     	dE7Yjkr5   c                @    | j                   j                  |||       y N)rH   r*   add_websocket_route)r0   rU   ri   rH   s       r3   rm   zStarlette.add_websocket_route   s     	''e$'?r5   c                L     t        j                  dt               d f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.c                ,    j                  |        | S rE   )r_   )rb   r^   r0   s    r3   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FKr5   rb   r   returnr   warningswarnDeprecationWarning)r0   r^   rp   s   `` r3   exception_handlerzStarlette.exception_handler   s%    Z	
	 r5   c                X     t        j                  dt               d f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.c                H    j                   j                  |        | S rd   rg   )rb   rf   re   rH   rU   r0   s    r3   rp   z"Starlette.route.<locals>.decorator   s0    KK!!"3 "  Kr5   rq   rs   )r0   rU   re   rH   rf   rp   s   ````` r3   ri   zStarlette.route   s,     	W	
	 	 r5   c                P     t        j                  dt               d f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.c                D    j                   j                  |        | S rk   rl   )rb   rH   rU   r0   s    r3   rp   z,Starlette.websocket_route.<locals>.decorator   s!    KK++D$T+BKr5   rq   rs   )r0   rU   rH   rp   s   ``` r3   websocket_routezStarlette.websocket_route   s'     	i	
	 r5   c                `     t        j                  dt               |dk(  sJ d       d f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.c                6    j                  t        |        | S )N)dispatch)r\   r   )rb   r0   s    r3   rp   z'Starlette.middleware.<locals>.decorator   s     2TBKr5   rq   rs   )r0   middleware_typerp   s   `  r3   r2   zStarlette.middleware   s=     	g	

 &([*[[(	 r5   )FNNNNNN)r0   r   r(   boolr1   zSequence[BaseRoute] | Noner2   zSequence[Middleware] | Noner,   z%Mapping[Any, ExceptionHandler] | Noner%   "Sequence[Callable[[], Any]] | Noner&   r   r'   zLifespan[AppType] | Nonerr   None)rr   r   )rr   zlist[BaseRoute])rH   strrI   r   rr   r   )rK   r   rL   r   rM   r   rr   r   )rQ   r   rr   r   rE   )rU   r   r?   r   rH   
str | Nonerr   r   )rW   r   r?   r   rH   r   rr   r   )r[   z_MiddlewareFactory[P]rA   zP.argsrB   zP.kwargsrr   r   )r^   int | type[Exception]r7   r   rr   r   )rQ   r   rb   r   rr   r   )NNT)rU   r   ri   z3Callable[[Request], Awaitable[Response] | Response]re   list[str] | NonerH   r   rf   r   rr   r   )rU   r   ri   z&Callable[[WebSocket], Awaitable[None]]rH   r   rr   r   )r^   r   rr   r   )
rU   r   re   r   rH   r   rf   r   rr   r   )rU   r   rH   r   rr   r   )r   r   rr   r   )__name__
__module____qualname____doc__r4   rC   propertyr1   rG   rN   rP   rT   rW   r\   r_   ra   rh   rm   rw   ri   r|   r2    r5   r3   r    r       s   + -126DH9=:>-1/5/5/5 +/5 0	/5
 B/5 7/5 8/5 +/5 
/5b, " "=:043V/V V 	V
 
VD"7D "D 
	D88 8 
	8 %)"&ll Cl "	l
 l  l 
l  	@@ 6@ 	@
 
@  %)"& " 	
   
@(r5   ).
__future__r   sysrt   collections.abcr   r   r   typingr   r   r	   version_infor   typing_extensionsstarlette.datastructuresr   r   starlette.middlewarer   r   starlette.middleware.baser   starlette.middleware.errorsr   starlette.middleware.exceptionsr   starlette.requestsr   starlette.responsesr   starlette.routingr   r   starlette.typesr   r   r   r   r   r   starlette.websocketsr   r   r"   r    r   r5   r3   <module>r      sp    " 
  8 8 ) )w + 3 ? 8 = ? & ( / U U *
);
/cN^ ^r5   