a qéqeÆã@sŒddlmZmZmZmZddlmZmZmZddl m Z ddl m Z m Z ddlmZGdd „d eƒZGd d „d e ƒZGd d „d e eƒZdS)é)ÚcastÚListÚ NamedTupleÚOptionalé)ÚBoundsÚBoundsRuletypeÚTypeé)ÚDiffResultDescriptor)Ú DifferenceÚWrapper)Útype_wrapper_factoryc@s*eZdZUdZeed<eed<eed<dS)ÚModifiedBoundsz.Difference details for a modified bounds rule.ÚruleZ added_boundZ removed_boundN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚ__annotations__r ©rrú9/usr/lib64/python3.9/site-packages/setools/diff/bounds.pyrs rc@s|eZdZUdZedƒZedƒZedƒZdZe e e e d<dZ e e e e d<ddœdd„Zddœd d „Zddœd d „ZdS) ÚBoundsDifferencez9Determine the difference in *bounds between two policies.Údiff_typeboundsNÚ_left_typeboundsÚ_right_typebounds)ÚreturncCs¼|j d |¡¡|jdus&|jdur.| ¡|jdd„ttt |jƒDƒdd„ttt |jƒDƒdd„d�\|_ |_ }g|_ |D]4\}}t |jƒt |jƒkr‚|j  t||j|jƒ¡q‚dS) z@Generate the difference in typebound rules between the policies.zJGenerating typebounds differences from {0.left_policy} to {0.right_policy}Ncss|]}t|ƒVqdS©N©Ú BoundsWrapper©Ú.0ÚcrrrÚ -óz3BoundsDifference.diff_typebounds..css|]}t|ƒVqdSrrr rrrr#.r$cSs t|jƒSr)ÚstrÚchild)ÚbrrrÚ/r$z2BoundsDifference.diff_typebounds..©Úkey)ÚlogÚinfoÚformatrrÚ_create_typebound_listsZ _set_diffrrrÚadded_typeboundsÚremoved_typeboundsÚmodified_typeboundsrÚparentÚappendr)ÚselfZmatched_typeboundsZ left_boundZ right_boundrrrr#s  ÿý  ÿz BoundsDifference.diff_typeboundscCsŒg|_|j ¡D]2}|jtjkr.|j |¡q|j d  |j¡¡qg|_ |j  ¡D]2}|jtjkrr|j  |¡qT|j d  |j¡¡qTdS)z$Create rule lists for both policies.z/Unknown rule type: {0} (This is an SETools bug)N) rZ left_policyZboundsÚruletyperZ typeboundsr3r+Úerrorr-rZ right_policy©r4rrrrr.;s  ÿ  ÿz(BoundsDifference._create_typebound_listscCs(|j d¡d|_d|_d|_d|_dS)z%Reset diff results on policy changes.z!Resetting all *bounds differencesN)r+Údebugr/r0rr©r4rrrÚ _reset_diffMs  zBoundsDifference._reset_diff)rrrrr r/r0r1rrrrrrrr.r:rrrrrs rc@s<eZdZdZdZeddœdd„Zdd„Zd d „Zd d „Z dS) rzWrap *bounds for diff purposes.)r5r2r&N)rrcCs4||_|j|_t|jƒ|_t|jƒ|_t|ƒ|_dSr)Úoriginr5rr2r&Úhashr*r7rrrÚ__init__^s   zBoundsWrapper.__init__cCs|jSrr)r9rrrÚ__hash__eszBoundsWrapper.__hash__cCs |j|jkSrr)©r4ÚotherrrrÚ__lt__hszBoundsWrapper.__lt__cCs|j|jko|j|jkSr)r5r&r?rrrÚ__eq__ks  ÿzBoundsWrapper.__eq__) rrrrÚ __slots__rr=r>rArBrrrrrXs rN)ÚtypingrrrrZ policyreprrr Z descriptorsr Ú differencer r ÚtypesrrrrrrrrÚs   A