
    gU                       U d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZm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+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJ dd lKmLZL dd!lMmNZN dd"lOmPZP dd#lQmRZR dd$lSmTZT dd%lUmVZV dd&lWmXZX dd'lYmZZZ dd(l[m\Z\ dd)l]m^Z^ dd*l_m`Z` dd+lambZb dd,lcmdZd dd-lemfZf dd.lgmhZh dd/limjZj dd0lkmlZl dd1lmmnZn dd2lompZp dd3lqmrZr dd4lsmtZt dd5lumvZv dd6lwmxZx dd7lymzZz dd8l{m|Z| dd9l}m~Z~ dd:lmZmZ dd;lmZ dd<lmZ dd=lmZ dd>lmZ e	rdd?lmZ dd@lmZ ddAlmZ dBZdCedD<    edE      ZeZdFedG<   ee   ZdFedH<   dIadJedK<   dQdLZ G dM dNgeeZe#e%e\e^e`ebede'efe-e/eje1e3e5e+e7e9e;e?eFeDeHeJeleneLeNe)ePepetereveRe=eTexezeVe|e!eXeh ZdRdOZ	 	 	 	 	 	 	 	 dSdPZy)Tz@Allows us to create and absorb changes (aka Deltas) to elements.    )annotationsN)Iterable)deepcopy)TYPE_CHECKINGAnyCallableFinalLiteralNoReturnTypeVarcast)	TypeAlias)cli_utilconfigcursorenv_utilloggerruntimeutil)context_dg_stack"get_last_dg_added_to_context_stack)
AlertMixin)
ArrowMixin)BalloonsMixin)
BokehMixin)	CodeMixin)PydeckMixin)	HelpMixin)
EmptyMixin)ExceptionMixin)	FormMixin)GraphvizMixin)HeadingMixin)	HtmlMixin)IframeMixin)
ImageMixin)	JsonMixin)LayoutsMixin)FormDatacurrent_form_id)MapMixin)MarkdownMixin)
MediaMixin)MetricMixin)PlotlyMixin)ProgressMixin)PyplotMixin)	SnowMixin)	TextMixin)
ToastMixin)VegaChartsMixin)AudioInputMixin)ButtonMixin)ButtonGroupMixin)CameraInputMixin)	ChatMixin)CheckboxMixin)ColorPickerMixin)DataEditorMixin)FileUploaderMixin)MultiSelectMixin)NumberInputMixin)
RadioMixin)SelectSliderMixin)SelectboxMixin)SliderMixin)TextWidgetsMixin)TimeWidgetsMixin)
WriteMixin)StreamlitAPIException)	Block_pb2ForwardMsg_pb2)RootContainer)caching)enqueue_message)get_script_run_ctx)Message)Cursor)AddRowsMetadatai   z
Final[int]MAX_DELTA_BYTESValuer   	BlockTypeAncestorBlockTypesFbool_use_warning_has_been_displayedc                    t         sda t        j                  ddd      } t        j                         r)t        j                  d      j                  d|  d       yt        j                         sUt        j                  d      r?t        j                  d	   }t        j                  d      j                  d|  d
| d       yyyy)zPrint a warning if Streamlit is imported but not being run with `streamlit run`.
    The warning is printed only once, and is printed using the root logger.
    TzWarning:yellow)boldfgrootz
  z to view a Streamlit app on a browser, use Streamlit in a file and
  run it with the following command:

    streamlit run [FILE_NAME] [ARGUMENTS]z#global.showWarningOnDirectExecutionr   zb to view this Streamlit app on a browser, run it with the following
  command:

    streamlit run z [ARGUMENTS]N)rW   r   style_for_clir   is_replr   
get_loggerwarningr   existsr   
get_optionsysargv)r`   script_names     N/var/www/openai/venv/lib/python3.12/site-packages/streamlit/delta_generator.py_maybe_print_use_warningrg   x   s     +*.'(($8Lf%--wi  * * !f&7&71'
 ((1+Kf%--wi  BBM O'
! +    c                  j   e Zd ZdZej
                  dddf	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 ddZ	e
dd       Ze
dd       Zdd	Zd
 Ze
dd       Ze
dd       Z	 	 	 	 ddZe
dd       Ze
dd       Ze
dd       ZddZ	 	 d	 	 	 	 	 	 	 	 	 d dZ ej0                         df	 	 	 	 	 d!dZy)"DeltaGeneratoraG  Creator of Delta protobuf messages.

    Parameters
    ----------
    root_container: BlockPath_pb2.BlockPath.ContainerValue or None
      The root container for this DeltaGenerator. If None, this is a null
      DeltaGenerator which doesn't print to the app at all (useful for
      testing).

    cursor: cursor.Cursor or None
      This is either:
      - None: if this is the running DeltaGenerator for a top-level
        container (MAIN or SIDEBAR)
      - RunningCursor: if this is the running DeltaGenerator for a
        non-top-level container (created with dg.container())
      - LockedCursor: if this is a locked DeltaGenerator returned by some
        other DeltaGenerator method. E.g. the dg returned in dg =
        st.text("foo").

    parent: DeltaGenerator
      To support the `with dg` notation, DGs are arranged as a tree. Each DG
      remembers its own parent, and the root of the tree is the main DG.

    block_type: None or "vertical" or "horizontal" or "column" or "expandable"
      If this is a block DG, we track its type to prevent nested columns/expanders

    Nc                :   ||||j                   k7  rt        d      || _        || _        || _        || _        d| _        | j                  j                  D ]A  }|j                  j                         D ]"  \  }}t        |      s| j                  |_        $ C y)am  Inserts or updates elements in Streamlit apps.

        As a user, you should never initialize this object by hand. Instead,
        DeltaGenerator objects are initialized for you in two places:

        1) When you call `dg = st.foo()` for some method "foo", sometimes `dg`
        is a DeltaGenerator object. You can call methods on the `dg` object to
        update the element `foo` that appears in the Streamlit app.

        2) This is an internal detail, but `st.sidebar` itself is a
        DeltaGenerator. That's why you can call `st.sidebar.foo()` to place
        an element `foo` inside the sidebar.

        NzHDeltaGenerator root_container and cursor.root_container must be the same)root_containerRuntimeError_root_container_provided_cursor_parent_block_type
_form_data	__class__	__bases____dict__itemscallable
__module__)selfrl   r   parent
block_typemixin_funcs           rf   __init__zDeltaGenerator.__init__   s    0 &"&"7"77Z   . !'% ,0 ^^--E >>//14D>&*ooDO 2 .rh   c                ,    t        j                  |       S N)r   repr_ry   s    rf   __repr__zDeltaGenerator.__repr__  s    zz$rh   c                Z    t        j                  t        j                         | fz          y r   r   setgetr   s    rf   	__enter__zDeltaGenerator.__enter__  s!    -113tg=>rh   c                X    t        j                  t        j                         d d        y)NFr   )ry   typevalue	tracebacks       rf   __exit__zDeltaGenerator.__exit__!  s(     	-113CR89 rh   c                @    | | j                   k(  rt               }||S | S )zReturn the DeltaGenerator that's currently 'active'.
        If we are the main DeltaGenerator, and are inside a `with` block that
        creates a container, our active_dg is that container. Otherwise,
        our active_dg is self.
        )_main_dgr   )ry   last_context_stack_dgs     rf   
_active_dgzDeltaGenerator._active_dg.  s/     4==  %G$H!$0,, rh   c                J    | j                   r| j                   j                  S | S )zReturn this DeltaGenerator's root - that is, the top-level ancestor
        DeltaGenerator that we belong to (this generally means the st._main
        DeltaGenerator).
        )rp   r   r   s    rf   r   zDeltaGenerator._main_dg@  s     )-t||$$>$>rh   c           	          dd l }t        |      D cg c]  }t        t        ||            s| c}d fd}|S c c}w )Nr   c                     v rEj                   t        j                  k(  rd d d}t        |      d d d}t        |      d d}t        |      )NzMethod `z6()` does not exist for `st.sidebar`. Did you mean `st.z()`?zB()` does not exist for `DeltaGenerator` objects. Did you mean `st.`z%()` is not a valid Streamlit command.)rn   rK   SIDEBARrH   )argskwargsmessagenamery   streamlit_methodss      rf   wrapperz+DeltaGenerator.__getattr__.<locals>.wrapperO  s    ((''=+@+@@"4& )::>tE  (00 #4& )#fD*  (00 dV#HI'00rh   )r   r   r   r   returnr   )	streamlitdirrw   getattr)ry   r   stmethod_namer   r   s   ``   @rf   __getattr__zDeltaGenerator.__getattr__H  sE     ,/r7
+2Khwr;?W6XK7
	1$ -
s
   AAc                    t        | j                  t        | j                        t        | j                        | j
                        }t        | j                        |_        |S )Nrl   r   rz   r{   )rj   rn   r   _cursorrp   rq   rr   )ry   _memodgs      rf   __deepcopy__zDeltaGenerator.__deepcopy__c  sM    //DLL)DLL)''	
 !1	rh   c              #  <   K   | }|| |j                   }|y y wr   )rp   )ry   
current_dgs     rf   
_ancestorszDeltaGenerator._ancestorsm  s*     ,0
$#++J $s   c              #  d   K   | j                   D ]  }|j                  |j                    yw)znIterate all the block types used by this DeltaGenerator and all
        its ancestor DeltaGenerators.
        N)r   rq   )ry   as     rf   _ancestor_block_typesz$DeltaGenerator._ancestor_block_typest  s*     
 A}}(mm# !s   00c                &    t        d |D              S )Nc              3  ,   K   | ]  }|d k(  s	d  yw)column   N ).0ancestor_blocks     rf   	<genexpr>z>DeltaGenerator._count_num_of_parent_columns.<locals>.<genexpr>  s      
$8.Nh<VA$8s   
)sum)ry   ancestor_block_typess     rf   _count_num_of_parent_columnsz+DeltaGenerator._count_num_of_parent_columns}  s      
$8
 
 	
rh   c                p    | j                   t        j                  | j                        S | j                   S )zReturn our Cursor. This will be None if we're not running in a
        ScriptThread - e.g., if we're running a "bare" script outside of
        Streamlit.
        )ro   r   get_container_cursorrn   r   s    rf   r   zDeltaGenerator._cursor  s3       (..t/C/CDD(((rh   c                    | j                   d u S r   )ro   r   s    rf   _is_top_levelzDeltaGenerator._is_top_level  s    $$,,rh   c                *    t        t        |             S r   )stridr   s    rf   r   zDeltaGenerator.id  s    2d8}rh   c                t    | j                   }|j                  t        |j                  j                        S dS )a  Returns the element's delta path as a string like "[0, 2, 3, 1]".

        This uniquely identifies the element's position in the front-end,
        which allows (among other potential uses) the MediaFileManager to maintain
        session-specific maps of MediaFile objects placed with their "coordinates".

        This way, users can (say) use st.image with a stream of different images,
        and Streamlit will expire the older images and replace them in place.
        z[])r   r   r   
delta_path)ry   r   s     rf   _get_delta_path_strz"DeltaGenerator._get_delta_path_str  s0     __-/ZZ-Cs2::(()MMrh   c                   | j                   }t               }|r"|j                  rt        |      rt	        d      t                t        j                         }t        |j                  j                  |      }|j                  |       d}	|j                  F|j                  :|j                  j                  |j                  j                  dd t!        |       d}	|	rD|j                  |j                  j#                  ||      nd}
t%        |j                  |
|      }n|}t'        j(                  ||| j*                  |j*                  |j*                         |S )a|  Create NewElement delta, fill it, and enqueue it.

        Parameters
        ----------
        delta_type : str
            The name of the streamlit method being called
        element_proto : proto
            The actual proto in the NewElement type e.g. Alert/Button/Slider
        add_rows_metadata : AddRowsMetadata or None
            Metadata for the add_rows method
        user_key : str or None
            A custom key for the element provided by the user.

        Returns
        -------
        DeltaGenerator
            Return a DeltaGenerator that can be used to modify the newly-created
            element.
        zCalling `st.sidebar` in a function wrapped with `st.fragment` is not supported. To write elements to the sidebar with a fragment, call your fragment function inside a `with st.sidebar` context manager.FNT)
delta_typeadd_rows_metadata)rl   r   rz   invoked_dg_id
used_dg_idreturned_dg_id)r   rN   current_fragment_id_writes_directly_to_sidebarrH   rg   rJ   
ForwardMsgr   deltanew_elementCopyFromrn   r   r   metadata_enqueue_messageget_locked_cursorrj   rL   save_element_messager   )ry   r   element_protor   user_keyr   ctxmsgmsg_el_protomsg_was_enqueued
new_cursor	output_dgs               rf   _enqueuezDeltaGenerator._enqueue  sM   6 __ "3**/J2/N'P  	!" '')syy44jAm, !)bjj.D)+)>)>CLL##A&S!# ::) 

,,)=N -    '!11!I I 	$$''uu$<<	
 rh   c           	     d   | j                   }|j                  d      }t        |j                        }t	        | ||       |j
                  |j                  |S t        j                         }|j                  j                  |j                  j                  d d  |j                  j                  j                  |       t        j                  |j
                  |j                  j                   |j                  j"                  fz         }|t$        }t'        t$         ||j
                  |||            }t)        t+        |            |_        |j                  j/                  d        t1        |       t3        j4                  || j6                  |j6                  |j6                         |S )Nr   )rl   parent_pathr   )r   r   )r   
WhichOneoflistr   _check_nested_element_violationrn   r   rJ   r   r   r   r   	add_blockr   r   RunningCursorr   indexrj   r   r)   r*   rr   r   r   rL   save_block_messager   )	ry   block_protodg_typer   r{   r   r   block_cursorblock_dgs	            rf   _blockzDeltaGenerator._block  sh    __ !++F3
#B$<$<='j:NO%);I'')%'ZZ%:%:"		$$[1
 ++--

.."**2B2B1DD
 ?$G!11#%	
 'r':; 	

$$t$<""''uu#;;		
 rh   )
rl   z
int | Noner   Cursor | Nonerz   zDeltaGenerator | Noner{   
str | Noner   None)r   r   r   r   )r   r   r   r   r   r   r   zLiteral[False])r   rj   )r   r   r   zCallable[..., NoReturn])r   zIterable[DeltaGenerator])r   rU   )r   rU   r   int)r   r   )r   rV   )NN)
r   r   r   rO   r   zAddRowsMetadata | Noner   r   r   rj   )r   zBlock_pb2.Blockr   ztype | Noner   rj   )__name__rx   __qualname____doc__rK   MAINr   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   rI   Blockr   r   rh   rf   rj   rj      s   `B &3%7%7 $(,!%36"36 36 &	36
 36 
36j ?  	
 
  " ? ?6 , , $ $
$6
	
 ) ) - -  N$ 59#SS S 2	S
 S 
Sn (7y'8#:$: : 
	:rh   rj   c                    t        d | j                  D              }t        t        t	        | j
                                    }|xr | S )Nc              3  V   K   | ]!  }|j                   t        j                  k(   # y wr   )rn   rK   r   )r   r   s     rf   r   z._writes_directly_to_sidebar.<locals>.<genexpr>8  s"     WAQ&&-*?*??s   '))anyr   rV   lenr   r   )r   
in_sidebarhas_containers      rf   r   r   7  s>    WWWJT"":":;<=M+m++rh   c                $   |dk(  rN| j                  |      }| j                  t        j                  k(  r|dkD  rt	        d      |dkD  rt	        d      |dk(  r||v rt	        d      |dk(  r||v rt	        d	      |d
k(  r||v rt	        d      yy)zCheck if elements are nested in a forbidden way.

    Raises
    ------
      StreamlitAPIException: throw if an invalid element nesting is detected.
    r   r   zpColumns cannot be placed inside other columns in the sidebar. This is only possible in the main area of the app.r   zKColumns can only be placed inside other columns up to one level of nesting.chat_messagez7Chat messages cannot nested inside other chat messages.
expandablez3Expanders may not be nested inside other expanders.popoverz1Popovers may not be nested inside other popovers.N)r   rn   rK   r   rH   )r   r{   r   num_of_parent_columnss       rf   r   r   =  s     X " ? ?@T U!6!66;PST;T' C  !1$']  ^#
6J(J#E
 	
 \!j4H&H#A
 	
 Y:1E#E#$WXX $Frh   r   )r   rj   r   rV   )r   rj   r{   r   r   zlist[BlockType]r   r   )r   
__future__r   rc   collections.abcr   copyr   typingr   r   r   r	   r
   r   r   r   typing_extensionsr   r   r   r   r   r   r   r   r   $streamlit.delta_generator_singletonsr   r   streamlit.elements.alertr   streamlit.elements.arrowr   streamlit.elements.balloonsr   streamlit.elements.bokeh_chartr   streamlit.elements.coder   %streamlit.elements.deck_gl_json_chartr   streamlit.elements.doc_stringr   streamlit.elements.emptyr   streamlit.elements.exceptionr    streamlit.elements.formr!   !streamlit.elements.graphviz_chartr"   streamlit.elements.headingr#   streamlit.elements.htmlr$   streamlit.elements.iframer%   streamlit.elements.imager&   streamlit.elements.jsonr'   streamlit.elements.layoutsr(   !streamlit.elements.lib.form_utilsr)   r*   streamlit.elements.mapr+   streamlit.elements.markdownr,   streamlit.elements.mediar-   streamlit.elements.metricr.   streamlit.elements.plotly_chartr/   streamlit.elements.progressr0   streamlit.elements.pyplotr1   streamlit.elements.snowr2   streamlit.elements.textr3   streamlit.elements.toastr4   streamlit.elements.vega_chartsr5   &streamlit.elements.widgets.audio_inputr6   !streamlit.elements.widgets.buttonr7   'streamlit.elements.widgets.button_groupr8   'streamlit.elements.widgets.camera_inputr9   streamlit.elements.widgets.chatr:   #streamlit.elements.widgets.checkboxr;   'streamlit.elements.widgets.color_pickerr<   &streamlit.elements.widgets.data_editorr=   (streamlit.elements.widgets.file_uploaderr>   &streamlit.elements.widgets.multiselectr?   'streamlit.elements.widgets.number_inputr@    streamlit.elements.widgets.radiorA   (streamlit.elements.widgets.select_sliderrB   $streamlit.elements.widgets.selectboxrC   !streamlit.elements.widgets.sliderrD   'streamlit.elements.widgets.text_widgetsrE   'streamlit.elements.widgets.time_widgetsrF   streamlit.elements.writerG   streamlit.errorsrH   streamlit.protorI   rJ   !streamlit.proto.RootContainer_pb2rK   streamlit.runtimerL   streamlit.runtime.scriptrunnerrM   r   rN   google.protobuf.messagerO   streamlit.cursorrP   +streamlit.elements.lib.built_in_chart_utilsrQ   rR   __annotations__rS   r   rT   rU   rW   rg   rj   r   r   r   rh   rf   <module>rC     sx   G " 
 $ 	 	 	 (   0 / 5 5 - = 3 / 7 - ; 3 - 1 / - 3 G + 5 / 1 7 5 1 - - / : B 9 D D 5 = D B F C D 7 F ? 9 D D / 2 5 ; % N =/'K. . 	9  ( 3 I 3 ).  -<^^^ ^ 	^
 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  !^" #^$ %^& '^( )^* +^, -^. /^0 1^2 3^4 5^6 7^8 9^: ;^< =^> ?^@ A^B C^D E^F G^H I^J K^L M^N O^P Q^R S^T U^V W^X Y^Z [^\ ]^B,YY$.YFUY	Yrh   