
    }Oi&                         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  G d d          ZdS )    N)StateURLPath)
Middleware)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppReceiveScopeSendc                   P   e Zd ZdZ	 	 	 	 	 	 	 d3d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j        d gej        f                  ddfdZdefdZedej        e         fd            Zedefd            Zej        dedd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"	 d4dededej        e         ddfdZ#	 d4d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j(        e         f         d$ej        ddfd%Z)ded&ej        ddfd'Z*	 	 	 d5ded)ej        d*ej        ej        e                  dej        e         d+eddfd,Z+	 d4ded)ej        dej        e         ddfd-Z,d#ej        e'ej(        e         f         dej        fd.Z-	 	 	 d5ded*ej        ej        e                  dej        e         d+edej        f
d/Z.	 d4dedej        e         dej        fd0Z/d1edej        fd2Z0dS )6	Starletteah  
    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.
    FNdebugroutes
middlewareexception_handlers
on_startupon_shutdownlifespanreturnc                    |||
J d            || _         t                      | _        t          ||||          | _        |i nt          |          | _        |g nt          |          | _        | 	                                | _
        d S )Nz>Use either 'lifespan' or 'on_startup'/'on_shutdown', not both.)r   r   r   )_debugr   stater   routerdictr   listuser_middlewarebuild_middleware_stackmiddleware_stack)selfr   r   r   r   r   r   r   s           q/var/www/html/web/mlink/mlink_AI_Server/mlink-backend/venv/lib/python3.11/site-packages/starlette/applications.py__init__zStarlette.__init__)   s    , ;#6#6K $7#6
 WW
z{X
 
 
 %,BB$7I2J2J 	 &0%7rrT*=M=M $ ; ; = =    c                 >   | j         }d }i }| 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%   r"   z Starlette.build_middleware_stackN   s    
  	 17799 	0 	0JCsI&&& %*/"3'' -}ERRRS"# '2DE   	 k$Z00 	* 	*LC#))#)))CC
r'   c                     | j         j        S N)r   r   r$   s    r%   r   zStarlette.routesj   s    {!!r'   c                     | j         S r6   )r   r7   s    r%   r   zStarlette.debugn   s
    {r'   r2   c                 F    || _         |                                 | _        d S r6   )r   r"   r#   )r$   r2   s     r%   r   zStarlette.debugr   s#     $ ; ; = =r'   namepath_paramsc                 (     | j         j        |fi |S r6   )r   url_path_for)r$   r:   r;   s      r%   r=   zStarlette.url_path_forw   s    't{'<<<<<r'   scopereceivesendc                 N   K   | |d<   |                      |||           d {V  d S )Nr+   )r#   )r$   r>   r?   r@   s       r%   __call__zStarlette.__call__z   s?      e##E7D99999999999r'   
event_typec                 6    | j                             |          S r6   )r   on_event)r$   rC   s     r%   rE   zStarlette.on_event   s    {##J///r'   pathr+   c                 @    | j                             |||           dS )z
        We no longer document this API, and its usage is discouraged.
        Instead you should use the following approach:

        routes = [
            Mount(path, ...),
            ...
        ]

        app = Starlette(routes=routes)
        r+   r:   N)r   mount)r$   rF   r+   r:   s       r%   rI   zStarlette.mount   s'     	$Cd33333r'   hostc                 @    | j                             |||           dS )z
        We no longer document this API, and its usage is discouraged.
        Instead you should use the following approach:

        routes = [
            Host(path, ...),
            ...
        ]

        app = Starlette(routes=routes)
        rH   N)r   rJ   )r$   rJ   r+   r:   s       r%   rJ   zStarlette.host   s'     	3T22222r'   middleware_classr4   c                     | j                             dt          |fi |           |                                 | _        d S )Nr   )r!   insertr   r"   r#   )r$   rL   r4   s      r%   add_middlewarezStarlette.add_middleware   sH     	##Az2B'N'Ng'N'NOOO $ ; ; = =r'   exc_class_or_status_coder)   c                 L    || j         |<   |                                 | _        d S r6   )r   r"   r#   )r$   rP   r)   s      r%   add_exception_handlerzStarlette.add_exception_handler   s-    
 =D 89 $ ; ; = =r'   funcc                 <    | j                             ||           d S r6   )r   add_event_handler)r$   rC   rS   s      r%   rU   zStarlette.add_event_handler   s"     	%%j$77777r'   Troutemethodsinclude_in_schemac                 D    | j                             |||||           d S N)rW   r:   rX   r   	add_route)r$   rF   rV   rW   r:   rX   s         r%   r\   zStarlette.add_route   s9     	%tGX 	 	
 	
 	
 	
 	
r'   c                 @    | j                             |||           d S N)r:   r   add_websocket_route)r$   rF   rV   r:   s       r%   r`   zStarlette.add_websocket_route   s'     	''e$'?????r'   c                 H     dt           j        dt           j        f fd}|S )NrS   r   c                 4                         |            | S r6   )rR   )rS   rP   r$   s    r%   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FFFKr'   typingCallable)r$   rP   rc   s   `` r%   exception_handlerzStarlette.exception_handler   sA    	FO 	 	 	 	 	 	 	 	 r'   c                 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 = [
            Route(path, endpoint=..., ...),
            ...
        ]

        app = Starlette(routes=routes)
        rS   r   c                 F    j                             |            | S rZ   r[   )rS   rX   rW   r:   rF   r$   s    r%   rc   z"Starlette.route.<locals>.decorator   s8    K!!"3 "    Kr'   rd   )r$   rF   rW   r:   rX   rc   s   ````` r%   rV   zStarlette.route   sS    &	FO 	 	 	 	 	 	 	 	 	 	 	 r'   c                 L     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)
        rS   r   c                 B    j                             |            | S r^   r_   )rS   r:   rF   r$   s    r%   rc   z,Starlette.websocket_route.<locals>.decorator   s%    K++D$T+BBBKr'   rd   )r$   rF   r:   rc   s   ``` r%   websocket_routezStarlette.websocket_route   sG    	FO 	 	 	 	 	 	 	 	 	 r'   middleware_typec                 d     |dk    s
J d            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:

        middleware = [
            Middleware(...),
            ...
        ]

        app = Starlette(middleware=middleware)
        httpz/Currently only middleware("http") is supported.rS   r   c                 @                         t          |            | S )N)dispatch)rO   r   )rS   r$   s    r%   rc   z'Starlette.middleware.<locals>.decorator  s"     2TBBBKr'   rd   )r$   rm   rc   s   `  r%   r   zStarlette.middleware  sY     v%%%< &%%	FO 	 	 	 	 	 	 	 r'   )FNNNNNNr6   )NNT)1__name__
__module____qualname____doc__boolre   OptionalSequencer   r   MappingAnyrf   r	   r.   Unionr
   	AwaitableAsyncContextManagerr&   r   r"   propertyListr   r   setterstrr   r=   r   r   r   rB   rE   rI   rJ   typerO   intTyperR   rU   r\   r`   rg   rV   rl   r   r,   r'   r%   r   r      s_        8 >BCG HLIM %#> #>#> 	 :;#> OFOJ$?@	#>
 #ON
i(L6+;H+E!EFH
#> OFOFO$DE#> _V_V_%EF#>  /O[M6+EEF
!#>& 
'#> #> #> #>J    8 "I. " " " X" t    X \>4 >D > > > \>= =VZ =G = = = =:E :G :4 :D : : : :03 06? 0 0 0 0 EI4 44%4-3_S-A4	4 4 4 4$ EI3 33%3-3_S-A3	3 3 3 3"> $>17>	> > > >>"(,sFK	4J/J"K> > 
	> > > >88%+_8	8 8 8 8 6:%)"&

 



 

 S!12	


 oc"

  

 


 

 

 

 OS@ @@ &@7=s7K@	@ @ @ @
(.S&+i:P5P(Q	    6:%)"&  S!12 oc"	
   
   @ 7; %s3	   *# &/      r'   r   )re   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   r,   r'   r%   <module>r      s
    3 3 3 3 3 3 3 3 + + + + + + 8 8 8 8 8 8 = = = = = = ? ? ? ? ? ? & & & & & & ( ( ( ( ( ( / / / / / / / / 9 9 9 9 9 9 9 9 9 9 9 9M M M M M M M M M Mr'   