grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a BÒi,ã@spdZddlmZddlmZejr.ddlmZGdd„dƒZdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dS)ai Classes and functions for the output of reference policy modules. This module takes a refpolicy.Module object and formats it for output using the ModuleWriter object. By separating the output in this way the other parts of Madison can focus solely on generating policy. This keeps the semantic / syntactic issues cleanly separated from the formatting issues. é)Ú refpolicy)Úutil)Úcmpc@seZdZdd„Zdd„ZdS)Ú ModuleWritercCsd|_d|_d|_d|_dS)NT)ÚfdÚmoduleÚsortÚrequires)Úself©r ú3/usr/lib/python3.9/site-packages/sepolgen/output.pyÚ__init__&szModuleWriter.__init__cCsF||_|jrt|jƒtj|jdd�D]\}}| dt|ƒ¡q&dS)NT)Z showdepthz%s )rrÚ sort_filterrZwalktreeÚwriteÚstr)r rrÚnodeÚdepthr r r r,s  zModuleWriter.writeN)Ú__name__Ú __module__Ú __qualname__r rr r r r r%srcCs€t |¡}| ¡t |¡}| ¡t|ƒt|ƒkrFt|d|dƒSt||ƒD]*}|d|dkrPt|d|dƒSqPdS)Nér)rZ set_to_listrÚlenrÚzip)ÚxÚyZxlZylÚvr r r Ú id_set_cmp=s  rcCsRt|j|jƒ}|dkr|St|j|jƒ}|dkr4|St|j|jƒ}|dkrN|SdS©Nr)rÚ src_typesZ tgt_typesZ obj_classes)ÚaÚbÚretr r r Ú avrule_cmpKsr"cCs8|jd|jdkr*t|jd|jdƒSt|j|jƒSr)ÚargsrZifname©rr r r r Ú ifcall_cmpZsr%cCsrt|tjƒr8t|tjƒr"t||ƒSt|jdg|jƒSn6t|tjƒsPt|tjƒrZt ||ƒSt|j|jdgƒSdSr) Ú isinstancerÚ InterfaceCallr%rr#rZAVRuleZ AVExtRuler"r$r r r Úrule_cmp`s    r(cCst|j|jƒS)N)rZroler$r r r Ú role_type_cmplsr)cCs"dd„}| ¡D] }||ƒqdS)z/Sort and group the output for readability. c Ssžg}| ¡D]}| |¡| t ¡¡q | ¡D]}| |¡q2| t ¡¡g}| | ¡¡| | ¡¡| | ¡¡|j t   t ¡d�d}g}|D]t}t |tjƒr¸|jd}n t  |j¡}||k�r|rà| t ¡¡|}t ¡} | j d|¡| | ¡| |¡qœ| |¡g} |  | ¡¡| j t   t¡d�t| ƒ�rht ¡} | j d¡| | ¡| | ¡|jD]} | |v�rx| | ¡�qx||_dS)N)Úkeyrz============= %s ==============z"============= ROLES ==============)Zmodule_declarationsÚappendrÚCommentr ÚextendZavrulesZ avextrulesZinterface_callsrrÚ cmp_to_keyr(r&r'r#ÚfirstrÚlinesZ role_typesr)rZchildren) rÚcÚmodZrequireZrulesZcurZ sep_rulesZrulerZcommentZrasÚchildr r r Ú sort_nodersN                 zsort_filter..sort_nodeN)Znodes)rr4rr r r ros= rN) Ú__doc__ÚrrZPY3rrrr"r%r(r)rr r r r Ús