3 ^B)@sddlmZmZddlmZddlmZmZmZeddddgZ ed dddgZ ed d d d dgZ ee Z ee ZddZddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdS) ) defaultdict namedtuple)DiffResultDescriptor) Difference SymbolWrapperWrapperZmodified_category added_aliasesremoved_aliasesmatched_aliasesZmodified_sensitivityZmodified_levelleveladded_categoriesremoved_categoriesmatched_categoriesc Cs>yt|j|Stk r8t|}|t|j|<|SXdS)z Wrap category from the specified policy. This caches results to prevent duplicate wrapper objects in memory. N) _cats_cachepolicyKeyErrorr)categorycr/usr/lib64/python3.6/mls.pycategory_wrapper_factory+s rc Cs>yt|j|Stk r8t|}|t|j|<|SXdS)z Wrap sensitivity from the specified policy. This caches results to prevent duplicate wrapper objects in memory. N) _sens_cacherrr) sensitivityrrrrsensitivity_wrapper_factory:s rc@s8eZdZdZedZedZedZddZddZ dS)CategoriesDifferencezXsz7CategoriesDifference.diff_categories..css|]}t|VqdS)N)r)rrrrrrYsF)unwrapN) loginfoformat _set_diff left_policy categories right_policyr rdictmodified_categoriesaliasesmodified_cat_record)selfrZ left_categoryZright_categoryr r r rrrrQs  z$CategoriesDifference.diff_categoriescCs"|jjdd|_d|_d|_dS)z%Reset diff results on policy changes.zResetting category differencesN)r debugr rr()r+rrr _reset_diffks z CategoriesDifference._reset_diffN) __name__ __module__ __qualname____doc__rr rr(rr-rrrrrIs rc@s8eZdZdZedZedZedZddZddZ dS)SensitivitiesDifferencez?Determine the difference in sensitivities between two policies.diff_sensitivitiescCs|jjdj||jdd|jjDdd|jjD\|_|_}t |_ xH|D]@\}}|j|j |j dd\}}}|s|rVt ||||j |<qVWdS)z>Generate the difference in sensitivities between the policies.zKGenerating sensitivity differences from {0.left_policy} to {0.right_policy}css|]}t|VqdS)N)r)rsrrrrsz=SensitivitiesDifference.diff_sensitivities..css|]}t|VqdS)N)r)rr4rrrrsF)rN) r r!r"r#r$Z sensitivitiesr&added_sensitivitiesremoved_sensitivitiesr'modified_sensitivitiesr)modified_sens_record)r+Zmatched_sensitivitiesZ left_sensZ right_sensr r r rrrr3{s z*SensitivitiesDifference.diff_sensitivitiescCs"|jjdd|_d|_d|_dS)z%Reset diff results on policy changes.z!Resetting sensitivity differencesN)r r,r5r6r7)r+rrrr-s z#SensitivitiesDifference._reset_diffN) r.r/r0r1rr5r6r7r3r-rrrrr2ss r2c@s8eZdZdZedZedZedZddZddZ dS)LevelDeclsDifferencez8Determine the difference in levels between two policies. diff_levelscCs|jjdj||jdd|jjDdd|jjD\|_|_}g|_ x\|D]T\}}|jdd|j Ddd|j D\}}}|s|rT|j j t ||||qTWdS)z7Generate the difference in levels between the policies.zJGenerating level decl differences from {0.left_policy} to {0.right_policy}css|]}t|VqdS)N)LevelDeclWrapper)rr4rrrrsz3LevelDeclsDifference.diff_levels..css|]}t|VqdS)N)r;)rr4rrrrscss|]}t|VqdS)N)r)rrrrrrscss|]}t|VqdS)N)r)rrrrrrsN) r r!r"r#r$Zlevelsr& added_levelsremoved_levelsmodified_levelsr%appendmodified_level_record)r+Zmatched_levelsZ left_levelZ right_levelr rrrrrr:s z LevelDeclsDifference.diff_levelscCs"|jjdd|_d|_d|_dS)z%Reset diff results on policy changes.z!Resetting sensitivity differencesN)r r,r<r=r>)r+rrrr-s z LevelDeclsDifference._reset_diffN) r.r/r0r1rr<r=r>r:r-rrrrr9s r9c@s4eZdZdZdZddZddZddZd d Zd S) r;z-Wrap level declarations to allow comparisons.rcCs ||_t|j|_t||_dS)N)originrrhashkey)r+r rrr__init__s zLevelDeclWrapper.__init__cCs|jS)N)rC)r+rrr__hash__szLevelDeclWrapper.__hash__cCs |j|jkS)N)r)r+otherrrr__eq__szLevelDeclWrapper.__eq__cCs |j|jkS)N)r)r+rFrrr__lt__szLevelDeclWrapper.__lt__N) r.r/r0r1 __slots__rDrErGrHrrrrr;s r;c@s4eZdZdZd ZddZddZdd Zd d Zd S) LevelWrapperz!Wrap levels to allow comparisons.rr%cCs.||_t|j|_tdd|jD|_dS)Ncss|]}t|VqdS)N)r)rrrrrrsz(LevelWrapper.__init__..)rArrsetr%)r+r rrrrDs zLevelWrapper.__init__cCs t|jS)N)rBrA)r+rrrrEszLevelWrapper.__hash__c Cs2y|j|jko|j|jkStk r,dSXdS)NF)rr%AttributeError)r+rFrrrrGs   zLevelWrapper.__eq__c Cs2y|j|jko|j|jkStk r,dSXdS)NF)rr%rL)r+rFrrrrHs   zLevelWrapper.__lt__N)rr%) r.r/r0r1rIrDrErGrHrrrrrJs  rJc@s4eZdZdZd ZddZddZdd Zd d Zd S) RangeWrapperz Wrap ranges to allow comparisons. This only compares the low and high levels of the range. It does not detect additions/removals/modifications to levels between the low and high levels of the range. lowhighcCs"||_t|j|_t|j|_dS)N)rArJrNrO)r+Zrange_rrrrDs zRangeWrapper.__init__cCs t|jS)N)rBrA)r+rrrrEszRangeWrapper.__hash__c Cs2y|j|jko|j|jkStk r,dSXdS)NF)rNrOrL)r+rFrrrrGs   zRangeWrapper.__eq__c Cs2y|j|jko|j|jkStk r,dSXdS)NF)rNrOrL)r+rFrrrrH s   zRangeWrapper.__lt__N)rNrO) r.r/r0r1rIrDrErGrHrrrrrMs  rMN) collectionsrrZ descriptorsr differencerrrr*r8r@r'rrrrrr2r9r;rJrMrrrrs, *,,!