
    g                        d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ erd dlmZ dd	Z G d
 d      Zy)    )annotationsN)ChainMapUserDict)TYPE_CHECKINGAnycast)Json)gather_metrics)is_custom_dictis_list_likeis_namedtupleis_pydantic_model)DeltaGeneratorc                N    t        | t              rt        |       S t        |       S )zWA repr function for json.dumps default arg, which tries to serialize sets
    as lists.)
isinstancesetlistrepr)os    L/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/json.py_ensure_serializationr   #   s      !C(475d1g5    c                  L    e Zd Z ed      dd	 	 	 	 	 dd       Zedd       Zy)		JsonMixinjsonT)expandedc                  t        |      r|j                         }t        |      r|j                         }t	        |t
        t        j                  t        f      st        |      rt        |      }t        |      rt        |      }t	        |t              s	 t        j                  |t               }t)               }||_        t	        |t,              r||_        n@t	        |t0              rd|_        ||_        n!t#        dt        t5        |             d      | j$                  j7                  d	|      S # t"        $ rE}| j$                  j'                  d| d       t        j                  |dt               }Y d}~d}~ww xY w)
a  Display an object or string as a pretty-printed, interactive JSON string.

        Parameters
        ----------

        body : object or str
            The object to print as JSON. All referenced objects should be
            serializable to JSON as well. If object is a string, we assume it
            contains serialized JSON.

        expanded : bool or int
            The initial expansion state of the JSON element. This can be one
            of the following:

            - ``True`` (default): The element is fully expanded.
            - ``False``: The element is fully collapsed.
            - An integer: The element is expanded to the depth specified. The
              integer must be non-negative. ``expanded=0`` is equivalent to
              ``expanded=False``.

            Regardless of the initial expansion state, users can collapse or
            expand any key-value pair to show or hide any part of the object.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> st.json(
        ...     {
        ...         "foo": "bar",
        ...         "stuff": [
        ...             "stuff 1",
        ...             "stuff 2",
        ...             "stuff 3",
        ...         ],
        ...         "level1": {"level2": {"level3": {"a": "b"}}},
        ...     },
        ...     expanded=2,
        ... )

        .. output::
           https://doc-json.streamlit.app/
           height: 385px

        )defaultzqWarning: this data structure was not fully serializable as JSON due to one or more unexpected keys.  (Error was: )T)skipkeysr   Nz	The type z5 of `expanded` is not supported, must be bool or int.r   )r   to_dictr   _asdictr   r   typesMappingProxyTyper   r   dictr   r   strr   dumpsr   	TypeErrordgwarning	JsonProtobodyboolr   intmax_expand_depthtype_enqueue)selfr,   r   err
json_protos        r   r   zJsonMixin.json*   sR   j $<<>D<<>D8U33X>
t$:D:D$$Vzz$0EF [

h%"*J#&"&J*2J'CX/0 1) ) 
 ww
33+  VMMPEQRT zz$?TUVs   D9 9	F;FFc                    t        d|       S )zGet our DeltaGenerator.r   )r   )r2   s    r   r)   zJsonMixin.dg   s     $d++r   N)r,   objectr   z
bool | intreturnr   )r7   r   )__name__
__module____qualname__r
   r   propertyr)    r   r   r   r   )   sT    F
  $	[4[4 	[4
 
[4 [4z , ,r   r   )r   r6   r7   zstr | list[Any])
__future__r   r   r#   collectionsr   r   typingr   r   r   streamlit.proto.Json_pb2r	   r+   streamlit.runtime.metrics_utilr
   streamlit.type_utilr   r   r   r   streamlit.delta_generatorr   r   r   r<   r   r   <module>rD      sB    #   * + + 6 9  86b, b,r   