o
    ii                     @  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   ^/var/www/scraper.webshop2u.hu/html/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route3Callable[[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     