+
    ,i!  c                   s    ^ RI Ht ^RIHt ^RIHt ^RIHtHtH	t	 ^RI
Ht ^RIHt  ! R R]4      t ! R	 R
]	]P                  ,          4      tR# )i    )defaultdict)	policyrep)DiffResultDescriptor)
DifferenceSymbolWrapperWrapper)class_wrapper_factory)RuleListc                   s4  a  ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 lt]	]
P                  ,          ! ]4      t]	]
P                  ,          ! ]4      t]	]
P                  ,          ! ]4      t]	]
P                  ,          ! ]4      t]	]
P                   ,          ! ]4      t]	]
P                   ,          ! ]4      t]	]
P                   ,          ! ]4      t]	]
P                   ,          ! ]4      tR
tR
tV 3R lR ltV 3R lR ltV 3R ltRtV tR
# )ConstraintsDifferenceaV  
Determine the difference in constraints between two policies.

Since the compiler does not union constraints, there may be multiple
constraints with the same ruletype, object class, and permission
set, so constraints can only be added or removed, not modified.

The constraint expressions are compared only on a basic level.
Expressions that are logically equivalent but are structurally
different, for example, by associativity, will be considered
different.  Type and role attributes are also not expanded,
so if there are changes to attribute members, it will not
be reflected as a difference.
c                   < V ^8  d   QhRR/#    returnN Zformat__classdict__   "?/usr/lib64/python3.14/site-packages/setools/diff/constraints.py__annotate__"ConstraintsDifference.__annotate__!   s     : : :    c                   V P                   P                  RV P                   RV P                   24       V P                  e   V P
                  f   V P                  4        V P                  R V P                  \        P                  P                  ,           4       R V P
                  \        P                  P                  ,           4       4      w  V n        V n        pR# )zAGenerate the difference in constraint rules between the policies.z'Generating constraint differences from  to Nc              3   8   "   T F  p\        V4      x  K  	  R # 5iNConstraintWrapper.0Zc   & r   	<genexpr>8ConstraintsDifference.diff_constrains.<locals>.<genexpr>.   !      9 ,8aq!! ,8   c              3   r   r   r   r   r   r   r   r   0   r    r!   )loginfoleft_policyright_policy_left_constraints_right_constraints_create_constrain_lists	_set_diffr   ConstraintRuletypeZ	constrainadded_constrainsremoved_constrainsselfZ_r   r   diff_constrainsZ%ConstraintsDifference.diff_constrains!   s     	5d6F6F5GtDL]L]K^_	a !!)T-D-D-L((*
 =ANN94+A+A,,66,8 994+B+B,,66,8 9=:9t6r   c                r	   r
   r   r   r   r   r   r   3   s     = =D =r   c                r   )zEGenerate the difference in MLS constraint rules between the policies.z+Generating MLS constraint differences from r   Nc              3   r   r   r   r   r   r   r   ;ConstraintsDifference.diff_mlsconstrains.<locals>.<genexpr>A   !      < ,;aq!! ,;r!   c              3   r   r   r   r   r   r   r   r0   C   r1   r!   )r"   r#   r$   r%   r&   r'   r(   r)   r   r*   Zmlsconstrainadded_mlsconstrainsremoved_mlsconstrainsr-   r   r   diff_mlsconstrainsZ(ConstraintsDifference.diff_mlsconstrains3   s     	9$:J:J9K L##$&	' !!)T-D-D-L((*
 CG..<4+A+A,,99,; <<4+B+B,,99,; <C=? $"<ar   c                r	   r
   r   r   r   r   r   r   F   s     > >D >r   c                r   )zDGenerate the difference in validatetrans rules between the policies.z*Generating validatetrans differences from r   Nc              3   r   r   r   r   r   r   r   ;ConstraintsDifference.diff_validatetrans.<locals>.<genexpr>S   !      = ,<aq!! ,<r!   c              3   r   r   r   r   r   r   r   r5   U   r6   r!   )r"   r#   r$   r%   r&   r'   r(   r)   r   r*   Zvalidatetransadded_validatetransremoved_validatetransr-   r   r   diff_validatetransZ(ConstraintsDifference.diff_validatetransF   s     	89I9I8J$tO`O`Nab	d !!)T-D-D-L((*
 CG..=4+A+A,,::,< ==4+B+B,,::,< =C>? $"<ar   c                r	   r
   r   r   r   r   r   r   X   s     A At Ar   c                r   )zHGenerate the difference in MLS validatetrans rules between the policies.z-Generating mlsvalidatetrans differences from r   Nc              3   r   r   r   r   r   r   r   >ConstraintsDifference.diff_mlsvalidatetrans.<locals>.<genexpr>f   "      @ ,?aq!! ,?r!   c              3   r   r   r   r   r   r   r   r:   h   r;   r!   )r"   r#   r$   r%   r&   r'   r(   r)   r   r*   Zmlsvalidatetransadded_mlsvalidatetransremoved_mlsvalidatetransr-   r   r   diff_mlsvalidatetransZ+ConstraintsDifference.diff_mlsvalidatetransX   s     	;D<L<L;M N##$&	' !!)T-D-D-L((*
 IM@4+A+A,,==,? @@4+B+B,,==,? @IAE#T%BAr   Nc                r	   r
   r   r   r   r   r   r   ~   s     D D Dr   c                s   \        \        4      V n        V P                  P	                  RV P
                   24       V P
                  P                  4        F/  pV P                  VP                  ,          P                  V4       K1  	  V P                  P                  4        F0  w  r#V P                  P	                  R\        V4       RV R24       K2  	  \        \        4      V n        V P                  P	                  RV P                   24       V P                  P                  4        F/  pV P                  VP                  ,          P                  V4       K1  	  V P                  P                  4        F0  w  r#V P                  P	                  R\        V4       RV R24       K2  	  V P                  P	                  R4       R# )z$Create rule lists for both policies.zBuilding constraint lists from zLoaded Z z rules.z)Completed building constraint rule lists.N)r    Zlistr&   r"   debugr$   ZconstraintsruletypeappendZitemsZlenr'   r%   )r.   ruler@   Zruless   &   r   r(   Z-ConstraintsDifference._create_constrain_lists~   s[   !,T!289I9I8JKL$$002D""4==188> 3  $55;;=OHHHNNWSZL(7CD  > #.d"389J9J8KLM%%113D##DMM299$? 4  $66<<>OHHHNNWSZL(7CD  ? 	BCr   c                r	   r
   r   r   r   r   r   r      s     ' 'T 'r   c                sx    V P                   P                  R4       V =V =V =V =V =V =V =V =	RV n
        RV n        R# )z%Reset diff results on policy changes.z%Resetting all constraints differencesN)r"   r?   r+   r,   r2   r3   r7   r8   r<   r=   r&   r'   r.      &r   _reset_diffZ!ConstraintsDifference._reset_diff   sU    >?!#$&$&') "&"&r   c                s   < V ^8  d   Qh/ S[ S[P                  S[P                  3,          ;R&   S[ S[P                  S[P                  3,          ;R&   # )r   r&   r'   )r   r   r*   AnyConstraintr   r   r   r   r      sO     P  	 < <i>U>U UV]Q R !!=!=y?V?V!VW^S r   )
r&   r'   r+   r2   r<   r7   r,   r3   r=   r8   )__name__
__module____qualname____firstlineno____doc__r/   r4   r9   r>   r   r   Z
Constraintr+   r,   r2   r3   ZValidatetransr7   r8   r<   r=   r&   r'   r(   rE   Z__annotate_func____static_attributes____classdictcell__r      @r   r   r      s    : :$= =&> >$A A& ,I,@,@A/R-i.B.BCOT.y/C/CDEWX01E1EFGYZ.y/F/FGHZ[01H1HIJ\]1)2I2IJK`a3I4K4KLMbc Z^Z^
D D(' 'E  r   r   c                   sL   a  ] tR t^t o RtR	tV 3R lR ltR tR tR t	Rt
V tR# )
r   z#Wrap constraints for diff purposes.c                s8   < V ^8  d   QhRS[ P                  RR/# )r   rB   r   N)r   rF   r   r   r   r   ZConstraintWrapper.__annotate__   s!     % %Y44 % %r   c                s   Wn         VP                  V n        \        VP                  4      V n        V   VP                  V n        \        V4      V n        . V n        VP                   Fa  p\        V\        4      '       d.   V P                  P                  \        R V 4       4      4       KF  V P                  P                  V4       Kc  	  R #   \
         d    R T n         Li ; i)Nc              3   r   r   )r   )r   Zitemr   r   r   Z-ConstraintWrapper.__init__.<locals>.<genexpr>   s     *N24=+>+>2r!   )originr@   r   tclasspermsZAttributeErrorZhashkeyexprZ
expressionZ
isinstanceZ	frozensetrA   )r.   rB   Zops   && r   __init__ZConstraintWrapper.__init__   s    +DKK8	DJ
 : KM 		 //B"i((		  *N2*N!NO 		  $ "  	DJ	s   C C%$C%c                s    V P                   # r   rS   rC   rD   r   __hash__ZConstraintWrapper.__hash__   s    xxr   c                s4    V P                   VP                   8  # r   rV   r.   Zother   &&r   __lt__ZConstraintWrapper.__lt__   s    xx%))##r   c                s    V P                   VP                   8H  ;'       d\    V P                  VP                  8H  ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # r   r@   rQ   rR   rT   rX   rY   r   __eq__ZConstraintWrapper.__eq__   sg    }}. $ $KK5<<'$ $JJ%++%$ $ II#	$r   )rT   rS   rP   rR   r@   rQ   Nr[   )rG   rH   rI   rJ   rK   Z	__slots__rU   rW   rZ   r\   rL   rM   rN   rO   r   r   r      s+     -7I% %4$$ $r   r   N)Zcollectionsr    Z r   Zdescriptorsr   Z
differencer   r   r   Zobjclassr   Ztypingr   r   rF   r   r   r   r   <module>r]      sB    $  - : : + P'J P'f*$	 7 78 *$r   