�
�"Kb> �
� � d dl Z d dlZd dlZd dlZ e n# e$ r d dlmZ Y nw xY wdd�Zdd�Z dd�Z dd d
ddd
dd�Z
e j dd� e
e j e
� � � � � � � z � � Zdd�ZdS )� 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 5�x�?�@�)�� �
���T����� �7�F�3�3�3�
���� � �� c
� � |rd|z }d}nd}d}|d }t |t � � st dt |� � z � � �| � |dz |z � � |dd� }|r}t |d t � � rbt |d � � � � � D ]0\ }} | � d |�d
t | d�� � �d
�� � �1|dd� }|r�| � d� � t d� |d� � }
|
}|r|r| � |� � |D ]O}t |t � � r#| � t |� � � � �:t | |||dz � � �P|r|r| � |� � | � d|�d|��� � dS | � d|z � � 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 �<� N� z="T)�attr�"�>c �0 � | ot |t � � S )N)�
isinstance�str)�x�ys r �<lambda>z'_ConstructContentList.<locals>.<lambda>^ s � �a�&>�J�q�#�,>�,>� 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��H�H��K��H� �q� �$� �D�#� � � J�
� 4�69�-�6H�6H�I� J� J� J����;��$�t�+�,�,�,�
�q�r�r� �$� � �j��a��$�'�'� ��$�q�'�-�-�/�/�*�*� F� F���C�����R�R�R��C�d�)C�)C�)C�)C�)C�D�E�E�E�E�����8�D� � (�
���S�����>�>��d�K�K�K� ��J�� !�h� !����x� � � �� H� H�
�
�J�� $� $� H����
�:�.�.�/�/�/�/��i��V�U�Q�Y�G�G�G�G�� $�k� $����{�#�#�#�
����$�$�$���1�2�2�2�2�2�
���V�h�&�'�'�'�'�'r c �~ � t | ||� � }|r�t j dk r�|� dd� � }t j � � d }|rd|� � � |� � � k r: |� |� � � |� � }n# t $ r Y nw xY w t |d� � }|� � � }|� � � n # d}Y nxY w||k r;t |d� � }|�
|� � |� � � dS 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�locale�getdefaultlocale�upper�decode�encode�AttributeError�open�read�close�write) r �pathr r
�win32�
xml_string�default_encoding�f�existings r �WriteXmlIfChangedrE p sI � � �7�H�f�5�5�*�
�
�r�z�V�#�#��#�#�D�&�1�1�J��.�0�0��3���
�,�2�2�4�4����8H�8H�H�H�
��&�&�'7�8�8�?�?��I�I�
�
��
�
�
�
���
������T�3���A��v�v�x�x�H��G�G�I�I�I�I����H�H�H���� �����T�3���A��G�G�J�����G�G�I�I�I�I�I� �s � (B) �)
B6�5B6�:8C3 �3C9z"z'z<z>z&z
z
)r �'r r �&r �
z(%s)�|c �D �� �fd�}t � || � � S )z& Escape a string for inclusion in XML.c � �� | j | � � � | � � � � }�r|dk r|S t | S )NrF )�string�start�end�_xml_escape_map)�match�mr s �r r4 z_XmlEscape.<locals>.replace� sD �� �
��U�[�[�]�]�U�Y�Y�[�[�0�1�A�� ��S���
�h��1��r )�_xml_escape_re�sub)�valuer r4 s ` r r# r# � s4 �� �� � � � �
� � �G�U� +� +�+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
� � � � �
�
�� �� ���
�S�X�X�c�c�"�)�_�%9�%9�%;�%;�<�<�
=�
=�=�?� ?��,� ,� ,� ,� ,� ,s � �#�# |