o
    j(                     @   s   d 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
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 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# G dd deeZ$dS )
   )ALL_ATTRIBUTESALL_OPERATIONAL_ATTRIBUTESNO_ATTRIBUTES   )MockBaseStrategy)AsyncStrategy)#search_result_done_response_to_dict$search_result_entry_response_to_dict)DO_NOT_RAISE_EXCEPTIONS)loglog_enabledERRORPROTOCOL)LDAPResponseTimeoutErrorLDAPOperationResult)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)extended_response_to_dictc                   @   s2   e Zd ZdZdd Zdd Zdd Zdd
dZdS )MockAsyncStrategyz
    This strategy create a mock LDAP server, with asynchronous 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/mockAsync.pyr   e   s   zMockAsyncStrategy.__init__c                 C   sz  |\}}}}g }t  }|dkr| ||\}}	d|	d< |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sg }|d D ]}t	|}d| v r|d	\}}}|| qq|D ]}ttrttd
||  |d |= |d |= q|| qt|	}d|d< |||f| j|< |S )NsearchRequestsearchResDonetypesearchResEntry
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>)dictmock_searchr
   
connectionserverschemacustom_formattercheck_namesempty_attributesstrr   r   r   listr   r   r   
auto_rangelower	partitionappendr	   
_responses)r   payload
message_idmessage_typerequestcontrolsasync_responseasync_result	responsesresultentryresponseattribute_typeattribute_nameattrs_to_remove	orig_attr_r   r   r   post_send_searchj   sR   

z"MockAsyncStrategy.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rt| ||}d|d< || | jjr|r|d tvrttrttd|| j t|d |d |d |d |d d|||f| j|< |S )NbindRequestbindResponser!   unbindRequestabandonRequest
delRequestdelResponse
addRequestaddResponsecompareRequestcompareResponsemodDNRequestmodDNResponsemodifyRequestmodifyResponseextendedReqextendedRespr=   operation result <%s> for <%s>descriptiondnmessager=   rW   rX   rY   response_type)r   	mock_bindboundr   mock_deleter   mock_addr   mock_comparer   mock_modify_dnr   mock_modifyr   mock_extendedr3   r(   raise_exceptionsr   r   r   r   r   r4   )r   r5   r6   r7   r8   r9   r<   r=   r   r   r   post_send_single_response   sF   






&z+MockAsyncStrategy.post_send_single_responseNFc                 C   s   || j v r| j |\}}}ntd| jjr>|r>|d tvr>ttr+ttd|| j t	|d |d |d |d |d d|rE|||fS ||fS )	Nz#message id not in outstanding queuer=   rV   rW   rX   rY   r!   rZ   )
r4   popr   r(   rd   r   r   r   r   r   )r   r6   timeoutget_requestr8   r=   r?   r   r   r   get_response   s   
&
zMockAsyncStrategy.get_response)NF)__name__
__module____qualname____doc__r   rE   re   ri   r   r   r   r   r   `   s    *&r   N)%rm    r   r   r   mockBaser   asynchronousr   operation.searchr	   r
   core.resultsr   	utils.logr   r   r   r   core.exceptionsr   r   operation.bindr   operation.deleter   operation.addr   operation.comparer   operation.modifyDnr   operation.modifyr   operation.extendedr   r   r   r   r   r   <module>   s"    8