
    "Kb>              
          d dl Z d dlZd dlZd dlZ	 e n# e$ r	 d dlmZ Y nw xY wddZddZ	 	 ddZ	dd	d
dddddZ
 e j        dd                     ee j        e
                                                    z            ZddZdS )    N)reduceutf-8Fc                     d|z  g}|r|                     d           t          || |           d                    |          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      sT    N 5x?@) T	7F333 
		    c           
         |rd|z  }d}nd}d}|d         }t          |t                    st          dt          |          z             |                     |dz   |z              |dd         }|r}t          |d         t                    rbt          |d                                                   D ]0\  }}	|                     d	|d
t          |	d          d           1|dd         }|r|                     d           t          d |d          }
|
 }|r|r|                     |           |D ]O}t          |t                    r#|                     t          |                     :t          | |||dz              P|r|r|                     |           |                     d|d|           dS |                     d|z             dS )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                 0    | o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	   @   sJ     ,KHHKH	q	$	D#		 J
 469-6H6HI J J J;$t+,,, 
qrr	$	 ja$'' $q'--//** F FCRRRCd)C)C)C)C)CDEEEE8D	 (S>>dKKK J !h !x    H H
 
J	$	$ H
:..////iVUQYGGGG $k ${###$$$122222Vh&'''''r   c                 ~   t          | ||          }|rt          j        dk    r|                    dd          }t	          j                    d         }|rd|                                |                                k    r:	 |                    |                              |          }n# t          $ r Y nw xY w	 t          |d          }|                                }|                                 n	#  d}Y nxY w||k    r;t          |d          }|                    |           |                                 dS dS )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   WriteXmlIfChangedrE   p   sI    7Hf55*
 rzV####D&11J.003 ,22448H8HHH&&'788??II

   T3AvvxxHGGIIIIHHH T3AGGJGGIIIII s    (B) )
B65B6:8C3 3C9z&quot;z&apos;z&lt;z&gt;z&amp;z&#xA;z&#xD;)r   'r   r   &r   z(%s)|c                 D    fd}t                               ||           S )z& Escape a string for inclusion in XML.c                     | j         |                                 |                                          }r|dk    r|S t          |         S )NrF   )stringstartend_xml_escape_map)matchmr   s     r   r4   z_XmlEscape.<locals>.replace   sD    U[[]]UYY[[01A Sh1r   )_xml_escape_resub)valuer   r4   s    ` r   r#   r#      s4         
		GU	+	++r   )r   F)r   )r   FF)F)rer2   r5   sysr   	NameError	functoolsr   r	   rE   rO   compiler
   mapescapekeysrR   r#    r   r   <module>r^      s6  
 
			 				  



&&   - - - -`-( -( -( -(` ?D!       H 
				

  
SXXcc")_%9%9%;%;<<===? ?, , , , , ,s    ##