
    9Cg(                    F   d dl mZ d dlZd dlZd dl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j$        dd          Z% ed          Z& G d d          Z'dS )    )annotationsN)   
   )	ParamSpec)StateURLPath)
Middleware_MiddlewareClass)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   aC  
    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 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.
    FNselfr   debugboolroutes!typing.Sequence[BaseRoute] | None
middleware"typing.Sequence[Middleware] | Noneexception_handlers3typing.Mapping[typing.Any, ExceptionHandler] | None
on_startup7typing.Sequence[typing.Callable[[], typing.Any]] | Noneon_shutdownlifespanLifespan[AppType] | NonereturnNonec                    |||
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           H/var/www/api/venv/lib/python3.11/site-packages/starlette/applications.py__init__zStarlette.__init__9   s     ;#6#6K $7#6#6 
WW
V
^fggg(:(B""M_H`H`%/%7rrT*=M=M04    r   c                @   | j         }d }i }| j                                        D ]\  }}|dt          fv r|}|||<   t	          t
          ||          g| j        z   t	          t          ||          gz   }| j        }t          |          D ]\  }}	}
 ||	d|i|
}|S )Ni  )handlerr   )handlersr   app)
r   r%   items	Exceptionr	   r   r3   r   r0   reversed)r   r   error_handlerr%   keyvaluer#   r;   clsargskwargss              r5   build_middleware_stackz Starlette.build_middleware_stackP   s    
`b17799 	0 	0JCsI&&& %*/"3'' -}ERRRS"#-8JRWXXXYZ 	 k!)*!5!5 	0 	0Cv#/#///CC
r7   list[BaseRoute]c                    | j         j        S N)r0   r!   )r   s    r5   r!   zStarlette.routesf   s    {!!r7   namestrpath_params
typing.Anyr   c               (     | j         j        |fi |S rH   )r0   url_path_for)r   rI   rK   s      r5   rN   zStarlette.url_path_forj   s    't{'<<<<<r7   scoper   receiver   sendr   c                   K   | |d<   | j         |                                 | _         |                      |||           d {V  d S )Nr;   )r4   rE   )r   rO   rP   rQ   s       r5   __call__zStarlette.__call__m   s\      e ($($?$?$A$AD!##E7D99999999999r7   
event_typetyping.Callablec                6    | j                             |          S rH   )r0   on_event)r   rT   s     r5   rW   zStarlette.on_events   s    {##J///r7   pathr;   
str | Nonec                @    | j                             |||           d S N)r;   rI   )r0   mount)r   rX   r;   rI   s       r5   r\   zStarlette.mountv   s%    $Cd33333r7   hostc                @    | j                             |||           d S r[   )r0   r]   )r   r]   r;   rI   s       r5   r]   zStarlette.hosty   s%    3T22222r7   middleware_classtype[_MiddlewareClass[P]]rC   P.argsrD   P.kwargsc                    | j         t          d          | j                            dt	          |g|R i |           d S )Nz6Cannot add middleware after an application has startedr   )r4   RuntimeErrorr3   insertr	   )r   r_   rC   rD   s       r5   add_middlewarezStarlette.add_middleware|   sT      ,WXXX##Az2B'TT'T'T'TV'T'TUUUUUr7   exc_class_or_status_codeint | type[Exception]r9   r   c                    || j         |<   d S rH   )r%   )r   rg   r9   s      r5   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 8999r7   funcc                <    | j                             ||           d S rH   )r0   add_event_handler)r   rT   rk   s      r5   rm   zStarlette.add_event_handler   s"    
 	%%j$77777r7   TrouteAtyping.Callable[[Request], typing.Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                D    | j                             |||||           d S N)rp   rI   rr   r0   	add_route)r   rX   rn   rp   rI   rr   s         r5   rv   zStarlette.add_route   s,     	dE7Yjkkkkkr7   4typing.Callable[[WebSocket], typing.Awaitable[None]]c                @    | j                             |||           d S N)rI   r0   add_websocket_route)r   rX   rn   rI   s       r5   r{   zStarlette.add_websocket_route   s'     	''e$'?????r7   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.rk   rU   r,   c                4                         |            | S rH   )rj   )rk   rg   r   s    r5   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FFFKr7   rk   rU   r,   rU   warningswarnDeprecationWarning)r   rg   r~   s   `` r5   exception_handlerzStarlette.exception_handler   sL    Z	
 	
 	
	 	 	 	 	 	 	 r7   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.rk   rU   r,   c                F    j                             |            | S rt   ru   )rk   rr   rp   rI   rX   r   s    r5   r~   z"Starlette.route.<locals>.decorator   s8    K!!"3 "    Kr7   r   r   )r   rX   rp   rI   rr   r~   s   ````` r5   rn   zStarlette.route   s`     	W	
 	
 	
	 	 	 	 	 	 	 	 	 	 r7   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.rk   rU   r,   c                B    j                             |            | S ry   rz   )rk   rI   rX   r   s    r5   r~   z,Starlette.websocket_route.<locals>.decorator   s%    K++D$T+BBBKr7   r   r   )r   rX   rI   r~   s   ``` r5   websocket_routezStarlette.websocket_route   sT     	i	
 	
 	
	 	 	 	 	 	 	 	 r7   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://www.starlette.io/middleware/#using-middleware for recommended approach.httpz/Currently only middleware("http") is supported.rk   rU   r,   c                @                         t          |            | S )N)dispatch)rf   r   )rk   r   s    r5   r~   z'Starlette.middleware.<locals>.decorator   s"     2TBBBKr7   r   r   )r   r   r~   s   `  r5   r#   zStarlette.middleware   sd     	g	
 	
 	

 &(((*[(((	 	 	 	 	 	 r7   )FNNNNNN)r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r(   r*   r+   r,   r-   )r,   r   )r,   rF   )rI   rJ   rK   rL   r,   r   )rO   r   rP   r   rQ   r   r,   r-   )rT   rJ   r,   rU   rH   )rX   rJ   r;   r   rI   rY   r,   r-   )r]   rJ   r;   r   rI   rY   r,   r-   )r_   r`   rC   ra   rD   rb   r,   r-   )rg   rh   r9   r   r,   r-   )rT   rJ   rk   rU   r,   r-   )NNT)rX   rJ   rn   ro   rp   rq   rI   rY   rr   r    r,   r-   )rX   rJ   rn   rw   rI   rY   r,   r-   )rg   rh   r,   rU   )
rX   rJ   rp   rq   rI   rY   rr   r    r,   rU   )rX   rJ   rI   rY   r,   rU   )r   rJ   r,   rU   )__name__
__module____qualname____doc__r6   rE   propertyr!   rN   rS   rW   r\   r]   rf   rj   rm   rv   r{   r   rn   r   r#    r7   r5   r   r      s        > 489=RVNROS-15 5 5 5 5.   , " " " 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  	@ @ @ @ @     %)"&    @    (     r7   )(
__future__r   systypingr   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   TypeVarr   r   r   r   r7   r5   <module>r      s   " " " " " " 



  w       ++++++ 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 * * * * * *
&.+
6
6
6IcNN_ _ _ _ _ _ _ _ _ _r7   