%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/utils/ |
Current File : //lib/python2.7/site-packages/salt/utils/dictdiffer.pyo |
� ���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z d � Z d e f d � � YZ d d � Z e d � Z d e f d � � YZ d S( 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 ( t absolute_importt print_functiont unicode_literalsN( t Mapping( t sixc C@ s t | | � S( N( t DictDiffer( t current_dictt past_dict( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt diff s R c B@ s; e Z d Z d � Z d � Z d � Z d � Z d � Z RS( 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 c C@ sZ | | | _ | _ t t | � � t t | � � | _ | _ | j j | j � | _ d S( N( R R t sett listt set_currentt set_pastt intersectiont intersect( t selfR R ( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt __init__ s +c C@ s | j | j S( N( R R ( R ( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt added% s c C@ s | j | j S( N( R R ( R ( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt removed( s c @ s t � f d � � j D� � S( Nc 3@ s/ | ]% } � j | � j | k r | Vq d S( N( R R ( t .0t o( R ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pys <genexpr>, s ( R R ( R ( ( R s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt changed+ s c @ s t � f d � � j D� � S( Nc 3@ s/ | ]% } � j | � j | k r | Vq d S( N( R R ( R R ( R ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pys <genexpr>/ s ( R R ( R ( ( R s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt unchanged. s ( t __name__t __module__t __doc__R R R R R ( ( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR s c C@ s� | p g } i } t j | � } t j | � } | | t f g } x\t | � d k r�g } | j � \ } } } xt t | � t | � � D]� } | | k r� | | k r� | | | | k r� | | =| | =q� n | s� | | k r� | | k r� | | =n | | k r| | k r| | =n t | j | � t � rst | j | � t � rs| j | | | | t f � qsq� q� W| rE | j | | t f g | � qE qE W| r�| | d <n | r�| | d <n | S( Ni u oldu new( t copyt deepcopyt Falset lent popR R t isinstancet getR t appendt extendt True( t oldt newt ignoret rest stackt tmpst tmp_oldt tmp_newt reentrantt key( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt deep_diff2 s: # ($ c C@ s t | | | � 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. ( t RecursiveDictDiffer( R R t ignore_missing_keys( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyt recursive_diffS s R/ c B@ s� e Z d Z d Z d � Z e d � � Z e d d � � Z e d � � Z d � Z d � Z d � Z d � Z e d � � Z e d � � Z e d � � Z e d � � Z RS( 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_>c C@ sD t t | � j | | � | j | j | j | � | _ t | _ d S( 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( t superR/ R t _get_diffsR R t _diffsR# t ignore_unset_values( R R R R0 ( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR � s c C@ s[ i } x� | j � D]� } | | k rQ | j i i | | d 6| j d 6| 6� q | | | | k r t | | t � r� t | | t � r� | j | | | | | � } | r� | j i | | 6� q� q� | j i i | | d 6| | d 6| 6� q q W| sWxU | j � D]D } | | j � k r| j i i | j d 6| | d 6| 6� qqWn | 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 u newu old( t keyst updatet NONE_VALUER t dictR3 ( t clst dict1t dict2R0 t ret_dictt pt sub_diff_dict( ( s9 /usr/lib/python2.7/site-packages/salt/utils/dictdiffer.pyR3 � s"