3 í«„^âã@s¤dZddlZddlmZmZddlmZddlmZGdd„dƒZ Gdd „d e ƒZ Gd d „d eƒZ Gd d „d e ƒZ Gdd„de ƒZ Gdd„de ƒZGdd„dƒZdS)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,eZdZdZd dd„Zd dd„Zdd„ZdS) Ú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. NcCs$||_||_||_||_tƒ|_dS)N)ÚregexÚ default_valueÚlookup_functionÚ enum_classrÚ instances)ÚselfZ name_regexr rr ©r ú#/usr/lib64/python3.6/descriptors.pyÚ__init__Cs zCriteriaDescriptor.__init__cCs|dkr |S|jj||jƒS)N)r Ú setdefaultr)r ÚobjÚobjtyper r rÚ__get__RszCriteriaDescriptor.__get__cCs‚|sd|j|<nn|jr6t||jdƒr6tj|ƒ|j|<nH|jrZt|j|jƒ}||ƒ|j|<n$|jrt|jj|ƒ|j|<n ||j|<dS)NF) r rÚgetattrÚreÚcompiler Úpolicyr Úlookup)r rÚvaluerr r rÚ__set__Xs zCriteriaDescriptor.__set__)NNNN)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr r r rr+s  rc@seZdZdZdd„ZdS)ÚCriteriaSetDescriptorz!Descriptor for a set of criteria.csž|sdˆj|<nŠˆjr6t|ˆjdƒr6tj|ƒˆj|<ndˆjrht|jˆjƒ‰t‡fdd„|Dƒƒˆj|<n2ˆjrŒt‡fdd„|Dƒƒˆj|<nt|ƒˆj|<dS)NFc3s|]}ˆ|ƒVqdS)Nr )Ú.0Úv)rr rú qsz0CriteriaSetDescriptor.__set__..c3s|]}ˆjj|ƒVqdS)N)r r)r r!)r r rr"ss) r rrrrr rÚsetr )r rrr )rr rrjs zCriteriaSetDescriptor.__set__N)rrrrrr r r rrfsrc@s:eZdZdZdd„Zd dd„Zedd„ƒZed d „ƒZdS) Ú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 cCs ||_dS)N)Úname)r Úpropnamer r rrŽsz$NetworkXGraphEdgeDescriptor.__init__Nc CsH|dkr |Sy|j|j|j|jStk rBt|jƒ‚YnXdS)N)ÚGÚsourceÚtargetr%ÚKeyErrorÚAttributeError)r rrr r rr‘s z#NetworkXGraphEdgeDescriptor.__get__cCsdS)Nr )r rrr r rršsz#NetworkXGraphEdgeDescriptor.__set__cCsdS)Nr )r rr r rÚ __delete__žsz&NetworkXGraphEdgeDescriptor.__delete__)N) rrrrrrrrr,r r r rr$€s   r$c@s eZdZdZdd„Zdd„ZdS)Ú EdgeAttrDictz7A descriptor for edge attributes that are dictionaries.cCs:|dkr&ttƒ|j|j|j|j<ntdj|jƒƒ‚dS)Nz0{0} dictionaries should not be assigned directly)rÚlistr'r(r)r%r+Úformat)r rrr r rr§szEdgeAttrDict.__set__cCs |j|j|j|jjƒdS)N)r'r(r)r%Úclear)r rr r rr,¯szEdgeAttrDict.__delete__N)rrrrrr,r r r rr-£sr-c@s eZdZdZdd„Zdd„ZdS)ÚEdgeAttrIntMaxz‹ A descriptor for edge attributes that are non-negative integers that always keep the max assigned value until re-initialized. cCs\|dkr"d|j|j|j|j<n6|j|j|j|j}t||ƒ|j|j|j|j<dS)Nr)r'r(r)r%Úmax)r rrZ current_valuer r rrºszEdgeAttrIntMax.__set__cCsd|j|j|j|j<dS)Nr)r'r(r)r%)r rr r rr,ÂszEdgeAttrIntMax.__delete__N)rrrrrr,r r r rr1³sr1c@s eZdZdZdd„Zdd„ZdS)Ú EdgeAttrListz0A descriptor for edge attributes that are lists.cCs6|dkr"g|j|j|j|j<ntdj|jƒƒ‚dS)Nz){0} lists should not be assigned directly)r'r(r)r%Ú ValueErrorr/)r rrr r rrÊszEdgeAttrList.__set__cCs |j|j|j|jjƒdS)N)r'r(r)r%r0)r rr r rr,ÑszEdgeAttrList.__delete__N)rrrrrr,r r r rr3Æsr3c@s2eZdZdZdd„Zd dd„Zdd„Zd d „ZdS) Ú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 cCs||_||_dS)N)r%Ú validator)r r&r6r r rrçsz PermissionMapDescriptor.__init__NcCs$|dkr |S|j|j|j|jS)N)Úperm_mapÚclass_Úpermr%)r rrr r rrëszPermissionMapDescriptor.__get__cCs"|j|ƒ|j|j|j|j<dS)N)r6r7r8r9r%)r rrr r rrñszPermissionMapDescriptor.__set__cCst‚dS)N)r+)r rr r rr,ôsz"PermissionMapDescriptor.__delete__)N)rrrrrrrr,r r r rr5Øs   r5)rrÚabcrrÚ collectionsrÚweakrefrrrr$r-r1r3r5r r r rÚs  ;#