3 �Pfa7�@s�ddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd je �d Zejd ed �Zejd ed�ZiZed�dkZx�eej��D]p\Z Z!er�ee!�dks�e r�ee!�dkr�q�e!dkr�ee!�dk�rej"e!�Z!ne#e!�Z!e!ek�s4e j$�r�e ee!<q�Wdd�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 Cs"t|ttf��rg}g}d}x�t|j|j|j��D]n\}}|rFd}q4||j}tj|j|t |j|dg���r�tj |j||d��}d}nt |�}|j |�q4Wx^|D]V}t j|�} | r�|j d�|j | �| jd�s�|j d�q�|j dt|�dd��q�Wdj|�|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/� /usr/lib/python3.6/serializer.py�htmlentityreplace_errors*s0  "      r1�htmlentityreplace�etreecKs$tj|�}tf|�}|j||�|�S)N)rZ getTreeWalker�HTMLSerializer�render)�inputZtree�encodingZserializer_optsZwalker�sr/r/r0� serializeJs  r9c@s~eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZd!Zdd�Zdd�Zdd�Zd"dd�Zd#dd�Zd$dd �ZdS)%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 Kszt|�t|j�}t|�dkr2tdtt|����d|kr@d|_x(|jD]}t|||j|t ||���qHWg|_ d|_ dS)a6 Initialize HTMLSerializer. Keyword options (default given first unless specified) include: inject_meta_charset=True|False Whether it insert a meta element to define the character set of the document. quote_attr_values="legacy"|"spec"|"always" Whether to quote attribute values that don't require quoting per legacy browser behaviour, when required by the standard, or always. quote_char=u'"'|u"'" Use given quote character for attribute quoting. Default is to use double quote unless attribute value contains a double quote, in which case single quotes are used instead. escape_lt_in_attrs=False|True Whether to escape < in attribute values. escape_rcdata=False|True Whether to escape characters that need to be escaped within normal elements within rcdata elements such as style. resolve_entities=True|False Whether to resolve named character entities that appear in the source tree. The XML predefined entities < > & " ' are unaffected by this setting. strip_whitespace=False|True Whether to remove semantically meaningless whitespace. (This compresses all whitespace to a single space except within pre.) minimize_boolean_attributes=True|False Shortens boolean attributes to give just the attribute value, for example becomes . use_trailing_solidus=False|True Includes a close-tag slash at the end of the start tag of void elements (empty elements whose end tag is forbidden). E.g.
. space_before_trailing_solidus=True|False Places a space immediately before the closing slash in a tag using a trailing solidus. E.g.
. Requires use_trailing_solidus. sanitize=False|True Strip all unsafe or unknown constructs from output. See `html5lib user documentation`_ omit_optional_tags=True|False Omit start/end tags that are optional. alphabetical_attributes=False|True Reorder attributes to be in alphabetical order. .. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation 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__ps.  zHTMLSerializer.__init__cCs|jr|j|jd�S|SdS)Nr2)r7�encode)rT�stringr/r/r0rX�szHTMLSerializer.encodecCs|jr|j|jd�S|SdS)NrS)r7rX)rTrYr/r/r0� encodeStrict�szHTMLSerializer.encodeStrictNccs�||_d}g|_|r0|jr0ddlm}|||�}|jrJddlm}||�}|jrdddlm}||�}|j r~ddl m}||�}|j r�ddl m}||�}�xR|D�]H}|d}|dk�r`d|d}|dr�|d |d7}n|d r�|d 7}|d �rJ|d j d �d k�r0|d j d�d k�r*|jd�d}nd }|d||d |f7}|d7}|j|�Vq�|d5k�r�|dk�sz|�r�|�r�|dj d�d k�r�|jd�|j|d�Vn|jt|d��Vq�|d6k�r�|d} |jd| �V| tk�r|j �rd}n|�r|jd��x�|dj�D�]�\\} } } | } | }|jd�V|j| �V|j �s�| tj| t��k�r"| tjdt��k�r"|jd�V|jdk�s�t|�d k�r�d}n@|jd k�r�tj|�dk }n$|jd!k�r�tj|�dk }ntd"��|jd#d$�}|j �r|jd%d&�}|�r�|j!}|j"�rTd|k�r� Characters�SpaceCharacters�dataz�Commentz--zComment contains --z ZEntityrzEntity %s not recognizedz&%s;)r`ra)rcrd))r7rRrGZfilters.inject_meta_charsetr[rFZfilters.alphabeticalattributesrHZfilters.whitespacerIZfilters.sanitizerr?Zfilters.optionaltags�find�serializeErrorrZrXrr 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_attrrb�keyr/r/r0r9�s�                                    zHTMLSerializer.serializecCs2|rdjt|j||���Sdjt|j|���SdS)N�r)r'�listr9)rTrur7r/r/r0r5?szHTMLSerializer.render�XXX ERROR MESSAGE NEEDEDcCs|jj|�|jrt�dS)N)rRr"rS�SerializeError)rTrbr/r/r0rmEs zHTMLSerializer.serializeError)r<r=r>r?r@rArBrCrDrErFrGrHrI)N)N)r})�__name__� __module__� __qualname__r<r=r>r?r@rArBrCrDrErFrGrHrIrKrWrXrZr9r5rmr/r/r/r0r4Qs68  r4c@seZdZdZdS)r~zError in serialized treeN)rr�r��__doc__r/r/r/r0r~Lsr~)r3N)+Z __future__rrrZpip._vendor.sixr�re�codecsrrZ constantsr r r r r rrrrZxml.sax.saxutilsrr'Z_quoteAttributeSpecChars�compilerprrr#rLZ_is_ucs4r|rnrxryr r!�islowerr1r9rr4� Exceptionr~r/r/r/r0�s:         |