ó
ÓnäZc           @   sÆ   d  d l  Z  d  d l Z d  d l Z d e d „ Z d d „ Z d e e d „ Z i d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6Z e  j d d j	 e
 e  j e j ƒ  ƒ ƒ ƒ Z e d „ Z d S(   iÿÿÿÿNs   utf-8c         C   s@   d | g } | r# | j  d ƒ n  t | |  | ƒ d j | ƒ S(   sy   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.
  s#   <?xml version="1.0" encoding="%s"?>s   
t    (   t   appendt   _ConstructContentListt   join(   t   contentt   encodingt   prettyt	   xml_parts(    (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyt   XmlToString
   s
    'i    c         C   sÉ  | r d | } d } n d } d } | d } t  | t ƒ sW t d t | ƒ ƒ ‚ n  |  j | d | ƒ | d } | ræ t  | d t ƒ ræ xG t | d j ƒ  ƒ D]/ \ } }	 |  j d | t |	 d	 t ƒf ƒ q¦ W| d } n  | r´|  j d
 ƒ t	 d „  | t ƒ }
 |
 } | r1| r1|  j | ƒ n  xJ | D]B } t  | t ƒ rc|  j t | ƒ ƒ q8t
 |  | | | d ƒ q8W| rš| rš|  j | ƒ n  |  j d | | f ƒ n |  j d | ƒ d S(   s+   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.
  s     s   
R    i    sR   The first item of an EasyXml specification should be a string.  Specification was t   <i   s    %s="%s"t   attrt   >c         S   s   |  o t  | t ƒ S(   N(   t
   isinstancet   str(   t   xt   y(    (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyt   <lambda>X   R    s   </%s>%ss   />%sN(   R   R   t	   ExceptionR   t   dictt   sortedt	   iteritemst
   _XmlEscapet   Truet   reduceR   (   R   t   specificationR   t   levelt   indentationt   new_linet   namet   restt   att   valt   all_stringst
   multi_linet
   child_spec(    (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyR   :   s:    

	

#'c   	      C   s÷   t  |  | | ƒ } | r< t j d k r< | j d d ƒ } n  t j ƒ  d } | r… | j ƒ  | j ƒ  k r… | j | ƒ j | ƒ } n  y) t	 | d ƒ } | j
 ƒ  } | j ƒ  Wn d } n X| | k ró t	 | d ƒ } | j | ƒ | j ƒ  n  d S(   s:   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.
  s   
s   
i   t   rt   wN(   R   t   ost   linesept   replacet   localet   getdefaultlocalet   uppert   decodet   encodet   opent   readt   closet   Nonet   write(	   R   t   pathR   R   t   win32t
   xml_stringt   default_encodingt   ft   existing(    (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyt   WriteXmlIfChangedj   s     

s   &quot;t   "s   &apos;t   's   &lt;R	   s   &gt;R   s   &amp;t   &s   &#xA;s   
s   &#xD;s   s   (%s)t   |c            s   ‡  f d †  } t  j | |  ƒ S(   s&    Escape a string for inclusion in XML.c            s:   |  j  |  j ƒ  |  j ƒ  !} ˆ  r2 | d k r2 | St | S(   NR:   (   t   stringt   startt   endt   _xml_escape_map(   t   matcht   m(   R
   (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyR'   œ   s    (   t   _xml_escape_ret   sub(   t   valueR
   R'   (    (   R
   s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyR   š   s    (   t   reR%   R(   t   FalseR   R   R8   R@   t   compileR   t   mapt   escapet   keysRC   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/gyp/easy_xml.pyt   <module>   s"   00 
(