
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
^                 @   sl   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	d
dgZ	G dd deZ
G dd deZdS )    )
namedtuple   )ContextWrapper)DiffResultDescriptor)
DifferenceWrapperZmodified_netifconZruleadded_contextremoved_contextadded_packetremoved_packetc               @   s8   e Zd ZdZedZedZedZdd Zdd Z	dS )NetifconsDifferencez;Determine the difference in netifcons between two policies.diff_netifconsc             C   s   | j jdj|  | jdd | jj D dd | jj D \| _| _}g | _	x|D ]|\}}t
|jt
|jkr~|j}|j}nd}d}t
|jt
|jkr|j}|j}nd}d}|s|rT| j	jt||||| qTW dS )z:Generate the difference in netifcons between the policies.zHGenerating netifcon differences from {0.left_policy} to {0.right_policy}c             s   s   | ]}t |V  qd S )N)NetifconWrapper).0n r    /usr/lib64/python3.6/netifcon.py	<genexpr>0   s    z5NetifconsDifference.diff_netifcons.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   r   r   r   r   r   1   s    N)loginfoformatZ	_set_diffZleft_policyZ	netifconsZright_policyadded_netifconsremoved_netifconsmodified_netifconsr   contextZpacketappendmodified_netifcon_record)selfZmatched_netifconsZleft_netifconZright_netifconr	   r   r   r
   r   r   r   r   )   s(    
 z"NetifconsDifference.diff_netifconsc             C   s"   | j jd d| _d| _d| _dS )z%Reset diff results on policy changes.zResetting netifcon differencesN)r   debugr   r   r   )r   r   r   r   _reset_diffN   s    zNetifconsDifference._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 netifcon statements for diff purposes.netifc             C   s   || _ |j| _t|| _d S )N)originr$   hashkey)r   Zoconr   r   r   __init__\   s    zNetifconWrapper.__init__c             C   s   | j S )N)r'   )r   r   r   r   __hash__a   s    zNetifconWrapper.__hash__c             C   s   | j |j k S )N)r$   )r   otherr   r   r   __lt__d   s    zNetifconWrapper.__lt__c             C   s   | j |j kS )N)r$   )r   r*   r   r   r   __eq__g   s    zNetifconWrapper.__eq__N)	r    r!   r"   r#   	__slots__r(   r)   r+   r,   r   r   r   r   r   V   s   r   N)collectionsr   r   r   Zdescriptorsr   
differencer   r   r   r   r   r   r   r   r   <module>   s   5