%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyc

�
���^c@@s�dZddlmZmZmZddlZddlmZddlm	Z	d�Z
defd��YZdd	�Zed
�Zdefd��YZdS(
u�
 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
i(tabsolute_importtprint_functiontunicode_literalsN(tMapping(tsixcC@s
t||�S(N(t
DictDiffer(tcurrent_dictt	past_dict((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytdiffsRcB@s;eZdZd�Zd�Zd�Zd�Zd�ZRS(u�
    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
    cC@sZ|||_|_tt|��tt|��|_|_|jj|j�|_dS(N(RRtsettlisttset_currenttset_pasttintersectiont	intersect(tselfRR((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt__init__ s+cC@s|j|jS(N(RR(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytadded%scC@s|j|jS(N(RR(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytremoved(sc@st�fd��jD��S(Nc3@s/|]%}�j|�j|kr|VqdS(N(RR(t.0to(R(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pys	<genexpr>,s(R	R(R((Rs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytchanged+sc@st�fd��jD��S(Nc3@s/|]%}�j|�j|kr|VqdS(N(RR(RR(R(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pys	<genexpr>/s(R	R(R((Rs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt	unchanged.s(t__name__t
__module__t__doc__RRRRR(((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRs				c
C@s�|p	g}i}tj|�}tj|�}||tfg}x\t|�dkr�g}|j�\}}}xtt|�t|��D]�}	|	|kr�|	|kr�||	||	kr�||	=||	=q�n|s�|	|kr�|	|kr�||	=n|	|kr|	|kr||	=nt|j|	�t	�rst|j|	�t	�rs|j
||	||	tf�qsq�q�W|rE|j||tfg|�qEqEW|r�||d<n|r�||d<n|S(Niuoldunew(
tcopytdeepcopytFalsetlentpopR	R
t
isinstancetgetRtappendtextendtTrue(
toldtnewtignoretreststackttmpsttmp_oldttmp_newt	reentranttkey((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt	deep_diff2s:#

($

cC@st|||�S(u�
    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.
    (tRecursiveDictDiffer(RRtignore_missing_keys((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytrecursive_diffSsR/cB@s�eZdZdZd�Zed��Zedd��Zed��Zd�Z	d�Z
d	�Zd
�Ze
d��Ze
d��Ze
d
��Ze
d��ZRS(u�
    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 aboce (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>

    u<_null_>cC@sDtt|�j||�|j|j|j|�|_t|_dS(uQ
        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.
        N(	tsuperR/Rt
_get_diffsRRt_diffsR#tignore_unset_values(RRRR0((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR�s
cC@s[i}x�|j�D]�}||krQ|jii||d6|jd6|6�q||||krt||t�r�t||t�r�|j|||||�}|r�|ji||6�q�q�|jii||d6||d6|6�qqW|sWxU|j�D]D}||j�kr|jii|jd6||d6|6�qqWn|S(u
        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
        unewuold(tkeystupdatet
NONE_VALUERtdictR3(tclstdict1tdict2R0tret_dicttpt
sub_diff_dict((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR3�s"
,&	1unewcC@s}i}xp|j�D]b}|||j�krN|ji||||6�q|ji|j||d|�|6�qW|S(u�
        Returns a dictionaries with the 'new' values in a diff dict.

        type
            Which values to return, 'new' or 'old'
        ttype(R6R7t_get_values(R:t	diff_dictR@R=R>((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRA�s%cC@s�g}x�t|j��D]�}t||j��ddgkr�||d}||d|jkrod}nnt||dtj�r�dj||d�}n:t||dt�r�djdj||d��}n||d}||d|jkrd}nnt||dtj�r?dj||d�}n:t||dt�rydjdj||d��}n|j	dj|||��q|j
||�}|r|j	dj|��|jg|D]}dj|�^q��qqW|S(	u�
        Returns a list of string message with the differences in a diff dict.

        Each inner difference is tabulated two space deeper
        unewuoldunothingu'{0}'u, u{0} from {1} to {2}u{0}:u  {0}(tsortedR6R8RRtstring_typestformatR
tjoinR!t_get_changesR"(R:RBtchanges_stringsR>t	old_valuet	new_valuetsub_changestc((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRG�s4"		#	'c@s+��fd��t��jdd��S(u�
        Returns all keys that have been added.

        If the keys are in child dictionaries they will be represented with
        . notation
        c	@s�g}x�|j�D]�}t||t�rhd||krh|j�||ddj||���q||d�jkrt||dt�r�|j�||dddj||���q�|jdj||��qqW|S(Nuoldtprefixu{0}{1}.unewu{0}{1}(R6RR9R"RER8R!(tdiffsRMR6R-(t_addedR(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRO�s# RMu(RCR4(R((RORs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR�sc@s+��fd��t��jdd��S(u�
        Returns all keys that have been removed.

        If the keys are in child dictionaries they will be represented with
        . notation
        c	@s�g}x�|j�D]�}t||t�rhd||krh|j�||ddj||���q||d�jkr�|jdj||��qt||dt�r|j�||dddj||���qqW|S(NuoldRMu{0}{1}.unewu{0}{1}(R6RR9R"RER8R!(RNRMR6R-(t_removedR(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRPs#RMu(RCR4(R((RPRs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRsc@s+��fd��t��jdd��S(u�
        Returns all keys that have been changed.

        If the keys are in child dictionaries they will be represented with
        . notation
        c@sJg}x=|j�D]/}t||t�s2qnt||t�r�d||kr�|j�||ddj||���qn�jr�d||kr>d||kr>||d�jkr>||d�jkr>t||dt�r"|j�||dddj||���q}|jdj||��qBt||t�rB|j�||ddj||���qBqd||krd||krt||dt�r�|j�||dddj||���qB|jdj||��qt||t�r|j�||ddj||���qqW|S(NuoldRMu{0}{1}.unewu{0}{1}(R6RR9R"RER5R8R!(RNRMR6R-(t_changedR(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRQ-s@#	 
 
RMu(RCR4(R((RQRs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR&s'c@s.�fd��t�|j|jdd��S(u�
        Returns all keys that have been unchanged.

        If the keys are in child dictionaries they will be represented with
        . notation
        c	@s�g}x�|j�D]�}||krA|jdj||��qt||t�rd||krjqq�|j�||||ddj||���qqW|S(Nu{0}{1}unewRMu{0}{1}.(R6R!RERR9R"(RRNRMR6R-(t
_unchanged(s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRR]s

RMu(RCRR4(R((RRs9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRVscC@s|jS(u@Returns a dict with the recursive diffs current_dict - past_dict(R4(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyRNoscC@s|j|jdd�S(u(Returns a dictionary with the new valuesR@unew(RAR4(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt
new_valuestscC@s|j|jdd�S(u(Returns a dictionary with the old valuesR@uold(RAR4(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt
old_valuesyscC@sdj|j|j��S(u'Returns a string describing the changesu
(RFRGR4(R((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pytchanges_str~s(RRRR8RtclassmethodR3RARGRRRRtpropertyRNRSRTRU(((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR/gs'	$			0	(Rt
__future__RRRRtcollectionsRtsalt.extRRtobjectRtNoneR.R#R1R/(((s9/usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt<module>
s	!

Zerion Mini Shell 1.0