
    i                       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%dS )    )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dAdZdBd#Z	dCdDd'Z
dCdEd)ZdFd0ZdGd5Z	 	 	 dHdId<ZdS )Jr   z!Creates an Starlette application.FNselfr   debugboolroutesSequence[BaseRoute] | None
middlewareSequence[Middleware] | Noneexception_handlers%Mapping[Any, ExceptionHandler] | NonelifespanLifespan[AppType] | NonereturnNonec                    || _         t                      | _        t          ||          | _        |i nt          |          | _        |g nt          |          | _        d| _	        dS )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.
        )r)   N)
r!   r   stater   routerdictr'   listuser_middlewaremiddleware_stack)r    r!   r#   r%   r'   r)   s         S/root/projects/qq-shell/venv/lib/python3.11/site-packages/starlette/applications.py__init__zStarlette.__init__   sk    8 
WW
Vh777(:(B""M_H`H`%/%7rrT*=M=M04    r   c                D   | j         }d }i }| j                                        D ]\  }}|dt          fv r|}|||<   t	          t
          ||          g| j        z   t	          t          ||          gz   }| j        }t          |          D ]\  }}	}
 ||g|	R i |
}|S )Ni  )handlerr!   )handlersr!   )
r!   r'   items	Exceptionr   r   r2   r   r/   reversed)r    r!   error_handlerr'   keyvaluer%   appclsargskwargss              r4   build_middleware_stackz Starlette.build_middleware_stack9   s    
:<17799 	0 	0JCsI&&& %*/"3'' -}ERRRS"#-8JRWXXXYZ 	 k!)*!5!5 	, 	,Cv#c+D+++F++CC
r6   list[BaseRoute]c                    | j         j        S N)r/   r#   )r    s    r4   r#   zStarlette.routesO   s    {!!r6   namestrpath_paramsr   r   c               (     | j         j        |fi |S rG   )r/   url_path_for)r    rH   rJ   s      r4   rL   zStarlette.url_path_forS   s    't{'<<<<<r6   scoper   receiver   sendr   c                   K   | |d<   | j         |                                 | _         |                      |||           d {V  d S )Nr@   )r3   rD   )r    rM   rN   rO   s       r4   __call__zStarlette.__call__V   s\      e ($($?$?$A$AD!##E7D99999999999r6   pathr@   
str | Nonec                @    | j                             |||           d S N)r@   rH   )r/   mount)r    rR   r@   rH   s       r4   rV   zStarlette.mount\   s%    $Cd33333r6   hostc                @    | j                             |||           d S rU   )r/   rW   )r    rW   r@   rH   s       r4   rW   zStarlette.host_   s%    3T22222r6   middleware_class_MiddlewareFactory[P]rB   P.argsrC   P.kwargsc                    | j         t          d          | j                            dt	          |g|R i |           d S )Nz6Cannot add middleware after an application has startedr   )r3   RuntimeErrorr2   insertr   )r    rY   rB   rC   s       r4   add_middlewarezStarlette.add_middlewareb   sR     ,WXXX##Az2B'TT'T'T'TV'T'TUUUUUr6   exc_class_or_status_codeint | type[Exception]r8   r   c                    || j         |<   d S rG   )r'   )r    ra   r8   s      r4   add_exception_handlerzStarlette.add_exception_handlerg   s    
 =D 8999r6   Troute3Callable[[Request], Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                D    | j                             |||||           d S )N)rg   rH   ri   )r/   	add_route)r    rR   re   rg   rH   ri   s         r4   rk   zStarlette.add_routen   s,     	dE7Yjkkkkkr6   )FNNNN)r    r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r+   r   )r+   rE   )rH   rI   rJ   r   r+   r   )rM   r   rN   r   rO   r   r+   r,   rG   )rR   rI   r@   r   rH   rS   r+   r,   )rW   rI   r@   r   rH   rS   r+   r,   )rY   rZ   rB   r[   rC   r\   r+   r,   )ra   rb   r8   r   r+   r,   )NNT)rR   rI   re   rf   rg   rh   rH   rS   ri   r"   r+   r,   )__name__
__module____qualname____doc__r5   rD   propertyr#   rL   rQ   rV   rW   r`   rd   rk    r6   r4   r   r      s.       ++ -126DH-1!5 !5 !5 !5 !5F   , " " " X"= = = =: : : :4 4 4 4 43 3 3 3 3V V V V
D D D D %)"&l l l l l l lr6   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   rq   r6   r4   <module>r}      s   " " " " " " B B B B B B B B B B B B * * * * * * * * * * 3 3 3 3 3 3 3 3 ? ? ? ? ? ? ? ? = = = = = = ? ? ? ? ? ? & & & & & & ( ( ( ( ( ( / / / / / / / / U U U U U U U U U U U U U U U U
');
/
/
/IcNNcl cl cl cl cl cl cl cl cl clr6   