
    qZhѠ                     8   d Z ddlmZ ddlmZmZmZ g dZ	 ddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlmZ ddlmZmZmZ dd	lmZmZmZ dd
lmZ  G d de          Z G d dej                  Z G d d          Z  G d de           Z!e Z"dS )z]
ldapobject.py - wraps class _ldap.LDAPObject

See https://www.python-ldap.org/ for details.
    )strerror)__version__
__author____license__)
LDAPObjectSimpleLDAPObjectReconnectLDAPObjectLDAPBytesWarningTN)SCHEMA_ATTRS)LDAPControlDecodeControlTuplesRequestControlTuples)ExtendedRequestExtendedResponsePasswordModifyResponse)	LDAPErrorc                   "     e Zd ZdZ fdZ xZS )r
   zPython 2 bytes mode warningc                 n    t          j        dt                      t                      j        |i | d S )Nz@LDAPBytesWarning is deprecated and will be removed in the future)warningswarnDeprecationWarningsuper__init__)selfargskwargs	__class__s      [/var/www/lab.imftr.de/alumni/alumnizer_venv/lib/python3.11/site-packages/ldap/ldapobject.pyr   zLDAPBytesWarning.__init__#   sA    N	
 	
 	
 	$)&)))))    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r
   r
       s>        %%* * * * * * * * *r   r
   c                       e Zd ZdZdS )NO_UNIQUE_ENTRYz
  Exception raised if a LDAP search returned more than entry entry
  although assumed to return a unique single search result.
  N)r    r!   r"   r#    r   r   r&   r&   +   s           r   r&   c            
       v   e Zd ZdZej        ej        ej        ej        ej	        ej
        ej        ej        ej        d	Z	 	 dOdZed             Zed             ZdPd
Zd Zd Zd Zd ZdQdZd ZdQdZdQdZdQdZdQdZd Zd ZdRdZ dRdZ!ej"        fdZ#ej"        fdZ$ddej%        fdZ&ddej%        d	fdZ'ddej%        d	fdZ(ddej%        d	fdZ)dQdZ*dQd Z+dQd!Z,d" Z-d# Z.dQd$Z/dQd%Z0d& Z1d' Z2dQd(Z3ej4        d)dfd*Z5dSd+Z6dQd,Z7dQd-Z8d. Z9d/ Z:dTd0Z;dTd1Z<dQd2Z=dUd4Z>dVd5Z?dVd6Z@ej4        d)dfd7ZAej4        d)dfd8ZBej4        d)ddfd9ZCej4        d)dddddfd:ZDdWd<ZEdWd=ZFdXd>ZGdXd?ZHdYd@ZIdA ZJdQdBZKdQdCZLdD ZMdE ZNdQdFZOdG ZPdH ZQdZdIZRd[dJZSdZdKZTejU        dddddd;fdLZVdQdMZWdN ZXdS )\r   z
  This basic class wraps all methods of the underlying C API object.

  The arguments are same as for the :func:`~ldap.initialize()` function.
  )	protocol_versionderef	referrals	timelimit	sizelimitnetwork_timeouterror_numbererror_string
matched_dnr   N   c                 t   |pt           j        | _        |pt           j        | _        || _        || _        |                     d          | _        |t          t          d          st          d          t          |d          r|
                                }t           j                            t           j        t          j        ||          | _        n:t           j                            t           j        t          j        |          | _        d| _        t           j        | _        |rt          d          d S )Nopcallinitialize_fdz&libldap does not support initialize_fdfilenoz-bytes_mode is *not* supported under Python 3.)ldap_trace_level_trace_file_trace_stack_limit_uri
_ldap_lock_ldap_object_lockhasattr_ldap
ValueErrorr6   	functions_ldap_function_call_ldap_module_lockr5   _l
initializetimeoutVERSION3r)   )r   uritrace_level
trace_filetrace_stack_limit
bytes_modebytes_strictnessr6   s           r   r   zSimpleLDAPObject.__init__E   s   
 $8t'8D!5T%5D/DDI!__X66DUO,, CABBB		"	" !22 3VS dgg 2243I%JZ[^__dgDL MD JHIIIJ Jr   c                     dS )NFr'   r   s    r   rM   zSimpleLDAPObject.bytes_mode_   s    5r   c                     dS )Nerrorr'   rP   s    r   rN   z!SimpleLDAPObject.bytes_strictnessc   s    7r    c                     t           j        r't          j        |dt          |                     S t           j        S )Nz within desc)r8   	LIBLDAP_RLDAPLockreprrD   )r   rV   s     r   r=   zSimpleLDAPObject._ldap_lockg   s9    ~ $]d4jjj ABBBB##r   c                    | j                                          	 | j        dk    r| j                            d                    t          |           | j        d                    | j	        j
        |j
        f          t          j        ||f                               | j        dk    r t          j        | j        | j                   d}	 	  ||i |}| j        dk    r/|j
        d	k    r$| j                            t$          j                  }| j                                          n# | j                                          w xY w	 | j        dk    r[|*| j                            d
t          |          z             | j                            dt          j        |          z             n# t*          $ r}	 d|j        d         vr=d|j        d         v r.t/          |j        d         d                   |j        d         d<   n# t0          $ r Y nw xY w| j        dk    rE| j                            d                    |j	        j
        t3          |                                d}~ww xY w|S )z[
    Wrapper method mainly for serializing calls into OpenLDAP libs
    and trace logs
    T   z*** {} {} - {}
{}
.	   )limitfileN   
unbind_extz=> diagnosticMessage: %s
z=> result:
%s
infor   errnoz=> LDAPError - {}: {}
)r>   acquirer9   r:   writeformatrY   r<   joinr   r    pprintpformat	tracebackprint_stackr;   rE   
get_optionr8   OPT_DIAGNOSTIC_MESSAGEreleaser   r   r   
IndexErrorstr)r   funcr   r   diagnostic_message_successresultes          r   
_ldap_callzSimpleLDAPObject._ldap_callm   s   
 	""$$$	U		A		5<<
t**
)
((DN+DM:
;
;
.$v
'
'	 
  
 	 	 	 a

d&=4CS
T
T
T
T!%N)t%f%%*A--]L(()-););D<W)X)X&&&((((&&((((( (!++)1


 
 !=F`AaAa!b
c
c
c1V^F5K5KLMMM    ""w!&)';';&qvay'9::!&)F
   (!++8??@TUXYZU[U[\\]]] MsK   AD+ F1 +EF1 1
I/<AH	I*	
HI*HAI**I/c                 r    || j         v r#|                     | j         |         |           d S || j        |<   d S N)CLASSATTR_OPTION_MAPPING
set_option__dict__)r   namevalues      r   __setattr__zSimpleLDAPObject.__setattr__   sD    t,,,
ood3D9%@@@@@!dmDr   c                     || j         v r |                     | j         |                   S || j        v r| j        |         S t          d                    | j        j        t          |                              )Nz{} has no attribute {})rx   rl   rz   AttributeErrorrf   r   r    rY   r   r{   s     r   __getattr__zSimpleLDAPObject.__getattr__   sy    t,,,__T:4@AAA			]4  3::T

  	 	 	r   c                 @    |                      t          j                  S )z
    Returns file description of LDAP connection.

    Just a convenience wrapper for LDAPObject.get_option(ldap.OPT_DESC)
    )rl   r8   OPT_DESCrP   s    r   r6   zSimpleLDAPObject.fileno   s     ??4=)))r   c                 z    |                      | j        j        |t          |          t          |                    S )a  
    abandon_ext(msgid[,serverctrls=None[,clientctrls=None]]) -> None
    abandon(msgid) -> None
        Abandons or cancels an LDAP operation in progress. The msgid should
        be the message id of an outstanding LDAP operation as returned
        by the asynchronous methods search(), modify() etc.  The caller
        can expect that the result of an abandoned operation will not be
        returned from a future call to result().
    )ru   rE   abandon_extr   )r   msgidserverctrlsclientctrlss       r   r   zSimpleLDAPObject.abandon_ext   s4     ??47.u5I+5V5VWklwWxWxyyyr   c                 0    |                      |d d           S rw   )r   )r   r   s     r   abandonzSimpleLDAPObject.abandon   s    E$t,,,r   c                 z    |                      | j        j        |t          |          t          |                    S )aQ  
    cancel(cancelid[,serverctrls=None[,clientctrls=None]]) -> int
        Send cancels extended operation for an LDAP operation specified by cancelid.
        The cancelid should be the message id of an outstanding LDAP operation as returned
        by the asynchronous methods search(), modify() etc.  The caller
        can expect that the result of an abandoned operation will not be
        returned from a future call to result().
        In opposite to abandon() this extended operation gets an result from
        the server and thus should be preferred if the server supports it.
    )ru   rE   cancelr   )r   cancelidr   r   s       r   r   zSimpleLDAPObject.cancel   s3     ??47>(3G3T3TUijuUvUvwwwr   c                     |                      |||          }	 |                     |d| j                  }n## t          j        t          j        f$ r d }Y nw xY w|S Nr[   allrG   )r   rs   rG   r8   	CANCELLEDSUCCESS)r   r   r   r   r   ress         r   cancel_szSimpleLDAPObject.cancel_s   si    KK[99EKK!DLK99ccN4<(   cccJs   7 AAc           	      |    |                      | j        j        ||t          |          t          |                    S )a\  
    add_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
        This function adds a new entry with a distinguished name
        specified by dn which means it must not already exist.
        The parameter modlist is similar to the one passed to modify(),
        except that no operation integer need be included in the tuples.
    )ru   rE   add_extr   r   dnmodlistr   r   s        r   r   zSimpleLDAPObject.add_ext   s5     ??47?2g6J;6W6WXlmxXyXyzzzr   c                     |                      ||||          }|                     |d| j                  \  }}}}	||||	fS r   )r   result3rG   
r   r   r   r   r   r   	resp_type	resp_data
resp_msgid
resp_ctrlss
             r   	add_ext_szSimpleLDAPObject.add_ext_s   sL    LLGK<<E37<<!TXT`<3a3a0Iy*jiZ77r   c                 2    |                      ||dd          S )a2  
    add(dn, modlist) -> int
        This function adds a new entry with a distinguished name
        specified by dn which means it must not already exist.
        The parameter modlist is similar to the one passed to modify(),
        except that no operation integer need be included in the tuples.
    N)r   r   r   r   s      r   addzSimpleLDAPObject.add   s     <<74---r   c                 2    |                      ||d d           S rw   )r   r   s      r   add_szSimpleLDAPObject.add_s   s    >>"WT$///r   c           	      |    |                      | j        j        ||t          |          t          |                    S )z1
    simple_bind([who='' [,cred='']]) -> int
    )ru   rE   simple_bindr   )r   whocredr   r   s        r   r   zSimpleLDAPObject.simple_bind   s6     ??47.s48L[8Y8YZnozZ{Z{|||r   c                     |                      ||||          }|                     |d| j                  \  }}}}	||||	fS )z7
    simple_bind_s([who='' [,cred='']]) -> 4-tuple
    r[   r   )r   r   rG   )
r   r   r   r   r   r   r   r   r   r   s
             r   simple_bind_szSimpleLDAPObject.simple_bind_s   sP     Sk+>>E37<<!TXT`<3a3a0Iy*jiZ77r   c                 b    |t           j        k    s
J d            |                     ||          S )z(
    bind(who, cred, method) -> int
    z/Only simple bind supported in LDAPObject.bind())r8   AUTH_SIMPLEr   )r   r   r   methods       r   bindzSimpleLDAPObject.bind   s7     4####$U###C%%%r   c                 j    |                      |||          }|                     |d| j                  S )z+
    bind_s(who, cred, method) -> None
    r[   r   )r   rs   rG   )r   r   r   r   r   s        r   bind_szSimpleLDAPObject.bind_s  s3     IIc$v&&E;;u4<;888r   c           	      ~    |                      | j        j        ||t          |          t          |          |          S )zx
    sasl_interactive_bind_s(who, auth [,serverctrls=None[,clientctrls=None[,sasl_flags=ldap.SASL_QUIET]]]) -> None
    )ru   rE   sasl_interactive_bind_sr   )r   r   authr   r   
sasl_flagss         r   r   z(SimpleLDAPObject.sasl_interactive_bind_s
  sS     ??47:3tDXYdDeDefz  |G  gH  gH  IS  T  T  Tr   c                     t           j                            t           j        j        |i|          }|                     d||||           dS )z^
    Send a SASL bind request using a non-interactive SASL method (e.g. GSSAPI, EXTERNAL)
    rS   N)r8   saslCB_USERr   )r   	sasl_mechr   r   r   authz_idr   s          r   sasl_non_interactive_bind_sz,SimpleLDAPObject.sasl_non_interactive_bind_s  sM     9>>y" D 	  D[LLLLLr   c                 8    |                      d||||           dS )z9
    Send SASL bind request using SASL mech EXTERNAL
    EXTERNALNr   r   r   r   r   r   s        r   sasl_external_bind_sz%SimpleLDAPObject.sasl_external_bind_s  s'     	$$ZK
S[\\\\\r   c                 8    |                      d||||           dS )z7
    Send SASL bind request using SASL mech GSSAPI
    GSSAPINr   r   s        r   sasl_gssapi_bind_sz#SimpleLDAPObject.sasl_gssapi_bind_s   s'     	$$Xk+jQYZZZZZr   c           
      ~    |                      | j        j        |||t          |          t          |                    S )z\
    sasl_bind_s(dn, mechanism, cred [,serverctrls=None[,clientctrls=None]]) -> int|str
    )ru   rE   sasl_bind_sr   )r   r   	mechanismr   r   r   s         r   r   zSimpleLDAPObject.sasl_bind_s&  sN     ??47.r)DAUVaAbAbcw  yD  dE  dE  F  F  Fr   c           
      ~    |                      | j        j        |||t          |          t          |                    S )a  
    compare_ext(dn, attr, value [,serverctrls=None[,clientctrls=None]]) -> int
    compare_ext_s(dn, attr, value [,serverctrls=None[,clientctrls=None]]) -> bool
    compare(dn, attr, value) -> int
    compare_s(dn, attr, value) -> bool
        Perform an LDAP comparison between the attribute named attr of entry
        dn, and the value value. The synchronous form returns True or False.
        The asynchronous form returns the message id of the initiates request,
        and the result of the asynchronous compare can be obtained using
        result().

        Note that this latter technique yields the answer by raising
        the exception objects COMPARE_TRUE or COMPARE_FALSE.

        A design bug in the library prevents value from containing
        nul characters.
    )ru   rE   compare_extr   )r   r   attrr|   r   r   s         r   r   zSimpleLDAPObject.compare_ext,  sJ    $ ??47.r$u=QR]=^=^_st  `A  `A  B  B  Br   c                     |                      |||||          }	 |                     |d| j                  }n'# t          j        $ r Y dS t          j        $ r Y dS w xY wt          j        d|          )Nr[   r   TFz)Compare operation returned wrong result: )r   r   rG   r8   COMPARE_TRUECOMPARE_FALSEPROTOCOL_ERROR)r   r   r   r|   r   r   r   ldap_ress           r   compare_ext_szSimpleLDAPObject.compare_ext_s@  s    RU;{CCE<<!DL<AA   TT   UU

@H@@  s   9 AAAc                 4    |                      |||d d           S rw   )r   r   r   r   r|   s       r   comparezSimpleLDAPObject.compareL  s    BtE$t444r   c                 4    |                      |||d d           S rw   )r   r   s       r   	compare_szSimpleLDAPObject.compare_sO  s    beD666r   c                 z    |                      | j        j        |t          |          t          |                    S )a  
    delete(dn) -> int
    delete_s(dn) -> None
    delete_ext(dn[,serverctrls=None[,clientctrls=None]]) -> int
    delete_ext_s(dn[,serverctrls=None[,clientctrls=None]]) -> tuple
        Performs an LDAP delete operation on dn. The asynchronous
        form returns the message id of the initiated request, and the
        result can be obtained from a subsequent call to result().
    )ru   rE   
delete_extr   )r   r   r   r   s       r   r   zSimpleLDAPObject.delete_extR  s4     ??47-b1Ek1R1RSghsStStuuur   c                     |                      |||          }|                     |d| j                  \  }}}}||||fS r   )r   r   rG   )	r   r   r   r   r   r   r   r   r   s	            r   delete_ext_szSimpleLDAPObject.delete_ext_s^  sJ    OOB{;77E37<<!TXT`<3a3a0Iy*jiZ77r   c                 0    |                      |d d           S rw   )r   r   r   s     r   deletezSimpleLDAPObject.deletec  s    ??2d4(((r   c                 0    |                      |d d           S rw   )r   r   s     r   delete_szSimpleLDAPObject.delete_sf  s    RT***r   c           	          |                      | j        j        |j        |                                t          |          t          |                    S )a  
    extop(extreq[,serverctrls=None[,clientctrls=None]]]) -> int
    extop_s(extreq[,serverctrls=None[,clientctrls=None[,extop_resp_class=None]]]]) ->
        (respoid,respvalue)
        Performs an LDAP extended operation. The asynchronous
        form returns the message id of the initiated request, and the
        result can be obtained from a subsequent call to extop_result().
        The extreq is an instance of class ldap.extop.ExtendedRequest.

        If argument extop_resp_class is set to a sub-class of
        ldap.extop.ExtendedResponse this class is used to return an
        object of this class instead of a raw BER value in respvalue.
    )ru   rE   extoprequestNameencodedRequestValuer   )r   extreqr   r   s       r   r   zSimpleLDAPObject.extopi  s^     ??47=);F<V<V<X<XYmnyYzYz  |P  Q\  |]  |]  ^  ^  ^r   r[   c                 X    |                      |d| j        ddd          \  }}}}}}||fS )Nr[   )r   rG   	add_ctrlsadd_intermediates	add_extop)result4rG   )	r   r   r   rG   
resulttypemsg	respctrlsrespoid	respvalues	            r   extop_resultzSimpleLDAPObject.extop_resulty  sL    7;||EaX\Xdop  DE  PQ|  8R  8R4Js579Ir   c                     |                      |||          }|                     |d| j                  }|r@|\  }}|j        |k    rt	          j        d|j         d|            ||j        |          S |S )Nr[   r   z)Wrong OID in extended response! Expected z, got )r   r   rG   responseNamer8   r   )	r   r   r   r   extop_resp_classr   r   r   r   s	            r   extop_szSimpleLDAPObject.extop_s}  s    JJvk+66E


Ea

=
=C gi		&	/	/!"|N^Nk"|"|sz"|"|}}}.;IFFFjr   c           	      |    |                      | j        j        ||t          |          t          |                    S )zN
    modify_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
    )ru   rE   
modify_extr   r   s        r   r   zSimpleLDAPObject.modify_ext  s6     ??47-b9Mk9Z9Z[op{[|[|}}}r   c                     |                      ||||          }|                     |d| j                  \  }}}}	||||	fS r   )r   r   rG   r   s
             r   modify_ext_szSimpleLDAPObject.modify_ext_s  sL    OOBw{;??E37<<!TXT`<3a3a0Iy*jiZ77r   c                 2    |                      ||dd          S )a  
    modify(dn, modlist) -> int
    modify_s(dn, modlist) -> None
    modify_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
    modify_ext_s(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> tuple
        Performs an LDAP modify operation on an entry's attributes.
        dn is the DN of the entry to modify, and modlist is the list
        of modifications to make to the entry.

        Each element of the list modlist should be a tuple of the form
        (mod_op,mod_type,mod_vals), where mod_op is the operation (one of
        MOD_ADD, MOD_DELETE, MOD_INCREMENT or MOD_REPLACE), mod_type is a
        string indicating the attribute type name, and mod_vals is either a
        string value or a list of string values to add, delete, increment by or
        replace respectively.  For the delete operation, mod_vals may be None
        indicating that all attributes are to be deleted.

        The asynchronous modify() returns the message id of the
        initiated request.
    N)r   r   s      r   modifyzSimpleLDAPObject.modify  s    * ??2gd4000r   c                 2    |                      ||d d           S rw   )r   r   s      r   modify_szSimpleLDAPObject.modify_s  s    RT222r   c                 2    |                      ||d|          S )ac  
    modrdn(dn, newrdn [,delold=1]) -> int
    modrdn_s(dn, newrdn [,delold=1]) -> None
        Perform a modify RDN operation. These routines take dn, the
        DN of the entry whose RDN is to be changed, and newrdn, the
        new RDN to give to the entry. The optional parameter delold
        is used to specify whether the old RDN should be kept as
        an attribute of the entry or not.  The asynchronous version
        returns the initiated message id.

        This operation is emulated by rename() and rename_s() methods
        since the modrdn2* routines in the C library are deprecated.
    N)renamer   r   newrdndelolds       r   modrdnzSimpleLDAPObject.modrdn  s     ;;r&f---r   c                 2    |                      ||d |          S rw   )rename_sr   s       r   modrdn_szSimpleLDAPObject.modrdn_s  s    ==F4///r   c           
      ~    |                      | j        j        |||t          |          t          |                    S rw   )ru   rE   passwdr   )r   useroldpwnewpwr   r   s         r   r  zSimpleLDAPObject.passwd  s6    ??47>$uU;OP[;\;\]qr}]~]~r   Fc                    |                      |||||          }|                     |d| j                  \  }}	|t          j        k    rt          j        d|z            |r|	rt          t          j        |	          }	||	fS )Nr[   r   z'Unexpected OID %s in extended response!)r  r   rG   r   r   r8   r   )
r   r  r  r	  r   r   extract_newpwr   r   r   s
             r   passwd_szSimpleLDAPObject.passwd_s  s    KKeUKEEE**5a*NNGY(555 IG STTT Y Y()?)LiXXiIr   c                     |                      | j        j        ||||t          |          t          |                    S )a  
    rename(dn, newrdn [, newsuperior=None [,delold=1][,serverctrls=None[,clientctrls=None]]]) -> int
    rename_s(dn, newrdn [, newsuperior=None] [,delold=1][,serverctrls=None[,clientctrls=None]]) -> None
        Perform a rename entry operation. These routines take dn, the
        DN of the entry whose RDN is to be changed, newrdn, the
        new RDN, and newsuperior, the new parent DN, to give to the entry.
        If newsuperior is None then only the RDN is modified.
        The optional parameter delold is used to specify whether the
        old RDN should be kept as an attribute of the entry or not.
        The asynchronous version returns the initiated message id.

        This actually corresponds to the rename* routines in the
        LDAP-EXT C API library.
    )ru   rE   r   r   )r   r   r   newsuperiorr   r   r   s          r   r   zSimpleLDAPObject.rename  sO     ??47>"VKG[\gGhGhi}  J  jK  jK  L  L  Lr   c                     |                      ||||||          }|                     |d| j                  \  }}	}
}||	|
|fS r   )r   r   rG   )r   r   r   r  r   r   r   r   r   r   r   r   s               r   r  zSimpleLDAPObject.rename_s  sP    KK6+f[MME37<<!TXT`<3a3a0Iy*jiZ77r   c                 @    |                      |||          \  }}}||fS )a	  
    result([msgid=RES_ANY [,all=1 [,timeout=None]]]) -> (result_type, result_data)

        This method is used to wait for and return the result of an
        operation previously initiated by one of the LDAP asynchronous
        operation routines (e.g. search(), modify(), etc.) They all
        returned an invocation identifier (a message id) upon successful
        initiation of their operation. This id is guaranteed to be
        unique across an LDAP session, and can be used to request the
        result of a specific operation via the msgid parameter of the
        result() method.

        If the result of a specific operation is required, msgid should
        be set to the invocation message id returned when the operation
        was initiated; otherwise RES_ANY should be supplied.

        The all parameter only has meaning for search() responses
        and is used to select whether a single entry of the search
        response should be returned, or to wait for all the results
        of the search before returning.

        A search response is made up of zero or more search entries
        followed by a search result. If all is 0, search entries will
        be returned one at a time as they come in, via separate calls
        to result(). If all is 1, the search response will be returned
        in its entirety, i.e. after all entries and the final search
        result have been received.

        For all set to 0, result tuples
        trickle in (with the same message id), and with the result type
        RES_SEARCH_ENTRY, until the final result which has a result
        type of RES_SEARCH_RESULT and a (usually) empty data field.
        When all is set to 1, only one result is returned, with a
        result type of RES_SEARCH_RESULT, and all the result tuples
        listed in the data field.

        The method returns a tuple of the form (result_type,
        result_data).  The result_type is one of the constants RES_*.

        See search() for a description of the search result's
        result_data, otherwise the result_data is normally meaningless.

        The result() method will block for timeout seconds, or
        indefinitely if timeout is negative.  A timeout of 0 will effect
        a poll. The timeout can be expressed as a floating-point value.
        If timeout is None the default in self.timeout is used.

        If a timeout occurs, a TIMEOUT exception is raised, unless
        polling (timeout = 0), in which case (None, None) is returned.
    )result2)r   r   r   rG   r   r   r   s          r   rs   zSimpleLDAPObject.result  s,    f (,||E#g'F'F$Iy*ir   c                 D    |                      |||          \  }}}}|||fS rw   )r   )r   r   r   rG   r   r   r   r   s           r   r  zSimpleLDAPObject.result2  s-    37<<c'3R3R0Iy*ji++r   c           	      T    |                      |||ddd|          \  }}}}}	}
||||fS )Nr   )r   r   r   resp_ctrl_classes)r   )r   r   r   rG   r  r   r   r   decoded_resp_ctrlsretoidretvals              r   r   zSimpleLDAPObject.result3  sO    KO<<CA) LX L LHIy*&8&&
 i-???r   c           	         || j         }|                     | j        j        ||||||          }|
d\  }	}
}}}}n9t	          |          dk    r|\  }	}
}}d\  }}n	|\  }	}
}}}}|rfd|
D             }
t          |          }|	|
||||fS )N)NNNNNN   NNc                 >    g | ]\  }}}||t          |          fS r'   )r   ).0trcr  s       r   
<listcomp>z,SimpleLDAPObject.result4.<locals>.<listcomp>3  s2    ]]]1Qq.q1BCCD]]]r   )rG   ru   rE   r   lenr   )r   r   r   rG   r   r   r   r  ldap_resultr   r   r   r   	resp_name
resp_valuer  s          `        r   r   zSimpleLDAPObject.result4&  s    g//$'/%GIN_`ijjKNmK	9j*i	[		1		7B4	9j* )	::NYK	9j*i	 ^]]]]R[]]]	,Z8IJJi-?JVVr   r7   c
                     |d}|                      | j        j        |||||t          |          t          |          ||	
  
        S )a  
    search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int
    search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]])
    search_st(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]])
    search_ext(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])
    search_ext_s(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])

        Perform an LDAP search operation, with base as the DN of
        the entry at which to start the search, scope being one of
        SCOPE_BASE (to search the object itself), SCOPE_ONELEVEL
        (to search the object's immediate children), or SCOPE_SUBTREE
        (to search the object and all its descendants).

        filter is a string representation of the filter to
        apply in the search (see RFC 4515).

        Each result tuple is of the form (dn,entry), where dn is a
        string containing the DN (distinguished name) of the entry, and
        entry is a dictionary containing the attributes.
        Attributes types are used as string dictionary keys and attribute
        values are stored in a list as dictionary value.

        The DN in dn is extracted using the underlying ldap_get_dn(),
        which may raise an exception of the DN is malformed.

        If attrsonly is non-zero, the values of attrs will be
        meaningless (they are not transmitted in the result).

        The retrieved attributes can be limited with the attrlist
        parameter.  If attrlist is None, all the attributes of each
        entry are returned.

        serverctrls=None

        clientctrls=None

        The synchronous form with timeout, search_st() or search_ext_s(),
        will block for at most timeout seconds (or indefinitely if
        timeout is negative). A TIMEOUT exception is raised if no result is
        received within the time.

        The amount of search results retrieved can be limited with the
        sizelimit parameter if non-zero.
    Nz(objectClass=*))ru   rE   
search_extr   )
r   basescope	filterstrattrlist	attrsonlyr   r   rG   r-   s
             r   r&  zSimpleLDAPObject.search_ext7  sU    Z #i??
g
5y;'';''i  r   c
                 x    |                      |||||||||		  	        }
|                     |
d|          d         S r   )r&  rs   )r   r'  r(  r)  r*  r+  r   r   rG   r-   r   s              r   search_ext_szSimpleLDAPObject.search_ext_so  sC    OODy)KP[\cdmnnE;;u7;33A66r   c           	      8    |                      |||||d d           S rw   )r&  r   r'  r(  r)  r*  r+  s         r   searchzSimpleLDAPObject.searchs  s     ??4i4MMMr   c           
      F    |                      |||||d d | j                  S )N)rG   )r-  rG   r/  s         r   search_szSimpleLDAPObject.search_sv  s+    T%	(9T$W[Wcdddr   c           
      :    |                      |||||d d |          S rw   )r-  )r   r'  r(  r)  r*  r+  rG   s          r   	search_stzSimpleLDAPObject.search_sty  s$    T%	(9T$wWWWr   c                 @    |                      | j        j                  S )z
    start_tls_s() -> None
    Negotiate TLS with server. The `version' attribute must have been
    set to VERSION3 before calling start_tls_s.
    If TLS could not be started an exception will be raised.
    )ru   rE   start_tls_srP   s    r   r6  zSimpleLDAPObject.start_tls_s|  s     ??47.///r   c                     |                      | j        j        t          |          t          |                    }	 | `n# t          $ r Y nw xY w|S )a  
    unbind() -> int
    unbind_s() -> None
    unbind_ext() -> int
    unbind_ext_s() -> None
        This call is used to unbind from the directory, terminate
        the current association, and free resources. Once called, the
        connection to the LDAP server is closed and the LDAP object
        is invalid. Further invocation of methods on the object will
        yield an exception.

        The unbind and unbind_s methods are identical, and are
        synchronous in nature
    )ru   rE   ra   r   r   )r   r   r   r   s       r   ra   zSimpleLDAPObject.unbind_ext  sb     //$',-A+-N-NOcdoOpOp
q
qC
''   
dJs   A   
AAc                     |                      ||          }|d k    r|                     |d| j                  }nd }| j        dk    r+	 | j                                         n# t          $ r Y nw xY w|S r   )ra   r   rG   r9   r:   flushr   )r   r   r   r   rs   s        r   unbind_ext_szSimpleLDAPObject.unbind_ext_s  s    OOK44Ed{{||Ea|==fff&))       Ms   	A# #
A0/A0c                 .    |                      d d           S rw   )ra   rP   s    r   unbindzSimpleLDAPObject.unbind  s    ??4%%%r   c                 .    |                      d d           S rw   )r:  rP   s    r   unbind_szSimpleLDAPObject.unbind_s  s    T$'''r   c                 D    |                      | j        j        ||          S rw   )ru   rE   whoami_s)r   r   r   s      r   r@  zSimpleLDAPObject.whoami_s  s    ??47+KDDDr   c                     |                      | j        j        |          }|t          j        k    s|t          j        k    rt          |          }|S rw   )ru   rE   rl   r8   OPT_SERVER_CONTROLSOPT_CLIENT_CONTROLSr   )r   optionrs   s      r   rl   zSimpleLDAPObject.get_option  sG    __TW/77Ft'''643K+K+K"6**fMr   c                     |t           j        k    s|t           j        k    rt          |          }|                     | j        j        ||          S rw   )r8   rB  rC  r   ru   rE   ry   r   rD  invalues      r   ry   zSimpleLDAPObject.set_option  sE    t'''643K+K+K$W--g??47-fW===r   c                     d}d}||}	 |                      |t          j        d|g          }n?# t          j        t          j        t          j        f$ r g }Y nt          j        $ r Y dS w xY w	 |r{t          j                            |d         d                   }|                    |dg          d         }||r| 	                    |          S dS ||
                    d          S dS dS # t          $ r Y dS w xY w)a
  
    Returns the distinguished name of the sub schema sub entry
    for a part of a DIT specified by dn.

    None as result indicates that the DN of the sub schema sub entry could
    not be determined.

    Returns: None or text/bytes depending on bytes_mode.
    rS   subschemaSubentryNr   r[   )r   zutf-8)r2  r8   
SCOPE_BASENO_SUCH_OBJECTNO_SUCH_ATTRIBUTEINSUFFICIENT_ACCESSUNDEFINED_TYPEcidictgetsearch_subschemasubentry_sdecodero   )r   r   empty_dnattrnamer  rt   search_subschemasubentry_dns          r   rQ  z+SimpleLDAPObject.search_subschemasubentry_s  sP    H"H	zb
--
4?4
 aa  6t7OP   
aaa   TT	
 ?KqtAw''&'eeHdV&<&<Q&?#&. 22h2??? 4(4.55g>>>? ? 54   TTs.   #. (A*A*)A*.A#C/ C/ /
C=<C=c           	      r    |                      |t          j        |||||          }|r|d         d         S dS )z~
    Reads and returns a single entry specified by `dn'.

    Other attributes just like those passed to `search_ext_s()'
    )r*  r   r   rG   r   r[   N)r-  r8   rJ  )r   r   r)  r*  r   r   rG   r  s           r   read_szSimpleLDAPObject.read_s  sQ     	
o 	 	 	A 	 qT!WnTr   c                 z    d}|t           }	 |                     |||          }|S # t          j        $ r Y dS w xY w)z1
    Returns the sub schema sub entry's data
    z(objectClass=subschema)Nr)  r*  )r   rW  r8   rK  )r   subschemasubentry_dnattrsr)  subschemasubentrys        r   read_subschemasubentry_sz)SimpleLDAPObject.read_subschemasubentry_s  si     *I}e	++ &       TTs   ' ::c	                     |                      ||||||||d	  	        }	t          |	          dk    rt          dt          |          z            |	d         S )z@
    Returns a unique entry, raises exception if not unique
    r`   )r*  r+  r   r   rG   r-   r[   z%No or non-unique search result for %sr   )r-  r!  r&   rY   )
r   r'  r(  r)  r*  r+  r   r   rG   r  s
             r   find_unique_entryz"SimpleLDAPObject.find_unique_entry	  sm     	
 	 
	 
	A 1vvqyyCtIWXXXQ4Kr   c                 F    d}|pddg}|                      |||          }|S )zA
    convenience wrapper around read_s() for reading rootDSE
    rS   *+rY  )rW  )r   r)  r*  r'  ldap_rootdses        r   read_rootdse_szSimpleLDAPObject.read_rootdse_s  s@     D%C:H;;
   L
 r   c                 \    d}|                      |g                              |g           S )z
    returns all attribute values of namingContexts in rootDSE
    if namingContexts is not present (not readable) then empty list is returned
    namingContexts)r*  )rd  rP  r   s     r   get_naming_contextsz$SimpleLDAPObject.get_naming_contexts)  s8    
 Dv   	c$mmr   )r   Nr2   NNN)rS   r  )NNNN)NNN)r[   )NNF)Nr[   NN)NNr   NNr7   r   )NNr   )NNr   r7   rw   )NNNNr7   )Yr    r!   r"   r#   r8   OPT_PROTOCOL_VERSION	OPT_DEREFOPT_REFERRALSOPT_TIMELIMITOPT_SIZELIMITOPT_NETWORK_TIMEOUTOPT_ERROR_NUMBEROPT_ERROR_STRINGOPT_MATCHED_DNrx   r   propertyrM   rN   r=   ru   r}   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   
SASL_QUIETr   r   r   r   r   r   r   r   r   r   r   r   r   r   RES_ANYr   r   r   r   r   r   r  r  r  r  r   r  rs   r  r   r   r&  r-  r0  r2  r4  r6  ra   r:  r<  r>  r@  rl   ry   rQ  rW  r]  SCOPE_SUBTREEr_  rd  rg  r'   r   r   r   r   2   s         3.,,,2(($
 
 BF"&J J J J4   8   8$ $ $ $' ' 'R" " "	 	 	* * *
z 
z 
z 
z- - -x x x x   { { { {8 8 8 8
. . .0 0 0} } } }8 8 8 8 !% 0 & & & & #'"2 9 9 9 9 9=Y]Yh T T T T >Bd^b^mwy M M M M -1TT_fh ] ] ] ] +/44?df [ [ [ [F F F FB B B B(
 
 
 
5 5 57 7 7
v 
v 
v 
v8 8 8 8
) ) )+ + +^ ^ ^ ^  #lq    	 	 	 	~ ~ ~ ~8 8 8 8
1 1 1.3 3 3. . . . 0 0 0 0@ @ @ @	 	 	 	L L L L"8 8 8 8
 4 4  4  4  4 l !D , , , , !D4 @ @ @ @ !D1WXcdw{ W W W W"6 6 6 6p7 7 7 7N N N Ne e e eX X X X0 0 0   ,   & & &( ( (E E E E  > > >
% % % %N   (   $ )-(:TSWbcpt  BF  OQ    &       r   r   c                       e Zd ZdZh dZ	 	 d!dZd	 Zd
 Zd Zd Z	d Z
d Zd"dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  ZdS )#r	   a0  
  :py:class:`SimpleLDAPObject` subclass whose synchronous request methods
  automatically reconnect and re-try in case of server failure
  (:exc:`ldap.SERVER_DOWN`).

  The first arguments are same as for the :py:func:`~ldap.initialize()`
  function.
  For automatic reconnects it has additional arguments:

  * retry_max: specifies the number of reconnect attempts before
    re-raising the :py:exc:`ldap.SERVER_DOWN` exception.

  * retry_delay: specifies the time in seconds between reconnect attempts.

  This class also implements the pickle protocol.
  >   rE   
_last_bindr:   _reconnect_lockr>   r   Nr2   r[         N@c
           
          || _         g | _        d| _        t                              | |||||||	           t          j        dt          |           z            | _        || _	        || _
        d| _        d| _        dS )z
    Parameters like SimpleLDAPObject.__init__() with these
    additional arguments:

    retry_max
        Maximum count of reconnect trials
    retry_delay
        Time span to wait between two reconnect trials
    N)rN   r6   reconnect lock within %srU   r   )r<   _optionsrv  r   r   r8   rX   rY   rw  
_retry_max_retry_delay
_start_tls_reconnects_done)
r   rI   rJ   rK   rL   rM   rN   	retry_maxretry_delayr6   s
             r   r   zReconnectLDAPObject.__init__N  s     DIDMDOdCj//?%+  - - -  =.HDQUJJ.WXXXDDO#DDODr   c                       fd j                                         D             } j        d         j         j        d          j        d         f|d<   |S )z-return data representation for pickled objectc                 .    i | ]\  }}|j         v||S r'   )__transient_attrs__)r  kvr   s      r   
<dictcomp>z4ReconnectLDAPObject.__getstate__.<locals>.<dictcomp>k  s7       AaD,,, 	
1,,,r   r   r[   r`   rv  )rz   itemsrv  r    )r   states   ` r   __getstate__z ReconnectLDAPObject.__getstate__i  sj       =&&((  E
 /!,5tq7I4?[\K]]E,Lr   c                    |                     d          }|r|                    dd           n|                    dd           | j                            |           t	          t
          | j        d                   | j        d         | j        d         f| _        |                                 | _        t          j
        dt          |           z  	          | _        t          j        | _        |                     | j        d
           dS )z#set up the object from pickled databytes_mode_hardfailrN   rR   r   r   r[   r`   rz  rU   T)forceN)rP  
setdefaultrz   updategetattrr   rv  r=   r>   r8   rX   rY   rw  r:   	reconnectr<   )r   dhardfails      r   __setstate__z ReconnectLDAPObject.__setstate__s  s    uu*++H 1	'1111	'000M.0BCCT_UVEWY]YhijYkkDO!__..D=.HDQUJJ.WXXXD'DNN494N(((((r   c                     |||f| _         d S rw   )rv  )r   _methodr   r   s       r   _store_last_bindz$ReconnectLDAPObject._store_last_bind  s    tF+DOOOr   c                     | j         d k    r| j         \  }}} || g|R i | d S t                              | d d            d S rw   )rv  r   r   r   rq   r   r   s       r   _apply_last_bindz$ReconnectLDAPObject._apply_last_bind  sc    d4
d4 $$T466666r   c                 X    | j         D ]!\  }}t                              | ||           "dS )zRestore all recorded optionsN)r{  r   ry   )r   r  r  s      r   _restore_optionsz$ReconnectLDAPObject._restore_options  s<    } , ,!!!$q++++, ,r   c                 8     | j         t          j        g|R i |S rw   )_apply_method_sr   r  r   r   r   s      r   r  zReconnectLDAPObject.passwd_s  )    4 0 9I4III&IIIr   Tc                    | j                                          	 t          | d          r9|rt                              |            n	 | j                                          d S |}|rd||z
  dz   |fz  }| j        dk    r.| j                            d	                    ||                     	 	 t          j                            t          j        t          j        |          | _        |                                  | j        rt                              |            |                                  n.# t          j        $ r t                              |             w xY w	 | j        dk    r.| j                            d	                    ||                     | j        dz   | _        n# t          j        t          j        f$ r | j        dk    r.| j                            d	                    ||                     |dz
  }|s | j        dk    r| j                            d|z             t3          j        |           Y nw xY w|| j                                          n# | j                                          w xY wd S )	NrE   z%d. (of %d)r[   Tz!*** Trying {} reconnect to {}...
z;*** {} reconnect to {} successful => repeat last operation
z*** {} reconnect to {} failed
z=> delay %s...
)rw  rd   r?   r   r>  rn   r9   r:   re   rf   r8   rB   rC   rD   r@   rF   rE   r  r~  r6  r  r   r  SERVER_DOWNTIMEOUTtimesleep)r   rI   r  r  r  reconnect_countercounter_texts          r   r  zReconnectLDAPObject.reconnect  s    	  """-%	d		  	

#
#D
)
)
)
)
P ""$$$$$O $ $$	2C(CA(Ei'PP*A--


 
 !E!L!L" "   	n889OPUP`adeeDG!!### 1**4000!!####   %%d+++ $   ,a//""#a#h#h3$ $    #'"7!";$

#  . 
	" 
	" 
	",a//""#D#K#K3$ $    01
" ,a//""#5#EFFF
*[
!
!
!
!
!
	"'  $L ""$$$$d""$$$$
FsK   -I( $AI( 1BD5 4F- 5+E  F- $A	I( -BII( II( (Jc                     |                      | j        | j        | j        d           	  || g|R i |S # t          j        $ r7 |                      | j        | j        | j        d            || g|R i |cY S w xY w)NF)r  r  r  T)r  r<   r|  r}  r8   r  r  s       r   r  z#ReconnectLDAPObject._apply_method_s  s    NN49t4CT[`Naaa'T$&&&&v&&& ' ' '
nnTYTEV]anbbbT$&&&&v&&&&&	's   6 AA<;A<c                 r    | j                             ||f           t                              | ||          S rw   )r{  appendr   ry   rF  s      r   ry   zReconnectLDAPObject.set_option  s5    M&)***&&tF7;;;r   c                 r     | j         t          j        g|R i |} | j        t          j        g|R i | |S rw   )r  r   r   r  r   r   r   r   s       r   r   zReconnectLDAPObject.bind_s  sT    
$
/6
F
F
F
Fv
F
FCD*1A4AAA&AAAJr   c                 r     | j         t          j        g|R i |} | j        t          j        g|R i | |S rw   )r  r   r   r  r  s       r   r   z!ReconnectLDAPObject.simple_bind_s  sT    
$
/=
Mt
M
M
Mf
M
MCD*8H$HHHHHHJr   c                 J     | j         t          j        g|R i |}d| _        |S )Nr[   )r  r   r6  r~  r  s       r   r6  zReconnectLDAPObject.start_tls_s  s4    
$
/;
KT
K
K
KF
K
KCDOJr   c                 r     | j         t          j        g|R i |} | j        t          j        g|R i | |S )z4
    sasl_interactive_bind_s(who, auth) -> None
    )r  r   r   r  r  s       r   r   z+ReconnectLDAPObject.sasl_interactive_bind_s  sW     $
/G
W
W
W
WPV
W
WCD*BRDRRR6RRRJr   c                 r     | j         t          j        g|R i |} | j        t          j        g|R i | |S rw   )r  r   r   r  r  s       r   r   zReconnectLDAPObject.sasl_bind_s  sT    
$
/;
KT
K
K
KF
K
KCD*6FFFFvFFFJr   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   zReconnectLDAPObject.add_ext_s  s)    4 0 :JDJJJ6JJJr   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   zReconnectLDAPObject.cancel_s  r  r   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   z!ReconnectLDAPObject.compare_ext_s  s)    4 0 >NNNNvNNNr   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   z ReconnectLDAPObject.delete_ext_s  )    4 0 =MtMMMfMMMr   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   zReconnectLDAPObject.extop_s  s)    4 0 8H$HHHHHHr   c                 8     | j         t          j        g|R i |S rw   )r  r   r   r  s      r   r   z ReconnectLDAPObject.modify_ext_s  r  r   c                 8     | j         t          j        g|R i |S rw   )r  r   r  r  s      r   r  zReconnectLDAPObject.rename_s  r  r   c                 8     | j         t          j        g|R i |S rw   )r  r   r-  r  s      r   r-  z ReconnectLDAPObject.search_ext_s  r  r   c                 8     | j         t          j        g|R i |S rw   )r  r   r@  r  s      r   r@  zReconnectLDAPObject.whoami_s  r  r   )r   Nr2   NNr[   rx  N)r[   rx  T)r    r!   r"   r#   r  r   r  r  r  r  r  r  r  r  ry   r   r   r6  r   r   r   r   r   r   r   r   r  r-  r@  r'   r   r   r	   r	   4  s        "   BFAE   6  ) ) ), , ,7 7 7, , ,
J J J2 2 2 2h' ' '< < <  
  
  
    
K K KJ J JO O ON N NI I IN N NJ J JN N NJ J J J Jr   r	   )#r#   osr   ldap.pkginfor   r   r   __all__rj   sysr  rh   r@   r8   	ldap.saslldap.functionsr   ldap.schemar   ldap.controlsr   r   r   
ldap.extopr   r   r   r   BytesWarningr
   rK  r&   r   r	   r   r'   r   r   <module>r     s   
       = = = = = = = = = =   : : : : : : : : : : : : : : : : : : : : : : : : : : : :  $ $ $ $ $ $ N N N N N N N N N N N N N N N N N N N N      * * * * *| * * *    d)          DXJ XJ XJ XJ XJ* XJ XJ XJz 


r   