o
    ]ôj‰  ã                   @   sŠ   d dl Z d dlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZmZ eeeedœZee
e	edœZ							dd
d„Zdd„ Zddd„ZdS )é    N)ÚMappingé   )Údot_reducerÚpath_reducerÚtuple_reducerÚunderscore_reducer)Údot_splitterÚpath_splitterÚtuple_splitterÚunderscore_splitter)ÚtupleÚpathÚdotZ
underscorer   F© c              
      s    t ˆƒ‰tfˆ ‰t| ˆƒstdt| ƒˆf ƒ‚ˆdur$ˆdk r$tdƒ‚tˆtƒr-tˆ ‰tt 	ˆ¡j
ƒdk‰i ‰d	‡ ‡‡‡‡‡‡‡‡f	dd„	‰ ˆ | dd� ˆS )
a²  Flatten `Mapping` object.

    Parameters
    ----------
    d : dict-like object
        The dict that will be flattened.
    reducer : {'tuple', 'path', 'underscore', 'dot', Callable}
        The key joining method. If a `Callable` is given, the `Callable` will be
        used to reduce.
        'tuple': The resulting key will be tuple of the original keys.
        'path': Use `os.path.join` to join keys.
        'underscore': Use underscores to join keys.
        'dot': Use dots to join keys.
    inverse : bool
        Whether you want invert the resulting key and value.
    max_flatten_depth : Optional[int]
        Maximum depth to merge.
    enumerate_types : Sequence[type]
        Flatten these types using `enumerate`.
        For example, if we set `enumerate_types` to ``(list,)``,
        `list` indices become keys: ``{'a': ['b', 'c']}`` -> ``{('a', 0): 'b', ('a', 1): 'c'}``.
    keep_empty_types : Sequence[type]
        By default, ``flatten({1: 2, 3: {}})`` will give you ``{(1,): 2}``, that is, the key ``3``
        will disappear.
        This is also applied for the types in `enumerate_types`, that is,
        ``flatten({1: 2, 3: []}, enumerate_types=(list,))`` will give you ``{(1,): 2}``.
        If you want to keep those empty values, you can specify the types in `keep_empty_types`:

        >>> flatten({1: 2, 3: {}}, keep_empty_types=(dict,))
        {(1,): 2, (3,): {}}

    Returns
    -------
    flat_dict : dict
    z3argument type %s is not in the flattenalbe types %sNr   z,max_flatten_depth should not be less than 1.é   c           	         s¸   t | ˆƒr	t| ƒn|  ¡ }d}|D ]H\}}d}ˆr ˆ||| ƒ}nˆ||ƒ}t |ˆƒrCˆd u s2|ˆk rCˆ ||d |d�}|sBt |ˆƒsCqˆrJ||}}|ˆv rUtd |¡ƒ‚|ˆ|< q|S )NFTr   )ÚdepthÚparentúduplicated key '{}')Ú
isinstanceÚ	enumerateÚitemsÚ
ValueErrorÚformat)	Ú_dr   r   Zkey_value_iterableZhas_itemÚkeyÚvalueÚflat_keyZ	has_child©	Ú_flattenÚenumerate_typesZ	flat_dictZflattenable_typesÚinverseÚkeep_empty_typesÚmax_flatten_depthÚreducerZreducer_accepts_parent_objr   új/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/flatten_dict/flatten_dict.pyr   R   s&   ÿ



zflatten.<locals>._flatten)r   )N)r   r   r   r   ÚtypeÚstrÚREDUCER_DICTÚlenÚinspectÚ	signatureÚ
parameters)Údr#   r    r"   r   r!   r   r   r$   Úflatten   s"   +


ÿÿ
r-   c                 C   sb   |sJ ‚|d }t |ƒdkr|| v rtd |¡ƒ‚|| |< dS |  |i ¡} t| |dd… |ƒ dS )z†Set a value to a sequence of nested keys.

    Parameters
    ----------
    d : Mapping
    keys : Sequence[str]
    value : Any
    r   r   r   N)r(   r   r   Ú
setdefaultÚnested_set_dict)r,   Úkeysr   r   r   r   r$   r/   t   s   	r/   c                 C   sN   t |tƒr	t| }i }|  ¡ D ]\}}|r||}}||ƒ}t|||ƒ q|S )a¨  Unflatten dict-like object.

    Parameters
    ----------
    d : dict-like object
        The dict that will be unflattened.
    splitter : {'tuple', 'path', 'underscore', 'dot', Callable}
        The key splitting method. If a Callable is given, the Callable will be
        used to split `d`.
        'tuple': Use each element in the tuple key as the key of the unflattened dict.
        'path': Use `pathlib.Path.parts` to split keys.
        'underscore': Use underscores to split keys.
        'dot': Use dots to split keys.
    inverse : bool
        Whether you want to invert the key and value before flattening.

    Returns
    -------
    unflattened_dict : dict
    )r   r&   ÚSPLITTER_DICTr   r/   )r,   Úsplitterr    Zunflattened_dictr   r   Z	key_tupler   r   r$   Ú	unflattenˆ   s   

r3   )r   FNr   r   )r   F)r)   Úcollections.abcr   Zreducersr   r   r   r   Z	splittersr   r	   r
   r   r'   r1   r-   r/   r3   r   r   r   r$   Ú<module>   s,    üü

ú^