
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
^                 @   sh   d dl mZ ddlmZ ddlmZ ddlmZmZ edddd	gZ	G d
d deZ
G dd deZdS )    )
namedtuple   )ContextWrapper)DiffResultDescriptor)
DifferenceWrapperZmodified_portconZruleZadded_contextZremoved_contextc               @   s8   e Zd ZdZedZedZedZdd Zdd Z	dS )PortconsDifferencez:Determine the difference in portcons between two policies.diff_portconsc             C   s   | j jdj|  | jdd | jj D dd | jj D \| _| _}g | _	x<|D ]4\}}t
|jt
|jkrT| j	jt||j|j qTW dS )z9Generate the difference in portcons between the policies.zGGenerating portcon differences from {0.left_policy} to {0.right_policy}c             s   s   | ]}t |V  qd S )N)PortconWrapper).0n r   /usr/lib64/python3.6/portcon.py	<genexpr>.   s    z3PortconsDifference.diff_portcons.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r
   )r   r   r   r   r   r   /   s    N)loginfoformatZ	_set_diffZleft_policyZportconsZright_policyadded_portconsremoved_portconsmodified_portconsr   contextappendmodified_portcon_record)selfZmatched_portconsZleft_portconZright_portconr   r   r   r	   '   s    
 
z PortconsDifference.diff_portconsc             C   s"   | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.zResetting portcon differencesN)r   debugr   r   r   )r   r   r   r   _reset_diff>   s    zPortconsDifference._reset_diffN)
__name__
__module____qualname____doc__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 portcon statements for diff purposes.protocollowhighc             C   s*   || _ |j| _|j\| _| _t|| _d S )N)originr    Zportsr!   r"   hashkey)r   Zoconr   r   r   __init__L   s    zPortconWrapper.__init__c             C   s   | j S )N)r%   )r   r   r   r   __hash__R   s    zPortconWrapper.__hash__c             C   s   | j |j k S )N)r#   )r   otherr   r   r   __lt__U   s    zPortconWrapper.__lt__c             C   s$   | j |j ko"| j|jko"| j|jkS )N)r    r!   r"   )r   r(   r   r   r   __eq__X   s    zPortconWrapper.__eq__N)r    r!   r"   )	r   r   r   r   	__slots__r&   r'   r)   r*   r   r   r   r   r
   F   s   r
   N)collectionsr   r   r   Zdescriptorsr   
differencer   r   r   r   r
   r   r   r   r   <module>   s   '