o
    àej«  ã                   @  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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)ÚServerErrorMiddleware)ÚExceptionMiddleware)ÚRequest)ÚResponse)Ú	BaseRouteÚRouter)ÚASGIAppÚExceptionHandlerÚLifespanÚReceiveÚScopeÚSendÚAppTypeÚ	Starlette)ÚboundÚPc                   @  s�   e Zd ZdZ					dGdHdd„ZdIdd„ZedJdd„ƒZdKdd „ZdLd'd(„Z	dMdNd,d-„Z
dMdOd/d0„ZdPd7d8„ZdQd=d>„Z			?dRdSdEdF„ZdS )Tr   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                 C  sR   || _ tƒ | _t||d�| _|du ri nt|ƒ| _|du r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'   © r1   úV/var/www/html/choboyeo/PHP/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   r/   r   r,   Úreversed)r   r   Úerror_handlerr%   ÚkeyÚvaluer#   ÚappÚclsÚargsÚkwargsr1   r1   r2   Úbuild_middleware_stack9   s"   
ÿþÿz Starlette.build_middleware_stackúlist[BaseRoute]c                 C  s   | j jS ©N)r,   r!   )r   r1   r1   r2   r!   O   s   zStarlette.routesÚnameÚstrÚpath_paramsr   r   c                K  s   | j j|fi |¤ŽS rB   )r,   Úurl_path_for)r   rC   rE   r1   r1   r2   rF   S   s   zStarlette.url_path_forÚscoper   Úreceiver   Úsendr   c                 Ã  s6   �| |d< | j d u r|  ¡ | _ |   |||¡I d H  d S )Nr<   )r0   r@   )r   rG   rH   rI   r1   r1   r2   Ú__call__V   s
   €

zStarlette.__call__Úpathr<   ú
str | Nonec                 C  ó   | j j|||d� d S ©N)r<   rC   )r,   Úmount)r   rK   r<   rC   r1   r1   r2   rO   \   ó   zStarlette.mountÚhostc                 C  rM   rN   )r,   rQ   )r   rQ   r<   rC   r1   r1   r2   rQ   _   rP   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   )r0   ÚRuntimeErrorr/   Úinsertr   )r   rR   r>   r?   r1   r1   r2   Úadd_middlewareb   s   
$zStarlette.add_middlewareÚexc_class_or_status_codeúint | type[Exception]r4   r   c                 C  s   || j |< d S rB   )r%   )r   rY   r4   r1   r1   r2   Úadd_exception_handlerg   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)r^   rC   r`   )r,   Ú	add_route)r   rK   r\   r^   rC   r`   r1   r1   r2   ra   n   s   zStarlette.add_route)FNNNN)r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   )r)   r   )r)   rA   )rC   rD   rE   r   r)   r   )rG   r   rH   r   rI   r   r)   r*   rB   )rK   rD   r<   r   rC   rL   r)   r*   )rQ   rD   r<   r   rC   rL   r)   r*   )rR   rS   r>   rT   r?   rU   r)   r*   )rY   rZ   r4   r   r)   r*   )NNT)rK   rD   r\   r]   r^   r_   rC   rL   r`   r    r)   r*   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r@   Úpropertyr!   rF   rJ   rO   rQ   rX   r[   ra   r1   r1   r1   r2   r      s*    ú
#



ú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   r1   r1   r1   r2   Ú<module>   s     