
    >OOf                         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ee
      Z$y)
   )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                   "    e Zd ZdZd Zd Zd Zy)MockSyncStrategyz
    This strategy create a mock LDAP server, with synchronous 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     X/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/strategy/mockSync.pyr   zMockSyncStrategy.__init__/   s     dO4!!$'    c                 L   |\  }}}}g | j                   _        t               | j                   _        |dk(  rX| j	                  ||      \  }}|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                   j                  j-                  |	        t/        |      }d
|d<   || j                   _        | j                   j0                  rW|rU|d   t2        vrJt!        t"              rt%        t"        d|| j                          t5        |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*   entryr2   attribute_typeattribute_nameattrs_to_remove	orig_attr_s                  r    post_send_searchz!MockSyncStrategy.post_send_search3   s   6=3
L'8#% !%?* $ 0 0( CIv" :?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 ((//9;:< 9@F,F6N%+DOO"//Fvh?OWn?nx("BFDOO\)1AvVcOdioptiu  @F  GP  @Q  ag  hn  ao  p  p'''r!   c                 r   |\  }}}}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                  j$                  rW|rU|d   t&        vrJt)        t*              rt-        t*        d|| j                         t/        |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_extendedr1   r*   r?   r@   r   r   r   r   r   )r   rA   rB   rC   rD   rE   rF   r*   s           r    post_send_single_responsez*MockSyncStrategy.post_send_single_responsea   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r!   N)__name__
__module____qualname____doc__r   rM   rg    r!   r    r   r   *   s    (,(\#r!   r   N)%rk   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   rl   r!   r    <module>r{      sM   2 3 & H H  2 6 0 8 ; 6 h : F 9 9Z' Zr!   