a
    /§»aE  ã                   @   s   d Z G dd„ dƒZdS )z0Simple class to generate a well-formed XML file.c                   @   sL   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zddd„Zdd„ Z	dd„ Z
dS )Ú	XmlWriterzÔ
    xml writer class.

    Parameters
    ----------
    filepath : str
        Path to the xml file.
    addDeclaration : bool, optional
        Whether to add the declaration.
        The default is True.
    Tc                 C   s(   t |dƒ| _d| _g | _|r$|  ¡  d S )NÚwbF)ÚopenÚstreamÚopenTagÚcurrentÚaddDeclaration)ÚselfÚfilepathr   © r
   úD/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/pyevtk/xml.pyÚ__init__)   s
    zXmlWriter.__init__c                 C   s   | j r
J ‚| j ¡  dS )zClose the file.N)r   r   Úclose©r   r
   r
   r   r   0   s    
zXmlWriter.closec                 C   s   | j  d¡ dS )zAdd xml declaration.s   <?xml version="1.0"?>N)r   Úwriter   r
   r
   r   r   5   s    zXmlWriter.addDeclarationc                 C   sB   | j r| j d¡ d| }| j t |¡¡ d| _ | j |¡ | S )zOpen a new xml element.ó   >z
<%sT)r   r   r   ÚstrÚencoder   Úappend©r   ÚtagÚstr
   r
   r   ÚopenElement9   s    zXmlWriter.openElementNc                 C   sj   |rJ| j  ¡ |ksJ ‚| jr.| j d¡ d| _d| }| j t |¡¡ n| j d¡ d| _| j  ¡  | S )a  
        Close the current element.

        Parameters
        ----------
        tag : str, optional
            Tag of the element.
            The default is None.

        Returns
        -------
        XmlWriter
            The XmlWriter itself for chained calles.
        r   Fz
</%s>s   />)r   Úpopr   r   r   r   r   r   r
   r
   r   ÚcloseElementC   s    
zXmlWriter.closeElementc                 C   s.   | j r| j d¡ d| _ | j t |¡¡ | S )zÖ
        Add text.

        Parameters
        ----------
        text : str
            Text to add.

        Returns
        -------
        XmlWriter
            The XmlWriter itself for chained calles.
        s   >
F©r   r   r   r   r   )r   Útextr
   r
   r   ÚaddText_   s
    zXmlWriter.addTextc                 K   s:   | j s
J ‚|D ]&}d||| f }| j t |¡¡ q| S )zæ
        Add attributes.

        Parameters
        ----------
        **kwargs
            keys as attribute names.

        Returns
        -------
        XmlWriter
            The XmlWriter itself for chained calles.
        z %s="%s"r   )r   ÚkwargsÚkeyr   r
   r
   r   ÚaddAttributess   s
    
zXmlWriter.addAttributes)T)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r
   r
   r
   r   r      s   


r   N)r#   r   r
   r
   r
   r   Ú<module>   s   