a
    hbòfÂÉ ã                   @   s  d dl mZmZmZ d dlmZmZ d dlZddlm	Z	 ddlm
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  d dd„Z!d!dd„Z"dd„ Z#G dd„ de$ƒZ%ej&dd„ ƒZ'dd„ Z(d"dd„Z)G dd„ de*ƒZ+dS )#é    )Úabsolute_importÚdivisionÚunicode_literals)Úwith_metaclassÚviewkeysNé   )Ú_inputstream)Ú
_tokenizer)Útreebuilders)ÚMarker)Ú_utils)ÚspaceCharactersÚasciiUpper2LowerÚspecialElementsÚheadingElementsÚcdataElementsÚrcdataElementsÚ
tokenTypesÚtagTokenTypesÚ
namespacesÚhtmlIntegrationPointElementsÚ"mathmlTextIntegrationPointElementsÚadjustForeignAttributesÚadjustMathMLAttributesÚadjustSVGAttributesÚEÚ_ReparseExceptionÚetreeTc                 K   s(   t  |¡}t||d�}|j| fi |¤ŽS )aò  Parse an HTML document as a string or file-like object into a tree

    :arg doc: the document to parse as a string or file-like object

    :arg treebuilder: the treebuilder to use when parsing

    :arg namespaceHTMLElements: whether or not to namespace HTML elements

    :returns: parsed tree

    Example:

    >>> from html5lib.html5parser import parse
    >>> parse('<html><body><p>This is a doc</p></body></html>')
    <Element u'{http://www.w3.org/1999/xhtml}html' at 0x7feac4909db0>

    ©ÚnamespaceHTMLElements)r
   ÚgetTreeBuilderÚ
HTMLParserÚparse)ÚdocÚtreebuilderr   ÚkwargsÚtbÚp© r(   ú]/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/html5lib/html5parser.pyr"      s    
r"   Údivc                 K   s,   t  |¡}t||d�}|j| fd|i|¤ŽS )a#  Parse an HTML fragment as a string or file-like object into a tree

    :arg doc: the fragment to parse as a string or file-like object

    :arg container: the container context to parse the fragment in

    :arg treebuilder: the treebuilder to use when parsing

    :arg namespaceHTMLElements: whether or not to namespace HTML elements

    :returns: parsed tree

    Example:

    >>> from html5lib.html5libparser import parseFragment
    >>> parseFragment('<b>this is a fragment</b>')
    <Element u'DOCUMENT_FRAGMENT' at 0x7feac484b090>

    r   Ú	container)r
   r    r!   ÚparseFragment)r#   r+   r$   r   r%   r&   r'   r(   r(   r)   r,   1   s    
r,   c                    s   G ‡ fdd„dt ƒ}|S )Nc                       s   e Zd Z‡ fdd„ZdS )z-method_decorator_metaclass.<locals>.Decoratedc                    s>   |  ¡ D ]$\}}t|tjƒr$ˆ |ƒ}|||< qt | |||¡S ©N)ÚitemsÚ
isinstanceÚtypesÚFunctionTypeÚtypeÚ__new__)ÚmetaÚ	classnameÚbasesÚ	classDictÚattributeNameÚ	attribute©Úfunctionr(   r)   r3   L   s
    
z5method_decorator_metaclass.<locals>.Decorated.__new__N)Ú__name__Ú
__module__Ú__qualname__r3   r(   r:   r(   r)   Ú	DecoratedK   s   r?   )r2   )r;   r?   r(   r:   r)   Úmethod_decorator_metaclassJ   s    r@   c                   @   sš   e Zd ZdZd'dd„Zd(dd	„Zd
d„ Zedd„ ƒZdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zd)dd„Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZdS )*r!   z]HTML parser

    Generates a tree structure from a stream of (possibly malformed) HTML.

    NFTc                    sH   |ˆ _ |du rt d¡}||ƒˆ _g ˆ _‡ fdd„t|ƒ ¡ D ƒˆ _dS )aÑ  
        :arg tree: a treebuilder class controlling the type of tree that will be
            returned. Built in treebuilders can be accessed through
            html5lib.treebuilders.getTreeBuilder(treeType)

        :arg strict: raise an exception when a parse error is encountered

        :arg namespaceHTMLElements: whether or not to namespace HTML elements

        :arg debug: whether or not to enable debug mode which logs things

        Example:

        >>> from html5lib.html5parser import HTMLParser
        >>> parser = HTMLParser()                     # generates parser with etree builder
        >>> parser = HTMLParser('lxml', strict=True)  # generates parser with lxml builder which is strict

        Nr   c                    s   i | ]\}}||ˆ ˆ j ƒ“qS r(   )Útree)Ú.0ÚnameÚcls©Úselfr(   r)   Ú
<dictcomp>y   ó    z'HTMLParser.__init__.<locals>.<dictcomp>)Ústrictr
   r    rA   ÚerrorsÚ	getPhasesr.   Úphases)rF   rA   rI   r   Údebugr(   rE   r)   Ú__init__]   s    



ÿzHTMLParser.__init__r*   c                 K   sf   || _ || _|| _tj|fd| i|¤Ž| _|  ¡  z|  ¡  W n" ty`   |  ¡  |  ¡  Y n0 d S )NÚparser)	ÚinnerHTMLModer+   Ú	scriptingr	   ÚHTMLTokenizerÚ	tokenizerÚresetÚmainLoopr   )rF   ÚstreamÚ	innerHTMLr+   rQ   r%   r(   r(   r)   Ú_parse|   s    zHTMLParser._parsec                 C   sÄ   | j  ¡  d| _g | _g | _d| _| jrœ| j ¡ | _	| j	t
v rL| jj| j_n0| j	tv rd| jj| j_n| j	dkr|| jj| j_n | jd | _| j ¡  |  ¡  nd| _	| jd | _d | _d | _d| _d S )NFz	no quirksÚ	plaintextÚ
beforeHtmlÚinitialT)rA   rT   ÚfirstStartTagrJ   ÚlogÚ
compatModerP   r+   ÚlowerrW   r   rS   ÚrcdataStateÚstater   ÚrawtextStateÚplaintextStaterL   ÚphaseÚinsertHtmlElementÚresetInsertionModeÚ	lastPhaseÚbeforeRCDataPhaseÚ
framesetOKrE   r(   r(   r)   rT   Š   s*    





zHTMLParser.resetc                 C   s   t | dƒsdS | jjjd jS )z‡Name of the character encoding that was used to decode the input stream, or
        :obj:`None` if that is not determined yet

        rS   Nr   )ÚhasattrrS   rV   ÚcharEncodingrC   rE   r(   r(   r)   ÚdocumentEncoding¬   s    
zHTMLParser.documentEncodingc                 C   sJ   |j dkr6|jtd kr6d|jv o4|jd  t¡dv S |j|j ftv S d S )Núannotation-xmlÚmathmlÚencoding)z	text/htmlzapplication/xhtml+xml)rC   Ú	namespacer   Ú
attributesÚ	translater   r   ©rF   Úelementr(   r(   r)   ÚisHTMLIntegrationPoint¶   s    
ÿ

ÿþÿz!HTMLParser.isHTMLIntegrationPointc                 C   s   |j |jftv S r-   )rp   rC   r   rs   r(   r(   r)   ÚisMathMLTextIntegrationPointÀ   s    z'HTMLParser.isMathMLTextIntegrationPointc                 C   sf  t d }t d }t d }t d }t d }t d }t d }| jD �]â}d }	|}
|
d u�rö|
}	| jjrn| jjd nd }|r||jnd }|rŠ|jnd }|
d	 }||kr¼|  |
d
 |
 di ¡¡ d }
qLt| jjƒdk�sb|| jj	k�sb|  
|¡�r||k�r|d tddgƒv�sb|||fv �sb|td k�rF|dk�rF||k�rF|d dk�sb|  |¡�rj||||fv �rj| j}n
| jd }||k�rŠ| |
¡}
qL||k�r | |
¡}
qL||k�r¶| |
¡}
qL||k�rÌ| |
¡}
qL||k�râ| |
¡}
qL||krL| |
¡}
qL||kr>|	d r>|	d s>|  dd|	d i¡ q>d}g }|�rb| | j¡ | j ¡ }|�r,| j|v�s,J ‚�q,d S )NÚ
CharactersÚSpaceCharactersÚStartTagÚEndTagÚCommentÚDoctypeÚ
ParseErroréÿÿÿÿr2   ÚdataÚdatavarsr   rC   ÚmglyphÚ
malignmarkrn   rm   ÚsvgÚinForeignContentÚselfClosingÚselfClosingAcknowledgedz&non-void-element-with-trailing-solidusT)r   rS   rA   ÚopenElementsrp   rC   Ú
parseErrorÚgetÚlenÚdefaultNamespacerv   Ú	frozensetr   ru   rd   rL   ÚprocessCharactersÚprocessSpaceCharactersÚprocessStartTagÚprocessEndTagÚprocessCommentÚprocessDoctypeÚappendÚ
processEOF)rF   ÚCharactersTokenÚSpaceCharactersTokenÚStartTagTokenÚEndTagTokenÚCommentTokenÚDoctypeTokenÚParseErrorTokenÚtokenÚ
prev_tokenÚ	new_tokenÚcurrentNodeÚcurrentNodeNamespaceÚcurrentNodeNamer2   rd   Ú	reprocessrL   r(   r(   r)   rU   Ã   sŠ    

ÿþýü
û
úùø	
÷
öõ





ÿ
ÿ
zHTMLParser.mainLoopc                 O   s&   | j |ddg|¢R i |¤Ž | j ¡ S )aî  Parse a HTML document into a well-formed tree

        :arg stream: a file-like object or string containing the HTML to be parsed

            The optional encoding parameter must be a string that indicates
            the encoding.  If specified, that encoding will be used,
            regardless of any BOM or later declaration (such as in a meta
            element).

        :arg scripting: treat noscript elements as if JavaScript was turned on

        :returns: parsed tree

        Example:

        >>> from html5lib.html5parser import HTMLParser
        >>> parser = HTMLParser()
        >>> parser.parse('<html><body><p>This is a doc</p></body></html>')
        <Element u'{http://www.w3.org/1999/xhtml}html' at 0x7feac4909db0>

        FN)rX   rA   ÚgetDocument©rF   rV   Úargsr%   r(   r(   r)   r"     s    zHTMLParser.parsec                 O   s$   | j |dg|¢R i |¤Ž | j ¡ S )aZ  Parse a HTML fragment into a well-formed tree fragment

        :arg container: name of the element we're setting the innerHTML
            property if set to None, default to 'div'

        :arg stream: a file-like object or string containing the HTML to be parsed

            The optional encoding parameter must be a string that indicates
            the encoding.  If specified, that encoding will be used,
            regardless of any BOM or later declaration (such as in a meta
            element)

        :arg scripting: treat noscript elements as if JavaScript was turned on

        :returns: parsed tree

        Example:

        >>> from html5lib.html5libparser import HTMLParser
        >>> parser = HTMLParser()
        >>> parser.parseFragment('<b>this is a fragment</b>')
        <Element u'DOCUMENT_FRAGMENT' at 0x7feac484b090>

        T)rX   rA   ÚgetFragmentr¤   r(   r(   r)   r,     s    zHTMLParser.parseFragmentúXXX-undefined-errorc                 C   s@   |d u ri }| j  | jj ¡ ||f¡ | jr<tt| | ƒ‚d S r-   )rJ   r“   rS   rV   ÚpositionrI   r}   r   )rF   Ú	errorcoder€   r(   r(   r)   rˆ   ;  s
    zHTMLParser.parseErrorc                 C   s   t |tƒ d S r-   )Úadjust_attributesr   ©rF   rœ   r(   r(   r)   r   C  s    z!HTMLParser.adjustMathMLAttributesc                 C   s   t |tƒ d S r-   )rª   r   r«   r(   r(   r)   r   F  s    zHTMLParser.adjustSVGAttributesc                 C   s   t |tƒ d S r-   )rª   ÚadjustForeignAttributesMapr«   r(   r(   r)   r   I  s    z"HTMLParser.adjustForeignAttributesc                 C   s   | j  ¡  d S r-   )rO   rd   r«   r(   r(   r)   ÚreparseTokenNormalL  s    zHTMLParser.reparseTokenNormalc                 C   sÊ   d}ddddddddddd	d	d
ddœ}| j jd d d… D ]†}|j}d }|| j jd krj| js`J ‚d}| j}|dv r|| js|J ‚|s�|j| j jkr�q8||v r¬| j||  } qÀq8|r8| jd	 } qÀq8|| _d S )NFÚinSelectÚinCellÚinRowÚinTableBodyÚ	inCaptionÚinColumnGroupÚinTableÚinBodyÚ
inFramesetÚ
beforeHead)ÚselectÚtdÚthÚtrÚtbodyÚtheadÚtfootÚcaptionÚcolgroupÚtableÚheadÚbodyÚframesetÚhtmlr~   r   T)r¸   rÀ   rÂ   rÅ   )rA   r‡   rC   rW   rp   r‹   rL   rd   )rF   ÚlastÚnewModesÚnodeÚnodeNameÚ	new_phaser(   r(   r)   rf   P  sD    ò


zHTMLParser.resetInsertionModec                 C   sR   |dv sJ ‚| j  |¡ |dkr.| jj| j_n| jj| j_| j| _| jd | _d S )N)ÚRAWTEXTÚRCDATArË   Útext)	rA   ÚinsertElementrS   rb   ra   r`   rd   ÚoriginalPhaserL   )rF   rœ   ÚcontentTyper(   r(   r)   ÚparseRCDataRawtext|  s    zHTMLParser.parseRCDataRawtext)NFTF)Fr*   F)r§   N)r<   r=   r>   Ú__doc__rN   rX   rT   Úpropertyrl   ru   rv   rU   r"   r,   rˆ   r   r   r   r­   rf   rÑ   r(   r(   r(   r)   r!   V   s$   

"
	
C
,r!   c                    s   dd„ }dd„ }G dd„ dt || |ƒƒƒ‰G dd„ dˆƒ}G d	d
„ d
ˆƒ}G dd„ dˆƒ}G dd„ dˆƒ}G dd„ dˆƒ}G dd„ dˆƒ}G ‡ ‡fdd„dˆƒ‰ G dd„ dˆƒ}	G ‡fdd„dˆƒ}
G ‡fdd„dˆƒ‰G ‡fdd„dˆƒ}G ‡fdd„dˆƒ}G ‡fdd „d ˆƒ}G ‡fd!d"„d"ˆƒ}G ‡fd#d$„d$ˆƒ}G ‡fd%d&„d&ˆƒ}G d'd(„ d(ˆƒ}G ‡fd)d*„d*ˆƒ}G d+d,„ d,ˆƒ}G ‡fd-d.„d.ˆƒ}G ‡fd/d0„d0ˆƒ}G d1d2„ d2ˆƒ}G d3d4„ d4ˆƒ}||||||ˆ |	|
ˆ|||||||||||||d5œS )6Nc                    s$   dd„ t  ¡ D ƒ‰‡ ‡fdd„}|S )z4Logger that records which phase processes each tokenc                 S   s   i | ]\}}||“qS r(   r(   )rB   ÚkeyÚvaluer(   r(   r)   rG   �  rH   z*getPhases.<locals>.log.<locals>.<dictcomp>c                    s¦   ˆ j  d¡rŒt|ƒdkrŒ|d }dˆ|d  i}|d tv rH|d |d< | jj | jjjj | jj	j
j | j
j ˆ j |f¡ ˆ | g|¢R i |¤ŽS ˆ | g|¢R i |¤ŽS d S )NÚprocessr   r2   rC   )r<   Ú
startswithrŠ   r   rO   r]   r“   rS   ra   rd   Ú	__class__)rF   r¥   r%   rœ   Úinfo©r;   Ú
type_namesr(   r)   Úwrapped’  s    
üz'getPhases.<locals>.log.<locals>.wrapped)r   r.   )r;   rÜ   r(   rÚ   r)   r]   Ž  s    zgetPhases.<locals>.logc                 S   s   | rt |ƒS tS d S r-   )r@   r2   )Úuse_metaclassÚmetaclass_funcr(   r(   r)   ÚgetMetaclass£  s    zgetPhases.<locals>.getMetaclassc                   @   s\   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )zgetPhases.<locals>.PhasezNBase class for helper object that implements each phase of processing
        )rO   rA   Ú__startTagCacheÚ__endTagCachec                 S   s   || _ || _i | _i | _d S r-   )rO   rA   Ú_Phase__startTagCacheÚ_Phase__endTagCache)rF   rO   rA   r(   r(   r)   rN   ¯  s    z!getPhases.<locals>.Phase.__init__c                 S   s   t ‚d S r-   )ÚNotImplementedErrorrE   r(   r(   r)   r”   µ  s    z#getPhases.<locals>.Phase.processEOFc                 S   s   | j  || j jd ¡ d S )Nr~   ©rA   ÚinsertCommentr‡   r«   r(   r(   r)   r‘   ¸  s    z'getPhases.<locals>.Phase.processCommentc                 S   s   | j  d¡ d S )Nzunexpected-doctype©rO   rˆ   r«   r(   r(   r)   r’   ½  s    z'getPhases.<locals>.Phase.processDoctypec                 S   s   | j  |d ¡ d S ©Nr   ©rA   Ú
insertTextr«   r(   r(   r)   r�   À  s    z*getPhases.<locals>.Phase.processCharactersc                 S   s   | j  |d ¡ d S rè   ré   r«   r(   r(   r)   rŽ   Ã  s    z/getPhases.<locals>.Phase.processSpaceCharactersc                 S   sj   |d }|| j v r| j | }nD| j|  }| j |< t| j ƒt| jƒd krb| j  tt| j ƒƒ¡ q2||ƒS ©NrC   gš™™™™™ñ?)râ   ÚstartTagHandlerrŠ   ÚpopÚnextÚiter©rF   rœ   rC   Úfuncr(   r(   r)   r�   Æ  s    
z(getPhases.<locals>.Phase.processStartTagc                 S   sf   | j js |d dkr | j  d¡ |d  ¡ D ],\}}|| jjd jvr,|| jjd j|< q,d| j _d S )NrC   rÅ   znon-html-rootr   r   F)rO   r\   rˆ   r.   rA   r‡   rq   ©rF   rœ   ÚattrrÕ   r(   r(   r)   ÚstartTagHtml×  s    z%getPhases.<locals>.Phase.startTagHtmlc                 S   sj   |d }|| j v r| j | }nD| j|  }| j |< t| j ƒt| jƒd krb| j  tt| j ƒƒ¡ q2||ƒS rë   )rã   ÚendTagHandlerrŠ   rí   rî   rï   rð   r(   r(   r)   r�   á  s    
z&getPhases.<locals>.Phase.processEndTagN)r<   r=   r>   rÒ   Ú	__slots__rN   r”   r‘   r’   r�   rŽ   r�   rô   r�   r(   r(   r(   r)   ÚPhaseª  s   
r÷   c                   @   sR   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZdS )zgetPhases.<locals>.InitialPhasec                 S   s   d S r-   r(   r«   r(   r(   r)   rŽ   õ  s    z6getPhases.<locals>.InitialPhase.processSpaceCharactersc                 S   s   | j  || j j¡ d S r-   ©rA   ræ   Údocumentr«   r(   r(   r)   r‘   ø  s    z.getPhases.<locals>.InitialPhase.processCommentc                 S   sü   |d }|d }|d }|d }|dks@|d us@|d urL|dkrL| j  d¡ |d u rXd}| j |¡ |dkrv| t¡}|rº|d dksº| d	¡sº|d
v sº| d¡rª|d u sº|rÄ| ¡ dkrÄd| j _n$| d¡sà| d¡rè|d urèd| j _| j j	d | j _
d S )NrC   ÚpublicIdÚsystemIdÚcorrectrÅ   zabout:legacy-compatzunknown-doctypeÚ )7z*+//silmaril//dtd html pro v0r11 19970101//z4-//advasoft ltd//dtd html 3.0 aswedit + extensions//z*-//as//dtd html 3.0 aswedit + extensions//z-//ietf//dtd html 2.0 level 1//z-//ietf//dtd html 2.0 level 2//z&-//ietf//dtd html 2.0 strict level 1//z&-//ietf//dtd html 2.0 strict level 2//z-//ietf//dtd html 2.0 strict//z-//ietf//dtd html 2.0//z-//ietf//dtd html 2.1e//z-//ietf//dtd html 3.0//z-//ietf//dtd html 3.2 final//z-//ietf//dtd html 3.2//z-//ietf//dtd html 3//z-//ietf//dtd html level 0//z-//ietf//dtd html level 1//z-//ietf//dtd html level 2//z-//ietf//dtd html level 3//z"-//ietf//dtd html strict level 0//z"-//ietf//dtd html strict level 1//z"-//ietf//dtd html strict level 2//z"-//ietf//dtd html strict level 3//z-//ietf//dtd html strict//z-//ietf//dtd html//z(-//metrius//dtd metrius presentational//z5-//microsoft//dtd internet explorer 2.0 html strict//z.-//microsoft//dtd internet explorer 2.0 html//z0-//microsoft//dtd internet explorer 2.0 tables//z5-//microsoft//dtd internet explorer 3.0 html strict//z.-//microsoft//dtd internet explorer 3.0 html//z0-//microsoft//dtd internet explorer 3.0 tables//z#-//netscape comm. corp.//dtd html//z*-//netscape comm. corp.//dtd strict html//z*-//o'reilly and associates//dtd html 2.0//z3-//o'reilly and associates//dtd html extended 1.0//z;-//o'reilly and associates//dtd html extended relaxed 1.0//zN-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//zE-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//z$-//spyglass//dtd html 2.0 extended//z+-//sq//dtd html 2.0 hotmetal + extensions//z--//sun microsystems corp.//dtd hotjava html//z4-//sun microsystems corp.//dtd hotjava strict html//z-//w3c//dtd html 3 1995-03-24//z-//w3c//dtd html 3.2 draft//z-//w3c//dtd html 3.2 final//z-//w3c//dtd html 3.2//z-//w3c//dtd html 3.2s draft//z-//w3c//dtd html 4.0 frameset//z#-//w3c//dtd html 4.0 transitional//z(-//w3c//dtd html experimental 19960712//z&-//w3c//dtd html experimental 970421//z-//w3c//dtd w3 html//z-//w3o//dtd w3 html 3.0//z#-//webtechs//dtd mozilla html 2.0//z-//webtechs//dtd mozilla html//)z$-//w3o//dtd w3 html strict 3.0//en//z"-/w3c/dtd html 4.0 transitional/enrÅ   )z -//w3c//dtd html 4.01 frameset//z$-//w3c//dtd html 4.01 transitional//z:http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtdÚquirks)z -//w3c//dtd xhtml 1.0 frameset//z$-//w3c//dtd xhtml 1.0 transitional//zlimited quirksrZ   )rO   rˆ   rA   ÚinsertDoctyperr   r   r×   r_   r^   rL   rd   )rF   rœ   rC   rú   rû   rü   r(   r(   r)   r’   û  sX    ÿÿ
ÿÿ9Ç<ÿÄ?Á@À@
ÀA
ÿÿýúz.getPhases.<locals>.InitialPhase.processDoctypec                 S   s   d| j _| j jd | j _d S )Nrþ   rZ   )rO   r^   rL   rd   rE   r(   r(   r)   ÚanythingElseZ  s    z,getPhases.<locals>.InitialPhase.anythingElsec                 S   s   | j  d¡ |  ¡  |S )Nzexpected-doctype-but-got-chars©rO   rˆ   r   r«   r(   r(   r)   r�   ^  s    z1getPhases.<locals>.InitialPhase.processCharactersc                 S   s"   | j  dd|d i¡ |  ¡  |S )Nz"expected-doctype-but-got-start-tagrC   r  r«   r(   r(   r)   r�   c  s
    
ÿz/getPhases.<locals>.InitialPhase.processStartTagc                 S   s"   | j  dd|d i¡ |  ¡  |S )Nz expected-doctype-but-got-end-tagrC   r  r«   r(   r(   r)   r�   i  s
    
ÿz-getPhases.<locals>.InitialPhase.processEndTagc                 S   s   | j  d¡ |  ¡  dS )Nzexpected-doctype-but-got-eofTr  rE   r(   r(   r)   r”   o  s    z*getPhases.<locals>.InitialPhase.processEOFN)r<   r=   r>   Útuplerö   rŽ   r‘   r’   r   r�   r�   r�   r”   r(   r(   r(   r)   ÚInitialPhaseò  s   _r  c                   @   sJ   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )z"getPhases.<locals>.BeforeHtmlPhasec                 S   s&   | j  tddƒ¡ | jjd | j_d S )NrÅ   ry   r·   )rA   Ú
insertRootÚimpliedTagTokenrO   rL   rd   rE   r(   r(   r)   re   x  s    z4getPhases.<locals>.BeforeHtmlPhase.insertHtmlElementc                 S   s   |   ¡  dS ©NT©re   rE   r(   r(   r)   r”   }  s    z-getPhases.<locals>.BeforeHtmlPhase.processEOFc                 S   s   | j  || j j¡ d S r-   rø   r«   r(   r(   r)   r‘   �  s    z1getPhases.<locals>.BeforeHtmlPhase.processCommentc                 S   s   d S r-   r(   r«   r(   r(   r)   rŽ   „  s    z9getPhases.<locals>.BeforeHtmlPhase.processSpaceCharactersc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r�   ‡  s    z4getPhases.<locals>.BeforeHtmlPhase.processCharactersc                 S   s    |d dkrd| j _|  ¡  |S )NrC   rÅ   T)rO   r\   re   r«   r(   r(   r)   r�   ‹  s    z2getPhases.<locals>.BeforeHtmlPhase.processStartTagc                 S   s4   |d dvr$| j  dd|d i¡ n|  ¡  |S d S )NrC   ©rÂ   rÃ   rÅ   Úbrzunexpected-end-tag-before-html)rO   rˆ   re   r«   r(   r(   r)   r�   ‘  s    
ÿz0getPhases.<locals>.BeforeHtmlPhase.processEndTagN)r<   r=   r>   r  rö   re   r”   r‘   rŽ   r�   r�   r�   r(   r(   r(   r)   ÚBeforeHtmlPhaset  s   r
  c                   @   s„   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Ze defde	fg¡Ze
e_e defg¡Zee_dS )z"getPhases.<locals>.BeforeHeadPhasec                 S   s   |   tddƒ¡ dS )NrÂ   ry   T©ÚstartTagHeadr  rE   r(   r(   r)   r”   œ  s    z-getPhases.<locals>.BeforeHeadPhase.processEOFc                 S   s   d S r-   r(   r«   r(   r(   r)   rŽ      s    z9getPhases.<locals>.BeforeHeadPhase.processSpaceCharactersc                 S   s   |   tddƒ¡ |S ©NrÂ   ry   r  r«   r(   r(   r)   r�   £  s    z4getPhases.<locals>.BeforeHeadPhase.processCharactersc                 S   s   | j jd  |¡S ©Nrµ   ©rO   rL   r�   r«   r(   r(   r)   rô   §  s    z/getPhases.<locals>.BeforeHeadPhase.startTagHtmlc                 S   s0   | j  |¡ | j jd | j _| jjd | j_d S )Nr~   ÚinHead)rA   rÎ   r‡   ÚheadPointerrO   rL   rd   r«   r(   r(   r)   r  ª  s    z/getPhases.<locals>.BeforeHeadPhase.startTagHeadc                 S   s   |   tddƒ¡ |S r  r  r«   r(   r(   r)   ÚstartTagOther¯  s    z0getPhases.<locals>.BeforeHeadPhase.startTagOtherc                 S   s   |   tddƒ¡ |S r  r  r«   r(   r(   r)   ÚendTagImplyHead³  s    z2getPhases.<locals>.BeforeHeadPhase.endTagImplyHeadc                 S   s   | j  dd|d i¡ d S )Nzend-tag-after-implied-rootrC   rç   r«   r(   r(   r)   ÚendTagOther·  s    
ÿz.getPhases.<locals>.BeforeHeadPhase.endTagOtherrÅ   rÂ   r  N)r<   r=   r>   r  rö   r”   rŽ   r�   rô   r  r  r  r  r   ÚMethodDispatcherrì   Údefaultrõ   r(   r(   r(   r)   ÚBeforeHeadPhase™  s$   þÿr  c                   @   sæ   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze defd efd!efd"efd#efd$e	fd%e
fd&efg¡Zee_e d&efd'efg¡Zee_d(S ))zgetPhases.<locals>.InHeadPhasec                 S   s   |   ¡  dS r  ©r   rE   r(   r(   r)   r”   Ê  s    z)getPhases.<locals>.InHeadPhase.processEOFc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r�   Î  s    z0getPhases.<locals>.InHeadPhase.processCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   Ò  s    z+getPhases.<locals>.InHeadPhase.startTagHtmlc                 S   s   | j  d¡ d S )Nz!two-heads-are-not-better-than-onerç   r«   r(   r(   r)   r  Õ  s    z+getPhases.<locals>.InHeadPhase.startTagHeadc                 S   s$   | j  |¡ | j j ¡  d|d< d S ©NTr†   ©rA   rÎ   r‡   rí   r«   r(   r(   r)   ÚstartTagBaseLinkCommandØ  s    z6getPhases.<locals>.InHeadPhase.startTagBaseLinkCommandc                 S   s´   | j  |¡ | j j ¡  d|d< |d }| jjjjd dkr°d|v rZ| jjj |d ¡ nVd|v r°d|v r°|d  	¡ d	kr°t
 |d  d
¡¡}t
 |¡}| ¡ }| jjj |¡ d S )NTr†   r   r   Ú	tentativeÚcharsetÚcontentz
http-equivzcontent-typezutf-8)rA   rÎ   r‡   rí   rO   rS   rV   rk   ÚchangeEncodingr_   r   ÚEncodingBytesÚencodeÚContentAttrParserr"   )rF   rœ   rq   r   rO   Úcodecr(   r(   r)   ÚstartTagMetaÝ  s     ÿþ
z+getPhases.<locals>.InHeadPhase.startTagMetac                 S   s   | j  |d¡ d S )NrÌ   ©rO   rÑ   r«   r(   r(   r)   ÚstartTagTitleò  s    z,getPhases.<locals>.InHeadPhase.startTagTitlec                 S   s   | j  |d¡ d S )NrË   r%  r«   r(   r(   r)   ÚstartTagNoFramesStyleõ  s    z4getPhases.<locals>.InHeadPhase.startTagNoFramesStylec                 S   s8   | j jr| j  |d¡ n| j |¡ | j jd | j _d S )NrË   ÚinHeadNoscript)rO   rQ   rÑ   rA   rÎ   rL   rd   r«   r(   r(   r)   ÚstartTagNoscriptù  s    z/getPhases.<locals>.InHeadPhase.startTagNoscriptc                 S   s<   | j  |¡ | jjj| jj_| jj| j_| jjd | j_d S )NrÍ   )	rA   rÎ   rO   rS   ÚscriptDataStatera   rd   rÏ   rL   r«   r(   r(   r)   ÚstartTagScript   s    z-getPhases.<locals>.InHeadPhase.startTagScriptc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r    s    z,getPhases.<locals>.InHeadPhase.startTagOtherc                 S   s:   | j jj ¡ }|jdks&J d|j ƒ‚| j jd | j _d S )NrÂ   zExpected head got %sÚ	afterHead©rO   rA   r‡   rí   rC   rL   rd   ©rF   rœ   rÈ   r(   r(   r)   Ú
endTagHead
  s    z)getPhases.<locals>.InHeadPhase.endTagHeadc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   ÚendTagHtmlBodyBr  s    z/getPhases.<locals>.InHeadPhase.endTagHtmlBodyBrc                 S   s   | j  dd|d i¡ d S ©Núunexpected-end-tagrC   rç   r«   r(   r(   r)   r    s    z*getPhases.<locals>.InHeadPhase.endTagOtherc                 S   s   |   tdƒ¡ d S )NrÂ   )r/  r  rE   r(   r(   r)   r     s    z+getPhases.<locals>.InHeadPhase.anythingElserÅ   Útitle)ÚnoframesÚstyleÚnoscriptÚscript)ÚbaseÚbasefontÚbgsoundÚcommandÚlinkr4   rÂ   )r	  rÅ   rÃ   N)r<   r=   r>   r  rö   r”   r�   rô   r  r  r$  r&  r'  r)  r+  r  r/  r0  r  r   r   r  rì   r  rõ   r(   r(   r(   r)   ÚInHeadPhaseÆ  sD   ÿ÷þr=  c                   @   s°   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze de	fde
fdefg¡Zee_e defdefg¡Zee_dS )z&getPhases.<locals>.InHeadNoscriptPhasec                 S   s   | j  d¡ |  ¡  dS )Nzeof-in-head-noscriptTr  rE   r(   r(   r)   r”   /  s    z1getPhases.<locals>.InHeadNoscriptPhase.processEOFc                 S   s   | j jd  |¡S ©Nr  )rO   rL   r‘   r«   r(   r(   r)   r‘   4  s    z5getPhases.<locals>.InHeadNoscriptPhase.processCommentc                 S   s   | j  d¡ |  ¡  |S )Nzchar-in-head-noscriptr  r«   r(   r(   r)   r�   7  s    z8getPhases.<locals>.InHeadNoscriptPhase.processCharactersc                 S   s   | j jd  |¡S r>  ©rO   rL   rŽ   r«   r(   r(   r)   rŽ   <  s    z=getPhases.<locals>.InHeadNoscriptPhase.processSpaceCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   ?  s    z3getPhases.<locals>.InHeadNoscriptPhase.startTagHtmlc                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   r  B  s    z>getPhases.<locals>.InHeadNoscriptPhase.startTagBaseLinkCommandc                 S   s   | j  dd|d i¡ d S ©Núunexpected-start-tagrC   rç   r«   r(   r(   r)   ÚstartTagHeadNoscriptE  s    z;getPhases.<locals>.InHeadNoscriptPhase.startTagHeadNoscriptc                 S   s"   | j  dd|d i¡ |  ¡  |S ©Nzunexpected-inhead-noscript-tagrC   r  r«   r(   r(   r)   r  H  s    z4getPhases.<locals>.InHeadNoscriptPhase.startTagOtherc                 S   s:   | j jj ¡ }|jdks&J d|j ƒ‚| j jd | j _d S )Nr6  zExpected noscript got %sr  r-  r.  r(   r(   r)   ÚendTagNoscriptM  s    z5getPhases.<locals>.InHeadNoscriptPhase.endTagNoscriptc                 S   s"   | j  dd|d i¡ |  ¡  |S rC  r  r«   r(   r(   r)   ÚendTagBrR  s    z/getPhases.<locals>.InHeadNoscriptPhase.endTagBrc                 S   s   | j  dd|d i¡ d S r1  rç   r«   r(   r(   r)   r  W  s    z2getPhases.<locals>.InHeadNoscriptPhase.endTagOtherc                 S   s   |   tdƒ¡ d S )Nr6  )rD  r  rE   r(   r(   r)   r   Z  s    z3getPhases.<locals>.InHeadNoscriptPhase.anythingElserÅ   )r9  r:  r<  r4   r4  r5  )rÂ   r6  r6  r	  N)r<   r=   r>   r  rö   r”   r‘   r�   rŽ   rô   r  rB  r  rD  rE  r  r   r   r  rì   r  rõ   r(   r(   r(   r)   ÚInHeadNoscriptPhase,  s0   ýþrF  c                   @   s®   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze defdefde	fde
fdefg¡Zee_e defg¡Zee_dS )z!getPhases.<locals>.AfterHeadPhasec                 S   s   |   ¡  dS r  r  rE   r(   r(   r)   r”   n  s    z,getPhases.<locals>.AfterHeadPhase.processEOFc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r�   r  s    z3getPhases.<locals>.AfterHeadPhase.processCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   v  s    z.getPhases.<locals>.AfterHeadPhase.startTagHtmlc                 S   s(   d| j _| j |¡ | j jd | j _d S )NFrµ   )rO   ri   rA   rÎ   rL   rd   r«   r(   r(   r)   ÚstartTagBodyy  s    z.getPhases.<locals>.AfterHeadPhase.startTagBodyc                 S   s    | j  |¡ | jjd | j_d S )Nr¶   )rA   rÎ   rO   rL   rd   r«   r(   r(   r)   ÚstartTagFrameset~  s    z2getPhases.<locals>.AfterHeadPhase.startTagFramesetc                 S   sr   | j  dd|d i¡ | jj | jj¡ | j jd  |¡ | jjd d d… D ] }|jdkrL| jj 	|¡  qnqLd S )Nz#unexpected-start-tag-out-of-my-headrC   r  r~   rÂ   )
rO   rˆ   rA   r‡   r“   r  rL   r�   rC   Úremover.  r(   r(   r)   ÚstartTagFromHead‚  s    
ÿ
z2getPhases.<locals>.AfterHeadPhase.startTagFromHeadc                 S   s   | j  dd|d i¡ d S r@  rç   r«   r(   r(   r)   r  Œ  s    z.getPhases.<locals>.AfterHeadPhase.startTagHeadc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r  �  s    z/getPhases.<locals>.AfterHeadPhase.startTagOtherc                 S   s   |   ¡  |S r-   r  r«   r(   r(   r)   r0  “  s    z2getPhases.<locals>.AfterHeadPhase.endTagHtmlBodyBrc                 S   s   | j  dd|d i¡ d S r1  rç   r«   r(   r(   r)   r  —  s    z-getPhases.<locals>.AfterHeadPhase.endTagOtherc                 S   s.   | j  tddƒ¡ | jjd | j_d| j_d S )NrÃ   ry   rµ   T)rA   rÎ   r  rO   rL   rd   ri   rE   r(   r(   r)   r   š  s    z.getPhases.<locals>.AfterHeadPhase.anythingElserÅ   rÃ   rÄ   )	r8  r9  r:  r<  r4   r4  r7  r5  r3  rÂ   )rÃ   rÅ   r	  N)r<   r=   r>   r  rö   r”   r�   rô   rG  rH  rJ  r  r  r0  r  r   r   r  rì   r  rõ   r(   r(   r(   r)   ÚAfterHeadPhasek  s4   
þù	ÿrK  c                $       sÖ  e Zd ZdZ‡‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dHdI„ Z'dJdK„ Z(dLdM„ Z)dNdO„ Z*dPdQ„ Z+dRdS„ Z,dTdU„ Z-dVdW„ Z.dXdY„ Z/dZd[„ Z0d\d]„ Z1d^d_„ Z2d`da„ Z3dbdc„ Z4ddde„ Z5dfdg„ Z6e7 8dh”j9fdiefdjefdkefdlefe:efdmefdnefdoefdpefdqefdrefdsefdtefduefdvefdwefdxefdyefdzefd{efd|efd}e fd~e!fde"fd€e#fd�e$fd‚e&fdƒe'fd„e%fd…e(fd†e)fd‡e*fg!¡Z;e+e;_<e7 8dje-fdhe.fdˆe/fdne0fd‰e,fdŠe1fe:e2fd‹e3fdue4fdŒe5fg
¡Z=e6e=_<‡  Z>S )�zgetPhases.<locals>.InBodyPhase)rŽ   c                    s"   t ˆ | ƒj|i |¤Ž | j| _d S r-   )ÚsuperrN   ÚprocessSpaceCharactersNonPrerŽ   ©rF   r¥   r%   )ÚInBodyPhaserØ   r(   r)   rN   ²  s    z'getPhases.<locals>.InBodyPhase.__init__c                 S   s$   |j |j ko"|j|jko"|j|jkS r-   )rC   rp   rq   )rF   Únode1Únode2r(   r(   r)   ÚisMatchingFormattingElement·  s
    
ÿ
þz:getPhases.<locals>.InBodyPhase.isMatchingFormattingElementc                 S   s˜   | j  |¡ | j jd }g }| j jd d d… D ](}|tu r@ qXq.|  ||¡r.| |¡ q.t|ƒdkshJ ‚t|ƒdkr†| j j |d ¡ | j j |¡ d S )Nr~   é   )	rA   rÎ   r‡   ÚactiveFormattingElementsr   rR  r“   rŠ   rI  )rF   rœ   rt   ÚmatchingElementsrÈ   r(   r(   r)   ÚaddFormattingElement½  s    z3getPhases.<locals>.InBodyPhase.addFormattingElementc                 S   s>   t dƒ}| jjd d d… D ]}|j|vr| j d¡  q:qd S )N)ÚddÚdtÚlir'   r¼   r¹   r¾   rº   r½   r»   rÃ   rÅ   r~   z expected-closing-tag-but-got-eof)rŒ   rA   r‡   rC   rO   rˆ   )rF   Úallowed_elementsrÈ   r(   r(   r)   r”   Î  s
    
z)getPhases.<locals>.InBodyPhase.processEOFc                 S   sf   |d }| j | _| d¡rH| jjd jdv rH| jjd  ¡ sH|dd … }|rb| j ¡  | j |¡ d S )Nr   Ú
r~   )ÚpreÚlistingÚtextarear   )	rM  rŽ   r×   rA   r‡   rC   Ú
hasContentÚ#reconstructActiveFormattingElementsrê   )rF   rœ   r   r(   r(   r)   Ú!processSpaceCharactersDropNewlineØ  s    
ÿþ
z@getPhases.<locals>.InBodyPhase.processSpaceCharactersDropNewlinec                 S   sT   |d dkrd S | j  ¡  | j  |d ¡ | jjrPtdd„ |d D ƒƒrPd| j_d S )Nr   ú c                 S   s   g | ]}|t v‘qS r(   ©r   ©rB   Úcharr(   r(   r)   Ú
<listcomp>í  s   ÿzDgetPhases.<locals>.InBodyPhase.processCharacters.<locals>.<listcomp>F)rA   r`  rê   rO   ri   Úanyr«   r(   r(   r)   r�   å  s    
ÿÿz0getPhases.<locals>.InBodyPhase.processCharactersc                 S   s   | j  ¡  | j  |d ¡ d S rè   )rA   r`  rê   r«   r(   r(   r)   rM  ñ  s    
z;getPhases.<locals>.InBodyPhase.processSpaceCharactersNonPrec                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   ÚstartTagProcessInHeadõ  s    z4getPhases.<locals>.InBodyPhase.startTagProcessInHeadc                 S   sˆ   | j  dddi¡ t| jjƒdks4| jjd jdkrB| j js„J ‚nBd| j _|d  ¡ D ],\}}|| jjd j	vrV|| jjd j	|< qVd S )NrA  rC   rÃ   r   Fr   )
rO   rˆ   rŠ   rA   r‡   rC   rW   ri   r.   rq   rò   r(   r(   r)   rG  ø  s    ÿz+getPhases.<locals>.InBodyPhase.startTagBodyc                 S   s¶   | j  dddi¡ t| jjƒdks4| jjd jdkrB| j js²J ‚np| j jsLnf| jjd jrv| jjd j 	| jjd ¡ | jjd jdkr–| jj 
¡  qv| j |¡ | j jd | j _d S )	NrA  rC   rÄ   r   rÃ   r~   rÅ   r¶   )rO   rˆ   rŠ   rA   r‡   rC   rW   ri   ÚparentÚremoveChildrí   rÎ   rL   rd   r«   r(   r(   r)   rH    s    "z/getPhases.<locals>.InBodyPhase.startTagFramesetc                 S   s.   | j jddd�r|  tdƒ¡ | j  |¡ d S ©Nr'   Úbutton©Úvariant)rA   ÚelementInScopeÚendTagPr  rÎ   r«   r(   r(   r)   ÚstartTagCloseP  s    z-getPhases.<locals>.InBodyPhase.startTagClosePc                 S   s>   | j jddd�r|  tdƒ¡ | j  |¡ d| j_| j| _d S )Nr'   rl  rm  F)	rA   ro  rp  r  rÎ   rO   ri   ra  rŽ   r«   r(   r(   r)   ÚstartTagPreListing  s
    z1getPhases.<locals>.InBodyPhase.startTagPreListingc                 S   sZ   | j jr| j dddi¡ n:| j jddd�r:|  tdƒ¡ | j  |¡ | j jd | j _d S )NrA  rC   Úformr'   rl  rm  r~   )	rA   ÚformPointerrO   rˆ   ro  rp  r  rÎ   r‡   r«   r(   r(   r)   ÚstartTagForm  s    z+getPhases.<locals>.InBodyPhase.startTagFormc                 S   s¬   d| j _dgddgddgdœ}||d  }t| jjƒD ]@}|j|v r^| j j t|jdƒ¡  qx|j	t
v r6|jdvr6 qxq6| jjd	d
d�rœ| j j td	dƒ¡ | j |¡ d S )NFrY  rX  rW  )rY  rX  rW  rC   rz   )Úaddressr*   r'   r'   rl  rm  )rO   ri   ÚreversedrA   r‡   rC   rd   r�   r  Ú	nameTupler   ro  rÎ   )rF   rœ   ÚstopNamesMapÚ	stopNamesrÈ   r(   r(   r)   ÚstartTagListItem&  s*    þ

ÿ
ÿÿz/getPhases.<locals>.InBodyPhase.startTagListItemc                 S   s>   | j jddd�r|  tdƒ¡ | j  |¡ | jjj| jj_d S rk  )	rA   ro  rp  r  rÎ   rO   rS   rc   ra   r«   r(   r(   r)   ÚstartTagPlaintext<  s    z0getPhases.<locals>.InBodyPhase.startTagPlaintextc                 S   sb   | j jddd�r|  tdƒ¡ | j jd jtv rR| j dd|d i¡ | j j 	¡  | j  
|¡ d S )Nr'   rl  rm  r~   rA  rC   )rA   ro  rp  r  r‡   rC   r   rO   rˆ   rí   rÎ   r«   r(   r(   r)   ÚstartTagHeadingB  s    z.getPhases.<locals>.InBodyPhase.startTagHeadingc                 S   s~   | j  d¡}|rf| j ddddœ¡ |  tdƒ¡ || j jv rL| j j |¡ || j jv rf| j j |¡ | j  	¡  |  
|¡ d S )NÚaú$unexpected-start-tag-implies-end-tag©Ú	startNameÚendName)rA   Ú!elementInActiveFormattingElementsrO   rˆ   ÚendTagFormattingr  r‡   rI  rT  r`  rV  )rF   rœ   ÚafeAElementr(   r(   r)   Ú	startTagAJ  s    ÿ
z(getPhases.<locals>.InBodyPhase.startTagAc                 S   s   | j  ¡  |  |¡ d S r-   )rA   r`  rV  r«   r(   r(   r)   ÚstartTagFormattingW  s    
z1getPhases.<locals>.InBodyPhase.startTagFormattingc                 S   sP   | j  ¡  | j  d¡rB| j ddddœ¡ |  tdƒ¡ | j  ¡  |  |¡ d S )NÚnobrr  r€  )rA   r`  ro  rO   rˆ   r�   r  rV  r«   r(   r(   r)   ÚstartTagNobr[  s    
ÿ
z+getPhases.<locals>.InBodyPhase.startTagNobrc                 S   sT   | j  d¡r2| j ddddœ¡ |  tdƒ¡ |S | j  ¡  | j  |¡ d| j_d S )Nrl  r  r€  F)	rA   ro  rO   rˆ   r�   r  r`  rÎ   ri   r«   r(   r(   r)   ÚstartTagButtone  s    ÿ
z-getPhases.<locals>.InBodyPhase.startTagButtonc                 S   s0   | j  ¡  | j  |¡ | j j t¡ d| j_d S ©NF)rA   r`  rÎ   rT  r“   r   rO   ri   r«   r(   r(   r)   ÚstartTagAppletMarqueeObjectp  s    
z:getPhases.<locals>.InBodyPhase.startTagAppletMarqueeObjectc                 S   sB   | j jddd�r|  tdƒ¡ | j  ¡  d| j_| j |d¡ d S )Nr'   rl  rm  FrË   )rA   ro  rp  r  r`  rO   ri   rÑ   r«   r(   r(   r)   ÚstartTagXmpv  s
    
z*getPhases.<locals>.InBodyPhase.startTagXmpc                 S   sR   | j jdkr*| jjddd�r*|  tdƒ¡ | j |¡ d| j _| j jd | j _	d S )Nrþ   r'   rl  rm  Fr´   )
rO   r^   rA   ro  r�   r  rÎ   ri   rL   rd   r«   r(   r(   r)   ÚstartTagTable}  s    z,getPhases.<locals>.InBodyPhase.startTagTablec                 S   s6   | j  ¡  | j  |¡ | j j ¡  d|d< d| j_d S )NTr†   F)rA   r`  rÎ   r‡   rí   rO   ri   r«   r(   r(   r)   ÚstartTagVoidFormatting…  s
    
z5getPhases.<locals>.InBodyPhase.startTagVoidFormattingc                 S   s@   | j j}|  |¡ d|d v r<|d d  t¡dkr<|| j _d S )Nr2   r   Úhidden)rO   ri   r�  rr   r   )rF   rœ   ri   r(   r(   r)   ÚstartTagInputŒ  s    
ÿz,getPhases.<locals>.InBodyPhase.startTagInputc                 S   s$   | j  |¡ | j j ¡  d|d< d S r  r  r«   r(   r(   r)   ÚstartTagParamSource”  s    z2getPhases.<locals>.InBodyPhase.startTagParamSourcec                 S   sJ   | j jddd�r|  tdƒ¡ | j  |¡ | j j ¡  d|d< d| j_d S )Nr'   rl  rm  Tr†   F)	rA   ro  rp  r  rÎ   r‡   rí   rO   ri   r«   r(   r(   r)   Ú
startTagHr™  s    z)getPhases.<locals>.InBodyPhase.startTagHrc                 S   s6   | j  ddddœ¡ |  tdd|d |d d�¡ d S )	Nzunexpected-start-tag-treated-asÚimageÚimg©ÚoriginalNameÚnewNamery   r   r…   ©rq   r…   )rO   rˆ   r�   r  r«   r(   r(   r)   ÚstartTagImage¡  s    ÿ
þz,getPhases.<locals>.InBodyPhase.startTagImagec                 S   s  | j  dddi¡ | jjrd S i }d|d v r>|d d |d< |  tdd|d�¡ |  td	dƒ¡ |  td
dƒ¡ d|d v rŒ|d d }nd}|  td |dœ¡ |d  ¡ }d|v r¾|d= d|v rÌ|d= d|d< |  tdd||d d�¡ |  	td
ƒ¡ |  td	dƒ¡ |  	tdƒ¡ d S )Nzdeprecated-tagrC   ÚisindexÚactionr   rs  ry   )rq   ÚhrÚlabelÚpromptz3This is a searchable index. Enter search keywords: rw   ©r2   r   Úinputr…   r™  )
rO   rˆ   rA   rt  r�   r  r�   r   Úcopyr�   )rF   rœ   Ú
form_attrsrŸ  rq   r(   r(   r)   ÚstartTagIsIndex©  s<    
ÿÿ
þz.getPhases.<locals>.InBodyPhase.startTagIsIndexc                 S   s0   | j  |¡ | jjj| jj_| j| _d| j_d S r‹  )	rA   rÎ   rO   rS   r`   ra   ra  rŽ   ri   r«   r(   r(   r)   ÚstartTagTextareaÈ  s    z/getPhases.<locals>.InBodyPhase.startTagTextareac                 S   s   d| j _|  |¡ d S r‹  )rO   ri   ÚstartTagRawtextr«   r(   r(   r)   ÚstartTagIFrameÎ  s    z-getPhases.<locals>.InBodyPhase.startTagIFramec                 S   s"   | j jr|  |¡ n
|  |¡ d S r-   )rO   rQ   r¦  r  r«   r(   r(   r)   r)  Ò  s    z/getPhases.<locals>.InBodyPhase.startTagNoscriptc                 S   s   | j  |d¡ dS )z8iframe, noembed noframes, noscript(if scripting enabled)rË   Nr%  r«   r(   r(   r)   r¦  Ø  s    z.getPhases.<locals>.InBodyPhase.startTagRawtextc                 S   s@   | j jd jdkr$| jj tdƒ¡ | j  ¡  | jj  |¡ d S ©Nr~   Úoption)	rA   r‡   rC   rO   rd   r�   r  r`  rÎ   r«   r(   r(   r)   ÚstartTagOptÜ  s    
z*getPhases.<locals>.InBodyPhase.startTagOptc                 S   sŒ   | j  ¡  | j  |¡ d| j_| jj| jjd | jjd | jjd | jjd | jjd | jjd fv rx| jjd | j_n| jjd	 | j_d S )
NFr´   r²   r³   r±   r°   r¯   ÚinSelectInTabler®   )rA   r`  rÎ   rO   ri   rd   rL   r«   r(   r(   r)   ÚstartTagSelectâ  s    





ûz-getPhases.<locals>.InBodyPhase.startTagSelectc                 S   sB   | j  d¡r2| j  ¡  | j jd jdkr2| j ¡  | j  |¡ d S )NÚrubyr~   )rA   ro  ÚgenerateImpliedEndTagsr‡   rC   rO   rˆ   rÎ   r«   r(   r(   r)   ÚstartTagRpRtð  s
    

z+getPhases.<locals>.InBodyPhase.startTagRpRtc                 S   sZ   | j  ¡  | j |¡ | j |¡ td |d< | j  |¡ |d rV| j j ¡  d|d< d S )Nrn   rp   r…   Tr†   )	rA   r`  rO   r   r   r   rÎ   r‡   rí   r«   r(   r(   r)   ÚstartTagMath÷  s    
z+getPhases.<locals>.InBodyPhase.startTagMathc                 S   sZ   | j  ¡  | j |¡ | j |¡ td |d< | j  |¡ |d rV| j j ¡  d|d< d S )Nrƒ   rp   r…   Tr†   )	rA   r`  rO   r   r   r   rÎ   r‡   rí   r«   r(   r(   r)   ÚstartTagSvg  s    
z*getPhases.<locals>.InBodyPhase.startTagSvgc                 S   s   | j  dd|d i¡ dS )a5   Elements that should be children of other elements that have a
            different insertion mode; here they are ignored
            "caption", "col", "colgroup", "frame", "frameset", "head",
            "option", "optgroup", "tbody", "td", "tfoot", "th", "thead",
            "tr", "noscript"
            zunexpected-start-tag-ignoredrC   Nrç   r«   r(   r(   r)   ÚstartTagMisplaced  s    z0getPhases.<locals>.InBodyPhase.startTagMisplacedc                 S   s   | j  ¡  | j  |¡ d S r-   )rA   r`  rÎ   r«   r(   r(   r)   r    s    
z,getPhases.<locals>.InBodyPhase.startTagOtherc                 S   sœ   | j jddd�sD|  tddƒ¡ | j dddi¡ |  tddƒ¡ nT| j  d¡ | j jd j	dkrt| j dddi¡ | j j 
¡ }|j	dkr˜| j j 
¡ }q€d S )	Nr'   rl  rm  ry   r2  rC   rz   r~   )rA   ro  rq  r  rO   rˆ   rp  r®  r‡   rC   rí   r.  r(   r(   r)   rp    s    
z&getPhases.<locals>.InBodyPhase.endTagPc                 S   s~   | j  d¡s| j ¡  d S | j jd jdkrj| j jdd … D ],}|jtdƒvr<| j dd|jdœ¡  qjq<| jjd | j_d S )NrÃ   r~   é   )rW  rX  rY  Úoptgroupr©  r'   ÚrpÚrtr¼   r¹   r¾   rº   r½   r»   rÃ   rÅ   ú$expected-one-end-tag-but-got-another©ÚgotNameÚexpectedNameÚ	afterBody)	rA   ro  rO   rˆ   r‡   rC   rŒ   rL   rd   r.  r(   r(   r)   Ú
endTagBody)  s    

þz)getPhases.<locals>.InBodyPhase.endTagBodyc                 S   s"   | j  d¡r|  tdƒ¡ |S d S )NrÃ   )rA   ro  r¼  r  r«   r(   r(   r)   Ú
endTagHtml;  s    z)getPhases.<locals>.InBodyPhase.endTagHtmlc                 S   sŽ   |d dkr| j | _| j |d ¡}|r2| j ¡  | jjd j|d kr^| j dd|d i¡ |rŠ| jj 	¡ }|j|d krŠ| jj 	¡ }qnd S )NrC   r\  r~   úend-tag-too-early)
rM  rŽ   rA   ro  r®  r‡   rC   rO   rˆ   rí   )rF   rœ   ÚinScoperÈ   r(   r(   r)   ÚendTagBlockA  s    
z*getPhases.<locals>.InBodyPhase.endTagBlockc                 S   sv   | j j}d | j _|d u s$| j  |¡s8| j dddi¡ n:| j  ¡  | j jd |krd| j dddi¡ | j j |¡ d S )Nr2  rC   rs  r~   zend-tag-too-early-ignored)rA   rt  ro  rO   rˆ   r®  r‡   rI  r.  r(   r(   r)   Ú
endTagFormO  s    ÿ
ÿz)getPhases.<locals>.InBodyPhase.endTagFormc                 S   s¬   |d dkrd}nd }| j j|d |d�sB| j dd|d i¡ nf| j j|d d� | j jd j|d kr€| j dd|d i¡ | j j ¡ }|j|d kr¨| j j ¡ }qŒd S )	NrC   rY  Úlistrm  r2  ©Úexcluder~   r¾  )rA   ro  rO   rˆ   r®  r‡   rC   rí   )rF   rœ   rn  rÈ   r(   r(   r)   ÚendTagListItem\  s    
þz-getPhases.<locals>.InBodyPhase.endTagListItemc                 S   s’   t D ]}| j |¡r| j ¡   q$q| jjd j|d krP| j dd|d i¡ t D ]8}| j |¡rT| jj ¡ }|jt vrˆ| jj ¡ }qp qŽqTd S )Nr~   rC   r¾  )	r   rA   ro  r®  r‡   rC   rO   rˆ   rí   )rF   rœ   Úitemr(   r(   r)   ÚendTagHeadingm  s    

z,getPhases.<locals>.InBodyPhase.endTagHeadingc                 S   s  d}|dk �r
|d7 }| j  |d ¡}|rD|| j jv rR| j  |j¡sR|  |¡ dS || j jvr†| j dd|d i¡ | j j 	|¡ dS | j  |j¡s®| j dd|d i¡ dS || j jd krÔ| j d	d|d i¡ | j j 
|¡}d}| j j|d… D ]}|jtv rö|} �qqö|du �rR| j j ¡ }||k�r@| j j ¡ }�q&| j j 	|¡ dS | j j|d  }| j j 
|¡}| }	}
d}| j j 
|
¡}|d
k �rX|d7 }|d8 }| j j| }
|
| j jv�rÐ| j j 	|
¡ �qŠ|
|k�rÞ�qX|	|k�rú| j j 
|
¡d }|
 ¡ }|| j j| j j 
|
¡< || j j| j j 
|
¡< |}
|	j�rF|	j |	¡ |
 |	¡ |
}	�qŠ|	j�rl|	j |	¡ |jtdƒv �r˜| j  ¡ \}}| |	|¡ n
| |	¡ | ¡ }| |¡ | |¡ | j j 	|¡ | j j ||¡ | j j 	|¡ | j j | j j 
|¡d |¡ qdS )z)The much-feared adoption agency algorithmr   é   r   rC   Nzadoption-agency-1.2zadoption-agency-4.4r~   zadoption-agency-1.3rS  ©rÁ   r¼   r¾   r½   r»   )rA   rƒ  r‡   ro  rC   r  rO   rˆ   rT  rI  Úindexrx  r   rí   Ú	cloneNoderi  rj  ÚappendChildrŒ   ÚgetTableMisnestedNodePositionÚinsertBeforeÚreparentChildrenÚinsert)rF   rœ   ÚouterLoopCounterÚformattingElementÚafeIndexÚfurthestBlockrt   ÚcommonAncestorÚbookmarkÚlastNoderÈ   ÚinnerLoopCounterrÊ  Úcloneri  rÎ  r(   r(   r)   r„  |  sž    

ÿ
ÿþ







ÿÿÿÿ



ÿz/getPhases.<locals>.InBodyPhase.endTagFormattingc                 S   sŒ   | j  |d ¡r| j  ¡  | j jd j|d krF| j dd|d i¡ | j  |d ¡rˆ| j j ¡ }|j|d kr~| j j ¡ }qb| j  ¡  d S )NrC   r~   r¾  )	rA   ro  r®  r‡   rC   rO   rˆ   rí   ÚclearActiveFormattingElements)rF   rœ   rt   r(   r(   r)   ÚendTagAppletMarqueeObject  s    
z8getPhases.<locals>.InBodyPhase.endTagAppletMarqueeObjectc                 S   s@   | j  ddddœ¡ | j ¡  | j tddƒ¡ | jj ¡  d S )Nzunexpected-end-tag-treated-asr	  z
br elementr–  ry   )rO   rˆ   rA   r`  rÎ   r  r‡   rí   r«   r(   r(   r)   rE  +  s    ÿ
z'getPhases.<locals>.InBodyPhase.endTagBrc                 S   s¤   | j jd d d… D ]Œ}|j|d krz| j j|d d� | j jd j|d krb| j dd|d i¡ | j j ¡ |krtqb q q|jtv r| j dd|d i¡  q qd S )Nr~   rC   rÃ  r2  )	rA   r‡   rC   r®  rO   rˆ   rí   rx  r   r.  r(   r(   r)   r  2  s    
z*getPhases.<locals>.InBodyPhase.endTagOtherrÅ   )	r8  r9  r:  r;  r<  r4   r7  r5  r3  rÃ   rÄ   )rv  ÚarticleÚasideÚ
blockquoteÚcenterÚdetailsÚdirr*   ÚdlÚfieldsetÚ
figcaptionÚfigureÚfooterÚheaderÚhgroupÚmainÚmenuÚnavÚolr'   ÚsectionÚsummaryÚul)r\  r]  rs  )rY  rW  rX  rY   r~  )ÚbÚbigÚcodeÚemÚfontÚiÚsÚsmallÚstrikeÚstrongÚttÚurˆ  rl  )ÚappletÚmarqueeÚobjectÚxmprÁ   )Úarear	  Úembedr•  ÚkeygenÚwbr)ÚparamÚsourceÚtrackr¡  r�  r”  r›  r^  Úiframer6  )Únoembedr4  r¸   )rµ  r¶  )r©  r´  Úmathrƒ   )r¿   ÚcolrÀ   ÚframerÂ   r¼   r¹   r¾   rº   r½   r»   )rv  rÜ  rÝ  rÞ  rl  rß  rà  Údialográ  r*   râ  rã  rä  rå  ræ  rç  rè  r]  ré  rê  rë  rì  r\  rí  rî  rï  r'   )rW  rX  rY  )r~  rð  rñ  rò  ró  rô  rõ  rˆ  rö  r÷  rø  rù  rú  rû  r	  )?r<   r=   r>   rö   rN   rR  rV  r”   ra  r�   rM  rh  rG  rH  rq  rr  ru  r{  r|  r}  r†  r‡  r‰  rŠ  rŒ  r�  rŽ  r�  r‘  r’  r“  rš  r¤  r¥  r§  r)  r¦  rª  r¬  r¯  r°  r±  r²  r  rp  r¼  r½  rÀ  rÁ  rÅ  rÇ  r„  rÛ  rE  r  r   r  rô   r   rì   r  rõ   Ú__classcell__r(   )rO  r÷   ©rØ   r)   rO  ­  sè   
	
	 $þüÿÿþ×-ýÿòrO  c                   @   s`   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	e
 g ¡Zee_e
 defg¡Ze	e_dS )zgetPhases.<locals>.TextPhasec                 S   s   | j  |d ¡ d S rè   ré   r«   r(   r(   r)   r�   „  s    z.getPhases.<locals>.TextPhase.processCharactersc                 S   s8   | j  dd| jjd ji¡ | jj ¡  | j j| j _dS )Nz&expected-named-closing-tag-but-got-eofrC   r~   T)rO   rˆ   rA   r‡   rC   rí   rÏ   rd   rE   r(   r(   r)   r”   ‡  s    ÿz'getPhases.<locals>.TextPhase.processEOFc                 S   s   dsJ d|d  ƒ‚d S )NFz4Tried to process start tag %s in RCDATA/RAWTEXT moderC   r(   r«   r(   r(   r)   r  Ž  s    z*getPhases.<locals>.TextPhase.startTagOtherc                 S   s*   | j j ¡ }|jdksJ ‚| jj| j_d S )Nr7  )rA   r‡   rí   rC   rO   rÏ   rd   r.  r(   r(   r)   ÚendTagScript‘  s    z)getPhases.<locals>.TextPhase.endTagScriptc                 S   s   | j j ¡  | jj| j_d S r-   )rA   r‡   rí   rO   rÏ   rd   r«   r(   r(   r)   r  ˜  s    z(getPhases.<locals>.TextPhase.endTagOtherr7  N)r<   r=   r>   r  rö   r�   r”   r  r  r  r   r  rì   r  rõ   r(   r(   r(   r)   Ú	TextPhase�  s   
ÿr  c                       s  e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Ze d%” jfd&e
fd'efd(efd)efd*efd+efd,efd-efd.efg
¡Zee_e d+efd/efg¡Zee_d0S )1zgetPhases.<locals>.InTablePhasec                 S   s$   | j jd jdvr | j j ¡  q d S )Nr~   )rÁ   rÅ   )rA   r‡   rC   rí   rE   r(   r(   r)   ÚclearStackToTableContext§  s    z8getPhases.<locals>.InTablePhase.clearStackToTableContextc                 S   s0   | j jd jdkr | j d¡ n| jjs,J ‚d S )Nr~   rÅ   zeof-in-table©rA   r‡   rC   rO   rˆ   rW   rE   r(   r(   r)   r”   °  s    z*getPhases.<locals>.InTablePhase.processEOFc                 S   s4   | j j}| j jd | j _|| j j_| j j |¡ d S ©NÚinTableText)rO   rd   rL   rÏ   rŽ   ©rF   rœ   rÏ   r(   r(   r)   rŽ   ·  s    
z6getPhases.<locals>.InTablePhase.processSpaceCharactersc                 S   s4   | j j}| j jd | j _|| j j_| j j |¡ d S r  )rO   rd   rL   rÏ   r�   r  r(   r(   r)   r�   ½  s    
z1getPhases.<locals>.InTablePhase.processCharactersc                 S   s&   d| j _| jjd  |¡ d| j _d S )NTrµ   F)rA   ÚinsertFromTablerO   rL   r�   r«   r(   r(   r)   rê   Ã  s    z*getPhases.<locals>.InTablePhase.insertTextc                 S   s6   |   ¡  | jj t¡ | j |¡ | jjd | j_d S )Nr²   )	r  rA   rT  r“   r   rÎ   rO   rL   rd   r«   r(   r(   r)   ÚstartTagCaptionÊ  s    z/getPhases.<locals>.InTablePhase.startTagCaptionc                 S   s(   |   ¡  | j |¡ | jjd | j_d S )Nr³   ©r  rA   rÎ   rO   rL   rd   r«   r(   r(   r)   ÚstartTagColgroupÐ  s    z0getPhases.<locals>.InTablePhase.startTagColgroupc                 S   s   |   tddƒ¡ |S )NrÀ   ry   )r  r  r«   r(   r(   r)   ÚstartTagColÕ  s    z+getPhases.<locals>.InTablePhase.startTagColc                 S   s(   |   ¡  | j |¡ | jjd | j_d S ©Nr±   r  r«   r(   r(   r)   ÚstartTagRowGroupÙ  s    z0getPhases.<locals>.InTablePhase.startTagRowGroupc                 S   s   |   tddƒ¡ |S )Nr¼   ry   )r  r  r«   r(   r(   r)   ÚstartTagImplyTbodyÞ  s    z2getPhases.<locals>.InTablePhase.startTagImplyTbodyc                 S   s6   | j  ddddœ¡ | j j tdƒ¡ | j js2|S d S )Nr  rÁ   r€  )rO   rˆ   rd   r�   r  rW   r«   r(   r(   r)   rŽ  â  s    ÿz-getPhases.<locals>.InTablePhase.startTagTablec                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   ÚstartTagStyleScripté  s    z3getPhases.<locals>.InTablePhase.startTagStyleScriptc                 S   sV   d|d v rH|d d   t¡dkrH| j d¡ | j |¡ | jj ¡  n
|  |¡ d S )Nr2   r   r�  z unexpected-hidden-input-in-table)	rr   r   rO   rˆ   rA   rÎ   r‡   rí   r  r«   r(   r(   r)   r‘  ì  s    ÿz-getPhases.<locals>.InTablePhase.startTagInputc                 S   sD   | j  d¡ | jjd u r@| j |¡ | jjd | j_| jj ¡  d S )Nzunexpected-form-in-tabler~   )rO   rˆ   rA   rt  rÎ   r‡   rí   r«   r(   r(   r)   ru  ö  s
    z,getPhases.<locals>.InTablePhase.startTagFormc                 S   s<   | j  dd|d i¡ d| j_| j jd  |¡ d| j_d S )Nz)unexpected-start-tag-implies-table-voodoorC   Trµ   F)rO   rˆ   rA   r  rL   r�   r«   r(   r(   r)   r  ý  s    z-getPhases.<locals>.InTablePhase.startTagOtherc                 S   sœ   | j jddd�r‚| j  ¡  | j jd jdkrJ| j dd| j jd jdœ¡ | j jd jdkrj| j j ¡  qJ| j j ¡  | j ¡  n| jj	sŽJ ‚| j ¡  d S )NrÁ   rm  r~   zend-tag-too-early-namedr¸  )
rA   ro  r®  r‡   rC   rO   rˆ   rí   rf   rW   r«   r(   r(   r)   ÚendTagTable  s    
ÿÿz+getPhases.<locals>.InTablePhase.endTagTablec                 S   s   | j  dd|d i¡ d S r1  rç   r«   r(   r(   r)   ÚendTagIgnore  s    z,getPhases.<locals>.InTablePhase.endTagIgnorec                 S   s<   | j  dd|d i¡ d| j_| j jd  |¡ d| j_d S )Nz'unexpected-end-tag-implies-table-voodoorC   Trµ   F)rO   rˆ   rA   r  rL   r�   r«   r(   r(   r)   r    s    z+getPhases.<locals>.InTablePhase.endTagOtherrÅ   r¿   rÀ   r
  ©r¼   r¾   r½   )r¹   rº   r»   rÁ   )r5  r7  r¡  rs  )rÃ   r¿   r
  rÀ   rÅ   r¼   r¹   r¾   rº   r½   r»   N)r<   r=   r>   r  rö   r  r”   rŽ   r�   rê   r  r  r  r  r  rŽ  r  r‘  ru  r  r  r   r  r   r  rô   rì   r  rõ   r(   ©r÷   r(   r)   ÚInTablePhase¢  sN   	
öÿþr#  c                       sZ   e Zd ZdZ‡‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Z‡  ZS )z#getPhases.<locals>.InTableTextPhase)rÏ   ÚcharacterTokensc                    s&   t ˆ | ƒj|i |¤Ž d | _g | _d S r-   )rL  rN   rÏ   r$  rN  )ÚInTableTextPhaserØ   r(   r)   rN   6  s    z,getPhases.<locals>.InTableTextPhase.__init__c                 S   sd   d  dd„ | jD ƒ¡}tdd„ |D ƒƒrJtd |dœ}| jjd  |¡ n|rZ| j |¡ g | _d S )Nrý   c                 S   s   g | ]}|d  ‘qS )r   r(   ©rB   rÆ  r(   r(   r)   rf  <  rH   zGgetPhases.<locals>.InTableTextPhase.flushCharacters.<locals>.<listcomp>c                 S   s   g | ]}|t v‘qS r(   rc  r&  r(   r(   r)   rf  =  rH   rw   r   r´   )Újoinr$  rg  r   rO   rL   rê   rA   )rF   r   rœ   r(   r(   r)   ÚflushCharacters;  s    z3getPhases.<locals>.InTableTextPhase.flushCharactersc                 S   s   |   ¡  | j| j_|S r-   ©r(  rÏ   rO   rd   r«   r(   r(   r)   r‘   D  s    
z2getPhases.<locals>.InTableTextPhase.processCommentc                 S   s   |   ¡  | j| j_dS r  r)  rE   r(   r(   r)   r”   I  s    
z.getPhases.<locals>.InTableTextPhase.processEOFc                 S   s    |d dkrd S | j  |¡ d S ©Nr   rb  ©r$  r“   r«   r(   r(   r)   r�   N  s    z5getPhases.<locals>.InTableTextPhase.processCharactersc                 S   s   | j  |¡ d S r-   r+  r«   r(   r(   r)   rŽ   S  s    z:getPhases.<locals>.InTableTextPhase.processSpaceCharactersc                 S   s   |   ¡  | j| j_|S r-   r)  r«   r(   r(   r)   r�   X  s    
z3getPhases.<locals>.InTableTextPhase.processStartTagc                 S   s   |   ¡  | j| j_|S r-   r)  r«   r(   r(   r)   r�   ]  s    
z1getPhases.<locals>.InTableTextPhase.processEndTag)r<   r=   r>   rö   rN   r(  r‘   r”   r�   rŽ   r�   r�   r  r(   )r%  r  r)   r%  3  s   	r%  c                       sš   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Ze d” jfdefg¡Ze	e_e de
fdefdefg¡Zee_dS )z!getPhases.<locals>.InCaptionPhasec                 S   s   | j jddd� S )Nr¿   rÁ   rm  ©rA   ro  rE   r(   r(   r)   ÚignoreEndTagCaptionf  s    z5getPhases.<locals>.InCaptionPhase.ignoreEndTagCaptionc                 S   s   | j jd  ¡  d S r  ©rO   rL   r”   rE   r(   r(   r)   r”   i  s    z,getPhases.<locals>.InCaptionPhase.processEOFc                 S   s   | j jd  |¡S r  ©rO   rL   r�   r«   r(   r(   r)   r�   l  s    z3getPhases.<locals>.InCaptionPhase.processCharactersc                 S   s0   | j  ¡  |  ¡ }| j j tdƒ¡ |s,|S d S ©Nr¿   ©rO   rˆ   r-  rd   r�   r  ©rF   rœ   ÚignoreEndTagr(   r(   r)   ÚstartTagTableElemento  s
    
z6getPhases.<locals>.InCaptionPhase.startTagTableElementc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   r  w  s    z/getPhases.<locals>.InCaptionPhase.startTagOtherc                 S   s¤   |   ¡ sŠ| j ¡  | jjd jdkrB| j dd| jjd jdœ¡ | jjd jdkrb| jj ¡  qB| jj ¡  | j ¡  | jj	d | j_
n| jjs–J ‚| j ¡  d S )Nr~   r¿   r·  r¸  r´   )r-  rA   r®  r‡   rC   rO   rˆ   rí   rÚ  rL   rd   rW   r«   r(   r(   r)   ÚendTagCaptionz  s    
ÿÿ
z/getPhases.<locals>.InCaptionPhase.endTagCaptionc                 S   s0   | j  ¡  |  ¡ }| j j tdƒ¡ |s,|S d S r0  r1  r2  r(   r(   r)   r  Œ  s
    
z-getPhases.<locals>.InCaptionPhase.endTagTablec                 S   s   | j  dd|d i¡ d S r1  rç   r«   r(   r(   r)   r   “  s    z.getPhases.<locals>.InCaptionPhase.endTagIgnorec                 S   s   | j jd  |¡S r  ©rO   rL   r�   r«   r(   r(   r)   r  –  s    z-getPhases.<locals>.InCaptionPhase.endTagOtherrÅ   ©	r¿   r
  rÀ   r¼   r¹   r¾   rº   r½   r»   r¿   rÁ   )
rÃ   r
  rÀ   rÅ   r¼   r¹   r¾   rº   r½   r»   N)r<   r=   r>   r  rö   r-  r”   r�   r4  r  r5  r  r   r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInCaptionPhaseb  s2   ÿþÿýr8  c                       sŒ   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Ze d” jfdefg¡Ze	e_e de
fdefg¡Zee_dS )z%getPhases.<locals>.InColumnGroupPhasec                 S   s   | j jd jdkS )Nr~   rÅ   )rA   r‡   rC   rE   r(   r(   r)   ÚignoreEndTagColgroup¬  s    z:getPhases.<locals>.InColumnGroupPhase.ignoreEndTagColgroupc                 S   sD   | j jd jdkr"| jjsJ ‚d S |  ¡ }|  tdƒ¡ |s@dS d S )Nr~   rÅ   rÀ   T)rA   r‡   rC   rO   rW   r9  ÚendTagColgroupr  )rF   r3  r(   r(   r)   r”   ¯  s    z0getPhases.<locals>.InColumnGroupPhase.processEOFc                 S   s"   |   ¡ }|  tdƒ¡ |s|S d S ©NrÀ   ©r9  r:  r  r2  r(   r(   r)   r�   ¹  s    z7getPhases.<locals>.InColumnGroupPhase.processCharactersc                 S   s$   | j  |¡ | j j ¡  d|d< d S r  r  r«   r(   r(   r)   r  ¿  s    z1getPhases.<locals>.InColumnGroupPhase.startTagColc                 S   s"   |   ¡ }|  tdƒ¡ |s|S d S r;  r<  r2  r(   r(   r)   r  Ä  s    z3getPhases.<locals>.InColumnGroupPhase.startTagOtherc                 S   s@   |   ¡ r | jjsJ ‚| j ¡  n| jj ¡  | jjd | j_d S ©Nr´   )	r9  rO   rW   rˆ   rA   r‡   rí   rL   rd   r«   r(   r(   r)   r:  Ê  s
    z4getPhases.<locals>.InColumnGroupPhase.endTagColgroupc                 S   s   | j  dddi¡ d S )Nz
no-end-tagrC   r
  rç   r«   r(   r(   r)   Ú	endTagColÓ  s    z/getPhases.<locals>.InColumnGroupPhase.endTagColc                 S   s"   |   ¡ }|  tdƒ¡ |s|S d S r;  r<  r2  r(   r(   r)   r  Ö  s    z1getPhases.<locals>.InColumnGroupPhase.endTagOtherrÅ   r
  rÀ   N)r<   r=   r>   r  rö   r9  r”   r�   r  r  r:  r>  r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInColumnGroupPhase¨  s&   
	þþr?  c                       s¾   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze d” jfde	fde
fdefg¡Zee_e defdefdefg¡Zee_d S )!z#getPhases.<locals>.InTableBodyPhasec                 S   sB   | j jd jdvr | j j ¡  q | j jd jdkr>| jjs>J ‚d S )Nr~   )r¼   r¾   r½   rÅ   rÅ   )rA   r‡   rC   rí   rO   rW   rE   r(   r(   r)   ÚclearStackToTableBodyContextí  s    z@getPhases.<locals>.InTableBodyPhase.clearStackToTableBodyContextc                 S   s   | j jd  ¡  d S r=  r.  rE   r(   r(   r)   r”   ÷  s    z.getPhases.<locals>.InTableBodyPhase.processEOFc                 S   s   | j jd  |¡S r=  r?  r«   r(   r(   r)   rŽ   ú  s    z:getPhases.<locals>.InTableBodyPhase.processSpaceCharactersc                 S   s   | j jd  |¡S r=  r/  r«   r(   r(   r)   r�   ý  s    z5getPhases.<locals>.InTableBodyPhase.processCharactersc                 S   s(   |   ¡  | j |¡ | jjd | j_d S )Nr°   )r@  rA   rÎ   rO   rL   rd   r«   r(   r(   r)   Ú
startTagTr   s    z.getPhases.<locals>.InTableBodyPhase.startTagTrc                 S   s*   | j  dd|d i¡ |  tddƒ¡ |S )Nzunexpected-cell-in-table-bodyrC   r»   ry   )rO   rˆ   rA  r  r«   r(   r(   r)   ÚstartTagTableCell  s
    
ÿz5getPhases.<locals>.InTableBodyPhase.startTagTableCellc                 S   sn   | j jddd�s0| j jddd�s0| j jddd�rT|  ¡  |  t| j jd jƒ¡ |S | jjs`J ‚| j 	¡  d S ©Nr¼   rÁ   rm  r½   r¾   r~   ©
rA   ro  r@  ÚendTagTableRowGroupr  r‡   rC   rO   rW   rˆ   r«   r(   r(   r)   ÚstartTagTableOther  s    ÿþÿz6getPhases.<locals>.InTableBodyPhase.startTagTableOtherc                 S   s   | j jd  |¡S r=  r  r«   r(   r(   r)   r    s    z1getPhases.<locals>.InTableBodyPhase.startTagOtherc                 S   sT   | j j|d dd�r:|  ¡  | j j ¡  | jjd | j_n| j dd|d i¡ d S )NrC   rÁ   rm  r´   ú unexpected-end-tag-in-table-body)	rA   ro  r@  r‡   rí   rO   rL   rd   rˆ   r«   r(   r(   r)   rE    s    
ÿz7getPhases.<locals>.InTableBodyPhase.endTagTableRowGroupc                 S   sn   | j jddd�s0| j jddd�s0| j jddd�rT|  ¡  |  t| j jd jƒ¡ |S | jjs`J ‚| j 	¡  d S rC  rD  r«   r(   r(   r)   r  %  s    ÿþÿz/getPhases.<locals>.InTableBodyPhase.endTagTablec                 S   s   | j  dd|d i¡ d S )NrG  rC   rç   r«   r(   r(   r)   r   2  s    
ÿz0getPhases.<locals>.InTableBodyPhase.endTagIgnorec                 S   s   | j jd  |¡S r=  r6  r«   r(   r(   r)   r  6  s    z/getPhases.<locals>.InTableBodyPhase.endTagOtherrÅ   r»   ©r¹   rº   )r¿   r
  rÀ   r¼   r¾   r½   r!  rÁ   )rÃ   r¿   r
  rÀ   rÅ   r¹   rº   r»   N)r<   r=   r>   r  rö   r@  r”   rŽ   r�   rA  rB  rF  r  rE  r  r   r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInTableBodyPhaseè  s<   
	ÿüÿýrI  c                       sÆ   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze d” jfde
fdefg¡Zee_e defdefd efd!efg¡Zee_d"S )#zgetPhases.<locals>.InRowPhasec                 S   s@   | j jd jdvr<| j dd| j jd ji¡ | j j ¡  q d S )Nr~   )r»   rÅ   z'unexpected-implied-end-tag-in-table-rowrC   )rA   r‡   rC   rO   rˆ   rí   rE   r(   r(   r)   ÚclearStackToTableRowContextO  s
    ÿz9getPhases.<locals>.InRowPhase.clearStackToTableRowContextc                 S   s   | j jddd� S )Nr»   rÁ   rm  r,  rE   r(   r(   r)   ÚignoreEndTagTrU  s    z,getPhases.<locals>.InRowPhase.ignoreEndTagTrc                 S   s   | j jd  ¡  d S r=  r.  rE   r(   r(   r)   r”   Y  s    z(getPhases.<locals>.InRowPhase.processEOFc                 S   s   | j jd  |¡S r=  r?  r«   r(   r(   r)   rŽ   \  s    z4getPhases.<locals>.InRowPhase.processSpaceCharactersc                 S   s   | j jd  |¡S r=  r/  r«   r(   r(   r)   r�   _  s    z/getPhases.<locals>.InRowPhase.processCharactersc                 S   s6   |   ¡  | j |¡ | jjd | j_| jj t¡ d S )Nr¯   )	rJ  rA   rÎ   rO   rL   rd   rT  r“   r   r«   r(   r(   r)   rB  b  s    z/getPhases.<locals>.InRowPhase.startTagTableCellc                 S   s"   |   ¡ }|  tdƒ¡ |s|S d S ©Nr»   ©rK  ÚendTagTrr  r2  r(   r(   r)   rF  h  s    z0getPhases.<locals>.InRowPhase.startTagTableOtherc                 S   s   | j jd  |¡S r=  r  r«   r(   r(   r)   r  o  s    z+getPhases.<locals>.InRowPhase.startTagOtherc                 S   sH   |   ¡ s.|  ¡  | jj ¡  | jjd | j_n| jjs:J ‚| j 	¡  d S r  )
rK  rJ  rA   r‡   rí   rO   rL   rd   rW   rˆ   r«   r(   r(   r)   rN  r  s    z&getPhases.<locals>.InRowPhase.endTagTrc                 S   s"   |   ¡ }|  tdƒ¡ |s|S d S rL  rM  r2  r(   r(   r)   r  |  s    z)getPhases.<locals>.InRowPhase.endTagTablec                 S   s4   | j j|d dd�r&|  tdƒ¡ |S | j ¡  d S )NrC   rÁ   rm  r»   )rA   ro  rN  r  rO   rˆ   r«   r(   r(   r)   rE  „  s    z1getPhases.<locals>.InRowPhase.endTagTableRowGroupc                 S   s   | j  dd|d i¡ d S )Nzunexpected-end-tag-in-table-rowrC   rç   r«   r(   r(   r)   r   ‹  s    
ÿz*getPhases.<locals>.InRowPhase.endTagIgnorec                 S   s   | j jd  |¡S r=  r6  r«   r(   r(   r)   r  �  s    z)getPhases.<locals>.InRowPhase.endTagOtherrÅ   rH  )r¿   r
  rÀ   r¼   r¾   r½   r»   r»   rÁ   r!  )rÃ   r¿   r
  rÀ   rÅ   r¹   rº   N)r<   r=   r>   r  rö   rJ  rK  r”   rŽ   r�   rB  rF  r  rN  r  rE  r   r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   Ú
InRowPhaseJ  s>   
ÿýÿürO  c                       sš   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Ze d” jfdefg¡Ze	e_e de
fdefdefg¡Zee_dS )zgetPhases.<locals>.InCellPhasec                 S   sB   | j jddd�r |  tdƒ¡ n| j jddd�r>|  tdƒ¡ d S ©Nr¹   rÁ   rm  rº   )rA   ro  ÚendTagTableCellr  rE   r(   r(   r)   Ú	closeCell¨  s    z(getPhases.<locals>.InCellPhase.closeCellc                 S   s   | j jd  ¡  d S r  r.  rE   r(   r(   r)   r”   ¯  s    z)getPhases.<locals>.InCellPhase.processEOFc                 S   s   | j jd  |¡S r  r/  r«   r(   r(   r)   r�   ²  s    z0getPhases.<locals>.InCellPhase.processCharactersc                 S   sF   | j jddd�s | j jddd�r,|  ¡  |S | jjs8J ‚| j ¡  d S rP  )rA   ro  rR  rO   rW   rˆ   r«   r(   r(   r)   rF  µ  s    ÿz1getPhases.<locals>.InCellPhase.startTagTableOtherc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   r  ¿  s    z,getPhases.<locals>.InCellPhase.startTagOtherc                 S   s²   | j j|d dd�r˜| j  |d ¡ | j jd j|d krp| j dd|d i¡ | j j ¡ }|j|d krPq|qPn| j j ¡  | j  ¡  | jj	d | j_
n| j dd|d i¡ d S )NrC   rÁ   rm  r~   zunexpected-cell-end-tagr°   r2  )rA   ro  r®  r‡   rC   rO   rˆ   rí   rÚ  rL   rd   r.  r(   r(   r)   rQ  Â  s    
ÿ
z.getPhases.<locals>.InCellPhase.endTagTableCellc                 S   s   | j  dd|d i¡ d S r1  rç   r«   r(   r(   r)   r   Ó  s    z+getPhases.<locals>.InCellPhase.endTagIgnorec                 S   s.   | j j|d dd�r |  ¡  |S | j ¡  d S )NrC   rÁ   rm  )rA   ro  rR  rO   rˆ   r«   r(   r(   r)   ÚendTagImplyÖ  s    z*getPhases.<locals>.InCellPhase.endTagImplyc                 S   s   | j jd  |¡S r  r6  r«   r(   r(   r)   r  Þ  s    z*getPhases.<locals>.InCellPhase.endTagOtherrÅ   r7  rH  )rÃ   r¿   r
  rÀ   rÅ   rÉ  N)r<   r=   r>   r  rö   rR  r”   r�   rF  r  rQ  r   rS  r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInCellPhase£  s.   
ÿþýrT  c                	       sÊ   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze d” jfdefdefde	fde
fdefg¡Zee_e defdefdefg¡Zee_dS ) z getPhases.<locals>.InSelectPhasec                 S   s0   | j jd jdkr | j d¡ n| jjs,J ‚d S )Nr~   rÅ   zeof-in-selectr  rE   r(   r(   r)   r”   ó  s    z+getPhases.<locals>.InSelectPhase.processEOFc                 S   s$   |d dkrd S | j  |d ¡ d S r*  ré   r«   r(   r(   r)   r�   ù  s    z2getPhases.<locals>.InSelectPhase.processCharactersc                 S   s.   | j jd jdkr| j j ¡  | j  |¡ d S r¨  ©rA   r‡   rC   rí   rÎ   r«   r(   r(   r)   ÚstartTagOptionþ  s    z/getPhases.<locals>.InSelectPhase.startTagOptionc                 S   sL   | j jd jdkr| j j ¡  | j jd jdkr<| j j ¡  | j  |¡ d S )Nr~   r©  r´  rU  r«   r(   r(   r)   ÚstartTagOptgroup	  s
    z1getPhases.<locals>.InSelectPhase.startTagOptgroupc                 S   s   | j  d¡ |  tdƒ¡ d S )Nzunexpected-select-in-selectr¸   )rO   rˆ   ÚendTagSelectr  r«   r(   r(   r)   r¬  	  s    z/getPhases.<locals>.InSelectPhase.startTagSelectc                 S   s>   | j  d¡ | jjddd�r.|  tdƒ¡ |S | j js:J ‚d S )Nzunexpected-input-in-selectr¸   rm  )rO   rˆ   rA   ro  rX  r  rW   r«   r(   r(   r)   r‘  	  s
    z.getPhases.<locals>.InSelectPhase.startTagInputc                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   r+  	  s    z/getPhases.<locals>.InSelectPhase.startTagScriptc                 S   s   | j  dd|d i¡ d S )Nzunexpected-start-tag-in-selectrC   rç   r«   r(   r(   r)   r  	  s    
ÿz.getPhases.<locals>.InSelectPhase.startTagOtherc                 S   s6   | j jd jdkr | j j ¡  n| j dddi¡ d S )Nr~   r©  úunexpected-end-tag-in-selectrC   ©rA   r‡   rC   rí   rO   rˆ   r«   r(   r(   r)   ÚendTagOption	  s
    ÿz-getPhases.<locals>.InSelectPhase.endTagOptionc                 S   sf   | j jd jdkr0| j jd jdkr0| j j ¡  | j jd jdkrP| j j ¡  n| j dddi¡ d S )Nr~   r©  éþÿÿÿr´  rY  rC   rZ  r«   r(   r(   r)   ÚendTagOptgroup%	  s    ÿÿz/getPhases.<locals>.InSelectPhase.endTagOptgroupc                 S   sZ   | j jddd�r@| j j ¡ }|jdkr4| j j ¡ }q| j ¡  n| jjsLJ ‚| j ¡  d S )Nr¸   rm  )	rA   ro  r‡   rí   rC   rO   rf   rW   rˆ   r.  r(   r(   r)   rX  2	  s    
z-getPhases.<locals>.InSelectPhase.endTagSelectc                 S   s   | j  dd|d i¡ d S )NrY  rC   rç   r«   r(   r(   r)   r  =	  s    
ÿz,getPhases.<locals>.InSelectPhase.endTagOtherrÅ   r©  r´  r¸   )r¡  r  r^  r7  N)r<   r=   r>   r  rö   r”   r�   rV  rW  r¬  r‘  r+  r  r[  r]  rX  r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInSelectPhaseï  s8   úýr^  c                   @   sn   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
e defg¡Zee_e de	fg¡Ze
e_dS )z'getPhases.<locals>.InSelectInTablePhasec                 S   s   | j jd  ¡  d S ©Nr®   r.  rE   r(   r(   r)   r”   U	  s    z2getPhases.<locals>.InSelectInTablePhase.processEOFc                 S   s   | j jd  |¡S r_  r/  r«   r(   r(   r)   r�   X	  s    z9getPhases.<locals>.InSelectInTablePhase.processCharactersc                 S   s(   | j  dd|d i¡ |  tdƒ¡ |S )Nz5unexpected-table-element-start-tag-in-select-in-tablerC   r¸   )rO   rˆ   r  r  r«   r(   r(   r)   rŽ  [	  s    z5getPhases.<locals>.InSelectInTablePhase.startTagTablec                 S   s   | j jd  |¡S r_  r  r«   r(   r(   r)   r  `	  s    z5getPhases.<locals>.InSelectInTablePhase.startTagOtherc                 S   s@   | j  dd|d i¡ | jj|d dd�r<|  tdƒ¡ |S d S )Nz3unexpected-table-element-end-tag-in-select-in-tablerC   rÁ   rm  r¸   )rO   rˆ   rA   ro  r  r  r«   r(   r(   r)   r  c	  s    z3getPhases.<locals>.InSelectInTablePhase.endTagTablec                 S   s   | j jd  |¡S r_  r6  r«   r(   r(   r)   r  i	  s    z3getPhases.<locals>.InSelectInTablePhase.endTagOther)r¿   rÁ   r¼   r¾   r½   r»   r¹   rº   N)r<   r=   r>   r  rö   r”   r�   rŽ  r  r  r  r   r  rì   r  rõ   r(   r(   r(   r)   ÚInSelectInTablePhaseR	  s&   ÿÿÿÿr`  c                       sB   e Zd Zeƒ Zeg d¢ƒZdd„ Z‡ fdd„Zdd„ Z	dd	„ Z
d
S )z(getPhases.<locals>.InForeignContentPhase),rð  rñ  rÞ  rÃ   r	  rß  rò  rW  r*   râ  rX  ró  r  Úh1Úh2Úh3Úh4Úh5Úh6rÂ   r�  rõ  r•  rY  r]  rê  r4   rˆ  rì  r'   r\  r­  rö  r÷  Úspanrù  rø  ÚsubÚsuprÁ   rú  rû  rï  Úvarc              %   S   sn   ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%œ$}|d& |v rj||d&  |d&< d S )'NÚaltGlyphÚaltGlyphDefÚaltGlyphItemÚanimateColorÚanimateMotionÚanimateTransformÚclipPathÚfeBlendÚfeColorMatrixÚfeComponentTransferÚfeCompositeÚfeConvolveMatrixÚfeDiffuseLightingÚfeDisplacementMapÚfeDistantLightÚfeFloodÚfeFuncAÚfeFuncBÚfeFuncGÚfeFuncRÚfeGaussianBlurÚfeImageÚfeMergeÚfeMergeNodeÚfeMorphologyÚfeOffsetÚfePointLightÚfeSpecularLightingÚfeSpotLightÚfeTileÚfeTurbulenceÚforeignObjectÚglyphRefÚlinearGradientÚradialGradientÚtextPath)$ÚaltglyphÚaltglyphdefÚaltglyphitemÚanimatecolorÚanimatemotionÚanimatetransformÚclippathÚfeblendÚfecolormatrixÚfecomponenttransferÚfecompositeÚfeconvolvematrixÚfediffuselightingÚfedisplacementmapÚfedistantlightÚfefloodÚfefuncaÚfefuncbÚfefuncgÚfefuncrÚfegaussianblurÚfeimageÚfemergeÚfemergenodeÚfemorphologyÚfeoffsetÚfepointlightÚfespecularlightingÚfespotlightÚfetileÚfeturbulenceÚforeignobjectÚglyphrefÚlineargradientÚradialgradientÚtextpathrC   r(   )rF   rœ   Úreplacementsr(   r(   r)   ÚadjustSVGTagNames„	  sN    Ý%z:getPhases.<locals>.InForeignContentPhase.adjustSVGTagNamesc                    sL   |d dkrd|d< n&| j jr<tdd„ |d D ƒƒr<d| j _ˆ  | |¡ d S )Nr   rb  u   ï¿½c                 s   s   | ]}|t vV  qd S r-   rc  rd  r(   r(   r)   Ú	<genexpr>±	  rH   zMgetPhases.<locals>.InForeignContentPhase.processCharacters.<locals>.<genexpr>F)rO   ri   rg  r�   r«   r"  r(   r)   r�   ­	  s    
ÿz:getPhases.<locals>.InForeignContentPhase.processCharactersc                 S   s(  | j jd }|d | jv s>|d dkr¤t|d  ¡ ƒh d£@ r¤| j dd|d i¡ | j jd j| j jkr | j 	| j jd ¡s | j 
| j jd ¡s | j j ¡  qT|S |jtd krÀ| j |¡ n$|jtd krä|  |¡ | j |¡ | j |¡ |j|d	< | j  |¡ |d
 �r$| j j ¡  d|d< d S )Nr~   rC   rô  r   >   ÚsizeÚcolorÚfacez*unexpected-html-element-in-foreign-contentrn   rƒ   rp   r…   Tr†   )rA   r‡   ÚbreakoutElementsÚsetÚkeysrO   rˆ   rp   r‹   ru   rv   rí   r   r   r´  r   r   rÎ   )rF   rœ   rŸ   r(   r(   r)   r�   µ	  s:    
ÿþ
ÿÿþý


z8getPhases.<locals>.InForeignContentPhase.processStartTagc                 S   sè   t | jjƒd }| jjd }|j t¡|d krF| j dd|d i¡ |j t¡|d kr¬| jj| jj	d krˆ| jj 
¡  | jjj| j_| jj ¡ |kr¦| jjsˆJ ‚qˆd }qä|d8 }| jj| }|j| jjkrÒqFqF| jj |¡}qäqF|S )Nr   r~   rC   r2  r  )rŠ   rA   r‡   rC   rr   r   rO   rˆ   rd   rL   r(  rÏ   rí   rp   r‹   r�   )rF   rœ   Ú	nodeIndexrÈ   rž   r(   r(   r)   r�   Ð	  s&    z6getPhases.<locals>.InForeignContentPhase.processEndTagN)r<   r=   r>   r  rö   rŒ   r¹  r´  r�   r�   r�   r(   r"  r(   r)   ÚInForeignContentPhasex	  s   	)r½  c                   @   sv   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Ze defg¡Ze	e_e de
fg¡Zee_dS )z!getPhases.<locals>.AfterBodyPhasec                 S   s   d S r-   r(   rE   r(   r(   r)   r”   í	  s    z,getPhases.<locals>.AfterBodyPhase.processEOFc                 S   s   | j  || j jd ¡ d S )Nr   rå   r«   r(   r(   r)   r‘   ñ	  s    z0getPhases.<locals>.AfterBodyPhase.processCommentc                 S   s    | j  d¡ | j jd | j _|S )Nzunexpected-char-after-bodyrµ   ©rO   rˆ   rL   rd   r«   r(   r(   r)   r�   ö	  s    z3getPhases.<locals>.AfterBodyPhase.processCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   û	  s    z.getPhases.<locals>.AfterBodyPhase.startTagHtmlc                 S   s*   | j  dd|d i¡ | j jd | j _|S )Nzunexpected-start-tag-after-bodyrC   rµ   r¾  r«   r(   r(   r)   r  þ	  s
    
ÿz/getPhases.<locals>.AfterBodyPhase.startTagOtherc                 S   s*   | j jr| j  d¡ n| j jd | j _d S )Nz'unexpected-end-tag-after-body-innerhtmlÚafterAfterBody)rO   rW   rˆ   rL   rd   )rF   rC   r(   r(   r)   r½  
  s    z,getPhases.<locals>.AfterBodyPhase.endTagHtmlc                 S   s*   | j  dd|d i¡ | j jd | j _|S )Nzunexpected-end-tag-after-bodyrC   rµ   r¾  r«   r(   r(   r)   r  

  s
    
ÿz-getPhases.<locals>.AfterBodyPhase.endTagOtherrÅ   N)r<   r=   r>   r  rö   r”   r‘   r�   rô   r  r½  r  r   r  rì   r  rõ   r(   r(   r(   r)   ÚAfterBodyPhaseê	  s   ÿrÀ  c                       s’   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Ze d” jfdefdefde	fg¡Ze
e_e defg¡Zee_dS )z"getPhases.<locals>.InFramesetPhasec                 S   s0   | j jd jdkr | j d¡ n| jjs,J ‚d S )Nr~   rÅ   zeof-in-framesetr  rE   r(   r(   r)   r”   
  s    z-getPhases.<locals>.InFramesetPhase.processEOFc                 S   s   | j  d¡ d S )Nzunexpected-char-in-framesetrç   r«   r(   r(   r)   r�   "
  s    z4getPhases.<locals>.InFramesetPhase.processCharactersc                 S   s   | j  |¡ d S r-   )rA   rÎ   r«   r(   r(   r)   rH  %
  s    z3getPhases.<locals>.InFramesetPhase.startTagFramesetc                 S   s   | j  |¡ | j j ¡  d S r-   r  r«   r(   r(   r)   ÚstartTagFrame(
  s    z0getPhases.<locals>.InFramesetPhase.startTagFramec                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   ÚstartTagNoframes,
  s    z3getPhases.<locals>.InFramesetPhase.startTagNoframesc                 S   s   | j  dd|d i¡ d S )Nz unexpected-start-tag-in-framesetrC   rç   r«   r(   r(   r)   r  /
  s    
ÿz0getPhases.<locals>.InFramesetPhase.startTagOtherc                 S   sZ   | j jd jdkr | j d¡ n| j j ¡  | jjsV| j jd jdkrV| jjd | j_d S )Nr~   rÅ   z)unexpected-frameset-in-frameset-innerhtmlrÄ   ÚafterFrameset)	rA   r‡   rC   rO   rˆ   rí   rW   rL   rd   r«   r(   r(   r)   ÚendTagFrameset3
  s    ÿz1getPhases.<locals>.InFramesetPhase.endTagFramesetc                 S   s   | j  dd|d i¡ d S )Nzunexpected-end-tag-in-framesetrC   rç   r«   r(   r(   r)   r  ?
  s    
ÿz.getPhases.<locals>.InFramesetPhase.endTagOtherrÅ   rÄ   r  r4  N)r<   r=   r>   r  rö   r”   r�   rH  rÁ  rÂ  r  rÄ  r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚInFramesetPhase
  s(   üÿrÅ  c                       sv   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
e d” jfdefg¡Zee_e de	fg¡Ze
e_dS )z%getPhases.<locals>.AfterFramesetPhasec                 S   s   d S r-   r(   rE   r(   r(   r)   r”   T
  s    z0getPhases.<locals>.AfterFramesetPhase.processEOFc                 S   s   | j  d¡ d S )Nzunexpected-char-after-framesetrç   r«   r(   r(   r)   r�   X
  s    z7getPhases.<locals>.AfterFramesetPhase.processCharactersc                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   rÂ  [
  s    z6getPhases.<locals>.AfterFramesetPhase.startTagNoframesc                 S   s   | j  dd|d i¡ d S )Nz#unexpected-start-tag-after-framesetrC   rç   r«   r(   r(   r)   r  ^
  s    
ÿz3getPhases.<locals>.AfterFramesetPhase.startTagOtherc                 S   s   | j jd | j _d S )NÚafterAfterFrameset)rO   rL   rd   r«   r(   r(   r)   r½  b
  s    z0getPhases.<locals>.AfterFramesetPhase.endTagHtmlc                 S   s   | j  dd|d i¡ d S )Nz!unexpected-end-tag-after-framesetrC   rç   r«   r(   r(   r)   r  e
  s    
ÿz1getPhases.<locals>.AfterFramesetPhase.endTagOtherrÅ   r4  N)r<   r=   r>   r  rö   r”   r�   rÂ  r  r½  r  r   r  rô   rì   r  rõ   r(   r"  r(   r)   ÚAfterFramesetPhaseP
  s    þÿrÇ  c                   @   s`   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Ze de	fg¡Ze
e_dS )z&getPhases.<locals>.AfterAfterBodyPhasec                 S   s   d S r-   r(   rE   r(   r(   r)   r”   w
  s    z1getPhases.<locals>.AfterAfterBodyPhase.processEOFc                 S   s   | j  || j j¡ d S r-   rø   r«   r(   r(   r)   r‘   z
  s    z5getPhases.<locals>.AfterAfterBodyPhase.processCommentc                 S   s   | j jd  |¡S r  r?  r«   r(   r(   r)   rŽ   }
  s    z=getPhases.<locals>.AfterAfterBodyPhase.processSpaceCharactersc                 S   s    | j  d¡ | j jd | j _|S )Núexpected-eof-but-got-charrµ   r¾  r«   r(   r(   r)   r�   €
  s    z8getPhases.<locals>.AfterAfterBodyPhase.processCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   …
  s    z3getPhases.<locals>.AfterAfterBodyPhase.startTagHtmlc                 S   s*   | j  dd|d i¡ | j jd | j _|S )Núexpected-eof-but-got-start-tagrC   rµ   r¾  r«   r(   r(   r)   r  ˆ
  s
    
ÿz4getPhases.<locals>.AfterAfterBodyPhase.startTagOtherc                 S   s*   | j  dd|d i¡ | j jd | j _|S )Núexpected-eof-but-got-end-tagrC   rµ   r¾  r«   r(   r(   r)   r�   Ž
  s
    
ÿz4getPhases.<locals>.AfterAfterBodyPhase.processEndTagrÅ   N)r<   r=   r>   r  rö   r”   r‘   rŽ   r�   rô   r  r�   r   r  rì   r  r(   r(   r(   r)   ÚAfterAfterBodyPhaset
  s   ÿrË  c                   @   sn   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Ze de	fde
fg¡Zee_dS )z*getPhases.<locals>.AfterAfterFramesetPhasec                 S   s   d S r-   r(   rE   r(   r(   r)   r”   œ
  s    z5getPhases.<locals>.AfterAfterFramesetPhase.processEOFc                 S   s   | j  || j j¡ d S r-   rø   r«   r(   r(   r)   r‘   Ÿ
  s    z9getPhases.<locals>.AfterAfterFramesetPhase.processCommentc                 S   s   | j jd  |¡S r  r?  r«   r(   r(   r)   rŽ   ¢
  s    zAgetPhases.<locals>.AfterAfterFramesetPhase.processSpaceCharactersc                 S   s   | j  d¡ d S )NrÈ  rç   r«   r(   r(   r)   r�   ¥
  s    z<getPhases.<locals>.AfterAfterFramesetPhase.processCharactersc                 S   s   | j jd  |¡S r  r  r«   r(   r(   r)   rô   ¨
  s    z7getPhases.<locals>.AfterAfterFramesetPhase.startTagHtmlc                 S   s   | j jd  |¡S r>  r  r«   r(   r(   r)   ÚstartTagNoFrames«
  s    z;getPhases.<locals>.AfterAfterFramesetPhase.startTagNoFramesc                 S   s   | j  dd|d i¡ d S )NrÉ  rC   rç   r«   r(   r(   r)   r  ®
  s    
ÿz8getPhases.<locals>.AfterAfterFramesetPhase.startTagOtherc                 S   s   | j  dd|d i¡ d S )NrÊ  rC   rç   r«   r(   r(   r)   r�   ²
  s    
ÿz8getPhases.<locals>.AfterAfterFramesetPhase.processEndTagrÅ   r4  N)r<   r=   r>   r  rö   r”   r‘   rŽ   r�   rô   rÌ  r  r�   r   r  rì   r  r(   r(   r(   r)   ÚAfterAfterFramesetPhase™
  s   þrÍ  )r[   rZ   r·   r  r(  r,  rµ   rÍ   r´   r  r²   r³   r±   r°   r¯   r®   r«  r„   r»  r¶   rÃ  r¿  rÆ  )r   )rM   r]   rß   r  r
  r  r=  rF  rK  r  r#  r8  r?  rI  rO  rT  r^  r`  r½  rÀ  rÅ  rÇ  rË  rÍ  r(   )rO  r%  r÷   r)   rK   Œ  sr    H %-f?B     Y! /F@bYLc&r.8$%&érK   c                    sF   t | d ƒt ˆ ƒ@ }|rBt| d ƒ‡ fdd„| d  ¡ D ƒƒ| d< d S )Nr   c                 3   s"   | ]\}}ˆ   ||¡|fV  qd S r-   )r‰   )rB   ÚkÚv©r³  r(   r)   rµ  Ý
  s   ÿz$adjust_attributes.<locals>.<genexpr>)r   r2   r.   )rœ   r³  Úneeds_adjustmentr(   rÐ  r)   rª   Ú
  s
    
ÿrª   rz   Fc                 C   s   |d u ri }t | | ||dœS )N)r2   rC   r   r…   )r   )rC   r2   rq   r…   r(   r(   r)   r  á
  s
    
ÿr  c                   @   s   e Zd ZdZdS )r}   zError in parsed documentN)r<   r=   r>   rÒ   r(   r(   r(   r)   r}   é
  s   r}   )r   T)r*   r   T)rz   NF),Ú
__future__r   r   r   Úpip._vendor.sixr   r   r0   rý   r   r	   r
   Ztreebuilders.baser   r   Ú	constantsr   r   r   r   r   r   r   r   r   r   r   r   r¬   r   r   r   r   r"   r,   r@   rþ  r!   ÚmemoizerK   rª   r  Ú	Exceptionr}   r(   r(   r(   r)   Ú<module>   sN   H

  8
                  _  ÿ
