o
    h)                     @  s  d dl mZ d dlZd dlZd dl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j$dddZ%edZ&G dd dZ'dS )    )annotationsN)   
   )	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!typing.Sequence[BaseRoute] | None
middleware"typing.Sequence[Middleware] | Noneexception_handlers3typing.Mapping[typing.Any, ExceptionHandler] | None
on_startup7typing.Sequence[typing.Callable[[], typing.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(    r2   j/var/www/html/construction_image-detection-poc/venv/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   r0   r   r-   reversed)r   r   error_handlerr#   keyvaluer!   appclsargskwargsr2   r2   r3   build_middleware_stackO   s"   
z Starlette.build_middleware_stacklist[BaseRoute]c                 C  s   | j jS N)r-   r   r   r2   r2   r3   r   e   s   zStarlette.routesnamestrpath_params
typing.Anyr   c                K  s   | j j|fi |S rC   )r-   url_path_for)r   rE   rG   r2   r2   r3   rI   i   s   zStarlette.url_path_forscoper   receiver   sendr   c                   s6   | |d< | j d u r|  | _ |  |||I d H  d S )Nr=   )r1   rA   )r   rJ   rK   rL   r2   r2   r3   __call__l   s
   

zStarlette.__call__
event_typetyping.Callablec                 C  s   | j |S rC   )r-   on_event)r   rN   r2   r2   r3   rP   r   s   zStarlette.on_eventpathr=   
str | Nonec                 C     | j j|||d d S N)r=   rE   )r-   mount)r   rQ   r=   rE   r2   r2   r3   rU   u      zStarlette.mounthostc                 C  rS   rT   )r-   rW   )r   rW   r=   rE   r2   r2   r3   rW   x   rV   zStarlette.hostmiddleware_class_MiddlewareFactory[P]r?   P.argsr@   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   )r1   RuntimeErrorr0   insertr   )r   rX   r?   r@   r2   r2   r3   add_middleware{   s   
$zStarlette.add_middlewareexc_class_or_status_codeint | type[Exception]r5   r   c                 C  s   || j |< d S rC   )r#   )r   r_   r5   r2   r2   r3   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C  s   | j || d S rC   )r-   add_event_handler)r   rN   rb   r2   r2   r3   rc      s   zStarlette.add_event_handlerTrouteAtyping.Callable[[Request], typing.Awaitable[Response] | Response]methodslist[str] | Noneinclude_in_schemac                 C  s   | j j|||||d d S N)rf   rE   rh   r-   	add_route)r   rQ   rd   rf   rE   rh   r2   r2   r3   rk      s   zStarlette.add_route4typing.Callable[[WebSocket], typing.Awaitable[None]]c                 C  rS   N)rE   r-   add_websocket_route)r   rQ   rd   rE   r2   r2   r3   ro      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.rb   rO   r*   c                   s     |  | S rC   )ra   rb   r_   r   r2   r3   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorrb   rO   r*   rO   warningswarnDeprecationWarning)r   r_   rr   r2   rq   r3   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.rb   rO   r*   c                   s   j j|  d | S ri   rj   rp   rh   rf   rE   rQ   r   r2   r3   rr      s   z"Starlette.route.<locals>.decoratorNrs   rt   )r   rQ   rf   rE   rh   rr   r2   ry   r3   rd      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.rb   rO   r*   c                   s   j j|  d | S rm   rn   rp   rE   rQ   r   r2   r3   rr      s   z,Starlette.websocket_route.<locals>.decoratorNrs   rt   )r   rQ   rE   rr   r2   rz   r3   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.rb   rO   r*   c                   s    j t| d | S )N)dispatch)r^   r
   rp   rD   r2   r3   rr      s   z'Starlette.middleware.<locals>.decoratorNrs   rt   )r   r|   rr   r2   rD   r3   r!      s   zStarlette.middleware)FNNNNNN)r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r&   r(   r)   r*   r+   )r*   r   )r*   rB   )rE   rF   rG   rH   r*   r   )rJ   r   rK   r   rL   r   r*   r+   )rN   rF   r*   rO   rC   )rQ   rF   r=   r   rE   rR   r*   r+   )rW   rF   r=   r   rE   rR   r*   r+   )rX   rY   r?   rZ   r@   r[   r*   r+   )r_   r`   r5   r   r*   r+   )rN   rF   rb   rO   r*   r+   )NNT)rQ   rF   rd   re   rf   rg   rE   rR   rh   r   r*   r+   )rQ   rF   rd   rl   rE   rR   r*   r+   )r_   r`   r*   rO   )
rQ   rF   rf   rg   rE   rR   rh   r   r*   rO   )rQ   rF   rE   rR   r*   rO   )r|   rF   r*   rO   )__name__
__module____qualname____doc__r4   rA   propertyr   rI   rM   rP   rU   rW   r^   ra   rc   rk   ro   rx   rd   r{   r!   r2   r2   r2   r3   r      sD    
1







 )(
__future__r   systypingru   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   TypeVarr   r   r   r2   r2   r2   r3   <module>   s(    
 