
    h                         d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZ  G d de      Z G d d	e      Z G d
 de      Z G d de      Zy)    N)Element
SubElement)ConfigParser)StringIO)GPParserENTITY_USER_IDc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy)
GPIniParserNc                     t        t        j                  d       | _        t        | j                  _        | j                  j                  t        |j                  | j                                     y )N	dict_typeinterpolation)
r   collectionsOrderedDictini_confstroptionxform	read_filer   decodeencoding)selfcontentss     7/usr/lib/python3/dist-packages/samba/gp_parse/gp_ini.pyparsezGPIniParser.parse#   sI    ${/F/F379$'!)G HI    c                 j    t        |d      }t        |d      }t        |d      }||_        ||_        |S )N	ParameterKeyValue)r   text)r   section_xmlsectionkey_inival_inichildkeyvalues           r   build_xml_parameterzGPIniParser.build_xml_parameter+   s9    ;4&5'*
r   c                     |j                  d      j                  }|j                  d      j                  }|d}| j                  j                  |||       ||fS )Nr   r    )findr    r   set)r   	param_xmlr"   r&   r'   s        r   load_xml_parameterzGPIniParser.load_xml_parameter4   sT    nnU#((w',,=E'3.U|r   c                 <    t        |d      }||j                  d<   |S )NSectionname)r   attrib)r   root_xmlsec_inir"   s       r   build_xml_sectionzGPIniParser.build_xml_section=   s!    Xy1!(vr   c                 Z    |j                   d   }| j                  j                  |       |S )Nr1   r2   r   add_section)r   r!   section_names      r   load_xml_sectionzGPIniParser.load_xml_sectionC   s*    "))&1!!,/r   c           	      T   t        |d      5 }t        d      }| j                  j                         D ]M  }| j	                  ||      }| j                  j                  |d      D ]  \  }}| j                  ||||        O | j                  ||       d d d        y # 1 sw Y   y xY w)NwbIniFileT)raw)openr   r   sectionsr5   itemsr(   write_pretty_xml)r   filenamefrootr4   r"   r#   r$   s           r   	write_xmlzGPIniParser.write_xmlI   s    (D! 
	+Q9%D==113 600w?(,(;(;G(;(N 6$GW,,Wgw-4666 !!$*
	+ 
	+ 
	+s   BBB'c                    t        t        j                  d       | _        t        | j                  _        |j                  d      D ];  }| j                  |      }|j                  d      D ]  }| j                  ||        = y )Nr   r0   r   )	r   r   r   r   r   r   findallr:   r.   )r   rE   sr9   params        r   load_xmlzGPIniParser.load_xmlZ   su    ${/F/F379$'!i( 	=A003L;/ =''|<=	=r   c                     t        j                  |d| j                        5 }| j                  j	                  |       d d d        y # 1 sw Y   y xY w)Nzwb+)codecsr?   r   r   write)r   rC   rD   s      r   write_binaryzGPIniParser.write_binaryf   s?    [[5$--8 	#AMM"	# 	# 	#s   AA)__name__
__module____qualname__r   r   r(   r.   r5   r:   rF   rK   rO    r   r   r
   r
       s0    HJ+"
=#r   r
   c                   "     e Zd ZdZ fdZ xZS )GPTIniParserzutf-8c                    	 t         t        |   |       y # t        $ rk t	        t
        j                  d       | _        t        | j                  _	        | j                  j                  t        |j                  d                   Y y w xY w)Nr   z
iso-8859-1)superrU   r   UnicodeDecodeErrorr   r   r   r   r   r   r   r   r   )r   r   	__class__s     r   r   zGPTIniParser.parsen   sn    		M,+H5! 	M(;3J3J7;=DM(+DMM% MM##HX__\-J$KL	Ms    A1B
B)rP   rQ   rR   r   r   __classcell__rY   s   @r   rU   rU   k   s    H
M 
Mr   rU   c                        e Zd Z fdZ xZS )GPScriptsIniParserc                     t         t        |   ||||      }t        j                  d|      }| |j                  d      }d|j                  d<   |S )Nz\d+CmdLine$r   TRUEnetwork_path)rW   r]   r(   rematchr+   r2   )	r   r!   r"   r#   r$   parent_returncmdliner'   rY   s	           r   r(   z&GPScriptsIniParser.build_xml_parameter|   sb    0"88CW8?%J 	 ((>73!&&w/E+1ELL(r   )rP   rQ   rR   r(   rZ   r[   s   @r   r]   r]   {   s    
 
r   r]   c                   :     e Zd Z fdZ fdZd Zd Zd Z xZS )GPFDeploy1IniParserc                    t         t        |   ||||      }|j                         dk(  r{|j	                  d      }|j                  |       |j                         j                  d      j                  d      }|D ]$  }t        |d      }	||	_	        d|	j                  d<   & |S |dk(  r |j	                  d      }d|j                  d<   |S )Nfolder_redirectionr   ;r_   user_idFullPathr`   )rW   rf   r(   lowerr+   removestripsplitr   r    r2   )r   r!   r"   r#   r$   rc   r&   sid_listsidr'   rY   s             r   r(   z'GPFDeploy1IniParser.build_xml_parameter   s    1"88CW8?%J 	 ==?22
  $$W-C  %}},,S177<H 1"=': 
*0Y'1 	 *$#((1-3

>*r   c                    |j                         dk(  r|j                  d      j                  }|j                  d      }t	        |      dk(  r|d   j                  dz   }n)dj                  |D cg c]  }|j                   c}      }| j                  j                  |||       ||fS t        t        | +  ||      S c c}w )Nrh   r   r      r   ri   )rl   r+   r    rH   lenjoinr   r,   rW   rf   r.   )r   r-   r"   r&   valuesr'   xrY   s          r   r.   z&GPFDeploy1IniParser.load_xml_parameter   s    ==?22..',,C&&w/F6{a q	,&!9Q!&&!9:MMgsE2< (..7A	B ":s   1C c                     t        |d      }|j                         dk7  rG|j                         dk7  r4|j                  d      \  }}||j                  d<   ||j                  d<   |S ||j                  d<   |S )Nr0   rh   version_fdeploy_GUIDfdeploy_SIDr1   )r   rl   ro   r2   )r   r3   r4   r"   guidrq   s         r   r5   z%GPFDeploy1IniParser.build_xml_section   su    Xy1MMO33MMOy(c*ID#-1GNN>*,/GNN=)  &-GNN6"r   c                     d|j                   v r|j                   d   }n&|j                   d   }|j                   d   }|dz   |z   }| j                  j                  |       |S )Nr1   r{   r|   rz   r7   )r   r!   r9   r}   rq   s        r   r:   z$GPFDeploy1IniParser.load_xml_section   sf    ['''&--f5L%%n5D$$]3C#:+L!!,/r   c                 *   g }|j                  d      }|j                  d        |D ]g  }|j                  d   }||v r||   }n=| j                  |t              }|j                  ||f       |j                  ||fg       ||j                  d<   i |S )Nz.//Section[@fdeploy_SID]c                     | j                   S )N)tag)rw   s    r   <lambda>z5GPFDeploy1IniParser.custom_entities.<locals>.<lambda>   s
    !%% r   )r&   r|   )rH   sortr2   new_xml_entityr   appendupdate)r   rE   global_entitiesentitiesfdeploy_sidsrq   
old_attrib
new_attribs           r   custom_entitiesz#GPFDeploy1IniParser.custom_entities   s    ||$>?0 	3CM2J_,,Z8
!00^L
Z 89&&Z(@'AB(2CJJ}%	3 r   )	rP   rQ   rR   r(   r.   r5   r:   r   rZ   r[   s   @r   rf   rf      s    :B*
r   rf   )rM   r   ra   xml.etree.ElementTreer   r   configparserr   ior   samba.gp_parser   r   r
   rU   r]   rf   rS   r   r   <module>r      sS   (   	 5 %  3H#( H#VM; M  ^+ ^r   