Ë
    úmxiè1  ã                  ó*  — d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZ e
rd d	lmZ  G d
„ de«      Z ed¬«       G d„ d«      «       Z ed¬«       G d„ d«      «       Z	 	 	 	 	 	 dd„Z	 	 	 	 	 	 dd„Z G d„ d«      Zy)é    )ÚannotationsN)Ú	dataclassÚfieldÚreplace)ÚEnum)ÚTYPE_CHECKINGÚcast)Úutil)ÚChatInputValue)ÚWidgetStateÚWidgetStates)ÚContextInfoc                  ó   — e Zd ZdZdZdZy)ÚScriptRequestTypeÚCONTINUEÚSTOPÚRERUNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   © ó    úk/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner_utils/script_requests.pyr   r      s   „ à€Hð
 €Dð �Er   r   T)Úfrozenc                  óÂ   — e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   dZ	d
ed<    e
e¬«      Zded<   dZded<   dZded<    e
e¬«      Zded<   dZded<   dd„Zy)Ú	RerunDataz+Data attached to RERUN requests. Immutable.Ú ÚstrÚquery_stringNúWidgetStates | NoneÚwidget_statesÚpage_script_hashÚ	page_namez
str | NoneÚfragment_id)Údefault_factoryú	list[str]Úfragment_id_queueFÚboolÚis_fragment_scoped_rerunÚis_auto_rerunzset[str]Úcached_message_hasheszContextInfo | NoneÚcontext_infoc                ó,   — t        j                  | «      S ©N©r
   Úrepr_©Úselfs    r   Ú__repr__zRerunData.__repr__A   ó   € Ü�z‰z˜$ÓÐr   ©Úreturnr   )r   r   r   Ú__doc__r   Ú__annotations__r!   r"   r#   r$   r   Úlistr'   r)   r*   Úsetr+   r,   r3   r   r   r   r   r   ,   s€   … á5à€L�#ÓØ)-€MÐ&Ó-ØÐ�cÓØ€IˆsÓð #€K�Ó"á#(¸Ô#>Ð�yÓ>Ø%*Ð˜dÓ*à€M�4Óá&+¸CÔ&@Ð˜8Ó@à'+€LÐ$Ó+ô r   r   c                  óD   — e Zd ZU dZded<   dZded<   ed	d„«       Zd
d„Zy)ÚScriptRequestz,A STOP or RERUN request and associated data.r   ÚtypeNzRerunData | NoneÚ_rerun_datac                ó|   — | j                   t        j                  urt        d«      ‚t	        d| j
                  «      S )Nz)RerunData is only set for RERUN requests.r   )r=   r   r   ÚRuntimeErrorr	   r>   r1   s    r   Ú
rerun_datazScriptRequest.rerun_dataL   s4   € à�9‰9Ô-×3Ñ3Ñ3ÜÐJÓKÐKÜ�K ×!1Ñ!1Ó2Ð2r   c                ó,   — t        j                  | «      S r.   r/   r1   s    r   r3   zScriptRequest.__repr__R   r4   r   )r6   r   r5   )	r   r   r   r7   r8   r>   ÚpropertyrA   r3   r   r   r   r<   r<   E   s-   … á6à
ÓØ$(€KÐ!Ó(àò3ó ð3ô
 r   r<   c                ó"   — t        | «      xr | S )a7  Returns whether the currently running script should be preempted due to a
    fragment rerun.

    Reruns corresponding to fragment runs that weren't caused by calls to
    `st.rerun(scope="fragment")` should *not* cancel the current script run
    as doing so will affect elements outside of the fragment.
    )r(   )r'   r)   s     r   Ú'_fragment_run_should_not_preempt_scriptrE   V   s   € ô Ð!Ó"ÒCÐ+CÐ'CÐCr   c                ó  — | s|sy| s|S |s| S |j                   D �ci c]  }|j                  |“Œ }}ddt        d¬«      fg}| j                   D ]‚  }|D ]{  \  }}|j                  d«      |k(  sŒt	        ||«      |k7  sŒ+|j                  |j                  «      }|r%|j                  d«      |k(  sŒ]t	        ||«      |k(  sŒm|||j                  <   Œ} Œ„ t        «       }	|	j                   j                  |j                  «       «       |	S c c}w )ad  Coalesce an older WidgetStates into a newer one, and return a new
    WidgetStates containing the result.

    For most widget values, we just take the latest version.

    However, any trigger_values (which are set by buttons) that are True in
    `old_states` will be set to True in the coalesced result, so that button
    presses don't go missing.
    N)Útrigger_valueFÚchat_input_value)ÚdataÚvalue)	ÚwidgetsÚidÚChatInputValueProtoÚ
WhichOneofÚgetattrÚgetr   ÚextendÚvalues)
Ú
old_statesÚ
new_statesÚwstateÚstates_by_idÚtrigger_value_typesÚ	old_stateÚtrigger_value_typeÚunset_valueÚnew_trigger_valÚ	coalesceds
             r   Ú_coalesce_widget_statesr]   d   s5  € ñ ™jØÙØÐÙØÐð )3×(:Ñ(:ö,Ø$ˆ�	‰	�6Ñð,€Lð ,ð
 	!Ø	Ô0°dÔ;Ð<ðÐð  ×'Ñ'ò ;ˆ	Ø/Bò 	;Ñ+Ð à×$Ñ$ WÓ-Ð1CÓCÜ˜IÐ'9Ó:¸kÓIà".×"2Ñ"2°9·<±<Ó"@�ñ 'ð $×.Ñ.¨wÓ7Ð;MÓMô   Ð1CÓDÈÓSà1:�L §¡Ò.ñ+	;ð;ô0 “€IØ×Ñ×Ñ˜\×0Ñ0Ó2Ô3àÐùòG,s   œDc                  ó8   — e Zd ZdZdd„Zdd„Zd	d„Zd
d„Zdd„Zy)ÚScriptRequestsz·An interface for communicating with a ScriptRunner. Thread-safe.

    AppSession makes requests of a ScriptRunner through this class, and
    ScriptRunner handles those requests.
    c                ó~   — t        j                  «       | _        t        j                  | _        t        «       | _        y r.   )Ú	threadingÚLockÚ_lockr   r   Ú_stater   r>   r1   s    r   Ú__init__zScriptRequests.__init__¤   s'   € Ü—^‘^Ó%ˆŒ
Ü'×0Ñ0ˆŒÜ$›;ˆÕr   c                óp   — | j                   5  t        j                  | _        ddd«       y# 1 sw Y   yxY w)z‘Request that the ScriptRunner stop running. A stopped ScriptRunner
        can't be used anymore. STOP requests succeed unconditionally.
        N)rc   r   r   rd   r1   s    r   Úrequest_stopzScriptRequests.request_stop©   s-   € ð �Z‰Zñ 	1Ü+×0Ñ0ˆDŒK÷	1÷ 	1ñ 	1ús   �,¬5c                ó´  — | j                   5  | j                  t        j                  k(  r
	 ddd«       y| j                  t        j                  k(  rKt        j
                  | _        |j                  rt        |d|j                  g¬«      }|| _        	 ddd«       y| j                  t        j
                  k(  rüt        | j                  j                  |j                  «      }|j                  rBg | j                  j                  ¢}|j                  |vr7|j                  |j                  «       n|j                  r|j                  }ng }t        |j                  ||j                  |j                   ||j"                  |j$                  |j&                  |j(                  ¬«	      | _        	 ddd«       yt+        d| j                  › �«      ‚# 1 sw Y   yxY w)a5  Request that the ScriptRunner rerun its script.

        If the ScriptRunner has been stopped, this request can't be honored:
        return False.

        Otherwise, record the request and return True. The ScriptRunner will
        handle the rerun request as soon as it reaches an interrupt point.
        NF)r$   r'   T)	r   r!   r"   r#   r'   r+   r)   r*   r,   ú Unrecognized ScriptRunnerState: )rc   rd   r   r   r   r   r$   r   r>   r]   r!   r'   Úappendr   r   r"   r#   r+   r)   r*   r,   r@   )r2   Únew_dataÚcoalesced_statesr'   s       r   Úrequest_rerunzScriptRequests.request_rerun°   sÁ  € ð �Z‰Zñ >	QØ�{‰{Ô/×4Ñ4Ò4à÷>	Qð >	Qð
 �{‰{Ô/×8Ñ8Ò8ô 0×5Ñ5�”ð ×'Ò'Ü&Ø Ø$(Ø+3×+?Ñ+?Ð*@ô �Hð $,�Ô Ø÷)>	Qð >	Qð, �{‰{Ô/×5Ñ5Ò5ô $;Ø×$Ñ$×2Ñ2°H×4JÑ4Jó$Ð ð ×'Ò'ð )N¨$×*:Ñ*:×*LÑ*LÐ(MÐ%à×+Ñ+Ð3DÑDØ)×0Ñ0°×1EÑ1EÕFØ×/Ò/à(0×(BÑ(BÑ%ð
 )+Ð%ä#,Ø!)×!6Ñ!6Ø"2Ø%-×%>Ñ%>Ø&×0Ñ0Ø&7Ø*2×*HÑ*HØ-5×-NÑ-NØ"*×"8Ñ"8Ø!)×!6Ñ!6ô
$�Ô ð ÷w>	Qð >	Qô| Ð!AÀ$Ç+Á+ÀÐOÓPÐP÷}>	Qð >	Qús   �GµAGÂDGÆ6GÇGc                óü  — | j                   t        j                  k(  sQ| j                   t        j                  k(  r5t	        | j
                  j                  | j
                  j                  «      ry| j                  5  | j                   t        j                  k(  r€t	        | j
                  j                  | j
                  j                  «      r
	 ddd«       yt        j                  | _         t        t        j                  | j
                  «      cddd«       S | j                   t        j                  k7  rt        d| j                   › d�«      ‚t        t        j                  «      cddd«       S # 1 sw Y   yxY w)a¨  Called by the ScriptRunner when it's at a yield point.

        If we have no request or a RERUN request corresponding to one or more fragments
        (that is not a fragment-scoped rerun), return None.

        If we have a (full script or fragment-scoped) RERUN request, return the request
        and set our internal state to CONTINUE.

        If we have a STOP request, return the request and remain stopped.
        Nri   z. This should never happen.)rd   r   r   r   rE   r>   r'   r)   rc   r<   r   r@   r1   s    r   Úon_scriptrunner_yieldz$ScriptRequests.on_scriptrunner_yieldú   s/  € ð �;‰;Ô+×4Ñ4Ò4Ø�K‰KÔ,×2Ñ2Ò2Ü7Ø× Ñ ×2Ñ2Ø× Ñ ×9Ñ9ôð à�Z‰Zñ 	9Ø�{‰{Ô/×5Ñ5Ò5ô ;Ø×$Ñ$×6Ñ6Ø×$Ñ$×=Ñ=ôð  ÷	9ð 	9ô 0×8Ñ8�”Ü$Ô%6×%<Ñ%<¸d×>NÑ>NÓO÷	9ñ 	9ð �{‰{Ô/×4Ñ4Ò4Ü"Ø6°t·{±{°mÐC^Ð_óð ô !Ô!2×!7Ñ!7Ó8÷#	9÷ 	9ò 	9ús   Á<AE2Ã8E2ÄAE2Å2E;c                ó`  — | j                   5  | j                  t        j                  k(  rBt        j                  | _        t        t        j                  | j                  «      cddd«       S t        j                  | _        t        t        j                  «      cddd«       S # 1 sw Y   yxY w)aY  Called by the ScriptRunner when it's about to run its script for
        the first time, and also after its script has successfully completed.

        If we have a RERUN request, return the request and set
        our internal state to CONTINUE.

        If we have a STOP request or no request, set our internal state
        to STOP.
        N)rc   rd   r   r   r   r<   r>   r   r1   s    r   Úon_scriptrunner_readyz$ScriptRequests.on_scriptrunner_ready%  s   € ð �Z‰Zñ 	9Ø�{‰{Ô/×5Ñ5Ò5Ü/×8Ñ8�”Ü$Ô%6×%<Ñ%<¸d×>NÑ>NÓO÷	9ñ 	9ô ,×0Ñ0ˆDŒKÜ Ô!2×!7Ñ!7Ó8÷	9÷ 	9ò 	9ús   �AB$Á--B$Â$B-N)r6   ÚNone)rk   r   r6   r(   )r6   zScriptRequest | None)r6   r<   )	r   r   r   r7   re   rg   rm   ro   rq   r   r   r   r_   r_   �   s$   „ ñó'ó
1óHQóT)9ôV9r   r_   )r'   r&   r)   r(   r6   r(   )rS   r    rT   r    r6   r    )Ú
__future__r   ra   Údataclassesr   r   r   Úenumr   Útypingr   r	   Ú	streamlitr
   Ústreamlit.proto.Common_pb2r   rM   Ú streamlit.proto.WidgetStates_pb2r   r   Ústreamlit.proto.ClientState_pb2r   r   r   r<   rE   r]   r_   r   r   r   ú<module>r{      s½   ðõ #ã ß 1Ñ 1Ý ß &å Ý Lß FáÝ;ô˜ô ñ �$Ô÷ ð  ó ð ñ0 �$Ô÷ ð  ó ð ð DØ ðDà"ðDð 
óDð6Ø#ð6Ø1Dð6àó6÷rZ9ò Z9r   