
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
^                 @   s   d Z ddlZddlmZmZ ddlmZ ddlmZ G dd dZ	G dd	 d	e	Z
G d
d deZG dd deZG dd deZG dd deZG dd dZdS )z
SETools descriptors.

These classes override how a class's attributes are get/set/deleted.
This is how the @property decorator works.

See https://docs.python.org/3/howto/descriptor.html
for more details.
    N)ABCabstractmethod)defaultdict)WeakKeyDictionaryc               @   s,   e Zd ZdZd	ddZd
ddZdd ZdS )CriteriaDescriptora  
    Single item criteria descriptor.

    Keyword Parameters:
    name_regex      The name of instance's regex setting attribute;
                    used as name_regex below.  If unset,
                    regular expressions will never be used.
    lookup_function The name of the SELinuxPolicy lookup function,
                    e.g. lookup_type or lookup_boolean.
    default_value   The default value of the criteria.  The default
                    is None.
    enum_class      The class of enumeration which supports a
                    lookup class method.

    Read-only instance attribute use (obj parameter):
    policy          The instance of SELinuxPolicy
    name_regex      This attribute is read to determine if
                    the criteria should be looked up or
                    compiled into a regex.  If the attribute
                    does not exist, False is assumed.
    Nc             C   sJ   |s|s|st d|o| s&t d|| _|| _|| _|| _t | _d S )NzQA simple attribute should be used if there is no regex, lookup function, or enum.z9Lookup functions and enum classes are mutually exclusive.)AssertionErrorregexdefault_valuelookup_function
enum_classr   	instances)selfZ
name_regexr
   r	   r    r   #/usr/lib64/python3.6/descriptors.py__init__C   s    zCriteriaDescriptor.__init__c             C   s   |d kr| S | j j|| jS )N)r   
setdefaultr	   )r   objobjtyper   r   r   __get__R   s    zCriteriaDescriptor.__get__c             C   s   |sd | j |< nn| jr6t|| jdr6tj|| j |< nH| jrZt|j| j}||| j |< n$| jrt| jj|| j |< n
|| j |< d S )NF)	r   r   getattrrecompiler
   policyr   lookup)r   r   valuer   r   r   r   __set__X   s    zCriteriaDescriptor.__set__)NNNN)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   +   s   

r   c               @   s   e Zd ZdZdd ZdS )CriteriaSetDescriptorz!Descriptor for a set of criteria.c                s   |sd j |< njr6t|jdr6tj|j |< ndjrht|jj t fdd|D j |< n2jrtfdd|D j |< nt|j |< d S )NFc             3   s   | ]} |V  qd S )Nr   ).0v)r   r   r   	<genexpr>q   s    z0CriteriaSetDescriptor.__set__.<locals>.<genexpr>c             3   s   | ]} j j|V  qd S )N)r   r   )r!   r"   )r   r   r   r#   s   s    )	r   r   r   r   r   r
   r   setr   )r   r   r   r   )r   r   r   r   j   s    zCriteriaSetDescriptor.__set__N)r   r   r   r   r   r   r   r   r   r    f   s   r    c               @   s:   e Zd ZdZdd ZdddZedd Zed	d
 ZdS )NetworkXGraphEdgeDescriptora'  
    Descriptor abstract base class for NetworkX graph edge attributes.

    Parameter:
    name        The edge property name

    Instance class attribute use (obj parameter):
    G           The NetworkX graph
    source      The edge's source node
    target      The edge's target node
    c             C   s
   || _ d S )N)name)r   propnamer   r   r   r      s    z$NetworkXGraphEdgeDescriptor.__init__Nc             C   sH   |d kr| S y|j |j |j | j S  tk
rB   t| jY nX d S )N)Gsourcetargetr&   KeyErrorAttributeError)r   r   r   r   r   r   r      s    z#NetworkXGraphEdgeDescriptor.__get__c             C   s   d S )Nr   )r   r   r   r   r   r   r      s    z#NetworkXGraphEdgeDescriptor.__set__c             C   s   d S )Nr   )r   r   r   r   r   
__delete__   s    z&NetworkXGraphEdgeDescriptor.__delete__)N)	r   r   r   r   r   r   r   r   r-   r   r   r   r   r%      s
   
	r%   c               @   s    e Zd ZdZdd Zdd ZdS )EdgeAttrDictz7A descriptor for edge attributes that are dictionaries.c             C   s:   |d kr&t t|j|j |j | j< ntdj| jd S )Nz0{0} dictionaries should not be assigned directly)r   listr(   r)   r*   r&   r,   format)r   r   r   r   r   r   r      s    zEdgeAttrDict.__set__c             C   s    |j |j |j | j j  d S )N)r(   r)   r*   r&   clear)r   r   r   r   r   r-      s    zEdgeAttrDict.__delete__N)r   r   r   r   r   r-   r   r   r   r   r.      s   r.   c               @   s    e Zd ZdZdd Zdd ZdS )EdgeAttrIntMaxz
    A descriptor for edge attributes that are non-negative integers that always
    keep the max assigned value until re-initialized.
    c             C   s\   |d kr"d|j |j |j | j< n6|j |j |j | j }t|||j |j |j | j< d S )Nr   )r(   r)   r*   r&   max)r   r   r   Zcurrent_valuer   r   r   r      s    zEdgeAttrIntMax.__set__c             C   s   d|j |j |j | j< d S )Nr   )r(   r)   r*   r&   )r   r   r   r   r   r-      s    zEdgeAttrIntMax.__delete__N)r   r   r   r   r   r-   r   r   r   r   r2      s   r2   c               @   s    e Zd ZdZdd Zdd ZdS )EdgeAttrListz0A descriptor for edge attributes that are lists.c             C   s6   |d kr"g |j |j |j | j< ntdj| jd S )Nz){0} lists should not be assigned directly)r(   r)   r*   r&   
ValueErrorr0   )r   r   r   r   r   r   r      s    zEdgeAttrList.__set__c             C   s    |j |j |j | j j  d S )N)r(   r)   r*   r&   r1   )r   r   r   r   r   r-      s    zEdgeAttrList.__delete__N)r   r   r   r   r   r-   r   r   r   r   r4      s   r4   c               @   s2   e Zd ZdZdd ZdddZdd Zd	d
 ZdS )PermissionMapDescriptoraN  
    Descriptor for Permission Map mappings.

    Parameter:
    name        The map setting name.
    validator   A callable for validating the setting.

    Instance class attribute use (obj parameter):
    perm_map    The full permission map.
    class_      The mapping's object class
    perm        The mapping's permission
    c             C   s   || _ || _d S )N)r&   	validator)r   r'   r7   r   r   r   r      s    z PermissionMapDescriptor.__init__Nc             C   s$   |d kr| S |j |j |j | j S )N)perm_mapclass_permr&   )r   r   r   r   r   r   r      s    zPermissionMapDescriptor.__get__c             C   s"   | j ||j|j |j | j< d S )N)r7   r8   r9   r:   r&   )r   r   r   r   r   r   r      s    zPermissionMapDescriptor.__set__c             C   s   t d S )N)r,   )r   r   r   r   r   r-      s    z"PermissionMapDescriptor.__delete__)N)r   r   r   r   r   r   r   r-   r   r   r   r   r6      s
   
r6   )r   r   abcr   r   collectionsr   weakrefr   r   r    r%   r.   r2   r4   r6   r   r   r   r   <module>   s   
;#