509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!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rŒt‡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   
;#