
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
B;ˆWU7  ã               @   s€  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
jeƒd Zejde d ƒZejde d ƒZi ZedƒdkZx€eejƒ ƒD ]p\Z Z!eräee!ƒdksÌe røee!ƒdkrøqÌe!dkrÌee!ƒdk�rej"e!ƒZ!ne#e!ƒZ!e!ek�s4e j$ƒ rÌe ee!< qÌW 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}xˆt| j| j| j… ƒD ]n\}}|rFd}q4|| j }tj| j|t	| j|d gƒ… ƒr�tj
| j||d … ƒ}d}nt|ƒ}|j|ƒ q4W x^|D ]V}tj|ƒ}	|	rè|jdƒ |j|	ƒ |	jdƒsæ|jdƒ q¬|jdt|ƒdd …  ƒ q¬W dj|ƒ| jfS t| ƒS d S )NFr   Tr   ú;z&#x%s;r   )Ú
isinstanceÚUnicodeEncodeErrorÚUnicodeTranslateErrorÚ	enumerateÚobjectÚstartÚendr   ZisSurrogatePairÚminÚsurrogatePairToCodepointÚordÚappendÚ_encode_entity_mapÚgetÚendswithÚhexÚjoinr   )
ÚexcÚresZ
codepointsÚskipÚiÚcÚindexZ	codepointZcpÚe© r/   ú /usr/lib/python3.6/serializer.pyÚhtmlentityreplace_errors*   s0     
"




r1   ÚhtmlentityreplaceÚetreec             K   s$   t j|ƒ}tf |Ž}|j|| ƒ|ƒS )N)r   ZgetTreeWalkerÚHTMLSerializerÚrender)ÚinputZtreeÚencodingZserializer_optsZwalkerÚsr/   r/   r0   Ú	serializeJ   s    

r9   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 )%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          	   K   sz   t |ƒt | jƒ }t|ƒdkr2tdtt|ƒƒ ƒ‚d|kr@d| _x(| jD ]}t| ||j|t	| |ƒƒƒ qHW g | _
d| _dS )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 &lt; &gt; &amp; &quot; &apos;
          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 <input disabled="disabled"> becomes <input disabled>.
        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. <hr/>.
        space_before_trailing_solidus=True|False
          Places a space immediately before the closing slash in a tag
          using a trailing solidus. E.g. <hr />. 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
        r   z2__init__() got an unexpected keyword argument '%s'r=   FN)Ú	frozensetÚoptionsÚlenÚ	TypeErrorÚnextÚiterr>   Úsetattrr$   ÚgetattrÚerrorsÚstrict)ÚselfÚkwargsZunexpected_argsÚattrr/   r/   r0   Ú__init__p   s    .zHTMLSerializer.__init__c             C   s*   t |tƒst‚| jr"|j| jdƒS |S d S )Nr2   )r   r   ÚAssertionErrorr7   Úencode)rT   Ústringr/   r/   r0   rY   ¨   s    zHTMLSerializer.encodec             C   s*   t |tƒst‚| jr"|j| jdƒS |S d S )NrS   )r   r   rX   r7   rY   )rT   rZ   r/   r/   r0   Ú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} ||ƒ}�xR|D �]H}|d }|dk�r`d|d  }|d rÞ|d	|d  7 }n|d
 rî|d7 }|d
 �rJ|d
 jdƒdk�r0|d
 jdƒdk�r*| jdƒ d}nd}|d||d
 |f 7 }|d7 }| j|ƒV  q |d5k�rÆ|dk�sz|�r°|�rž|d jdƒdk�rž| jdƒ | j|d ƒV  n| jt|d ƒƒV  q |d6k�rò|d }	| jd|	 ƒV  |	tk�r| j �rd}n|�r| jdƒ �xš|d jƒ D �]ˆ\\}
}}|}|}| jdƒV  | j|ƒV  | j �s‚|tj|	tƒ ƒk�r"|tjdtƒ ƒk�r"| jdƒV  | jdk�s¨t|ƒdk�r®d}n@| jd k�rÊtj|ƒd k	}n$| jd!k�rætj|ƒd k	}ntd"ƒ‚|jd#d$ƒ}| j �r|jd%d&ƒ}|�rž| j!}| j"�rTd|k�r<d|k�r<d}nd|k�rTd|k�rTd}|dk�rl|jdd'ƒ}n|jdd(ƒ}| j|ƒV  | j|ƒV  | j|ƒV  n| j|ƒV  �q"W |	t#k�rä| j$�rä| j%�rØ| jd)ƒV  n| jd*ƒV  | jdƒV  q |d+k�r6|d }	|	tk�rd}n|�r$| jdƒ | jd,|	 ƒV  q |d-k�rx|d }|jd.ƒdk�rb| jd/ƒ | jd0|d  ƒV  q |d1k�rÜ|d }	|	d2 }|t&k�rª| jd3|	 ƒ | j'�rÆ|t(k�rÆt&| }nd4|	 }| j|ƒV  q | j|d ƒ q W d S )7NFr   )ÚFilterÚtypeZDoctypez<!DOCTYPE %sÚnameZpublicIdz PUBLIC "%s"ZsystemIdz SYSTEMr;   r   ú'zASystem identifer contains both single and double quote charactersz %s%s%sú>Ú
CharactersÚSpaceCharactersÚ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 /ú/ZEndTagz</%s>ÚCommentz--zComment contains --z	<!--%s-->ZEntityr   zEntity %s not recognizedz&%s;)ra   rb   )rd   re   ))r7   rR   rG   Zfilters.inject_meta_charsetr\   rF   Zfilters.alphabeticalattributesrH   Zfilters.whitespacerI   Zfilters.sanitizerr?   Zfilters.optionaltagsÚfindÚserializeErrorr[   rY   r   r   rD   Úitemsr@   r
   r$   Útupler<   rL   Ú_quoteAttributeSpecÚsearchÚ_quoteAttributeLegacyÚ
ValueErrorÚreplacerC   r=   r>   r	   rA   rB   r   rE   r   )rT   Ú
treewalkerr7   Zin_cdatar\   Útokenr]   Zdoctyper=   r^   Ú_Z	attr_nameZ
attr_valueÚkÚvZ
quote_attrrc   Úkeyr/   r/   r0   r9   ¶   sØ    


















zHTMLSerializer.serializec             C   s2   |rdj t| j||ƒƒƒS dj t| j|ƒƒƒS d S )Nó    r   )r'   Úlistr9   )rT   rv   r7   r/   r/   r0   r5   ?  s    zHTMLSerializer.renderúXXX ERROR MESSAGE NEEDEDc             C   s   | j j|ƒ | jrt‚d S )N)rR   r"   rS   ÚSerializeError)rT   rc   r/   r/   r0   rn   E  s    zHTMLSerializer.serializeError)r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   )N)N)r~   )Ú__name__Ú
__module__Ú__qualname__r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rK   rW   rY   r[   r9   r5   rn   r/   r/   r/   r0   r4   Q   s6        8
 

r4   c               @   s   e Zd ZdZdS )r   zError in serialized treeN)r€   r�   r‚   Ú__doc__r/   r/   r/   r0   r   L  s   r   )r3   N)+Z
__future__r   r   r   Zsixr   ÚreÚcodecsr   r   Z	constantsr	   r
   r   r   r   r   r   r   r   Zxml.sax.saxutilsr   r'   Z_quoteAttributeSpecCharsÚcompilerq   rs   r#   rL   Z_is_ucs4r}   ro   ry   rz   r    r!   Úislowerr1   r9   r   r4   Ú	Exceptionr   r/   r/   r/   r0   Ú<module>   s:   
	

 |