o
    h>                     @  sv  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 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	rYddlmZ dZded< G dd dZ d?ddZ!dd Z"dd Z#dd Z$dd  Z%d!d" Z&d#d$ Z'e(d%Z)d&d' Z*d(d) Z+d*d+ Z,d,d- Z-d.d/ Z.d0d1 Z/d2d3 Z0d4d5 Z1d6d7 Z2d@d9d:Z3d;d< Z4d=d> Z5dS )Az@Allows us to create and absorb changes (aka Deltas) to elements.    )annotationsN)TYPE_CHECKINGAnyFinalcast)	DocString)Member)gather_metrics)__file__)Secrets)is_mem_address_str)DeltaGenerator)z
(element, r    CONFUSING_STREAMLIT_SIG_PREFIXESc                   @  s0   e Zd ZedefdddZeddd	Zd
S )	HelpMixinhelpobjr   returnr   c                 C  s   t  }t|| | j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.

        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
        
doc_string)DocStringProto	_marshalldg_enqueue)selfr   doc_string_proto r   Q/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/doc_string.pyr   ,   s   I
zHelpMixin.helpc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r   r   y   s   
zHelpMixin.dgN)r   r   r   r   )r   r   )__name__
__module____qualname__r	   	streamlitr   propertyr   r   r   r   r   r   +   s
    L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   c                 C  s    t | dd }|r
|S t | dd S )Nr   r   getattr)r   r#   r   r   r   	_get_name   s   r2   c                 C  s   t | dd S )Nr   r0   r   r   r   r   _get_module   s   r4   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callablestr	signature
ValueError	TypeError
contextlibsuppressAttributeErrorr   r   
startswithreplace)r   sigis_delta_genprefixr   r   r   _get_signature   s,   
rF   c                 C  sZ   t | }|d u r%t| }|tur%|tjur%t | s%t | s%t |}|r+| S d S N)r7   getdocr%   types
ModuleType
isfunctionismethodstrip)r   r   r-   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"   c           	      C  s   t | }t|ddst|dds| d} | S t|}|s d S t|t ju r4t|jt ju r3|jj	S n	t|t j
u r=d S | d}t|dk}|j}|rY|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linenor1   )	rP   treearg_node
code_linesis_multilinestart_offsetfirst_lineno
first_line
end_offsetr   r   r   rO      s2   



rO   z[\n\r]+c                  C  s<   t  } | d u r	d S | j}|sd S d|}ttd| S )Nr5   )_get_scriptrunner_framecode_contextjoinresub	_NEWLINESrM   )scriptrunner_framero   code_as_stringr   r   r   rN   ?  s   
rN   c                  C  sB   d } d }t  D ]}|jd u r d S |jtkr| } |S |} q|S rG   )r7   stackro   filenameSCRIPTRUNNER_FILENAME)
prev_framert   framer   r   r   rn   V  s   

rn   c                 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   Fr`   Nattr)bodyr(   
isinstancerX   Callr1   func)rf   rQ   	root_noder   r   r   rZ   m  s   rZ   c                 C  s    | j d j}|jr|jd S dS )z8Gets the argument node for the st command in tree (AST).r   N)r|   r(   args)rf   r   r   r   r   r\   }  s   
r\   c                 C  s   t | rdS tt| jS )Nclass)r7   r8   r:   r%   r   r3   r   r   r   r$     s   
r$   c                 C  s   | sdS |  d\}}}|S )Nr5   rT   )	partition)textleft_r   r   r   _get_first_line  s   r   c                 C  s,   t | rdS t | rdS t| rdS dS )N      rU   r   )r7   ismoduler8   r9   )r(   r   r   r   _get_weight  s   

r   c                 C  s   t | }|d ur
|S t| }|r| }nt| }t|}t|}t|p$d}|r9|r3| d| | }n| | }||kr?d }|S )Nr5   .)_get_human_readable_valuer2   r%   r4   rF   )r   r,   r/   r#   name_objmodulerC   r   r   r   r'     s"   r'   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 rG   )
r}   r   r7   r8   r   r9   reprr:   _shortenr   )r(   	value_strr   r   r   r     s   

r   ,  c                 C  s(   |   } t| |kr| d | d S | S )Nz...)rM   rc   )slengthr   r   r   r     s    r   c                 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)r1   r7   getmror}   r    isgetsetdescriptor)r   	attr_name	obj_classparent_class
class_attrr   r   r   _is_computed_property  s   r   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   rU   )r#   )xr   r   r   <lambda>+  s    z_get_members.<locals>.<lambda>)keyc                 S  s   g | ]\}}|qS r   r   ).0r   mr   r   r   
<listcomp>,  s    z _get_members.<locals>.<listcomp>)dirrA   r   r1   r   r&   r   r   r$   r@   MemberProtor#   r%   r   r   r(   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   r+     sN   



r+   )r   r   r   r   r   r!   )r   )6__doc__
__future__r   rX   r>   r7   rq   rI   typingr   r   r   r   r   streamlit.proto.DocString_pb2r   r   r   r   streamlit.runtime.metrics_utilr	   ,streamlit.runtime.scriptrunner.script_runnerr
   rx   streamlit.runtime.secretsr   streamlit.string_utilr   streamlit.delta_generatorr   r   __annotations__r   r   r2   r4   rF   r&   r"   rO   compilers   rN   rn   rZ   r\   r$   r   r   r'   r   r   r   r+   r   r   r   r   <module>   sN   
T!
F
#
