o
    h                     @  s   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dZG dd dZdS )    )annotationsN)ChainMapUserDict)TYPE_CHECKINGAnycast)Json)gather_metrics)is_custom_dictis_list_likeis_namedtupleis_pydantic_model)DeltaGeneratoroobjectreturnstr | list[Any]c                 C  s   t | tr	t| S t| S )z\A repr function for json.dumps default arg, which tries to serialize sets
    as lists.
    )
isinstancesetlistrepr)r    r   K/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/json.py_ensure_serialization#   s   r   c                   @  s2   e Zd Zeddddd
dZedddZdS )	JsonMixinjsonT)expandedbodyr   r   
bool | intr   r   c             
   C  s  t |r| }t|r| }t|ttjtfst	|r!t
|}t|r)t|}t|ts\z	tj|td}W n$ ty[ } z| jd| d tj|dtd}W Y d}~nd}~ww t }||_t|trk||_nt|trwd|_||_ntdtt| d| jd	|S )
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	JsonProtor   boolr   intmax_expand_depthtype_enqueue)selfr   r   err
json_protor   r   r   r   +   sF   4


zJsonMixin.jsonc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r2   r   r   r   r*      s   
zJsonMixin.dgN)r   r   r   r   r   r   )r   r   )__name__
__module____qualname__r	   r   propertyr*   r   r   r   r   r   *   s    \r   )r   r   r   r   )
__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   r   <module>   s   
