
    E2ik(                    (   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	m
Z
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*dS )    )annotationsN)	AwaitableCallableMappingSequence)Any	ParamSpecTypeVar)StateURLPath)
Middleware_MiddlewareFactory)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppExceptionHandlerLifespanReceiveScopeSend)	WebSocketAppType	Starlette)boundPc                      e Zd ZdZ	 	 	 	 	 	 	 dLdMdZdNdZedOd            ZdPdZdQd&Z	dRd)Z
dSdTd-ZdSdUd/ZdVd6ZdWd;ZdXd=Z	 	 	 dYdZdDZ	 dSd[dFZd\dGZ	 	 	 dYd]dHZdSd^dIZd_dKZdS )`r   z!Creates an Starlette application.FNselfr   debugboolroutesSequence[BaseRoute] | None
middlewareSequence[Middleware] | Noneexception_handlers%Mapping[Any, ExceptionHandler] | None
on_startup"Sequence[Callable[[], Any]] | Noneon_shutdownlifespanLifespan[AppType] | NonereturnNonec                    |||
J d            || _         t                      | _        t          ||||          | _        |i nt          |          | _        |g 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.   s           U/var/www/html/pixcura-vrs/venv/lib/python3.11/site-packages/starlette/applications.py__init__zStarlette.__init__   s    L J$6;;N;NL <O;N;N 
WW
V
^fggg(:(B""M_H`H`%/%7rrT*=M=M04    r   c                D   | j         }d }i }| j                                        D ]\  }}|dt          fv r|}|||<   t	          t
          ||          g| j        z   t	          t          ||          gz   }| j        }t          |          D ]\  }}	}
 ||g|	R i |
}|S )Ni  )handlerr#   )handlersr#   )
r#   r)   items	Exceptionr   r   r7   r   r4   reversed)r"   r#   error_handlerr)   keyvaluer'   appclsargskwargss              r9   build_middleware_stackz Starlette.build_middleware_stackJ   s    
:<17799 	0 	0JCsI&&& %*/"3'' -}ERRRS"#-8JRWXXXYZ 	 k!)*!5!5 	, 	,Cv#c+D+++F++CC
r;   list[BaseRoute]c                    | j         j        S N)r4   r%   )r"   s    r9   r%   zStarlette.routes`   s    {!!r;   namestrpath_paramsr   r   c               (     | j         j        |fi |S rL   )r4   url_path_for)r"   rM   rO   s      r9   rQ   zStarlette.url_path_ford   s    't{'<<<<<r;   scoper   receiver   sendr   c                   K   | |d<   | j         |                                 | _         |                      |||           d {V  d S )NrE   )r8   rI   )r"   rR   rS   rT   s       r9   __call__zStarlette.__call__g   s\      e ($($?$?$A$AD!##E7D99999999999r;   
event_typer   c                6    | j                             |          S rL   )r4   on_event)r"   rW   s     r9   rY   zStarlette.on_eventm   s    {##J///r;   pathrE   
str | Nonec                @    | j                             |||           d S N)rE   rM   )r4   mount)r"   rZ   rE   rM   s       r9   r^   zStarlette.mountp   s%    $Cd33333r;   hostc                @    | j                             |||           d S r]   )r4   r_   )r"   r_   rE   rM   s       r9   r_   zStarlette.hosts   s%    3T22222r;   middleware_class_MiddlewareFactory[P]rG   P.argsrH   P.kwargsc                    | j         t          d          | j                            dt	          |g|R i |           d S )Nz6Cannot add middleware after an application has startedr   )r8   RuntimeErrorr7   insertr   )r"   ra   rG   rH   s       r9   add_middlewarezStarlette.add_middlewarev   sT      ,WXXX##Az2B'TT'T'T'TV'T'TUUUUUr;   exc_class_or_status_codeint | type[Exception]r=   r   c                    || j         |<   d S rL   )r)   )r"   ri   r=   s      r9   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 8999r;   funcc                <    | j                             ||           d S rL   )r4   add_event_handler)r"   rW   rm   s      r9   ro   zStarlette.add_event_handler   s"    
 	%%j$77777r;   Troute3Callable[[Request], Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                D    | j                             |||||           d S N)rr   rM   rt   r4   	add_route)r"   rZ   rp   rr   rM   rt   s         r9   rx   zStarlette.add_route   s,     	dE7Yjkkkkkr;   &Callable[[WebSocket], Awaitable[None]]c                @    | j                             |||           d S N)rM   r4   add_websocket_route)r"   rZ   rp   rM   s       r9   r}   zStarlette.add_websocket_route   s'     	''e$'?????r;   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://starlette.dev/exceptions/ for the recommended approach.rm   r   r0   c                4                         |            | S rL   )rl   )rm   ri   r"   s    r9   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FFFKr;   rm   r   r0   r   warningswarnDeprecationWarning)r"   ri   r   s   `` r9   exception_handlerzStarlette.exception_handler   sL    W	
 	
 	
	 	 	 	 	 	 	 r;   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://starlette.dev/routing/ for the recommended approach.rm   r   r0   c                F    j                             |            | S rv   rw   )rm   rt   rr   rM   rZ   r"   s    r9   r   z"Starlette.route.<locals>.decorator   s8    K!!"3 "    Kr;   r   r   )r"   rZ   rr   rM   rt   r   s   ````` r9   rp   zStarlette.route   s`     	T	
 	
 	
	 	 	 	 	 	 	 	 	 	 r;   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://starlette.dev/routing/#websocket-routing for the recommended approach.rm   r   r0   c                B    j                             |            | S r{   r|   )rm   rM   rZ   r"   s    r9   r   z,Starlette.websocket_route.<locals>.decorator   s%    K++D$T+BBBKr;   r   r   )r"   rZ   rM   r   s   ``` r9   websocket_routezStarlette.websocket_route   sT     	f	
 	
 	
	 	 	 	 	 	 	 	 r;   middleware_typec                h     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://starlette.dev/middleware/#using-middleware for recommended approach.httpz/Currently only middleware("http") is supported.rm   r   r0   c                @                         t          |            | S )N)dispatch)rh   r   )rm   r"   s    r9   r   z'Starlette.middleware.<locals>.decorator   s"     2TBBBKr;   r   r   )r"   r   r   s   `  r9   r'   zStarlette.middleware   sd     	d	
 	
 	

 &(((*[(((	 	 	 	 	 	 r;   )FNNNNNN)r"   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r,   r.   r/   r0   r1   )r0   r   )r0   rJ   )rM   rN   rO   r   r0   r   )rR   r   rS   r   rT   r   r0   r1   )rW   rN   r0   r   rL   )rZ   rN   rE   r   rM   r[   r0   r1   )r_   rN   rE   r   rM   r[   r0   r1   )ra   rb   rG   rc   rH   rd   r0   r1   )ri   rj   r=   r   r0   r1   )rW   rN   rm   r   r0   r1   )NNT)rZ   rN   rp   rq   rr   rs   rM   r[   rt   r$   r0   r1   )rZ   rN   rp   ry   rM   r[   r0   r1   )ri   rj   r0   r   )
rZ   rN   rr   rs   rM   r[   rt   r$   r0   r   )rZ   rN   rM   r[   r0   r   )r   rN   r0   r   )__name__
__module____qualname____doc__r:   rI   propertyr%   rQ   rV   rY   r^   r_   rh   rl   ro   rx   r}   r   rp   r   r'    r;   r9   r   r      s       ++ -126DH9=:>-1/5 /5 /5 /5 /5b   , " " " X"= = = =: : : :0 0 0 04 4 4 4 43 3 3 3 3V V V VD D D D8 8 8 8 %)"&l l l l l  	@ @ @ @ @     %)"&    @    (     r;   )+
__future__r   r   collections.abcr   r   r   r   typingr   r	   r
   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   r;   r9   <module>r      s   " " " " " "  B B B B B B B B B B B B * * * * * * * * * * 3 3 3 3 3 3 3 3 ? ? ? ? ? ? ? ? 8 8 8 8 8 8 = = = = = = ? ? ? ? ? ? & & & & & & ( ( ( ( ( ( / / / / / / / / U U U U U U U U U U U U U U U U * * * * * *
');
/
/
/IcNN^ ^ ^ ^ ^ ^ ^ ^ ^ ^r;   