
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
^h                 @   st   d dl mZ ddlmZ ddlmZ ddlmZmZ ddl	m
Z
 edd	d
dgZG dd deZG dd deZdS )    )
namedtuple   )BoundsRuletype   )DiffResultDescriptor)
DifferenceWrapper)type_wrapper_factoryZmodified_boundruleZadded_boundZremoved_boundc               @   sH   e Zd ZdZedZedZedZdZdZ	dd Z
dd Zdd	 ZdS )
BoundsDifferencez9Determine the difference in *bounds between two policies.diff_typeboundsNc             C   s   | j jdj|  | jdks&| jdkr.| j  | jdd | jD dd | jD dd d\| _| _}g | _	x<|D ]4\}}t
|jt
|jkrp| j	jt||j|j qpW dS )	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  qd S )N)BoundsWrapper).0c r   /usr/lib64/python3.6/bounds.py	<genexpr>5   s    z3BoundsDifference.diff_typebounds.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r   6   s    c             S   s
   t | jS )N)strchild)br   r   r   <lambda>7   s    z2BoundsDifference.diff_typebounds.<locals>.<lambda>)key)loginfoformat_left_typebounds_right_typebounds_create_typebound_listsZ	_set_diffadded_typeboundsremoved_typeboundsmodified_typeboundsr	   parentappendmodified_bounds_record)selfZmatched_typeboundsZ
left_boundZright_boundr   r   r   r   +   s    
z BoundsDifference.diff_typeboundsc             C   s   g | _ x@| jj D ]2}|jtjkr0| j j| q| jjdj	|j qW g | _
x@| jj D ]2}|jtjkrx| j
j| qZ| jjdj	|j qZW dS )z$Create rule lists for both policies.z/Unknown rule type: {0} (This is an SETools bug)N)r   Zleft_policyZboundsruletyper   Z
typeboundsr"   r   errorr   r   Zright_policy)r$   r
   r   r   r   r   C   s    

z(BoundsDifference._create_typebound_listsc             C   s(   | j jd d| _d| _d| _d| _dS )z%Reset diff results on policy changes.z!Resetting all *bounds differencesN)r   debugr   r   r   r   )r$   r   r   r   _reset_diffU   s
    zBoundsDifference._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 Zd ZdZdZdd Zdd Zd	d
 Zdd ZdS )r   zWrap *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
    zBoundsWrapper.__init__c             C   s   | j S )N)r   )r$   r   r   r   __hash__m   s    zBoundsWrapper.__hash__c             C   s   | j |j k S )N)r   )r$   otherr   r   r   __lt__p   s    zBoundsWrapper.__lt__c             C   s   | j |j ko| j|jkS )N)r%   r   )r$   r1   r   r   r   __eq__s   s    zBoundsWrapper.__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   Zdescriptorsr   
differencer   r   typesr	   r#   r   r   r   r   r   r   <module>   s   A