
    6i                        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mZ d dlmZmZmZm Z m!Z!m"Z"  e
dd      Z# e	d      Z$ G d d      Z%y)    )annotations)	AwaitableCallableMappingSequence)Any	ParamSpecTypeVar)StateURLPath)
Middleware_MiddlewareFactory)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppExceptionHandlerLifespanReceiveScopeSendAppType	Starlette)boundPc                      e Zd ZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZedd       ZddZddZ	dddZ
ddd	Zdd
Z	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZy)r   z!Creates an Starlette application.Nc                    || _         t               | _        t        ||      | _        |i n
t        |      | _        |g n
t        |      | _        d| _	        y)aA  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.
        )lifespanN)
debugr   stater   routerdictexception_handlerslistuser_middlewaremiddleware_stack)selfr"   routes
middlewarer&   r!   s         I/var/www/files/kim/lib/python3.12/site-packages/starlette/applications.py__init__zStarlette.__init__   sS    8 
W
Vh7(:(B"M_H`%/%7rT*=M04    c                N   | j                   }d }i }| j                  j                         D ]  \  }}|dt        fv r|}|||<    t	        t
        ||      g| j                  z   t	        t        ||      gz   }| j                  }t        |      D ]  \  }}	}
 ||g|	i |
} |S )Ni  )handlerr"   )handlersr"   )
r"   r&   items	Exceptionr   r   r(   r   r$   reversed)r*   r"   error_handlerr&   keyvaluer,   appclsargskwargss              r-   build_middleware_stackz Starlette.build_middleware_stack9   s    

:<11779 	0JCsI&& %*/"3'		0 -}ERS""#-8JRWXYZ 	 kk!)*!5 	,Cvc+D+F+C	,
r/   c                .    | j                   j                  S N)r$   r+   )r*   s    r-   r+   zStarlette.routesO   s    {{!!!r/   c               <     | j                   j                  |fi |S r?   )r$   url_path_for)r*   namepath_paramss      r-   rA   zStarlette.url_path_forS   s    't{{''<<<r/   c                   K   | |d<   | j                   | j                         | _         | j                  |||       d {    y 7 w)Nr9   )r)   r=   )r*   scopereceivesends       r-   __call__zStarlette.__call__V   sD     e  ($($?$?$AD!##E7D999s   =AA Ac                @    | j                   j                  |||       y N)r9   rB   )r$   mount)r*   pathr9   rB   s       r-   rK   zStarlette.mount\   s    $Cd3r/   c                @    | j                   j                  |||       y rJ   )r$   host)r*   rN   r9   rB   s       r-   rN   zStarlette.host_   s    3T2r/   c                    | j                   t        d      | j                  j                  dt	        |g|i |       y )Nz6Cannot add middleware after an application has startedr   )r)   RuntimeErrorr(   insertr   )r*   middleware_classr;   r<   s       r-   add_middlewarezStarlette.add_middlewareb   s@      ,WXX##Az2B'TT'TV'TUr/   c                "    || j                   |<   y r?   )r&   )r*   exc_class_or_status_coder1   s      r-   add_exception_handlerzStarlette.add_exception_handlerg   s    
 =D 89r/   c                D    | j                   j                  |||||       y )N)methodsrB   include_in_schema)r$   	add_route)r*   rL   routerX   rB   rY   s         r-   rZ   zStarlette.add_routen   s"     	dE7Yjkr/   )FNNNN)r*   r   r"   boolr+   zSequence[BaseRoute] | Noner,   zSequence[Middleware] | Noner&   z%Mapping[Any, ExceptionHandler] | Noner!   zLifespan[AppType] | NonereturnNone)r]   r   )r]   zlist[BaseRoute])rB   strrC   r   r]   r   )rE   r   rF   r   rG   r   r]   r^   r?   )rL   r_   r9   r   rB   
str | Noner]   r^   )rN   r_   r9   r   rB   r`   r]   r^   )rR   z_MiddlewareFactory[P]r;   zP.argsr<   zP.kwargsr]   r^   )rU   zint | type[Exception]r1   r   r]   r^   )NNT)rL   r_   r[   z3Callable[[Request], Awaitable[Response] | Response]rX   zlist[str] | NonerB   r`   rY   r\   r]   r^   )__name__
__module____qualname____doc__r.   r=   propertyr+   rA   rH   rK   rN   rS   rV   rZ    r/   r-   r   r      s	   + -126DH-1!5!5!5 +!5 0	!5
 B!5 +!5 
!5F, " "=:43V
D"7D "D 
	D %)"&ll Cl "	l
 l  l 
lr/   N)&
__future__r   collections.abcr   r   r   r   typingr   r	   r
   starlette.datastructuresr   r   starlette.middlewarer   r   starlette.middleware.errorsr   starlette.middleware.exceptionsr   starlette.requestsr   starlette.responsesr   starlette.routingr   r   starlette.typesr   r   r   r   r   r   r   r   r   rf   r/   r-   <module>rr      sR    " B B * * 3 ? = ? & ( / U U
);
/cNcl clr/   