
    xi$                        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
 d dlmZ erd dlmZ 	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZ ed	      Z G d
 dee         Z G d d      Z G d de      Z G d de      Zy)    )annotations)TYPE_CHECKINGAnyGenericTypeVar)util)Element)get_script_run_ctx)Iteratorc                P    | g}|j                  |       |j                  |       |S N)extendappend)root_containerparent_pathindex
delta_paths       \/var/www/html/chatbot/card-advisor-bot/venv/lib/python3.12/site-packages/streamlit/cursor.pymake_delta_pathr      s.     !!Jk"e    c                    | yt               }|y| |j                  v r|j                  |    S t        |       }||j                  | <   |S )zReturn the top-level RunningCursor for the given container.
    This is the cursor that is used when user code calls something like
    `st.foo` (which uses the main container) or `st.sidebar.foo` (which uses
    the sidebar container).
    N)r   )r
   cursorsRunningCursor)r   ctxcursors      r   get_container_cursorr   $   sU     

C
{${{>**.9F"(CKKMr   Tc                  X    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
dd	Zdd
Zy)
SparseListz<A list-like data structure that only stores non-empty items.c                    i | _         y r   _dataselfs    r   __init__zSparseList.__init__B   s	    #%
r   c                b    t        |t              r|dk  rt        d      || j                  |<   y )Nr   z0SparseList indices must be non-negative integers)
isinstanceint
IndexErrorr"   )r$   r   values      r   __setitem__zSparseList.__setitem__E   s,    %%OPP!

5r   c                Z    || j                   vrt        d| d      | j                   |   S NzIndex z	 is emptyr"   KeyErrorr$   r   s     r   __getitem__zSparseList.__getitem__K   s1    

"VE7)455zz%  r   c                X    || j                   v r| j                   |= y t        d| d      r-   r.   r0   s     r   __delitem__zSparseList.__delitem__Q   s.    DJJ

5!VE7)455r   c              #  b   K   t        | j                        D ]  }| j                  |     y wr   sortedr"   r0   s     r   __iter__zSparseList.__iter__W   s-     DJJ' 	$E**U##	$s   -/c                ,    t        | j                        S r   )lenr"   r#   s    r   __len__zSparseList.__len__\   s    4::r   c              #  f   K   t        | j                        D ]  }|| j                  |   f  yw)z2Iterate through (index, value) for filled entries.Nr5   r0   s     r   itemszSparseList.items`   s2     DJJ' 	+EE***	+s   /1c                    || j                   v S r   r!   r0   s     r   __contains__zSparseList.__contains__e   s    

""r   c                Z    dj                  d | j                         D              }d| dS )Nz, c              3  0   K   | ]  \  }}| d |   yw)z: N ).0ivs      r   	<genexpr>z&SparseList.__repr__.<locals>.<genexpr>i   s     ?$!QQCr!+?s   zSparseList({z}))joinr<   )r$   r<   s     r   __repr__zSparseList.__repr__h   s+    		?$**,??ugS))r   N)returnNone)r   r(   r*   r   rH   rI   )r   r(   rH   r   )r   r(   rH   rI   )rH   zIterator[T]rH   r(   )rH   zIterator[tuple[int, T]])r   r(   rH   boolrH   str)__name__
__module____qualname____doc__r%   r+   r1   r3   r7   r:   r<   r>   rG   rA   r   r   r   r   ?   s2    F&"!6$
+
#*r   r   c                      e Zd ZdZ	 	 d	 	 	 	 	 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edd       ZddZddZedd       Zy)Cursora|  A pointer to a delta location in the app.

    When adding an element to the app, you should always call
    get_locked_cursor() on that element's respective Cursor.

    Parameters
    ----------
    transient_index: int | None
      The running index of the transient elements.
    transient_elements: SparseList[Element] | None
      The list of active transient elements.
    Nc                F    || _         |xs t        t                  | _        y r   )_transient_indexr   r	   _transient_elements)r$   transient_indextransient_elementss      r   r%   zCursor.__init__{   s!    
 -<#5#NG9L9N r   c                ,    t        j                  |       S r   )r   repr_r#   s    r   rG   zCursor.__repr__   s    zz$r   c                    t               )zwThe top-level container this cursor lives within - either
        RootContainer.MAIN or RootContainer.SIDEBAR.
        NotImplementedErrorr#   s    r   r   zCursor.root_container   s    
 "##r   c                    t               )z0The cursor's parent's path within its container.r\   r#   s    r   r   zCursor.parent_path        "##r   c                    t               )z/The index of the Delta within its parent block.r\   r#   s    r   r   zCursor.index   r_   r   c                X    t        | j                  | j                  | j                        S )zrThe complete path of the delta pointed to by this cursor - its
        container, parent path, and index.
        )r   r   r   r   r#   s    r   r   zCursor.delta_path   s#    
 t22D4D4DdjjQQr   c                    t               r   r\   r#   s    r   	is_lockedzCursor.is_locked   s    !##r   c                    | j                   S r   )rV   r#   s    r   rX   zCursor.transient_elements   s    '''r   c                6    | j                   dS | j                   S )Nr   rU   r#   s    r   rW   zCursor.transient_index   s    ))1qLt7L7LLr   c                    t               r   r\   r$   propss     r   get_locked_cursorzCursor.get_locked_cursor   s    !##r   c                Z    | j                   	d| _         | S | xj                   dz  c_         | S )Nr      rf   r#   s    r   get_transient_cursorzCursor.get_transient_cursor   s5      ($%D!  !!Q&!r   c                    t               )zOther data in this cursor. This is a temporary measure that will go
        away when we implement improved return values for elements.

        This is only implemented in LockedCursor.
        r\   r#   s    r   ri   zCursor.props   s     "##r   )NN)rW   
int | NonerX   SparseList[Element] | NonerH   rI   rL   rJ   rH   tuple[int, ...])rH   	list[int]rH   rK   )rH   zSparseList[Element]ri   r   rH   LockedCursor)rH   rS   rH   r   )rN   rO   rP   rQ   r%   rG   propertyr   r   r   r   rc   rX   rW   rj   rm   ri   rA   r   r   rS   rS   m   s     '+9=O#O 7O 
	O  $ $ $ $ $ $ R R $ $ ( ( M M$ $ $r   rS   c                       e Zd Z	 	 	 d	 	 	 	 	 	 	 	 	 d fdZed	d       Zed
d       Zed	d       Zedd       ZddZ	 xZ
S )r   c                P    t         |   ||       || _        || _        d| _        y)a  A moving pointer to a delta location in the app.

        RunningCursors auto-increment to the next available location when you
        call get_locked_cursor() on them.

        Parameters
        ----------
        root_container: int
            The root container this cursor lives in.
        parent_path: tuple of ints
          The full path of this cursor, consisting of the IDs of all ancestors.
          The 0th item is the topmost ancestor.
        transient_index: int | None
          The running index of the transient elements.
        transient_elements: SparseList[Element]
          The list of active transient elements.

        r   N)superr%   _root_container_parent_path_index)r$   r   r   rW   rX   	__class__s        r   r%   zRunningCursor.__init__   s,    2 	*<=-'r   c                    | j                   S r   r|   r#   s    r   r   zRunningCursor.root_container       ###r   c                    | j                   S r   r}   r#   s    r   r   zRunningCursor.parent_path          r   c                    | j                   S r   r~   r#   s    r   r   zRunningCursor.index       {{r   c                     y)NFrA   r#   s    r   rc   zRunningCursor.is_locked   s    r   c                    t        d| j                  | j                  | j                  d|}| xj                  dz  c_        d | _        t        t                  | _        |S )N)r   r   r   rl   rA   )rv   r|   r}   r~   rU   r   r	   rV   )r$   ri   locked_cursors      r   rj   zRunningCursor.get_locked_cursor   sb    $ 
//))++
 	
 	q $#-g#6#8 r   )rA   NN)
r   r(   r   rr   rW   ro   rX   rp   rH   rI   rJ   rq   rt   ru   )rN   rO   rP   r%   rx   r   r   r   rc   rj   __classcell__r   s   @r   r   r      s     (*&*9= % $	
 7 
< $ $ ! !    r   r   c                       e Zd Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d	 fdZed
d       Zedd       Zed
d       Zedd       Zedd       Z	ddZ
 xZS )rv   c                ^    t         |   ||       || _        || _        || _        || _        y)aX  A locked pointer to a location in the app.

        LockedCursors always point to the same location, even when you call
        get_locked_cursor() on them.

        Parameters
        ----------
        root_container: int
            The root container this cursor lives in.
        parent_path: tuple of ints
          The full path of this cursor, consisting of the IDs of all ancestors. The
          0th item is the topmost ancestor.
        index: int
        transient_index: int | None
          The running index of the transient elements.
        transient_elements: SparseList[Element]
          The list of active transient elements.
        **props: any
          Anything else you want to store in this cursor. This is a temporary
          measure that will go away when we implement improved return values
          for elements.

        N)r{   r%   r|   r~   r}   _props)r$   r   r   r   rW   rX   ri   r   s          r   r%   zLockedCursor.__init__   s4    @ 	*<=-'r   c                    | j                   S r   r   r#   s    r   r   zLockedCursor.root_container$  r   r   c                    | j                   S r   r   r#   s    r   r   zLockedCursor.parent_path(  r   r   c                    | j                   S r   r   r#   s    r   r   zLockedCursor.index,  r   r   c                     y)NTrA   r#   s    r   rc   zLockedCursor.is_locked0  s    r   c                    | j                   S r   r   r#   s    r   ri   zLockedCursor.props4  r   r   c                    || _         | S r   r   rh   s     r   rj   zLockedCursor.get_locked_cursor8  s    r   )rA   r   NN)r   r(   r   rr   r   r(   rW   ro   rX   rp   ri   r   rH   rI   rJ   rq   rt   rw   ru   )rN   rO   rP   r%   rx   r   r   r   rc   ri   rj   r   r   s   @r   rv   rv      s     (*&*9=$$ %$ 	$
 $$ 7$ $ 
$L $ $ ! !      r   rv   N)r   r(   r   rr   r   r(   rH   rs   )r   ro   rH   zRunningCursor | None)
__future__r   typingr   r   r   r   	streamlitr   streamlit.proto.Element_pb2r	   7streamlit.runtime.scriptrunner_utils.script_run_contextr
   collections.abcr   r   r   r   r   rS   r   rv   rA   r   r   <module>r      s    # 7 7  / V(&5>A0 CL+* +*\O$ O$d;F ;|=6 =r   