3 ^4@sddlmZmZddlmZddlmZddlmZm Z ddl m Z ddl m Z dd lmZed d d d gZGdddeZGddde ZdS)) defaultdict namedtuple) MLSRuletype)DiffResultDescriptor) DifferenceWrapper) RangeWrapper)class_wrapper_factory)type_or_attr_wrapper_factoryZmodified_mlsruleruleZ added_defaultZremoved_defaultc@sPeZdZdZedZedZedZee Z ee Z ddZ ddZ ddZd S) MLSRulesDifferencez;Determine the difference in MLS rules between two policies.diff_range_transitionscCs|jjdj||j s"|j r*|j|j|j|jtj t |j|jtj t \}}}g}x:|D]2\}}t |j t |j krf|j t||j |j qfW||_||_||_dS)zGGenerate the difference in range_transition rules between the policies.zPGenerating range_transition differences from {0.left_policy} to {0.right_policy}N)loginfoformat_left_mls_rules_right_mls_rules_create_mls_rule_listsZ _set_diffZ_expand_generatorrZrange_transitionMLSRuleWrapperr defaultappendmodified_mlsrule_recordadded_range_transitionsremoved_range_transitionsmodified_range_transitions)selfZaddedZremovedZmatchedZmodifiedZ left_ruleZ right_ruler /usr/lib64/python3.6/mlsrules.pyr/s&z)MLSRulesDifference.diff_range_transitionscCs|jjdj|x$|jjD]}|j|jj|qW|jjdj|x$|jjD]}|j |jj|qVW|jjddS)z$Create rule lists for both policies.z,Building MLS rule lists from {0.left_policy}z-Building MLS rule lists from {0.right_policy}z"Completed building MLS rule lists.N) rdebugrZ left_policyZmlsrulesrruletyperZ right_policyr)rr rrrrPsz)MLSRulesDifference._create_mls_rule_listscCs6|jjdd|_d|_d|_|jj|jjdS)z%Reset diff results on policy changes.zResetting MLS rule differencesN)rr rrrrclearr)rrrr _reset_diff^s   zMLSRulesDifference._reset_diffN)__name__ __module__ __qualname____doc__rrrrrlistrrrrr#rrrrr#s!rc@s4eZdZdZdZddZdd Zd d Zd d ZdS)rz'Wrap MLS rules to allow set operations.r!sourcetargettclasscCs8||_t|j|_t|j|_t|j|_t||_dS)N)originr r)r*r r+hashkey)rr rrr__init__ps    zMLSRuleWrapper.__init__cCs|jS)N)r.)rrrr__hash__wszMLSRuleWrapper.__hash__cCs |j|jkS)N)r.)rotherrrr__lt__zszMLSRuleWrapper.__lt__cCs$|j|jko"|j|jko"|j|jkS)N)r)r*r+)rr1rrr__eq__}s  zMLSRuleWrapper.__eq__N)r!r)r*r+) r$r%r&r' __slots__r/r0r2r3rrrrrjs rN) collectionsrrrZ descriptorsr differencerr Zmlsr Zobjclassr typesr rrrrrrrs     G