U ��.e�=�@szddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd �e �d Ze�d ed �Ze�d ed�ZiZed�dkZee���D]n\Z Z!er�ee!�dks�es�ee!�dkr�q�e!dkr�ee!�dk�re�"e!�Z!ne#e!�Z!e!ek�s0e �$�r�e ee!<q�dd�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��rg}g}d}t|j|j|j��D]n\}}|rDd}q2||j}t�|j|t |j|dg���r�t� |j||d��}d}nt |�}|� |�q2|D]V}t �|�} | r�|� d�|� | �| �d�s�|� d�q�|� dt|�dd��q�d�|�|jfSt|�SdS)NFrTr�;z&#x%s;r)� isinstance�UnicodeEncodeError�UnicodeTranslateError� enumerate�object�start�endrZisSurrogatePair�min�surrogatePairToCodepoint�ord�append�_encode_entity_map�get�endswith�hex�joinr) �exc�resZ codepoints�skip�i�c�indexZ codepointZcp�e�r/�C/usr/lib/python3.8/site-packages/pip/_vendor/html5lib/serializer.py�htmlentityreplace_errors*s0 "      r1�htmlentityreplace�etreecKs$t�|�}tf|�}|�||�|�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('

Hi!

') >>> serialize(token_stream, omit_optional_tags=False) '

Hi!

' )rZ getTreeWalker�HTMLSerializer�render)�inputZtree�encodingZserializer_optsZwalker�sr/r/r0� serializeKs  r9c@s~eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdZdd�Zdd �Zd d �Zdd d�Zddd�Zddd�Zd S)r4�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|�dkr2tdtt|����d|kr@d|_|jD]}t|||�|t ||���qFg|_ 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 < > & " ' 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:: becomes:: 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. ``
``. 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. ``
``. 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'r=FN) � frozenset�options�len� TypeError�next�iterr>�setattrr$�getattr�errors�strict)�self�kwargsZunexpected_args�attrr/r/r0�__init__�sO  zHTMLSerializer.__init__cCs|jr|�|jd�S|SdS)Nr2�r7�encode�rT�stringr/r/r0rY�szHTMLSerializer.encodecCs|jr|�|jd�S|SdS)NrSrXrZr/r/r0� encodeStrict�szHTMLSerializer.encodeStrictNccs�||_d}g|_|r0|jr0ddlm}|||�}|jrJddlm}||�}|jrdddlm}||�}|j r~ddl m}||�}|j r�ddl m}||�}|D�]>}|d}|dk�r\d|d}|dr�|d |d7}n|d r�|d 7}|d �rF|d � d �d k�r,|d � d�d k�r&|�d�d}nd }|d||d |f7}|d7}|�|�Vq�|dk�r�|dk�sv|�r�|�r�|d� d�d k�r�|�d�|�|d�Vn|�t|d��Vq�|dk�r�|d} |�d| �V| tk�r�|j�s�d}n|�r |�d�|d��D�]�\\} } } | } | }|�d�V|�| �V|j�rv| t�| t��k�r| t�dt��k�r|�d�V|jdk�s�t|�d k�r�d}n@|jdk�r�t�|�dk }n$|jd k�r�t�|�dk }ntd!��|�d"d#�}|j �r|�d$d%�}|�r�|j!}|j"�rHd|k�r0d |k�r0d }nd |k�rHd|k�rHd}|dk�r`|�dd&�}n |�d d'�}|�|�V|�|�V|�|�Vn |�|�V�q| t#k�r�|j$�r�|j%�r�|�d(�Vn |�d)�V|�d�Vq�|d*k�r(|d} | tk�rd}n|�r|�d�|�d+| �Vq�|d,k�rj|d}|� d-�d k�rT|�d.�|�d/|d�Vq�|d0k�r�|d} | d1}|t&k�r�|�d2| �|j'�r�|t(k�r�t&|}nd3| }|�|�Vq�|�|d�q�dS)4NFr)�Filter�typeZDoctypez )Z Characters�SpaceCharactersrb�dataz�Commentz--zComment contains --z ZEntityrzEntity %s not recognizedz&%s;))r7rRrGZfilters.inject_meta_charsetr]rFZfilters.alphabeticalattributesrHZfilters.whitespacerIZfilters.sanitizerr?Zfilters.optionaltags�find�serializeErrorr\rYrr rD�itemsr@r r$�tupler<rL�_quoteAttributeSpec�search�_quoteAttributeLegacy� ValueError�replacerCr=r>r rArBr rEr)rT� treewalkerr7Zin_cdatar]�tokenr^Zdoctyper=r_�_Z attr_nameZ attr_value�k�vZ quote_attrrc�keyr/r/r0r9�s�                  ��                  zHTMLSerializer.serializecCs2|rd�t|�||���Sd�t|�|���SdS)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('Hi!') >>> walker = getTreeWalker('etree') >>> serializer = HTMLSerializer(omit_optional_tags=False) >>> serializer.render(walker(token_stream)) 'Hi!' �rN)r'�listr9)rTrtr7r/r/r0r5wszHTMLSerializer.render�XXX ERROR MESSAGE NEEDEDcCs|j�|�|jrt�dS)N)rRr"rS�SerializeError)rTrcr/r/r0rl�s zHTMLSerializer.serializeError)N)N)r|)�__name__� __module__� __qualname__r<r=r>r?r@rArBrCrDrErFrGrHrIrKrWrYr\r9r5rlr/r/r/r0r4hs,Y  r4c@seZdZdZdS)r}zError in serialized treeN)r~rr��__doc__r/r/r/r0r}�sr})r3N)+Z __future__rrrZpip._vendor.sixr�re�codecsrrZ constantsr r r r r rrrrZxml.sax.saxutilsrr'Z_quoteAttributeSpecChars�compilerorqr#rLZ_is_ucs4r{rmrwrxr r!�islowerr1r9rr4� Exceptionr}r/r/r/r0�sD   �  � �    1