
    df)                         d dl Z d dl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 d d	lmZmZ d d
lmZmZmZmZmZ  e j4                  dd      Z G d d      Zy)    N)StateURLPath)
Middleware)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppLifespanReceiveScopeSendAppType	Starlette)boundc                      e Zd ZdZ	 	 	 	 	 	 	 d1dddedej                  ej                  e      dej                  ej                  e	      dej                  ej                  ej                  ej                  eegej                  eej"                  e   f   f   f      d	ej                  ej                  ej                        d
ej                  ej                  ej                        dej                  ed      ddfdZdefdZedej.                  e   fd       Zdedej                  defdZdedededdfdZdedej                  fdZ 	 d2dededej                  e   ddfdZ!	 d2dededej                  e   ddfdZ"de#d ej                  ddfd!Z$d"ej                  e%ejL                  e   f   d#ej                  ddfd$Z'ded%ej                  ddfd&Z(	 	 	 d3ded'ej                  d(ej                  ej.                  e      dej                  e   d)eddfd*Z)	 d2ded'ej                  dej                  e   ddfd+Z*d"ej                  e%ejL                  e   f   dej                  fd,Z+	 	 	 d3ded(ej                  ej.                  e      dej                  e   d)edej                  f
d-Z,	 d2dedej                  e   dej                  fd.Z-d/edej                  fd0Z.y)4r   aL  
    Creates an application instance.

    **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 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 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 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.
    Nselfr   debugroutes
middlewareexception_handlers
on_startupon_shutdownlifespanreturnc                     |||J d       || _         t               | _        t        ||||      | _        |i n
t        |      | _        |g n
t        |      | _        d | _	        y )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           O/home/api-vastappli/venv/lib/python3.12/site-packages/starlette/applications.py__init__zStarlette.__init__/   s    ( ;#6	LK	L 
W
z{X
 %,B$7I2J 	 &0%7rT*=M:>    c                 H   | j                   }d }i }| j                  j                         D ]  \  }}|dt        fv r|}|||<    t	        t
        ||      g| j                  z   t	        t        ||      gz   }| j                  }t        |      D ]  \  }}	 |dd|i|	} |S )Ni  )handlerr   )handlersr   app )
r   r   items	Exceptionr   r   r$   r   r!   reversed)
r   r   error_handlerr   keyvaluer   r,   clsoptionss
             r&   build_middleware_stackz Starlette.build_middleware_stackR   s    

  	 11779 	0JCsI&& %*/"3'		0 -}ERS""# '2DE 	 kk$Z0 	*LC)#))C	*
r(   c                 .    | j                   j                  S N)r!   r   )r   s    r&   r   zStarlette.routesn   s    {{!!!r(   _Starlette__namepath_paramsc                 <     | j                   j                  |fi |S r8   )r!   url_path_for)r   r9   r:   s      r&   r<   zStarlette.url_path_fors   s    't{{''>+>>r(   scopereceivesendc                    K   | |d<   | j                   | j                         | _         | j                  |||       d {    y 7 w)Nr,   )r%   r6   )r   r=   r>   r?   s       r&   __call__zStarlette.__call__v   sD     e  ($($?$?$AD!##E7D999s   =AA A
event_typec                 8    | j                   j                  |      S r8   )r!   on_event)r   rB   s     r&   rD   zStarlette.on_event|   s    {{##J//r(   pathr,   namec                 @    | j                   j                  |||       y N)r,   rF   )r!   mount)r   rE   r,   rF   s       r&   rI   zStarlette.mount   s     	$Cd3r(   hostc                 @    | j                   j                  |||       y rH   )r!   rJ   )r   rJ   r,   rF   s       r&   rJ   zStarlette.host   s     	3T2r(   middleware_classr5   c                 ~    | j                   t        d      | j                  j                  dt	        |fi |       y )Nz6Cannot add middleware after an application has startedr   )r%   RuntimeErrorr$   insertr   )r   rL   r5   s      r&   add_middlewarezStarlette.add_middleware   s;      ,WXX##Az2B'Ng'NOr(   exc_class_or_status_coder*   c                 "    || j                   |<   y r8   )r   )r   rQ   r*   s      r&   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 89r(   funcc                 <    | j                   j                  ||       y r8   )r!   add_event_handler)r   rB   rT   s      r&   rV   zStarlette.add_event_handler   s     	%%j$7r(   routemethodsinclude_in_schemac                 D    | j                   j                  |||||       y N)rX   rF   rY   r!   	add_route)r   rE   rW   rX   rF   rY   s         r&   r]   zStarlette.add_route   s'     	%tGX 	 	
r(   c                 @    | j                   j                  |||       y N)rF   r!   add_websocket_route)r   rE   rW   rF   s       r&   ra   zStarlette.add_websocket_route   s     	''e$'?r(   c                      t        j                  dt               dt        j                  dt        j                  f 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.rT   r   c                 ,    j                  |        | S r8   )rS   )rT   rQ   r   s    r&   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FKr(   warningswarnDeprecationWarningtypingCallable)r   rQ   rd   s   `` r&   exception_handlerzStarlette.exception_handler   s=     	Z	
	FOO 	 	 r(   c                      t        j                  dt               dt        j                  dt        j                  f 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.rT   r   c                 H    j                   j                  |        | S r[   r\   )rT   rY   rX   rF   rE   r   s    r&   rd   z"Starlette.route.<locals>.decorator   s0    KK!!"3 "  Kr(   re   )r   rE   rX   rF   rY   rd   s   ````` r&   rW   zStarlette.route   sB     	W	
	FOO 	 	 	 r(   c                      t        j                  dt               dt        j                  dt        j                  f 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.rT   r   c                 D    j                   j                  |        | S r_   r`   )rT   rF   rE   r   s    r&   rd   z,Starlette.websocket_route.<locals>.decorator   s!    KK++D$T+BKr(   re   )r   rE   rF   rd   s   ``` r&   websocket_routezStarlette.websocket_route   s=     	i	
	FOO 	 	 r(   middleware_typec                      t        j                  dt               |dk(  sJ d       dt        j                  dt        j                  f 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.rT   r   c                 6    j                  t        |        | S )N)dispatch)rP   r   )rT   r   s    r&   rd   z'Starlette.middleware.<locals>.decorator  s     2TBKr(   re   )r   rq   rd   s   `  r&   r   zStarlette.middleware   sT     	g	
 v%	=<	=	FOO 	 	 r(   )FNNNNNNr8   )NNT)/__name__
__module____qualname____doc__boolri   OptionalSequencer   r   MappingAnyrj   r	   r/   Unionr
   	Awaitabler   r'   r   r6   propertyListr   strr   r<   r   r   r   rA   rD   rI   rJ   typerP   intTyperS   rV   r]   ra   rk   rW   rp   r   r-   r(   r&   r   r      s!   > >BCG HLIM9=!!?!?!? 	 :;!? OOFOOJ$?@	!?
 #OONN

i(LL6+;+;H+E!EFH
!? OOFOOFOO$DE!? __V__V__%EF!?  //(9"56!!?" 
#!?F 8 "I. " "?3 ?vzz ?g ?:E :G :4 :D :03 06?? 0 EI44%4-3__S-A4	4 EI33%3-3__S-A3	3
Pt P

 Pt P
D"(,,sFKK	4J/J"KD D 
	D88%+__8	8 6:%)"&



 

 S!12	


 ooc"

  

 


 OS@@ &@7=s7K@	@
(.S&++i:P5P(Q	$ 6:%)"& S!12 ooc"	
   
B 7;%s3	,# &// r(   )ri   rf   starlette.datastructuresr   r   starlette.middlewarer   starlette.middleware.baser   starlette.middleware.errorsr   starlette.middleware.exceptionsr   starlette.requestsr	   starlette.responsesr
   starlette.routingr   r   starlette.typesr   r   r   r   r   TypeVarr   r   r-   r(   r&   <module>r      sG      3 + 8 = ? & ( / C C
&..+
6t tr(   