
EUc           @   s   d  d l  Z  d   Z e  j d  Z d   Z d   Z d   Z d   Z d   Z e	 d	 k r d  d l
 Z
 y e
 j d
 Z Wn6 e k
 r e
 j d e
 j d IJe
 j d
  n Xe e  GHn  d S(   iNc         C   s   | } x} t  r |  j   } | d  d k rV | d k rC | d k sI t  | | } q	 | d k r{ | } | d k r Pq q	 | } Pq	 W| | f S(   s+   Read a line from an LDIF file, unfolding iti   t    t    s   
(   t   Truet   readlinet   AssertionError(   t   ft   buffert   linet   l(    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   __read_folded_line   s    	s   ^([A-Za-z][A-Za-z0-9-]*):c         c   s   d } x t  r g  } x t  r t |  |  \ } } | d  d k rI q n  | d k sa | d k re Pn  t j |  } | r | d d k r | d  } n  | j |  q t j d | It j d  q Wt |  r | Vn  | d k r	 Pq	 q	 Wd S(   s(   Read an LDIF entry, only unfolding linesR   i   t   #s   
is   Invalid line: %sN(	   R   R	   t   attr_type_ret   matcht   appendt   syst   stderrt   exitt   len(   R   R   t   entryR   t   m(    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   __read_raw_entries;   s(    		c         C   s?   |  j  d  d k r7 |  j d d  }  |  j d d  S|  Sd S(   s"   Fix a string DN to use ${CONFIGDN}s%   <Configuration NC Distinguished Name>is   
 R   s   ${CONFIGDN}N(   t   findt   replace(   t   dn(    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   fix_dn]   s    c         C   su   g  } x_ |  D]W } | d d k rE | j  d | d | d f  q | j  d | d | d f  q Wd j |  S(   s   Write out entry as LDIFi   i    s   %s: %si   s   %s:: %ss   
(   R   t   join(   R   t   outR   (    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   __write_ldif_onef   s    "#c         C   sW  g  } xD|  D]<} g  } | j  d  d k rP | j d d  } | j d  n | j d d  } | j d  | d j   } | d k r q n  | d k r q n  | d	 k r q n  | d
 k r q n  | d k r q n  | d k r q n  | d k r(| d j   j   j   } | d k r(q q(n  t | d  | d <| j |  q W| }  |  S(   s?   Perform required transformations to the Microsoft-provided LDIFs   ::is   :: i   s   : i    t
   changetypet   distinguishednamet   instancetypet   namet   cnt   objectcategoryt   showinadvancedviewonlyt   TRUE(   R   t   splitR   t   lowert   uppert   lstript   rstripR   (   R   t
   temp_entryR   t   tt   keyt   value(    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   __transform_entrys   s:    	c         C   sV   g  } t  |  d  } x- t |  D] } | j t t |    q" Wd j |  d S(   s0   Read and transform Microsoft-provided LDIF file.t   rUs   

(   t   openR   R   R   R-   R   (   t   filenameR   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   read_ms_ldif   s
    t   __main__i   s*   Usage: %s display-specifiers-ldif-file.txti    (   t   reR	   t   compileR   R   R   R   R-   R1   t   __name__R   t   argvt   display_specifiers_filet
   IndexErrorR   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/samba/ms_display_specifiers.pyt   <module>   s   	"	"				3	