HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/dictdiffer.cpython-310.pyc
o

�N�g�A�@sVdZddlZddlmZdd�ZGdd�d�Zddd	�Zddd�ZGd
d�de�ZdS)a�
 Calculate the difference between two dictionaries as:
    (1) items added
    (2) items removed
    (3) keys same in both but changed values
    (4) keys same in both and unchanged values

  Originally posted at http://stackoverflow.com/questions/1165352/fast-comparison-between-two-python-dictionary/1165552#1165552
  Available at repository: https://github.com/hughdbrown/dictdiffer

  Added the ability to recursively compare dictionaries
�N)�MappingcCs
t||�S�N)�
DictDiffer)�current_dict�	past_dict�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/dictdiffer.py�diffs
r	c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
rz�
    Calculate the difference between two dictionaries as:
    (1) items added
    (2) items removed
    (3) keys same in both but changed values
    (4) keys same in both and unchanged values
    cCs@|||_|_tt|��tt|��|_|_|j�|j�|_dSr)rr�set�list�set_current�set_past�intersection�	intersect)�selfrrrrr�__init__szDictDiffer.__init__cC�|j|jSr)rr�rrrr�added$�zDictDiffer.addedcCrr)r
rrrrr�removed'rzDictDiffer.removedc��fdd��jD�S)Ncs$h|]}�j|�j|kr|�qSr�rr��.0�orrr�	<setcomp>+�$z%DictDiffer.changed.<locals>.<setcomp>�rrrrr�changed*�zDictDiffer.changedcr)Ncs$h|]}�j|�j|kr|�qSrrrrrrr.rz'DictDiffer.unchanged.<locals>.<setcomp>rrrrr�	unchanged-r zDictDiffer.unchangedN)	�__name__�
__module__�__qualname__�__doc__rrrrr!rrrrrsrc
Cs,|pg}i}t�|�}t�|�}||dfg}|r�g}|��\}}}tt|�t|��D]M}	|	|vrD|	|vrD||	||	krD||	=||	=q+|sx|	|vrQ|	|vrQ||	=|	|vr\|	|vr\||	=t|�|	�t�rxt|�|	�t�rx|�||	||	df�q+|r�|�	||dfg|�|s|r�||d<|r�||d<|S)NFT�old�new)
�copy�deepcopy�popr
r�
isinstance�getr�append�extend)
r&r'�ignore�res�stackZtmpsZtmp_oldZtmp_newZ	reentrant�keyrrr�	deep_diff1s>

 
���r3TcCst|||�S)a�
    Returns a RecursiveDictDiffer object that computes the recursive diffs
    between two dictionaries

    past_dict
            Past dictionary

    current_dict
        Current dictionary

    ignore_missing_keys
        Flag specifying whether to ignore keys that no longer exist in the
        current_dict, but exist in the past_dict. If true, the diff will
        not contain the missing keys.
        Default is True.
    )�RecursiveDictDiffer)rr�ignore_missing_keysrrr�recursive_diffRsr6cs�eZdZdZdZ�fdd�Zedd��Zed"dd	��Zed
d��Z			
			d#dd�Z
	d$dd�Z	d$dd�Zd%dd�Z
d%dd�Zedd��Zedd��Zedd��Zed d!��Z�ZS)&r4a�
    Calculates a recursive diff between the current_dict and the past_dict
    creating a diff in the format

    {'new': new_value, 'old': old_value}

    It recursively searches differences in common keys whose values are
    dictionaries creating a diff dict in the format

    {'common_key' : {'new': new_value, 'old': old_value}

    The class overrides all DictDiffer methods, returning lists of keys and
    subkeys using the . notation (i.e 'common_key1.common_key2.changed_key')

    The class provides access to:
        (1) the added, removed, changes keys and subkeys (using the . notation)
               ``added``, ``removed``, ``changed`` methods
        (2) the diffs in the format above (diff property)
                ``diffs`` property
        (3) a dict with the new changed values only (new_values property)
                ``new_values`` property
        (4) a dict with the old changed values only (old_values property)
                ``old_values`` property
        (5) a string representation of the changes in the format:
                ``changes_str`` property

    Note:
        The <_null_> value is a reserved value

    .. code-block:: text

        common_key1:
          common_key2:
            changed_key1 from '<old_str>' to '<new_str>'
            changed_key2 from '[<old_elem1>, ..]' to '[<new_elem1>, ..]'
        common_key3:
          changed_key3 from <old_int> to <new_int>

    z<_null_>cs,t��||�|�|j|j|�|_d|_dS)aQ
        past_dict
            Past dictionary.

        current_dict
            Current dictionary.

        ignore_missing_keys
            Flag specifying whether to ignore keys that no longer exist in the
            current_dict, but exist in the past_dict. If true, the diff will
            not contain the missing keys.
        TN)�superr�
_get_diffsrr�_diffs�ignore_unset_values)rrrr5��	__class__rrr�s


�
zRecursiveDictDiffer.__init__cCs�i}|D]M}||vr|�||||jd�i�q||||krQt||t�rCt||t�rC|�|||||�}|rB|�||i�q|�|||||d�i�q|sj|D]}||vri|�||j||d�i�qV|S)a
        Returns a dict with the differences between dict1 and dict2

        Notes:
            Keys that only exist in dict2 are not included in the diff if
            ignore_missing_keys is True, otherwise they are
            Simple compares are done on lists
        )r'r&)�update�
NONE_VALUEr+�dictr8)�clsZdict1Zdict2r5�ret_dict�pZ
sub_diff_dictrrrr8�s(
����zRecursiveDictDiffer._get_diffsr'cCsRi}|D]"}|||vr|�||||i�q|�||j|||d�i�q|S)z�
        Returns a dictionaries with the 'new' values in a diff dict.

        type
            Which values to return, 'new' or 'old'
        ��type)r=�_get_values)r@�	diff_dictrDrArBrrrrE�szRecursiveDictDiffer._get_valuesc	Csg}t|�D]w}t||�ddhkrb||d||dd�}dD].}||}||jkr1d||<q!t|t�r?d|�d�||<q!t|t�rOdd�|��d�||<q!|�|�d|d�d	|d
���q|�||�}|r}|�|�d��|�	dd
�|D��q|S)z�
        Returns a list of string message with the differences in a diff dict.

        Each inner difference is tabulated two space deeper
        r'r&)�	old_value�	new_valueZnothing�'z, z from rGz to rH�:cSsg|]}d|���qS)z  r)r�crrr�
<listcomp>�sz4RecursiveDictDiffer._get_changes.<locals>.<listcomp>)
�sortedr
r>r+�strr�joinr-�_get_changesr.)r@rFZchanges_stringsrBZchanges�ref�valZsub_changesrrrrP�s0

�



���z RecursiveDictDiffer._get_changesFN��.c
Cs�g}|dur	|j}|D]�}	|r|�|�|	���t||	t�s q|r<|r<|�|j||||	|�|	�|��|||d��qd||	vrZ|�|j||||	|�|	�|��|||d��q||	||jkr�|�|�|	���t||	|t�r�|r�|�|j||||	|d|�|	�|��||d��q|s�t||	|t�s�t||	|t�r�|�|j||||	|d|�|	�|��||d��q|S)N)�diffs�prefix�	is_nested�include_nested�	separatorr&T)rUrWrVrXrY)rUr-r+r?r.�	_it_addrmr>)
rZkey_aZkey_brXrUrVrWrY�keysr2rrrrZ�s�
����
���
���
���zRecursiveDictDiffer._it_addrmcC�t|jdd||d��S)ar
        Returns all keys that have been added.

        include_nested
            If an added key contains a dictionary, include its
            keys in dot notation as well. Defaults to false.

            .. versionadded:: 3006.0

        separator
            Separator used to indicate nested keys. Defaults to ``.``.

            .. versionadded:: 3006.0
        r&r'�rY�rMrZ�rrXrYrrrrC�zRecursiveDictDiffer.addedcCr\)at
        Returns all keys that have been removed.

        include_nested
            If an added key contains a dictionary, include its
            keys in dot notation as well. Defaults to false.

            .. versionadded:: 3006.0

        separator
            Separator used to indicate nested keys. Defaults to ``.``.

            .. versionadded:: 3006.0
        r'r&r]r^r_rrrrVr`zRecursiveDictDiffer.removedcs"��fdd��t��jd|d��S)z�
        Returns all keys that have been changed.

        separator
            Separator used to indicate nested keys. Defaults to ``.``.

            .. versionadded:: 3006.0
        cs�g}|D]�}t||t�sqt||t�r.d||vr.|��|||�|�|��|d��q�jr�d||vrwd||vrw||d�jkrw||d�jkrwt||dt�rm|��||d|�|�|��|d��q|�|�|���qt||t�r�|��|||�|�|��|d��qd||vr�d||vr�t||dt�r�|��||d|�|�|��|d��q|�|�|���qt||t�r�|��|||�|�|��|d��q|S)Nr&�rVrYr')r+r?r.r:r>r-)rUrVrYr[r2��_changedrrrrcssp��
�����
�����z-RecursiveDictDiffer.changed.<locals>._changedrSra)rMr9�rrYrrbrris
?zRecursiveDictDiffer.changedcs$�fdd��t�|j|jd|d��S)z�
        Returns all keys that have been unchanged.

        separator
            Separator used to indicate nested keys. Defaults to ``.``.

            .. versionadded:: 3006.0
        c	stg}|D]3}||vr|�|�|���qt||t�r7d||vr"q|��|||||�|�|��|d��q|S)Nr'ra)r-r+r?r.)rrUrVrYr[r2��
_unchangedrrrf�s"���	z1RecursiveDictDiffer.unchanged.<locals>._unchangedrSra)rMrr9rdrrerr!�s
�zRecursiveDictDiffer.unchangedcCs|jS)z@Returns a dict with the recursive diffs current_dict - past_dict)r9rrrrrU�szRecursiveDictDiffer.diffscC�|j|jdd�S)z(Returns a dictionary with the new valuesr'rC�rEr9rrrr�
new_values��zRecursiveDictDiffer.new_valuescCrg)z(Returns a dictionary with the old valuesr&rCrhrrrr�
old_values�rjzRecursiveDictDiffer.old_valuescCsd�|�|j��S)z'Returns a string describing the changes�
)rOrPr9rrrr�changes_str�szRecursiveDictDiffer.changes_str)r')FNrSFrT)FrT)rT)r"r#r$r%r>r�classmethodr8rErPrZrrrr!�propertyrUrirkrm�
__classcell__rrr;rr4fs<(

$
�Q
�
�

K"


r4r)T)	r%r(�collections.abcrr	rr3r6r4rrrr�<module>s


!