
    &e                       U d Z ddlmZ ddlZddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ ddlm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( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF erddlGmHZH dd lImJZJ ee e"e$e&e(e*e,e.e0e2e4e6e8e:e<e>e@eBf         ZKd!eLd"<   d#ZMd$eLd%<    ed&          ZN ed'd()          ZOeed*f         ZPd!eLd+<   eeQef         ZRd!eLd,<   ed-         ZSd!eLd.<   eeeQgeNf         ZTd!eLd/<   eeNgef         ZUd!eLd0<    ed(1           G d2 d3eeN                               ZV ed(1           G d4 d5eeO                               ZWeeXeYeZeQe[f         Z\eee	ee
dd6d7ee\f	         Z]	 dIdJd?Z^dKdBZ_dLdEZ`dLdFZadMdHZbdS )NzGFunctions and data structures shared by session_state.py and widgets.py    )annotationsN)	dataclassfield)datedatetimetime	timedelta)
TYPE_CHECKINGAnyCallableDictGenericOptionalSequenceTupleTypeVarUnion)Message)Final	TypeAlias)util)StreamlitAPIException)Arrow)Button)CameraInput)	ChatInput)Checkbox)ColorPicker)ComponentInstance)	DateInput)DownloadButton)FileUploader)MultiSelect)NumberInput)Radio)	Selectbox)Slider)TextArea)	TextInput)	TimeInput)ValueFieldName)HASHLIB_KWARGS)ellipsis)NoValuer   WidgetProtoz$$WIDGET_IDr   GENERATED_WIDGET_ID_PREFIXTT_coT)	covariant.
WidgetArgsWidgetKwargs).NWidgetCallbackWidgetDeserializerWidgetSerializer)frozenc                      e Zd ZU dZded<    ed          Zded<    ed          Zded	<   d
ed<   dZded<   dZ	ded<   dZ
ded<   ddZdS )WidgetMetadataz4Metadata associated with a single widget. Immutable.stridF)reprzWidgetDeserializer[T]deserializerzWidgetSerializer[T]
serializerr+   
value_typeNzWidgetCallback | NonecallbackzWidgetArgs | Nonecallback_argszWidgetKwargs | Nonecallback_kwargsreturnc                *    t          j        |           S N)r   repr_)selfs    >lib/python3.11/site-packages/streamlit/runtime/state/common.py__repr__zWidgetMetadata.__repr__{   s    z$    )rE   r<   )__name__
__module____qualname____doc____annotations__r   r?   r@   rB   rC   rD   rK    rL   rJ   r;   r;   k   s         >>GGG*/%U*;*;*;L;;;;&+e&7&7&7J7777
 '+H****'+M+++++/O////           rL   r;   c                  @    e Zd ZU dZded<   ded<   edd
            ZdS )RegisterWidgetResultal  Result returned by the `register_widget` family of functions/methods.

    Should be usable by widget code to determine what value to return, and
    whether to update the UI.

    Parameters
    ----------
    value : T_co
        The widget's current value, or, in cases where the true widget value
        could not be determined, an appropriate fallback value.

        This value should be returned by the widget call.
    value_changed : bool
        True if the widget's value is different from the value most recently
        returned from the frontend.

        Implies an update to the frontend is needed.
    r2   valueboolvalue_changedr?   WidgetDeserializer[T_co]rE   'RegisterWidgetResult[T_co]'c                0     |  |dd          d          S )zThe canonical way to construct a RegisterWidgetResult in cases
        where the true widget value could not be determined.
        N F)rU   rW   rR   )clsr?   s     rJ   failurezRegisterWidgetResult.failure   s%     sdB//uEEEErL   N)r?   rX   rE   rY   )rM   rN   rO   rP   rQ   classmethodr]   rR   rL   rJ   rT   rT      s[          & KKKF F F [F F FrL   rT   r.   r-   element_typer<   user_key
str | Nonekwargs#SAFE_VALUES | Sequence[SAFE_VALUES]rE   c                   t          j        di t          }|                    |                     d                     |                                D ]o\  }}|                    t          |                              d                     |                    t          |                              d                     pt           d|                                 d| S )aX  Compute the widget id for the given widget. This id is stable: a given
    set of inputs to this function will always produce the same widget id output.

    Only stable, deterministic values should be used to compute widget ids. Using
    nondeterministic values as inputs can cause the resulting widget id to
    change between runs.

    The widget id includes the user_key so widgets with identical arguments can
    use it to be distinct.

    The widget id includes an easily identified prefix, and the user_key as a
    suffix, to make it easy to identify it and know if a key maps to it.
    md5zutf-8-)re   )	hashlibnewr,   updateencodeitemsr<   r0   	hexdigest)r_   r`   rb   hkvs         rJ   compute_widget_idrp      s    $ 	,,^,,AHH\  ))***  ) )1	Qw''(((	Qw''(((((EE1;;==EE8EEErL   	widget_idOptional[str]c                T    |                      dd          d         }|dk    rdn|}|S )aR  Return the user key portion of a widget id, or None if the id does not
    have a user key.

    TODO This will incorrectly indicate no user key if the user actually provides
    "None" as a key, but we can't avoid this kind of problem while storing the
    string representation of the no-user-key sentinel as part of the widget id.
    rf      )maxsplitNoneN)split)rq   r`   s     rJ   user_key_from_widget_idry      s6     sQ//3H6))ttxHOrL   keyrV   c                6    |                      t                    S )zETrue if the given session_state key has the structure of a widget ID.)
startswithr0   rz   s    rJ   is_widget_idr~      s    >>4555rL   c                L    t          |           o|                     d           S )zUTrue if the given session_state key has the structure of a widget ID with a user_key.z-None)r~   endswithr}   s    rJ   is_keyed_widget_idr      s$    :S\\'%:%:!::rL   rw   c                T    t          |           rt          dt           d          dS )z4Raise an Exception if the given user_key is invalid.zKeys beginning with z are reserved.N)r~   r   r0   r}   s    rJ   require_valid_user_keyr      s=    C 
#M#=MMM
 
 	

 
rL   rG   )r_   r<   r`   ra   rb   rc   rE   r<   )rq   r<   rE   rr   )rz   r<   rE   rV   )rz   r<   rE   rw   )crP   
__future__r   rg   dataclassesr   r   r   r   r   r	   typingr
   r   r   r   r   r   r   r   r   r   google.protobuf.messager   typing_extensionsr   r   	streamlitr   streamlit.errorsr   streamlit.proto.Arrow_pb2r   streamlit.proto.Button_pb2r   streamlit.proto.CameraInput_pb2r   streamlit.proto.ChatInput_pb2r   streamlit.proto.Checkbox_pb2r   streamlit.proto.ColorPicker_pb2r   streamlit.proto.Components_pb2r   streamlit.proto.DateInput_pb2r    "streamlit.proto.DownloadButton_pb2r!    streamlit.proto.FileUploader_pb2r"   streamlit.proto.MultiSelect_pb2r#   streamlit.proto.NumberInput_pb2r$   streamlit.proto.Radio_pb2r%   streamlit.proto.Selectbox_pb2r&   streamlit.proto.Slider_pb2r'   streamlit.proto.TextArea_pb2r(   streamlit.proto.TextInput_pb2r)   streamlit.proto.TimeInput_pb2r*   streamlit.type_utilr+   streamlit.utilr,   builtinsr-   streamlit.runtime.state.widgetsr.   r/   rQ   r0   r1   r2   r4   r<   r5   r6   r7   r8   r;   rT   floatintrV   bytesPROTO_SCALAR_VALUESAFE_VALUESrp   ry   r~   r   r   rR   rL   rJ   <module>r      s6   N M M " " " " " "  ( ( ( ( ( ( ( ( 4 4 4 4 4 4 4 4 4 4 4 4                        , + + + + + . . . . . . . .       2 2 2 2 2 2 + + + + + + - - - - - - 7 7 7 7 7 7 3 3 3 3 3 3 1 1 1 1 1 1 7 7 7 7 7 7 < < < < < < 3 3 3 3 3 3 = = = = = = 9 9 9 9 9 9 7 7 7 7 7 7 7 7 7 7 7 7 + + + + + + 3 3 3 3 3 3 - - - - - - 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 . . . . . . ) ) ) ) ) ) 8!!!!!!777777 	
	
#    * %2  1 1 1 1 GCLLwv&&& c3h
 ' ' ' 'sCx. ( ( ( ($Y/ / / / / !)#sQ 7  7 7 7 7&sCx0  0 0 0 0 $         WQZ      & $F F F F F74= F F FB 5#tS%78 
  F F F F F8
 
 
 
6 6 6 6
; ; ; ;

 
 
 
 
 
rL   