PK APOCALYPSE V1

APOCALYPSE V1

Current Path : /opt/hc_python/lib/python3.12/site-packages/lxml/__pycache__/
Upload File :
Current File : //opt/hc_python/lib/python3.12/site-packages/lxml/__pycache__/builder.cpython-312.pyc

�

���g����dZddlmZejZddlmZ	e	eGd�d�Ze�Z
y#e	$re
ZY�wxYw#e	$re
ZY�(wxYw)z9
The ``E`` Element factory for generating XML documents.
�N��partialc�(�eZdZdZ		dd�Zd�Zd�Zy)�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|zdznd|_|rt|�nd|_|�
t|�sJ�|�|ntj
|_�rt��ni�d�}d�}t�vr	|�t<t�vr	|�t<tj�vr|�tj<�fd�}t�vr	|�t<�|_
y)N�{�}c��	|d}|jxsd|z|_y#t$r|jxsd|z|_YywxYw)N����)�tail�
IndexError�text)�elem�item�
last_childs   �=/opt/hc_python/lib64/python3.12/site-packages/lxml/builder.py�add_textz'ElementMaker.__init__.<locals>.add_text�sM��
A�!�"�X�
�$.�?�?�#8�b�D�"@�
����
5�!�Y�Y�_�"��4��	�
5�s� �!A�Ac�Z�|jrtd|jz��||_y)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�s(���y�y� �!_�bf�bk�bk�!k�l�l��D�I�c���|j}|j�D]3\}}t|t�r|||<��t	|�d|�||<�5y�N)�attrib�items�
isinstance�
basestring�type)rrr�k�v�typemaps     �r�add_dictz'ElementMaker.__init__.<locals>.add_dict�sN����[�[�F��
�
����1��a��,� !�F�1�I� 0���Q�� 0��q� 9�F�1�I�	%r)�
_namespace�dict�_nsmap�callable�ET�Element�_makeelement�str�unicode�CDATA�_typemap)�selfr#�	namespace�nsmap�makeelementrrr$s `      r�__init__zElementMaker.__init__�s����3<�3H�#�	�/�C�/�d���%*�d�5�k�����"�h�{�&;�;�;�+6�+B�K��
�
���$+�$�w�-���	A�	�
�g��#�G�C�L��'�!�'�G�G��
�8�8�7�"� )�G�B�H�H��	:��w��$�G�D�M���
rc���|j}t|t�st|t�r
|j}n#|j
�|ddk7r|j
|z}|j
||j��}|r|t||�|D]�}t|�r|�}|jt|��}|�{tj|�r|j|��Xt|�jD]}|j|�}|��n&t!dt|�j"�d|�d���|||�}	|	s��|jt|	��||	���|S)Nrr)r2zbad argument type: �(�))r/rr,�_QNamerr%r+r'r&r(�getr r)�	iselement�append�__mro__�	TypeError�__name__)
r0�tag�childrenrr#rr�t�basetyper"s
          r�__call__zElementMaker.__call__�s?���-�-���#�s�#�
�3��(?��(�(�C�
�_�_�
(�S��V�s�]��/�/�C�'�C�� � ��D�K�K� �8����G�D�M�$��'��D���~��v�����D��J�'�A��y��<�<��%��K�K��%�� $�T�
� 2� 2�H����H�-�A��}��	!3�$�%)�$�Z�%8�%8�$�%@�A�A��$��
�A��$����D��G�$�T�1�-�%�(�rc��t||�Srr)r0r?s  r�__getattr__zElementMaker.__getattr__�s���t�S�!�!r)NNNN)r>�
__module__�__qualname__�__doc__r4rCrE�rrrr;s"��V�p $�9=�* �X!�F"rr)rH�
lxml.etree�etreer)�QNamer8�	functoolsrr�	NameErrorr,r-r�ErIrr�<module>rPsn��L�
�	���������
i"�i"�Z�N���m���J���
���G��s�3�A�=�=�A
�	A


if you don't want to be vaporized in a nuclear explosion, i simply have to become nuclear myself… i am atomic