
    擖g1              
          S SK r S SKrS SKrS SKrS SKJr  SS jrSS jrSS\ R                  S:H  4S jr	S	S
SSSSSS.r
\R                  " SSR                  \" \R                  \
R                  5       5      5      -  5      rSS jrg)    N)reduceutf-8Fc                 x    SU-  /nU(       a  UR                  S5        [        X0U5        SR                  U5      $ )a>  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 7ABI)f5 779    c                 V   U(       a  SU-  nSnOSnSnUS   n[        U[        5      (       d  [        S[        U5      -   5      eU R                  US-   U-   5        USS nU(       ab  [        US   [        5      (       aJ  [        US   R                  5       5       H%  u  pU R                  S	U S
[        U	SS9 S35        M'     USS nU(       a  U R                  S5        [        S US5      n
U
(       + nU(       a  U(       a  U R                  U5        U HC  n[        U[        5      (       a  U R                  [        U5      5        M4  [        XX#S-   5        ME     U(       a  U(       a  U R                  U5        U R                  SU SU 35        gU R                  SU-  5        g)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                 4    U =(       a    [        U[        5      $ )N)
isinstancestr)xys     r   <lambda>'_ConstructContentList.<locals>.<lambda>\   s    !*B
1c0B*Br   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    UlDdC  ,.1-.@A
 	
 [3&-. D
47D))d1gmmo.GBqBz#D'A&B!DE /ABxBD$O$_
(X&J *c**  J!78%iVQYO  +[)2dV1XJ/0(*+r   win32c                 r   [        XU5      nU(       a&  [        R                  S:w  a  UR                  SS5      n [        R
                  " 5       S   nU(       a3  UR                  5       UR                  5       :w  a  UR                  U5      n [        U5       nUR                  5       nSSS5        WU:w  a'  [        US5       nUR                  U5        SSS5        gg! [         a    [        R                  " 5       n Nf = f! , (       d  f       Na= f! [         a    Sn Nrf = f! , (       d  f       g= f)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   Nwb)r   oslinesepreplacelocalegetdefaultlocaleAttributeErrorgetencodingupperencodeopenreadOSErrorwrite)	r   pathr   r   r0   
xml_stringdefault_encodingfileexistings	            r   WriteXmlIfChangedrE   n   s    W7Jv%''f5
0!224Q7 ,2248HH&&x0
$Z4yy{H  :$JJz"    0!--/0 Z 
 sM   C  D D*D D( DD
DD D D%$D%(
D6z&quot;z&apos;z&lt;z&gt;z&amp;z&#xA;z&#xD;)r   'r   r   &r   z(%s)|c                 :   ^ U4S jn[         R                  X 5      $ )z%Escape a string for inclusion in XML.c                    > U R                   U R                  5       U R                  5        nT(       a  US:X  a  U$ [        U   $ )NrF   )stringstartend_xml_escape_map)matchmr   s     r   r5   _XmlEscape.<locals>.replace   s8    LL5AHHq!!r   )_xml_escape_resub)valuer   r5   s    ` r   r$   r$      s    " g--r   )r   F)r   )F)sysrer3   r6   	functoolsr   r   r	   platformrE   rO   compiler
   mapescapekeysrS   r$    r   r   <module>r_      s   
  	 	  -`/,d /6e \\W4 #H 
				

 FSXXc"))_=Q=Q=S.T%UUV
.r   