o
    ßý°j“  ã                   @   sÞ   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ ddlm Z m!Z!m"Z"m#Z# G dd„ dee
ƒZ$dS )Ú
é   )ÚDO_NOT_RAISE_EXCEPTIONSé   )ÚMockBaseStrategy)ÚALL_ATTRIBUTESÚALL_OPERATIONAL_ATTRIBUTESÚNO_ATTRIBUTES)ÚSyncStrategy)Úbind_response_to_dict)Údelete_response_to_dict)Úadd_response_to_dict)Úcompare_response_to_dict)Úmodify_dn_response_to_dict)Úmodify_response_to_dict)Ú#search_result_done_response_to_dictÚ$search_result_entry_response_to_dict)Úextended_response_to_dict)ÚLDAPSocketOpenErrorÚLDAPOperationResult)ÚlogÚlog_enabledÚERRORÚPROTOCOLc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚMockSyncStrategyzŒ
    This strategy create a mock LDAP server, with synchronous access
    It can be useful to test LDAP without accessing a real Server
    c                 C   s   t  | |¡ t | ¡ d S )N)r	   Ú__init__r   )ÚselfÚldap_connection© r   úŠ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/strategy/mockSync.pyr   /   s   zMockSyncStrategy.__init__c                 C   sÐ  |\}}}}g | j _tƒ | j _|dkrä|  ||¡\}}|D ]�}t|| j jj| j jj| j j	ƒ}	d|	d< | j j
r¥|d D ],}
t|
ƒ}||	d vrf|tttfvrftƒ |	d |< tƒ |	d |< ttƒrfttd|
| ƒ q:| j js¥g }|	d D ]}
t|
ƒ}d| ¡ v rŠ| d¡\}}}| |¡ qq|D ]}
ttƒršttd	|
| ƒ |	d |
= |	d |
= q�| j j |	¡ qt|ƒ}d
|d< || j _| j jrä|rä|d tvrättƒrÑttd|| j ƒ t|d |d |d |d |d d�‚| j jS )NÚsearchRequestÚsearchResEntryÚtypeÚ
attributesÚraw_attributesz>attribute set to empty list for missing attribute <%s> in <%s>z;rangeú;ziattribute type <%s> removed in response because of same attribute returned as range by the server in <%s>ÚsearchResDoneÚresultúoperation result <%s> for <%s>ÚdescriptionÚdnÚmessage©r&   r(   r)   r*   Úresponse_type)Ú
connectionÚresponseÚdictr&   Úmock_searchr   ÚserverÚschemaÚcustom_formatterÚcheck_namesÚempty_attributesÚstrr   r   r   Úlistr   r   r   Ú
auto_rangeÚlowerÚ	partitionÚappendr   Úraise_exceptionsr   r   )r   ÚpayloadÚ
message_idÚmessage_typeÚrequestÚcontrolsÚ	responsesr&   Úentryr.   Úattribute_typeÚattribute_nameÚattrs_to_removeÚ	orig_attrÚ_r   r   r   Úpost_send_search3   sX   
ÿ€
€þ
&z!MockSyncStrategy.post_send_searchc                 C   s†  |\}}}}g }d }|dkrt |  ||¡ƒ}d|d< nr|dkr#d | _nj|dkr(ne|dkr9t|  ||¡ƒ}d|d< nT|dkrJt|  ||¡ƒ}d	|d< nC|d
kr[t|  ||¡ƒ}d|d< n2|dkrlt	|  
||¡ƒ}d|d< n!|dkr}t|  ||¡ƒ}d|d< n|dkr�t|  ||¡ƒ}d|d< || j_| |¡ | jjrÁ|rÁ|d tvrÁttƒr®ttd|| jƒ t|d |d |d |d |d d�‚|S )NÚbindRequestÚbindResponser!   ÚunbindRequestÚabandonRequestÚ
delRequestÚdelResponseÚ
addRequestÚaddResponseÚcompareRequestÚcompareResponseÚmodDNRequestÚmodDNResponseÚmodifyRequestÚmodifyResponseÚextendedReqÚextendedRespr&   r'   r(   r)   r*   r+   )r
   Ú	mock_bindÚboundr   Úmock_deleter   Úmock_addr   Úmock_comparer   Úmock_modify_dnr   Úmock_modifyr   Úmock_extendedr-   r&   r;   r<   r   r   r   r   r   )r   r=   r>   r?   r@   rA   rB   r&   r   r   r   Úpost_send_single_responsea   sF   






&z*MockSyncStrategy.post_send_single_responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rI   rb   r   r   r   r   r   *   s
    .r   N)%rf   Úcore.resultsr   ÚmockBaser   Ú r   r   r   Úsyncr	   Úoperation.bindr
   Úoperation.deleter   Úoperation.addr   Úoperation.comparer   Úoperation.modifyDnr   Úoperation.modifyr   Úoperation.searchr   r   Úoperation.extendedr   Úcore.exceptionsr   r   Ú	utils.logr   r   r   r   r   r   r   r   r   Ú<module>   s     