
    ~i                     *    d dl Z  G d de          ZdS )    Nc                   $    e Zd ZddZd ZddZdS )	Flatten.   Nc                 L    || _         || _        || _        || _        || _        dS )aO  
        :param nested_dict: dictionary we want to flatten
        :param start_index: start index for list param
        :param separator: string to separate dictionary keys by
        :param root_keys_to_ignore: set of root keys to ignore from flattening
        :param str replace_separators: Replace separators within keys
        N)nested_dict	separatorstart_indexroot_keys_to_ignorereplace_separators)selfr   r	   r
   r   r   s         b/root/.openclaw/workspace/.venvs/ark-sdk/lib/python3.11/site-packages/volcenginesdkcore/flatten.py__init__zFlatten.__init__
   s1     '"&#6 "4    c                 h    t           j        t                    st          d          t           j        t
          j                  st          d           j        t                      t           j                  dk    ri S t                       fd  j        d            S )Nz#flatten requires a dictionary inputzseparator must be stringr   c           
         | s| |<   dS t          | t                    r@| D ];}|s|v s3 | |                             |j        |j                             <dS t          | t
          t          t          f          rLt          |           D ]:\  }} |                    |j        |j	        z   j                             ;dS | |<   dS )aY  
            For dict, list and set objects_ calls itself on the elements and for
            other types assigns the object_ to
            the corresponding key in the global flattened_dict
            :param object_: object to flatten
            :param key: carries the concatenated key for the object_
            :return: None
            )r   N)

isinstancedict_construct_keyr	   r   listsettuple	enumerater
   )	object_key
object_keyindexitem_flattenflattened_dictr   r   s	        r   r   zFlatten.flat.<locals>._flatten)   sT     .&-s###GT** .") M MJ # M
6I(I(I #J/ // # $ *373J	 0 L LM M MM M GdC%788 .#,W#5#5 I IKE4H++ N!D$44/3/F	 , H HI I I II I '.s###r   )
r   r   r   	TypeErrorr	   sixstring_typesr   r   len)r   r   r    r   s   `@@@r   flatzFlatten.flat   s    $*D11 	CABBB$.#*:;; 	86777#+"%%%t  A%%I "	. "	. "	. "	. "	. "	. "	. "	.H 	!4(((r   c                     |#t          |                              ||          }|rd                    |||          S |S )a  
        Returns the new_key if no previous key exists, otherwise concatenates
        previous key, separator, and new_key
        :param previous_key:
        :param separator:
        :param new_key:
        :param str replace_separators: Replace separators within keys
        :return: a string if previous_key exists and simply passes through the
        new_key otherwise
        Nz{}{}{})strreplaceformat)r   previous_keyr	   new_keyr   s        r   r   zFlatten._construct_keyP   sK     )'ll**96HIIG 	##L)WEEENr   )r   r   NN)N)__name__
__module____qualname__r   r%   r    r   r   r   r      sL        5 5 5 56 6 6p     r   r   )r"   objectr   r/   r   r   <module>r1      sN   
 


X X X X Xf X X X X Xr   