AlkantarClanX12

Your IP : 3.145.161.194


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/builder.cpython-37.pyc

B

�|/\'�@s�dZddlmZddlmZddlmZyeWne	k
rHe
ZYnXyeWne	k
rje
ZYnXGdd�de�Z
e
�ZdS)z9
The ``E`` Element factory for generating XML documents.
�)�absolute_importN)�partialc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�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/"/>
    Ncs�|dk	rd|d|_nd|_|r.t|�|_nd|_|dk	rPt|�sHt�||_ntj|_�rft���ni�dd�}dd�}t�kr�|�t<t	�kr�|�t	<tj
�kr�|�tj
<�fdd�}t�kr�|�t<�|_dS)	N�{�}cSsFy|djpd||d_Wn$tk
r@|jp4d||_YnXdS)N����)�tail�
IndexError�text)�elem�item�r�?/opt/alt/python37/lib64/python3.7/site-packages/lxml/builder.py�add_text�sz'ElementMaker.__init__.<locals>.add_textcSs|jrtd|j��||_dS)Nz<Can't add a CDATA section. Element already has some text: %r)r�
ValueError)rZcdatarrr�	add_cdata�sz(ElementMaker.__init__.<locals>.add_cdatacsJ|j}x>|��D]2\}}t|t�r,|||<q�t|�d|�||<qWdS)N)�attrib�items�
isinstance�
basestring�type)rr
r�k�v)�typemaprr�add_dict�s


z'ElementMaker.__init__.<locals>.add_dict)�
_namespace�dict�_nsmap�callable�AssertionError�_makeelement�ETZElement�str�unicodeZCDATA�_typemap)�selfr�	namespace�nsmapZmakeelementrrrr)rr�__init__�s2


zElementMaker.__init__c
Os�|j}|jdk	r&|ddkr&|j|}|j||jd�}|rH|t||�x�|D]�}t|�r`|�}|�t|��}|dkr�t�	|�r�|�
|�qNx<t|�jD]}|�|�}|dk	r�Pq�Wtdt|�j
|f��|||�}	|	rN|�t|	��||	�qNW|S)Nrr)r(zbad argument type: %s(%r))r%rr!rrr�getrr"Z	iselement�append�__mro__�	TypeError�__name__)
r&�tag�childrenrrrr
�tZbasetyperrrr�__call__�s0





zElementMaker.__call__cCs
t||�S)N)r)r&r/rrr�__getattr__�szElementMaker.__getattr__)NNNN)r.�
__module__�__qualname__�__doc__r)r2r3rrrrr;s
W
6r)r6�
__future__rZ
lxml.etree�etreer"�	functoolsrr�	NameErrorr#r$�objectr�Errrr�<module>(s

5