o
    ùT·jƒ  ã                   @  sê   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d�Z%e	dƒZ&G dd„ dƒZ'dS )é    )Ú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                   @  s–   e Zd ZdZ					dJddœdKdd„ZdLdd„ZedMdd„ƒZdNd"d#„ZdOd*d+„Z	dPdQd/d0„Z
dPdRd2d3„ZdSd:d;„ZdTd@dA„Z			BdUdVdHdI„ZdS )Wr   z Creates a Starlette application.FN©Úmax_body_sizeÚselfr   ÚdebugÚboolÚroutesúSequence[BaseRoute] | NoneÚ
middlewareúSequence[Middleware] | NoneÚexception_handlersú%Mapping[Any, ExceptionHandler] | NoneÚlifespanúLifespan[AppType] | Noner    ú
int | NoneÚreturnÚNonec                C  sX   || _ tƒ | _t||d�| _|| _|du ri nt|ƒ| _|du r"g 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.
            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.
        )r*   N)r"   r
   Ústater   Úrouterr    Údictr(   ÚlistÚuser_middlewareÚmiddleware_stack)r!   r"   r$   r&   r(   r*   r    © r5   úY/home/dinkstrade/pdmp-scanner/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d ur5| tt| jd�¡ || j	7 }| tt
||d�¡ | j}t|ƒD ]\}}	}
||g|	¢R i |
¤Ž}qK|S )Niô  )Úhandlerr"   r   )Úhandlersr"   )r"   r(   ÚitemsÚ	Exceptionr   r   r    Úappendr   r3   r   r0   Úreversed)r!   r"   Úerror_handlerr(   ÚkeyÚvaluer&   ÚappÚclsÚargsÚkwargsr5   r5   r6   Úbuild_middleware_stack?   s    


z Starlette.build_middleware_stackúlist[BaseRoute]c                 C  s   | j jS ©N)r0   r$   )r!   r5   r5   r6   r$   U   s   zStarlette.routesÚnameÚstrÚpath_paramsr   r   c                K  s   | j j|fi |¤ŽS rG   )r0   Úurl_path_for)r!   rH   rJ   r5   r5   r6   rK   Y   s   zStarlette.url_path_forÚscoper   Úreceiver   Úsendr   c                 Ã  s6   �| |d< | j d u r|  ¡ | _ |   |||¡I d H  d S )NrA   )r4   rE   )r!   rL   rM   rN   r5   r5   r6   Ú__call__\   s
   €

zStarlette.__call__ÚpathrA   ú
str | Nonec                 C  ó   | j j|||d� d S ©N)rA   rH   )r0   Úmount)r!   rP   rA   rH   r5   r5   r6   rT   b   ó   zStarlette.mountÚhostc                 C  rR   rS   )r0   rV   )r!   rV   rA   rH   r5   r5   r6   rV   e   rU   zStarlette.hostÚmiddleware_classú_MiddlewareFactory[P]rC   úP.argsrD   ú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   )r4   ÚRuntimeErrorr3   Úinsertr   )r!   rW   rC   rD   r5   r5   r6   Úadd_middlewareh   s   
$zStarlette.add_middlewareÚexc_class_or_status_codeúint | type[Exception]r8   r   c                 C  s   || j |< d S rG   )r(   )r!   r^   r8   r5   r5   r6   Úadd_exception_handlerm   s   zStarlette.add_exception_handlerTÚrouteú3Callable[[Request], Awaitable[Response] | Response]Úmethodsúlist[str] | NoneÚinclude_in_schemac                 C  s   | j j|||||d� d S )N)rc   rH   re   )r0   Ú	add_route)r!   rP   ra   rc   rH   re   r5   r5   r6   rf   t   s   zStarlette.add_route)FNNNN)r!   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r    r,   r-   r.   )r-   r   )r-   rF   )rH   rI   rJ   r   r-   r   )rL   r   rM   r   rN   r   r-   r.   rG   )rP   rI   rA   r   rH   rQ   r-   r.   )rV   rI   rA   r   rH   rQ   r-   r.   )rW   rX   rC   rY   rD   rZ   r-   r.   )r^   r_   r8   r   r-   r.   )NNT)rP   rI   ra   rb   rc   rd   rH   rQ   re   r#   r-   r.   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   rE   Úpropertyr$   rK   rO   rT   rV   r]   r`   rf   r5   r5   r5   r6   r      s.    úø
(



ú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   r5   r5   r5   r6   Ú<module>   s     