o
    OÊÆh)  ã                   @   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#   úc/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/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   Ú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 r2   )r   Úurl_path_for)r   r4   r5   r#   r#   r$   r6   s   s   zStarlette.url_path_forÚscopeÚreceiveÚsendc                 Ã   s6   �| |d< | j d u r|  ¡ | _ |   |||¡I d H  d S )Nr(   )r"   r1   )r   r7   r8   r9   r#   r#   r$   Ú__call__v   s
   €

zStarlette.__call__Ú
event_typec                 C   s   | j  |¡S r2   )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$   rA      ó   zStarlette.mountÚhostc                 C   r?   r@   )r   rC   )r   rC   r(   r>   r#   r#   r$   rC   „   rB   zStarlette.hostÚmiddleware_classr0   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   rD   r0   r#   r#   r$   Úadd_middleware‰   s   
zStarlette.add_middlewareÚexc_class_or_status_coder&   c                 C   s   || j |< d S r2   )r   )r   rH   r&   r#   r#   r$   Úadd_exception_handlerŽ   s   zStarlette.add_exception_handlerÚfuncc                 C   s   | j  ||¡ d S r2   )r   Úadd_event_handler)r   r;   rJ   r#   r#   r$   rK   •   s   zStarlette.add_event_handlerTÚrouteÚmethodsÚinclude_in_schemac                 C   s   | j j|||||d� d S ©N)rM   r>   rN   ©r   Ú	add_route)r   r=   rL   rM   r>   rN   r#   r#   r$   rQ   š   s   

ÿzStarlette.add_routec                 C   r?   ©N)r>   ©r   Úadd_websocket_route)r   r=   rL   r>   r#   r#   r$   rT   ¦   rB   zStarlette.add_websocket_routec                    s,   t  dt¡ dtjdtjf‡ ‡fdd„}|S )Nz¢The `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.rJ   r   c                    s   ˆ  ˆ | ¡ | S r2   )rI   ©rJ   ©rH   r   r#   r$   Ú	decorator´   s   z.Starlette.exception_handler.<locals>.decorator©ÚwarningsÚwarnÚDeprecationWarningÚtypingÚCallable)r   rH   rW   r#   rV   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)
        z“The `route` decorator is deprecated, and will be removed in version 1.0.0. Refer to https://www.starlette.io/routing/ for the recommended approach.rJ   r   c                    s   ˆj jˆ| ˆˆˆ d� | S rO   rP   rU   ©rN   rM   r>   r=   r   r#   r$   rW   Î   s   ûz"Starlette.route.<locals>.decoratorrX   )r   r=   rM   r>   rN   rW   r#   r_   r$   rL   º   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)
        z¯The `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.rJ   r   c                    s   ˆj jˆ| ˆ d� | S rR   rS   rU   ©r>   r=   r   r#   r$   rW   ê   s   z,Starlette.websocket_route.<locals>.decoratorrX   )r   r=   r>   rW   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)
        z¨The `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.rJ   r   c                    s   ˆ j t| d� | S )N)Údispatch)rG   r   rU   r3   r#   r$   rW     s   z'Starlette.middleware.<locals>.decoratorrX   )r   rb   rW   r#   r3   r$   r   ð   s   ý
ÿzStarlette.middleware)FNNNNNNr2   )NNT)/Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úboolr\   ÚOptionalÚSequencer
   r   ÚMappingÚAnyr]   r   r*   ÚUnionr	   Ú	Awaitabler   r%   r   r1   ÚpropertyÚListr   Ústrr   r6   r   r   r   r:   r<   rA   rC   ÚtyperG   ÚintÚTyperI   rK   rQ   rT   r^   rL   ra   r   r#   r#   r#   r$   r      s
   	ðÿþýüÿÿÿÿÿûòñð
ï#ÿÿÿÿ
þÿÿÿÿ
þþý
üÿÿ
þ	úþýüûú
ùÿÿÿÿ
þÿ
þûþýüû
ú!ÿÿÿ
þ)r\   rY   Ústarlette.datastructuresr   r   Ústarlette.middlewarer   Ústarlette.middleware.baser   Ústarlette.middleware.errorsr   Ústarlette.middleware.exceptionsr   Ústarlette.requestsr   Ústarlette.responsesr	   Ústarlette.routingr
   r   Ústarlette.typesr   r   r   r   r   ÚTypeVarr   r   r#   r#   r#   r$   Ú<module>   s    