3 �^h � @ st d dl mZ ddlmZ ddlmZ ddlmZmZ ddl m Z edd d dg�ZG dd � d e�ZG dd� de�Z dS )� )� namedtuple� )�BoundsRuletype� )�DiffResultDescriptor)� Difference�Wrapper)�type_wrapper_factoryZmodified_bound�ruleZadded_boundZ removed_boundc @ sH e Zd ZdZed�Zed�Zed�ZdZdZ 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 |j�t |j�krp| 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)�.0�c� r �/usr/lib64/python3.6/bounds.py� <genexpr>5 s z3BoundsDifference.diff_typebounds.<locals>.<genexpr>c s s | ]}t |�V qd 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)�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_policyZbounds�ruletyper Z typeboundsr"