
    ?De(                         d Z ddlmZ ddlZej        ek    sJ  ede dej         d                      ddlZd ZddZd	 Z	ddZ
ddZddZdS )zs
dn.py - misc stuff for handling distinguished names (see RFC 4514)

See https://www.python-ldap.org/ for details.
    )__version__Nzldap z and _ldap z version mismatch!c                 L   | r |                      dd          } |                      dd          } |                      dd          } |                      dd          } |                      d	d
          } |                      dd          } |                      dd          } |                      dd          } |                      dd          } | d         dk    rd                    | dd         df          } | d         dk    s| d         dk    rd                    d| f          } | S )za
  Escape all DN special characters found in s
  with a back-slash (see RFC 4514, section 2.4)
  \z\\,z\,+z\+"z\"<z\<>z\>;z\;=z\= z\   Nz\ r   #)replacejoin)ss    /./ldap/dn.pyescape_dn_charsr      s   
  			$vA			#uA			#uA			#uA			#uA			#uA			#uA			#uA			&(##Auczz
''1SbS6%.
!
!atSyyAaD#II
''4(

a	
(    c                 b    | sg S t           j                            dt          j        | |          S )z
  This function takes a DN as string as parameter and returns
  a decomposed DN. It's the inverse to dn2str().

  flags describes the format of the dn

  See also the OpenLDAP man-page ldap_str2dn(3)
  N)ldap	functions_ldap_function_call_ldapstr2dn)dnflagss     r   r   r   %   s/     
 I		+	+Db	G	GGr   c                 @    d                     d | D                       S )z
  This function takes a decomposed DN as parameter and returns
  a single string. It's the inverse to str2dn() but will always
  return a DN in LDAPv3 format compliant to RFC 4514.
  r   c                 L    g | ]!}d                      d |D                       "S )r   c                 b    g | ],\  }}}d                      |t          |pd          f          -S r   r   r   r   .0atypeavaluedummys       r   
<listcomp>z%dn2str.<locals>.<listcomp>.<listcomp>:   sK     % % %
%u 
hhofl33455% % %r   r   )r&   rdns     r   r*   zdn2str.<locals>.<listcomp>9   sT        	 HH % % #% % % & &  r   r+   )r   s    r   dn2strr-   3   s8     
   	   
 
 r   Fc                 
   | sg S t          | |          }g }|D ]i}|r3|                    d                    d |D                                  7|                    d                    d |D                                  j|S )a  
  explode_dn(dn [, notypes=False [, flags=0]]) -> list

  This function takes a DN and breaks it up into its component parts.
  The notypes parameter is used to specify that only the component's
  attribute values be returned and not the attribute types.
  r   c                 8    g | ]\  }}}t          |pd           S r   )r   r%   s       r   r*   zexplode_dn.<locals>.<listcomp>N   s:          E& 	"%%     r   c                 b    g | ],\  }}}d                      |t          |pd          f          -S r#   r$   r%   s       r   r*   zexplode_dn.<locals>.<listcomp>S   sK          E& 	%"55677     r   )r   appendr   )r   notypesr   	dn_decomprdn_listr,   s         r   
explode_dnr6   @   s     
 IR)( 

 

c 	
oochh    "%      	 	 
 
 
 

 oochh    "%      	 	 
 
 
 
 
/r   c                 j    | sg S t          | |          d         }|rd |D             S d |D             S )a  
  explode_rdn(rdn [, notypes=0 [, flags=0]]) -> list

  This function takes a RDN and breaks it up into its component parts
  if it is a multi-valued RDN.
  The notypes parameter is used to specify that only the component's
  attribute values be returned and not the attribute types.
  r   c                     g | ]
\  }}}|pd S r0    r%   s       r   r*   zexplode_rdn.<locals>.<listcomp>g   s#    >>>/U6%FLb>>>r   c                 b    g | ],\  }}}d                      |t          |pd          f          -S r#   r$   r%   s       r   r*   zexplode_rdn.<locals>.<listcomp>i   s<    aaa@RfUCHHeOFLb99:;;aaar   )r   )r,   r3   r   
rdn_decomps       r   explode_rdnr<   Z   sW     
 Ic%  #* b>>:>>>>aaV`aaaar   c                 J    	 t          | |           dS # t          $ r Y dS w xY w)z}
  Returns True if `s' can be parsed by ldap.dn.str2dn() as a
  distinguished host_name (DN), otherwise False is returned.
  TF)r   	Exception)r   r   s     r   is_dnr?   l   s?    

1UOOO 4 
   55s    
"")r   )Fr   )__doc__ldap.pkginfor   r   ImportErrorldap.functionsr   r   r   r-   r6   r<   r?   r9   r   r   <module>rD      s    
 % $ $ $ $ $ +%%%{X;XX53DXXXYY &%%      ,H H H H     4b b b b$
 
 
 
 
 
r   