o
    ђh)                     @  s&  d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	m
Z
mZ ejdkr.d dlmZ nd dl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dZ+edZ,G dd dZ-dS )    )annotationsN)	AwaitableMappingSequence)AnyCallableTypeVar)   
   )	ParamSpec)StateURLPath)
Middleware_MiddlewareFactory)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppExceptionHandlerLifespanReceiveScopeSend)	WebSocketAppType	Starlette)boundPc                   @  s   e Zd ZdZ							d]d^ddZd_ddZed`ddZdad"d#Zdbd*d+Z	dcd.d/Z
ddded3d4Zdddfd6d7Zdgd>d?ZdhdDdEZdidGdHZ			IdjdkdOdPZ	dddldRdSZdmdTdUZ			IdjdndVdWZdddodXdYZdpd[d\ZdS )qr   z!Creates an Starlette application.FNselfr   debugboolroutesSequence[BaseRoute] | None
middlewareSequence[Middleware] | Noneexception_handlers%Mapping[Any, ExceptionHandler] | None
on_startup"Sequence[Callable[[], Any]] | Noneon_shutdownlifespanLifespan[AppType] | NonereturnNonec                 C  sv   |du s|du r|du sJ d|| _ t | _t||||d| _|du r&i nt|| _|du r1g 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.
            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.)r+   r-   r.   )
r#   r   stater   routerdictr)   listuser_middlewaremiddleware_stack)r"   r#   r%   r'   r)   r+   r-   r.    r8   O/var/www/html/govbot/env/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 tt||dg }| j}t	|D ]\}}	}
||g|	R i |
}q8|S )Ni  )handlerr#   )handlersr#   )
r#   r)   items	Exceptionr   r   r6   r   r3   reversed)r"   r#   error_handlerr)   keyvaluer'   appclsargskwargsr8   r8   r9   build_middleware_stackP   s"   
z Starlette.build_middleware_stacklist[BaseRoute]c                 C  s   | j jS N)r3   r%   r"   r8   r8   r9   r%   f   s   zStarlette.routesnamestrpath_paramsr   r   c                K  s   | j j|fi |S rI   )r3   url_path_for)r"   rK   rM   r8   r8   r9   rN   j   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )NrC   )r7   rG   )r"   rO   rP   rQ   r8   r8   r9   __call__m   s
   

zStarlette.__call__
event_typer   c                 C  s   | j |S rI   )r3   on_event)r"   rS   r8   r8   r9   rT   s   s   zStarlette.on_eventpathrC   
str | Nonec                 C     | j j|||d d S N)rC   rK   )r3   mount)r"   rU   rC   rK   r8   r8   r9   rY   v      zStarlette.mounthostc                 C  rW   rX   )r3   r[   )r"   r[   rC   rK   r8   r8   r9   r[   y   rZ   zStarlette.hostmiddleware_class_MiddlewareFactory[P]rE   P.argsrF   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   )r7   RuntimeErrorr6   insertr   )r"   r\   rE   rF   r8   r8   r9   add_middleware|   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | type[Exception]r;   r   c                 C  s   || j |< d S rI   )r)   )r"   rc   r;   r8   r8   r9   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C  s   | j || d S rI   )r3   add_event_handler)r"   rS   rf   r8   r8   r9   rg      s   zStarlette.add_event_handlerTroute3Callable[[Request], Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                 C  s   | j j|||||d d S N)rj   rK   rl   r3   	add_route)r"   rU   rh   rj   rK   rl   r8   r8   r9   ro      s   zStarlette.add_route&Callable[[WebSocket], Awaitable[None]]c                 C  rW   N)rK   r3   add_websocket_route)r"   rU   rh   rK   r8   r8   r9   rs      s   zStarlette.add_websocket_routec                   s    t dt d fdd}|S )NzThe `exception_handler` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/exceptions/ for the recommended approach.rf   r   r0   c                   s     |  | S rI   )re   rf   rc   r"   r8   r9   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorrf   r   r0   r   warningswarnDeprecationWarning)r"   rc   rv   r8   ru   r9   exception_handler   s   zStarlette.exception_handlerc                   s&   t dt d fd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://www.starlette.io/routing/ for the recommended approach.rf   r   r0   c                   s   j j|  d | S rm   rn   rt   rl   rj   rK   rU   r"   r8   r9   rv      s   z"Starlette.route.<locals>.decoratorNrw   rx   )r"   rU   rj   rK   rl   rv   r8   r}   r9   rh      s   
zStarlette.routec                   s"   t dt d fd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://www.starlette.io/routing/#websocket-routing for the recommended approach.rf   r   r0   c                   s   j j|  d | S rq   rr   rt   rK   rU   r"   r8   r9   rv      s   z,Starlette.websocket_route.<locals>.decoratorNrw   rx   )r"   rU   rK   rv   r8   r~   r9   websocket_route   s   zStarlette.websocket_routemiddleware_typec                   s.   t dt |dksJ dd
 fd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://www.starlette.io/middleware/#using-middleware for recommended approach.httpz/Currently only middleware("http") is supported.rf   r   r0   c                   s    j t| d | S )N)dispatch)rb   r   rt   rJ   r8   r9   rv      s   z'Starlette.middleware.<locals>.decoratorNrw   rx   )r"   r   rv   r8   rJ   r9   r'      s   zStarlette.middleware)FNNNNNN)r"   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r,   r.   r/   r0   r1   )r0   r   )r0   rH   )rK   rL   rM   r   r0   r   )rO   r   rP   r   rQ   r   r0   r1   )rS   rL   r0   r   rI   )rU   rL   rC   r   rK   rV   r0   r1   )r[   rL   rC   r   rK   rV   r0   r1   )r\   r]   rE   r^   rF   r_   r0   r1   )rc   rd   r;   r   r0   r1   )rS   rL   rf   r   r0   r1   )NNT)rU   rL   rh   ri   rj   rk   rK   rV   rl   r$   r0   r1   )rU   rL   rh   rp   rK   rV   r0   r1   )rc   rd   r0   r   )
rU   rL   rj   rk   rK   rV   rl   r$   r0   r   )rU   rL   rK   rV   r0   r   )r   rL   r0   r   )__name__
__module____qualname____doc__r:   rG   propertyr%   rN   rR   rT   rY   r[   rb   re   rg   ro   rs   r|   rh   r   r'   r8   r8   r8   r9   r      sD    
1







 ).
__future__r   sysry   collections.abcr   r   r   typingr   r   r   version_infor   typing_extensions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   r8   r8   r8   r9   <module>   s*    
 