HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pip/_vendor/html5lib/__pycache__/serializer.cpython-310.pyc
o

@%Ne�=�@svddlmZmZmZddlmZddlZddlmZm	Z	ddl
mZmZm
Z
ddl
mZmZmZddlmZmZdd	lmZd
�e
�dZe�ded
�Ze�ded�ZiZed�dkZee���D]5\Z Z!erqee!�dksyeszee!�dkrzqee!dkr�ee!�dkr�e�"e!�Z!ne#e!�Z!e!evs�e �$�r�e ee!<qedd�Z%ede%�ddd�Z&Gdd�de'�Z(Gdd�de)�Z*dS)�)�absolute_import�division�unicode_literals)�	text_typeN)�register_error�xmlcharrefreplace_errors�)�voidElements�booleanAttributes�spaceCharacters)�rcdataElements�entities�xmlEntities)�treewalkers�_utils)�escape�z"'=<>`�[�]u_	

 /`  ᠎᠏           

   ]u􏿿��&c
	Cst|ttf�r�g}g}d}t|j|j|j��D]7\}}|r!d}q||j}t�|j|t	|j|dg���rFt�
|j||d��}d}nt|�}|�|�q|D]+}t
�|�}	|	rp|�d�|�|	�|	�d�so|�d�qR|�dt|�dd��qRd�|�|jfSt|�S)NFrTr�;z&#x%s;r)�
isinstance�UnicodeEncodeError�UnicodeTranslateError�	enumerate�object�start�endr�isSurrogatePair�min�surrogatePairToCodepoint�ord�append�_encode_entity_map�get�endswith�hex�joinr)
�exc�res�
codepoints�skip�i�c�index�	codepoint�cp�e�r3�A/usr/lib/python3/dist-packages/pip/_vendor/html5lib/serializer.py�htmlentityreplace_errors*s2
"




�r5�htmlentityreplace�etreecKs(t�|�}tdi|��}|�||�|�S)a�Serializes the input token stream using the specified treewalker

    :arg input: the token stream to serialize

    :arg tree: the treewalker to use

    :arg encoding: the encoding to use

    :arg serializer_opts: any options to pass to the
        :py:class:`html5lib.serializer.HTMLSerializer` that gets created

    :returns: the tree serialized as a string

    Example:

    >>> from html5lib.html5parser import parse
    >>> from html5lib.serializer import serialize
    >>> token_stream = parse('<html><body><p>Hi!</p></body></html>')
    >>> serialize(token_stream, omit_optional_tags=False)
    '<html><head></head><body><p>Hi!</p></body></html>'

    Nr3)r�
getTreeWalker�HTMLSerializer�render)�input�tree�encoding�serializer_opts�walker�sr3r3r4�	serializeKs
rAc@s~eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdd�Zdd	�Zd
d�Zdd
d�Zddd�Zddd�ZdS)r9�legacy�"TF)�quote_attr_values�
quote_char�use_best_quote_char�omit_optional_tags�minimize_boolean_attributes�use_trailing_solidus�space_before_trailing_solidus�escape_lt_in_attrs�
escape_rcdata�resolve_entities�alphabetical_attributes�inject_meta_charset�strip_whitespace�sanitizec
Ksvt|�t|j�}t|�dkrtdtt|����d|vr d|_|jD]}t|||�|t	||���q#g|_
d|_dS)aB
Initialize HTMLSerializer

        :arg inject_meta_charset: Whether or not to inject the meta charset.

            Defaults to ``True``.

        :arg quote_attr_values: Whether to quote attribute values that don't
            require quoting per legacy browser behavior (``"legacy"``), when
            required by the standard (``"spec"``), or always (``"always"``).

            Defaults to ``"legacy"``.

        :arg quote_char: Use given quote character for attribute quoting.

            Defaults to ``"`` which will use double quotes unless attribute
            value contains a double quote, in which case single quotes are
            used.

        :arg escape_lt_in_attrs: Whether or not to escape ``<`` in attribute
            values.

            Defaults to ``False``.

        :arg escape_rcdata: Whether to escape characters that need to be
            escaped within normal elements within rcdata elements such as
            style.

            Defaults to ``False``.

        :arg resolve_entities: Whether to resolve named character entities that
            appear in the source tree. The XML predefined entities &lt; &gt;
            &amp; &quot; &apos; are unaffected by this setting.

            Defaults to ``True``.

        :arg strip_whitespace: Whether to remove semantically meaningless
            whitespace. (This compresses all whitespace to a single space
            except within ``pre``.)

            Defaults to ``False``.

        :arg minimize_boolean_attributes: Shortens boolean attributes to give
            just the attribute value, for example::

              <input disabled="disabled">

            becomes::

              <input disabled>

            Defaults to ``True``.

        :arg use_trailing_solidus: Includes a close-tag slash at the end of the
            start tag of void elements (empty elements whose end tag is
            forbidden). E.g. ``<hr/>``.

            Defaults to ``False``.

        :arg space_before_trailing_solidus: Places a space immediately before
            the closing slash in a tag using a trailing solidus. E.g.
            ``<hr />``. Requires ``use_trailing_solidus=True``.

            Defaults to ``True``.

        :arg sanitize: Strip all unsafe or unknown constructs from output.
            See :py:class:`html5lib.filters.sanitizer.Filter`.

            Defaults to ``False``.

        :arg omit_optional_tags: Omit start/end tags that are optional.

            Defaults to ``True``.

        :arg alphabetical_attributes: Reorder attributes to be in alphabetical order.

            Defaults to ``False``.

        rz2__init__() got an unexpected keyword argument '%s'rEFN)�	frozenset�options�len�	TypeError�next�iterrF�setattrr%�getattr�errors�strict)�self�kwargs�unexpected_args�attrr3r3r4�__init__�sO

zHTMLSerializer.__init__cC�&t|t�sJ�|jr|�|jd�S|S)Nr6�rrr=�encode�r\�stringr3r3r4rc��zHTMLSerializer.encodecCra)Nr[rbrdr3r3r4�encodeStrict�rfzHTMLSerializer.encodeStrictNccs��||_d}g|_|r|jrddlm}|||�}|jr&ddlm}||�}|jr3ddlm}||�}|j	r@ddl
m}||�}|jrMddlm}||�}|D�]}|d}|dkr�d|d}|drm|d	|d7}n|d
ru|d7}|d
r�|d
�
d�d
kr�|d
�
d�d
kr�|�d�d}nd}|d||d
|f7}|d7}|�|�VqO|dvr�|dks�|r�|r�|d�
d�d
kr�|�d�|�|d�VqO|�t|d��VqO|dv�r�|d}	|�d|	�V|	tvr�|js�d}n|r�|�d�|d��D]�\\}
}}|}
|}|�d�V|�|
�V|j�r/|
t�|	t��v�r�|
t�dt��v�r�|�d�V|jdk�sBt|�d
k�rEd}n |jdk�rSt�|�du}n|jd k�rat�|�du}ntd!��|�d"d#�}|j �ru|�d$d%�}|�r�|j!}|j"�r�d|v�r�d|v�r�d}nd|v�r�d|v�r�d}|dk�r�|�dd&�}n|�dd'�}|�|�V|�|�V|�|�V�q|�|�V�q|	t#v�r�|j$�r�|j%�r�|�d(�Vn|�d)�V|�d�VqO|d*k�r	|d}	|	tv�r�d}n|�r|�d�|�d+|	�VqO|d,k�r*|d}|�
d-�d
k�r|�d.�|�d/|d�VqO|d0k�r\|d}	|	d1}|t&v�rC|�d2|	�|j'�rQ|t(v�rQt&|}nd3|	}|�|�VqO|�|d�qOdS)4NFr)�Filter�type�Doctypez<!DOCTYPE %s�name�publicIdz PUBLIC "%s"�systemIdz SYSTEMrCr�'zBSystem identifier contains both single and double quote charactersz %s%s%s�>)�
Characters�SpaceCharactersrq�dataz</zUnexpected </ in CDATA)�StartTag�EmptyTagz<%sTz+Unexpected child element of a CDATA element� r�=�always�specrBz?quote_attr_values must be one of: 'always', 'spec', or 'legacy'rz&amp;�<z&lt;z&#39;z&quot;z /�/�EndTagz</%s>�Commentz--zComment contains --z	<!--%s-->�EntityrzEntity %s not recognizedz&%s;))r=rZrO�filters.inject_meta_charsetrhrN�filters.alphabeticalattributesrP�filters.whitespacerQ�filters.sanitizerrG�filters.optionaltags�find�serializeErrorrgrcrrrL�itemsrHr
r%�tuplerDrT�_quoteAttributeSpec�search�_quoteAttributeLegacy�
ValueError�replacerKrErFr	rIrJr
rMr)r\�
treewalkerr=�in_cdatarh�tokenri�doctyperErk�_�	attr_name�
attr_value�k�v�
quote_attrrr�keyr3r3r4rA�s��







�







�zHTMLSerializer.serializecCs.|r
d�t|�||���Sd�t|�|���S)anSerializes the stream from the treewalker into a string

        :arg treewalker: the treewalker to serialize

        :arg encoding: the string encoding to use

        :returns: the serialized tree

        Example:

        >>> from html5lib import parse, getTreeWalker
        >>> from html5lib.serializer import HTMLSerializer
        >>> token_stream = parse('<html><body>Hi!</body></html>')
        >>> walker = getTreeWalker('etree')
        >>> serializer = HTMLSerializer(omit_optional_tags=False)
        >>> serializer.render(walker(token_stream))
        '<html><head></head><body>Hi!</body></html>'

        �r)r(�listrA)r\r�r=r3r3r4r:wszHTMLSerializer.render�XXX ERROR MESSAGE NEEDEDcCs|j�|�|jrt�dS�N)rZr#r[�SerializeError)r\rrr3r3r4r��s�zHTMLSerializer.serializeErrorr�)r�)�__name__�
__module__�__qualname__rDrErFrGrHrIrJrKrLrMrNrOrPrQrSr`rcrgrAr:r�r3r3r3r4r9hs.Y


r9c@seZdZdZdS)r�zError in serialized treeN)r�r�r��__doc__r3r3r3r4r��sr�)r7N)+�
__future__rrr�pip._vendor.sixr�re�codecsrr�	constantsr	r
rrr
rrrr�xml.sax.saxutilsrr(�_quoteAttributeSpecChars�compiler�r�r$rT�_is_ucs4r�r�r�r�r!r"�islowerr5rArr9�	Exceptionr�r3r3r3r4�<module>sF
�
��

1