Ë
    dQêje]  ã                   óz  — d Z ddlZddlZddlZddlZddlmZmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZ ddl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 m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'  ejP                  e)«      Z*e G d„ d«      «       Z+ ejX                  «       Z-de+fd„Z.d„ Z/dd„Z0dd„Z1de!de!fd„Z2 G d„ de3«      Z4 G d„ d«      Z5	 ddl6m7Z7 e7jp                  e5_9        e5jp                  e7_8        ee<e=e>e&ef   Z?ee?   Z@ee?   ZAeeAe@f   ZB G d„ de«      ZCy# e:$ r e*jw                  d«       Y Œ?w xY w)uU  Server-Sent Events response for Starlette / FastAPI.

Intentional divergence from ``starlette.responses.StreamingResponse``
--------------------------------------------------------------------

``EventSourceResponse`` is modelled on Starlette's ``StreamingResponse`` and
re-syncs most of its behaviour (WebSocket denial, ``collapse_excgroups()``
around the task group, ``memoryview`` chunk handling). The following points
are deliberate divergences â€” DO NOT "fix" them without reading the rationale:

1. ASGI ``spec_version >= 2.4`` fast path is NOT adopted.
   Upstream short-circuits to ``await stream_response(send)`` and converts
   ``OSError`` into ``ClientDisconnect``, skipping ``listen_for_disconnect``.
   We keep ``_listen_for_disconnect`` running because it
     (a) invokes ``client_close_handler_callable`` on disconnect,
     (b) flips ``self.active = False`` so ``_ping`` and the cooperative
         shutdown grace loop exit promptly.
   Adopting the upstream fast path would regress both features.

2. ``_wrap_websocket_denial_send`` is inlined in this module rather than
   inherited from ``starlette.responses.Response``. The helper landed on
   Starlette ``main`` after our minimum pin (``starlette>=0.41.3``); inline
   until the floor moves past the release that contains it.

3. ``collapse_excgroups()`` is vendored in ``sse_starlette._utils`` rather
   than imported from ``starlette._utils`` (private module).

4. HEAD is answered with headers and an empty body; the stream never starts
   (Issue #218). Upstream ``StreamingResponse`` streams on HEAD too, which is
   harmless for finite bodies but never completes for an endless SSE
   generator, wedging keep-alive connections. Same contract as Starlette's
   ``FileResponse``: headers match GET, the background task still runs, and
   neither the iterator nor ``data_sender_callable`` is touched.
é    N)Ú	dataclassÚfield)ÚdatetimeÚtimezone)
ÚAnyÚAsyncIterableÚ	AwaitableÚCallableÚ	CoroutineÚIteratorÚMappingÚOptionalÚSetÚUnion)ÚBackgroundTask)Úiterate_in_threadpool)ÚMutableHeaders)ÚResponse)ÚReceiveÚScopeÚSendÚMessage)Úcollapse_excgroups)ÚServerSentEventÚensure_bytesc                   óV   — e Zd ZU dZ ee¬«      Zeej                     e
d<   dZee
d<   y)Ú_ShutdownStatezºPer-thread state for shutdown coordination.

    Issue #152 fix: Uses threading.local() instead of ContextVar to ensure
    one watcher per thread rather than one per async context.
    )Údefault_factoryÚeventsFÚwatcher_startedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úsetr   r   ÚanyioÚEventÚ__annotations__r    Úbool© ó    úV/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/sse_starlette/sse.pyr   r   E   s+   … ññ  %°SÔ9€FˆC�—‘ÑÓ9Ø!€O�TÔ!r+   r   Úreturnc                  óV   — t        t        dd«      } | €t        «       } | t        _        | S )z4Get or create shutdown state for the current thread.Úshutdown_stateN)ÚgetattrÚ_thread_stater   r/   )Ústates    r,   Ú_get_shutdown_stater3   U   s+   € ä”MÐ#3°TÓ:€EØ€}ÜÓ ˆØ',ŒÔ$Ø€Lr+   c                  ó¶   — 	 t        j                  t         j                  «      } t        | d«      r| j                  }t        |d«      r|S y# t
        $ r Y yw xY w)am  
    Try to get uvicorn Server instance via signal handler introspection.

    When uvicorn registers signal handlers, they're bound methods on the Server instance.
    We can retrieve the Server from the handler's __self__ attribute.

    Returns None if:
    - Not running under uvicorn
    - Signal handler isn't a bound method
    - Any introspection fails
    Ú__self__Úshould_exitN)ÚsignalÚ	getsignalÚSIGTERMÚhasattrr5   Ú	Exception)ÚhandlerÚservers     r,   Ú_get_uvicorn_serverr>   ^   s[   € ðÜ×"Ñ"¤6§>¡>Ó2ˆÜ�7˜JÔ'Ø×%Ñ%ˆFÜ�v˜}Ô-Ø�ð øô ò ØØðús   ‚AA Á	AÁAc               ƒ   óT  K  — t        «       } 	 	 t        «       }t        j                  rn=t        j                  r|�|j                  rnt        j                  d«      ƒ d{  –—†  ŒXt        | j                  «      D ]  }|j                  «        Œ 	 d| _
        y7 Œ8# d| _
        w xY w­w)ag  
    Poll for shutdown and broadcast to all events in this context.

    One watcher runs per thread (event loop). Checks two shutdown sources:
    1. AppStatus.should_exit - set when our monkey-patch works
    2. uvicorn Server.should_exit - via signal handler introspection (Issue #132 fix)

    When either becomes True, signals all registered events.
    Ng      à?F)r3   r>   Ú	AppStatusr6   Úenable_automatic_graceful_drainr&   ÚsleepÚlistr   r%   r    )r2   Úuvicorn_serverÚevents      r,   Ú_shutdown_watcherrF   u   sŸ   è ø€ ô  Ó!€Eð&Øô 1Ó2ˆNä×$Ò$Øô
 ×9Ò9Ø"Ð.Ø"×.Ò.àÜ—+‘+˜cÓ"×"Ð"ð# ô( ˜%Ÿ,™,Ó'ò 	ˆEØ�I‰I�Kñ	ð !&ˆÕð #ùð !&ˆÕüs/   ‚B(ŽAB Á!BÁ"/B ÂB(ÂB Â	B%Â%B(c                  óÈ   — t        «       } | j                  s6d| _        	 t        j                  «       }|j	                  t        «       «       yy# t        $ r
 d| _        Y yw xY w)zDEnsure the shutdown watcher is running for this thread (event loop).TFN)r3   r    ÚasyncioÚget_running_loopÚcreate_taskrF   ÚRuntimeError)r2   Úloops     r,   Ú$_ensure_watcher_started_on_this_looprM   �   s^   € äÓ!€EØ× Ò Ø $ˆÔð	*Ü×+Ñ+Ó-ˆDØ×ÑÔ.Ó0Õ1ð	 !øô
 ò 	*à$)ˆEÖ!ð	*ús   Ÿ-A ÁA!Á A!Úsendc                 ó$   ‡ — dt         ddfˆ fd„}|S )a;  Mirror of ``starlette.responses.Response._wrap_websocket_denial_send``.

    Divergence #2 (see module docstring): inlined because the helper landed
    on Starlette ``main`` (commit 9ee9519) after our minimum pin
    ``starlette>=0.41.3``. Drop this once the floor moves past the release
    that contains it.
    Úmessager-   Nc              “   óZ   •K  — | d   }|dv ri | ¥dd|z   i¥}  ‰| «      ƒ d {  –—†  y 7 Œ­w)NÚtype>   úhttp.response.bodyúhttp.response.startz
websocket.r*   )rP   Úmessage_typerN   s     €r,   Úwrappedz,_wrap_websocket_denial_send.<locals>.wrapped³   s<   øè ø€ Ø˜v‘ˆØÐHÑHØF˜ÐF &¨,¸Ñ*EÑFˆGÙ�7‹m×Òús   ƒ +£)¤+)r   )rN   rV   s   ` r,   Ú_wrap_websocket_denial_sendrW   ª   s   ø€ ðœwð ¨4õ ð €Nr+   c                   ó   — e Zd Zy)ÚSendTimeoutErrorN)r!   r"   r#   r*   r+   r,   rY   rY   ¼   s   „ Ør+   rY   c                   ó^   — e Zd ZU dZdZdZdZee   e	d<   e
d„ «       Ze
d„ «       Ze
d„ «       Zy)	r@   z\Helper to capture a shutdown signal from Uvicorn so we can gracefully terminate SSE streams.FTNÚoriginal_handlerc                  ó   — dt         _        y)aJ  
        Prevent automatic SSE stream termination on server shutdown.

        WARNING: When disabled, you MUST set AppStatus.should_exit = True
        at some point during shutdown, or streams will never close and the
        server will hang indefinitely (or until uvicorn's graceful shutdown
        timeout expires).
        FN©r@   rA   r*   r+   r,   Ú disable_automatic_graceful_drainz*AppStatus.disable_automatic_graceful_drainÇ   s   € ð 5:Œ	Õ1r+   c                  ó   — dt         _        y)a  
        Re-enable automatic SSE stream termination on server shutdown.

        This restores the default behavior where SIGTERM triggers immediate
        stream draining. Call this to undo a previous call to
        disable_automatic_graceful_drain().
        TNr]   r*   r+   r,   Ú$enable_automatic_graceful_drain_modez.AppStatus.enable_automatic_graceful_drain_modeÓ   s   € ð 59Œ	Õ1r+   c                  ó†   — t         j                  rdt         _        t         j                  �t        j                  | i |¤Ž y y )NT)r@   rA   r6   r[   )ÚargsÚkwargss     r,   Úhandle_exitzAppStatus.handle_exitÞ   s7   € ä×4Ò4Ø$(ŒIÔ!Ü×%Ñ%Ð1Ü×&Ñ&¨Ð7°Ó7ð 2r+   )r!   r"   r#   r$   r6   rA   r[   r   r
   r(   Ústaticmethodr^   r`   rd   r*   r+   r,   r@   r@   À   sZ   … Ùfà€KØ&*Ð#Ø+/Ð�h˜xÑ(Ó/àñ	:ó ð	:ð ñ9ó ð9ð ñ8ó ñ8r+   r@   )ÚServerzHUvicorn not installed. Graceful shutdown on server termination disabled.c                   óÜ  — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 d%dededee	e
e
f      de
d	ee   d
eeeef      dee
   deeg ef      deeg ed   f      dee   deeeged   f      deej(                     deddfd„Zedeeef   fd„«       Zej0                  deeef   ddfd„«       Zd&deddfd„Zdededdfd„Zdeddfd„Zdeddfd„Ze d'd „«       Z!d'd!„Z"deddfd"„Z#d#e$dededdfd$„Z%y)(ÚEventSourceResponseaµ  Streaming response implementing the SSE (Server-Sent Events) specification.

    Args:
        content: Async iterable or sync iterator yielding SSE event data.
        status_code: HTTP status code. Default: 200.
        headers: Additional HTTP headers.
        media_type: Response media type. Default: "text/event-stream".
        background: Background task to run after response completes.
        ping: Ping interval in seconds. Default: 15. Set to 0 to disable
            keep-alive pings entirely (no ping task is started).
        sep: Line separator for SSE messages ("\r\n", "\r", or "\n").
        ping_message_factory: Callable returning custom ping ServerSentEvent.
        data_sender_callable: Async callable for push-based data sending.
        send_timeout: Timeout in seconds for individual data or heartbeat sends.
        client_close_handler_callable: Async callback on client disconnect.
        shutdown_event: Optional ``anyio.Event`` set by the library when server
            shutdown is detected. Generators can watch this event to send farewell
            messages and exit cooperatively instead of receiving CancelledError.
        shutdown_grace_period: Seconds to wait after setting ``shutdown_event``
            before force-cancelling the generator. Must be >= 0. Should be less
            than your ASGI server's graceful shutdown timeout. Default: 0
            (immediate cancel, identical to pre-v3.3.0 behavior).
    é   ú
NÚcontentÚstatus_codeÚheadersÚ
media_typeÚ
backgroundÚpingÚsepÚping_message_factoryÚdata_sender_callable)NNNÚsend_timeoutÚclient_close_handler_callableÚshutdown_eventÚshutdown_grace_periodr-   c                 óZ  — |dvrt        d|› �«      ‚|xs | j                  | _        t        |t        «      r|| _        nt        |«      | _        || _        |€| j                  n|| _        || _	        |	| _
        |
| _        t        «       }|�|j                  |«       |j                  dd«       d|d<   d|d<   | j                  |«       |€| j                   n|| _        || _        || _        |d	k  rt        d
«      ‚|| _        || _        d| _        t/        j0                  «       | _        y )N)Nrj   úú
z'sep must be one of: \r\n, \r, \n, got: zCache-Controlzno-storez
keep-aliveÚ
ConnectionÚnozX-Accel-Bufferingr   z"shutdown_grace_period must be >= 0T)Ú
ValueErrorÚDEFAULT_SEPARATORrq   Ú
isinstancer   Úbody_iteratorr   rl   rn   ro   rs   rt   r   ÚupdateÚ
setdefaultÚinit_headersÚDEFAULT_PING_INTERVALÚping_intervalrr   ru   Ú_shutdown_eventÚ_shutdown_grace_periodÚactiver&   ÚLockÚ
_send_lock)Úselfrk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   Ú_headerss                  r,   Ú__init__zEventSourceResponse.__init__  s3  € ð* Ð0Ñ0ÜÐJÈ3È%ÐPÓQÐQØÒ0˜$×0Ñ0ˆŒô �gœ}Ô-Ø!(ˆDÕä!6°wÓ!?ˆDÔà&ˆÔØ-7Ð-?˜$Ÿ/š/ÀZˆŒØ$ˆŒØ$8ˆÔ!Ø(ˆÔô "Ó#ˆØÐØ�O‰O˜GÔ$ð 	×Ñ˜O¨ZÔ8à!-ˆ�ÑØ(,ˆÐ$Ñ%Ø×Ñ˜(Ô#à;?¸<˜T×7Ò7ÈTˆÔØ$8ˆÔ!à-JˆÔ*ð ! 1Ò$ÜÐAÓBÐBØ-ˆÔØ&;ˆÔ#àˆŒäŸ*™*›,ˆ�r+   c                 ó   — | j                   S ©N)Ú_ping_interval©r‹   s    r,   r…   z!EventSourceResponse.ping_interval[  s   € à×"Ñ"Ð"r+   Úvaluec                 ót   — t        |t        t        f«      st        d«      ‚|dk  rt	        d«      ‚|| _        y )Nz"ping interval must be int or floatr   z,ping interval must be >= 0 (0 disables ping))r   ÚintÚfloatÚ	TypeErrorr}   r�   )r‹   r’   s     r,   r…   z!EventSourceResponse.ping_interval_  s7   € ä˜%¤#¤u Ô.ÜÐ@ÓAÐAØ�1Š9ÜÐKÓLÐLØ#ˆÕr+   Úforcec                 ó   — t        d«      ‚)Nz-Compression is not supported for SSE streams.)ÚNotImplementedError)r‹   r—   s     r,   Úenable_compressionz&EventSourceResponse.enable_compressiong  s   € Ü!Ð"QÓRÐRr+   rN   rP   c              ƒ   óÊ   K  — t        j                  | j                  «      5 } ||«      ƒ d{  –—†  ddd«       r|j                  r
t	        «       ‚yy7 Œ&# 1 sw Y   Œ%xY w­w)z@Send one ASGI message, applying the response's per-send timeout.N)r&   Úmove_on_afterrt   Úcancel_calledrY   )r‹   rN   rP   Úcancel_scopes       r,   Ú_send_with_timeoutz&EventSourceResponse._send_with_timeoutj  s`   è ø€ ä× Ñ  ×!2Ñ!2Ó3ð 	 °|Ù�w“-×Ð÷	 ñ ˜L×6Ò6Ü"Ó$Ð$ð 7ˆ<ð  ø÷	 ð 	 üs+   ‚ A#¢A®A¯A³"A#ÁAÁA ÁA#c              ƒ   óî  K  —  |d| j                   | j                  dœ«      ƒ d{  –—†  | j                  2 3 d{  –—† }t        || j                  «      }t
        j                  d|«       	 | j                  |d|ddœ«      ƒ d{  –—†  ŒU7 Œe7 ŒR7 Œ	# t        $ r} t        | j                  dd«      }|�bt        j                  d¬	«      5  	  |«       ƒ d{  –—†7   n$# t        $ r t
        j                  d
«       Y nw xY wddd«       ‚ # 1 sw Y   ‚ xY w‚ w xY w6 | j                  4 ƒd{  –—†7   d| _         |ddddœ«      ƒ d{  –—†7   ddd«      ƒd{  –—†7   y# 1 ƒd{  –—†7  sw Y   yxY w­w)zHSend out SSE data to the client as it becomes available in the iterator.rT   ©rR   Ústatusrm   Nz	chunk: %srS   T©rR   ÚbodyÚ	more_bodyÚaclose)Úshieldz2Error closing body iterator after interrupted sendFr+   )rl   Úraw_headersr€   r   rq   ÚloggerÚdebugrŸ   ÚBaseExceptionr0   r&   ÚCancelScoper;   Ú	exceptionrŠ   rˆ   )r‹   rN   ÚdataÚchunkr¦   s        r,   Ú_stream_responsez$EventSourceResponse._stream_responser  s}  è ø€ áà-Ø×*Ñ*Ø×+Ñ+ñó
÷ 	
ð 	
ð ×,Ñ,÷ 	ð 	�$Ü   t§x¡xÓ0ˆEÜ�L‰L˜ eÔ,ðØ×-Ñ-ØØ1¸5ÈtÑTó÷ ñ ð	
øð	øðùô !ò ô ! ×!3Ñ!3°X¸tÓD�ØÐ%Ü×*Ñ*°$Ô7ñ ðÙ"(£(ŸNšNøÜ(ò Ü"×,Ñ,Ø Töðú÷ð ÷ð ú�ðúð -ð, —?‘?÷ 	Xò 	XØˆDŒKÙÐ 4¸cÐPUÑVÓW×WÑW÷	X÷ 	X÷ 	X÷ 	Xó 	Xüsã   ‚$E5¦B§E5·D»B¼D¿-E5Á-BÂBÂBÂE5ÂDÂBÂ8DÃ
D
Ã
CÃC
ÃCÃD
ÃC>	Ã;D
Ã=C>	Ã>D
Ä	DÄ
DÄ	DÄE5Ä,D/Ä-E5Ä1E ÅEÅ	E ÅE5ÅEÅE5Å E2Å&E)Å'E2Å.E5Úreceivec              ƒ   óú   K  — | j                   rg |«       ƒ d{  –—† }|d   dk(  rBd| _         t        j                  d«       | j                  r| j                  |«      ƒ d{  –—†  y| j                   rŒfyy7 Œ]7 Œ­w)uq  Watch for a disconnect message from the client.

        Divergence #1 (see module docstring): kept unconditionally instead of
        adopting Starlette's ASGI 2.4 ``OSError â†’ ClientDisconnect`` fast path,
        because this loop drives ``client_close_handler_callable`` and flips
        ``self.active = False`` for ``_ping`` and the shutdown grace loop.
        NrR   zhttp.disconnectFz+Got event: http.disconnect. Stop streaming.)rˆ   r©   rª   ru   )r‹   r±   rP   s      r,   Ú_listen_for_disconnectz*EventSourceResponse._listen_for_disconnect–  sl   è ø€ ð �kŠkÙ#›I—oˆGØ�v‰Ð"3Ò3Ø#�”Ü—‘ÐJÔKØ×5Ò5Ø×<Ñ<¸WÓE×EÐEØð �k�kØ%øð
 Fús(   ‚A;™A7šAA;Á"A9Á#A;Á5A;Á9A;c               ƒ   óº  K  — t         j                  ryt        «        t        «       } t	        j
                  «       }| j                  j                  |«       	 t         j                  r	 | j                  j                  |«       y|j                  «       ƒ d{  –—†  | j                  j                  |«       y7 Œ # | j                  j                  |«       w xY w­w)z0Wait for shutdown signal via the shared watcher.N)
r@   r6   rM   r3   r&   r'   r   ÚaddÚdiscardÚwait)r2   rE   s     r,   Ú_listen_for_exit_signalz+EventSourceResponse._listen_for_exit_signal§  sŸ   è ø€ ô × Ò Øä,Ô.ä#Ó%ˆÜ—‘“ˆØ�‰×Ñ˜Ôð	(ä×$Ò$Øð �L‰L× Ñ  Õ'ð —*‘*“,×Ðà�L‰L× Ñ  Õ'ð ùà�L‰L× Ñ  Õ'üs<   ‚ACÁB; Á)CÂB; ÂB9ÂB; ÂCÂ9B; Â;CÃCc              ƒ   ó„  K  — | j                  «       ƒ d{  –—†  | j                  r| j                  j                  «        | j                  dkD  r_t	        j
                  | j                  «      5  | j                  r*t	        j                  d«      ƒ d{  –—†  | j                  rŒ*ddd«       yy7 Œ™7 Œ# 1 sw Y   yxY w­w)a~  Wait for shutdown signal, then optionally give generator a grace period.

        Issue #167: When a shutdown_event is provided, the library sets it before
        returning, giving the generator a chance to send farewell events and exit
        cooperatively. The shutdown_grace_period controls how long to wait before
        force-cancelling via task group cancellation.
        Nr   gš™™™™™¹?)r¸   r†   r%   r‡   r&   rœ   rˆ   rB   r‘   s    r,   Ú"_listen_for_exit_signal_with_gracez6EventSourceResponse._listen_for_exit_signal_with_grace»  s§   è ø€ ð ×*Ñ*Ó,×,Ð,ð ×ÒØ× Ñ ×$Ñ$Ô&ð ×&Ñ&¨Ò*Ü×$Ñ$ T×%@Ñ%@ÓAñ +Ø—k’kÜŸ+™+ cÓ*×*Ð*ð —k“k÷+ð +ð +ð 	-øð +ø÷+ð +üs:   ‚C –B0—AC Á/%B4ÂB2ÂB4Â&C Â2B4Â4B=Â9C c              ƒ   óp  K  — | j                   �rt        j                  | j                  «      ƒ d{  –—†  | j                  r| j	                  «       n:t        dt        j                  t        j                  «      › �| j                  ¬«      }t        || j                  «      }t        j                  d|«       | j                  4 ƒd{  –—†  | j                   r| j                  |d|ddœ«      ƒ d{  –—†  ddd«      ƒd{  –—†  | j                   r�Œyy7 Œæ7 ŒP7 Œ(7 Œ# 1 ƒd{  –—†7  sw Y   Œ*xY w­w)a®  Periodically send ping messages to keep the connection alive on proxies.
        - frequency ca every 15 seconds.
        - Alternatively one can send periodically a comment line (one starting with a ':' character)

        Invariant (Issue #206): must NOT be started when ``ping_interval == 0``
        (ping disabled), because ``anyio.sleep(0)`` is a bare checkpoint and the
        loop would busy-spin, flooding the client with pings and contending for
        ``_send_lock`` with the data stream. ``__call__`` skips the task instead
        of returning early here, since ``_ping`` runs under ``cancel_on_finish``
        and any return would tear down the whole response.
        Nzping - )Úcommentrq   zping: %srS   Tr£   )rˆ   r&   rB   r�   rr   r   r   Únowr   Úutcrq   r   r©   rª   rŠ   rŸ   )r‹   rN   Ússe_pingÚ
ping_bytess       r,   Ú_pingzEventSourceResponse._pingÏ  s  è ø€ ð �k‹kÜ—+‘+˜d×1Ñ1Ó2×2Ð2ð ×,Ò,ð ×)Ñ)Ô+ä$Ø%¤h§l¡l´8·<±<Ó&@Ð%AÐBÈÏÉôð ô & h°·±Ó9ˆJÜ�L‰L˜ ZÔ0à—‘÷ ñ Ø—;’;ð ×1Ñ1Øà$8Ø$.Ø)-ñó÷ ð ÷÷ ð �kŽkØ2øðøðøðø÷ ÷ ñ üsp   ‚0D6²D³BD6Ã
DÃD6Ã&D!Ã4DÃ5D!Ã9D6ÄDÄD6ÄD6ÄD6ÄD!ÄD6Ä!D3Ä'D*Ä(D3Ä/D6Úscopec              ƒ   óâ  ‡ ‡‡‡K  — |d   dk(  rt        ‰«      Š|d   dk(  r‹|d   j                  «       dk(  ru‰ j                  ‰d‰ j                  ‰ j                  dœ«      ƒ d{  –—†  ‰ j                  ‰d	d
ddœ«      ƒ d{  –—†  ‰ j
                  �‰ j                  «       ƒ d{  –—†  yt        «       5  t        j                  «       4 ƒd{  –—† Šdt        g t        d   f   fˆfd„}‰j                  |ˆ ˆfd„«       ‰ j                  dkD  r‰j                  |ˆ ˆfd„«       ‰j                  |‰ j                  «       ‰ j                  r‰j                  ‰ j                  «       ‰j                  |ˆˆ fd„«       ddd«      ƒd{  –—†  ddd«       ‰ j
                  �‰ j                  «       ƒ d{  –—†  yy7 �ŒZ7 �Œ?7 �Œ7 Œ÷7 Œ=# 1 ƒd{  –—†7  sw Y   ŒMxY w# 1 sw Y   ŒQxY w7 Œ4­w)a  Entrypoint for Starlette's ASGI contract. We spin up tasks:
        - _stream_response to push events
        - _ping to keep the connection alive
        - _listen_for_exit_signal to respond to server shutdown
        - _listen_for_disconnect to respond to client disconnect
        rR   Ú	websocketÚhttpÚmethodÚHEADrT   r¡   NrS   r+   Fr£   Úcoroc              “   ód   •K  —  | «       ƒ d {  –—†  ‰j                   j                  «        y 7 Œ­wr�   )rž   Úcancel)rÈ   Ú
task_groups    €r,   Úcancel_on_finishz6EventSourceResponse.__call__.<locals>.cancel_on_finish,  s'   øè ø€ Ù›&—L�LØ×+Ñ+×2Ñ2Õ4ð !ús   ƒ0Ž.� 0c                  ó&   •— ‰ j                  ‰«      S r�   )r°   ©r‹   rN   s   €€r,   ú<lambda>z.EventSourceResponse.__call__.<locals>.<lambda>1  s   ø€ ¨d×.CÑ.CÀDÓ.I€ r+   r   c                  ó&   •— ‰ j                  ‰«      S r�   )rÁ   rÎ   s   €€r,   rÏ   z.EventSourceResponse.__call__.<locals>.<lambda>5  s   ø€ ÀDÇJÁJÈtÓDT€ r+   c                  ó&   •— ‰j                  ‰ «      S r�   )r³   )r±   r‹   s   €€r,   rÏ   z.EventSourceResponse.__call__.<locals>.<lambda>?  s   ø€ ¨d×.IÑ.IÈ'Ó.R€ r+   )rW   ÚupperrŸ   rl   r¨   ro   r   r&   Úcreate_task_groupr
   r	   Ú
start_soonr�   rº   rs   )r‹   rÂ   r±   rN   rÌ   rË   s   ` `` @r,   Ú__call__zEventSourceResponse.__call__ü  sð  ûè ø€ ð �‰=˜KÒ'Ü.¨tÓ4ˆDð �‰=˜FÒ" u¨X¡×'<Ñ'<Ó'>À&Ò'HØ×)Ñ)Øà1Ø"×.Ñ.Ø#×/Ñ/ñó÷ ð ð ×)Ñ)ØÐ3¸SÈuÑUó÷ ð ð �‰Ð*Ø—o‘oÓ'×'Ð'Øô
  Ó!ñ 	Ü×.Ñ.Ó0÷ ð °Jð5´¸"¼iÈ¹oÐ:MÑ1Nõ 5ð ×%Ñ%Ø$Ô&Iôð ×&Ñ&¨Ò*Ø×)Ñ)Ð*:Ô<TÔUØ×%Ñ%Ø$ d×&MÑ&Môð ×,Ò,Ø×)Ñ)¨$×*CÑ*CÔDð ×%Ñ%Ø$Ô&Rô÷)÷ ÷	ð2 �?‰?Ð&Ø—/‘/Ó#×#Ñ#ð 'ðWùðùð (ùðøð ø÷ ÷ ñ ú÷	ð 	úð4 $ús£   †AG/Á%F?Á&G/ÂGÂ#G/Â'GÂ(G/Â7G!ÃGÃG!ÃB-GÆG!ÆG
ÆG!Æ'G/Æ8G-Æ9G/ÇG/ÇG/ÇG!Ç
G!ÇG	ÇGÇG	ÇG!Ç!G*Ç&G/)éÈ   Nztext/event-streamNNNNNNNNr   )F©r-   N)&r!   r"   r#   r$   r„   r~   ÚContentStreamr”   r   r   Ústrr   r   r•   r
   r   r   r   r	   r&   r'   r�   Úpropertyr…   Úsetterr)   rš   r   rŸ   r°   r   r³   re   r¸   rº   rÁ   r   rÕ   r*   r+   r,   rh   rh   ö   sQ  „ ñð0 ÐØÐð
 Ø/3Ø-Ø/3Ø,0Ø!ØHLð Ø(,ð Ø04Ø'(ñ%G'àðG'ð ðG'ð ˜' # s (Ñ+Ñ,ð	G'ð
 ðG'ð ˜^Ñ,ðG'ð �u˜S %˜ZÑ(Ñ)ðG'ð �c‰]ðG'ð ' x°°OÐ0CÑ'DÑEðG'ð 'Ø�R˜Ð#3Ñ4Ð4Ñ5ñ
ðG'ð ˜u‘oðG'ð (0Ø�g�Y 	¨$¡Ð/Ñ0ñ(
ðG'ð" ! §¡Ñ-ð#G'ð$  %ð%G'ð& 
ó'G'ðR ð#˜u S¨% ZÑ0ò #ó ð#ð ×Ñð$ 5¨¨e¨Ñ#4ð $¸ò $ó ð$ñS¨ð S¸ó Sð%¨Tð %¸Gð %Èó %ð"X¨4ð "X°Dó "XðH°Gð Àó ð" ò(ó ð(ó&+ð(+ ð +¨ó +ðZG$ Eð G$°Gð G$À4ð G$ÈDô G$r+   rh   r×   )Dr$   rH   Úloggingr7   Ú	threadingÚdataclassesr   r   r   r   Útypingr   r   r	   r
   r   r   r   r   r   r   r&   Ústarlette.backgroundr   Ústarlette.concurrencyr   Ústarlette.datastructuresr   Ústarlette.responsesr   Ústarlette.typesr   r   r   r   Ússe_starlette._utilsr   Ússe_starlette.eventr   r   Ú	getLoggerr!   r©   r   Úlocalr1   r3   r>   rF   rM   rW   ÚTimeoutErrorrY   r@   Úuvicorn.mainrf   rd   r[   ÚImportErrorrª   rÙ   ÚbytesÚdictÚContentÚSyncContentStreamÚAsyncContentStreamrØ   rh   r*   r+   r,   ú<module>rñ      s^  ðñ!óF Û Û Û ß (ß '÷÷ ÷ ó Ý /Ý 7Ý 3Ý (ß 9Ó 9å 3ß =ð 
ˆ×	Ñ	˜8Ó	$€ð ÷"ð "ó ð"ð  �	—‘Ó!€ð˜^ó òó.%&óP
*ð dð ¨tó ô$	�|ô 	÷#8ñ #8ðLÝ#à!'×!3Ñ!3€IÔØ"×.Ñ.€FÔð ��U˜D /°3Ð6Ñ
7€Ø˜WÑ%Ð Ø" 7Ñ+Ð ØÐ(Ð*;Ð;Ñ<€ôM$˜(õ M$øð ò Ø
‡L�LØRöðús   Ã(D! Ä!D:Ä9D: