
    $j                        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      Z% e	d      Z& G d d      Z'y)    )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                      e Zd ZdZ	 	 	 	 	 dd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.Nmax_body_sizec                   || _         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.
            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.
        )lifespanN)debugr   stater   routerr"   dictexception_handlerslistuser_middlewaremiddleware_stack)selfr%   routes
middlewarer)   r$   r"   s          Z/var/www/oz-panel.ru/ozpay-pub/venv/lib/python3.12/site-packages/starlette/applications.py__init__zStarlette.__init__   s\    @ 
W
Vh7*(:(B"M_H`%/%7rT*=M04    c                   | j                   }d }i }| j                  j                         D ]  \  }}|dt        fv r|}|||<    t	        t
        ||      g}| j                  *|j                  t	        t        | j                               || j                  z  }|j                  t	        t        ||             | j                  }t        |      D ]  \  }}	}
 ||g|	i |
} |S )Ni  )handlerr%   r!   )handlersr%   )r%   r)   items	Exceptionr   r   r"   appendr   r+   r   r'   reversed)r-   r%   error_handlerr)   keyvaluer/   appclsargskwargss              r0   build_middleware_stackz Starlette.build_middleware_stack?   s    

:<11779 	0JCsI&& %*/"3'		0 !!6UZ[\
)j)CSWSeSefgd***
*%8CU]bcdkk!)*!5 	,Cvc+D+F+C	,
r2   c                .    | j                   j                  S N)r'   r.   )r-   s    r0   r.   zStarlette.routesU   s    {{!!!r2   c               <     | j                   j                  |fi |S rC   )r'   url_path_for)r-   namepath_paramss      r0   rE   zStarlette.url_path_forY   s    't{{''<<<r2   c                   K   | |d<   | j                   | j                         | _         | j                  |||       d {    y 7 w)Nr=   )r,   rA   )r-   scopereceivesends       r0   __call__zStarlette.__call__\   sD     e  ($($?$?$AD!##E7D999s   =AA Ac                @    | j                   j                  |||       y N)r=   rF   )r'   mount)r-   pathr=   rF   s       r0   rO   zStarlette.mountb   s    $Cd3r2   c                @    | j                   j                  |||       y rN   )r'   host)r-   rR   r=   rF   s       r0   rR   zStarlette.hoste   s    3T2r2   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       r0   add_middlewarezStarlette.add_middlewareh   s@      ,WXX##Az2B'TT'TV'TUr2   c                "    || j                   |<   y rC   )r)   )r-   exc_class_or_status_coder4   s      r0   add_exception_handlerzStarlette.add_exception_handlerm   s    
 =D 89r2   c                D    | j                   j                  |||||       y )N)methodsrF   include_in_schema)r'   	add_route)r-   rP   router\   rF   r]   s         r0   r^   zStarlette.add_routet   s"     	dE7Yjkr2   )FNNNN)r-   r   r%   boolr.   zSequence[BaseRoute] | Noner/   zSequence[Middleware] | Noner)   z%Mapping[Any, ExceptionHandler] | Noner$   zLifespan[AppType] | Noner"   z
int | NonereturnNone)ra   r   )ra   zlist[BaseRoute])rF   strrG   r   ra   r   )rI   r   rJ   r   rK   r   ra   rb   rC   )rP   rc   r=   r   rF   
str | Nonera   rb   )rR   rc   r=   r   rF   rd   ra   rb   )rV   z_MiddlewareFactory[P]r?   zP.argsr@   zP.kwargsra   rb   )rY   zint | type[Exception]r4   r   ra   rb   )NNT)rP   rc   r_   z3Callable[[Request], Awaitable[Response] | Response]r\   zlist[str] | NonerF   rd   r]   r`   ra   rb   )__name__
__module____qualname____doc__r1   rA   propertyr.   rE   rL   rO   rR   rW   rZ   r^    r2   r0   r   r      s   + -126DH-1&5 %)&5&5&5 +&5 0	&5
 B&5 +&5 "&5 
&5P, " "=:43V
D"7D "D 
	D %)"&ll Cl "	l
 l  l 
lr2   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   rj   r2   r0   <module>rw      sU    " B B * * 3 ? F = ? & ( / U U
);
/cNhl hlr2   