
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
^B)                 @   s   d dl mZmZ ddlmZ ddlmZmZmZ eddddgZ	ed	dddgZ
ed
ddddgZeeZeeZdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )     )defaultdict
namedtuple   )DiffResultDescriptor)
DifferenceSymbolWrapperWrapperZmodified_categoryadded_aliasesremoved_aliasesmatched_aliasesZmodified_sensitivityZmodified_levelleveladded_categoriesremoved_categoriesmatched_categoriesc             C   s>   yt | j |  S  tk
r8   t| }|t | j | < |S X dS )z
    Wrap category from the specified policy.

    This caches results to prevent duplicate wrapper
    objects in memory.
    N)_cats_cachepolicyKeyErrorr   )categoryc r   /usr/lib64/python3.6/mls.pycategory_wrapper_factory+   s    r   c             C   s>   yt | j |  S  tk
r8   t| }|t | j | < |S X dS )z
    Wrap sensitivity from the specified policy.

    This caches results to prevent duplicate wrapper
    objects in memory.
    N)_sens_cacher   r   r   )sensitivityr   r   r   r   sensitivity_wrapper_factory:   s    r   c               @   s8   e Zd ZdZedZedZedZdd Zdd Z	dS )CategoriesDifferencez<Determine the difference in categories between two policies.diff_categoriesc             C   s   | j jdj|  | jdd | jj D dd | jj D \| _| _}t	 | _
xH|D ]@\}}| j|j |j dd\}}}|s|rVt|||| j
|< qVW dS )z;Generate the difference in categories between the policies.zHGenerating category differences from {0.left_policy} to {0.right_policy}c             s   s   | ]}t |V  qd S )N)r   ).0r   r   r   r   	<genexpr>X   s    z7CategoriesDifference.diff_categories.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r   Y   s    F)unwrapN)loginfoformat	_set_diffleft_policy
categoriesright_policyr   r   dictmodified_categoriesaliasesmodified_cat_record)selfr   Zleft_categoryZright_categoryr	   r
   r   r   r   r   r   Q   s     z$CategoriesDifference.diff_categoriesc             C   s"   | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.zResetting category differencesN)r    debugr   r   r(   )r+   r   r   r   _reset_diffk   s    z CategoriesDifference._reset_diffN)
__name__
__module____qualname____doc__r   r   r   r(   r   r-   r   r   r   r   r   I   s   r   c               @   s8   e Zd ZdZedZedZedZdd Zdd Z	dS )SensitivitiesDifferencez?Determine the difference in sensitivities between two policies.diff_sensitivitiesc             C   s   | j jdj|  | jdd | jj D dd | jj D \| _| _}t	 | _
xH|D ]@\}}| j|j |j dd\}}}|s|rVt|||| j
|< qVW dS )z>Generate the difference in sensitivities between the policies.zKGenerating sensitivity differences from {0.left_policy} to {0.right_policy}c             s   s   | ]}t |V  qd S )N)r   )r   sr   r   r   r      s    z=SensitivitiesDifference.diff_sensitivities.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   r4   r   r   r   r      s    F)r   N)r    r!   r"   r#   r$   Zsensitivitiesr&   added_sensitivitiesremoved_sensitivitiesr'   modified_sensitivitiesr)   modified_sens_record)r+   Zmatched_sensitivitiesZ	left_sensZ
right_sensr	   r
   r   r   r   r   r3   {   s     z*SensitivitiesDifference.diff_sensitivitiesc             C   s"   | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.z!Resetting sensitivity differencesN)r    r,   r5   r6   r7   )r+   r   r   r   r-      s    z#SensitivitiesDifference._reset_diffN)
r.   r/   r0   r1   r   r5   r6   r7   r3   r-   r   r   r   r   r2   s   s   r2   c               @   s8   e Zd ZdZedZedZedZdd Zdd Z	dS )LevelDeclsDifferencez8Determine the difference in levels between two policies.diff_levelsc             C   s   | j jdj|  | jdd | jj D dd | jj D \| _| _}g | _	x\|D ]T\}}| jdd |j
 D dd |j
 D \}}}|s|rT| j	jt|||| qTW dS )z7Generate the difference in levels between the policies.zJGenerating level decl differences from {0.left_policy} to {0.right_policy}c             s   s   | ]}t |V  qd S )N)LevelDeclWrapper)r   r4   r   r   r   r      s    z3LevelDeclsDifference.diff_levels.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r;   )r   r4   r   r   r   r      s    c             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r      s    c             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r      s    N)r    r!   r"   r#   r$   Zlevelsr&   added_levelsremoved_levelsmodified_levelsr%   appendmodified_level_record)r+   Zmatched_levelsZ
left_levelZright_levelr   r   r   r   r   r   r:      s     z LevelDeclsDifference.diff_levelsc             C   s"   | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.z!Resetting sensitivity differencesN)r    r,   r<   r=   r>   )r+   r   r   r   r-      s    z LevelDeclsDifference._reset_diffN)
r.   r/   r0   r1   r   r<   r=   r>   r:   r-   r   r   r   r   r9      s   r9   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 level declarations to allow comparisons.r   c             C   s    || _ t|j| _t|| _d S )N)originr   r   hashkey)r+   r   r   r   r   __init__   s    zLevelDeclWrapper.__init__c             C   s   | j S )N)rC   )r+   r   r   r   __hash__   s    zLevelDeclWrapper.__hash__c             C   s   | j |j kS )N)r   )r+   otherr   r   r   __eq__   s    zLevelDeclWrapper.__eq__c             C   s   | j |j k S )N)r   )r+   rF   r   r   r   __lt__   s    zLevelDeclWrapper.__lt__N)	r.   r/   r0   r1   	__slots__rD   rE   rG   rH   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 )LevelWrapperz!Wrap levels to allow comparisons.r   r%   c             C   s.   || _ t|j| _tdd |j D | _d S )Nc             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r      s    z(LevelWrapper.__init__.<locals>.<genexpr>)rA   r   r   setr%   )r+   r   r   r   r   rD      s    zLevelWrapper.__init__c             C   s
   t | jS )N)rB   rA   )r+   r   r   r   rE      s    zLevelWrapper.__hash__c             C   s2   y| j |j ko| j|jkS  tk
r,   dS X d S )NF)r   r%   AttributeError)r+   rF   r   r   r   rG      s
    zLevelWrapper.__eq__c             C   s2   y| j |j k o| j|jk S  tk
r,   dS X d S )NF)r   r%   rL   )r+   rF   r   r   r   rH      s
    zLevelWrapper.__lt__N)r   r%   )	r.   r/   r0   r1   rI   rD   rE   rG   rH   r   r   r   r   rJ      s   	rJ   c               @   s4   e Zd ZdZdZdd Zdd Zdd	 Zd
d Zd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.
    lowhighc             C   s"   || _ t|j| _t|j| _d S )N)rA   rJ   rN   rO   )r+   Zrange_r   r   r   rD     s    zRangeWrapper.__init__c             C   s
   t | jS )N)rB   rA   )r+   r   r   r   rE     s    zRangeWrapper.__hash__c             C   s2   y| j |j ko| j|jkS  tk
r,   dS X d S )NF)rN   rO   rL   )r+   rF   r   r   r   rG     s
    zRangeWrapper.__eq__c             C   s2   y| j |j k o| j|jk S  tk
r,   dS X d S )NF)rN   rO   rL   )r+   rF   r   r   r   rH      s
    zRangeWrapper.__lt__N)rN   rO   )	r.   r/   r0   r1   rI   rD   rE   rG   rH   r   r   r   r   rM     s   	rM   N)collectionsr   r   Zdescriptorsr   
differencer   r   r   r*   r8   r@   r'   r   r   r   r   r   r2   r9   r;   rJ   rM   r   r   r   r   <module>   s,   *,,!