a
    ýÓEb�=  ã                   @   sz  d dl mZmZmZ d dlmZ d dlZd dlmZm	Z	 ddl
mZmZmZ ddl
mZmZmZ ddlmZmZ d d	lmZ d
 e¡d Ze de d ¡Ze de d ¡Zi ZedƒdkZee ¡ ƒD ]n\Z Z!erâee!ƒdksÊesôee!ƒdkrôqÊe!dkrÊee!ƒdk�re "e!¡Z!ne#e!ƒZ!e!ev�s0e  $¡ rÊe ee!< qÊdd„ Z%ede%ƒ ddd„Z&G dd„ de'ƒZ(G dd„ de)ƒZ*dS )é    )Úabsolute_importÚdivisionÚunicode_literals)Ú	text_typeN)Úregister_errorÚxmlcharrefreplace_errorsé   )ÚvoidElementsÚbooleanAttributesÚspaceCharacters)ÚrcdataElementsÚentitiesÚxmlEntities)ÚtreewalkersÚ_utils)ÚescapeÚ z"'=<>`ú[ú]u_    	
 /`Â áš€á Žá �â€€â€�â€‚â€ƒâ€„â€…â€†â€‡â€ˆâ€‰â€Šâ€¨â€©â€¯â�Ÿã€€]u   ô�¿¿é   ú&c           
   	   C   s  t | ttfƒ�rg }g }d}t| j| j| j… ƒD ]n\}}|rDd}q2|| j }t | j|t	| j|d gƒ… ¡rŽt 
| j||d … ¡}d}nt|ƒ}| |¡ q2|D ]V}t |¡}	|	râ| d¡ | |	¡ |	 d¡sü| d¡ q¦| dt|ƒdd …  ¡ q¦d |¡| jfS t| ƒS d S )NFr   Tr   ú;z&#x%s;r   )Ú
isinstanceÚUnicodeEncodeErrorÚUnicodeTranslateErrorÚ	enumerateÚobjectÚstartÚendr   ÚisSurrogatePairÚminÚsurrogatePairToCodepointÚordÚappendÚ_encode_entity_mapÚgetÚendswithÚhexÚjoinr   )
ÚexcÚresZ
codepointsÚskipÚiÚcÚindexÚ	codepointÚcpÚe© r2   ú_/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pip/_vendor/html5lib/serializer.pyÚhtmlentityreplace_errors*   s0    
"



r4   ÚhtmlentityreplaceÚetreec                 K   s(   t  |¡}tf i |¤Ž}| || ƒ|¡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>'

    )r   ÚgetTreeWalkerÚHTMLSerializerÚrender)ÚinputÚtreeÚencodingZserializer_optsÚwalkerÚsr2   r2   r3   Ú	serializeK   s    
r?   c                   @   s~   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdd„ Zdd	„ Zd
d„ Zddd„Zddd„Zddd„ZdS )r8   Ú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              
   K   sv   t |ƒt | jƒ }t|ƒdkr2tdtt|ƒƒ ƒ‚d|v r@d| _| jD ]}t| || |t	| |ƒ¡ƒ qFg | _
d| _dS )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``.

        r   z2__init__() got an unexpected keyword argument '%s'rC   FN)Ú	frozensetÚoptionsÚlenÚ	TypeErrorÚnextÚiterrD   Úsetattrr%   ÚgetattrÚerrorsÚstrict)ÚselfÚkwargsZunexpected_argsÚattrr2   r2   r3   Ú__init__‡   s    O
zHTMLSerializer.__init__c                 C   s*   t |tƒsJ ‚| jr"| | jd¡S |S d S )Nr5   ©r   r   r<   Úencode©rZ   Ústringr2   r2   r3   r_   à   s    zHTMLSerializer.encodec                 C   s*   t |tƒsJ ‚| jr"| | jd¡S |S d S )NrY   r^   r`   r2   r2   r3   ÚencodeStrictç   s    zHTMLSerializer.encodeStrictNc                 c   sâ  || _ d}g | _|r0| jr0ddlm} |||ƒ}| jrJddlm} ||ƒ}| jrdddlm} ||ƒ}| j	r~ddl
m} ||ƒ}| jr˜ddlm} ||ƒ}|D �]>}|d }|dk�r\d|d  }|d rÚ|d	|d  7 }n|d
 rê|d7 }|d
 �rF|d
  d¡dk�r,|d
  d¡dk�r&|  d¡ d}nd}|d||d
 |f 7 }|d7 }|  |¡V  qœ|dv �rÂ|dk�sv|�r¬|�rš|d  d¡dk�rš|  d¡ |  |d ¡V  n|  t|d ƒ¡V  qœ|dv �rä|d }	|  d|	 ¡V  |	tv �rü| j�süd}n|�r|  d¡ |d  ¡ D �]†\\}
}}|}|}|  d¡V  |  |¡V  | j�rv|t |	tƒ ¡v�r|t dtƒ ¡v�r|  d¡V  | jdk�sœt|ƒdk�r¢d}n@| jdk�r¾t |¡d u}n$| jd k�rÚt |¡d u}ntd!ƒ‚| d"d#¡}| j �r| d$d%¡}|�r’| j!}| j"�rHd|v �r0d|v�r0d}nd|v �rHd|v�rHd}|dk�r`| dd&¡}n| dd'¡}|  |¡V  |  |¡V  |  |¡V  n|  |¡V  �q|	t#v �rÖ| j$�rÖ| j%�rÊ|  d(¡V  n|  d)¡V  |  d¡V  qœ|d*k�r(|d }	|	tv �rd}n|�r|  d¡ |  d+|	 ¡V  qœ|d,k�rj|d }| d-¡dk�rT|  d.¡ |  d/|d  ¡V  qœ|d0k�rÎ|d }	|	d1 }|t&v�rœ|  d2|	 ¡ | j'�r¸|t(v�r¸t&| }nd3|	 }|  |¡V  qœ|  |d ¡ qœd S )4NFr   )ÚFilterÚtypeÚDoctypez<!DOCTYPE %sÚnameÚpublicIdz PUBLIC "%s"ÚsystemIdz SYSTEMrA   r   ú'zBSystem identifier contains both single and double quote charactersz %s%s%sú>)Ú
CharactersÚSpaceCharactersrl   Údataz</zUnexpected </ in CDATA)ÚStartTagÚEmptyTagz<%sTz+Unexpected child element of a CDATA elementú r   ú=ÚalwaysÚspecr@   z?quote_attr_values must be one of: 'always', 'spec', or 'legacy'r   z&amp;ú<z&lt;z&#39;z&quot;z /ú/ÚEndTagz</%s>ÚCommentz--zComment contains --z	<!--%s-->ÚEntityr   zEntity %s not recognizedz&%s;))r<   rX   rM   Zfilters.inject_meta_charsetrc   rL   Zfilters.alphabeticalattributesrN   Zfilters.whitespacerO   Zfilters.sanitizerrE   Zfilters.optionaltagsÚfindÚserializeErrorrb   r_   r   r   rJ   ÚitemsrF   r
   r%   ÚtuplerB   rR   Ú_quoteAttributeSpecÚsearchÚ_quoteAttributeLegacyÚ
ValueErrorÚreplacerI   rC   rD   r	   rG   rH   r   rK   r   )rZ   Ú
treewalkerr<   Zin_cdatarc   Útokenrd   ÚdoctyperC   rf   Ú_Ú	attr_nameZ
attr_valueÚkÚvZ
quote_attrrm   Úkeyr2   r2   r3   r?   î   sÜ    









ÿþ








zHTMLSerializer.serializec                 C   s2   |rd  t|  ||¡ƒ¡S d  t|  |¡ƒ¡S dS )an  Serializes 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   N)r(   Úlistr?   )rZ   r‚   r<   r2   r2   r3   r9   w  s    zHTMLSerializer.renderúXXX ERROR MESSAGE NEEDEDc                 C   s   | j  |¡ | jrt‚d S )N)rX   r#   rY   ÚSerializeError)rZ   rm   r2   r2   r3   rz   �  s    zHTMLSerializer.serializeError)N)N)rŒ   )Ú__name__Ú
__module__Ú__qualname__rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rQ   r]   r_   rb   r?   r9   rz   r2   r2   r2   r3   r8   h   s,   Y
 

r8   c                   @   s   e Zd ZdZdS )r�   zError in serialized treeN)rŽ   r�   r�   Ú__doc__r2   r2   r2   r3   r�   —  s   r�   )r6   N)+Ú
__future__r   r   r   Úpip._vendor.sixr   ÚreÚcodecsr   r   Ú	constantsr	   r
   r   r   r   r   r   r   r   Zxml.sax.saxutilsr   r(   Z_quoteAttributeSpecCharsÚcompiler}   r   r$   rR   Z_is_ucs4r‹   r{   r‡   rˆ   r!   r"   Úislowerr4   r?   r   r8   Ú	Exceptionr�   r2   r2   r2   r3   Ú<module>   sD   
ÿ
ÿ
ÿ


  1