
    >OOf(                         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ee      Z$y)
   )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                   *    e Zd ZdZd Zd Zd ZddZy)MockAsyncStrategyz
    This strategy create a mock LDAP server, with asynchronous access
    It can be useful to test LDAP without accessing a real Server
    c                 Z    t        j                  | |       t        j                  |        y )N)r	   __init__r   )selfldap_connections     Y/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/strategy/mockAsync.pyr   zMockAsyncStrategy.__init__e   s     t_5!!$'    c                    |\  }}}}g }t               }|dk(  r| j                  ||      \  }}	d|	d<   |D ]  }
t        |
| j                  j                  j
                  | j                  j                  j                  | j                  j                        }d|d<   | j                  j                  r|d   D ]k  }t        |      }||d   vs|t        t        t        fvs*t               |d   |<   t               |d   |<   t        t              sZt!        t        d||        m | j                  j"                  sg }|d   D ]F  }t        |      }d|j%                         v s!|j'                  d	      \  }}}|j)                  |       H |D ]/  }t        t              rt!        t        d
||        |d   |= |d   |= 1 |j)                  |        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_s                    r    post_send_searchz"MockAsyncStrategy.post_send_searchj   sK   6=3
L'8v?* $ 0 0( CIv,F6N" 0?tG]G]GdGdfjfufuf|f|  gN  gN  PT  P_  P_  Pk  Pk  l#3 ??33*1,*? :),^)<):J1KKP^gu  xR  Ta  gb  QbIMH%56~FEIVH\2>B*84 #H.n$2D!::  ??55*,.6|.D BN-0-@N'>+?+?+AA2@2J2J32O	1a / 6 6y A	B
 /> GN*84 #H %P$2D!: !))9 :> J ( 6~ FG %%h/;0< ?vFL#2L '.n&M
#r!   c                 t   |\  }}}}g }d }|dk(  r!t        | j                  ||            }d|d<   n|dk(  rd | _        n|dk(  rn|dk(  r!t        | j	                  ||            }d|d<   n|dk(  r!t        | j                  ||            }d	|d<   n|d
k(  r!t        | j                  ||            }d|d<   nq|dk(  r!t        | j                  ||            }d|d<   nK|dk(  r!t        | j                  ||            }d|d<   n%|dk(  r t        | j                  ||            }d|d<   |j                  |       | j                   j"                  rW|rU|d   t$        vrJt'        t(              rt+        t(        d|| j                          t-        |d   |d   |d   |d   |d         |||f| j.                  |<   |S )NbindRequestbindResponser%   unbindRequestabandonRequest
delRequestdelResponse
addRequestaddResponsecompareRequestcompareResponsemodDNRequestmodDNResponsemodifyRequestmodifyResponseextendedReqextendedResprA   operation result <%s> for <%s>descriptiondnmessagerA   r\   r]   r^   response_type)r   	mock_bindboundr   mock_deleter   mock_addr   mock_comparer   mock_modify_dnr   mock_modifyr   mock_extendedr7   r,   raise_exceptionsr   r   r   r   r   r8   )r   r9   r:   r;   r<   r=   r@   rA   s           r    post_send_single_responsez+MockAsyncStrategy.post_send_single_response   s   6=3
L'8	=(*4>>'8+LMF+F6N_,DJ--\),T-=-=gx-PQF*F6N\))$--*JKF*F6N---d.?.?.RSF.F6N^+/0C0CGX0VWF,F6N_,,T-=-=gx-PQF-F6N]*.t/A/A'8/TUF+F6N ??++6(;KSj;j8$H>X%VH-=6R_K`eklpeq  |B  CL  |M  ]c  dj  ]k  l  l'.	&B
#r!   Nc                 d   || j                   v r | j                   j                  |      \  }}}nt        d      | j                  j                  rW|rU|d   t
        vrJt        t              rt        t        d|| j                         t        |d   |d   |d   |d   |d         |r|||fS ||fS )	Nz#message id not in outstanding queuerA   r[   r\   r]   r^   r%   r_   )
r8   popr   r,   ri   r   r   r   r   r   )r   r:   timeoutget_requestr<   rA   rC   s          r    get_responsezMockAsyncStrategy.get_response   s    ((,(;(;J(G%GVX*+PQR??++6(;KSj;j8$H>X%VH-=6R_K`eklpeq  |B  CL  |M  ]c  dj  ]k  l  lVW,,V##r!   )NF)__name__
__module____qualname____doc__r   rI   rj   ro    r!   r    r   r   `   s    (
(T#L$r!   r   N)%rs    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   rt   r!   r    <module>r      sR   2 I H & ' h 2 9 9 K 2 6 0 8 ; 6 h :ph$(- h$r!   