o
    ßñh4  ã                   @  sV   d Z ddlmZ ddlmZmZ erddlmZ ddd	„Z	
dddd„Z	ddd„Z
d
S )zTools for working with dicts.é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚMappingÚ	flat_dictúdict[Any, Any]Úreturnc                 C  sb   i }|   ¡ D ](\}}| d¡}d}|}|D ]}||vri ||< |}|| }q|dur.|||< q|S )a–  Convert a flat dict of key-value pairs to dict tree.

    Example
    -------

        _unflatten_single_dict({
          foo_bar_baz: 123,
          foo_bar_biz: 456,
          x_bonks: 'hi',
        })

        # Returns:
        # {
        #   foo: {
        #     bar: {
        #       baz: 123,
        #       biz: 456,
        #     },
        #   },
        #   x: {
        #     bonks: 'hi'
        #   }
        # }

    Parameters
    ----------
    flat_dict : dict
        A one-level dict where keys are fully-qualified paths separated by
        underscores.

    Returns
    -------
    dict
        A tree made of dicts inside of dicts.

    Ú_N)ÚitemsÚsplit)r   ÚoutÚpathstrÚvÚpathÚ	prev_dictÚ	curr_dictÚk© r   úT/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/lib/dicttools.pyÚ_unflatten_single_dict   s   %

€r   NÚ	encodingsúset[str] | Nonec                 C  s¨   |du rt ƒ }t| ƒ}t| ¡ ƒD ]@\}}t|tƒr t||ƒ}nt|dƒr:t|ƒD ]\}}t|tƒr9t||ƒ||< q)||v rQd|vrFi |d< ||d |< | 	|¡ q|S )a!  Converts a flat dict of key-value pairs to a spec tree.

    Example
    -------
        unflatten({
          foo_bar_baz: 123,
          foo_bar_biz: 456,
          x_bonks: 'hi',
        }, ['x'])

        # Returns:
        # {
        #   foo: {
        #     bar: {
        #       baz: 123,
        #       biz: 456,
        #     },
        #   },
        #   encoding: {  # This gets added automatically
        #     x: {
        #       bonks: 'hi'
        #     }
        #   }
        # }

    Args
    ----
    flat_dict: dict
        A flat dict where keys are fully-qualified paths separated by
        underscores.

    encodings: set
        Key names that should be automatically moved into the 'encoding' key.

    Returns
    -------
    A tree made of dicts inside of dicts.
    NÚ__iter__Úencoding)
Úsetr   Úlistr
   Ú
isinstanceÚdictÚ	unflattenÚhasattrÚ	enumerateÚpop)r   r   Úout_dictr   r   ÚiÚchildr   r   r   r   Q   s$   )


€
€r   Ú
input_dictúMapping[Any, Any]c                 C  s<   i }|   ¡ D ]\}}t|tƒrt|ƒ}|dur|||< q|S )z-Remove all keys with None values from a dict.N)r
   r   r   Úremove_none_values)r%   Únew_dictÚkeyÚvalr   r   r   r'   ’   s   
€r'   )r   r   r   r   )N)r   r   r   r   r   r   )r%   r&   r   r   )Ú__doc__Ú
__future__r   Útypingr   r   Úcollections.abcr   r   r   r'   r   r   r   r   Ú<module>   s   
9ÿA