Ë
    úmxi»$  ã                  óô   — d dl mZ d dlZd dlmZ d dl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mZ erd dlmZ  ee«      Z	 d	 	 	 	 	 dd„Zdd„Zdd„Zdd„Ze G d„ d«      «       Z y)é    )ÚannotationsN)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚcast)ÚARROW_REF_KEY)Úconvert_anything_to_arrow_bytesÚis_dataframe_like)Ú
get_logger)ÚBidiComponent)Ú	MixedData)ÚAttributeDictionaryÚcalc_md5)ÚBidiComponentStatec                ó  — |€i }i }| j                  «       D ]=  \  }}t        |«      r(	 t        |«      }t        |«      }|||<   t        |i||<   Œ9|||<   Œ? |S # t
        $ r&}t        j                  d||«       |||<   Y d}~Œld}~ww xY w)aÒ  Extract dataframe-like objects from a dictionary and replace them with
    placeholders.

    This function traverses the first level of a dictionary, detects any
    dataframe-like objects, stores their Arrow bytes representation in the
    `arrow_blobs` dictionary, and replaces them with JSON-serializable
    placeholder objects.

    Parameters
    ----------
    data
        The dictionary to process. Only the first level is checked for
        dataframe-like objects.
    arrow_blobs
        The dictionary to store the extracted Arrow bytes in, keyed by a unique
        reference ID.

    Returns
    -------
    dict[str, Any]
        A new dictionary with dataframe-like objects replaced by placeholders.
    NzAArrow serialization failed for key %r, keeping original value: %s)Úitemsr
   r	   r   r   Ú	ExceptionÚ_LOGGERÚdebug)ÚdataÚarrow_blobsÚprocessed_dataÚkeyÚvalueÚarrow_bytesÚref_idÚes           úk/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/components/v2/bidi_component/serialization.pyÚ_extract_dataframes_from_dictr   "   s²   € ð2 ÐØˆà€Nà—j‘j“lò (‰
ˆˆUÜ˜UÔ#ð,Ü=¸eÓD�ô " +Ó.�Ø&1�˜FÑ#Ü'4°fÐ&=�˜sÒ#ð #(ˆN˜3Òð-(ð0 Ðøô ò ,ô —‘ØWØØôð
 ',�˜sÖ#ûð,ús   ©&AÁ	BÁ"BÂBc                ó"  — i }t        | t        «      rt        | |«      }n| }|rmt        «       }	 t	        j
                  |«      |_        |j                  «       D ]  \  }}||j                  |   _
        Œ |j                  j                  |«       y	 t	        j
                  |«      |_        y# t        $ r& t	        j
                  t        |«      «      |_        Y Œ’w xY w# t        $ r& t	        j
                  t        |«      «      |_        Y yw xY w)a4  Serialize mixed data with automatic dataframe detection into a protobuf message.

    This function detects dataframe-like objects in the first level of a dictionary,
    extracts them into separate Arrow blobs, and populates a `MixedDataProto`
    protobuf message for efficient serialization.

    Parameters
    ----------
    data
        The data structure to serialize. If it is a dictionary, its first
        level will be scanned for dataframe-like objects.
    bidi_component_proto
        The protobuf message to populate with the serialized data.

    N)Ú
isinstanceÚdictr   ÚMixedDataProtoÚjsonÚdumpsÚ	TypeErrorÚstrr   r   r   ÚmixedÚCopyFrom)r   Úbidi_component_protor   r   Úmixed_protor   r   s          r   Úserialize_mixed_datar,   [   sý   € ð  %'€Kô �$œÔÜ6°t¸[ÓI‰ð ˆáä$Ó&ˆð	?Ü#Ÿz™z¨.Ó9ˆKÔð $/×#4Ñ#4Ó#6ò 	?ÑˆF�KØ3>ˆK×#Ñ# FÑ+Õ0ð	?ð 	×"Ñ"×+Ñ+¨KÕ8ð	HÜ(,¯
©
°>Ó(BÐ Õ%øô ò 	?ô  $Ÿz™z¬#¨nÓ*=Ó>ˆKÖð	?ûô ò 	Hô )-¯
©
´3°~Ó3FÓ(GÐ Ö%ð	Hús#   ¯B- ÂC Â-,CÃCÃ,DÄDc                ój   — | €y	 t        j                  | «      S # t         j                  $ r | cY S w xY w)a;  Deserialize a JSON string, returning the string itself if it's not valid JSON.

    Parameters
    ----------
    s
        The string to deserialize.

    Returns
    -------
    Any
        The deserialized JSON object, or the original string if parsing fails.
        Returns `None` if the input is `None`.

    N)r$   ÚloadsÚJSONDecodeError)Úss    r   Úhandle_deserializer1   Ž   s9   € ð 	€yØðÜ�z‰z˜!‹}ÐøÜ×Ñò ØŠðús   … š2±2c                óH   — t        | «      }|€yt        |t        «      r|S |gS )aö  Deserialize trigger aggregator payloads as a list.

    For bidirectional components, the frontend always sends a JSON array of payload
    objects. This deserializer normalizes older or singular payloads into a list
    while preserving ``None`` for cleared values.

    Parameters
    ----------
    s
        The JSON string to deserialize, hopefully representing a list of payloads.

    Returns
    -------
    list[Any] or None
        A list of payloads, or `None` if the input was `None`.

    N)r1   r!   Úlist)r0   r   s     r   Údeserialize_trigger_listr4   ¥   s,   € ô$ ˜qÓ!€EØ€}ØÜ�%œÔØˆØˆ7€Nó    c                  ó0   — e Zd ZU dZdZded<   dd„Zdd„Zy)	ÚBidiComponentSerdeaÐ  Serialization and deserialization logic for a bidirectional component.

    This class handles the conversion of component state between the frontend
    (JSON strings) and the backend (Python objects).

    The canonical shape is a flat mapping of state keys to values.

    Parameters
    ----------
    default
        A dictionary of default values to be applied to the state when
        deserializing, if the corresponding keys are not already present.

    Nzdict[str, Any] | NoneÚdefaultc                óÀ  — t        |t        «      r|}n=t        |t        «      r+	 t        j                  |«      }t        |t        «      r|ni }ni }| j                  �,| j                  j                  «       D ]  \  }}||vsŒ|||<   Œ t        dt        |«      «      }|S # t        j
                  t        f$ r$}t        j                  d||¬«       i }Y d}~Œ‡d}~ww xY w)a_  Deserialize the component's state from a frontend value.

        Parameters
        ----------
        ui_value
            The value received from the frontend, which can be a JSON string,
            a dictionary, or `None`.

        Returns
        -------
        BidiComponentState
            The deserialized state as a flat mapping.

        z7Failed to deserialize component state from frontend: %s)Úexc_infoNr   )r!   r"   r'   r$   r.   r/   r&   r   Úwarningr8   r   r   r   )ÚselfÚui_valueÚdeserialized_valueÚparsedr   Údefault_keyÚdefault_valueÚstates           r   ÚdeserializezBidiComponentSerde.deserializeÒ   së   € ô* �h¤Ô%Ø!)ÑÜ˜¤#Ô&ð	(ÜŸ™ HÓ-�Ü/9¸&Ä$Ô/G¡VÈRÑ"ð "$Ðð �<‰<Ð#Ø.2¯l©l×.@Ñ.@Ó.Bò DÑ*�˜]ØÐ&8Ò8Ø6CÐ& {Ò3ðDô %)Ø Ô"5Ð6HÓ"Ió%
ˆð ˆøô' ×(Ñ(¬)Ð4ò (Ü—‘ØMØØð  ô ð
 &(Õ"ûð(ús   ¥)B  Â CÂ9CÃCc                ó,   — t        j                  |«      S )a  Serialize the component's state into a JSON string for the frontend.

        Parameters
        ----------
        value
            The component state to serialize.

        Returns
        -------
        str
            A JSON string representation of the value.

        )r$   r%   )r<   r   s     r   Ú	serializezBidiComponentSerde.serialize  s   € ô �z‰z˜%Ó Ð r5   )r=   zstr | dict[str, Any] | NoneÚreturnr   )r   r   rF   r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   Ú__annotations__rC   rE   © r5   r   r7   r7   ¿   s   … ñð &*€GÐ"Ó)ó.ô`!r5   r7   )N)r   údict[str, Any]r   zdict[str, bytes] | NonerF   rM   )r   r   r*   ÚBidiComponentProtorF   ÚNone)r0   ú
str | NonerF   r   )r0   rP   rF   zlist[Any] | None)!Ú
__future__r   r$   Údataclassesr   Útypingr   r   r   Ú0streamlit.components.v2.bidi_component.constantsr   Ústreamlit.dataframe_utilr	   r
   Ústreamlit.loggerr   Ú!streamlit.proto.BidiComponent_pb2r   rN   r   r#   Ústreamlit.utilr   r   Ú,streamlit.components.v2.bidi_component.stater   rG   r   r   r,   r1   r4   r7   rL   r5   r   ú<module>rZ      sŠ   ðõ #ã Ý !ß +Ñ +å Jß WÝ 'Ý QÝ Iß 8áÝOá
�XÓ
€ð BFð6Ø
ð6Ø'>ð6àó6ór0Hófó.ð4 ÷P!ð P!ó ñP!r5   