
    g                    V   U d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZmZmZ d dlmZmZ d dlmZmZ erd dlmZ d d	lmZ  e	j8                  e      Zd
ed<   ddZ da!ded<   	 d	 	 	 	 	 	 	 ddZ" G d de      Z#ddZ$ddZ%	 ddddd	 	 	 	 	 	 	 	 	 	 	 d dZ&d!dZ'y)"    )annotations)TYPE_CHECKINGAnyFinal)configerrorsloggerruntime)
is_in_form)StreamlitAPIWarning.StreamlitFragmentWidgetsNotAllowedOutsideError!StreamlitInvalidFormCallbackError'StreamlitValueAssignmentNotAllowedError)get_script_run_ctxin_cached_function)WidgetCallbackget_session_state)Sequence)DeltaGeneratorr   _LOGGERc                ^    t        j                         rt        |       r|
t               yyy)zEnsures that widgets other than `st.form_submit_button` within a form don't have
    an on_change callback set.

    Raises
    ------
    StreamlitInvalidFormCallbackError:
        Raised when the described rule is violated.
    N)r
   existsr   r   )dg	on_changes     T/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/lib/policies.pycheck_callback_rulesr   *   s-     ~~JrNy/D/11 0EN    Fbool_shown_default_value_warningTc                    |t        j                         syt               }|j                  |      sy|st	        |      | 2t
        s+t        j                  d      sddlm	}  |d| d       dayyyy)	a|  Ensures that no values are set for widgets with the given key when writing
    is not allowed.

    Additionally, if `global.disableWidgetStateDuplicationWarning` is False a warning is
    shown when a widget has a default value but its value is also set via session state.

    Raises
    ------
    StreamlitAPIException:
        Raised when the described rule is violated.
    N)keyz+global.disableWidgetStateDuplicationWarningr   )warningzThe widget with key "zX" was created with a default value but also had its value set via the Session State API.T)
r
   r   r   is_new_state_valuer   r   r   
get_option	streamlitr"   )default_valuer!   writes_allowedsession_stater"   s        r   check_session_state_rulesr)   ;   s      {'..*%'M++C05#>> 	!,!!"OP%#C5 )A A	
 (,$ Q - 	"r   c                       e Zd Z fdZ xZS )CachedWidgetWarningc                $    t         |   d       y )Na#  
Your script uses a widget command in a cached function
(function decorated with `@st.cache_data` or `@st.cache_resource`).
This code will only be called when we detect a cache "miss",
which can lead to unexpected results.

To fix this, move all widget commands outside the cached function.
)super__init__)self	__class__s    r   r.   zCachedWidgetWarning.__init__d   s    		
r   )__name__
__module____qualname__r.   __classcell__)r0   s   @r   r+   r+   c   s    

 

r   r+   c                 Z    t        j                         rddlm}   | t	                      yy)av  Check if a widget is allowed to be used in the current context.
    More specifically, this checks if the current context is inside a
    cached function that disallows widget usage. If so, it raises a warning.

    If there are other similar checks in the future, we could extend this
    function to check for those as well. And rename it to check_widget_usage_rules.
    r   	exceptionN)r   getr%   r7   r+   r6   s    r   check_cache_replay_rulesr9   q   s&     ' 	%'(  r   c                $   t               }||j                  y|j                  }| j                  j                  }|y|j
                  }t        |      t        |      k  r
t               t        |      D ]  \  }}||   |k7  st                y)a[  Ensures that the current widget is not written outside of the
    fragment's delta path.

    Should be called by ever element that acts as a widget.
    We don't allow writing widgets from within a widget to the outside path
    because it can lead to unexpected behavior. For elements, this is okay
    because they do not trigger a re-run.
    N)	r   current_fragment_idcurrent_fragment_delta_path
_active_dg_cursor
delta_pathlenr   	enumerate)r   ctxr<   current_cursorcurrent_cursor_delta_pathindex
path_indexs          r   check_fragment_path_policyrG      s     
C
{c--5"%"A"A]]**N . 9 9 $%,G(HH<>> ''BCz$U+z9@BB Dr   N)r&   r'   enable_check_callback_rulesc               f    t        |        t                |rt        | |       t        |||       y)z7Check all widget policies for the given DeltaGenerator.)r&   r!   r'   N)rG   r9   r   r)   )r   r!   r   r&   r'   rH   s         r   check_widget_policiesrJ      s.     r""R+#^r   c                l    | st         j                  d       |dvrt        j                  d| d      y )Nz`label` got an empty value. This is discouraged for accessibility reasons and may be disallowed in the future by raising an exception. Please provide a non-empty label and hide it with label_visibility if needed.)visiblehidden	collapsedz%Unsupported label_visibility option 'z7'. Valid values are 'visible', 'hidden' or 'collapsed'.)r   r"   r   StreamlitAPIException)labellabel_visibilitys     r   maybe_raise_label_warningsrR      sP    	
 AA**34D3E FC D
 	
 Br   )r   r   r   WidgetCallback | NonereturnNone)T)r&   r   r!   
str | Noner'   r   rT   rU   )rT   rU   )r   r   )N)r   r   r!   rV   r   rS   r&   zSequence[Any] | Any | Noner'   r   rH   r   )rP   rV   rQ   rV   )(
__future__r   typingr   r   r   r%   r   r   r	   r
   !streamlit.elements.lib.form_utilsr   streamlit.errorsr   r   r   r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.runtime.stater   r   collections.abcr   streamlit.delta_generatorr   
get_loggerr1   r   __annotations__r   r   r)   r+   r9   rG   rJ   rR    r   r   <module>rb      s    # , , 5 5 8  F(8 #""8, ,2 &+ d * AE%,%,'%,9=%,	%,P
- 
) CJ (,
 15(,	 %
 .  "&&
r   