Ë
    úmxi¬  ã                  óò   — U d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
mZ erddlmZ ddlmZ ddlmZ dd	lmZ  G d
„ d«      Zdd„Z e	d«      Z G d„ dee   «      Z edd„ ¬«      Zded<   dd„Zdd„Zy)zŠ
The main purpose of this module (right now at least) is to avoid a dependency
cycle between streamlit.delta_generator and some elements.
é    )Úannotations)Ú
ContextVarÚToken)ÚTYPE_CHECKINGÚGenericÚTypeVar)ÚRootContainer)ÚCallable)ÚDeltaGenerator)ÚDialog)ÚStatusContainerc                  óº   — e Zd ZU dZdZded<   edd„«       Z	 	 	 	 	 	 	 	 dd„Ze	dd„«       Z
e	dd„«       Ze	dd	„«       Ze	dd
„«       Ze		 	 dd„«       Ze	dd„«       Zy)ÚDeltaGeneratorSingletona  Used to initialize the DeltaGenerator classes and store them as singletons.
    This module allows us to avoid circular imports between DeltaGenerator and elements,
    because elements can import this singleton module instead of DeltaGenerator directly.
    NzDeltaGeneratorSingleton | NoneÚ	_instancec                óH   — | j                   €t        d«      ‚| j                   S )zŽReturn the singleton DeltaGeneratorSingleton instance. Raise an Error if the
        DeltaGeneratorSingleton hasn't been created yet.
        z,DeltaGeneratorSingleton hasn't been created!)r   ÚRuntimeError)Úclss    ú[/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/delta_generator_singletons.pyÚinstancez DeltaGeneratorSingleton.instance+   s$   € ð
 �=‰=Ð ÜÐMÓNÐNØ�}‰}Ðó    c                óŽ  — t         j                  �t        d«      ‚| t         _         |t        j                  ¬«      | _         |t        j                  | j
                  ¬«      | _         |t        j                  | j
                  ¬«      | _	         |t        j                  | j
                  ¬«      | _        || _        || _        y)aE  Registers and initializes all delta-generator classes.

        Parameters
        ----------
        delta_generator_cls : type[DeltaGenerator]
            The main DeltaGenerator class.
        status_container_cls : type[StatusContainer]
            The delta-generator class that is used as return value for `st.status`.
        dialog_container_cls : type[Dialog]
            The delta-generator class used is used as return value for `st.dialog`.

        Raises
        ------
        RuntimeError
            If the DeltaGeneratorSingleton instance already exists.
        Nz0DeltaGeneratorSingleton instance already exists!)Úroot_container)r   Úparent)r   r   r   Ú_RootContainerÚMAINÚ_main_dgÚSIDEBARÚ_sidebar_dgÚEVENTÚ	_event_dgÚBOTTOMÚ
_bottom_dgÚ_status_container_clsÚ_dialog_container_cls)ÚselfÚdelta_generator_clsÚstatus_container_clsÚdialog_container_clss       r   Ú__init__z DeltaGeneratorSingleton.__init__4   sŸ   € ô, #×,Ñ,Ð8ÜÐQÓRÐRØ,0ÔÔ)á+¼>×;NÑ;NÔOˆŒÙ.Ü)×1Ñ1¸$¿-¹-ô
ˆÔñ -Ü)×/Ñ/¸¿¹ô
ˆŒñ .Ü)×0Ñ0¸¿¹ô
ˆŒð &:ˆÔ"Ø%9ˆÕ"r   c                ó   — | j                   S ©N)r   ©r%   s    r   Úmain_dgzDeltaGeneratorSingleton.main_dg[   s   € à�}‰}Ðr   c                ó   — | j                   S r+   )r   r,   s    r   Ú
sidebar_dgz"DeltaGeneratorSingleton.sidebar_dg_   s   € à×ÑÐr   c                ó   — | j                   S r+   )r    r,   s    r   Úevent_dgz DeltaGeneratorSingleton.event_dgc   s   € à�~‰~Ðr   c                ó   — | j                   S r+   )r"   r,   s    r   Ú	bottom_dgz!DeltaGeneratorSingleton.bottom_dgg   s   € à�‰Ðr   c                ó   — | j                   S )z†Stub for StatusContainer. Since StatusContainer inherits from DeltaGenerator,
        this is used to avoid circular imports.
        )r#   r,   s    r   r'   z,DeltaGeneratorSingleton.status_container_clsk   s   € ð ×)Ñ)Ð)r   c                ó   — | j                   S )ztStub for Dialog. Since Dialog inherits from DeltaGenerator,
        this is used to avoid circular imports.
        )r$   r,   s    r   r(   z,DeltaGeneratorSingleton.dialog_container_clst   s   € ð
 ×)Ñ)Ð)r   ©Úreturnr   )r&   ztype[DeltaGenerator]r'   útype[StatusContainer]r(   útype[Dialog]r7   ÚNone)r7   r   )r7   r8   )r7   r9   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__Úclassmethodr   r)   Úpropertyr-   r/   r1   r3   r'   r(   © r   r   r   r   #   sÒ   … ñð
 15€IÐ-Ó4àòó ðð%:à1ð%:ð 4ð%:ð +ð	%:ð
 
ó%:ðN òó ðð ò ó ð ð òó ðð òó ðð ð*à	ò*ó ð*ð ò*ó ñ*r   r   c                 ó*   — t         j                  «       S )z|Return the DeltaGeneratorSingleton instance. Raise an Error if the
    DeltaGeneratorSingleton hasn't been created yet.
    )r   r   rB   r   r   Úget_dg_singleton_instancerD   |   s   € ô #×+Ñ+Ó-Ð-r   Ú_Tc                  óH   — e Zd ZdZd
d„Zdd„Zdd„Zdd„Zdd„Zdd„Z	dd„Z
y	)ÚContextVarWithLazyDefaulta˜  The dg_stack tracks the currently active DeltaGenerator, and is pushed to when
    a DeltaGenerator is entered via a `with` block. This is implemented as a ContextVar
    so that different threads or async tasks can have their own stacks.

    We have a wrapper around it because ContextVar default cannot be a function, but
    the default dg (main_dg) might not exist yet when this module is imported.
    c               ó.   — || _         || _        d | _        y r+   )Ú_nameÚ_defaultÚ_context_var)r%   ÚnameÚdefaults      r   r)   z"ContextVarWithLazyDefault.__init__�   s   € ØˆŒ
ØˆŒØ37ˆÕr   c                ó†   — | j                   €*t        | j                  | j                  «       ¬«      | _         | j                   S )N©rM   )rK   r   rI   rJ   r,   s    r   Ú_ensure_context_varz-ContextVarWithLazyDefault._ensure_context_var”   s3   € Ø×ÑÐ$Ü *¨4¯:©:¸t¿}¹}»Ô OˆDÔØ× Ñ Ð r   c                ó>   — | j                  «       j                  «       S r+   )rP   Úgetr,   s    r   rR   zContextVarWithLazyDefault.get™   s   € Ø×'Ñ'Ó)×-Ñ-Ó/Ð/r   c                ó@   — | j                  «       j                  |«      S r+   )rP   Úset)r%   Úvalues     r   rT   zContextVarWithLazyDefault.setœ   s   € Ø×'Ñ'Ó)×-Ñ-¨eÓ4Ð4r   c                óB   — | j                  «       j                  |«       y r+   )rP   Úreset)r%   Útokens     r   rW   zContextVarWithLazyDefault.resetŸ   s   € Ø× Ñ Ó"×(Ñ(¨Õ/r   c                ó6   — t        |t        «      st        S | |u S r+   )Ú
isinstancerG   ÚNotImplemented)r%   Úothers     r   Ú__eq__z ContextVarWithLazyDefault.__eq__¢   s   € Ü˜%Ô!:Ô;Ü!Ð!à�uˆ}Ðr   c                ó>   — | j                  «       j                  «       S r+   )rP   Ú__hash__r,   s    r   r_   z"ContextVarWithLazyDefault.__hash__¨   s   € Ø×'Ñ'Ó)×2Ñ2Ó4Ð4r   N)rL   ÚstrrM   zCallable[[], _T]r7   r:   )r7   zContextVar[_T])r7   rE   )rU   rE   r7   ú	Token[_T])rX   ra   r7   r:   )r\   Úobjectr7   Úbool)r7   Úint)r;   r<   r=   r>   r)   rP   rR   rT   rW   r]   r_   rB   r   r   rG   rG   †   s*   „ ñó8ó
!ó
0ó5ó0óô5r   rG   Úcontext_dg_stackc                 ó,   — t        «       j                  fS r+   )rD   r-   rB   r   r   ú<lambda>rg   °   s   € Ô-FÓ-H×-PÑ-PÐ,R€ r   rO   z5ContextVarWithLazyDefault[tuple[DeltaGenerator, ...]]c                 ó^   — t        «       } | j                  €t        d«      ‚| j                  fS )zjGet the default dg_stack value with which the dg_stack should
    be initialized and reset if needed.
    zmain_dg is not set)rD   r   r   )r   s    r   Úget_default_dg_stack_valueri   µ   s3   € ô )Ó*€HØ×ÑÐ ÜÐ/Ó0Ð0à×ÑÐÐr   c                 óR   — t         j                  «       } t        | «      dkD  r| d   S y)z Get the last added DeltaGenerator of the stack in the current context.

    Returns None if the stack has only one element or is empty for whatever reason.
    é   éÿÿÿÿN)re   rR   Úlen)Úcurrent_stacks    r   Ú"get_last_dg_added_to_context_stackro   À   s/   € ô
 %×(Ñ(Ó*€Mô ˆ=Ó˜AÒØ˜RÑ Ð Ør   Nr6   )r7   ztuple[DeltaGenerator, ...])r7   zDeltaGenerator | None)r>   Ú
__future__r   Úcontextvarsr   r   Útypingr   r   r   Ú!streamlit.proto.RootContainer_pb2r	   r   Úcollections.abcr
   Ústreamlit.delta_generatorr   Ústreamlit.elements.lib.dialogr   Ú/streamlit.elements.lib.mutable_status_containerr   r   rD   rE   rG   re   r?   ri   ro   rB   r   r   ú<module>rx      s   ðòõ
 #ç )ß 2Ñ 2å MáÝ(å8Ý4ÝO÷V*ñ V*ór.ñ ˆTƒ]€ô#5 ¨¡ô #5ñR ØÑ$Rôð ÐGó ó ôr   