§
    ™à˜cÓ  ã                   ó°   — d Z ddlmZ ddlmZ ej        Zddlm	Z	 	 e
 n# e$ r eZ
Y nw xY w	 e n# e$ r eZY nw xY w G d„ de¦  «        Z e¦   «         ZdS )z9
The ``E`` Element factory for generating XML documents.
é    )Úabsolute_importN©Úpartialc                   ó*   — e Zd ZdZ	 	 dd„Zd„ Zd„ ZdS )ÚElementMakerac  Element generator factory.

    Unlike the ordinary Element factory, the E factory allows you to pass in
    more than just a tag and some optional attributes; you can also pass in
    text and other elements.  The text is added as either text or tail
    attributes, and elements are inserted at the right spot.  Some small
    examples::

        >>> from lxml import etree as ET
        >>> from lxml.builder import E

        >>> ET.tostring(E("tag"))
        '<tag/>'
        >>> ET.tostring(E("tag", "text"))
        '<tag>text</tag>'
        >>> ET.tostring(E("tag", "text", key="value"))
        '<tag key="value">text</tag>'
        >>> ET.tostring(E("tag", E("subtag", "text"), "tail"))
        '<tag><subtag>text</subtag>tail</tag>'

    For simple tags, the factory also allows you to write ``E.tag(...)`` instead
    of ``E('tag', ...)``::

        >>> ET.tostring(E.tag())
        '<tag/>'
        >>> ET.tostring(E.tag("text"))
        '<tag>text</tag>'
        >>> ET.tostring(E.tag(E.subtag("text"), "tail"))
        '<tag><subtag>text</subtag>tail</tag>'

    Here's a somewhat larger example; this shows how to generate HTML
    documents, using a mix of prepared factory functions for inline elements,
    nested ``E.tag`` calls, and embedded XHTML fragments::

        # some common inline elements
        A = E.a
        I = E.i
        B = E.b

        def CLASS(v):
            # helper function, 'class' is a reserved word
            return {'class': v}

        page = (
            E.html(
                E.head(
                    E.title("This is a sample document")
                ),
                E.body(
                    E.h1("Hello!", CLASS("title")),
                    E.p("This is a paragraph with ", B("bold"), " text in it!"),
                    E.p("This is another paragraph, with a ",
                        A("link", href="http://www.python.org"), "."),
                    E.p("Here are some reserved characters: <spam&egg>."),
                    ET.XML("<p>And finally, here is an embedded XHTML fragment.</p>"),
                )
            )
        )

        print ET.tostring(page)

    Here's a prettyprinted version of the output from the above script::

        <html>
          <head>
            <title>This is a sample document</title>
          </head>
          <body>
            <h1 class="title">Hello!</h1>
            <p>This is a paragraph with <b>bold</b> text in it!</p>
            <p>This is another paragraph, with <a href="http://www.python.org">link</a>.</p>
            <p>Here are some reserved characters: &lt;spam&amp;egg&gt;.</p>
            <p>And finally, here is an embedded XHTML fragment.</p>
          </body>
        </html>

    For namespace support, you can pass a namespace map (``nsmap``)
    and/or a specific target ``namespace`` to the ElementMaker class::

        >>> E = ElementMaker(namespace="http://my.ns/")
        >>> print(ET.tostring( E.test ))
        <test xmlns="http://my.ns/"/>

        >>> E = ElementMaker(namespace="http://my.ns/", nsmap={'p':'http://my.ns/'})
        >>> print(ET.tostring( E.test ))
        <p:test xmlns:p="http://my.ns/"/>
    Nc                 ó   ‡— |�d|z   dz   nd | _         |rt          |¦  «        nd | _        |�t          |¦  «        sJ ‚|�|nt          j        | _        ‰rt          ‰¦  «        ni Šd„ }d„ }t          ‰vr
|‰t          <   t          ‰vr
|‰t          <   t          j	        ‰vr|‰t          j	        <   ˆfd„}t          ‰vr
|‰t          <   ‰| _
        d S )Nú{ú}c                 ó~   — 	 | d         }|j         pd|z   |_         d S # t          $ r | j        pd|z   | _        Y d S w xY w)NéÿÿÿÿÚ )ÚtailÚ
IndexErrorÚtext)ÚelemÚitemÚ
last_childs      ú./usr/lib/python3/dist-packages/lxml/builder.pyÚadd_textz'ElementMaker.__init__.<locals>.add_text    s_   € ðAØ! "œX�
ð $.¤?Ð#8°b¸DÑ"@�
”��øõ ð 5ð 5ð 5Ø!œY˜_¨"°Ñ4�”	�	�	�	ð5øøøs   ‚ �<»<c                 óP   — | j         rt          d| j         z  ¦  «        ‚|| _         d S )Nz<Can't add a CDATA section. Element already has some text: %r)r   Ú
ValueError)r   Úcdatas     r   Ú	add_cdataz(ElementMaker.__init__.<locals>.add_cdata¨   s0   € ØŒyð mÝ Ð!_ÐbfÔbkÑ!kÑlÔlÐlØˆDŒIˆIˆIó    c                 óÄ   •— | j         }|                     ¦   «         D ]B\  }}t          |t          ¦  «        r|||<   Œ  ‰t	          |¦  «                 d |¦  «        ||<   ŒCd S ©N)ÚattribÚitemsÚ
isinstanceÚ
basestringÚtype)r   r   r   ÚkÚvÚtypemaps        €r   Úadd_dictz'ElementMaker.__init__.<locals>.add_dict´   sn   ø€ Ø”[ˆFØŸ
š
™œð :ð :‘��1Ý˜a¥Ñ,Ô,ð :Ø !�F˜1‘I�Ià 0 ­¨Q©¬Ô 0°°qÑ 9Ô 9�F˜1‘I�Ið	:ð :r   )Ú
_namespaceÚdictÚ_nsmapÚcallableÚETÚElementÚ_makeelementÚstrÚunicodeÚCDATAÚ_typemap)Úselfr$   Ú	namespaceÚnsmapÚmakeelementr   r   r%   s    `      r   Ú__init__zElementMaker.__init__•   s  ø€ à3<Ð3H˜# 	™/¨CÑ/Ð/ÈdˆŒØ%*Ð4•d˜5‘k”k�k°ˆŒàÐ"¥h¨{Ñ&;Ô&;Ð"Ð"Ð"Ø+6Ð+B˜K˜KÍÌ
ˆÔð $+Ð2•$�w‘-”-�-°ˆð	Að 	Að 	Að	ð 	ð 	õ
 �gÐÐØ#ˆG•C‰LÝ˜'Ð!Ð!Ø'ˆG•GÑÝŒ8˜7Ð"Ð"Ø )ˆG•B”HÑð	:ð 	:ð 	:ð 	:ð 	:õ �wÐÐØ$ˆG•D‰MàˆŒˆˆr   c                 ó  — | j         }t          |t          ¦  «        st          |t          ¦  «        r|j        }n| j        �|d         dk    r
| j        |z   }|                      || j        ¬¦  «        }|r |t                   ||¦  «         |D ]û}t          |¦  «        r
 |¦   «         }| 
                    t          |¦  «        ¦  «        }|€‚t          j        |¦  «        r|                     |¦  «         Œit          |¦  «        j        D ]}| 
                    |¦  «        }|� n)Œt!          dt          |¦  «        j        ›d|›d�¦  «        ‚ |||¦  «        }	|	r, | 
                    t          |	¦  «        ¦  «        ||	¦  «         Œü|S )Nr   r	   )r3   zbad argument type: ú(ú))r0   r   r-   Ú_QNamer   r&   r,   r(   r'   r)   Úgetr!   r*   Ú	iselementÚappendÚ__mro__Ú	TypeErrorÚ__name__)
r1   ÚtagÚchildrenr   r$   r   r   ÚtÚbasetyper#   s
             r   Ú__call__zElementMaker.__call__Á   s¬  € Ø”-ˆõ ˜#�sÑ#Ô#ð 	(­
°3½Ñ(?Ô(?ð 	(à”(ˆCˆCØŒ_Ð(¨S°¬V°sª]¨]Ø”/ CÑ'ˆCØ× Ò  ¨D¬KÐ Ñ8Ô8ˆØð 	(ØˆG•DŒM˜$ Ñ'Ô'Ð'àð 	.ð 	.ˆDÝ˜‰~Œ~ð Ø�t‘v”v�Ø—’�D ™JœJÑ'Ô'ˆAØˆyÝ”< Ñ%Ô%ð Ø—K’K Ñ%Ô%Ð%ØÝ $ T¡
¤
Ô 2ð Að A�HàŸš HÑ-Ô-�AØ�}Ø˜ð %õ $˜)Ý%)¨$¡Z¤ZÔ%8Ð%8Ð%8¸$¸$¸$ð%@ñ Aô Að Aà��$˜‘”ˆAØð .Ø$�—’�D ™GœGÑ$Ô$ T¨1Ñ-Ô-Ð-øàˆr   c                 ó"   — t          | |¦  «        S r   r   )r1   r@   s     r   Ú__getattr__zElementMaker.__getattr__ä   s   € Ý�t˜SÑ!Ô!Ð!r   )NNNN)r?   Ú
__module__Ú__qualname__Ú__doc__r5   rD   rF   © r   r   r   r   <   s]   € € € € € ðVð Vðp  $Ø9=ð* ð * ð * ð * ðX!ð !ð !ðF"ð "ð "ð "ð "r   r   )rI   Ú
__future__r   Ú
lxml.etreeÚetreer*   ÚQNamer9   Ú	functoolsr   r    Ú	NameErrorr-   r.   Úobjectr   ÚErJ   r   r   ú<module>rS      só   ððLð ð 'Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ð Ð Ø	Œ€à Ð Ð Ð Ð Ð ðØ€J€JøØð ð ð Ø€J€J€JðøøøðØ€G€GøØð ð ð Ø€G€G€Gðøøøði"ð i"ð i"ð i"ð i"�6ñ i"ô i"ð i"ðZ €L�N„N€€€s   �   *©*®1 ±;º;