o
    ßý°j!.  ã                   @   s´   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZmZmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZ G dd„ deƒZ dS )Ú
é    )Úlinesepé   )ÚAttrDefé   )ÚLDAPKeyErrorÚLDAPObjectErrorÚLDAPAttributeErrorÚLDAPSchemaError)ÚSTRING_TYPESÚSEQUENCE_TYPESÚServerÚ
Connection)Ú
SchemaInfoÚconstant_to_class_kind)Úfind_attribute_validator)ÚCaseInsensitiveWithAliasDict)Úget_config_parameter)ÚlogÚlog_enabledÚERRORÚBASICÚPROTOCOLÚEXTENDEDc                   @   s°   e Zd ZdZd(dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zeeur<dd„ Zndd„ Zdd„ Zd)d d!„Zd*d"d#„Zd$d%„ Zd&d'„ ZdS )+Ú	ObjectDefaC  Represent an object in the LDAP server. AttrDefs are stored in a dictionary; the key is the friendly name defined in AttrDef.

    AttrDefs can be added and removed using the += and -= operators

    ObjectDef can be accessed either as a sequence and a dictionary. When accessed the whole AttrDef instance is returned

    Nc                    s”  |d u rg }t |tƒs|g}|d u rg }t |tƒs|g}tƒ | jd< || jd< g | jd< t ˆ tƒr;ˆ js7ˆ jr;ˆ  ¡  ˆ d ur€t ˆ tƒrHˆ j	‰ n#t ˆ tƒrRˆ j
j	‰ nt ˆ tƒrXnˆ rkd}ttƒrgttd|| ƒ t|ƒ‚ˆ d u r€d}ttƒr|ttd|| ƒ t|ƒ‚ˆ | jd< | jr²‡ fdd	„|D ƒ}‡ fd
d	„|D ƒ}|D ]	}|r¥|  |¡ qœ|D ]	}|r±|  |¡ q¨|| jd< || jd< ttƒrÈttd| ƒ d S d S )NÚ_attributesÚ_custom_validatorÚ	_oid_infozunable to read schemaú%s for <%s>zschema not presentÚ_schemac                    ó   g | ]
}ˆ j | jd  ‘qS ©r   ©Úobject_classesÚname©Ú.0r$   ©Úschema© ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/abstract/objectDef.pyÚ
<listcomp>V   ó    z&ObjectDef.__init__.<locals>.<listcomp>c                    r    r!   r"   r%   r'   r)   r*   r+   W   r,   Ú_object_classÚ_auxiliary_classzinstantiated ObjectDef: <%r>)Ú
isinstancer   r   Ú__dict__r   Ú_deferred_bindÚ_deferred_openÚ_fire_deferredr   r(   Úserverr   r   r   r   r
   r   Ú_populate_attr_defsr   )ÚselfÚobject_classr(   Úcustom_validatorÚauxiliary_classÚerror_messageÚobject_namer)   r'   r*   Ú__init__.   s^   









€
€

ÿzObjectDef.__init__c                 C   sÄ   || j jv rO| j j| }| jd  |d t|jƒ d t|jƒ ¡ |jr0|jD ]}|  	|¡ q(|j
D ]}|  |d¡ q3|jD ]}|| jvrL|  |d¡ q?d S d| }ttƒr^ttd|| ƒ t|ƒ‚)Nr   z (z) TFz'object class '%s' not defined in schemar   )r   r#   r0   Úappendr   ÚkindÚstrÚoidÚsuperiorr5   Úmust_containÚadd_from_schemaÚmay_containr   r   r   r   r   )r6   r;   Úobject_schemaÚsupÚattribute_namer:   r)   r)   r*   r5   f   s"   ,



€þzObjectDef._populate_attr_defsc                    sÊ   ˆ j rdd ˆ j ¡ t }ndt }ˆ jr"|dd ˆ j¡ t 7 }n|dt 7 }|dd dd„ ˆ jD ƒ¡ t 7 }|d	d t‡ fd
d„ˆ jD ƒƒ¡ t 7 }|dd t‡ fdd„ˆ jD ƒƒ¡ t 7 }|S )NzOBJ : z, zOBJ : <None>zAUX : zAUX : <None>zOID: c                 S   s   g | ]}|‘qS r)   r)   )r&   r@   r)   r)   r*   r+   ‚   s    z&ObjectDef.__repr__.<locals>.<listcomp>zMUST: c                    s   g | ]
}ˆ j | jr|‘qS r)   ©r   Ú	mandatory©r&   Úattr©r6   r)   r*   r+   ƒ   r,   zMAY : c                    s   g | ]
}ˆ j | js|‘qS r)   rH   rJ   rL   r)   r*   r+   „   r,   )r-   Újoinr   r.   r   Úsortedr   )r6   Úrr)   rL   r*   Ú__repr__y   s   "**zObjectDef.__repr__c                 C   s   |   ¡ S ©N)rP   rL   r)   r)   r*   Ú__str__ˆ   s   zObjectDef.__str__c                 C   s
   |   |¡S rQ   )Ú__getattr__©r6   Úitemr)   r)   r*   Ú__getitem__‹   ó   
zObjectDef.__getitem__c                 C   s€   d  | ¡ ¡ ¡ }d| jv r/z| j| W S  ty.   d| }ttƒr*ttd|| ƒ t	|ƒ‚w d}ttƒr<ttd|| ƒ t	|ƒ‚)NÚ r   úkey '%s' not presentr   z)internal _attributes property not defined)
rM   ÚsplitÚlowerr0   r   ÚKeyErrorr   r   r   r   )r6   rU   r:   r)   r)   r*   rS   Ž   s   
üzObjectDef.__getattr__c                 C   s&   d| }t tƒrttd|| ƒ t|ƒ‚)Nzobject '%s' is read onlyr   )r   r   r   r   )r6   ÚkeyÚvaluer:   r)   r)   r*   Ú__setattr__ž   s   zObjectDef.__setattr__c                 C   s   |   |¡ | S rQ   )Úadd_attribute©r6   Úotherr)   r)   r*   Ú__iadd__¤   s   
zObjectDef.__iadd__c                 C   s2   t |tƒr|  |j¡ | S t |tƒr|  |¡ | S rQ   )r/   r   Úremove_attributer]   r   ra   r)   r)   r*   Ú__isub__¨   s   

ý
zObjectDef.__isub__c                 c   s   � | j D ]}| j | V  qd S rQ   )r   )r6   Ú	attributer)   r)   r*   Ú__iter__°   s   €
ÿzObjectDef.__iter__c                 C   s
   t | jƒS rQ   )Úlenr   rL   r)   r)   r*   Ú__len__´   rW   zObjectDef.__len__c                 C   ó   dS ©NTr)   rL   r)   r)   r*   Ú__bool__¸   ó   zObjectDef.__bool__c                 C   rj   rk   r)   rL   r)   r)   r*   Ú__nonzero__»   rm   zObjectDef.__nonzero__c                 C   s&   z|   |¡ W dS  ty   Y dS w )NFT)rV   r\   rT   r)   r)   r*   Ú__contains__¾   s   ýÿzObjectDef.__contains__Fc                 C   sf   t |ƒ}t| j|| jƒ|_||_| jr,| jjr,|| jjv r,| jj| j|_| jj| |_|  	|¡ d S rQ   )
r   r   r   r   ÚvalidaterI   Úattribute_typesÚsingle_valueÚoid_infor`   )r6   rG   rI   Úattr_defr)   r)   r*   rC   Æ   s   zObjectDef.add_from_schemac                    s(  dd„ t dƒD ƒ}tˆ tƒr|  ˆ ¡ dS tˆ tƒrrˆ j ¡ |vrnˆ j| jvrYˆ | jˆ j< ˆ jr?ˆ jˆ jkr?| j 	ˆ jˆ j¡ ˆ j
rM‡ fdd„ˆ j
jD ƒnd}|rY| j 	ˆ j|¡ ˆ jspt| jˆ j| jƒ}|| jˆ j _dS dS dS tˆ tƒrƒˆ D ]}|  |¡ qydS d}ttƒr�ttd|| ƒ t|ƒ‚)zØAdd an AttrDef to the ObjectDef. Can be called with the += operator.
        :param definition: the AttrDef object to add, can also be a string containing the name of attribute to add. Can be a list of both

        c                 S   s   g | ]}|  ¡ ‘qS r)   )r[   )r&   Úvr)   r)   r*   r+   Ô   s    z+ObjectDef.add_attribute.<locals>.<listcomp>Ú#ATTRIBUTES_EXCLUDED_FROM_OBJECT_DEFc                    s"   g | ]}ˆ j  ¡ | ¡ kr|‘qS r)   )r]   r[   r%   ©Ú
definitionr)   r*   r+   Ý   s   " Nz*unable to add element to object definitionr   )r   r/   r   rC   r   r]   r[   r   r$   Ú	set_aliasrs   rp   r   r   r   r   r`   r   r   r   r   )r6   rx   Ú(conf_attributes_excluded_from_object_defÚother_namesÚ	validatorÚelementr:   r)   rw   r*   r`   Ï   s2   

 õ	
ÿzObjectDef.add_attributec                 C   s´   d}t |tƒrd | ¡ ¡ ¡ }n
t |tƒr|j ¡ }|rC| jD ]}|| ¡ kr/| j|=  dS q d| }tt	ƒr?t
t	d|| ƒ t|ƒ‚dtt|ƒƒ }tt	ƒrVt
t	d|| ƒ t|ƒ‚)z¿Remove an AttrDef from the ObjectDef. Can be called with the -= operator.
        :param item: the AttrDef to remove, can also be a string containing the name of attribute to remove

        NrX   rY   r   z$key type must be str or AttrDef not )r/   r   rM   rZ   r[   r   r]   r   r   r   r   r   r?   Útyper	   )r6   rU   r]   rK   r:   r)   r)   r*   rd   í   s&   



þzObjectDef.remove_attributec                 C   s$   d| j d< d| j d< tƒ | j d< dS )z,Empty the ObjectDef attribute list

        Nr7   r9   r   )r0   ÚdictrL   r)   r)   r*   Úclear_attributes  s   

zObjectDef.clear_attributes)NNNN)FrQ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   r5   rP   rR   rV   rS   r_   rc   re   rg   ri   r?   Úbytesrl   rn   ro   rC   r`   rd   r€   r)   r)   r)   r*   r   &   s*    
8


	r   N)!r„   Úosr   ÚattrDefr   Úcore.exceptionsr   r   r	   r
   rX   r   r   r   r   Úprotocol.rfc4512r   r   Úprotocol.formatters.standardr   Úutils.ciDictr   Úutils.configr   Ú	utils.logr   r   r   r   r   r   Úobjectr   r)   r)   r)   r*   Ú<module>   s     