
    Vh                    \    d dl mZ d dlZd dlmZ d dlmZ ddZddZddZ	ddZ
d	 Zd
 Zy)    )annotationsN)deepcopy)MutableMappingc                   fdi }| j                         D ]o  \  }}t        |t              r||vrt        |      |t	        |      <   5t        |t
              r||vr |      |t	        |      <   `||t	        |      <   q |S )a  
    reversible allows two way conversion of a camelized dict
    such that snake_dict_to_camel_dict(camel_dict_to_snake_dict(x)) == x

    This is achieved through mapping e.g. HTTPEndpoint to h_t_t_p_endpoint
    where the default would be simply http_endpoint, which gets turned into
    HttpEndpoint if recamelized.

    ignore_list is used to avoid converting a sub-tree of a dict. This is
    particularly important for tags, where keys are case-sensitive. We convert
    the 'Tags' key but nothing below.
    c                    g }| D ]g  }t        |t              r|j                  t        |             /t        |t              r|j                   |             W|j                  |       i |S N)
isinstancedictappendcamel_dict_to_snake_dictlist)
camel_listchecked_listitem
reversiblevalue_is_lists      `/home/dcms/DCMS/lib/python3.12/site-packages/ansible/module_utils/common/dict_transformations.pyr   z/camel_dict_to_snake_dict.<locals>.value_is_list   sj     	*D$%##$<T:$NOD$'##M$$78##D)	*     )r   )itemsr	   r
   r   _camel_to_snaker   )
camel_dictr   ignore_list
snake_dictkvr   s    `    @r   r   r      s     J  " F1a1K#7D\]^`jDkJqZ@A4 Qk%9DQRSDTJqZ@ADEJqZ@AF r   c                "    dfd	 | |      S )z
    Perhaps unexpectedly, snake_dict_to_camel_dict returns dromedaryCase
    rather than true CamelCase. Passing capitalize_first=True returns
    CamelCase. The default remains False as that was the original implementation
    c                   | y  t        |              }t        | t              r"| D ]  } | |   |      |t        ||      <    |S t        | t              r6t        t        |             D ]  }|j                   | |   |              |S | S r   )typer	   r
   _snake_to_camelr   rangelenr   )complex_typecapitalize_firstnew_typekeyicamelizes        r   r'   z*snake_dict_to_camel_dict.<locals>.camelize=   s    %4%'lD)# qCKLY\L]_oCp.>?@q  d+3|,- Ma:J KLM   r   F )r   r#   r'   s     @r   snake_dict_to_camel_dictr*   6   s     J 011r   c                    |r'dj                  d | j                  d      D              S | j                  d      d   dj                  d | j                  d      dd  D              z   S )N c              3  D   K   | ]  }|j                         xs d   yw_N
capitalize.0xs     r   	<genexpr>z"_snake_to_camel.<locals>.<genexpr>P   s     Gq||~,,G    r/   r   c              3  D   K   | ]  }|j                         xs d   ywr.   r0   r2   s     r   r5   z"_snake_to_camel.<locals>.<genexpr>R   s     ,aqQ\\^-Bs-B,ar6      )joinsplit)snaker#   s     r   r   r   N   s^    wwGekk#6FGGG{{3"RWW,aEKKX[L\]^]_L`,a%aaar   c                   d }|rd}nd}t        j                  |||       }|j                  d      r| j                  d      s|dd  }|r|S d}d}t        j                  |d|      }t        j                  |d|      j                         S )	Nc                F    d| j                  d      j                         z   S )Nr/   r   )grouplower)ms    r   prepend_underscore_and_lowerz5_camel_to_snake.<locals>.prepend_underscore_and_lowerW   s    QWWQZ%%'''r   z[A-Z]z[A-Z]{3,}s$r/   r8   z(.)([A-Z][a-z]+)z([a-z0-9])([A-Z]+)z\1_\2)resub
startswithr?   )namer   rA   upper_patterns1first_cap_patternall_cap_patterns2s           r   r   r   U   s    (   '	;T	BB	}}S$//#"6V	 ,+O	!8R	0B66/8R06688r   c                    t        |t              s|S t        |       }|j                         D ]=  \  }}||v r&t        ||   t              rt	        ||   |      ||<   0t        |      ||<   ? |S )zrecursively merges dicts. not just simple a['key'] = b['key'], if
    both a and b have a key whose value is a dict then dict_merge is called
    on both values and the result stored in the returned dictionary.)r	   r
   r   r   
dict_merge)abresultr   r   s        r   rL   rL   o   sq     aa[F	 $1;:fQi6"6!9a0F1I F1I	$
 Mr   c                P    t        d  fD              s$t        dt               dt              d      t        fd j	                         D              }t         fdj	                         D              }t         j                               t        j                               z  D ]j  }t         |   t              r9t        |   t              r&t         |   |         }|s>|d   ||<   |d   ||<   O |   |   k7  s[ |   ||<   |   ||<   l |s|r||fS y	)
a  Recursively diff two dictionaries

    Raises ``TypeError`` for incorrect argument type.

    :arg dict1: Dictionary to compare against.
    :arg dict2: Dictionary to compare with ``dict1``.
    :return: Tuple of dictionaries of differences or ``None`` if there are no differences.
    c              3  <   K   | ]  }t        |t                y wr   )r	   r   )r3   r   s     r   r5   z!recursive_diff.<locals>.<genexpr>   s     LT
40Ls   zUnable to diff 'dict1' z and 'dict2' z. Both must be a dictionary.c              3  6   K   | ]  \  }}|vs||f  y wr   r)   )r3   r   r   dict2s      r   r5   z!recursive_diff.<locals>.<genexpr>   s     E6AqaunAE   	c              3  6   K   | ]  \  }}|vs||f  y wr   r)   )r3   r   r   dict1s      r   r5   z!recursive_diff.<locals>.<genexpr>   s     FFQq~!QFrT   r   r8   N)	all	TypeErrorr   r
   r   setkeysr	   recursive_diff)rV   rS   leftrightr   rO   s   ``    r   r[   r[   ~   s    LeU^LM8<UT%[R S 	S EU[[]EEDFekkmFFE%**,#ejjl"33  eAh%*U1Xt*D#E!HeAh7F )Q!!9a1Xq!AhDGQxE!H  uU{r   )Fr)   r(   )
__future__r   rB   copyr   .ansible.module_utils.six.moves.collections_abcr   r   r*   r   r   rL   r[   r)   r   r   <module>ra      s5    # 
  I$N20b94r   