
    b                         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dS )    N)Element
SubElement)ConfigParser)StringIO)GPParserENTITY_USER_IDc                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 ZdS )
GPIniParserNc                     t          t          j        d           | _        t          | j        _        | j                            t          |                    | j	                                       d S )N	dict_typeinterpolation)
r   collectionsOrderedDictini_confstroptionxformreadfpr   decodeencoding)selfcontentss     7/usr/lib/python3/dist-packages/samba/gp_parse/gp_ini.pyparsezGPIniParser.parse#   s\    ${/F379 9 9$'!Xhoodm&D&DEEFFFFF    c                     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+   sB    ;44&&5'**
r   c                     |                     d          j        }|                     d          j        }|d}| j                            |||           ||fS )Nr   r    )findr    r   set)r   	param_xmlr"   r&   r'   s        r   load_xml_parameterzGPIniParser.load_xml_parameter4   sX    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1!(vr   c                 T    |j         d         }| j                            |           |S )Nr1   r2   r   add_section)r   r!   section_names      r   load_xml_sectionzGPIniParser.load_xml_sectionC   s+    ")&1!!,///r   c           	      z   t          |d          5 }t          d          }| j                                        D ]R}|                     ||          }| j                            |d          D ]\  }}|                     ||||           S|                     ||           d d d            d S # 1 swxY w Y   d S )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3 6 600w??(,(;(;G(;(N(N 6 6$GW,,Wgw-46 6 6 66 !!$***
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+s   BB00B47B4c                    t          t          j        d           | _        t          | j        _        |                    d          D ]E}|                     |          }|                    d          D ]}|                     ||           Fd S )Nr   r0   r   )	r   r   r   r   r   r   findallr:   r.   )r   rE   sr9   params        r   load_xmlzGPIniParser.load_xmlZ   s    ${/F379 9 9$'!i(( 	= 	=A0033L;// = =''|<<<<=	= 	=r   c                     t          j        |d| j                  5 }| j                            |           d d d            d S # 1 swxY w Y   d S )Nzwb+)codecsr?   r   r   write)r   rC   rD   s      r   write_binaryzGPIniParser.write_binaryf   s    [5$-88 	#AM"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   AAA)__name__
__module____qualname__r   r   r(   r.   r5   r:   rF   rK   rO    r   r   r
   r
       s        HG G G        + + +"
= 
= 
=# # # # #r   r
   c                   "     e Zd ZdZ fdZ xZS )GPTIniParserzutf-8c                 R   	 t          t          |                               |           d S # t          $ ro t	          t
          j        d           | _        t          | j        _	        | j        
                    t          |                    d                               Y d S 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   s    		J,%%++H55555! 	J 	J 	J(;3J7;= = =DM(+DM% M  (//,*G*G!H!HIIIIII	Js   (- A5B&%B&)rP   rQ   rR   r   r   __classcell__rY   s   @r   rU   rU   k   sF        H
J 
J 
J 
J 
J 
J 
J 
J 
Jr   rU   c                        e Zd Z fdZ xZS )GPScriptsIniParserc                     t          t          |                               ||||          }t          j        d|          }||                    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|   st    0"$ $$7$7W8?%J %J 	 (>733!&&w//E+1EL(r   )rP   rQ   rR   r(   rZ   r[   s   @r   r]   r]   {   s8        
 
 
 
 
 
 
 
 
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          |                               ||||          }|                                dk    r|                    d          }|                    |           |                                                    d                              d          }|D ]#}t          |d          }	||	_	        d|	j
        d<   $n%|dk    r|                    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"$ $$7$7W8?%J %J 	 ==??222
  $$W--C  %%%}},,S1177<<H 1 1"=':: 
*0Y''1 *$$#((11-3
>*r   c                    |                                 dk    r|                    d          j        }|                    d          }t	          |          dk    r|d         j        dz   }nd                    d |D                       }| j                            |||           ||fS t          t          |           
                    ||          S )Nrh   r   r      r   ri   c                     g | ]	}|j         
S rS   )r    ).0xs     r   
<listcomp>z:GPFDeploy1IniParser.load_xml_parameter.<locals>.<listcomp>   s    !9!9!9Q!&!9!9!9r   )rl   r+   r    rH   lenjoinr   r,   rW   rf   r.   )r   r-   r"   r&   valuesr'   rY   s         r   r.   z&GPFDeploy1IniParser.load_xml_parameter   s    ==??222..'',C&&w//F6{{a q	,!9!9&!9!9!9::MgsE222< ( --iAA	Br   c                     t          |d          }|                                dk    rE|                                dk    r-|                    d          \  }}||j        d<   ||j        d<   n
||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   sy    Xy11MMOO333MMOOy((c**ID#-1GN>*,/GN=))%,GN6"r   c                     d|j         v r|j         d         }n"|j         d         }|j         d         }|dz   |z   }| j                            |           |S )Nr1   r~   r   r}   r7   )r   r!   r9   r   rq   s        r   r:   z$GPFDeploy1IniParser.load_xml_section   sc    ['''&-f5LL%n5D$]3C#:+L!!,///r   c                 H   g }|                     d          }|                    d            |D ]p}|j        d         }||v r	||         }nJ|                     |t                    }|                    ||f           |                    ||fg           ||j        d<   q|S )Nz.//Section[@fdeploy_SID]c                     | j         S )N)tag)rv   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00 	3 	3CM2J_,,,Z8

!00^LL
Z 8999&&Z(@'ABBB(2CJ}%%r   )	rP   rQ   rR   r(   r.   r5   r:   r   rZ   r[   s   @r   rf   rf      s            :B B B B 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      sF  (      				 5 5 5 5 5 5 5 5 % % % % % %       3 3 3 3 3 3 3 3H# H# H# H# H#( H# H# H#VJ J J J J; J J J        ^ ^ ^ ^ ^+ ^ ^ ^ ^ ^r   