o
    YhC                     @  s  U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZ ddl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  e	rmddl!m"Z" ddlm#Z# dZ$de%d< G dd dZ&dTddZ'dUddZ(dUd d!Z)dUd"d#Z*dUd$d%Z+dVd&d'Z,dWd*d+Z-e.d,Z/dVd-d.Z0dXd0d1Z1dYd5d6Z2dZd9d:Z3d[d;d<Z4d\d>d?Z5d]dBdCZ6d^dEdFZ7d_dGdHZ8d`dadLdMZ9dbdOdPZ:dcdRdSZ;dS )dz@Allows us to create and absorb changes (aka Deltas) to elements.    )annotationsN)TYPE_CHECKINGAnyFinalcast)LayoutConfigvalidate_width)	DocString)Member)
CachedFunc)gather_metrics)__file__)Secrets)is_mem_address_str)DeltaGenerator)WidthWithoutContent)z
(element, r    CONFUSING_STREAMLIT_SIG_PREFIXESc                   @  s6   e Zd Zedefdddd
dZedddZdS )	HelpMixinhelpstretchwidthobjr   r   r   returnr   c                C  s8   t  }t|dd t|d}t|| | jjd||dS )u	  Display help and other information for a given object.

        Depending on the type of object that is passed in, this displays the
        object's name, type, value, signature, docstring, and member variables,
        methods — as well as the values/docstring of members and methods.

        Parameters
        ----------
        obj : any
            The object whose information should be displayed. If left
            unspecified, this call will display help for Streamlit itself.
        width : "stretch" or int
            The width of the help element. This can be one of the following:

            - ``"stretch"`` (default): The width of the element matches the
              width of the parent container.
            - An integer specifying the width in pixels: The element has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the element matches the width
              of the parent container.

        Example
        -------

        Don't remember how to initialize a dataframe? Try this:

        >>> import streamlit as st
        >>> import pandas
        >>>
        >>> st.help(pandas.DataFrame)

        .. output::
            https://doc-string.streamlit.app/
            height: 700px

        Want to quickly check what data type is output by a certain function?
        Try:

        >>> import streamlit as st
        >>>
        >>> x = my_poorly_documented_function()
        >>> st.help(x)

        Want to quickly inspect an object? No sweat:

        >>> class Dog:
        >>>   '''A typical dog.'''
        >>>
        >>>   def __init__(self, breed, color):
        >>>     self.breed = breed
        >>>     self.color = color
        >>>
        >>>   def bark(self):
        >>>     return 'Woof!'
        >>>
        >>>
        >>> fido = Dog("poodle", "white")
        >>>
        >>> st.help(fido)

        .. output::
            https://doc-string1.streamlit.app/
            height: 300px

        And if you're using Magic, you can get help for functions, classes,
        and modules without even typing ``st.help``:

        >>> import streamlit as st
        >>> import pandas
        >>>
        >>> # Get help for Pandas read_csv:
        >>> pandas.read_csv
        >>>
        >>> # Get help for Streamlit itself:
        >>> st

        .. output::
            https://doc-string2.streamlit.app/
            height: 700px
        F)allow_contentr   
doc_string)layout_config)DocStringProtor   r   	_marshalldg_enqueue)selfr   r   doc_string_protor    r#   ^/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/doc_string.pyr   /   s   T

zHelpMixin.helpc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r!   r#   r#   r$   r      s   
zHelpMixin.dgN)r   r   r   r   r   r   )r   r   )__name__
__module____qualname__r   	streamlitr   propertyr   r#   r#   r#   r$   r   .   s    ]r   r"   r   r   r   r   Nonec                 C  sd   t  }|dur
|| _t|}|| _t|}|dur|| _t||}|dur(|| _| j	t
| dS )zIConstruct a DocString object.

    See DeltaGenerator.help for docs.
    N)_get_variable_namename_get_type_as_strtype_get_docstringr   
_get_valuevaluemembersextend_get_members)r"   r   var_nameobj_typeobj_docs	obj_valuer#   r#   r$   r      s   
r   object
str | Nonec                 C  s,   t | dd }|rtd|S tdt | dd S )Nr'   strr:   r%   )getattrr   )r   r,   r#   r#   r$   	_get_name   s   
r=   c                 C  s   t | dd S )Nr&   )r<   r   r#   r#   r$   _get_module   s   r?   c                 C  s   t | st| sd S d}z	tt | }W n ty!   d}Y n
 ty*   Y d S w d}tt	 | j
dk}W d    n1 sBw   Y  |r\tD ]}||r[||d} |S qK|S )N z(...)Fzstreamlit.delta_generator()inspectisclasscallabler;   	signature
ValueError	TypeError
contextlibsuppressAttributeErrorr&   r   
startswithreplace)r   sigis_delta_genprefixr#   r#   r$   _get_signature   s,   
rP   c                 C  sb   t | }|d u r)t| }|tur)|tjur)t | s)t | s)|tur)t |}|r/| S d S N)	rB   getdocr.   types
ModuleType
isfunctionismethodr   strip)r   r   r6   r#   r#   r$   r/      s   


r/   c                  C  s   t  } | du r	dS t| S )zTry to get the name of the variable in the current line, as set by the user.

    For example:
    foo = bar.Baz(123)
    st.help(foo)

    The name is "foo"
    N) _get_current_line_of_code_as_str _get_variable_name_from_code_str)coder#   r#   r$   r+      s   	r+   rZ   r;   c           	      C  s   t | }t|ddst|dds| dS t|}|sd S t|t ju r2t|jt ju r1|jj	S n	t|t j
u r;d S | d}t|dk}|j}|rW|jd }|| }d }n
|d }t|dd	}||| S )
Nr   )command_namewrite,
   r   end_col_offset)astparse_is_stcommandremovesuffix_get_stcommand_argr.   	NamedExprtargetNameidConstantsplitlen
col_offsetlinenor<   )	rZ   treearg_node
code_linesis_multilinestart_offsetfirst_lineno
first_line
end_offsetr#   r#   r$   rY     s0   



rY   z[\n\r]+c                  C  s<   t  } | d u r	d S | j}|sd S d|}ttd| S )Nr@   )_get_scriptrunner_framecode_contextjoinresub	_NEWLINESrW   )scriptrunner_framery   code_as_stringr#   r#   r$   rX   K  s   
rX   inspect.FrameInfo | Nonec                  C  sB   d } d }t  D ]}|jd u r d S |jtkr| } |S |} q|S rQ   )rB   stackry   filenameSCRIPTRUNNER_FILENAME)
prev_framer~   framer#   r#   r$   rx   b  s   

rx   rp   r[   boolc                 C  s@   | j d j}t|tjsdS t|jdd|kpt|jdd|kS )z:Checks whether the AST in tree is a call for command_name.r   Frj   Nattr)bodyr1   
isinstancerb   Callr<   func)rp   r[   	root_noder#   r#   r$   rd   y  s   rd   
ast.Moduleast.expr | Nonec                 C  s&   | j d j}|jrtd|jd S dS )z8Gets the argument node for the st command in tree (AST).r   zast.exprN)r   r1   argsr   )rp   r   r#   r#   r$   rf     s   rf   c                 C  s   t | rdS tt| jS )Nclass)rB   rC   r;   r.   r%   r>   r#   r#   r$   r-     s   
r-   textc                 C  s   | sdS |  d\}}}|S )Nr@   r^   )	partition)r   left_r#   r#   r$   _get_first_line  s   r   r1   intc                 C  s,   t | rdS t | rdS t| rdS dS )N      r_   r   )rB   ismodulerC   rD   )r1   r#   r#   r$   _get_weight  s   

r   r5   c                 C  s   t | }|d ur
|S t| }|r| }nt| }t|}t|}t|p$d}|r8|r2| d| | n| | }||kr>d }|S )Nr@   .)_get_human_readable_valuer=   r.   r?   rP   )r   r5   r8   r,   name_objmodulerM   r#   r#   r$   r0     s   "r0   c                 C  s\   t | trd S t| st| st| rd S t| }t | tr$t|S t	|r*d S t|S rQ   )
r   r   rB   rC   r   rD   reprr;   _shortenr   )r1   	value_strr#   r#   r$   r     s   

r   ,  slengthc                 C  s(   |   } t| |kr| d | d S | S )Nz...)rW   rm   )r   r   r#   r#   r$   r     s    r   	attr_namec                 C  sX   t | dd }|s
dS t|D ]}t ||d }|d u rqt|ts&t|r) dS qdS )N	__class__FT)r<   rB   getmror   r)   isgetsetdescriptor)r   r   	obj_classparent_class
class_attrr#   r#   r$   _is_computed_property  s   r   list[MemberProto]c              	   C  s  g }t | D ]q}|drqz:t| |}|r't| j|}d}d}t|}d }n t| |}	t|	}t|	}
t|	}|
d u rCt|	}d }nd }|
}W n	 t	yQ   Y qw |dkrWqt
 }||_||_|d urit||_|d urp||_|||f q|rt|dd d}dd	 |D S g S )
Nr   r)   r   r   c                 S  s   | d | d j fS )Nr   r_   )r,   )xr#   r#   r$   <lambda>4  s    z_get_members.<locals>.<lambda>)keyc                 S  s   g | ]\}}|qS r#   r#   ).0r   mr#   r#   r$   
<listcomp>5  s    z _get_members.<locals>.<listcomp>)dirrK   r   r<   r   r/   r   r   r-   rJ   MemberProtor,   r.   r   r   r1   appendsorted)r   members_for_sortingr   is_computed_valueparent_attrmember_typeweightmember_docsmember_value
attr_valuehuman_readable_valuemembersorted_membersr#   r#   r$   r4     sN   



r4   )r"   r   r   r   r   r*   )r   r9   r   r:   )r   r:   )rZ   r;   r   r:   )r   r   )rp   r   r[   r;   r   r   )rp   r   r   r   )r   r9   r   r;   )r   r;   r   r;   )r1   r   r   r   )r   r9   r5   r:   r   r:   )r1   r   r   r:   )r   )r   r;   r   r   r   r;   )r   r9   r   r;   r   r   )r   r9   r   r   )<__doc__
__future__r   rb   rH   rB   r{   rS   typingr   r   r   r   r(   #streamlit.elements.lib.layout_utilsr   r   streamlit.proto.DocString_pb2r	   r   r
   r   %streamlit.runtime.caching.cache_utilsr   streamlit.runtime.metrics_utilr   ,streamlit.runtime.scriptrunner.script_runnerr   r   streamlit.runtime.secretsr   streamlit.string_utilr   streamlit.delta_generatorr   r   r   __annotations__r   r   r=   r?   rP   r/   r+   rY   compiler}   rX   rx   rd   rf   r-   r   r   r0   r   r   r   r4   r#   r#   r#   r$   <module>   sT   
e






D









 
