
    g>                    r   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	rddlmZ dZded<    G d d      Z d%dZ!d Z"d Z#d Z$d Z%d Z&d Z' ejP                  d      Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d  Z1d! Z2d&d"Z3d# Z4d$ Z5y)'z@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                  @    e Zd Z ed      efdd       Zedd       Zy)	HelpMixinhelpc                f    t               }t        ||       | j                  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)selfobjdoc_string_protos      R/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/doc_string.pyr   zHelpMixin.help,   s1    R *+"C(ww.>??    c                    t        d|       S )zGet our DeltaGenerator.r   )r   )r   s    r   r   zHelpMixin.dgy   s     $d++r   N)r   r   returnr   )r   r   )__name__
__module____qualname__r
   	streamlitr   propertyr    r   r   r   r   +   s5    F' J@ J@X , ,r   r   c                    t               }||| _        t        |      }|| _        t	        |      }||| _        t        ||      }||| _        | j                  j                  t        |             y)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_values         r   r   r      s{    
 "#H ($H$c"H&.#3)I!*##L$56r   c                >    t        | dd       }|r|S t        | dd       S )Nr"   r    getattr)r   r(   s     r   	_get_namer8      s+     3-D 3
D))r   c                    t        | dd       S )Nr!   r6   r   s    r   _get_moduler;      s    3d++r   c                   t        j                  |       st        |       sy d}	 t        t        j                  |             }d}t        j                  t              5  | j                  dk(  }d d d        |r1t        D ](  }|j                  |      s|j                  |d      } |S  |S # t
        $ r d}Y ut        $ r Y y w xY w# 1 sw Y   YxY w)N z(...)Fzstreamlit.delta_generator()inspectisclasscallablestr	signature
ValueError	TypeError
contextlibsuppressAttributeErrorr!   r   
startswithreplace)r   sigis_delta_genprefixs       r   _get_signaturerN      s    ??3
C'##C() L			^	,~~)DD 
- 6F~~f%kk&#.J 7
 J%    
-	,s#   B+ C+C8CCCc                   t        j                  |       }|dt        |       }|t        urQ|t        j                  ur?t        j
                  |       s*t        j                  |       st        j                  |      }|r|j                         S y N)r?   getdocr*   types
ModuleType
isfunctionismethodstrip)r   r   r2   s      r   r+   r+      sx    $J 9 D  0 00&&s+$$S) 1J!!r   c                 2    t               } | y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)codes    r   r'   r'      s     ,-D|+D11r   c                F   t        j                  |       }t        |d      s%t        |d      s| j                  d      r| d d } | S t	        |      }|sy t        |      t         j                  u r;t        |j                        t         j                  u r2|j                  j                  S t        |      t         j                  u ry | j                  d      }t        |      dkD  }|j                  }|r|j                  dz
  }||   }d }n|d   }t        |d	d      }||| S )
Nr   )command_namewrite,
   r   end_col_offset)astparse_is_stcommandendswith_get_stcommand_argr*   	NamedExprtargetNameidConstantsplitlen
col_offsetlinenor7   )	rZ   treearg_node
code_linesis_multilinestart_offsetfirst_lineno
first_line
end_offsets	            r   rY   rY      s   99T?D* F3M7=
 ==9D!$'H  
h3==	(  CHH,??%%% 
h3<<	'
 D!Jz?Q&L&&L*-

  ]
X'7<
l:..r   z[\n\r]+c                     t               } | y | j                  }|sy dj                  |      }t        j                  t
        d|j                               S )Nr=   )_get_scriptrunner_framecode_contextjoinresub	_NEWLINESrV   )scriptrunner_framer{   code_as_strings      r   rX   rX   @  sS    02!
 %22L
 WW\*N66)R!5!5!788r   c                     d } d }t        j                         D ]*  }|j                   y |j                  t        k(  r| } |S |} , |S rP   )r?   stackr{   filenameSCRIPTRUNNER_FILENAME)
prev_framer   frames      r   rz   rz   W  s]    J  %>>22!+  
 ! r   c                    | j                   d   j                  }t        |t        j                        syt        |j                  dd      |k(  xs t        |j                  dd      |k(  S )z:Checks whether the AST in tree is a call for command_name.r   Frk   Nattr)bodyr-   
isinstancerc   Callr7   func)rq   r\   	root_nodes      r   re   re   n  s^    		!""Ii* 		d+|; 	> 		-=r   c                l    | j                   d   j                  }|j                  r|j                  d   S y)z8Gets the argument node for the st command in tree (AST).r   N)r   r-   args)rq   r   s     r   rg   rg   ~  s0     		!""I~~~~a  r   c                j    t        j                  |       ryt        t        |       j                        S )Nclass)r?   r@   rB   r*   r    r:   s    r   r)   r)     s&    stCy!!""r   c                6    | sy| j                  d      \  }}}|S )Nr=   r`   )	partition)textleft_s      r   _get_first_liner     s!    %JD!QKr   c                t    t        j                  |       ryt        j                  |       ryt        |       ryy)N      ra   r   )r?   ismoduler@   rA   )r-   s    r   _get_weightr     s/    ur   c                    t        |       }||S t        |       }|r| }nt        |       }t        |      }t        |      }t	        |      xs d}|r|r
| d| | }n| | }||k(  rd }|S )Nr=   .)_get_human_readable_valuer8   r*   r;   rN   )r   r1   r4   r(   name_objmodulerK   s          r   r,   r,     s    )#.I S>D 9""F

"
(bC!(!D6#/I&IH 	r   c                
   t        | t              ry t        j                  |       s t        j                  |       st        |       ry t        |       }t        | t              rt        |      S t        |      ry t        |      S rP   )
r   r   r?   r@   r   rA   reprrB   _shortenr   )r-   	value_strs     r   r   r     si    %! u!1!1%!8HUOUI% 	"")$Ir   c                R    | j                         } t        |       |kD  r| d | dz   S | S )Nz...)rV   rn   )slengths     r   r   r     s-    		A!$Q&1Wf:7a7r   c                    t        | dd       }|syt        j                  |      D ]9  }t        ||d       }|t        |t              st        j
                  |      s9 y y)N	__class__FT)r7   r?   getmror   r$   isgetsetdescriptor)r   	attr_name	obj_classparent_class
class_attrs        r   _is_computed_propertyr     sc    [$/I  y1\9d;
 j(+w/I/I*/U 2 r   c                L   g }t        |       D ]  }|j                  d      r	 t        | |      }|r(t        | j                  |      }d}d}t        |      }d }nAt        | |      }	t        |	      }t        |	      }
t        |	      }|
t        |	      }d }nd }|
}|dk(  rt               }||_        ||_        |t        |      |_        |||_        |j!                  ||f        |r#t#        |d       }|D cg c]  \  }}|	 c}}S g S # t        $ r Y w xY wc c}}w )Nr   r$   r   r   c                *    | d   | d   j                   fS )Nr   ra   )r(   )xs    r   <lambda>z_get_members.<locals>.<lambda>,  s    AaD!A$))CTr   )key)dirrI   r   r7   r   r+   r   r   r)   rH   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   ms                  r   r0   r0     sQ   X	$	 5c9 E %cmmY?(,[9#$S)4
$Z0'@'L$.z:'/"0"<K#'L"&K#7L ("!" / <F#'FL""FF#34a d  39TU,-ndan--I5  	 		0 .s   A7D>D 	DD)r   r   r   r   r   None)i,  )6__doc__
__future__r   rc   rF   r?   r}   rR   typingr   r   r   r   r#   streamlit.proto.DocString_pb2r   r   r	   r   streamlit.runtime.metrics_utilr
   ,streamlit.runtime.scriptrunner.script_runnerr   r   streamlit.runtime.secretsr   streamlit.string_utilr   streamlit.delta_generatorr   r   __annotations__r   r   r8   r;   rN   r+   r'   rY   compiler   rX   rz   re   rg   r)   r   r   r,   r   r   r   r0   r%   r   r   <module>r      s    G " 
   	  2 2  E ? 9 . 48 +:  % 9Q, Q,h7.*$,B02"D/N BJJz"	9.. # F.8
*9r   