File: //lib/python3/dist-packages/apparmor/rule/__pycache__/__init__.cpython-310.pyc
o
%`b�Q � @ s| d dl mZ d dlmZmZ d dlmZ e� ZG dd� de�Z G dd� de�Z
dd d
�Zdd� Zd
d� Z
dd� Zdd� ZdS )� )�AARE)�AppArmorBug�type_is_str)�init_translationc @ s e Zd ZdZdZdZdZdZ d7dd�Zdd� Z d d
� Z
edd� �Zed
d� �Z
edd� �Zedd� �Zd8dd�Zd8dd�Zd9dd�Zdd� Zdd� Zd:dd �Zd!d"� Zd;d#d$�Zd%d&� Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zd/d0� Zd1d2� Zd3d4� Zd5d6� Z dS )<�BaseRulez,Base class to handle and store a single ruleF� Nc C s( || _ || _|| _|| _|| _d| _dS )z-initialize variables needed by all rule typesN)�audit�deny�
allow_keyword�comment� log_event�raw_rule)�selfr r r
r r � r �8/usr/lib/python3/dist-packages/apparmor/rule/__init__.py�__init__4 s
zBaseRule.__init__c C sp || j krdS t|�r*t|�� �dkr!td|| jjt|�d� ��t|||d�dfS td|| jjt|�d� ��)a# checks rulepart and returns
- (AARE, False) if rulepart is a (non-empty) string
- (None, True) if rulepart is all_obj (typically *Rule.ALL)
- raises AppArmorBug if rulepart is an empty string or has a wrong type
Parameters:
- rulepart: the rule part to check (string or *Rule.ALL object)
- partname: the name of the rulepart (for example 'peer', used for exception messages)
- is_path (passed through to AARE)
- log_event (passed through to AARE)
)NTr z8Passed empty %(partname)s to %(classname)s: %(rulepart)s)�partname� classname�rulepart)�is_pathr Fz:Passed unknown %(partname)s to %(classname)s: %(rulepart)s) �ALLr �len�stripr � __class__�__name__�strr )r r r r r r r r �_aare_or_all@ s
��zBaseRule._aare_or_allc C s: | j j}z| �� }d||f W S ty d| Y S w )Nz<%s> %sz9<%s (NotImplementedError - get_clean() not implemented?)>)r r �get_raw�NotImplementedError)r r �raw_contentr r r �__repr__X s �zBaseRule.__repr__c C s | � |�rdS dS )z�return True if raw_rule matches the class (main) regex, False otherwise
Note: This function just provides an answer to "is this your job?".
It does not guarantee that the rule is completely valid.TF)�_match��clsr
r r r �match` s
zBaseRule.matchc C � t dt| � ��)z,parse raw_rule and return regex match objectz,'%s' needs to implement _match(), but didn't�r r r"