File: //proc/self/root/lib/python3.6/site-packages/gyp/__pycache__/easy_xml.cpython-36.pyc
3
��S]> � @ s� d dl Z d dlZd dlZd dlZye W n ek
rH d dlmZ Y nX ddd�Zddd�Zdd d
�Z ddd
ddddd�Z
e jddje
e je
j� �� �Zddd�ZdS )� N)�reduce�utf-8Fc C s. d| g}|r|j d� t|| |� dj|�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_parts� r
�/usr/lib/python3.6/easy_xml.py�XmlToString s
'
r c
C s` |rd| }d}nd}d}|d }t |t�s<tdt|� ��| j|d | � |dd� }|r�t |d t�r�x6t|d j� �D ]"\}} | jd |t| d
d�f � q~W |dd� }|�rN| jd� td
d� |d
�}
|
}|r�|r�| j|� x:|D ]2}t |t��r| jt|�� q�t | |||d � q�W |�r:|�r:| j|� | jd||f � n| jd| � dS )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 �<� Nz %s="%s"T)�attr�>c S s | ot |t�S )N)�
isinstance�str)�x�yr
r
r �<lambda>^ s z'_ConstructContentList.<locals>.<lambda>z</%s>%sz/>%s)
r r � Exceptionr �dict�sorted�items�
_XmlEscaper r )
r Z
specificationr �levelZindentationZnew_line�name�restZat�valZall_stringsZ
multi_lineZ
child_specr
r
r r @ s:
r c C s� t | ||�}|rptjdkrp|jdd�}tj� d }|rp|j� |j� krpy|j|�j|�}W n t k
rn Y nX yt
|d�}|j� }|j� W n d}Y nX ||kr�t
|d�}|j
|� |j� dS )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�localeZgetdefaultlocale�upper�decode�encode�AttributeError�open�read�close�write) r �pathr
r Zwin32Z
xml_stringZdefault_encoding�fZexistingr
r
r �WriteXmlIfChangedp s&