o
    $6d)                     @   s   d dl Z d dl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 d d	lmZmZ d d
lmZmZmZmZmZ e jdddZG dd dZdS )    N)StateURLPath)
Middleware)BaseHTTPMiddleware)ServerErrorMiddleware)ExceptionMiddleware)Request)Response)	BaseRouteRouter)ASGIAppLifespanReceiveScopeSendAppType	Starlette)boundc                   @   s  e Zd ZdZ							dDdddedejeje  dejeje	  d	ejej
ejejeegejeeje f f f  d
ejejej  dejejej  dejed  ddfddZdefddZedeje fddZdedejdefddZdedededdfddZdedejfddZ 	dEd ed!ed"eje ddfd#d$Z!	dEd%ed!ed"eje ddfd&d'Z"d(e#d)ejddfd*d+Z$d,eje%ej&e f d-ejddfd.d/Z'ded0ejddfd1d2Z(			3dFd ed4ejd5ejeje  d"eje d6eddfd7d8Z)	dEd ed4ejd"eje ddfd9d:Z*d,eje%ej&e f dejfd;d<Z+			3dFd ed5ejeje  d"eje d6edejf
d=d>Z,	dEd ed"eje dejfd?d@Z-dAedejfdBdCZ.dS )Gr   aL  
    Creates an application instance.

    **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 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 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 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.
    FNselfr   debugroutes
middlewareexception_handlers
on_startupon_shutdownlifespanreturnc                 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 )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    r#   mC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\starlette/applications.py__init__/   s   
zStarlette.__init__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 ]\}}	|dd|i|	}q8|S )Ni  )handlerr   )handlersr   appr#   )
r   r   items	Exceptionr   r   r!   r   r   reversed)
r   r   Zerror_handlerr   keyvaluer   r(   clsoptionsr#   r#   r$   build_middleware_stackR   s*   

z Starlette.build_middleware_stackc                 C   s   | j jS N)r   r   r   r#   r#   r$   r   n   s   zStarlette.routes_Starlette__namepath_paramsc                 K   s   | j j|fi |S r1   )r   url_path_for)r   r3   r4   r#   r#   r$   r5   s   s   zStarlette.url_path_forscopereceivesendc                    s6   | |d< | j d u r|  | _ |  |||I d H  d S )Nr(   )r"   r0   )r   r6   r7   r8   r#   r#   r$   __call__v   s
   

zStarlette.__call__
event_typec                 C   s   | j |S r1   )r   on_event)r   r:   r#   r#   r$   r;   |   s   zStarlette.on_eventpathr(   namec                 C      | j j|||d d S N)r(   r=   )r   mount)r   r<   r(   r=   r#   r#   r$   r@         zStarlette.mounthostc                 C   r>   r?   )r   rB   )r   rB   r(   r=   r#   r#   r$   rB      rA   zStarlette.hostmiddleware_classr/   c                 K   s0   | j d ur	td| jdt|fi | d S )Nz6Cannot add middleware after an application has startedr   )r"   RuntimeErrorr!   insertr   )r   rC   r/   r#   r#   r$   add_middleware   s   
zStarlette.add_middlewareexc_class_or_status_coder&   c                 C   s   || j |< d S r1   )r   )r   rG   r&   r#   r#   r$   add_exception_handler   s   zStarlette.add_exception_handlerfuncc                 C   s   | j || d S r1   )r   add_event_handler)r   r:   rI   r#   r#   r$   rJ      s   zStarlette.add_event_handlerTroutemethodsinclude_in_schemac                 C   s   | j j|||||d d S N)rL   r=   rM   r   	add_route)r   r<   rK   rL   r=   rM   r#   r#   r$   rP      s   

zStarlette.add_routec                 C   r>   N)r=   r   add_websocket_route)r   r<   rK   r=   r#   r#   r$   rS      rA   zStarlette.add_websocket_routec                    s,   t dt dtjdtjf 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.rI   r   c                    s     |  | S r1   )rH   rI   rG   r   r#   r$   	decorator   s   z.Starlette.exception_handler.<locals>.decoratorwarningswarnDeprecationWarningtypingCallable)r   rG   rV   r#   rU   r$   exception_handler   s   zStarlette.exception_handlerc                    s2   t dt dtjdtjf 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.rI   r   c                    s   j j|  d | S rN   rO   rT   rM   rL   r=   r<   r   r#   r$   rV      s   z"Starlette.route.<locals>.decoratorrW   )r   r<   rL   r=   rM   rV   r#   r^   r$   rK      s   "
zStarlette.routec                    s.   t dt dtjdtjf 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.rI   r   c                    s   j j|  d | S rQ   rR   rT   r=   r<   r   r#   r$   rV      s   z,Starlette.websocket_route.<locals>.decoratorrW   )r   r<   r=   rV   r#   r_   r$   websocket_route   s   
zStarlette.websocket_routemiddleware_typec                    s:   t dt |dksJ ddtjdtjf 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.rI   r   c                    s    j t| d | S )N)dispatch)rF   r   rT   r2   r#   r$   rV     s   z'Starlette.middleware.<locals>.decoratorrW   )r   ra   rV   r#   r2   r$   r      s   
zStarlette.middleware)FNNNNNNr1   )NNT)/__name__
__module____qualname____doc__boolr[   OptionalSequencer
   r   MappingAnyr\   r   r*   Unionr	   	Awaitabler   r%   r   r0   propertyListr   strr   r5   r   r   r   r9   r;   r@   rB   typerF   intTyperH   rJ   rP   rS   r]   rK   r`   r   r#   r#   r#   r$   r      s
   	
#



	



!
)r[   rX   Zstarlette.datastructuresr   r   Zstarlette.middlewarer   Zstarlette.middleware.baser   Zstarlette.middleware.errorsr   Zstarlette.middleware.exceptionsr   Zstarlette.requestsr   Zstarlette.responsesr	   Zstarlette.routingr
   r   Zstarlette.typesr   r   r   r   r   TypeVarr   r   r#   r#   r#   r$   <module>   s    