%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/listdiffer.pyo

�
���^c@@s_dZddlmZmZddlmZddlmZd�Zde	fd��YZ
dS(	u�
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 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
i(tabsolute_importtunicode_literals(trecursive_diff(tsixcC@st|||�S(N(tListDictDiffer(tlist_atlist_btkey((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyt	list_diffsRcB@s�eZdZd�Zd�Zed��Zed��Zed��Zddd�Z
ed��Zed	��Zed
d��Z
ed��Zed
��Zdd�Zed��Zed��ZRS(u�
    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.
    cC@sWg|_g|_g|_||_||_||_x�|D]�}||krptdj||j����nx�|D]z}||kr�tdj||j����n||||krwi|||6|d6|d6}|jj	|�PqwqwW|jj	|�q=WxG|D]?}x6|D]}||||krPqqW|jj	|�qWdS(NuJThe supplied key '{0}' does not exist in item, the available keys are: {1}uoldunew(
t
_intersectt_removedt_addedt_newt_currentt_keyt
ValueErrortformattkeystappend(tselftcurrent_listt	next_listRtcurrent_itemt	next_itemtitem((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyt__init__$s4						
	
	


cC@sS|dkr7g|jD]}t|d|d�^qS|dkrfg|jD]}ti|�^qMS|dkr�g|jD]}t|idt�^q|S|dkrCg}|jg|jD]}t|d|d�^q��|jg|jD]}ti|�^q��|jg|jD]}t|idt�^q�|Std��d	S(
u.Returns the recursive diff between dict valuesu	intersectuoldunewuaddeduremovedtignore_missing_keysuallu<The given type for recursive list matching is not supported.N(R	RRR
tFalsetextendR(RttypeRtrecursive_list((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyt_get_recursive_differenceEs+#&4,	)cC@s|jS(u3Returns the objects which are removed from the list(R
(R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytremovedZscC@s|jS(u/Returns the objects which are added to the list(R(R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytadded_scC@s|jS(uReturns the intersect objects(R	(R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyt	intersectdsu	intersectcC@s�|dkrKx<|jD].}|dj|d�|dj|d�qWn|dkr~x$|jD]}|j|d�qaWndS(u6Deletes an attribute from all of the intersect objectsu	intersectuoldunewuremovedN(R	tpoptNoneR
(Rtdiff_keyt	diff_listR((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytremove_diffiscC@s�g}x�|jdd�D]l}|jr|jrU|ji|j|j|j6�q�|jr�|ji|j|j|j6�q�qqW|S(u�
        Returns a list of dictionaries with key value pairs.
        The values are the differences between the items identified by the key.
        Ruall(Rtdiffst	past_dictRRtcurrent_dict(RtdifferencesR((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR(ss		$	+c	C@s!d}xf|jdd�D]R}|jrdj|dj|j|j|j|jjdd��g�}qqWxT|jdd�D]@}|jr�dj|dj|j|j|j�g�}q�q�WxT|jdd	�D]@}|jr�dj|d
j|j|j|j�g�}q�q�W|S(u'Returns a string describing the changesuRu	intersectu	identified by {0} {1}:
	{2}
u
u
	uremovedu)	identified by {0} {1}:
	will be removed
uaddedu'	identified by {0} {1}:
	will be added
(	RR(tjoinRRR)tchanges_strtreplaceR*(RtchangesR((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR-�s*		
%		 		 u  c	C@s9g}xm|jdd�D]Y}|jr|jdj|j|j|j|jjddj|��d|��qqWxR|jdd�D]>}|jr�|jdj|j|j|jd|��q�q�Wx^|jdd	�D]J}|jr�|jd
j|j|j|jt	|j�d|��q�q�Wdj
|�S(u�
        Returns a string in a more compact format describing the changes.

        The output better alligns with the one in recursive_diff.
        Ru	intersectu%{tab}{0}={1} (updated):
{tab}{tab}{2}u
u
{0}{0}ttaburemovedu{tab}{0}={1} (removed)uaddedu{tab}{0}={1} (added): {2}(RR(RRRR)R-R.R*tdictR,(Rt
tab_stringR/R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytchanges_str2�s&			'	 c@sG�fd�}g�jd�D]$}|jr|jr||�^qS(u$Returns the new values from the diffc@s[|j}|jr6|ji|j�j�j6�n!|ji|j�j�j6�|S(N(t
new_valuesR)tupdateRR*(Rtvalues(R(s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytget_new_values_and_key�s
		$!uall(RR(R*(RR7tel((Rs9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR4�s	c@sG�fd�}g�jd�D]$}|jr|jr||�^qS(u$Returns the old values from the diffc@s.|j}|ji|j�j�j6�|S(N(t
old_valuesR5R)R(RR6(R(s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytget_old_values_and_key�s	!uall(RR(R)(RR:R8((Rs9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR9�suallcC@s�g}|dkr�x�|jdd�D]�}t|_|j|jkr_tj|j|j�ntj|j|j�}xH|j�D]:}||jkr�|j	dj
|j||g��q�q�Wq%W|S|dkr�x�|jdd�D]�}t|_|j|jkr$tj|j|j�ntj|j|j�}xH|j�D]:}||jkrJ|j	dj
|j||g��qJqJWq�W|SdS(uS
        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
        uallRu.u	intersectN(RRtignore_unset_valuesRR)Rt	text_typeR*tchangedRR,(Rt	selectionR=trecursive_itemtkey_valtchange((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR=�s&	+-	+-cC@s|jS(N(R
(R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyR�scC@s|jS(N(R(R((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pytnew_listsN(t__name__t
__module__t__doc__RRtpropertyR R!R"R$R'R(R-R3R4R9R=RRB(((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyRs 	!	
%N(REt
__future__RRtsalt.utils.dictdifferRtsalt.extRRtobjectR(((s9/usr/lib/python2.7/site-packages/salt/utils/listdiffer.pyt<module>s
	

Zerion Mini Shell 1.0