o
    Ci*                     @  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daddZedbddZdcd"d#Zddd*d+Z	ded.d/Z
dfdgd3d4Zdfdhd6d7Zdid>d?ZdjdDdEZdkdGdHZ			IdldmdPdQZ	dfdndSdTZdodUdVZ			IdldpdXdYZdfdqdZd[Zdrd]d^ZdS )sr   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self	'AppType'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$typing.Optional[Lifespan['AppType']]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)    r3   n/var/www/html/fyndo/python/python_agents/rag_suite/venv/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   r1   r   r.   reversed)r   r   error_handlerr$   keyvaluer"   r8   clsargskwargsr3   r3   r4   build_middleware_stackT   s*   

z Starlette.build_middleware_stacktyping.List[BaseRoute]c                 C  s   | j jS N)r.   r    r   r3   r3   r4   r    p   s   zStarlette.routesnamestrpath_params
typing.Anyr   c                K  s   | j j|fi |S rD   )r.   url_path_for)r   rF   rH   r3   r3   r4   rJ   t   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )Nr8   )r2   rB   )r   rK   rL   rM   r3   r3   r4   __call__w   s
   

zStarlette.__call__
event_typetyping.Callablec                 C  s   | j |S rD   )r.   on_event)r   rO   r3   r3   r4   rQ   }   s   zStarlette.on_eventpathr8   
str | Nonec                 C     | j j|||d d S N)r8   rF   )r.   mount)r   rR   r8   rF   r3   r3   r4   rV         zStarlette.mounthostc                 C  rT   rU   )r.   rX   )r   rX   r8   rF   r3   r3   r4   rX      rW   zStarlette.hostmiddleware_class typing.Type[_MiddlewareClass[P]]r@   P.argsrA   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   )r2   RuntimeErrorr1   insertr   )r   rY   r@   rA   r3   r3   r4   add_middleware   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | typing.Type[Exception]r6   r   c                 C  s   || j |< d S rD   )r$   )r   r`   r6   r3   r3   r4   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C  s   | j || d S rD   )r.   add_event_handler)r   rO   rc   r3   r3   r4   rd      s   zStarlette.add_event_handlerTrouteAtyping.Callable[[Request], typing.Awaitable[Response] | Response]methods!typing.Optional[typing.List[str]]typing.Optional[str]include_in_schemac                 C  s   | j j|||||d d S N)rg   rF   rj   r.   	add_route)r   rR   re   rg   rF   rj   r3   r3   r4   rm      s   

zStarlette.add_route4typing.Callable[[WebSocket], typing.Awaitable[None]]c                 C  rT   N)rF   r.   add_websocket_route)r   rR   re   rF   r3   r3   r4   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://www.starlette.io/exceptions/ for the recommended approach.rc   rP   r+   c                   s     |  | S rD   )rb   rc   r`   r   r3   r4   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorrc   rP   r+   rP   warningswarnDeprecationWarning)r   r`   rt   r3   rs   r4   exception_handler   s   zStarlette.exception_handlertyping.List[str] | Nonec                   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.rc   rP   r+   c                   s   j j|  d | S rk   rl   rr   rj   rg   rF   rR   r   r3   r4   rt      s   z"Starlette.route.<locals>.decoratorNru   rv   )r   rR   rg   rF   rj   rt   r3   r|   r4   re      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.rc   rP   r+   c                   s   j j|  d | S ro   rp   rr   rF   rR   r   r3   r4   rt      s   z,Starlette.websocket_route.<locals>.decoratorNru   rv   )r   rR   rF   rt   r3   r}   r4   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.rc   rP   r+   c                   s    j t| d | S )N)dispatch)r_   r
   rr   rE   r3   r4   rt     s   z'Starlette.middleware.<locals>.decoratorNru   rv   )r   r   rt   r3   rE   r4   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+   rC   )rF   rG   rH   rI   r+   r   )rK   r   rL   r   rM   r   r+   r,   )rO   rG   r+   rP   rD   )rR   rG   r8   r   rF   rS   r+   r,   )rX   rG   r8   r   rF   rS   r+   r,   )rY   rZ   r@   r[   rA   r\   r+   r,   )r`   ra   r6   r   r+   r,   )rO   rG   rc   rP   r+   r,   )NNT)rR   rG   re   rf   rg   rh   rF   ri   rj   r   r+   r,   )rR   rG   re   rn   rF   rS   r+   r,   )r`   ra   r+   rP   )
rR   rG   rg   r{   rF   rS   rj   r   r+   rP   )rR   rG   rF   rS   r+   rP   )r   rG   r+   rP   )__name__
__module____qualname____doc__r5   rB   propertyr    rJ   rN   rQ   rV   rX   r_   rb   rd   rm   rq   rz   re   r~   r"   r3   r3   r3   r4   r      sD    








 )(
__future__r   systypingrw   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   r3   r3   r3   r4   <module>   s(    
 