3 ^ @shddlmZddlmZddlmZddlmZmZedddd gZ Gd d d eZ Gd d d eZ dS)) namedtuple)ContextWrapper)DiffResultDescriptor) DifferenceWrapperZmodified_portconZruleZ added_contextZremoved_contextc@s8eZdZdZedZedZedZddZddZ dS)PortconsDifferencez:Determine the difference in portcons between two policies. diff_portconscCs|jjdj||jdd|jjDdd|jjD\|_|_}g|_ x<|D]4\}}t |j t |j krT|j j t ||j |j qTWdS)z9Generate the difference in portcons between the policies.zGGenerating portcon differences from {0.left_policy} to {0.right_policy}css|]}t|VqdS)N)PortconWrapper).0nr /usr/lib64/python3.6/portcon.py .sz3PortconsDifference.diff_portcons..css|]}t|VqdS)N)r )r r r r rr/sN)loginfoformatZ _set_diffZ left_policyZportconsZ right_policyadded_portconsremoved_portconsmodified_portconsrcontextappendmodified_portcon_record)selfZmatched_portconsZ left_portconZ right_portconr r rr 's   z PortconsDifference.diff_portconscCs"|jjdd|_d|_d|_dS)z%Reset diff results on policy changes.zResetting portcon differencesN)rdebugrrr)rr r r _reset_diff>s zPortconsDifference._reset_diffN) __name__ __module__ __qualname____doc__rrrrr rr r r rrs rc@s4eZdZdZdZddZddZd d Zd d Zd S)r z*Wrap portcon statements for diff purposes.protocollowhighcCs*||_|j|_|j\|_|_t||_dS)N)originr Zportsr!r"hashkey)rZoconr r r__init__LszPortconWrapper.__init__cCs|jS)N)r%)rr r r__hash__RszPortconWrapper.__hash__cCs |j|jkS)N)r#)rotherr r r__lt__UszPortconWrapper.__lt__cCs$|j|jko"|j|jko"|j|jkS)N)r r!r")rr(r r r__eq__Xs  zPortconWrapper.__eq__N)r r!r") rrrr __slots__r&r'r)r*r r r rr Fs r N) collectionsrrrZ descriptorsr differencerrrrr r r r rs   '