
    7bhٶ                     d   	 d dl Zd dlZd dlZd dlmZ d dlmZ  G d dej                  j                        Z
 G d de
      Z G d d	e
      Z G d
 de
      Z G d dej                        Z G d de      Z G d de      Z G d dej                        Zedk(  r ej(                          yy)    N)patch)supportc                   Z    e Zd ZdddZd Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zy)EventCollectorF	autocdatac                    || _         g | _        | j                  j                  | _        t        j                  j
                  j                  | g|i | |r| j                  d       y y )NF)r   eventsappendhtmlparser
HTMLParser__init___set_support_cdata)selfr   argskws       >/opt/python-3.12.12/usr/lib/python3.12/test/test_htmlparser.pyr   zEventCollector.__init__   sY    "kk(('':t:r:##E*     c                     g }d }| j                   D ]<  }|d   }||cxk(  rdk(  rn nd|d   d   |d   z   f|d<   n|j                  |       |}> || _         |S )Nr   data   )r
   r   )r   Lprevtypeeventtypes        r   
get_eventszEventCollector.get_events   so     [[E8Dx)6)2qE!H!45"H ! r   c                 t    | j                  d||f       | j                  r|dk(  r| j                  d       y y y )NstarttagsvgTr   r   r   r   tagattrss      r   handle_starttagzEventCollector.handle_starttag&   s7    Ze,->>cUl##D) +>r   c                 ,    | j                  d||f       y )Nstartendtagr   r#   s      r   handle_startendtagz!EventCollector.handle_startendtag+   s    ]C/0r   c                 r    | j                  d|f       | j                  r|dk(  r| j                  d       y y y )Nendtagr!   Fr"   )r   r$   s     r   handle_endtagzEventCollector.handle_endtag.   s4    XsO$>>cUl##E* +>r   c                 *    | j                  d|f       y )Ncommentr)   r   r   s     r   handle_commentzEventCollector.handle_comment5       Y%&r   c                 *    | j                  d|f       y )Ncharrefr)   r0   s     r   handle_charrefzEventCollector.handle_charref8   r2   r   c                 *    | j                  d|f       y )Nr   r)   r0   s     r   handle_datazEventCollector.handle_data;       VTN#r   c                 *    | j                  d|f       y )Ndeclr)   r0   s     r   handle_declzEventCollector.handle_decl>   r8   r   c                 *    | j                  d|f       y )N	entityrefr)   r0   s     r   handle_entityrefzEventCollector.handle_entityrefA   s    [$'(r   c                 *    | j                  d|f       y )Npir)   r0   s     r   	handle_pizEventCollector.handle_piD   s    T4L!r   c                 *    | j                  d|f       y )Nunknown declr)   )r   r:   s     r   unknown_declzEventCollector.unknown_declG   s    ^T*+r   N)__name__
__module____qualname__r   r   r&   r*   r-   r1   r5   r7   r;   r>   rA   rD    r   r   r   r      sA    (- +"*
1+''$$)",r   r   c                       e Zd Zd Zy)EventCollectorExtrac                 t    t         j                  | ||       | j                  d| j                         f       y )Nstarttag_text)r   r&   r   get_starttag_textr#   s      r   r&   z#EventCollectorExtra.handle_starttagM   s.    &&tS%8_d&<&<&>?@r   N)rE   rF   rG   r&   rH   r   r   rJ   rJ   K   s    Ar   rJ   c                       e Zd Zd Zd Zy)EventCollectorCharrefsc                 &    | j                  d       y Nz6This should never be called with convert_charrefs=Truefailr0   s     r   r5   z%EventCollectorCharrefs.handle_charrefT       		JKr   c                 &    | j                  d       y rQ   rR   r0   s     r   r>   z'EventCollectorCharrefs.handle_entityrefW   rT   r   N)rE   rF   rG   r5   r>   rH   r   r   rO   rO   R   s    LLr   rO   c                       e Zd Zd Zy)EventCollectorNoNormalizec                     | j                   S N)r
   r   s    r   r   z$EventCollectorNoNormalize.get_events^   s    {{r   N)rE   rF   rG   r   rH   r   r   rW   rW   ]   s    r   rW   c                        e Zd Zd ZddZd Zy)TestCaseBasec                     t        d      S NFconvert_charrefs)r   rZ   s    r   get_collectorzTestCaseBase.get_collectord   s    u55r   Nc                 F   || j                         }|}|D ]  }|j                  |        |j                          |j                         }||k7  rP| j	                  dt        |      z   dz   t        j                  |      z   dz   t        j                  |      z          y y )Nz6received events did not match expected events
Source:
z
Expected:
z
Received:
)ra   feedcloser   rS   reprpprintpformat)r   sourceexpected_events	collectorr   sr
   s          r   
_run_checkzTestCaseBase._run_checkg   s    **,IAKKN ""$_$II $&*6l3%&(.(GH && )/v(>? @ %r   c                 >    | j                  ||t        d             y r^   )rl   rJ   )r   rh   r
   s      r   _run_check_extrazTestCaseBase._run_check_extrau   s    +UC	Er   rY   )rE   rF   rG   ra   rl   rn   rH   r   r   r\   r\   b   s    6@Er   r\   c                   ~   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 ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d      d        Z ej                   dg d       d!        Z ej                   dg d"      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&d0 Z'd1 Z(d2 Z) ej                   dg d3      d4        Z*d5 Z+d6 Z, ej                   dg d7      d8        Z-d9 Z.d: Z/ ej`                  d;      d<        Z1y=)>HTMLParserTestCasec                 P    | j                  ddg       | j                  ddg       y )Nz<?processing instruction>)r@   zprocessing instructionz<?processing instruction ?>)r@   zprocessing instruction ?rl   rZ   s    r    test_processing_instruction_onlyz3HTMLParserTestCase.test_processing_instruction_only|   s2    3,6 	 	5.8 	r   c                 Z    | j                  ddddddg fddddddd	d
dgfdddddddg       y )Nz
<!DOCTYPE html PUBLIC 'foo'>
<HTML>&entity;&#32;
<!--comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1b-->
<Img sRc='Bar' isMAP>sample
text
&#x201C;
<!--comment2a-- --comment2b-->
</Html>
r   
)r:   zDOCTYPE html PUBLIC 'foo'r    r   )r=   entity)r4   32)r/   z4comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1bimg)srcBar)ismapN)r   zsample
text
)r4   x201C)r/   zcomment2a-- --comment2br,   r   rr   rZ   s    r   test_simple_htmlz#HTMLParserTestCase.test_simple_html   s`      )I9:*#	r   c                 f    | j                  dddg fddg       | j                  dgddg fddg       y )	Nz<p>&#bad;</p>r    p)r   z&#bad;r,   r   z<div>&#bad;</div>divr,   r   rr   rZ   s    r   test_malformatted_charrefz,HTMLParserTestCase.test_malformatted_charref   sN    b!*
 	 	,-#0
 	r   c                 ,    | j                  dddg       y )Nz&entityref foo)r=   r=   )r   z foorr   rZ   s    r   test_unclosed_entityrefz*HTMLParserTestCase.test_unclosed_entityref   s    (&+ 	r   c                 <    | j                  dddg fddg fddg       y )Nz<a><b></a></b>r    abr,   r   r,   r   rr   rZ   s    r   test_bad_nestingz#HTMLParserTestCase.test_bad_nesting   s2     	(b!b!	+ 	r   c                 *    | j                  ddg       y )N#this text & contains & ampersands &)r   r   rr   rZ   s    r   test_bare_ampersandsz'HTMLParserTestCase.test_bare_ampersands   s    =;@ 	r   c                 *    | j                  ddg       y )N.this < text > contains < bare>pointy< brackets)r   r   rr   rZ   s    r   test_bare_pointy_bracketsz,HTMLParserTestCase.test_bare_pointy_brackets   s    HFK 	r   c                 `    | j                  ddddgfg       | j                  ddddgfg       y )N	<a b='<'>r    r   r   <	<a b='>'>r   >rr   rZ   s    r   test_starttag_end_boundaryz-HTMLParserTestCase.test_starttag_end_boundary   s6    :sZL*I)JK:sZL*I)JKr   c                    dddgfg}| j                  dg|       | j                  ddg|       | j                  ddg|       | j                  d	d
g|       | j                  ddg|       | j                  ddg|       dddgfg}| j                  dg|       | j                  ddg|       | j                  ddg|       | j                  d	dg|       | j                  ddg|       | j                  ddg|       dg}| j                  ddg|       | j                  ddg|       | j                  ddg|       | j                  ddg|       | j                  dd g|       | j                  d!d"g|       | j                  d#d$g|       | j                  d%d&g|       | j                  d'd(g|       | j                  d)dg|       | j                  ddg|       y )*Nr    r   r   r   <a zb='<'>z<a bz='<'>z<a b=z'<'>z<a b='<z'>z<a b='<'r   r   r   zb='>'>z='>'>z'>'>z<a b='>z<a b='>')r/   abc z
<!--abc-->r   z	!--abc--><!z--abc--><!-z-abc--><!--zabc-->z<!--azbc-->z<!--abzc-->z<!--abcz-->z<!--abc-z->z	<!--abc--rr   r   outputs     r   test_buffer_artefactsz(HTMLParserTestCase.test_buffer_artefacts   s   sZL12v.)62)62&)62D)62S)62sZL12v.)62)62&)62D)62S)62$%\*F3k*F3z*F3	*F3*F3'*F36*F3E*F3T*F3c*F3r*F3r   c                 P    g d}|D ]  }| j                  d|z  dd|z   fg        y )N)
HTMLzOHTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"z[HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"zbhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"zfhtml PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"zYmath PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"zhtml PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"zWsvg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"z'html PUBLIC "-//IETF//DTD HTML 2.0//EN"z,html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"z<!DOCTYPE %s>r:   DOCTYPE rr   )r   dtdsdtds      r   test_valid_doctypesz&HTMLParserTestCase.test_valid_doctypes   s9    @$ COOOc1$j3&678: r   c                     | j                  dddg fg       | j                  dddg fdg       | j                  dddg fddd	gfdg       y )
Nz<p/>r(   r   z<p></p>r    r   z<p><img src='foo' /></p>ry   )rz   foorr   rZ   s    r   test_startendtagz#HTMLParserTestCase.test_startendtag  sq    C$! 	 		b!$ 	 	2b!EN#345 	r   c                 >    d}| j                  |ddddgfd|fg       y )Nz <foo:bar   
   one="1"	two=2   >r    zfoo:bar)one1)two2rL   )rn   )r   rk   s     r   test_get_starttag_textz)HTMLParserTestCase.test_get_starttag_text  s3    4a\<$@Aa "" 	#r   content)z*<!-- not a comment --> &not-an-entity-ref;<not a='start tag'>z<a href="" /> <p> <span></span>zfoo = "</scr" + "ipt>";zfoo = "</SCRIPT" + ">";zfoo = <
/script> z*<!-- document.write("</scr" + "ipt>"); -->z
//<![CDATA[
document.write('<s'+'cript type="text/javascript" src="http://www.example.org/r='+new Date().getTime()+'"><\/s'+'cript>');
//]]>z 
<!-- //
var foo = 3.14;
// -->
u   <!-- ☃ -->zfoo = "</ script>"zfoo = "</scripture>"zfoo = "</script>"u   foo = "</script >"u   foo = "</ſcript>"u   foo = "</scrıpt>"c                 D    d| d}| j                  |ddg fd|fdg       y )Nz<script>z	</script>r    scriptr   r,   r   rr   r   r   rk   s      r   test_script_contentz&HTMLParserTestCase.test_script_content  s9    , wiy)Z26#W-02 	3r   )
z0a::before { content: "<!-- not a comment -->"; }z-a::before { content: "&not-an-entity-ref;"; }z-a::before { content: "<not a='start tag'>"; }u   a::before { content: "☃"; }z#a::before { content: "< /style>"; }z#a::before { content: "</ style>"; }z#a::before { content: "</styled>"; }z#a::before { content: "</style>"; }u$   a::before { content: "</style >"; }u#   a::before { content: "</ſtyle>"; }c                 D    d| d}| j                  |ddg fd|fdg       y )Nz<style>z</style>r    styler   r,   r   rr   r   s      r   test_style_contentz%HTMLParserTestCase.test_style_content5  s9     gYh'Z"5#W-/1 	2r   )<!-- not a comment -->r   <![CDATA[not a cdata]]><!not a bogus comment></not a bogus comment>   ☃z	< /title>z	</ title>z	</titled>z	</title>u
   </title >u	   </tıtle>c                 D    d| d}| j                  |ddg fd|fdg       y )Nz<title>z</title>r    titler   r,   r   rr   r   r   rh   s      r   test_title_contentz%HTMLParserTestCase.test_title_contentG  s:     7)8,"%W!
 	r   )r   r   r   r   r   r   z< /textarea>z</ textarea>z</textareable>z</textarea>u   </textarea >c                 D    d| d}| j                  |ddg fd|fdg       y )Nz
<textarea>z</textarea>r    textarear   r,   r   rr   r   s      r   test_textarea_contentz(HTMLParserTestCase.test_textarea_content]  s:     gYk2R(W"!
 	r   r,   )r   SCRIPTzscript zscript
zscript/zscript foo=barzscript foo=">"c                 f    d}d| d| d}| j                  |ddg fd|fdgt        d	
             y )Nz<!-- not a comment --> &not-an-entity-ref;
                  <a href="" /> </p><p> <span></span></style>
                  '</script' + '>'<ScrIPt></r   r    r   r   r   Fr_   rj   rl   rW   r   r,   r   rk   s       r   test_script_closing_tagz*HTMLParserTestCase.test_script_closing_tagr  sV    
& wir&+Z26#W-02 #<U"S 	 	Ur   )r   STYLEzstyle zstyle
zstyle/zstyle foo=barzstyle foo=">"c                 f    d}d| d| d}| j                  |ddg fd|fdgt        d	
             y )Nz
            b::before { content: "<!-- not a comment -->"; }
            p::before { content: "&not-an-entity-ref;"; }
            a::before { content: "<i>"; }
            a::after { content: "</i>"; }
            z<StyLE>r   r   r    r   r   r   Fr_   r   r   r   s       r   test_style_closing_tagz)HTMLParserTestCase.test_style_closing_tag  sV     gYb*Z"5#W-/1 #<U"S 	 	Ur   )r   TITLEztitle ztitle
ztitle/ztitle foo=barztitle foo=">"c                     d}d| d| d}| j                  |ddg fddgt        d	
             | j                  |ddg fddddgt        d
             y )N+<!-- not a comment --><i>Egg &amp; Spam</i>z<TitLe>r   r   r    r   r   z'<!-- not a comment --><i>Egg & Spam</i>r   Tr_   r   r   z<!-- not a comment --><i>Egg r=   ampr   z	 Spam</i>Fr   r   s       r   test_title_closing_tagz)HTMLParserTestCase.test_title_closing_tag  s     @gYb*Z"5O/1 #<T"R 	 	T 	Z"5E01/	1
 #<U"S 	 	Ur   )r   TEXTAREAz	textarea z	textarea
z	textarea/ztextarea foo=barztextarea foo=">"c                     d}d| d| d}| j                  |ddg fddgt        d	
             | j                  |ddg fddddgt        d
             y )Nr   z
<TexTarEa>r   r   r    r   r   r   Tr_   r   r   r   r   Fr   r   s       r   test_textarea_closing_tagz,HTMLParserTestCase.test_textarea_closing_tag  s     @	F81-ZR8O24 #<T"R 	 	T 	ZR8E012	4
 #<U"S 	 	Ur   ztail,end)r   Fr   Fr   F)z</sF)z</scriptF)z	</script T)z</script foo=barT)z</script foo=">Tc                 n    d}d| | }| j                  |ddg fd|r|n||z   fgt        d             y )	Nza = 123r   r    r   r   Fr_   r   r   )r   tailendr   rk   s        r   test_eof_in_scriptz%HTMLParserTestCase.test_eof_in_script  sT     wiv&Z26#W4HJ";U"S 	 	Ur   )r   r   r   )z</tF)z</titleF)z</title T)z</title foo=barT)z</title foo=">Tc           	          d| }| j                  |ddg fdd|rdn|z   fgt        d      	       | j                  |ddg fd
ddd|rdn|z   fgt        d      	       y )Nz<TitLe>Egg &amp; Spamr    r   r   z
Egg & Spamr   Tr_   r   )r   zEgg r   z SpamFr   )r   r   r   rk   s       r   test_eof_in_titlez$HTMLParserTestCase.test_eof_in_title  s     $D6*Z"5#\3RD%IJL";T"R 	 	T 	Z"5,0#Wct%DEG #<U"S	 	 	Ur   c                 4    d}g d}| j                  ||       y )Na.  <!-- I'm a valid comment --><!--me too!--><!------><!-----><!----><!---><!--><!----I have many hyphens----><!-- I have a > in the middle --><!-- and I have -- in the middle! --><!--incorrectly-closed-comment--!><!----!><!----!--><!---- >--><!---!>--><!--!>--><!-- <!-- nested --> --><!--<!--><!--<!--!>))r/   z I'm a valid comment )r/   zme too!r/   z--r/   -r/   r   r   r   )r/   z--I have many hyphens--)r/   z I have a > in the middle )r/   z and I have -- in the middle! )r/   zincorrectly-closed-commentr   )r/   z--!)r/   z-- >r/   z-!>)r/   z!>)r/   z <!-- nested )r   z -->r/   r   r   rr   r   r   expecteds      r   test_commentsz HTMLParserTestCase.test_comments  s     ,
( 	h'r   c                 4    d}g d}| j                  ||       y )Nzs<!--[if IE & !(lte IE 8)]>aren't<![endif]--><!--[if IE 8]>condcoms<![endif]--><!--[if lte IE 7]>pretty?<![endif]-->))r/   z%[if IE & !(lte IE 8)]>aren't<![endif])r/   z[if IE 8]>condcoms<![endif])r/   z[if lte IE 7]>pretty?<![endif]rr   r   s      r   test_condcomsz HTMLParserTestCase.test_condcoms  s!    8C 	h'r   c           
         d }| j                   |       j                         g d}dddgfddg}|D ]*  }| j                  dj                  |      | |       	       , d
ddg dfd
dd
g}|D ]*  }| j                  dj                  |      | |       	       , |D ]U  }dj	                  |gdz        }d
ddg fd|fdd
ddg fd|fdd
g	}| j                  dj                  ||      | |       	       W d}t        dt        |            D ]$  }| j                  |d | d|d | fg |       	       & | j                  ddg |       	       y )Nc                      t               S rY   )rO   rH   r   r   <lambda>z:HTMLParserTestCase.test_convert_charrefs.<locals>.<lambda>  s    24r   )z&quot;z&#34;z&#x22;z&quotz&#34z&#x22r    r   )hrefzfoo"zar)r   za"zr   z<a href="foo{0}zar">a{0}z</a>r   )r   "))xr   )yz"X)zzX"z*{0}<a x="{0}" y="{0}X" z="X{0}">{0}</a>{0}X   r   r   r   r   r   z/{1}<script>{0}</script>{1}<style>{0}</style>{1}z&quo &# &#xr   no charrefs here)r   r  )
assertTruer`   rl   formatjoinrangelen)r   rj   charrefsr   r4   textr   r   s           r   test_convert_charrefsz(HTMLParserTestCase.test_convert_charrefs  s   4		445J':&;<#_6GOO;BB7K$	  =   "&LM!?MC  GOO ))/$	  =  
  G88WIaK(D%#Xr2VTN,m#Wb1FD>+]	<H
 OO 44:F44I$	  =   q#d)$AOOD!HRa'9&:&/k  3 % 	*-I,J"++ 	 	/r   c           
      F    | j                  ddddgfdddddd	gfd
dg       y )NzF<html <html>te>>xt&a<<bc</a></html>
<img src="URL><//img></html</html>r    r   )z<htmlN)r   zte>>xt)r=   r   r   r   zbc<)r   Nr~   ru   rr   rZ   s    r   test_tolerant_parsingz(HTMLParserTestCase.test_tolerant_parsing4  s@     ='/1BC..)'>.*?,	-r   c                    | j                  ddg       | j                  ddg       | j                  ddg       | j                  ddg       | j                  d	g        | j                  d
dg       | j                  ddg       | j                  ddg       | j                  dg        | j                  ddg       | j                  ddg       | j                  dddg fg       | j                  ddg       | j                  ddg       | j                  dg        | j                  dg        | j                  dg        | j                  dg        | j                  dg        | j                  d dd!g fg       | j                  d"dd#g fg       | j                  d$d%d#g fg       | j                  d&dd#g fg       | j                  d'd%d#g fg       | j                  d(d)g       y )*Nr   r  <>)r   r  < >)r   r  < )r   r  z</><$>)r   r  z</$>)r/   $r   )r   r   z</az</ a>)r/   z az</ az<a<a>r    a<az</a<a>)r,   r  r   r   z<az<a foo='bar'z<a foo='barz
<a foo='>'z	<a foo='>z<a$>za$z<a$b>a$bz<a$b/>r(   z<a$b  >z<a$b  />z</a$b>)r,   r  rr   rZ   s    r   test_starttag_junk_charsz+HTMLParserTestCase.test_starttag_junk_chars?  s   m_-~./01~./r"01!1 23~./r""3!45!2 34:ub"9!:;#4"56/0b!+r*b)R(*dB!7 89:ub"9!:;M5"#=">?	Z$;#<=
mUB%?$@A#4"56r   c           
         | j                  ddddgfg       d}ddg dfg}| j                  ||       d}ddg d	fd
dg d	fg}| j                  ||       d}d
dg fd
dg fd
dg fd
dg fddg fddg fddg fddg fg}| j                  ||       y )Nz<a foo="var"/>r(   r   )r   varzj<img width=902 height=250px src="/sites/default/files/images/homepage/foo.jpg" /*what am I doing here*/ />ry   ))width902)height250px)rz   z,/sites/default/files/images/homepage/foo.jpg)z*whatN)amN)iN)doingN)zhere*Nz9<a / /foo/ / /=/ / /bar/ / /><a / /foo/ / /=/ / /bar/ / >))r   N)=N)barNr    zD<meta><meta / ><meta // ><meta / / ><meta/><meta /><meta //><meta//>metarr   r   s      r   test_slashes_in_starttagz+HTMLParserTestCase.test_slashes_in_starttagZ  s    (M3@P+Q*RS. 5/
  	h'/ C!LMIJ
 	h'3 $z62&>$z62&>FB'-)DFB'-)D	
 	h'r   c                 P    | j                  ddg       | j                  ddg       y )Nz</a/>r   z</a foo="var"/>rr   rZ   s    r   test_slashes_in_endtagz)HTMLParserTestCase.test_slashes_in_endtagy  s%    /!23)O+<=r   c                 *    | j                  ddg       y )Nz<!DOCTYPE foo $ >)r:   zDOCTYPE foo $ rr   rZ   s    r   test_declaration_junk_charsz.HTMLParserTestCase.test_declaration_junk_chars}  s    +.H-IJr   c                 *    | j                  ddg       y )Nz"<!spacer type="block" height="25">)r/   zspacer type="block" height="25"rr   rZ   s    r   test_illegal_declarationsz,HTMLParserTestCase.test_illegal_declarations  s    <GH	Jr   c                 r    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g fg}| j                  ||       y )Nzn<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br></li class="unit"><br></li
						</ul><br></><br>r    br)r,   zlabel<r   )r/   z<h4)r,   lirr   r   s      r   test_invalid_end_tagsz(HTMLParserTestCase.test_invalid_end_tags  sv    Mr*(r*%r*&r*$r*$r*r*#,$ 	h'r   c                 >    d}ddg fdddg}| j                  ||       y )Nz(<b>This</b attr=">"> confuses the parserr    r   )r   Thisr   )r   z confuses the parserrr   r   s      r   test_broken_invalid_end_tagz.HTMLParserTestCase.test_broken_invalid_end_tag  s1    9b)$#46 	h'r   c                     d}dddgfddg fddddgfd	d
dddg fdddg fddddg}| j                  ||       d}ddg dfddg fddddgfd	d
g}| j                  ||       y )Nz[<div style=""    ><b>The <a href="some_url">rain</a> <br /> in <span>Spain</span></b></div>r    r   r   r   r   )r   zThe r   )r   some_url)r   rainr   r    r(   r-  )r   z in span)r   Spainr,   r9  r   r   z><div style="", foo = "bar" ><b>The <a href="some_url">rain</a>)r4  ,Nr   r#  rr   r   s      r   $test_correct_detection_of_start_tagsz7HTMLParserTestCase.test_correct_detection_of_start_tags  s    9 0b!345D"%$
  	h'O LMb!345
 	h'r   c                 d    ddgfddgfdg dfddd	gfg}|D ]  \  }}| j                  ||        y )
Na&)r   rA  za&b)r   abza&b )r   r   r=   r   r7  za&b;rC  rD  rr   r   r   r   r   s       r   test_EOF_in_charrefz&HTMLParserTestCase.test_EOF_in_charref  sV     N#$^$%GHm%789	
 #ND(OOD(+ #r   c                     ddgfddgfddgfddgfddgfd	dgfd
dgfddgfddgfddgfddgfddgfddgfddgfg}|D ]  \  }}| j                  ||        y )Nr   r   z<!---z<!----z<!-----r   z<!------r   z<!----!z<!---!)r/   z-!z<!---!>r   z<!--foo)r/   r   z<!--foo-z	<!--foo--z
<!--foo--!z<!--<!--r   z	<!--<!--!rr   rE  s       r   test_eof_in_commentsz'HTMLParserTestCase.test_eof_in_comments  s    o&''(())*++,-)*)*++,-+,-,-.-././0+,-,-.
  #ND(OOD(+ #r   c                     ddgfddgfddgfddgfd	d
gfddgfddgfddgfddgfddgfg
}|D ]  \  }}| j                  ||        y )Nr   r   r   r   z<![)r/   [z	<!DOCTYPE)r:   DOCTYPEz
<!DOCTYPE )r:   r   z<!DOCTYPE html)r:   zDOCTYPE htmlz<!DOCTYPE html )r:   zDOCTYPE html z<!DOCTYPE html PUBLIC)r:   zDOCTYPE html PUBLICz<!DOCTYPE html PUBLIC "foo)r:   zDOCTYPE html PUBLIC "fooz6<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "foo)r:   z4DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "foorr   rE  s       r   test_eof_in_declarationsz+HTMLParserTestCase.test_eof_in_declarations  s    O$%%&'%&'./0012 89:!: ;<$'F&GH),P+QRENOQ
 #ND(OOD(+ #r   )r   r   zx]zx]]c                     | j                  d|z   dd|z   fg       | j                  d|z   dd|z   fgt        d             | j                  d	|z   d
dg fd
ddgfdd|z   fg       y )Nz	<![CDATA[rC   CDATA[r/   z[CDATA[Tr   r   <svg><text y="100"><![CDATA[r    r!   r  r   100rl   r   )r   r   s     r   test_eof_in_cdataz$HTMLParserTestCase.test_eof_in_cdata  s    g-((W*<=>	@g-#Y%89:"04"@ 	 	B 	6@$eR0$f|n=((W*<=?	@r   c                 4    d}g d}| j                  ||       y )Nz<!ELEMENT br EMPTY><! not really a comment ><! not a comment either --><! -- close enough --><!><!<-- this was an empty comment><!!! another bogus comment !!!>))r/   zELEMENT br EMPTY)r/   z not really a comment )r/   z not a comment either --)r/   z -- close enough --r   )r/   z<-- this was an empty comment)r/   z!! another bogus comment !!!rr   r   s      r   test_bogus_commentsz&HTMLParserTestCase.test_bogus_comments  s     2
 	h'r   c                 p    d}dddddddgfdd	dd
dgfddddg fdddddd
dgfdg}| j                  ||       y )Nz<![if !(IE)]>broken condcom<![endif]><![if ! IE]><link href="favicon.tiff"/><![endif]><![if !IE 6]><img src="firefox.png" /><![endif]><![if !ie 6]><b>foo</b><![endif]><![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>)rC   zif !(IE))r   zbroken condcom)rC   endif)rC   zif ! IEr(   link)r   zfavicon.tiff)rC   zif !IE 6ry   )rz   zfirefox.png)rC   zif !ie 6r    r   )r   r   r   )rC   zif (!IE)|(lt IE 9))rz   zmammoth.bmprr   r   s      r   test_broken_condcomsz'HTMLParserTestCase.test_broken_condcoms  s~    M )&%'F%=$>?%(E$:#;<%(b!%2E$:#;<%#
( 	h'r   )zjust some plain textr   z&not-an-entity-ref;r   r   z[[I have many brackets]]zI have a > in the middlezI have a ]] in the middlez] ]>z]] >zN
    if (a < b && a > b) {
        printf("[<marquee>How?</marquee>]");
    }
c                     d| d}ddg fdddgfdd|z   fd	d
g}| j                  ||       | j                  ||t        d             y )NrO  z]]></text></svg>r    r!   r  rP  rC   rN  r,   r  r,   r!   Tr   r   rR  )r   r   r   r   s       r   test_cdata_section_contentz-HTMLParserTestCase.test_cdata_section_content:  sj    & .gY6FG#,0X/0
 	h'h.42PQr   c           	      h    d}ddddg fdddgfdd	d
ddg	}| j                  ||t        d             y )Nzb<![CDATA[foo<br>bar]]><svg><text y="100"><![CDATA[foo<br>bar]]></text></svg><![CDATA[foo<br>bar]]>)r/   z[CDATA[foo<br)r   zbar]]>r    r!   r  rP  )rC   zCDATA[foo<br>barr[  r\  Tr   r   rR  r   s      r   test_cdata_sectionz%HTMLParserTestCase.test_cdata_sectionX  sV    ) )#,00(

 	h.42PQr   c                     t        d      }|j                  d       | j                  |j                         dddg fddd	g       y )
NTr_   zfoo <a>link</a> bar &amp; baz)r   zfoo r    r   )r   rX  r   )r   z
 bar & baz)r   rc   assertEqualr   )r   r   s     r   "test_convert_charrefs_dropped_textz5HTMLParserTestCase.test_convert_charrefs_dropped_textj  sO      634
C46F46	
r   cpuc                     d }d} |d|z          |d|z          |d|z          |d|z          |d|z          |d|z          |d	|z          |d
|z          |d|z          |d|z         y )Nc                     t         j                  j                         }|j                  |        |j	                          y rY   )r   r   r   rc   rd   )rh   r   s     r   checkzBHTMLParserTestCase.test_eof_no_quadratic_complexity.<locals>.checkz  s)    [[++-FKKLLNr   i r   z<a a=z8</a </a </a </a </a </a </a </a </a </a </a </a </a </a zB</a a=</a a=</a a=</a a=</a a=</a a=</a a=</a a=</a a=</a a=</a a=z<!--<!--<!--<!--zx<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!z&<?<?<?<?<?<?<?<?<?<?<?<?<?<?<?<?<?<?<?z-</$</$</$</$</$</$</$</$</$</$</$</$</$</$</$zQ<![CDATA[<![CDATA[<![CDATA[<![CDATA[<![CDATA[<![CDATA[<![CDATA[<![CDATA[<![CDATA[a;  <!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctype<!doctyperH   )r   rf  ns      r    test_eof_no_quadratic_complexityz3HTMLParserTestCase.test_eof_no_quadratic_complexityv  s    	 eaigkkAoma j1ni!mi!mj1no!""#r   N)2rE   rF   rG   rs   r   r   r   r   r   r   r   r   r   r   r   r   subTestsr   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r%  r'  r)  r+  r/  r2  r?  rF  rH  rL  rS  rU  rY  r]  r_  rb  requires_resourcerh  rH   r   r   rp   rp   z   s   @	

L4<:0# Wi "
 *3+*3 Wi "
 22 Wi "
  Wi "
  Wh !P Q
UQ
U Wh !M NUNU Wh !M NUNU Wh !V WUWU Wj 	# 	U	U Wj 	# 		U		U+(Z(%/R	-76(>>KJ(4((B,,(," Wi!78	@ 9	@($ (D Wi "  R! RR$

 Wu%$ &$r   rp   c                   r    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 Zd Zy)AttributesTestCasec                    ddg dfg}| j                  d|       | j                  ddddgfg       | j                  ddddgfg       | j                  d	dddgfg       | j                  d
dddgfg       | j                  ddddgfg       | j                  ddddgfg       | j                  ddddgfg       | j                  ddddgfg       | j                  ddddgfg       y )Nr    r   ))r   v)crn  )drn  )eNz<a b='v' c="v" d=v e>z<a foo==bar>)r   z=barz<a foo =bar>r>  z<a foo	=bar>z<a foo=bar>)zfoor#  u   <a foo =bar>)u   foo r#  z<a foo= bar>z<a foo=	bar>z<a foo=bar>)r   zbaru   <a foo= bar>)r   u    barrr   r   s     r   test_attr_syntaxz#AttributesTestCase.test_attr_syntax  s   sM
N
 	3V<*cO;L)M(NO*cN;K)L(MN:s^<L*M)NO:s=M<N*O)PQ)Z?Q>R,S+TU*cN;K)L(MN:s^<L*M)NO:s=M<N*O)PQ)Z?Q>R,S+TUr   c                     | j                  dddg dfg       | j                  dddddgfg       | j                  dddd	d
gfg       | j                  dddddgfg       | j                  ddddgfg       | j                  ddddgfg       y )Nz'<a b='xxx
	xxx' c="yyy	
yyy" d='	xyz
'>r    r   ))r   zxxx
	xxx)ro  zyyy	
yyy)rp  z	xyz
z<a b='' c="">)r   r   )ro  r   z<a b=	x c=
y>)r   r   )ro  r   u   <a b= c= >)r   )ro      z<e a=rgb(1,2,3)>rq  )r   z
rgb(1,2,3)z<a href=mailto:xyz@example.com>)r   zmailto:xyz@example.comrr   rZ   s    r   test_attr_valuesz#AttributesTestCase.test_attr_values  s    K$c ,> ? @	A 	+$cIy+ABC	E)$cJ
+CDE	G)$cK+GHI	K 	*$c,?+@AB	D 	-# BCDE	Gr   c                     | j                  dddddgfg       | j                  ddddd	gfg       | j                  d
dddd	gfg       y )Nu!   <img src=/foo/bar.png alt=中文>r    ry   )rz   z/foo/bar.png)altu   中文u+   <a title='テスト' href='テスト.html'>r   )r   u	   テスト)r   u   テスト.htmlu+   <a title="テスト" href="テスト.html">rr   rZ   s    r   test_attr_nonasciiz%AttributesTestCase.test_attr_nonascii  s    5%"9"9"; < =	> 	K# ? C E F G	H 	K# ? C E F G	Hr   c                 2    | j                  ddddgfg       y )Nz!<a b='&amp;&gt;&lt;&quot;&apos;'>r    r   )r   z&><"'rr   rZ   s    r   test_attr_entity_replacementz/AttributesTestCase.test_attr_entity_replacement  s!    /#012	4r   c                 4    | j                  dddg dfg       y )Nz<a a.b='v' c:d=v e-f=v>r    r   ))za.brn  )zc:drn  )ze-frn  rr   rZ   s    r   test_attr_funky_namesz(AttributesTestCase.test_attr_funky_names  s     %#IJK	Mr   c                 2    | j                  ddddgfg       y )Nz0<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>r    r   )r   u   €&aa&unsupported;rr   rZ   s    r   test_entityrefs_in_attributesz0AttributesTestCase.test_entityrefs_in_attributes  s#    >&#D"EFG	Ir   c                 F    | j                  ddddgfdddgfdddgfg       y )	Nz<a $><b $=%><c \=/>r    r   )r  Nr   )r  %ro  )\/rr   rZ   s    r   test_attr_funky_names2z)AttributesTestCase.test_attr_funky_names2  s:    "#}-#
|,#}-/	0r   c                     dD ]P  }| j                  d|z  dddgfg       | j                  d|z  dddgfg       | j                  d|z  dddgfg       R y )N)&z&amp;z&#38;z&#x26;z<a href="%s">r    r   )r   r  z<a href='%s'>z<a href=%s>rr   )r   rw   s     r    test_entities_in_attribute_valuez3AttributesTestCase.test_entities_in_attribute_value  su    7FOOOf4(#?@BOOOf4(#?@BOOMF2(#?@B 8r   c                 h    d}dddgfdddddgfddddd	gfd
ddddgfddg}| j                  ||       y )Nz<a href=test'style='color:red;bad1'>test - bad1</a><a href=test'+style='color:red;ba2'>test - bad2</a><a href=test'&nbsp;style='color:red;bad3'>test - bad3</a><a href = test'&nbsp;style='color:red;bad4'  >test - bad4</a>r    r   )r   ztest'style='color:red;bad1')r   ztest - bad1r   )r   ztest'+style='color:red;ba2')r   ztest - bad2)r   u   test' style='color:red;bad3')r   ztest - bad3)r   u   test' style='color:red;bad4')r   ztest - bad4rr   r   s      r   test_malformed_attributesz,AttributesTestCase.test_malformed_attributes  sv    L 	 FGH#FGH#JKL#JKL#
 	h'r   c                 x    | j                  dddg fddddgfdg       | j                  d	ddg fdddd
gfdg       y )Nz<x><y z=""o"" /></x>r    r   r(   r   )r  r   )zo""N)r,   r   z<x><y z="""" /></x>)z""Nrr   rZ   s    r   "test_malformed_adjacent_attributesz5AttributesTestCase.test_malformed_adjacent_attributes  sd    .$c2.*C)]1KL+-	. 	-$c2.*C)\1JK+-	.r   c                 d    | j                  dddddgfg       | j                  dddddgfg       y )	Nz<a width="100%"cellspacing=0>r    r   r  z100%cellspacing0z<a id="foo"class="bar">)idr   classr#  rr   rZ   s    r   test_adjacent_attributesz+AttributesTestCase.test_adjacent_attributes  sT    7$c,.ABD E	F 	1$c(/:< =	>r   c                 2    | j                  ddddgfg       y )Nz<a v=>r    r   )rn  r   rr   rZ   s    r   test_missing_attribute_valuez/AttributesTestCase.test_missing_attribute_value  s    $cI;78	:r   c                 2    | j                  ddddgfg       y )Nz-<a href=javascript:popup('/popup/help.html')>r    r   )r   z$javascript:popup('/popup/help.html')rr   rZ   s    r   test_javascript_attribute_valuez2AttributesTestCase.test_javascript_attribute_value  s)    G$cKLN O	Pr   c                 6    | j                  ddddgfddg       y )Nz-<a href='http://www.example.org/">;'>spam</a>r    r   )r   zhttp://www.example.org/">;)r   spamr   rr   rZ   s    r   test_end_tag_in_attribute_valuez2AttributesTestCase.test_end_tag_in_attribute_value  s,    H$cBCE)?<	=r   c                     d}ddg fddddgfddg dfdd	g fdd
dgfdddgfddddgfdddgfdddddddgfdddgfddddg}| j                  ||       y )Nz<html><body bgcolor=d0ca90 text='181008'><table cellspacing=0 cellpadding=1 width=100% ><tr><td align=left><font size=-1>- <a href=/rabota/><span class=en> software-and-i</span></a>- <a href='/1/'><span class=en> library</span></a></table>r    r   body)bgcolord0ca90)r  181008table)r  )cellpaddingr   r  trtd)alignleftfont)sizez-1)r   z- r   )r   z/rabota/r9  )r  en)r   z software-and-ir;  r   )r   z/1/)r   z library)r,   r  rr   r   s      r   test_with_unquoted_attributesz0AttributesTestCase.test_with_unquoted_attributes  s    M $"79K!LMOQr" 123.!12Z/C.DE/!235PZ.?@/!235I1D
 	h'r   c                     d}dddgfddddgfddddgfddg d	fdddd
gfddddgfddddgfddddgfddddgfg	}| j                  ||       y )Nz<div class=bar,baz=asd><div class="bar",baz="asd"><div class=bar, baz=asd,><div class="bar", baz="asd",><div class="bar",><div class=,bar baz=,asd><div class=,"bar" baz=,"asd"><div ,class=bar ,baz=asd><div class,="bar" baz,="asd">r    r   )r  zbar,baz=asdr  )z,bazasd)r  zbar,)bazzasd,)r  r<  )r  r  r<  r<  )r  z,bar)r  z,asd)r  z,"bar")r  z,"asd")z,classr#  )zclass,r#  )zbaz,r  rr   r   s      r   test_comma_between_attributesz0AttributesTestCase.test_comma_between_attributes4  s    0 !9 ;<!1? CD!2O DE !> ?!1; ?@!2O DE!46G HI!2O DE!2O DE
 	h'r   c                 2    | j                  ddddgfg       y )Nz<form action=bogus|&#()value>r    form)actionzbogus|&#()valuerr   rZ   s    r   -test_weird_chars_in_unquoted_attribute_valuesz@AttributesTestCase.test_weird_chars_in_unquoted_attribute_valuesP  s)    7'!> ?A:B 	Cr   N)rE   rF   rG   rr  rv  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  rH   r   r   rl  rl    s_    VG&H4
M
I0B(0	.>:P
=(0(8Cr   rl  c                   >    e Zd Z ed       ed      d               Zy)TestInheritancez_markupbase.ParserBase.__init__z_markupbase.ParserBase.resetc                     t        d      5 }t                |j                          |j                          d d d        y # 1 sw Y   y xY w)Nz_markupbase.ParserBase)r   r   assert_called_once)r   super_reset_methodsuper_init_methodparser_bases       r   test_base_class_methods_calledz.TestInheritance.test_base_class_methods_calledX  s9     +,002113 -,,s   +A  A	N)rE   rF   rG   r   r  rH   r   r   r  r  V  s(    
,-
)*4 + .4r   r  __main__)html.parserr   rf   unittestunittest.mockr   testr   r   r   r   rJ   rO   rW   TestCaser\   rp   rl  r  rE   mainrH   r   r   <module>r     s         =,T[[++ =,@A. AL^ L 
E8$$ E0N$ N$bHC HCV4h'' 4 zHMMO r   