
    "Kb>              
       
   d dl Z d dlZd dlZd dlZ	 e ddZddZ	 	 ddZ	dddd	d
dddZ
 e j                  ddj                   ee j                  e
j                                     z        ZddZy# e$ r	 d dlmZ Y mw xY w)    N)reducec                 p    d|z  g}|r|j                  d       t        || |       dj                  |      S )ay   Writes the XML content to disk, touching the file only if it has changed.

  Visual Studio files have a lot of pre-defined structures.  This function makes
  it easy to represent these structures as Python data structures, instead of
  having to create a lot of function calls.

  Each XML element of the content is represented as a list composed of:
  1. The name of the element, a string,
  2. The attributes of the element, a dictionary (optional), and
  3+. The content of the element, if any.  Strings are simple text nodes and
      lists are child elements.

  Example 1:
      <test/>
  becomes
      ['test']

  Example 2:
      <myelement a='value1' b='value2'>
         <childtype>This is</childtype>
         <childtype>it!</childtype>
      </myelement>

  becomes
      ['myelement', {'a':'value1', 'b':'value2'},
         ['childtype', 'This is'],
         ['childtype', 'it!'],
      ]

  Args:
    content:  The structured content to be converted.
    encoding: The encoding to report on the first XML line.
    pretty: True if we want pretty printing with indents and new lines.

  Returns:
    The XML content as a string.
  z#<?xml version="1.0" encoding="%s"?>
 )append_ConstructContentListjoin)contentencodingpretty	xml_partss       ./usr/lib/python3/dist-packages/gyp/easy_xml.pyXmlToStringr      s@    N 5x?@)T	7F3 
	    c           
         |rd|z  }d}nd}d}|d   }t        |t              st        dt        |      z         | j                  |dz   |z          |dd }|r_t        |d   t              rLt        |d   j                               D ](  \  }}	| j                  d	|d
t        |	d      d       * |dd }|r| j                  d       t        d |d      }
|
 }|r|r| j                  |       |D ]>  }t        |t              r| j                  t        |             .t        | |||dz          @ |r|r| j                  |       | j                  d|d|       y| j                  d|z         y)a+   Appends the XML parts corresponding to the specification.

  Args:
    xml_parts: A list of XML parts to be appended to.
    specification:  The specification of the element.  See EasyXml docs.
    pretty: True if we want pretty printing with indents and new lines.
    level: Indentation level.
  z  r   r   r   zRThe first item of an EasyXml specification should be a string.  Specification was <   N z="T)attr">c                 *    | xr t        |t              S )N)
isinstancestr)xys     r   <lambda>z'_ConstructContentList.<locals>.<lambda>^   s    a&>Jq#,> r   z</z/>%s)
r   r   	Exceptionr   dictsorteditems
_XmlEscaper   r   )r   specificationr   levelindentationnew_linenamerestatvalall_strings
multi_line
child_specs                r   r   r   @   s    ,KHKH	q	$	D#	
 469-6HI J J;$t+, 
qr	$	ja$'$q'--/* FCRCd)CDEF8D	S>dKK Jhx  H
 
J	$
:./iVUQYGH k{#$12Vh&'r   c                    t        | ||      }|rt        j                  dk7  rm|j                  dd      }t	        j
                         d   }|rB|j                         |j                         k7  r!	 |j                  |      j                  |      }	 t        |d      }|j                         }|j                          ||k7  r.t        |d      }|j                  |       |j                          yy# t        $ r Y lw xY w#  d}Y IxY w)a:   Writes the XML content to disk, touching the file only if it has changed.

  Args:
    content:  The structured content to be written.
    path: Location of the file.
    encoding: The encoding to report on the first line of the XML file.
    pretty: True if we want pretty printing with indents and new lines.
  z
r   r   rNw)r   oslinesepreplacelocalegetdefaultlocaleupperdecodeencodeAttributeErroropenreadclosewrite)	r
   pathr   r   win32
xml_stringdefault_encodingfexistings	            r   WriteXmlIfChangedrD   p   s     7Hf5*
rzzV###D&1J..03,2248HH&&'78??I

T3AvvxHGGI
 T3AGGJGGI   Hs   0 C1 ,D  1	C=<C= Dz&quot;z&apos;z&lt;z&gt;z&amp;z&#xA;z&#xD;)r   'r   r   &r   z(%s)|c                 :    fd}t         j                  ||       S )z& Escape a string for inclusion in XML.c                 ~    | j                   | j                         | j                          }r|dk(  r|S t        |   S )NrE   )stringstartend_xml_escape_map)matchmr   s     r   r3   z_XmlEscape.<locals>.replace   s8    U[[]UYY[1ASh1r   )_xml_escape_resub)valuer   r3   s    ` r   r"   r"      s     
		GU	++r   )utf-8F)r   )rT   FF)F)rer1   r4   sysr   	NameError	functoolsr   r   rD   rN   compiler	   mapescapekeysrQ   r"    r   r   <module>r^      s   
 
 	  
-`-(` ?D! H 
				

 
SXXc"))_%9%9%;<==?,k  s   A4 4BB