
    =OOf!.                         d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZmZmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZ  G d de      Z y)
    )linesep   )AttrDef   )LDAPKeyErrorLDAPObjectErrorLDAPAttributeErrorLDAPSchemaError)STRING_TYPESSEQUENCE_TYPESServer
Connection)
SchemaInfoconstant_to_class_kind)find_attribute_validator)CaseInsensitiveWithAliasDict)get_config_parameter)loglog_enabledERRORBASICPROTOCOLEXTENDEDc                       e 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eeurd Znd Zd ZddZddZd Zd Zy)	ObjectDefaC  Represent an object in the LDAP server. AttrDefs are stored in a dictionary; the key is the friendly name defined in AttrDef.

    AttrDefs can be added and removed using the += and -= operators

    ObjectDef can be accessed either as a sequence and a dictionary. When accessed the whole AttrDef instance is returned

    Nc                    |g }t        |t              s|g}|g }t        |t              s|g}t               | j                  d<   || j                  d<   g | j                  d<   t        |t              r(|j
                  s|j                  r|j                          |t        |t              r|j                  }nht        |t              r|j                  j                  }nAt        |t              rn0|r.d}t        t              rt        t        d||        t        |      |.d}t        t              rt        t        d||        t        |      || j                  d<   | j                   r|D cg c]  }|j"                  |   j$                  d     }}|D cg c]  }|j"                  |   j$                  d     }}|D ]  }|s| j'                  |        |D ]  }|s| j'                  |        || j                  d	<   || j                  d
<   t        t(              rt        t(        d|        y y c c}w c c}w )N_attributes_custom_validator	_oid_infozunable to read schema%s for <%s>zschema not present_schemar   _object_class_auxiliary_classzinstantiated ObjectDef: <%r>)
isinstancer   r   __dict__r   _deferred_bind_deferred_open_fire_deferredr   schemaserverr   r   r   r   r   r"   object_classesname_populate_attr_defsr   )selfobject_classr*   custom_validatorauxiliary_classerror_messager-   object_names           Y/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/abstract/objectDef.py__init__zObjectDef.__init__.   s   L,7(>L" O/>:./O'C'Em$-=)*%'k"fj)v/D/DH]H]!!#&&)FJ/--FJ/ 7u%}mTB%m44~ 4u%}mTB%m44#)i <<LXYDF11$7<<Q?YLYO^_tv44T:??B_O_+ :,,[9:  / :,,[9: *6o&,;()u5t<  Z_s   2#H6#H;c                 n   || j                   j                  v r| j                   j                  |   }| j                  d   j                  |dz   t	        |j
                        z   dz   t        |j                        z          |j                  r"|j                  D ]  }| j                  |        |j                  D ]  }| j                  |d        |j                  D ]#  }|| j                  vs| j                  |d       % y d|z  }t        t              rt!        t        d||        t#        |      )Nr    z (z) TFz'object class '%s' not defined in schemar!   )r"   r,   r&   appendr   kindstroidsuperiorr.   must_containadd_from_schemamay_containr   r   r   r   r	   )r/   r4   object_schemasupattribute_namer3   s         r5   r.   zObjectDef._populate_attr_defsf   s8   $,,555 LL77DMMM+&--kD.@CYZgZlZlCm.mpt.twz  |I  |M  |M  xN  /N  O%%(11 2C,,S12"/"<"< ;$$^T:;"/";"; @!)9)99((?@ H+UM5!E=->!-00    c                    | j                   r&ddj                  | j                         z   t        z   }n	dt        z   }| j                  r)|ddj                  | j                        z   t        z   z  }n|dt        z   z  }|ddj                  | j                  D cg c]  }| c}      z   t        z   z  }|ddj                  t        | j                  D cg c]  }| j                  |   j                  s|  c}            z   t        z   z  }|ddj                  t        | j                  D cg c]  }| j                  |   j                  r|  c}            z   t        z   z  }|S c c}w c c}w c c}w )	NzOBJ : z, zOBJ : <None>zAUX : zAUX : <None>zOID: zMUST: zMAY : )r#   joinr   r$   r    sortedr   	mandatory)r/   rr;   attrs       r5   __repr__zObjectDef.__repr__y   sF   499T%7%7887BA(A  DIId&;&;<<wFFA'))A	Wtyy!@##!@AAGKK	X		&4;K;K)p4tO_O_`dOeOoOo$)p"qrru|||	X		&4;K;K)t4SWScScdhSiSsSs$)t"uvv  zA  A  	A	 "A)p)ts   	E'E,2E,,E1E1c                 "    | j                         S N)rJ   r/   s    r5   __str__zObjectDef.__str__   s    }}rC   c                 $    | j                  |      S rL   )__getattr__r/   items     r5   __getitem__zObjectDef.__getitem__   s    %%rC   c                 p   dj                  |j                               j                         }d| j                  v r	 | j                  |   S d}t        t              rt        t        d||        t        |      # t
        $ r2 d|z  }t        t              rt        t        d||        t        |      w xY w)N r   key '%s' not presentr!   z)internal _attributes property not defined)
rE   splitlowerr&   r   KeyErrorr   r   r   r   )r/   rR   r3   s      r5   rP   zObjectDef.__getattr__   s    wwtzz|$**,DMM)2''-- HM5!E=->}--  2 84 ?u%}mTB"=11	2s   A: :;B5c                 d    d|z  }t        t              rt        t        d||        t        |      )Nzobject '%s' is read onlyr!   )r   r   r   r	   )r/   keyvaluer3   s       r5   __setattr__zObjectDef.__setattr__   s-    4s:u}mT:m,,rC   c                 (    | j                  |       | S rL   )add_attributer/   others     r5   __iadd__zObjectDef.__iadd__   s    5!rC   c                     t        |t              r| j                  |j                         | S t        |t              r| j                  |       | S rL   )r%   r   remove_attributer[   r   r`   s     r5   __isub__zObjectDef.__isub__   sD    eW%!!%)),  |,!!%(rC   c              #   P   K   | j                   D ]  }| j                   |     y wrL   )r   )r/   	attributes     r5   __iter__zObjectDef.__iter__   s,     )) 	.I""9--	.s   $&c                 ,    t        | j                        S rL   )lenr   rM   s    r5   __len__zObjectDef.__len__   s    4##$$rC   c                      yNT rM   s    r5   __bool__zObjectDef.__bool__       rC   c                      yrm   rn   rM   s    r5   __nonzero__zObjectDef.__nonzero__   rp   rC   c                 F    	 | j                  |       y# t        $ r Y yw xY w)NFT)rS   rY   rQ   s     r5   __contains__zObjectDef.__contains__   s.    	T"   		s    	  c                    t        |      }t        | j                  || j                        |_        ||_        | j                  rt| j                  j                  r^|| j                  j                  v rF| j                  j                  |   j                  |_        | j                  j                  |   |_        | j                  |       y rL   )
r   r   r"   r   validaterG   attribute_typessingle_valueoid_infor_   )r/   rB   rG   attr_defs       r5   r>   zObjectDef.add_from_schema   s    ~.H 8~W[WmWm nH!*H|| < <SWS_S_SoSoAo(,(D(D^(T(a(a%$(LL$@$@$P!x(rC   c                 x   t        d      D cg c]  }|j                          }}t        |t              r| j	                  |       yt        |t
              r|j                  j                         |vrc|j                  | j                  vr|| j                  |j                  <   |j                  rI|j                  |j                  k7  r0| j                  j                  |j                  |j                         |j                  rP|j                  j                  D cg c]0  }|j                  j                         |j                         k7  s/|2 c}nd}|r&| j                  j                  |j                  |       |j                  sJt        | j                  |j                  | j                        }|| j                  |j                     _        yyyt        |t              r|D ]  }| j!                  |        yd}t#        t$              rt'        t$        d||        t)        |      c c}w c c}w )zAdd an AttrDef to the ObjectDef. Can be called with the += operator.
        :param definition: the AttrDef object to add, can also be a string containing the name of attribute to add. Can be a list of both

        #ATTRIBUTES_EXCLUDED_FROM_OBJECT_DEFNz*unable to add element to object definitionr!   )r   rX   r%   r   r>   r   r[   r   r-   	set_aliasry   rv   r   r"   r   r   r_   r   r   r   r	   )	r/   
definitionv(conf_attributes_excluded_from_object_defr-   other_names	validatorelementr3   s	            r5   r_   zObjectDef.add_attribute   s   
 H\  ]B  HC  4D!AGGI  4D0  4Dj,/  ,
G,~~##%-UU>>)9)997AD$$Z^^4!:??jnn+L((22:>>:??S |F  |O  |OJ4G4G4L4L"wDPZP^P^PdPdPfjnjtjtjvPv4"w  UYK"((22:>>;O!** 8z~~W[WmWm nI@ID$$Z^^4= + V 
N3% ,""7+, IM5!E=->!-00/ 4D #xs   H2!0H7H7c                 (   d}t        |t              r.dj                  |j                               j	                         }n*t        |t
              r|j                  j	                         }|rd| j                  D ]$  }||j	                         k(  s| j                  |=  y d|z  }t        t              rt        t        d||        t        |      dt        t        |            z   }t        t              rt        t        d||        t        |      )zRemove an AttrDef from the ObjectDef. Can be called with the -= operator.
        :param item: the AttrDef to remove, can also be a string containing the name of attribute to remove

        NrU   rV   r!   z$key type must be str or AttrDef not )r%   r   rE   rW   rX   r   r[   r   r   r   r   r   r:   typer
   )r/   rR   r[   rI   r3   s        r5   rd   zObjectDef.remove_attribute   s    
 dL)''$**,'--/Cg&((.."C(( 2$**,&((.2
 !93 >u%}mTB"=11BSd_TM5!E=->$]33rC   c                 n    d| j                   d<   d| j                   d<   t               | j                   d<   y)z,Empty the ObjectDef attribute list

        Nr0   r2   r   )r&   dictrM   s    r5   clear_attributeszObjectDef.clear_attributes  s1     )-n%+/'('+vm$rC   )NNNN)FrL   )__name__
__module____qualname____doc__r6   r.   rJ   rN   rS   rP   r]   rb   re   rh   rk   r:   bytesro   rr   rt   r>   r_   rd   r   rn   rC   r5   r   r   &   sl    6=p1&&. -.% %		)1<46.rC   r   N)!r   osr   attrDefr   core.exceptionsr   r	   r
   r   rU   r   r   r   r   protocol.rfc4512r   r   protocol.formatters.standardr   utils.ciDictr   utils.configr   	utils.logr   r   r   r   r   r   objectr   rn   rC   r5   <module>r      s>   2   ` ` ? ? A C 7 / J Jh. h.rC   