
    "d)                         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 j        dd          Z G d d          ZdS )    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	 	 	 	 	 	 	 d3d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 	 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Z.dS )6r   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.
    FNselfr   debugroutes
middlewareexception_handlers
on_startupon_shutdownlifespanreturnc                     |||
J d            || _         t                      | _        t          ||||          | _        |i nt          |          | _        |g nt          |          | _        d | _	        d S )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           :D:\api_v1\venv\Lib\site-packages\starlette/applications.py__init__zStarlette.__init__/   s    ( ;#6#6K $7#6#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&   build_middleware_stackz Starlette.build_middleware_stackR   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.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         |                                 | _         |                      |||           d {V  d S )Nr,   )r%   r6   )r   r=   r>   r?   s       r&   __call__zStarlette.__call__v   s\      e ($($?$?$A$AD!##E7D99999999999r(   
event_typec                 6    | j                             |          S r8   )r!   on_event)r   rB   s     r&   rD   zStarlette.on_event|   s    {##J///r(   pathr,   namec                 @    | j                             |||           d S N)r,   rF   )r!   mount)r   rE   r,   rF   s       r&   rI   zStarlette.mount   s'     	$Cd33333r(   hostc                 @    | j                             |||           d S rH   )r!   rJ   )r   rJ   r,   rF   s       r&   rJ   zStarlette.host   s'     	3T22222r(   middleware_classr5   c                 ~    | j         t          d          | j                            dt	          |fi |           d S )Nz6Cannot add middleware after an application has startedr   )r%   RuntimeErrorr$   insertr   )r   rL   r5   s      r&   add_middlewarezStarlette.add_middleware   sJ     ,WXXX##Az2B'N'Ng'N'NOOOOOr(   exc_class_or_status_coder*   c                     || j         |<   d S r8   )r   )r   rQ   r*   s      r&   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 8999r(   funcc                 <    | j                             ||           d S r8   )r!   add_event_handler)r   rB   rT   s      r&   rV   zStarlette.add_event_handler   s"     	%%j$77777r(   Troutemethodsinclude_in_schemac                 D    | j                             |||||           d S N)rX   rF   rY   r!   	add_route)r   rE   rW   rX   rF   rY   s         r&   r]   zStarlette.add_route   s9     	%tGX 	 	
 	
 	
 	
 	
r(   c                 @    | j                             |||           d S 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                 4                         |            | S r8   )rS   )rT   rQ   r   s    r&   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FFFKr(   warningswarnDeprecationWarningtypingCallable)r   rQ   rd   s   `` r&   exception_handlerzStarlette.exception_handler   s`     	Z	
 	
 	
	FO 	 	 	 	 	 	 	 	 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                 F    j                             |            | S r[   r\   )rT   rY   rX   rF   rE   r   s    r&   rd   z"Starlette.route.<locals>.decorator   s8    K!!"3 "    Kr(   re   )r   rE   rX   rF   rY   rd   s   ````` r&   rW   zStarlette.route   sr     	W	
 	
 	
	FO 	 	 	 	 	 	 	 	 	 	 	 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                 B    j                             |            | S r_   r`   )rT   rF   rE   r   s    r&   rd   z,Starlette.websocket_route.<locals>.decorator   s%    K++D$T+BBBKr(   re   )r   rE   rF   rd   s   ``` r&   websocket_routezStarlette.websocket_route   sf     	i	
 	
 	
	FO 	 	 	 	 	 	 	 	 	 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                 @                         t          |            | S )N)dispatch)rP   r   )rT   r   s    r&   rd   z'Starlette.middleware.<locals>.decorator  s"     2TBBBKr(   re   )r   rq   rd   s   `  r&   r   zStarlette.middleware   sx     	g	
 	
 	
 v%%%< &%%	FO 	 	 	 	 	 	 	 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=!!? !?!?!? 	 :;!? OFOJ$?@	!?
 #ON
i(L6+;H+E!EFH
!? OFOFO$DE!? _V_V_%EF!?  /(9"56!!?" 
#!? !? !? !?F    8 "I. " " " X"?3 ?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
Pt P
 Pt P P P P
D"(,sFK	4J/J"KD D 
	D D D D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"	
   
   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      s/     3 3 3 3 3 3 3 3 + + + + + + 8 8 8 8 8 8 = = = = = = ? ? ? ? ? ? & & & & & & ( ( ( ( ( ( / / / / / / / / C C C C C C C C C C C C C C
&.+
6
6
6t t t t t t t t t tr(   