U
    ARdM'                     @   s   U d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	 d dl
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 erd dlmZ ejejej ej!ej"fZ#eeee df  e$d< ee%Z&G dd dZ'dS )    N)TYPE_CHECKINGAnyListTupleTypecast)Final)	type_util)StreamlitAPIException)
get_logger)gather_metrics)SessionStateProxy)is_mem_address_str)UserInfoProxy)DeltaGenerator.
HELP_TYPESc                   @   s>   e Zd ZedddeeddddZedd	d
dZdS )
WriteMixinwriteFunsafe_allow_htmlN)argsr   returnc          	         s  |rt d| g  jjs0t|dkr0td fdd}|D ]}t|tr`| qDt	
|r~|   j| qDt	|r|  tt|dkr j| n j| qDt|tr|   j| qDt|t r|   j| qDt	|r|   j| qDt	|dr<|   j| qDt	|r\|   j| qDt	|dr~|   j| qDt	|r|   j| qDt	|r|   j| qDt	|rd	d
l m!} |  |"|} j|#  qDt|t$t%t&t'fr |   j(| qDt	)|rJ|   j(t(*|+  qDt	,|rj|   j-| qDt./|r|   jt0t1| qDt2|dr jj3|4 dd qDt|}t5|r|   j| qDd|6dd  qD|  dS )az  Write arguments to the app.

        This is the Swiss Army knife of Streamlit commands: it does different
        things depending on what you throw at it. Unlike other Streamlit commands,
        write() has some unique properties:

        1. You can pass in multiple arguments, all of which will be written.
        2. Its behavior depends on the input types as follows.
        3. It returns None, so its "slot" in the App cannot be reused.

        Parameters
        ----------
        *args : any
            One or many objects to print to the App.

            Arguments are handled as follows:

            - write(string)     : Prints the formatted Markdown string, with
                support for LaTeX expression, emoji shortcodes, and colored text.
                See docs for st.markdown for more.
            - write(data_frame) : Displays the DataFrame as a table.
            - write(error)      : Prints an exception specially.
            - write(func)       : Displays information about a function.
            - write(module)     : Displays information about the module.
            - write(class)      : Displays information about a class.
            - write(dict)       : Displays dict in an interactive widget.
            - write(mpl_fig)    : Displays a Matplotlib figure.
            - write(altair)     : Displays an Altair chart.
            - write(keras)      : Displays a Keras model.
            - write(graphviz)   : Displays a Graphviz graph.
            - write(plotly_fig) : Displays a Plotly figure.
            - write(bokeh_fig)  : Displays a Bokeh figure.
            - write(sympy_expr) : Prints SymPy expression using LaTeX.
            - write(htmlable)   : Prints _repr_html_() for the object if available.
            - write(obj)        : Prints str(obj) if otherwise unknown.

        unsafe_allow_html : bool
            This is a keyword-only argument that defaults to False.

            By default, any HTML tags found in strings will be escaped and
            therefore treated as pure text. This behavior may be turned off by
            setting this argument to True.

            That said, *we strongly advise against it*. It is hard to write secure
            HTML, so by using this argument you may be compromising your users'
            security. For more information, see:

            https://github.com/streamlit/streamlit/issues/152

        Example
        -------

        Its basic use case is to draw Markdown-formatted text, whenever the
        input is a string:

        >>> import streamlit as st
        >>>
        >>> st.write('Hello, *World!* :sunglasses:')

        ..  output::
            https://doc-write1.streamlitapp.com/
            height: 150px

        As mentioned earlier, ``st.write()`` also accepts other data formats, such as
        numbers, data frames, styled data frames, and assorted objects:

        >>> import streamlit as st
        >>> import pandas as pd
        >>>
        >>> st.write(1234)
        >>> st.write(pd.DataFrame({
        ...     'first column': [1, 2, 3, 4],
        ...     'second column': [10, 20, 30, 40],
        ... }))

        ..  output::
            https://doc-write2.streamlitapp.com/
            height: 350px

        Finally, you can pass in multiple arguments to do things like:

        >>> import streamlit as st
        >>>
        >>> st.write('1 + 1 = ', 2)
        >>> st.write('Below is a DataFrame:', data_frame, 'Above is a dataframe.')

        ..  output::
            https://doc-write3.streamlitapp.com/
            height: 410px

        Oh, one more thing: ``st.write`` accepts chart objects too! For example:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>> import altair as alt
        >>>
        >>> df = pd.DataFrame(
        ...     np.random.randn(200, 3),
        ...     columns=['a', 'b', 'c'])
        ...
        >>> c = alt.Chart(df).mark_circle().encode(
        ...     x='a', y='b', size='c', color='c', tooltip=['a', 'b', 'c'])
        >>>
        >>> st.write(c)

        ..  output::
            https://doc-vega-lite-chart.streamlitapp.com/
            height: 300px

        zInvalid arguments were passed to "st.write" function. Support for passing such unknown keywords arguments will be dropped in future. Invalid arguments were: %s   zCannot replace a single element with multiple elements.

The `write()` method only supports multiple elements when inserting elements rather than replacing. That is, only when called as `st.write()` or `st.sidebar.write()`.c                      s*   r& j jdd g d d < d S )N r   )dgmarkdownjoin selfZstring_bufferr   r   </tmp/pip-unpacked-wheel-b9et7o5g/streamlit/elements/write.pyflush_buffer   s    z&WriteMixin.write.<locals>.flush_buffer   zmatplotlib.figure.Figurezbokeh.plotting.figure.Figurer   )	vis_utils_repr_html_Tr   z`%s``z\`N)7_LOGGERwarningr   Z_is_top_levellenr
   
isinstancestrappendr	   Z"is_snowpark_or_pyspark_data_objectZ	dataframeZis_dataframe_likenpshapetext	Exception	exceptionr   helpZis_altair_chartZaltair_chartZis_typeZpyplotZis_plotly_chartZplotly_chartZbokeh_chartZis_graphviz_chartZgraphviz_chartZis_sympy_expessionZlatexZis_keras_modelZtensorflow.python.keras.utilsr#   Zmodel_to_dotZ	to_stringdictlistr   r   jsonZis_namedtupledumps_asdictZ	is_pydeckZpydeck_chartinspectisclassr   typehasattrr   r$   r   replace)	r   r   r   kwargsr!   argr#   dotZstringified_argr   r   r    r   0   s    q






zWriteMixin.writer   )r   c                 C   s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r    r     s    zWriteMixin.dg)	__name__
__module____qualname__r   r   boolr   propertyr   r   r   r   r    r   /   s
    Xr   )(r7   r4   typestypingr   r   r   r   r   r   Znumpyr,   Ztyping_extensionsr   Z	streamlitr	   Zstreamlit.errorsr
   Zstreamlit.loggerr   Zstreamlit.runtime.metrics_utilr   Zstreamlit.runtime.stater   Zstreamlit.string_utilr   Zstreamlit.user_infor   Zstreamlit.delta_generatorr   BuiltinFunctionTypeBuiltinMethodTypeFunctionType
MethodType
ModuleTyper   __annotations__r?   r&   r   r   r   r   r    <module>   s.     