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__/listdiffer.cpython-310.pyc
o

�N�g�+�@s*dZddlmZdd�ZGdd�d�ZdS)a�
Compare lists of dictionaries by a specified key.

The following can be retrieved:
    (1) List of added, removed, intersect elements
    (2) List of diffs having the following format:
        <key_val>: {<elem_key: {'old': <old_value>, 'new': <new_value>}}
        A recursive diff is done between the values (dicts) with the same
        key
    (3) List with the new values for each key
    (4) List with the old values for each key
    (5) List of changed items in the format
        ('<key_val>.<elem_key>', {'old': <old_value>, 'new': <new_value>})
    (5) String representations of the list diff

Note: All dictionaries keys are expected to be strings
���recursive_diffcCst|||�S�N)�ListDictDiffer)Zlist_aZlist_b�key�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/listdiffer.py�	list_diffsr	c@s�eZdZdZdd�Zdd�Zedd��Zedd	��Zed
d��Z	d"dd�Z
edd��Zedd��Zed#dd��Z
edd��Zedd��Zd$dd�Zedd��Zed d!��ZdS)%rz�
    Calculates the differences between two lists of dictionaries.

    It matches the items based on a given key and uses the recursive_diff to
    diff the two values.
    cCs�g|_g|_g|_||_||_||_|D]C}||vr$td�||�����|D]*}||vr6td�||�����||||krP|||d|d|i}|j�	|�nq&|j�	|�q|D]}|D]}||||krjnq^|j�	|�qZdS)NzHThe supplied key '{}' does not exist in item, the available keys are: {}�old�new)
�
_intersect�_removed�_added�_new�_current�_key�
ValueError�format�keys�append)�self�current_listZ	next_listrZcurrent_itemZ	next_item�itemrrr�__init__"sB�������zListDictDiffer.__init__cCs�|dkrdd�|jD�S|dkrdd�|jD�S|dkr$dd�|jD�S|dkrMg}|�d	d�|jD��|�d
d�|jD��|�dd�|jD��|Std��)
z.Returns the recursive diff between dict values�	intersectcS�g|]}t|d|d��qS�r
rr��.0rrrr�
<listcomp>Hs�z<ListDictDiffer._get_recursive_difference.<locals>.<listcomp>�addedcS�g|]}ti|��qSrrrrrrrL��removedcS�g|]	}t|idd��qS�F)Zignore_missing_keysrrrrrrN����allcSrrrrrrrrUscSr!rrrrrrrWr"cSr$r%rrrrrrYr&z<The given type for recursive list matching is not supported.)rrr
�extendr)r�typeZrecursive_listrrr�_get_recursive_differenceEs2������z(ListDictDiffer._get_recursive_differencecC�|jS)z3Returns the objects which are removed from the list)r
�rrrrr#d�zListDictDiffer.removedcCr+)z/Returns the objects which are added to the list)rr,rrrr ir-zListDictDiffer.addedcCr+)zReturns the intersect objects)rr,rrrrnr-zListDictDiffer.intersectNrcCs\|dkr|jD]}|d�|d�|d�|d�q|dkr*|jD]
}|�|d�q!dSdS)z6Deletes an attribute from all of the intersect objectsrr
Nrr#)r�popr
)rZdiff_keyZ	diff_listrrrr�remove_diffss

�zListDictDiffer.remove_diffcCs^g}|jdd�D]$}|jr,|jr|�|j|j|ji�q|jr,|�|j|j|ji�q|S)z�
        Returns a list of dictionaries with key value pairs.
        The values are the differences between the items identified by the key.
        r'�r))r*�diffs�	past_dictrr�current_dict)rZdifferencesrrrrr1}s�zListDictDiffer.diffscCs�d}|jdd�D]}|jr#d�|d�|j|j|j|j�dd��g�}q|jdd�D]}|jr?d�|d�|j|j|j�g�}q*|jd	d�D]}|jr[d�|d
�|j|j|j�g�}qF|S)z'Returns a string describing the changes�rr0z	identified by {} {}:
	{}
�
z
	r#z'	identified by {} {}:
	will be removed
r z%	identified by {} {}:
	will be added
)	r*r1�joinrrr2�changes_str�replacer3)r�changesrrrrr7�sD
����
����	����	zListDictDiffer.changes_str�  cCs�g}|jdd�D]}|jr&|�dj|j|j|j|j�dd�|��|d��q|jdd�D]}|jrB|�dj|j|j|j|d��q-|jd	d�D]}|jrb|�d
j|j|j|jt	|j�|d��qId�
|�S)z�
        Returns a string in a more compact format describing the changes.

        The output better alligns with the one in recursive_diff.
        rr0z%{tab}{0}={1} (updated):
{tab}{tab}{2}r5z
{0}{0})�tabr#z{tab}{0}={1} (removed)r z{tab}{0}={1} (added): {2})r*r1rrrr2r7r8r3�dictr6)rZ
tab_stringr9rrrr�changes_str2�s@
������
���
zListDictDiffer.changes_str2c�$�fdd���fdd���d�D�S)z$Returns the new values from the diffcsD|j}|jr|��j|j�ji�|S|��j|j�ji�|Sr)�
new_valuesr2�updaterr3�r�valuesr,rr�get_new_values_and_key�s�z9ListDictDiffer.new_values.<locals>.get_new_values_and_keyc� g|]}|jr|jr�|��qSr)r1r3�r�el)rCrrr�����z-ListDictDiffer.new_values.<locals>.<listcomp>r'�r*r,r)rCrrr?�s
	�zListDictDiffer.new_valuescr>)z$Returns the old values from the diffcs"|j}|��j|j�ji�|Sr)�
old_valuesr@rr2rAr,rr�get_old_values_and_key�sz9ListDictDiffer.old_values.<locals>.get_old_values_and_keycrDr)r1r2rE)rJrrr�rGz-ListDictDiffer.old_values.<locals>.<listcomp>r'rHr,r)rJrrrI�s
�zListDictDiffer.old_valuesr'c	Csg}|dkrB|jdd�D]3}d|_|j|jvrt|j|j�nt|j|j�}|��D]}||jkr>|�d�|j||g��q+q|S|dkr�|jdd�D]3}d|_|j|jvr_t|j|j�nt|j|j�}|��D]}||jkr~|�d�|j||g��qkqL|SdS)aS
        Returns the list of changed values.
        The key is added to each item.

        selection
            Specifies the desired changes.
            Supported values are
                ``all`` - all changed items are included in the output
                ``intersect`` - changed items present in both lists are included
        r'r0F�.rN)	r*Zignore_unset_valuesrr2�strr3�changedrr6)rZ	selectionrMZrecursive_itemZkey_valZchangerrrrM�s8��
����
���zListDictDiffer.changedcCr+r)rr,rrrr'�zListDictDiffer.current_listcCr+r)rr,rrr�new_list+rNzListDictDiffer.new_list)Nr)r:)r')�__name__�
__module__�__qualname__�__doc__rr*�propertyr#r rr/r1r7r=r?rIrMrrOrrrrrs4#






*$


)
rN)rSZsalt.utils.dictdifferrr	rrrrr�<module>s