o
    	+ik(                     @  s   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	m
Z
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dddZ(e
dZ)G dd dZ*dS )    )annotationsN)	AwaitableCallableMappingSequence)Any	ParamSpecTypeVar)StateURLPath)
Middleware_MiddlewareFactory)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   z!Creates an Starlette application.FNselfr   debugboolroutesSequence[BaseRoute] | None
middlewareSequence[Middleware] | Noneexception_handlers%Mapping[Any, ExceptionHandler] | None
on_startup"Sequence[Callable[[], 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 )a  Initializes the application.

        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.
        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,    r6   S/var/www/html/psymed-ai/venv/lib/python3.10/site-packages/starlette/applications.py__init__   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 ]\}}	}
||g|	R i |
}q8|S )Ni  )handlerr!   )handlersr!   )
r!   r'   items	Exceptionr   r   r4   r   r1   reversed)r    r!   error_handlerr'   keyvaluer%   appclsargskwargsr6   r6   r7   build_middleware_stackJ   s"   
z Starlette.build_middleware_stacklist[BaseRoute]c                 C  s   | j jS N)r1   r#   r    r6   r6   r7   r#   `   s   zStarlette.routesnamestrpath_paramsr   r   c                K  s   | j j|fi |S rG   )r1   url_path_for)r    rI   rK   r6   r6   r7   rL   d   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )NrA   )r5   rE   )r    rM   rN   rO   r6   r6   r7   __call__g   s
   

zStarlette.__call__
event_typer   c                 C  s   | j |S rG   )r1   on_event)r    rQ   r6   r6   r7   rR   m   s   zStarlette.on_eventpathrA   
str | Nonec                 C     | j j|||d d S N)rA   rI   )r1   mount)r    rS   rA   rI   r6   r6   r7   rW   p      zStarlette.mounthostc                 C  rU   rV   )r1   rY   )r    rY   rA   rI   r6   r6   r7   rY   s   rX   zStarlette.hostmiddleware_class_MiddlewareFactory[P]rC   P.argsrD   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   )r5   RuntimeErrorr4   insertr   )r    rZ   rC   rD   r6   r6   r7   add_middlewarev   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | type[Exception]r9   r   c                 C  s   || j |< d S rG   )r'   )r    ra   r9   r6   r6   r7   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C  s   | j || d S rG   )r1   add_event_handler)r    rQ   rd   r6   r6   r7   re      s   zStarlette.add_event_handlerTroute3Callable[[Request], Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                 C  s   | j j|||||d d S N)rh   rI   rj   r1   	add_route)r    rS   rf   rh   rI   rj   r6   r6   r7   rm      s   zStarlette.add_route&Callable[[WebSocket], Awaitable[None]]c                 C  rU   N)rI   r1   add_websocket_route)r    rS   rf   rI   r6   r6   r7   rq      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://starlette.dev/exceptions/ for the recommended approach.rd   r   r.   c                   s     |  | S rG   )rc   rd   ra   r    r6   r7   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorrd   r   r.   r   warningswarnDeprecationWarning)r    ra   rt   r6   rs   r7   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://starlette.dev/routing/ for the recommended approach.rd   r   r.   c                   s   j j|  d | S rk   rl   rr   rj   rh   rI   rS   r    r6   r7   rt      s   z"Starlette.route.<locals>.decoratorNru   rv   )r    rS   rh   rI   rj   rt   r6   r{   r7   rf      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://starlette.dev/routing/#websocket-routing for the recommended approach.rd   r   r.   c                   s   j j|  d | S ro   rp   rr   rI   rS   r    r6   r7   rt      s   z,Starlette.websocket_route.<locals>.decoratorNru   rv   )r    rS   rI   rt   r6   r|   r7   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://starlette.dev/middleware/#using-middleware for recommended approach.httpz/Currently only middleware("http") is supported.rd   r   r.   c                   s    j t| d | S )N)dispatch)r`   r   rr   rH   r6   r7   rt      s   z'Starlette.middleware.<locals>.decoratorNru   rv   )r    r~   rt   r6   rH   r7   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.   rF   )rI   rJ   rK   r   r.   r   )rM   r   rN   r   rO   r   r.   r/   )rQ   rJ   r.   r   rG   )rS   rJ   rA   r   rI   rT   r.   r/   )rY   rJ   rA   r   rI   rT   r.   r/   )rZ   r[   rC   r\   rD   r]   r.   r/   )ra   rb   r9   r   r.   r/   )rQ   rJ   rd   r   r.   r/   )NNT)rS   rJ   rf   rg   rh   ri   rI   rT   rj   r"   r.   r/   )rS   rJ   rf   rn   rI   rT   r.   r/   )ra   rb   r.   r   )
rS   rJ   rh   ri   rI   rT   rj   r"   r.   r   )rS   rJ   rI   rT   r.   r   )r~   rJ   r.   r   )__name__
__module____qualname____doc__r8   rE   propertyr#   rL   rP   rR   rW   rY   r`   rc   re   rm   rq   rz   rf   r}   r%   r6   r6   r6   r7   r      sD    
1







 )+
__future__r   rw   collections.abcr   r   r   r   typingr   r   r	   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   r   r   r   r6   r6   r6   r7   <module>   s"     