o
    沪gU                     @  sp  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	rdd?lmZ dd@lmZ ddAlmZ dBZdCedD< edEZeZdFedG< ee ZdFedH< dIadJedK< d[dNdOZG dPdQ dQg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R  Zd\dSdTZd]dYdZZdS )^z@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_displayedreturnNonec                  C  s   t s=da tjdddd} t rtdd|  d dS t	 s?t
drAtjd	 }tdd|  d
| d dS dS dS dS )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)rV   r   style_for_clir   is_replr   
get_loggerwarningr   existsr   
get_optionsysargv)r`   script_name rf   U/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/delta_generator.py_maybe_print_use_warningx   s$   



rh   c                   @  s   e Zd ZdZejdddfdFddZdGddZdHddZdIddZ	e
dJddZe
dJddZdKd!d"Zd#d$ Ze
dLd&d'Ze
dMd)d*ZdNd-d.Ze
dOd/d0Ze
dPd2d3Ze
dGd4d5ZdGd6d7Z		dQdRd>d?Ze dfdSdDdEZdS )T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

    Nroot_container
int | Noner   Cursor | NoneparentDeltaGenerator | None
block_type
str | NonerW   rX   c                 C  sv   |dur|dur||j krtd|| _|| _|| _|| _d| _| jjD ]}|j	
 D ]\}}t|r7| j|_q+q$dS )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)rj   RuntimeError_root_container_provided_cursor_parent_block_type
_form_data	__class__	__bases____dict__itemscallable
__module__)selfrj   r   rm   ro   mixin_funcrf   rf   rg   __init__   s$   
zDeltaGenerator.__init__strc                 C  s
   t | S N)r   repr_r}   rf   rf   rg   __repr__  s   
zDeltaGenerator.__repr__c                 C  s   t t  | f  d S r   r   setgetr   rf   rf   rg   	__enter__  s   zDeltaGenerator.__enter__typer   value	tracebackLiteral[False]c                 C  s   t t  d d  dS )NFr   )r}   r   r   r   rf   rf   rg   __exit__!  s   zDeltaGenerator.__exit__c                 C  s    | | j krt }|dur|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.
        N)_main_dgr   )r}   last_context_stack_dgrf   rf   rg   
_active_dg.  s
   
zDeltaGenerator._active_dgc                 C  s   | 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).
        )rt   r   r   rf   rf   rg   r   @  s   zDeltaGenerator._main_dgnameCallable[..., NoReturn]c                   s4   dd l fddtD d fd	d
}|S )Nr   c                   s   g | ]}t t |r|qS rf   )r{   getattr).0method_name)strf   rg   
<listcomp>K  s
    z.DeltaGenerator.__getattr__.<locals>.<listcomp>argsr   kwargsrW   r
   c                    s\    v r$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.)rr   rJ   SIDEBARrG   )r   r   message)r   r}   streamlit_methodsrf   rg   wrapperO  s   z+DeltaGenerator.__getattr__.<locals>.wrapper)r   r   r   r   rW   r
   )	streamlitdir)r}   r   r   rf   )r   r}   r   r   rg   __getattr__H  s   
zDeltaGenerator.__getattr__c                 C  s0   t | jt| jt| j| jd}t| j|_|S )Nrj   r   rm   ro   )ri   rr   r   _cursorrt   ru   rv   )r}   _memodgrf   rf   rg   __deepcopy__c  s   zDeltaGenerator.__deepcopy__Iterable[DeltaGenerator]c                 c  s*    | }|d ur|V  |j }|d usd S d S r   )rt   )r}   
current_dgrf   rf   rg   
_ancestorsm  s   zDeltaGenerator._ancestorsrT   c                 c  s$    | j D ]}|jdur|jV  qdS )znIterate all the block types used by this DeltaGenerator and all
        its ancestor DeltaGenerators.
        N)r   ru   )r}   arf   rf   rg   _ancestor_block_typest  s   

z$DeltaGenerator._ancestor_block_typesancestor_block_typesintc                 C  s   t dd |D S )Nc                 s  s    | ]	}|d krdV  qdS )column   Nrf   )r   ancestor_blockrf   rf   rg   	<genexpr>  s    z>DeltaGenerator._count_num_of_parent_columns.<locals>.<genexpr>)sum)r}   r   rf   rf   rg   _count_num_of_parent_columns}  s   z+DeltaGenerator._count_num_of_parent_columnsc                 C  s   | j du rt| 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.
        N)rs   r   get_container_cursorrr   r   rf   rf   rg   r     s   
zDeltaGenerator._cursorrU   c                 C  s
   | j d u S r   )rs   r   rf   rf   rg   _is_top_level  s   
zDeltaGenerator._is_top_levelc                 C  s   t t| S r   )r   idr   rf   rf   rg   r     s   zDeltaGenerator.idc                 C  s    | j }|jdur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.
        Nz[])r   r   r   
delta_path)r}   r   rf   rf   rg   _get_delta_path_str  s   z"DeltaGenerator._get_delta_path_str
delta_typeelement_protorN   add_rows_metadataAddRowsMetadata | Noneuser_keyc                 C  s   | j }t }|r|jrt|rtdt  t }t|j	j
|}|| d}	|jdurB|jdurB|jj|jjdd< t| d}	|	r\|jdurQ|jj||dnd}
t|j|
|d}n|}tj||| j|j|jd |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)r   r   )rj   r   rm   invoked_dg_id
used_dg_idreturned_dg_id)r   rM   current_fragment_id_writes_directly_to_sidebarrG   rh   rI   
ForwardMsgr   deltanew_elementCopyFromrr   r   r   metadata_enqueue_messageget_locked_cursorri   rK   save_element_messager   )r}   r   r   r   r   r   ctxmsgmsg_el_protomsg_was_enqueued
new_cursor	output_dgrf   rf   rg   _enqueue  sH   

zDeltaGenerator._enqueueblock_protoBlock_pb2.Blockdg_typetype | Nonec           	      C  s   | j }|d}t|j}t| || |jd u s|jd u r|S t }|jj	|j
j	d d < |jj| tj|j|jj|jjf d}|d u rIt}tt||j|||d}tt||_|jjd d t| tj|| j|j|jd |S )Nr   )rj   parent_pathr   )r   r   )r   
WhichOneoflistr   _check_nested_element_violationrr   r   rI   r   r   r   r   	add_blockr   r   RunningCursorr   indexri   r   r(   r)   rv   r   r   rK   save_block_messager   )	r}   r   r   r   ro   r   r   block_cursorblock_dgrf   rf   rg   _block  sD   

zDeltaGenerator._block)
rj   rk   r   rl   rm   rn   ro   rp   rW   rX   )rW   r   rW   rX   )r   r   r   r   r   r   rW   r   )rW   ri   )r   r   rW   r   )rW   r   )rW   rT   )r   rT   rW   r   )rW   rl   )rW   rU   )NN)
r   r   r   rN   r   r   r   rp   rW   ri   )r   r   r   r   rW   ri   )__name__r|   __qualname____doc__rJ   MAINr   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   rH   Blockr   rf   rf   rf   rg   ri      sD    0!
5






Wri   r   c                 C  s0   t dd | jD }ttt| j}|o| S )Nc                 s  s    | ]	}|j tjkV  qd S r   )rr   rJ   r   )r   r   rf   rf   rg   r   8  s    z._writes_directly_to_sidebar.<locals>.<genexpr>)anyr   rU   lenr   r   )r   
in_sidebarhas_containerrf   rf   rg   r   7  s   
r   ro   rp   r   list[BlockType]c                 C  s   |dkr|  |}| jtjkr|dkrtd|dkrtd|dkr+||v r+td|dkr7||v r7td	|d
krC||v rEtddS dS )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   rr   rJ   r   rG   )r   ro   r   num_of_parent_columnsrf   rf   rg   r   =  s*   

r   r   )r   ri   rW   rU   )r   ri   ro   rp   r   r   rW   rX   )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.progressr/   streamlit.elements.pyplotr0   streamlit.elements.snowr1   streamlit.elements.textr2   streamlit.elements.toastr3   streamlit.elements.vega_chartsr4   &streamlit.elements.widgets.audio_inputr5   !streamlit.elements.widgets.buttonr6   'streamlit.elements.widgets.button_groupr7   'streamlit.elements.widgets.camera_inputr8   streamlit.elements.widgets.chatr9   #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.radior@   (streamlit.elements.widgets.select_sliderrA   $streamlit.elements.widgets.selectboxrB   !streamlit.elements.widgets.sliderrC   'streamlit.elements.widgets.text_widgetsrD   'streamlit.elements.widgets.time_widgetsrE   streamlit.elements.writerF   streamlit.errorsrG   streamlit.protorH   rI   !streamlit.proto.RootContainer_pb2rJ   streamlit.runtimerK   streamlit.runtime.scriptrunnerrL   r   rM   google.protobuf.messagerN   streamlit.cursorrO   +streamlit.elements.lib.built_in_chart_utilsrP   rQ   __annotations__rR   r   rS   rT   rV   rh   ri   r   r   rf   rf   rf   rg   <module>   sT  ($	
	
 !"#$%&'()*+,-.   
$