
    =OOfd                        d 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mZ d	d
l
mZmZmZmZmZmZmZ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!m"Z" d	dl#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 d	dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d	dl7m8Z8m9Z9m:Z:m;Z;  edd      Z<d Z=d Z> G d de?      Z@ G d de@      ZA G d  d!e@      ZBy")#
    )
namedtuple)deepcopy)datetime)linesep)sleep   )STATUS_VIRTUALSTATUS_READSTATUS_WRITABLE   )SUBTREELEVELDEREF_ALWAYSDEREF_NEVERBASESEQUENCE_TYPESSTRING_TYPESget_config_parameter)STATUS_PENDING_CHANGES)	AttributeOperationalAttributeWritableAttribute)AttrDef)	ObjectDef)EntryWritableEntry)LDAPCursorErrorLDAPObjectDereferenceError)RESULT_SUCCESS)CaseInsensitiveWithAliasDict)safe_dnsafe_rdn)to_raw)r   )loglog_enabledERRORBASICPROTOCOLEXTENDED)ATTRIBUTE_DIRECTORY_OPERATIONATTRIBUTE_DISTRIBUTED_OPERATIONATTRIBUTE_DSA_OPERATIONCLASS_AUXILIARY	Operation)requestresultresponsec                 @    | d   dv r| d   dk7  r| d   dz   | dd  z   S | S )Nr   z<>~r	   = )values    V/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/abstract/cursor.py_ret_search_valuer8   2   s6    ).qU):uQx358c>E!"I%YTYY    c                     t               }| rS| j                  d      D ]?  }d|v s|j                  d      }|d   j                         ||d   j                         <   A |S )zu
    Create a dictionary with query key:value definitions
    query_text is a comma delimited key:value sequence
    ,:r	   r   )dictsplitstrip)
query_text
query_dictarg_value_strarg_value_lists       r7   _create_query_dictrD   6   sp    
 J'--c2 	RMm#!.!4!4S!98Fq8I8O8O8Q
>!,2245	R
 r9   c                       e Zd ZddZd Zd Zd Zd Zd Ze	e
urd Znd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zed        Zed        Zed        Zy)CursorNc                    t        d      D cg c]  }|j                          }}|| _        || _        |j                  s|j
                  r|j                          t        |t        t        f      r>|j                  r|j                          t        ||j                  j                  |      }|| _        |rg }	t        |t              r|g}|D ]?  }
|
| j                  j                   vs|
j                         |vs/|	j#                  |
       A |	r@ddj%                  |	      z  }t'        t(              rt+        t(        d||        t-        |      |rt/        |      n,t/        | j                  D cg c]  }|j0                   c}      | _        || _        d | _        g | _        | j                  j                  j                  | _        d| _        t=               | _        y c c}w c c}w )N#ATTRIBUTES_EXCLUDED_FROM_OBJECT_DEF)auxiliary_classz!Attributes '%s' non in definition, %s for <%s>F) r   lower
connectionget_operational_attributes_deferred_bind_deferred_open_fire_deferred
isinstancer   r   closedbindr   serverschema
definition_attributesappendjoinr&   r'   r%   r   setname
attributescontrolsexecution_timeentries_do_not_resetlist_operation_history)selfrM   
object_defrN   r]   r^   rI   v(conf_attributes_excluded_from_object_defnot_defined_attributes	attributeerror_messageattrs                r7   __init__zCursor.__init__L   s   G[  ]B  HC  4D!AGGI  4D0  4D$*D'$$
(A(A%%'j<"@A  !":z/@/@/G/GYhiJ$%'"*l3(\
' =	DOO$?$??IOODU  ^F  EF*11)<= & E		RhHi iu%}mTB%m44-7#j/SX\XgXgAhPT$))Ah=i "oo,,33""&&A 4D4 Bis   G%5G*c                 
   d| j                   j                  z   t        z   }|dt        | j                        z   t        z   z  }|ddj                  | j                  j                        z   z  }| j                  j                  r.|ddj                  | j                  j                        z   dz   z  }|t        z  }t        | d      r<|dt        t        | j                              z   | j                  rd	nd
z   t        z   z  }t        | t              r/t        | d      r3|dt        | j                         z   | j"                  rdndz   t        z   z  }t        | d      rO| j$                  rC|dt        | j$                        z   d| j$                  v rd
n| j&                  rdndz   t        z   z  }t        | d      rO| j(                  rC|dt        | j(                        z   d| j$                  v rd
n| j&                  rdndz   t        z   z  }t        | d      r.| j*                  r"|dt        | j*                        z   t        z   z  }t        | d      rc| j,                  rW|dt        t/        | j0                              z   z  }|dt        | j,                  j3                               z   dz   t        z   z  }| j4                  r|dt        t/        | j6                              z   dz   t/        | j6                        dkD  rdnd
z   dz   t/        | j6                        dkD  rd nd!z   dj                  t9        | j:                        D cg c]'  \  }}|j<                  d"   t>        k7  st        |      ) c}}      z   dz   z  }|S c c}}w )#Nz	CURSOR : z	CONN   : z	DEFS   : rJ   z [AUX: ]r]   z	ATTRS  : z [OPERATIONAL] basez	BASE   : z [SUB]z [LEVEL]_queryz	QUERY  : (z [AND]z [OR]validated_queryz	PARSED : query_filterz	FILTER : r_   z	ENTRIES: z [executed at: zLAST OPERATION FAILED [z failurer	   sz at operationzs  r1   ) 	__class____name__r   strrM   rZ   rW   _object_class_auxiliary_classhasattrreprsortedr]   rN   rR   Readerrp   sub_treerq   components_in_andrs   rt   r_   lenr`   	isoformatfailederrors	enumerate
operationsr1   r    )rd   rierrors       r7   __repr__zCursor.__repr__o   s   $..111G;	[3t//'99	[499T__%B%BCCC??++TYYt'G'GHH3NNA	W 4&tF4??$;<<TXTsTs@Py{|  @G  G  GAdF#tV$[4		?2$--hU_`cjjjtX&4;;[4#44cT[[>PcgcycyW_  @G  I  LS  S  St./D4H4H[4(<(<#==sdkkGYlp  mC  mC`h  IP  R  U\  \  \t^,1B1B[4(9(9#::WDD4)*t/B/Bs3t||#4555A"S)<)<)F)F)H%IICORYYYA;;*ST[[1A-BBZOZ]^b^i^iZjmnZnSVtvw  {J  J  VY  Z^  Ze  Ze  Vf  ij  Vj  NR  ps  t  w{  w@  w@  Yb  cg  cr  cr  Ys  A`  MU  MN  PU  w|  wC  wC  DL  wM  Q_  w_  BE  FG  BH  A`  wa  a  dg  g  gA A`s   M?!M?c                 "    | j                         S N)r   rd   s    r7   __str__zCursor.__str__   s    }}r9   c                 6    | j                   j                         S r   )r`   __iter__r   s    r7   r   zCursor.__iter__   s    ||$$&&r9   c                     	 | j                   |   S # t        $ r Y nw xY wt        |t              r| j	                  |      }t        |      dk(  r|d   S t        |      dkD  rdt        |      z  t        |      dkD  rdn4ddj                  |D cg c]  }|j                   nc c}w c}      z   dz   z   }t        t              rt        t        d	||        t        |      d
}t        t              rt        t        d	||        t        |      )aP  Return indexed item, if index is not found then try to sequentially search in DN of entries.
        If only one entry is found return it else raise a KeyError exception. The exception message
        includes the number of entries that matches, if less than 10 entries match then show the DNs
        in the exception message.
        r	   r   z7Multiple entries found: %d entries match the text in dn
   ro   z [z; rn   rK   zno entry found)r`   	TypeErrorrR   r   match_dnr   rZ   entry_dnr&   r'   r%   KeyError)rd   itemfounderj   s        r7   __getitem__zCursor.__getitem__   sB   	<<%% 		 dL)MM$'E5zQQxUa Y\_`e\f fpstypz}pjl  GK  NR  NW  NW  mr  Xs  hi  YZ  Yc  Yc  Xs  Xs  Nt  Gt  wz  Gz  !|u%}mTB}--(u}mT:}%%s    	B#c                 ,    t        | j                        S r   )r   r`   r   s    r7   __len__zCursor.__len__   s    4<<  r9   c                      yNTr5   r   s    r7   __bool__zCursor.__bool__       r9   c                      yr   r5   r   s    r7   __nonzero__zCursor.__nonzero__   r   r9   c                 	   t        d      }t        d      D cg c]  }|j                          }}t               }t               }|D ]  }	||	   }
d}|d   D ]1  }|
j                  j                         |j                         k(  s/|} n |s|
j
                  t        usY| j                  |
||       }||_        |r|d   |   nd|_	        |
j                  rI|
j                  |d   v r8|d   t               k7  r(|
j                  |
j                  |d   |         |_        nm|
j
                  t        u s|r!|d   |   t               k7  r|d   |   |_        n8t        |
j
                  t              r|
j
                  n|
j
                  g|_        t        |j                  t              s|j                  g|_        |
j                   r|j                  rt#        | j$                  |
j                   d| j&                  | j(                        }g }|j                  D ]  }|j*                  |k7  r!|j-                  |j/                  |             3d|j*                  d	|j0                  j                  d
}t3        t4              rt7        t4        d||        t9        |       ~||_        |||j                  <   |j:                  r&|j=                  |j                  |j:                         |
j:                  r&|j=                  |j                  |
j:                         |j?                  |        | j@                  r|jC                  | j@                         |d   D ]]  }||vs	d}|| jD                  jF                  v rZ| jD                  jF                  |   jH                  s4| jD                  jF                  |   jJ                  tL        tN        tP        fv rd}nd}|sz||vrv|j                         |vrdd|ddjS                  |jT                  jV                        d|j*                  }t3        t4              rt7        t4        d||        tY        |      t[        t]        ||z         ||       }|d   |   |_	        t        |d   |   t              r|d   |   n|d   |   g|_        ||z   |vsV||||z   <   ` |S c c}w )a  Assign the result of the LDAP query to the Entry object dictionary.

        If the optional 'post_query' callable is present in the AttrDef it is called with each value of the attribute and the callable result is stored in the attribute.

        Returns the default value for missing attributes.
        If the 'dereference_dn' in AttrDef is a ObjectDef then the attribute values are treated as distinguished name and the relevant entry is retrieved and stored in the attribute value.

        (ABSTRACTION_OPERATIONAL_ATTRIBUTE_PREFIXrH   Nr]   raw_attributesro   )rp   rN   r^   zobject z is referencing itself in the 'z' attributerK   FTzattribute 'z' not in object class 'rJ   z' for entry )/r   rL   r!   r[   r\   defaultNotImplementedattribute_classr2   
raw_values
post_queryrb   keyvaluesrR   r   dereference_dnr   rM   rN   r^   r   rY   search_objectrW   r&   r'   r%   r   other_names	set_aliasaddr]   updaterV   attribute_typesno_user_modificationusager+   r,   r-   rZ   entry_definitionrz   r   r   r   )rd   r2   	attr_defsentry!conf_operational_attribute_prefixrf   rg   r]   used_attribute_namesrk   attr_defattribute_name	attr_nameri   temp_readertemp_valueselementrj   operational_attributes                      r7   _get_attributeszCursor._get_attributes   sP    -AAk,l)G[  ]B  HC  4D!AGGI  4D0  4D13
"u (	9D H!N%l3 	==&&(IOO,==%.N
 !1!1!G 005$G	%-	"Ucx0@'A.'Qim	$&&8==H\<R+RW_`pWquyu{W{'/':':8<<R^I_`nIo'pI$''>9nQYZjQklzQ{  @D  @F  RF+3L+A.+Q	(?I(JZJZ\j?k8+;+;rz  sC  sC  rD	(!)"2"2D9(1(8(8'9I$** ''&,T__h>U>U\^{  |[  |[  fj  fs  fs  't&('0'7'7 PG$~~8 + 2 2;3L3LW3U V  9 nsm{m{  ~G  ~R  ~R  ~W  ~W  1X#.u#5$'}mT$R&@&O OP (+6	(,5
9==)((((	8M8MN''((8L8LM$((8Q(	9T ?? ''8&|4 	_N%99(-%!T[[%@%@@{{22>BWW[_[f[f[v[v  xF  \G  \M  \M  Ro  qP  Ri  Qj  \j04-,0),y1PUcUiUiUk  t\  V\bprvr{r{  }B  }S  }S  }a  }a  sb  di  dr  dr  %sM"5)E=-F)-8809Z]k9k1lnsuyz	'/0@'A.'Q	$MWX`amXno}X~  AO  NP8L#9.#I  W_  `l  Wm  n|  W}  V~	 5FzYU^J@>QR%	_( I 4Ds   R=c                     g }| j                   D ]>  }|j                         |j                  j                         v s.|j                  |       @ |S )zReturn entries with text in DN)r`   rL   r   rY   )rd   dnmatchedr   s       r7   r   zCursor.match_dn  sH    \\ 	&ExxzU^^1133u%	& r9   c                 x   g }t        |t              s|g}| j                  D ]  }d}|D ]	  }||v s	||   j                  D ]Y  }t	        |d      r/t	        |d      r#|j                         |j                         v rd}n||k(  rd}|sH|j                  |        n |r t        |      }t        |t        t        f      s||   j                  D ]Y  }t	        |d      r/t	        |d      r#|j                         |j                         v rd}n||k(  rd}|sH|j                  |        n |s	   |S )z;Return entries with text in one of the specified attributesFrL   T)rR   r   r`   r   r|   rL   rY   r$   bytes	bytearrayr   )	rd   r]   r6   r   r   r   ri   
attr_value	raw_values	            r7   matchzCursor.match  s_   *n5$J\\ 	"EE' "	%&+I&6&=&= "
":w7GE7<SX]XcXcXeisiyiyi{X{$(E"j0$(E #NN51!"  &uI!)eY-?@*/	*:*E*E &J&z7;	SZ@[`i`o`o`qu  vF  vF  vH  aH(,!*j!8(,$ 'u 5 %& !!1"	"6 r9   c                    |d   dk(  sy | j                  |d   |       }| j                  || j                  j                  |      |j                  _        t        |d         |j                  _        ||j                  _        t        j                         |j                  _        |j                  j                  | j                         |D ]  }||j                  |j                  <    |S )NtypesearchResEntryr   r   )entry_classr   rW   rX   _stater]   r   r   r2   r   now	read_time
set_statusentry_initial_status__dict__r   )rd   r2   r   rk   s       r7   _create_entryzCursor._create_entry6  s    #33  $6"&"6"6xA\A\^c"d&.x8H/I&J# (!) 9 9: 	,D'+ENN488$	, r9   c           
      B   | j                   s.d}t        t              rt        t        d||        t	        |      d }|t
        k(  r t        | d      r| j                  }d| _        n| j                          t        t              r(t        t        d| j                  | j                  ||        | j                   5  | j                   j                  | j                  | j                  || j                  |r|nt        | j                        | j                  | j                         }| j                   j"                  j$                  s"| j                   j'                  |d      \  }}}nj| j                   j"                  j(                  r|\  }}}}n,| j                   j*                  }| j                   j,                  }| j                   j.                  }d d d        | j1                         | j2                  r| j5                  |d	         S g | _        |D ]  }	| j5                  |	      }
|
| j6                  j9                  |
       d
|
v s7|
j:                  D ]  }| j<                  s| j<                  j>                  |   j@                  tB        k(  s;|| jD                  jF                  vsT| jD                  jF                  j9                  |       | jD                  jI                  |         tK        jL                         | _'        |r|| _        y y # 1 sw Y   ExY w)Nno connection establishedrK   rt   (objectclass=*)z<executing query - base: %s - filter: %s - scope: %s for <%s>search_basesearch_filtersearch_scopedereference_aliasesr]   rN   r^   Tget_requestr   objectClass)(rM   r&   r'   r%   r   r   r|   rt   _create_query_filterr)   rp   searchr   rb   r]   rN   r^   strategysyncget_responsethread_safer2   r1   r0   _store_operation_in_historyra   r   r`   rY   r   rV   object_classeskindr.   rW   r{   _populate_attr_defsr   r   r_   )rd   query_scoper]   rj   old_query_filterr1   r2   r0   _r   r   object_classs               r7   _execute_queryzCursor._execute_queryF  s   7M5!E=->!-00$t^,#'#4#4  1D%%'x XZ^ZcZceievev  yD  FJ  K__ 	2__++		:>:K:K9D@D@X@XEOzUYZ^ZiZiUjGKGfGf59]] , DF ??++00,0OO,H,H]a,H,b)&'??++77-3*Avx#77H!__33F//11!	2$ 	((&(C%%hqk22 		NA&&q)E ##E* E)(-(9(9 N;;4;;+E+El+S+X+X\k+kp|  EI  ET  ET  Ee  Ee  qe OO<<CCLQ OO??M	N		N 'lln 0D I	2 	2s   9DLLc                 |    t        t              rt        t        d||        | j                  j	                  |       y )Nzremoving entry <%s> in <%s>)r&   r)   r%   r`   removerd   r   s     r7   r   zCursor.remove|  s+    x 7EE"r9   c                 "    t               | _        y r   )rb   rc   r   s    r7   _reset_historyzCursor._reset_history  s    "&&r9   c                 P    | j                   j                  t        |||             y r   )rc   rY   r/   )rd   r0   r1   r2   s       r7   r   z"Cursor._store_operation_in_history  s    &&y&('KLr9   c                     | j                   S r   )rc   r   s    r7   r   zCursor.operations      &&&r9   c                 n    | j                   D cg c]  }|j                  d   t        k7  s| c}S c c}w )Nr1   )rc   r1   r    rd   r   s     r7   r   zCursor.errors  s-    #'#:#:g%ell8>TXf>fgggs   22c                     t        | d      r7t        | j                  D cg c]  }|j                  d   t        k7   c}      S y c c}w )Nrc   r1   )r|   anyrc   r1   r    r   s     r7   r   zCursor.failed  s?    4-.dNeNefUX..@fgg /fs   AFNNN)rx   
__module____qualname__rl   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r5   r9   r7   rF   rF   E   s    !)FB'&6! %		N`!F 41l#
)M ' ' h h h hr9   rF   c                       e Zd ZdZeZeZeZ	ddZ
ed        Zej                  d        Zed        Zej                  d        Zd Zd	 Zd
 Zd ZddZddZddZddZd ZddZy)r   aq  Reader object to perform searches:

    :param connection: the LDAP connection object to use
    :type connection: LDAPConnection
    :param object_def: the ObjectDef of the LDAP object returned
    :type object_def: ObjectDef
    :param query: the simplified query (will be transformed in an LDAP filter)
    :type query: str
    :param base: starting base of the search
    :type base: str
    :param components_in_and: specify if assertions in the query must all be satisfied or not (AND/OR)
    :type components_in_and: bool
    :param sub_tree: specify if the search must be performed ad Single Level (False) or Whole SubTree (True)
    :type sub_tree: bool
    :param get_operational_attributes: specify if operational attributes are returned or not
    :type get_operational_attributes: bool
    :param controls: controls to be used in search
    :type controls: tuple

    Nc           	      B   t         j                  | |||||	|
       || _        || _        || _        || _        t        | _        d | _        t               | _
        t               | _        d | _        | j                          t        t              rt!        t        d|        y y )Nz instantiated Reader Cursor: <%r>)rF   rl   _components_in_andr   rq   rp   r   r   rs   r=   _query_dict_validated_query_dictrt   resetr&   r(   r%   )rd   rM   re   rp   queryr   r   rN   r]   r^   rI   s              r7   rl   zReader.__init__  s    j*6PR\^fhwx"3 	#/ #6%)V" 

u94@ r9   c                     | j                   S r   )rq   r   s    r7   r  zReader.query  s    {{r9   c                 2    || _         | j                          y r   )rq   r  rd   r6   s     r7   r  zReader.query  s    

r9   c                     | j                   S r   )r  r   s    r7   r   zReader.components_in_and  r   r9   c                 2    || _         | j                          y r   )r  r  r  s     r7   r   zReader.components_in_and  s    "'

r9   c                 :    t         | _        | j                          y)z,Clear the Reader search parameters

        N)r   r   r   r   s    r7   clearzReader.clear  s     $0 r9   c                     | j                          d| _        t               | _        t               | _        d| _        d| _        g | _        | j                          y)z)Clear all the Reader parameters

        N)	r  rs   r=   r  r  r_   rt   r`   r   r   s    r7   r  zReader.reset  sL     	

#6%)V"" !!#r9   c                 r   | j                   st        | j                        | _         d}t        | j                         D ]R  }|d   dv r|dd n|}| j                  D ]X  }dj                  |j                               j                         |j                  j                         k(  sL|j                  } n || j                  v rt        | j                   |   j                  d            }||d   dv r|d   |z   n|dz   z  }|D ]N  }|j                         }|d   dk(  rd	nd
}d}|rY|dd j                         d   dvr|dd j                         }	n]|dd j                         d   }|dd j                         dd }	n0|d   dvr|j                         }	n|d   }|dd j                         }	| j                  |   j                  r\| j                  |   j                  |	      }
|
d
u r4d|d|}t        t              rt        t        d||        t        |      |
d	ur|
}	|r|d|z   t!        |	      z   z  }n||t!        |	      z   z  }|dz  }Q |dd dz   }$d|z  }t        t              rt        t        d||        t        |       |dd | _        t        | j"                        | _        y)zProcesses the text query and verifies that the requested friendly names are in the Reader dictionary
        If the AttrDef has a 'validate' property the callable is executed and if it returns False an Exception is raised

        ro   r   &|r	   N;z: !TFr4   z=<>~z validation failed for attribute z and value rK   rJ   z attribute '%s' not in definition)r  rD   rq   r~   rW   rZ   r>   rL   r   r?   lstripvalidater&   r'   r%   r   ry   rs   r  )rd   r  drk   r   valsvalval_notval_search_operatorr6   	validatedrj   s               r7   _validate_queryzReader._validate_query  s   
 1$++>D(() /	5AaDDL1QR5aD OO 774::<(..0HLL4F4F4HH#<<D t&d..q177<=1!A$+44GG !C))+C&)!fmdG*-'qr7>>+A.f<$'GNN$4E25ab'..2B12E/$'GNN$4QR$8Eq6/$'JJLE25a&/$'GNN$4Et,55$(OOD$9$B$B5$I	$-abdg,hM*51 #E=- N"1-"@@&d2(1':!:SZ!GG!4s5z!AASLE?!@ cr
T) Dt Ku%}mTB%m44_/	5`  %Sbz%78L8L%M"r9   c                 2	   d| _         | j                  j                  rA| xj                   dz  c_         t        | j                  j                  t              rUt        | j                  j                        dk(  r3| xj                   d| j                  j                  d   z   dz   z  c_         nt        | j                  j                  t              ra| xj                   dz  c_         | j                  j                  D ]  }| xj                   d|z   dz   z  c_          | xj                   dz  c_         n.d}t        t              rt        t        d||        t        |      | j                  r| j                  j                  d	      rl| j                  j                  d      rQd
| j                  j                         vr#| xj                   | j                  dz   z  c_         y| j                  | _         y| j                  r| j                  s| xj                   dz  c_         n+| j                  j                  s| xj                   dz  c_         | j                          d}t!        | j"                        D ]  }|dz  }d| j"                  |   v rdnd}t!        | j"                  |   j%                  d            }|d   dv r| j                  |dd    n| j                  |   }|j&                  r?g }|D ]6  }	|j)                  |	d   |j'                  |j*                  |	dd       z          8 |}|r8|d   dv r| xj                   d	|d   z   z  c_         n| xj                   dz  c_         |D ]p  }	|	d   dk(  r5| xj                   d|j,                  z   t/        |	dd       z   dz   z  c_         @| xj                   d	|j,                  z   t/        |	      z   dz   z  c_         r |sk| xj                   dz  c_          | j                  s| xj                   dz  c_         n| xj                   dz  c_         | j                  j                  s|dk(  r| j                   dd | _         | j                   dk(  s| j                   dk(  rd| _         yy| j                   dd | _         y)z0Converts the query dictionary to the filter textro   z(&r	   z(objectClass=r   )z'object class must be a string or a listrK   rr   objectclassNz(|r  TFr  r  z(!(z))r   r  z(|)z(&))rt   rW   rz   rR   r   r   r&   r'   r%   r   rq   
startswithendswithrL   r   r  r~   r  r>   	pre_queryrY   r   r\   r8   )
rd   r   rj   attr_counterrk   multir  r   modvalsr  s
             r7   r   zReader._create_query_filter   s   ??((%$//77HSQUQ`Q`QnQnMostMt!!_t7T7TUV7W%WZ]%]]!DOO99>J!!T)!$(OO$A$A NL%%<)G#)MM%N!!S(! Iu%}mTB%m44;;4;;11#64;;;O;OPS;TDKK$5$5$77!!T[[3%66!  %)KK![[))!!T)!__22!!T)!  "Lt99: -! #t'A'A$'G GUd88>DDSIJ8<Q44??484T__]aMb%% G# [s1v0B0B8<<QTUVUWQX0Y'YZ["DAw$))S47]:)))T1) `C1v}))UX]]-BEVWZ[\[]W^E_-_bf-ff)))S8==-@CTUXCY-Y\_-__)	`
 %%,%--0 ))!!T)!!!S(!??00\Q5F$($5$5a$<!  E)T->->%-G$&! .H !% 1 1!" 5Dr9   c                     | j                          | j                  rt        nt        }t	        t
              rt        t
        d|        | j                  ||       | j                  S )zKPerform the LDAP search

        :return: Entries found in search

        zperforming search in <%s>)	r  r   r   r   r&   r)   r%   r   r`   )rd   r]   r   s      r7   r   zReader.searchg  sI     	

!%gEx 5t<K4||r9   c                 F   t        t              rt        t        d|        | j                          |r1| j                  }|| _        | j                  t        |       || _        n| j                  t        |       t        | j                        dkD  r| j                  d   S dS )zgPerform the LDAP search operation SINGLE_OBJECT scope

        :return: Entry found in search

        z performing object search in <%s>r   N)	r&   r)   r%   r  rp   r   r   r   r`   )rd   r   r]   old_bases       r7   r   zReader.search_objectu  s     x <dC

yyH DIj1 DIj1"%dll"3a"7t||AATAr9   c                     t        t              rt        t        d|        | j                          | j	                  t
        |       | j                  S )zmPerform the LDAP search operation with SINGLE_LEVEL scope

        :return: Entries found in search

        z&performing single level search in <%s>)r&   r)   r%   r  r   r   r`   rd   r]   s     r7   search_levelzReader.search_level  s<     x BDI

E:.||r9   c                     t        t              rt        t        d|        | j                          | j	                  t
        |       | j                  S )ziPerform the LDAP search operation WHOLE_SUBTREE scope

        :return: Entries found in search

        z'performing whole subtree search in <%s>)r&   r)   r%   r  r   r   r`   r-  s     r7   search_subtreezReader.search_subtree  s<     x CTJ

GZ0||r9   c              #   @   K   |D ]  }| j                  |        y wr   )r   )rd   	responsesr2   s      r7   _entries_generatorzReader._entries_generator  s&     ! 	/H$$X..	/s   c                    t        t              rt        t        d| t        |             | j                  s.d}t        t
              rt        t
        d||        t        |      | j                          | j                          g | _	        t        j                         | _        | j                  j                  j                  j                  | j                   | j"                  | j$                  rt&        nt(        | j*                  |r|n| j,                  | j.                  | j0                  |||
      }|r| j3                  |      S t5        | j3                  |            S )a  Perform a paged search, can be called as an Iterator

        :param attributes: optional attributes to search
        :param paged_size: number of entries returned in each search
        :type paged_size: int
        :param paged_criticality: specify if server must not execute the search if it is not capable of paging searches
        :type paged_criticality: bool
        :param generator: if True the paged searches are executed while generating the entries,
                          if False all the paged searches are execute before returning the generator
        :type generator: bool
        :return: Entries found in search

        z2performing paged search in <%s> with paged size %sr   rK   )
r   r   r   r   r]   rN   r^   
paged_sizepaged_criticality	generator)r&   r)   r%   ry   rM   r'   r   r  r   r`   r   r   r_   extendstandardpaged_searchrp   rt   r   r   r   r   r]   rN   r^   r3  rb   )rd   r5  r6  r7  r]   rj   r2   s          r7   search_pagedzReader.search_paged  s    x NPTVYZdVef7M5!E=->!-00

!!#&lln??))22??DIINRN_N_X\XeXeWkpTXTlTlYc:imixix[_[z[zIMKURcJS @ 	U **844//9::r9   )ro   TTFNNNr   )NN)TTN)rx   r   r   __doc__r   r   r   r   r   r   rl   r  r  setterr   r  r  r  r   r   r   r.  r0  r3  r;  r5   r9   r7   r   r     s    ( KO&A    \\  ' '  $:NxE6NB&/';r9   r   c                   h    e Zd ZeZeZeZe	d
d       Z
e	dd       ZddZddZd ZddZd Zdd	Zy)WriterNc                    || j                   }|| j                  }t        ||| j                        }| j                  D ]y  }t        | t              r|j                  |||       (t        | t              r9dt        t        |             z  }t        t              rt        t        d|       t        |       | j                  |_        t        t              rt        t        d||        |S )N)r]   )custom_validatorzunknown cursor type %s%sz0instantiated Writer Cursor <%r> from cursor <%r>)rM   rW   r?  r]   r`   rR   r   entry_writablery   r   r&   r'   r%   r   r_   r(   )cursorrM   re   rA  writerr   rj   s          r7   from_cursorzWriter.from_cursor  s    **J**J
J6;L;LM^^ 		5E&&)$$ZJZ$[FF+ 83tF|;L Lu%t]3%m44		5 !' 5 5uI6SYZr9   c                    || j                   j                  s-d}t        t              rt	        t        d|       t        |      | j                  r| j                  }n-d}t        t              rt	        t        d|       t        |      t        | |      }|D ]7  }|d   dk(  s|j                  |      }|j                  j                  |       9 t        t              rt	        t        d|       |S )Nz7with asynchronous strategies response must be specifiedrB  zresponse not presentr   r   z-instantiated Writer Cursor <%r> from response)r   r   r&   r'   r%   r   r2   r?  r   r`   rY   r(   )rM   re   r2   rj   rE  respr   s          r7   from_responsezWriter.from_response  s    &&++ Yu%t]3%m44$$%.. 6u%t]3%m44
J/ 	-DF|//,,T2%%e,	- uFOr9   c           	          t         j                  | ||||||       t        | _        t	        t
              rt        t
        d|        y y )Nz instantiated Writer Cursor: <%r>)rF   rl   r   r   r&   r(   r%   )rd   rM   re   rN   r]   r^   rI   s          r7   rl   zWriter.__init__  s@    j*6PR\^fhwx#. u94@ r9   c                     t        t              rt        t        d|        | j                          d}| j                  D ]#  }|j                  || j                  d      r"d}% t        j                         | _	        |S )Nzcommitted changes for <%s>TF)refreshr^   clear_history)
r&   r)   r%   r   r`   entry_commit_changesr^   r   r   r_   )rd   rL  
successfulr   s       r7   commitzWriter.commit  sp    x 6=
\\ 	#E--gej-k"
	# 'llnr9   c                     t        t              rt        t        d|        | j                  D ]  }|j	                           y )Nzdiscarded changes for <%s>)r&   r)   r%   r`   entry_discard_changesr   s     r7   discardzWriter.discard  s6    x 6=\\ 	*E'')	*r9   c           
         t        t              rt        t        d||        | j                  s.d}t        t              rt        t        d||        t        |      g }| j                  5  d}||k  r%| j                  j                  |dt        t        |r|n| j                  | j                  |      }	| j                  j                  j                  s"| j                  j                  |	d      \  }}	}
nj| j                  j                  j                  r|	\  }}	}}
nB| j                  j                  }| j                  j                   }	| j                  j"                  }
|	d	   t$        fv rn*t'        |       |d
z  }| j)                  |
|	|       ||k  r%ddd       t+        |      d
k(  r| j-                  |d         S t+        |      dk(  ryd}t        t              rt        t        d||        t        |      # 1 sw Y   hxY w)zhPerforms the LDAP search operation SINGLE_OBJECT scope

        :return: Entry found in search

        zrefreshing object <%s> for <%s>r   rK   r   r   r   Tr   r1   r	   Nz5more than 1 entry returned for a single object search)r&   r)   r%   rM   r'   r   r   r   r   r]   rN   r   r   r   r   r2   r1   r0   r    r   r   r   r   )rd   r   r]   triessecondsr^   rj   r2   counterr1   r0   r   s               r7   _refresh_objectzWriter._refresh_object  s    x ;XtL7M5!E=->!-00__ 	LGE///H>O=ADOIS:Y]YhYhKOKjKj9A 0 C //44040L0LVae0L0f-Hfg//;;7=468W#'??#;#;!%!7!7"&//"9"9(#'77g100&(K- E/	L4 x=A%%hqk22]aOu}mT:m,,E	L 	Ls   *D,G??Hc                    t        t              rt        t        d||        t        |      }| j                  D ]?  }|j
                  |k(  sd}t        t              rt        t        d||        t        |       t        |d      }| j                  ||       }|j                  D ]i  }| j                  |j                  j                  |   ||       |j                  j                  |<   |j                  j                  |   |j                  |<   k |j                   j#                  | j                  j$                         |D ]+  }|d   |j                  j                  j&                  v r|j                  j                  j&                  |d      j(                  }||j                  j                  vrg| j                  |j                  j                  |   ||       |j                  j                  |<   |j                  j                  |   |j                  |<   |j                  |   j#                  |d          d|d   z  }t        t              rt        t        d||        t        |       |j                  j+                  t,               |j                  j+                  t.               | j                  j1                  |       |S )	Nz creating new entry <%s> for <%s>zdn already present in cursorrK   T)	decomposer   r	   z,rdn type '%s' not in object class definition)r&   r(   r%   r"   r`   r   r'   r   r#   r   entry_mandatory_attributesr   r   rW   r]   r   r"  r[   rz   rX   r\   r   r
   r   rY   )rd   r   r   rj   rdnsrk   rdnrdn_names           r7   newz
Writer.newQ  sN   u92tDR[\\ 	5E~~# >u%}mTB%m44	5 d+  T*44 	ED040D0DU\\E\E\]aEbdiko0p''-',||'>'>t'Dt$	E 	doo;;< 	5C1v00<<< <<22>>s1vFKK5<<#:#::8<8L8LU\\MdMdemMnpuw{8|ELL++H5/4||/F/Fx/PENN8,x(,,SV4 PSVWXSY Yu%}mTB%m44	5 	/ 67E"r9   c                 (   t        d      }d| _        g }t        t              rt	        t        d||        |j
                  j                  D ]  }|j                         j                  |j                               r1|j
                  j                  |   j                  r3|j                  |j
                  j                  |   j                         |j                  |j
                  j                  |   j                          | j                  |j                  |||      }d| _        |rc|j
                  j                  |j
                  _        |j                   j#                          |j
                  |j                   d<   |j
                  j                  D ](  }|j
                  j                  |   |j                   |<   * |j$                  D ]  }||j
                  j                  vs||j&                  j(                  v s5t+        |j&                  |   ||       |j
                  j                  |<   |j
                  j                  |   |j                   |<    |j
                  j-                  |j
                  j.                         yy)Nr   Tzrefreshing entry <%s> for <%s>)rV  Fr   )r   ra   r&   r)   r%   r   r]   rL   r#  rW   r\   rY   r   rX  r   originr   r  entry_attributesr   rX   r   r   _initial_status)rd   r   rU  rV  r   	attr_listrk   
temp_entrys           r7   refresh_entryzWriter.refresh_entryr  s   ,@Ak,l)!	x :E4HLL++ 	DDzz|&&'H'N'N'PQ||&&t,11  !8!8!>!C!CD  !8!8!>!B!BC	D ))%..)UT[)\
"',||':':J$NN  "'1'8'8ENN8$// E',||'>'>t'Dt$E .. Iu||66645CYCYCeCe;e4EeF\F\]aFbdiko4pELL++D1+0<<+B+B4+HENN4(I LL##ELL$@$@Ar9   )NNNr   r   )T)N   r   N)rg  r   )rx   r   r   r   r   r   r   r   r   staticmethodrF  rI  rl   rP  rS  rX  r_  rf  r5   r9   r7   r?  r?    sY    K'O* *  0A*1-fBr9   r?  N)Cr<  collectionsr   copyr   r   osr   timer   ro   r
   r   r   r   r   r   r   r   r   r   r   abstractr   ri   r   r   r   attrDefr   	objectDefr   r   r   r   core.exceptionsr   r   core.resultsr    utils.ciDictr!   utils.dnr"   r#   
utils.convr$   utils.config	utils.logr%   r&   r'   r(   r)   r*   protocol.oidr+   r,   r-   r.   r/   r8   rD   objectrF   r   r?  r5   r9   r7   <module>ry     s   0 #     : : r r r - I I    ' I ) 7 (  / J J D  D{$EF	ZMhV Mh`
x;V x;v	@V @r9   