o
    j                     @  s   d dl m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$ e
dddZ%e	dZ&G dd dZ'dS )    )annotations)	AwaitableCallableMappingSequence)Any	ParamSpecTypeVar)StateURLPath)
Middleware_MiddlewareFactory)RequestBodyLimitMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppExceptionHandlerLifespanReceiveScopeSendAppType	Starlette)boundPc                   @  s   e Zd ZdZ					dJdddKddZdLddZedMddZdNd"d#ZdOd*d+Z	dPdQd/d0Z
dPdRd2d3ZdSd:d;ZdTd@dAZ			BdUdVdHdIZdS )Wr   z!Creates an Starlette application.FNmax_body_sizeselfr   debugboolroutesSequence[BaseRoute] | None
middlewareSequence[Middleware] | Noneexception_handlers%Mapping[Any, ExceptionHandler] | NonelifespanLifespan[AppType] | Noner    
int | NonereturnNonec                C  sX   || _ t | _t||d| _|| _|du ri nt|| _|du r"g 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.
            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.
            max_body_size: Non-negative maximum total size in bytes of an HTTP request
                body. The default, `None`, does not limit request body size.
        )r*   N)r"   r
   stater   routerr    dictr(   listuser_middlewaremiddleware_stack)r!   r"   r$   r&   r(   r*   r     r5   T/home/djax/ivt_ai_plugin/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d ur5|tt| jd || j	7 }|tt
||d | j}t|D ]\}}	}
||g|	R i |
}qK|S )Ni  )handlerr"   r   )handlersr"   )r"   r(   items	Exceptionr   r   r    appendr   r3   r   r0   reversed)r!   r"   error_handlerr(   keyvaluer&   appclsargskwargsr5   r5   r6   build_middleware_stack?   s    


z Starlette.build_middleware_stacklist[BaseRoute]c                 C  s   | j jS N)r0   r$   )r!   r5   r5   r6   r$   U   s   zStarlette.routesnamestrpath_paramsr   r   c                K  s   | j j|fi |S rG   )r0   url_path_for)r!   rH   rJ   r5   r5   r6   rK   Y   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )NrA   )r4   rE   )r!   rL   rM   rN   r5   r5   r6   __call__\   s
   

zStarlette.__call__pathrA   
str | Nonec                 C     | j j|||d d S N)rA   rH   )r0   mount)r!   rP   rA   rH   r5   r5   r6   rT   b      zStarlette.mounthostc                 C  rR   rS   )r0   rV   )r!   rV   rA   rH   r5   r5   r6   rV   e   rU   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   )r4   RuntimeErrorr3   insertr   )r!   rW   rC   rD   r5   r5   r6   add_middlewareh   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | type[Exception]r8   r   c                 C  s   || j |< d S rG   )r(   )r!   r^   r8   r5   r5   r6   add_exception_handlerm   s   zStarlette.add_exception_handlerTroute3Callable[[Request], Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                 C  s   | j j|||||d d S )N)rc   rH   re   )r0   	add_route)r!   rP   ra   rc   rH   re   r5   r5   r6   rf   t   s   zStarlette.add_route)FNNNN)r!   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r    r,   r-   r.   )r-   r   )r-   rF   )rH   rI   rJ   r   r-   r   )rL   r   rM   r   rN   r   r-   r.   rG   )rP   rI   rA   r   rH   rQ   r-   r.   )rV   rI   rA   r   rH   rQ   r-   r.   )rW   rX   rC   rY   rD   rZ   r-   r.   )r^   r_   r8   r   r-   r.   )NNT)rP   rI   ra   rb   rc   rd   rH   rQ   re   r#   r-   r.   )__name__
__module____qualname____doc__r7   rE   propertyr$   rK   rO   rT   rV   r]   r`   rf   r5   r5   r5   r6   r      s.    
(



N)(
__future__r   collections.abcr   r   r   r   typingr   r   r	   starlette.datastructuresr
   r   starlette.middlewarer   r   starlette.middleware.body_limitr   starlette.middleware.errorsr   starlette.middleware.exceptionsr   starlette.requestsr   starlette.responsesr   starlette.routingr   r   starlette.typesr   r   r   r   r   r   r   r   r   r5   r5   r5   r6   <module>   s     