HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib64/python3.6/site-packages/ldap/__pycache__/ldapobject.cpython-36.opt-1.pyc
3

�`a���@s8dZddlmZddlmZddlmZmZmZddddgZ	dd	l
Z
dd	lZdd	lZdd	l
Z
dd	lZdd	lZdd	lZdd	lZdd
lmZddlmZmZmZddlmZmZmZdd
lmZddlmZe
jddkZ e r�e!Z"ne#Z"dZ$Gdd�de%�Z&dd�Z'Gdd�dej(�Z)Gdd�d�Z*Gdd�de*�Z+e*Z,d	S)z]
ldapobject.py - wraps class _ldap.LDAPObject

See https://www.python-ldap.org/ for details.
�)�unicode_literals)�strerror)�__version__�
__author__�__license__�
LDAPObject�SimpleLDAPObject�ReconnectLDAPObject�LDAPBytesWarningN)�SCHEMA_ATTRS)�LDAPControl�DecodeControlTuples�RequestControlTuples)�ExtendedRequest�ExtendedResponse�PasswordModifyResponse)�reraise)�	LDAPError�Tc@seZdZdZdS)r
z!python-ldap bytes mode warning
  N)�__name__�
__module__�__qualname__�__doc__�rr�"/usr/lib64/python3.6/ldapobject.pyr
-sc
Csjd}y
tj}Wntk
r"Yn0Xtj|�}x"|rP|jjd�rP|d7}|j}q0Wtj|t|dd�dS)zRaise LDAPBytesWarning
    r�_LDAP_WARN_SKIP_FRAME�)�
stacklevelN)	�sys�	_getframe�AttributeError�	f_globals�get�f_back�warnings�warnr
)�messagerZgetframe�framerrr�_raise_byteswarning1s


r(c@seZdZdZdS)�NO_UNIQUE_ENTRYz�
  Exception raised if a LDAP search returned more than entry entry
  although assumed to return a unique single search result.
  N)rrrrrrrrr)Fsr)c
@sTeZdZdZejejejejej	ej
ejejej
d�	Zd�dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zd�dd�Zd�dd�Zdd�Zdd�Zdd�Zdd�Zd�d d!�Zd"d#�Zd�d$d%�Zd�d&d'�Zd�d(d)�Zd�d*d+�Z d,d-�Z!d.d/�Z"d�d0d1�Z#d�d2d3�Z$ej%fd4d5�Z&ej%fd6d7�Z'ddej(fd8d9�Z)ddej(dfd:d;�Z*ddej(dfd<d=�Z+ddej(dfd>d?�Z,d�d@dA�Z-d�dBdC�Z.d�dDdE�Z/dFdG�Z0dHdI�Z1d�dJdK�Z2d�dLdM�Z3dNdO�Z4dPdQ�Z5d�dRdS�Z6ej7dTdfdUdV�Z8d�dWdX�Z9d�dYdZ�Z:d�d[d\�Z;d]d^�Z<d_d`�Z=d�dadb�Z>d�dcdd�Z?d�dedf�Z@d�dgdh�ZAd�didj�ZBd�dkdl�ZCej7dTdfdmdn�ZDej7dTdfdodp�ZEej7dTddfdqdr�ZFej7dTdddddfdsdt�ZGd�dudv�ZHd�dwdx�ZId�dydz�ZJd�d{d|�ZKd�d}d~�ZLdd��ZMd�d�d��ZNd�d�d��ZOd�d��ZPd�d��ZQd�d�d��ZRd�d��ZSd�d��ZTd�d�d��ZUd�d�d��ZVd�d�d��ZWejXdddddd�fd�d��ZYd�d�d��ZZd�d��Z[dS)�rz�
  This basic class wraps all methods of the underlying C API object.

  The arguments are same as for the :func:`~ldap.initialize()` function.
  )	�protocol_versionZderefZ	referralsZ	timelimit�	sizelimitZnetwork_timeoutZerror_numberZerror_stringZ
matched_dnrN�cCs�|ptj|_|ptj|_||_||_|jd�|_|dk	rvttd�sJt	d��t|d�r\|j
�}tjjtj
tj||�|_ntjjtj
tj|�|_d|_tj|_tr�|dkr�d}|dkr�td�d}q�|dkr�d	}n|r�t	d
��d}d	}||_||_dS)
NZopcall�
initialize_fdz&libldap does not support initialize_fd�filenorTz�Under Python 2, python-ldap uses bytes by default. This will be removed in Python 3 (no bytes for DN/RDN/field names). Please call initialize(..., bytes_mode=False) explicitly.r%�errorz-bytes_mode is *not* supported under Python 3.F���)�ldap�_trace_level�_trace_fileZ_trace_stack_limit�_uri�
_ldap_lock�_ldap_object_lock�hasattr�_ldap�
ValueErrorr.�	functions�_ldap_function_call�_ldap_module_lockr-�_l�
initialize�timeoutZVERSION3r*�PY2r(�
bytes_mode�bytes_strictness)�self�uri�trace_level�
trace_file�trace_stack_limitrArBr.rrr�__init__`s<

zSimpleLDAPObject.__init__cCs�ts|S|dkr|S|jrnt|t�r(|S|jdkr4n0|jdkrNtdj|��ntdjt|�j	|���|j
d�St|t�r�|j
d�S|jdkr�n0|jdkr�tdj|��ntdjt|�j	|���|SdS)	a�Adapt a value following bytes_mode in Python 2.

    In Python 3, returns the original value unmodified.

    With bytes_mode ON, takes bytes or None and returns bytes or None.
    With bytes_mode OFF, takes unicode or None and returns bytes or None.

    For the wrong argument type (unicode or bytes, respectively),
    behavior depends on the bytes_strictness setting.
    In all cases, bytes or None are returned (or an exception is raised).
    NZsilentr%zxReceived non-bytes value for '{}' in bytes mode; please choose an explicit option for bytes_mode on your LDAP connectionzRAll provided fields *must* be bytes when bytes mode is on; got type '{}' for '{}'.zutf-8zPReceived non-text value for '{}' with bytes_mode off and bytes_strictness='warn'zRAll provided fields *must* be text when bytes mode is off; got type '{}' for '{}'.)r@rA�
isinstance�bytesrBr(�format�	TypeError�typer�encode�unicode)rC�arg_name�valuerrr�_bytesify_input�s:









z SimpleLDAPObject._bytesify_inputcs@ts|S|r$t��fdd�|D��St��fdd�|D��SdS)z�Adapt a modlist according to bytes_mode.

    A modlist is a tuple of (op, attr, value), where:
    - With bytes_mode ON, attr is checked to be bytes
    - With bytes_mode OFF, attr is converted from unicode to bytes
    - value is *always* bytes
    c3s&|]\}}}|�j�|�|fVqdS)N)rR)�.0�op�attr�val)rPrCrr�	<genexpr>�sz5SimpleLDAPObject._bytesify_modlist.<locals>.<genexpr>c3s"|]\}}�j�|�|fVqdS)N)rR)rSrUrV)rPrCrrrW�sN)r@�tuple)rCrP�modlist�with_opcoder)rPrCr�_bytesify_modlist�s
z"SimpleLDAPObject._bytesify_modlistcCs(|dkr|Str|jr|S|jd�SdS)anAdapt a 'known text, UTF-8 encoded' returned value following bytes_mode.

    With bytes_mode ON, takes bytes or None and returns bytes or None.
    With bytes_mode OFF, takes bytes or None and returns unicode or None.

    This function should only be applied on field *values*; distinguished names
    or field *names* are already natively handled in result4.
    Nzutf-8)r@rA�decode)rCrQrrr�_unbytesify_text_value�s	z'SimpleLDAPObject._unbytesify_text_valuecCs,ts|S|dkr|S|js|S|jd�SdS)z�Re-encodes text to bytes if needed by bytes_mode.

    Takes unicode (and checks for it), and returns:
    - bytes under bytes_mode
    - unicode otherwise.
    Nzutf-8)r@rArN)rCrQrrr�_maybe_rebytesify_text�sz'SimpleLDAPObject._maybe_rebytesify_textcsLts|St|d�r(�fdd�|j�D�St|t�r6|S�fdd�|D�SdS)z�Applies bytes_mode to a result value.

    Such a value can either be:
    - a dict mapping an attribute name to its list of values
      (where attribute names are unicode and values bytes)
    - a list of referals (which are unicode)
    �itemscsi|]\}}|�j|��qSr)r^)rS�keyrQ)rCrr�
<dictcomp>	sz;SimpleLDAPObject._bytesify_result_value.<locals>.<dictcomp>csg|]}�j|��qSr)r^)rSZreferal)rCrr�
<listcomp>sz;SimpleLDAPObject._bytesify_result_value.<locals>.<listcomp>N)r@r7r_rIrJ)rCZresult_valuer)rCr�_bytesify_result_value�s


z'SimpleLDAPObject._bytesify_result_valueFcs4ts|S|r�fdd�|D�S�fdd�|D�SdS)a	Converts a "results" object according to bytes_mode.

    Takes:
    - a list of (dn, {field: [values]}) if with_ctrls is False
    - a list of (dn, {field: [values]}, ctrls) if with_ctrls is True

    And, if bytes_mode is on, converts dn and fields to bytes.
    cs(g|] \}}}�j|��j|�|f�qSr)r^rc)rS�dn�fieldsZctrls)rCrrrb"sz6SimpleLDAPObject._bytesify_results.<locals>.<listcomp>cs$g|]\}}�j|��j|�f�qSr)r^rc)rSrdre)rCrrrb'sN)r@)rC�results�
with_ctrlsr)rCr�_bytesify_resultss	

z"SimpleLDAPObject._bytesify_results�cCs(tjrtjd|t|�fd�StjSdS)Nz%s within %s)�desc)r1Z	LIBLDAP_R�LDAPLock�reprr<)rCrjrrrr5+szSimpleLDAPObject._ldap_lockc
Osn|jj�d}yFz4|||�}drB|jdkrB|jdkrB|jjtj�}Wd|jj�XWn�t	k
�r"}z�t
j�\}}}	y<d|jdkr�d|jdkr�t
|jdd�|jdd<Wntk
r�YnXdr�|jdkr�|jjd|jjt|�f�zt|||	�Wdd}}}	XWYdd}~XnHXd�rj|jdk�rj|dk	�rT|jjd	t|��|jjd
tj|��|S)z[
    Wrapper method mainly for serializing calls into OpenLDAP libs
    and trace logs
    NFr�
unbind_ext�infor�errnoz=> LDAPError - %s: %s
z=> diagnosticMessage: %s
z=> result:
%s
)r6�acquirer2rr=�
get_optionr1ZOPT_DIAGNOSTIC_MESSAGE�releaserr�exc_info�argsr�
IndexErrorr3�write�	__class__�strrrl�pprintZpformat)
rC�funcrt�kwargsZdiagnostic_message_success�result�e�exc_type�	exc_value�
exc_tracebackrrr�
_ldap_call1s4


  
zSimpleLDAPObject._ldap_callcCs,||jkr|j|j||�n
||j|<dS)N)�CLASSATTR_OPTION_MAPPING�
set_option�__dict__)rC�namerQrrr�__setattr__^s
zSimpleLDAPObject.__setattr__cCsJ||jkr|j|j|�S||jkr.|j|Std|jjt|�f��dS)Nz%s has no attribute %s)r�rqr�r rwrrl)rCr�rrr�__getattr__ds


zSimpleLDAPObject.__getattr__cCs|jtj�S)z
    Returns file description of LDAP connection.

    Just a convenience wrapper for LDAPObject.get_option(ldap.OPT_DESC)
    )rqr1ZOPT_DESC)rCrrrr.nszSimpleLDAPObject.filenocCs|j|jj|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().
    )r�r=�abandon_extr)rC�msgid�serverctrls�clientctrlsrrrr�vs
zSimpleLDAPObject.abandon_extcCs|j|dd�S)N)r�)rCr�rrr�abandon�szSimpleLDAPObject.abandoncCs|j|jj|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.
    )r�r=�cancelr)rC�cancelidr�r�rrrr��szSimpleLDAPObject.cancelcCsJ|j|||�}y|j|d|jd�}Wn tjtjfk
rDd}YnX|S)Nr)�allr?)r�r|r?r1Z	CANCELLED�SUCCESS)rCr�r�r�r��resrrr�cancel_s�s
zSimpleLDAPObject.cancel_scCs>tr |jd|�}|jd|dd�}|j|jj||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.
    rdrYF)rZ)r@rRr[r�r=�add_extr)rCrdrYr�r�rrrr��szSimpleLDAPObject.add_extc
Cs6|j||||�}|j|d|jd�\}}}}	||||	fS)Nr)r�r?)r��result3r?)
rCrdrYr�r�r��	resp_type�	resp_data�
resp_msgid�
resp_ctrlsrrr�	add_ext_s�szSimpleLDAPObject.add_ext_scCs|j||dd�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�)rCrdrYrrr�add�szSimpleLDAPObject.addcCs|j||dd�S)N)r�)rCrdrYrrr�add_s�szSimpleLDAPObject.add_scCs:tr|jd|�}|jd|�}|j|jj||t|�t|��S)z1
    simple_bind([who='' [,cred='']]) -> int
    �who�cred)r@rRr�r=�simple_bindr)rCr�r�r�r�rrrr��szSimpleLDAPObject.simple_bindc
Cs6|j||||�}|j|d|jd�\}}}}	||||	fS)z7
    simple_bind_s([who='' [,cred='']]) -> 4-tuple
    r)r�r?)r�r�r?)
rCr�r�r�r�r�r�r�r�r�rrr�
simple_bind_s�szSimpleLDAPObject.simple_bind_scCs|j||�S)z(
    bind(who, cred, method) -> int
    )r�)rCr�r��methodrrr�bind�szSimpleLDAPObject.bindcCs |j|||�}|j|d|jd�S)z+
    bind_s(who, cred, method) -> None
    r)r�r?)r�r|r?)rCr�r�r�r�rrr�bind_s�szSimpleLDAPObject.bind_scCs |j|jj||t|�t|�|�S)zx
    sasl_interactive_bind_s(who, auth [,serverctrls=None[,clientctrls=None[,sasl_flags=ldap.SASL_QUIET]]]) -> None
    )r�r=�sasl_interactive_bind_sr)rCr��authr�r��
sasl_flagsrrrr��sz(SimpleLDAPObject.sasl_interactive_bind_scCs,tjjtjj|i|�}|jd||||�dS)z^
    Send a SASL bind request using a non-interactive SASL method (e.g. GSSAPI, EXTERNAL)
    riN)r1ZsaslZCB_USERr�)rCZ	sasl_mechr�r�r��authz_idr�rrr�sasl_non_interactive_bind_s�s
z,SimpleLDAPObject.sasl_non_interactive_bind_scCs|jd||||�dS)z9
    Send SASL bind request using SASL mech EXTERNAL
    ZEXTERNALN)r�)rCr�r�r�r�rrr�sasl_external_bind_s�sz%SimpleLDAPObject.sasl_external_bind_scCs|jd||||�dS)z7
    Send SASL bind request using SASL mech GSSAPI
    ZGSSAPIN)r�)rCr�r�r�r�rrr�sasl_gssapi_bind_s�sz#SimpleLDAPObject.sasl_gssapi_bind_scCs |j|jj|||t|�t|��S)z\
    sasl_bind_s(dn, mechanism, cred [,serverctrls=None[,clientctrls=None]]) -> int|str
    )r�r=�sasl_bind_sr)rCrdZ	mechanismr�r�r�rrrr��szSimpleLDAPObject.sasl_bind_scCs<tr|jd|�}|jd|�}|j|jj|||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.
    rdrU)r@rRr�r=�compare_extr)rCrdrUrQr�r�rrrr��szSimpleLDAPObject.compare_extcCsh|j|||||�}y|j|d|jd�}Wn*tjk
r>dStjk
rRdSXtjd|f��dS)Nr)r�r?TFz+Compare operation returned wrong result: %r)r�r�r?r1ZCOMPARE_TRUEZ
COMPARE_FALSE�PROTOCOL_ERROR)rCrdrUrQr�r�r�Zldap_resrrr�
compare_ext_sszSimpleLDAPObject.compare_ext_scCs|j|||dd�S)N)r�)rCrdrUrQrrr�compareszSimpleLDAPObject.comparecCs|j|||dd�S)N)r�)rCrdrUrQrrr�	compare_s szSimpleLDAPObject.compare_scCs(|jd|�}|j|jj|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().
    rd)rRr�r=�
delete_extr)rCrdr�r�rrrr�#s
zSimpleLDAPObject.delete_extc	Cs4|j|||�}|j|d|jd�\}}}}||||fS)Nr)r�r?)r�r�r?)	rCrdr�r�r�r�r�r�r�rrr�delete_ext_s0szSimpleLDAPObject.delete_ext_scCs|j|dd�S)N)r�)rCrdrrr�delete5szSimpleLDAPObject.deletecCs|j|dd�S)N)r�)rCrdrrr�delete_s8szSimpleLDAPObject.delete_scCs$|j|jj|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.
    )r�r=�extopZrequestNameZencodedRequestValuer)rC�extreqr�r�rrrr�;szSimpleLDAPObject.extoprc	Cs,|j|d|jdddd�\}}}}}}||fS)Nr)r�r?�	add_ctrls�add_intermediates�	add_extop)�result4r?)	rCr�r�r?Z
resulttype�msgZ	respctrls�respoid�	respvaluerrr�extop_resultKs$zSimpleLDAPObject.extop_resultc	Cs^|j|||�}|j|d|jd�}|rV|\}}|j|krJtjd|j|f��||j|�S|SdS)Nr)r�r?z3Wrong OID in extended response! Expected %s, got %s)r�r�r?�responseNamer1r�)	rCr�r�r�Zextop_resp_classr�r�r�r�rrr�extop_sOs
zSimpleLDAPObject.extop_scCs>tr |jd|�}|jd|dd�}|j|jj||t|�t|��S)zN
    modify_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
    rdrYT)rZ)r@rRr[r�r=�
modify_extr)rCrdrYr�r�rrrr�ZszSimpleLDAPObject.modify_extc
Cs6|j||||�}|j|d|jd�\}}}}	||||	fS)Nr)r�r?)r�r�r?)
rCrdrYr�r�r�r�r�r�r�rrr�modify_ext_scszSimpleLDAPObject.modify_ext_scCs|j||dd�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�)rCrdrYrrr�modifyhszSimpleLDAPObject.modifycCs|j||dd�S)N)r�)rCrdrYrrr�modify_sszSimpleLDAPObject.modify_scCs|j||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)rCrd�newrdn�deloldrrr�modrdn�szSimpleLDAPObject.modrdncCs|j||d|�S)N)�rename_s)rCrdr�r�rrr�modrdn_s�szSimpleLDAPObject.modrdn_scCsHtr(|jd|�}|jd|�}|jd|�}|j|jj|||t|�t|��S)N�user�oldpw�newpw)r@rRr�r=�passwdr)rCr�r�r�r�r�rrrr��s
zSimpleLDAPObject.passwdc
Cs\|j|||||�}|j|d|jd�\}}	|tjkr@tjd|��|rT|	rTttj|	�}	||	fS)Nr)r�r?z'Unexpected OID %s in extended response!)r�r�r?rr�r1r�)
rCr�r�r�r�r�Z
extract_newpwr�r�r�rrr�passwd_s�s
zSimpleLDAPObject.passwd_sc	CsJtr(|jd|�}|jd|�}|jd|�}|j|jj||||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.
    rdr��newsuperior)r@rRr�r=r�r)rCrdr�r�r�r�r�rrrr��s
zSimpleLDAPObject.renamecCs:|j||||||�}|j|d|jd�\}}	}
}||	|
|fS)Nr)r�r?)r�r�r?)rCrdr�r�r�r�r�r�r�r�r�r�rrrr��szSimpleLDAPObject.rename_scCs|j|||�\}}}||fS)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)rCr�r�r?r�r�r�rrrr|�s3zSimpleLDAPObject.resultcCs |j|||�\}}}}|||fS)N)r�)rCr�r�r?r�r�r�r�rrrr��szSimpleLDAPObject.result2c	Cs0|j|||ddd|d�\}}}}}	}
||||fS)Nr)r�r�r��resp_ctrl_classes)r�)rCr�r�r?r�r�r�r��decoded_resp_ctrlsZretoidZretvalrrrr��s
zSimpleLDAPObject.result3cs�|dkr|j}|j|jj||||||�}|dkrBd\}	}
}}}
}nHt|�dkrd|\}	}
}}d\}
}n|\}	}
}}}
}|r��fdd�|
D�}
t|��}|
dk	r�|j|
|d�}
|	|
|||
|fS)N�cs"g|]\}}}||t|��f�qSr)r
)rS�t�r�c)r�rrrbsz,SimpleLDAPObject.result4.<locals>.<listcomp>)rg)NNNNNN)NN)r?r�r=r��lenr
rh)rCr�r�r?r�r�r�r�Zldap_resultr�r�r�r�Z	resp_nameZ
resp_valuer�r)r�rr�s

zSimpleLDAPObject.result4c

s�trV�jd|�}|dkr*�jr$d}q6d}n�jd|�}|dk	rbt�fdd�|D��}n|dkrbd}�j�jj|||||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.
    �baseNs(objectClass=*)z(objectClass=*)�	filterstrc3s|]}�jd|�VqdS)�attrlistN)rR)rS�a)rCrrrWPsz.SimpleLDAPObject.search_ext.<locals>.<genexpr>)r@rRrArXr�r=�
search_extr)
rCr��scoper�r��	attrsonlyr�r�r?r+r)rCrr�s&.zSimpleLDAPObject.search_extc

Cs.|j|||||||||	�	}
|j|
d|d�dS)Nr)r�r?)r�r|)rCr�r�r�r�r�r�r�r?r+r�rrr�search_ext_s^szSimpleLDAPObject.search_ext_scCs|j|||||dd�S)N)r�)rCr�r�r�r�r�rrr�searchbszSimpleLDAPObject.searchc
Cs|j|||||dd|jd�S)N)r?)r�r?)rCr�r�r�r�r�rrr�search_seszSimpleLDAPObject.search_sc	Cs|j|||||dd|�S)N)r�)rCr�r�r�r�r�r?rrr�	search_sthszSimpleLDAPObject.search_stcCs|j|jj�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.
    )r�r=�start_tls_s)rCrrrr�kszSimpleLDAPObject.start_tls_scCs<|j|jjt|�t|��}y|`Wntk
r6YnX|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
    )r�r=rmrr )rCr�r�r�rrrrmtszSimpleLDAPObject.unbind_extcCsb|j||�}|dkr(|j|d|jd�}nd}dr^|jdkr^y|jj�Wntk
r\YnX|S)Nr)r�r?F)rmr�r?r2r3�flushr )rCr�r�r�r|rrr�unbind_ext_s�szSimpleLDAPObject.unbind_ext_scCs|jdd�S)N)rm)rCrrr�unbind�szSimpleLDAPObject.unbindcCs|jdd�S)N)r�)rCrrr�unbind_s�szSimpleLDAPObject.unbind_scCs|j|jj||�S)N)r�r=�whoami_s)rCr�r�rrrr��szSimpleLDAPObject.whoami_scCs0|j|jj|�}|tjks$|tjkr,t|�}|S)N)r�r=rqr1�OPT_SERVER_CONTROLS�OPT_CLIENT_CONTROLSr
)rC�optionr|rrrrq�szSimpleLDAPObject.get_optioncCs.|tjks|tjkrt|�}|j|jj||�S)N)r1r�r�rr�r=r�)rCr��invaluerrrr��szSimpleLDAPObject.set_optioncCs�|jrd}d}nd}d}|dkr$|}y|j|tjd|g�}Wn8tjtjtjfk
r`g}Yntjk
rtdSXyV|r�tjj|dd�}|j	|dg�d}|dkr�|r�|j
|d�SdSn
|j|�SWntk
r�dSXdS)	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.
    �ssubschemaSubentryriZsubschemaSubentryNrr)rd)
rAr�r1�
SCOPE_BASE�NO_SUCH_OBJECTZNO_SUCH_ATTRIBUTEZINSUFFICIENT_ACCESSZUNDEFINED_TYPEZcidictr"�search_subschemasubentry_sr]ru)rCrdZempty_dnZattrnamer�r}Zsearch_subschemasubentry_dnrrrr��s2
z+SimpleLDAPObject.search_subschemasubentry_sc	Cs2|j|tj|||||d�}|r*|ddSdSdS)z~
    Reads and returns a single entry specified by `dn'.

    Other attributes just like those passed to `search_ext_s()'
    )r�r�r�r?rrN)r�r1r�)rCrdr�r�r�r�r?r�rrr�read_s�szSimpleLDAPObject.read_scCsf|jr"d}|dkr2dd�tD�}nd}|dkr2t}y|j|||d�}Wntjk
r\dSX|SdS)z1
    Returns the sub schema sub entry's data
    s(objectClass=subschema)NcSsg|]}|jd��qS)zutf-8)rN)rSrUrrrrb�sz=SimpleLDAPObject.read_subschemasubentry_s.<locals>.<listcomp>z(objectClass=subschema))r�r�)rArr�r1r�)rCZsubschemasubentry_dnZattrsr�Zsubschemasubentryrrr�read_subschemasubentry_s�sz)SimpleLDAPObject.read_subschemasubentry_sc	
Cs@|j||||||||dd�	}	t|	�dkr8tdt|���|	dS)z@
    Returns a unique entry, raises exception if not unique
    r)r�r�r�r�r?r+rz%No or non-unique search result for %sr)r�r�r)rl)
rCr�r�r�r�r�r�r�r?r�rrr�find_unique_entrysz"SimpleLDAPObject.find_unique_entrycCs<|jrd}|pddg}nd}|p&ddg}|j|||d�}|S)zA
    convenience wrapper around read_s() for reading rootDSE
    r��*�+ri�*�+)r�r�)rAr�)rCr�r�r�Zldap_rootdserrr�read_rootdse_sszSimpleLDAPObject.read_rootdse_scCs&|jrd}nd}|j|gd�j|g�S)z�
    returns all attribute values of namingContexts in rootDSE
    if namingContexts is not present (not readable) then empty list is returned
    snamingContextsZnamingContexts)r�)rAr�r")rCr�rrr�get_naming_contexts&s
z$SimpleLDAPObject.get_naming_contexts)rNr,NNN)F)ri)NN)NN)NN)NN)NN)NNNN)NNNN)NN)NN)NN)NN)NN)NN)NNN)NN)NN)r)r)NN)NNF)NrNN)NrNNr0)NNrNNr0rr0)NNrNNr0r)NNr)NNrr0)NNrr0)NN)NN)NN)Nr0)NNNNr0)Nr0)NN)\rrrrr1ZOPT_PROTOCOL_VERSIONZ	OPT_DEREFZ
OPT_REFERRALSZ
OPT_TIMELIMITZ
OPT_SIZELIMITZOPT_NETWORK_TIMEOUTZOPT_ERROR_NUMBERZOPT_ERROR_STRINGZOPT_MATCHED_DNr�rHrRr[r]r^rcrhr5r�r�r�r.r�r�r�r�r�r�r�r�r�r�ZAUTH_SIMPLEr�r�Z
SASL_QUIETr�r�r�r�r�r�r�r�r�r�r�r�r�r�ZRES_ANYr�r�r�r�r�r�r�r�r�r�r�r�r|r�r�r�r�r�r�r�r�r�rmr�r�r�r�rqr�r�r�r�Z
SCOPE_SUBTREEr�r�r�rrrrrMs�

,1

-







	









	






6
H



	




,


c@s�eZdZdZdddddhZd<dd
�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zd=dd�Zdd�Z
dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�ZdS)>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.
  r=r6r3�_reconnect_lock�
_last_bindrNr,r�N@c


Cs^||_g|_d|_tj||||||||	d�tjdt|�d�|_||_	||_
d|_d|_dS)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)rBr.zreconnect lock within %s)rjr)
r4�_optionsr�rrHr1rkrlr��
_retry_max�_retry_delay�
_start_tls�_reconnects_done)
rCrDrErFrGrArB�	retry_max�retry_delayr.rrrrHNszReconnectLDAPObject.__init__cs>�fdd��jj�D�}�jdj�jd�jdf|d<|S)z-return data representation for pickled objectcs i|]\}}|�jkr||�qSr)�__transient_attrs__)rS�k�v)rCrrraksz4ReconnectLDAPObject.__getstate__.<locals>.<dictcomp>rrrr�)r�r_r�r)rC�stater)rCr�__getstate__is
"z ReconnectLDAPObject.__getstate__cCs�|jd�}|r|jdd�n|jdd�|jj|�tt|jd�|jd|jdf|_|j�|_t	j
dt|�d	�|_t	j
|_
|j|j�d
S)z#set up the object from pickled dataZbytes_mode_hardfailrBr/r%rrrzreconnect lock within %s)rjN)r"�
setdefaultr��update�getattrrr�r5r6r1rkrlr�r3�	reconnectr4)rC�dZhardfailrrr�__setstate__ss
$
z ReconnectLDAPObject.__setstate__cOs|||f|_dS)N)r�)rCr�rtr{rrr�_store_last_bind�sz$ReconnectLDAPObject._store_last_bindcCs:|jdkr(|j\}}}||f|�|�ntj|dd�dS)N)r�rr�)rCrzrtr{rrr�_apply_last_bind�s
z$ReconnectLDAPObject._apply_last_bindcCs&x |jD]\}}tj|||�qWdS)zRestore all recorded optionsN)r�rr�)rCrrrrr�_restore_options�sz$ReconnectLDAPObject._restore_optionscOs|jtjf|�|�S)N)�_apply_method_srr�)rCrtr{rrrr��szReconnectLDAPObject.passwd_scCs~|jj��z`|}�xT|�rhd||d|f}drR|jdkrR|jjd||f�yby:tjjtjt	j
|�|_|j�|j
r�tj|�|j�Wn"tjk
r�tj|��YnXWn|tjtjfk
�r0dr�|jdkr�|jjd||f�|d}|�s�d�r"|jdk�r"|jjd|�tj|�YqXd�rX|jdk�rX|jjd||f�|jd|_PqWWd|jj�XdS)Nz%d. (of %d)rFz!*** Trying %s reconnect to %s...
z*** %s reconnect to %s failed
z=> delay %s...
z;*** %s reconnect to %s successful => repeat last operation
)r�rpr2r3rvr1r:r;r<r8r>r=rrrr�rrr��SERVER_DOWNZTIMEOUT�timeZsleeprrr)rCrDrrZreconnect_counterZcounter_textrrrr�sF




zReconnectLDAPObject.reconnectcOsxt|d�s |j|j|j|jd�y||f|�|�Stjk
rrtj|�|j|j|j|jd�||f|�|�SXdS)Nr=)rr)	r7rr4r�r�r1rrr�)rCrzrtr{rrrr�s

z#ReconnectLDAPObject._apply_method_scCs|jj||f�tj|||�S)N)r��appendrr�)rCr�r�rrrr��szReconnectLDAPObject.set_optioncOs,|jtjf|�|�}|jtjf|�|�|S)N)rrr�r)rCrtr{r�rrrr��szReconnectLDAPObject.bind_scOs,|jtjf|�|�}|jtjf|�|�|S)N)rrr�r)rCrtr{r�rrrr��sz!ReconnectLDAPObject.simple_bind_scOs|jtjf|�|�}d|_|S)Nr)rrr�r)rCrtr{r�rrrr��szReconnectLDAPObject.start_tls_scOs,|jtjf|�|�}|jtjf|�|�|S)z4
    sasl_interactive_bind_s(who, auth) -> None
    )rrr�r)rCrtr{r�rrrr��sz+ReconnectLDAPObject.sasl_interactive_bind_scOs,|jtjf|�|�}|jtjf|�|�|S)N)rrr�r)rCrtr{r�rrrr��szReconnectLDAPObject.sasl_bind_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��szReconnectLDAPObject.add_ext_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��szReconnectLDAPObject.cancel_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��sz!ReconnectLDAPObject.compare_ext_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��sz ReconnectLDAPObject.delete_ext_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��szReconnectLDAPObject.extop_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr��sz ReconnectLDAPObject.modify_ext_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr�szReconnectLDAPObject.rename_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr�sz ReconnectLDAPObject.search_ext_scOs|jtjf|�|�S)N)rrr�)rCrtr{rrrr�szReconnectLDAPObject.whoami_s)rNr,NNrr�N)rr�)rrrrrrHrrrrrr�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	4s>


/)-rZ
__future__r�osrZldap.pkginforrr�__all__rrryr8r1Z	ldap.saslZldap.functionsr$Zldap.schemarZ
ldap.controlsrr
rZ
ldap.extoprrrZldap.compatrr�version_infor@rOZ	text_typerxr�BytesWarningr
r(r�r)rr	rrrrr�<module>sB8n[