o
    tfN*                     @  s  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dZ%edZ&G d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                   @  s   e Zd ZdZ							d]d^ddZd_ddZed`ddZdad"d#Zdbd*d+Z	dcd.d/Z
ddded3d4Zdddfd6d7Zdgd>d?ZdhdDdEZdidGdHZ			IdjdkdOdPZ	dddldRdSZdmdTdUZ			IdjdndVdWZdddodXdYZdpd[d\ZdS )qr   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                 C  sv   |d u s|d u r|d u sJ d|| _ t | _t||||d| _|d u r&i nt|| _|d u r1g 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(    r2   _/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/starlette/applications.py__init__9   s   
zStarlette.__init__r   c                 C  s   | j }d }i }| j D ]\}}|dtfv r|}q|||< qtt||dg| j tt||dg }| j}t	|D ]\}}	}
||	d|i|
}q8|S )Ni  )handlerr   )handlersr   app)
r   r#   items	Exceptionr   r   r0   r   r-   reversed)r   r   Zerror_handlerr#   keyvaluer!   r7   clsargskwargsr2   r2   r3   build_middleware_stackT   s*   

z Starlette.build_middleware_stacklist[BaseRoute]c                 C  s   | j jS N)r-   r   r   r2   r2   r3   r   p   s   zStarlette.routesnamestrpath_params
typing.Anyr   c                K  s   | j j|fi |S rB   )r-   url_path_for)r   rD   rF   r2   r2   r3   rH   t   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )Nr7   )r1   r@   )r   rI   rJ   rK   r2   r2   r3   __call__w   s
   

zStarlette.__call__
event_typetyping.Callablec                 C  s   | j |S rB   )r-   on_event)r   rM   r2   r2   r3   rO   }   s   zStarlette.on_eventpathr7   
str | Nonec                 C     | j j|||d d S N)r7   rD   )r-   mount)r   rP   r7   rD   r2   r2   r3   rT         zStarlette.mounthostc                 C  rR   rS   )r-   rV   )r   rV   r7   rD   r2   r2   r3   rV      rU   zStarlette.hostmiddleware_classtype[_MiddlewareClass[P]]r>   P.argsr?   P.kwargsc                 O  s6   | j d ur	td| jdt|g|R i | d S )Nz6Cannot add middleware after an application has startedr   )r1   RuntimeErrorr0   insertr   )r   rW   r>   r?   r2   r2   r3   add_middleware   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | type[Exception]r5   r   c                 C  s   || j |< d S rB   )r#   )r   r^   r5   r2   r2   r3   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C  s   | j || d S rB   )r-   add_event_handler)r   rM   ra   r2   r2   r3   rb      s   zStarlette.add_event_handlerTrouteAtyping.Callable[[Request], typing.Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                 C  s   | j j|||||d d S N)re   rD   rg   r-   	add_route)r   rP   rc   re   rD   rg   r2   r2   r3   rj      s   

zStarlette.add_route4typing.Callable[[WebSocket], typing.Awaitable[None]]c                 C  rR   N)rD   r-   add_websocket_route)r   rP   rc   rD   r2   r2   r3   rn      s   zStarlette.add_websocket_routec                   s    t dt d fd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.ra   rN   r*   c                   s     |  | S rB   )r`   ra   r^   r   r2   r3   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorra   rN   r*   rN   warningswarnDeprecationWarning)r   r^   rq   r2   rp   r3   exception_handler   s   zStarlette.exception_handlerc                   s&   t dt d fd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.ra   rN   r*   c                   s   j j|  d | S rh   ri   ro   rg   re   rD   rP   r   r2   r3   rq      s   z"Starlette.route.<locals>.decoratorNrr   rs   )r   rP   re   rD   rg   rq   r2   rx   r3   rc      s   
zStarlette.routec                   s"   t dt d fd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.ra   rN   r*   c                   s   j j|  d | S rl   rm   ro   rD   rP   r   r2   r3   rq      s   z,Starlette.websocket_route.<locals>.decoratorNrr   rs   )r   rP   rD   rq   r2   ry   r3   websocket_route   s   zStarlette.websocket_routemiddleware_typec                   s.   t dt |dksJ dd
 fd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.ra   rN   r*   c                   s    j t| d | S )N)dispatch)r]   r
   ro   rC   r2   r3   rq     s   z'Starlette.middleware.<locals>.decoratorNrr   rs   )r   r{   rq   r2   rC   r3   r!      s   
zStarlette.middleware)FNNNNNN)r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r&   r(   r)   r*   r+   )r*   r   )r*   rA   )rD   rE   rF   rG   r*   r   )rI   r   rJ   r   rK   r   r*   r+   )rM   rE   r*   rN   rB   )rP   rE   r7   r   rD   rQ   r*   r+   )rV   rE   r7   r   rD   rQ   r*   r+   )rW   rX   r>   rY   r?   rZ   r*   r+   )r^   r_   r5   r   r*   r+   )rM   rE   ra   rN   r*   r+   )NNT)rP   rE   rc   rd   re   rf   rD   rQ   rg   r   r*   r+   )rP   rE   rc   rk   rD   rQ   r*   r+   )r^   r_   r*   rN   )
rP   rE   re   rf   rD   rQ   rg   r   r*   rN   )rP   rE   rD   rQ   r*   rN   )r{   rE   r*   rN   )__name__
__module____qualname____doc__r4   r@   propertyr   rH   rL   rO   rT   rV   r]   r`   rb   rj   rn   rw   rc   rz   r!   r2   r2   r2   r3   r      sD    








 )(
__future__r   systypingrt   version_infor   Ztyping_extensionsZstarlette.datastructuresr   r   Zstarlette.middlewarer   r	   Zstarlette.middleware.baser
   Zstarlette.middleware.errorsr   Zstarlette.middleware.exceptionsr   Zstarlette.requestsr   Zstarlette.responsesr   Zstarlette.routingr   r   Zstarlette.typesr   r   r   r   r   r   Zstarlette.websocketsr   TypeVarr   r   r   r2   r2   r2   r3   <module>   s(    
 