
    }<ik(                       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      Z( e
d      Z) G d d      Z*y)    )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                  L   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Z
ddd	Zddd
Z	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 d dZ	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d"dZ	 d	 	 	 	 	 	 	 d#dZd$dZ	 	 	 d!	 	 	 	 	 	 	 	 	 d%dZdd&dZd'dZy)(r   z!Creates an Starlette application.Nc                    |||J d       || _         t               | _        t        ||||      | _        |i n
t        |      | _        |g n
t        |      | _        d| _	        y)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.)
on_startupon_shutdownlifespan)
debugr   stater   routerdictexception_handlerslistuser_middlewaremiddleware_stack)selfr&   routes
middlewarer*   r#   r$   r%   s           [/home/www/utuvibe.miabetepe.com/venv/lib/python3.12/site-packages/starlette/applications.py__init__zStarlette.__init__   s{    L J$6;;N 	
L	
O 
W
V
^fg(:(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valuer0   appclsargskwargss              r1   build_middleware_stackz Starlette.build_middleware_stackJ   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	,
r3   c                .    | j                   j                  S N)r(   r/   )r.   s    r1   r/   zStarlette.routes`   s    {{!!!r3   c               <     | j                   j                  |fi |S rC   )r(   url_path_for)r.   namepath_paramss      r1   rE   zStarlette.url_path_ford   s    't{{''<<<r3   c                   K   | |d<   | j                   | j                         | _         | j                  |||       d {    y 7 w)Nr=   )r-   rA   )r.   scopereceivesends       r1   __call__zStarlette.__call__g   sD     e  ($($?$?$AD!##E7D999s   =AA Ac                8    | j                   j                  |      S rC   )r(   on_event)r.   
event_types     r1   rN   zStarlette.on_eventm   s    {{##J//r3   c                @    | j                   j                  |||       y N)r=   rF   )r(   mount)r.   pathr=   rF   s       r1   rR   zStarlette.mountp   s    $Cd3r3   c                @    | j                   j                  |||       y rQ   )r(   host)r.   rU   r=   rF   s       r1   rU   zStarlette.hosts   s    3T2r3   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       r1   add_middlewarezStarlette.add_middlewarev   sB       ,WXX##Az2B'TT'TV'TUr3   c                "    || j                   |<   y rC   )r*   )r.   exc_class_or_status_coder5   s      r1   add_exception_handlerzStarlette.add_exception_handler   s    
 =D 89r3   c                <    | j                   j                  ||       y rC   )r(   add_event_handler)r.   rO   funcs      r1   r_   zStarlette.add_event_handler   s    
 	%%j$7r3   c                D    | j                   j                  |||||       y N)methodsrF   include_in_schemar(   	add_route)r.   rS   routerc   rF   rd   s         r1   rf   zStarlette.add_route   s"     	dE7Yjkr3   c                @    | j                   j                  |||       y N)rF   r(   add_websocket_route)r.   rS   rg   rF   s       r1   rk   zStarlette.add_websocket_route   s     	''e$'?r3   c                L     t        j                  dt               d f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.c                ,    j                  |        | S rC   )r]   )r`   r\   r.   s    r1   	decoratorz.Starlette.exception_handler.<locals>.decorator   s    &&'?FKr3   r`   r   returnr   warningswarnDeprecationWarning)r.   r\   rn   s   `` r1   exception_handlerzStarlette.exception_handler   s%    W	
	 r3   c                X     t        j                  dt               d f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.c                H    j                   j                  |        | S rb   re   )r`   rd   rc   rF   rS   r.   s    r1   rn   z"Starlette.route.<locals>.decorator   s0    KK!!"3 "  Kr3   ro   rq   )r.   rS   rc   rF   rd   rn   s   ````` r1   rg   zStarlette.route   s,     	T	
	 	 r3   c                P     t        j                  dt               d f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.c                D    j                   j                  |        | S ri   rj   )r`   rF   rS   r.   s    r1   rn   z,Starlette.websocket_route.<locals>.decorator   s!    KK++D$T+BKr3   ro   rq   )r.   rS   rF   rn   s   ``` r1   websocket_routezStarlette.websocket_route   s'     	f	
	 r3   c                `     t        j                  dt               |dk(  sJ d       d f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.c                6    j                  t        |        | S )N)dispatch)rZ   r   )r`   r.   s    r1   rn   z'Starlette.middleware.<locals>.decorator   s     2TBKr3   ro   rq   )r.   middleware_typern   s   `  r1   r0   zStarlette.middleware   s=     	d	

 &([*[[(	 r3   )FNNNNNN)r.   r   r&   boolr/   zSequence[BaseRoute] | Noner0   zSequence[Middleware] | Noner*   z%Mapping[Any, ExceptionHandler] | Noner#   "Sequence[Callable[[], Any]] | Noner$   r   r%   zLifespan[AppType] | Nonerp   None)rp   r   )rp   zlist[BaseRoute])rF   strrG   r   rp   r   )rI   r   rJ   r   rK   r   rp   r   )rO   r   rp   r   rC   )rS   r   r=   r   rF   
str | Nonerp   r   )rU   r   r=   r   rF   r   rp   r   )rY   z_MiddlewareFactory[P]r?   zP.argsr@   zP.kwargsrp   r   )r\   int | type[Exception]r5   r   rp   r   )rO   r   r`   r   rp   r   )NNT)rS   r   rg   z3Callable[[Request], Awaitable[Response] | Response]rc   list[str] | NonerF   r   rd   r   rp   r   )rS   r   rg   z&Callable[[WebSocket], Awaitable[None]]rF   r   rp   r   )r\   r   rp   r   )
rS   r   rc   r   rF   r   rd   r   rp   r   )rS   r   rF   r   rp   r   )r   r   rp   r   )__name__
__module____qualname____doc__r2   rA   propertyr/   rE   rL   rN   rR   rU   rZ   r]   r_   rf   rk   ru   rg   rz   r0    r3   r1   r   r      s   + -126DH9=:>-1/5/5/5 +/5 0	/5
 B/5 7/5 8/5 +/5 
/5b, " "=:043V/V V 	V
 
VD"7D "D 
	D88 8 
	8 %)"&ll Cl "	l
 l  l 
l  	@@ 6@ 	@
 
@  %)"& " 	
   
@(r3   )+
__future__r   rr   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   r   r3   r1   <module>r      sY    "  B B * * 3 ? 8 = ? & ( / U U *
);
/cN^ ^r3   