3
^h @ st d dl mZ ddlmZ ddlmZ ddlmZmZ ddl m
Z
edd d
dgZG dd
d
eZG dd deZ
dS ) )
namedtuple )BoundsRuletype )DiffResultDescriptor)
DifferenceWrapper)type_wrapper_factoryZmodified_boundruleZadded_boundZ
removed_boundc @ sH e Zd ZdZedZedZedZdZdZ dd Z
dd Zdd ZdS )
BoundsDifferencez9Determine the difference in *bounds between two policies.diff_typeboundsNc C s | j jdj| | jdks&| jdkr.| j | jdd | jD dd | jD dd d\| _| _}g | _ x<|D ]4\}}t
|jt
|jkrp| j jt
||j|j qpW dS ) z@Generate the difference in typebound rules between the policies.zJGenerating typebounds differences from {0.left_policy} to {0.right_policy}Nc s s | ]}t |V qd S )N)
BoundsWrapper).0c r /usr/lib64/python3.6/bounds.py 5 s z3BoundsDifference.diff_typebounds..c s s | ]}t |V qd S )N)r
)r r r r r r 6 s c S s
t | jS )N)strchild)br r r 7 s z2BoundsDifference.diff_typebounds..)key)loginfoformat_left_typebounds_right_typebounds_create_typebound_listsZ _set_diffadded_typeboundsremoved_typeboundsmodified_typeboundsr parentappendmodified_bounds_record)selfZmatched_typeboundsZ
left_boundZright_boundr r r r + s
z BoundsDifference.diff_typeboundsc C s g | _ x@| jj D ]2}|jtjkr0| j j| q| jjdj |j qW g | _
x@| jj D ]2}|jtjkrx| j
j| qZ| jjdj |j qZW dS )z$Create rule lists for both policies.z/Unknown rule type: {0} (This is an SETools bug)N)r Zleft_policyZboundsruletyper Z
typeboundsr" r errorr r Zright_policy)r$ r
r r r r C s
z(BoundsDifference._create_typebound_listsc C s( | j jd d| _d| _d| _d| _dS )z%Reset diff results on policy changes.z!Resetting all *bounds differencesN)r debugr r r r )r$ r r r _reset_diffU s
zBoundsDifference._reset_diff)
__name__
__module____qualname____doc__r r r r r r r r r( r r r r r s r c @ s4 e Zd ZdZdZdd Zdd Zd d
Zdd Zd
S )r
zWrap *bounds for diff purposes.r% r! r c C s4 || _ |j| _t|j| _t|j| _t|| _d S )N)originr% r r! r hashr )r$ r
r r r __init__f s
zBoundsWrapper.__init__c C s | j S )N)r )r$ r r r __hash__m s zBoundsWrapper.__hash__c C s | j |j k S )N)r )r$ otherr r r __lt__p s zBoundsWrapper.__lt__c C s | j |j ko| j|jkS )N)r% r )r$ r1 r r r __eq__s s zBoundsWrapper.__eq__N)r% r! r ) r) r* r+ r, __slots__r/ r0 r2 r3 r r r r r
` s r
N)collectionsr Z policyrepr Zdescriptorsr
differencer r typesr r# r r
r r r r s A