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. NcCsJ|s|s|stdƒ‚|o| s&tdƒ‚||_||_||_||_tƒ|_dS)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__Cs zCriteriaDescriptor.__init__cCs|dkr |S|jj||jƒS)N)r Ú setdefaultr )r ÚobjÚobjtyperrrÚ__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ÚvaluerrrrÚ__set__Xs zCriteriaDescriptor.__set__)NNNN)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrr+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)rrrú qsz0CriteriaSetDescriptor.__set__..c3s|]}ˆjj|ƒVqdS)N)r r)r!r")r rrr#ss) r rrrrr rÚsetr )r rrr)rr rrjs zCriteriaSetDescriptor.__set__N)rrrrrrrrrr fsr c@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 ÚpropnamerrrrŽsz$NetworkXGraphEdgeDescriptor.__init__Nc CsH|dkr |Sy|j|j|j|jStk rBt|jƒ‚YnXdS)N)ÚGÚsourceÚtargetr&ÚKeyErrorÚAttributeError)r rrrrrr‘s z#NetworkXGraphEdgeDescriptor.__get__cCsdS)Nr)r rrrrrršsz#NetworkXGraphEdgeDescriptor.__set__cCsdS)Nr)r rrrrÚ __delete__žsz&NetworkXGraphEdgeDescriptor.__delete__)N) rrrrrrrrr-rrrrr%€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 rrrrrr§szEdgeAttrDict.__set__cCs |j|j|j|jjƒdS)N)r(r)r*r&Úclear)r rrrrr-¯szEdgeAttrDict.__delete__N)rrrrrr-rrrrr.£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_valuerrrrºszEdgeAttrIntMax.__set__cCsd|j|j|j|j<dS)Nr)r(r)r*r&)r rrrrr-ÂszEdgeAttrIntMax.__delete__N)rrrrrr-rrrrr2³sr2c@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&Ú ValueErrorr0)r rrrrrrÊszEdgeAttrList.__set__cCs |j|j|j|jjƒdS)N)r(r)r*r&r1)r rrrrr-ÑszEdgeAttrList.__delete__N)rrrrrr-rrrrr4Æsr4c@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'r7rrrrçsz PermissionMapDescriptor.__init__NcCs$|dkr |S|j|j|j|jS)N)Úperm_mapÚclass_Úpermr&)r rrrrrrëszPermissionMapDescriptor.__get__cCs"|j|ƒ|j|j|j|j<dS)N)r7r8r9r:r&)r rrrrrrñszPermissionMapDescriptor.__set__cCst‚dS)N)r,)r rrrrr-ôsz"PermissionMapDescriptor.__delete__)N)rrrrrrrr-rrrrr6Øs   r6)rrÚabcrrÚ collectionsrÚweakrefrrr r%r.r2r4r6rrrrÚs  ;#