File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/listdiffer.cpython-310.pyc
o
�N�g�+ � @ s* d Z ddlmZ dd� ZG dd� 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_diffc C s t | ||�S �N)�ListDictDiffer)Zlist_aZlist_b�key� r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/listdiffer.py� list_diff s r c @ s� e Zd ZdZdd� Zdd� Zedd� �Zedd � �Zed
d� �Z d"dd�Z
edd� �Zedd� �Zed#dd��Z
edd� �Zedd� �Zd$dd�Zedd� �Zed d!� �ZdS )%r z�
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.
c C s� g | _ g | _g | _|| _|| _|| _|D ]C}||vr$td�||�� ���|D ]*}||vr6td�||�� ���|| || krP||| d|d|i}| j � |� nq&| j� |� q|D ]}|D ]}|| || krj nq^| j� |� qZd S )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_listr Zcurrent_itemZ next_item�itemr r r �__init__"