????

Your IP : 18.221.20.252


Current Path : /lib/python3.9/site-packages/sepolgen/__pycache__/
Upload File :
Current File : //lib/python3.9/site-packages/sepolgen/__pycache__/output.cpython-39.pyc

a


z
f,�@spdZddlmZddlmZejr.ddlmZGdd�d�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�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�depthrrrr,s

zModuleWriter.writeN)�__name__�
__module__�__qualname__r
rrrrrr%srcCs�t�|�}|��t�|�}|��t|�t|�krFt|d|d�St||�D]*}|d|dkrPt|d|d�SqPdS)N�r)rZset_to_listr�lenr�zip)�x�yZxlZyl�vrrr�
id_set_cmp=s

rcCsRt|j|j�}|dkr|St|j|j�}|dkr4|St|j|j�}|dkrN|SdS�Nr)r�	src_typesZ	tgt_typesZobj_classes)�a�b�retrrr�
avrule_cmpKsr"cCs8|jd|jdkr*t|jd|jd�St|j|j�Sr)�argsrZifname�rr rrr�
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$rrr�rule_cmp`s

r(cCst|j|j�S)N)rZroler$rrr�
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�childrrr�	sort_nodersN








zsort_filter.<locals>.sort_nodeN)Znodes)rr4rrrrros=rN)
�__doc__�rrZPY3rrrr"r%r(r)rrrrr�<module>s