a qéqe¦ ã@s®UddlmZddlmZmZddlmZmZddlm Z ddl m Z m Z ddlm Z dd lmZeeƒZe eed <Gd d „d eƒZee ed œdd„ZGdd„de ƒZdS)é)Ú defaultdict)Ú NamedTupleÚSeté)ÚRoleÚTypeé)ÚDiffResultDescriptor)Ú DifferenceÚ SymbolWrapper)Ú SymbolCache©Útype_wrapper_factoryÚ _roles_cachec@s6eZdZUdZeeed<eeed<eeed<dS)Ú ModifiedRolez'Difference details for a modified role.Ú added_typesÚ removed_typesÚ matched_typesN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrÚ__annotations__©rrú8/usr/lib64/python3.9/site-packages/setools/diff/roles.pyrs   r)ÚroleÚreturncCsBzt|j|WSty<t|ƒ}|t|j|<|YS0dS)z| Wrap roles from the specified policy. This caches results to prevent duplicate wrapper objects in memory. N)rZpolicyÚKeyErrorr )rÚrrrrÚrole_wrapper_factorys  rc@sDeZdZdZedƒZedƒZedƒZddœdd„Zddœdd„Z dS) ÚRolesDifferencez7Determine the difference in roles between two policies.Ú diff_rolesN)rcCsª|j d |¡¡| dd„|j ¡Dƒdd„|j ¡Dƒ¡\|_|_}t ƒ|_ |D]P\}}| dd„|  ¡Dƒdd„|  ¡Dƒ¡\}}}|s’|rTt |||ƒ|j |<qTdS)z6Generate the difference in roles between the policies.zDGenerating role differences from {0.left_policy} to {0.right_policy}css|]}t|ƒVqdS©N©r©Ú.0rrrrÚ :óz-RolesDifference.diff_roles..css|]}t|ƒVqdSr"r#r$rrrr&;r'css|]}t|ƒVqdSr"r ©r%Útrrrr&Dr'css|]}t|ƒVqdSr"r r(rrrr&Er'N) ÚlogÚinfoÚformatZ _set_diffZ left_policyZrolesZ right_policyÚ added_rolesÚ removed_rolesÚdictÚmodified_rolesÚtypesr)ÚselfZ matched_rolesZ left_roleZ right_rolerrrrrrr!3s$ÿþ þ þzRolesDifference.diff_rolescCs"|j d¡d|_d|_d|_dS)z%Reset diff results on policy changes.zResetting role differencesN)r*Údebugr-r.r0)r2rrrÚ _reset_diffOs zRolesDifference._reset_diff) rrrrr r-r.r0r!r4rrrrr +s r N)Ú collectionsrÚtypingrrZ policyreprrZ descriptorsr Ú differencer r r r1rr/rrrrr rrrrÚs