
    dafx                     D   d Z ddlZddlZddl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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)zTests for HTMLParser.py.    N)patchc                   T    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y)EventCollectorc                     g | _         | j                   j                  | _        t        j                  j                  j
                  | g|i | y N)eventsappendhtmlparser
HTMLParser__init__)selfargskws      //root/Python-3.12.4/Lib/test/test_htmlparser.pyr   zEventCollector.__init__   s<    kk(('':t:r:    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   st     [[ 	E8Dx)6)2qE!H!45"H	 r   c                 ,    | j                  d||f       y )Nstarttagr	   r   tagattrss      r   handle_starttagzEventCollector.handle_starttag"   s    Ze,-r   c                 ,    | j                  d||f       y )Nstartendtagr   r   s      r   handle_startendtagz!EventCollector.handle_startendtag%   s    ]C/0r   c                 *    | j                  d|f       y )Nendtagr   )r   r    s     r   handle_endtagzEventCollector.handle_endtag(   s    XsO$r   c                 *    | j                  d|f       y )Ncommentr   r   r   s     r   handle_commentzEventCollector.handle_comment-       Y%&r   c                 *    | j                  d|f       y )Ncharrefr   r+   s     r   handle_charrefzEventCollector.handle_charref0   r-   r   c                 *    | j                  d|f       y )Nr   r   r+   s     r   handle_datazEventCollector.handle_data3       VTN#r   c                 *    | j                  d|f       y )Ndeclr   r+   s     r   handle_declzEventCollector.handle_decl6   r3   r   c                 *    | j                  d|f       y )N	entityrefr   r+   s     r   handle_entityrefzEventCollector.handle_entityref9   s    [$'(r   c                 *    | j                  d|f       y )Npir   r+   s     r   	handle_pizEventCollector.handle_pi<   s    T4L!r   c                 *    | j                  d|f       y )Nunknown declr   )r   r5   s     r   unknown_declzEventCollector.unknown_decl?   s    ^T*+r   N)__name__
__module____qualname__r   r   r"   r%   r(   r,   r0   r2   r6   r9   r<   r?    r   r   r   r   
   s>    ;
".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_starttagE   s.    &&tS%8_d&<&<&>?@r   N)r@   rA   rB   r"   rC   r   r   rE   rE   C   s    Ar   rE   c                       e Zd Zd Zd Zy)EventCollectorCharrefsc                 &    | j                  d       y Nz6This should never be called with convert_charrefs=Truefailr+   s     r   r0   z%EventCollectorCharrefs.handle_charrefL       		JKr   c                 &    | j                  d       y rL   rM   r+   s     r   r9   z'EventCollectorCharrefs.handle_entityrefO   rO   r   N)r@   rA   rB   r0   r9   rC   r   r   rJ   rJ   J   s    LLr   rJ   c                        e Zd Zd ZddZd Zy)TestCaseBasec                     t        d      S NFconvert_charrefs)r   r   s    r   get_collectorzTestCaseBase.get_collectorU   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:
)rX   feedcloser   rN   reprpprintpformat)r   sourceexpected_events	collectorr   sr   s          r   
_run_checkzTestCaseBase._run_checkX   s    **,I 	AKKN	""$_$II $&*6l3%&(.(GH && )/v(>? @ %r   c                 >    | j                  ||t        d             y rT   )rc   rE   )r   r_   r   s      r   _run_check_extrazTestCaseBase._run_check_extraf   s    +UC	Er   r   )r@   rA   rB   rX   rc   re   rC   r   r   rR   rR   S   s    6@Er   rR   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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)HTMLParserTestCasec                 P    | j                  ddg       | j                  ddg       y )Nz<?processing instruction>)r;   zprocessing instructionz<?processing instruction ?>)r;   zprocessing instruction ?rc   rW   s    r    test_processing_instruction_onlyz3HTMLParserTestCase.test_processing_instruction_onlym   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   
)r5   zDOCTYPE html PUBLIC 'foo'r   r
   )r8   entity)r/   32)r*   z4comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1bimg)srcBar)ismapN)r   zsample
text
)r/   x201C)r*   zcomment2a-- --comment2br'   r
   ri   rW   s    r   test_simple_htmlz#HTMLParserTestCase.test_simple_htmlu   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'   rw   z<div>&#bad;</div>divr'   ry   ri   rW   s    r   test_malformatted_charrefz,HTMLParserTestCase.test_malformatted_charref   sN    b!*
 	 	,-#0
 	r   c                 ,    | j                  dddg       y )Nz&entityref foo)r8   r8   )r   z foori   rW   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   ri   rW   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   ri   rW   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   ri   rW   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   >ri   rW   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   z<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<!-z-abc-->z<!--zabc-->z<!--azbc-->z<!--abzc-->z<!--abcz-->z<!--abc-z->z	<!--abc--ri   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>r5   zDOCTYPE ri   )r   dtdsdtds      r   test_valid_doctypesz&HTMLParserTestCase.test_valid_doctypes   s>    @$  	: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$   rw   z<p></p>r   rx   z<p><img src='foo' /></p>ro   )rp   foori   rW   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2rG   )re   )r   rb   s     r   test_get_starttag_textz)HTMLParserTestCase.test_get_starttag_text  s3    4a\<$@Aa "" 	#r   c           	          g d}g d}|D ]H  }|D ]A  }|j                         }dj                  ||      }| j                  |d|g fd|fd|fg       C J y )N)z*<!-- not a comment --> &not-an-entity-ref;z<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;
// -->
zfoo = "</sty" + "le>";u   <!-- ☃ -->)scriptstyleSCRIPTSTYLEScriptStylez <{element}>{content}</{element}>elementcontentr   r   r'   )lowerformatrc   )r   contentselementsr   r   element_lowerrb   s          r   test_cdata_contentz%HTMLParserTestCase.test_cdata_content  s    
( M 	@G# @ '6==gGN > PZ$C%+W$5%-}$=$? @	@	@r   c                      G d dt               }d}dD ]X  }|j                         j                         }dj                  ||      }| j	                  |d|g fd|fd	|fg |d
             Z y )Nc                       e Zd Zd Zy)BHTMLParserTestCase.test_cdata_with_closing_tags.<locals>.Collectorc                     | j                   S r   )r   rW   s    r   r   zMHTMLParserTestCase.test_cdata_with_closing_tags.<locals>.Collector.get_events0  s    {{"r   N)r@   rA   rB   r   rC   r   r   	Collectorr   /  s    #r   r   z<!-- not a comment --> &not-an-entity-ref;
                  <a href="" /> </p><p> <span></span></style>
                  '</script' + '>')z scriptzscript z script z
scriptzscript
z
script
z<script>{content}</{element}>r   r   r   r'   FrU   ra   )r   r   stripr   rc   )r   r   r   r   r   rb   s         r   test_cdata_with_closing_tagsz/HTMLParserTestCase.test_cdata_with_closing_tags*  s    
	# 	#&> 	IG#MMO113M/66w?F 7 HAOOA]B ?!' 1!)= 9 ; '0&G  I	Ir   c                 4    d}g d}| j                  ||       y )Nz<!-- I'm a valid comment --><!--me too!--><!------><!----><!----I have many hyphens----><!-- I have a > in the middle --><!-- and I have -- in the middle! -->))r*   z I'm a valid comment )r*   zme too!)r*   z--r*   r   )r*   z--I have many hyphens--)r*   z I have a > in the middle )r*   z and I have -- in the middle! ri   r   r
   expecteds      r   test_commentsz HTMLParserTestCase.test_comments@  s!    8C 	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]ri   r   s      r   test_condcomsz HTMLParserTestCase.test_condcomsQ  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 r   )rJ   rC   r   r   <lambda>z:HTMLParserTestCase.test_convert_charrefs.<locals>.<lambda>\  s
    24 r   )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   )r'   r   z/{1}<script>{0}</script>{1}<style>{0}</style>{1}z&quo &# &#xr   no charrefs here)r   r   )
assertTruerV   rc   r   joinrangelen)r   ra   charrefsr   r/   textr
   r   s           r   test_convert_charrefsz(HTMLParserTestCase.test_convert_charrefsZ  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)$ 	3AOOD!HRa'9&:&/k  3	3 	*-I,J"++ 	 	/r   c                 J    | j                  ddddgfdddddd	gfd
d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)r8   r   )r   r   zbc<)r   Nrt   )r   z
<img src="URL>)r*   z/img)r'   zhtml<ri   rW   s    r   test_tolerant_parsingz(HTMLParserTestCase.test_tolerant_parsing  sF     ='/1BC..)'>.8//	?1
	2r   c                    | j                  dg        | j                  d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dg       | j                  ddg       | j                  ddg       | j                  ddg       | j                  d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       y )!Nz</>z</$>)r*   $</)r   r   </a)r   r   z<a<a>r   a<az</a<a>)r'   r   r   )r   r   <a)r   r   <a foo='bar')r   r   <a foo='bar)r   r   
<a foo='>')r   r   	<a foo='>)r   r   z<a$>za$z<a$b>za$bz<a$b/>r$   z<a$b  >z<a$b  />ri   rW   s    r   test_starttag_junk_charsz+HTMLParserTestCase.test_starttag_junk_chars  sP   r"!1 23~./01:ub"9!:;#4"56~./~./)A(BC(?'@A'=&>?&;%<=*dB!7 89:ub"9!:;M5"#=">?	Z$;#<=
mUB%?$@Ar   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*/ />ro   ))width902)height250px)rp   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//>metari   r   s      r   test_slashes_in_starttagz+HTMLParserTestCase.test_slashes_in_starttag  s    (M3@P+Q*RS. 5/
  	h'/ C!LMIJ
 	h'3 $z62&>$z62&>FB'-)DFB'-)D	
 	h'r   c                 *    | j                  ddg       y )Nz<!DOCTYPE foo $ >)r5   zDOCTYPE foo $ ri   rW   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"ri   rW   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<rz   )r*   z<h4)r'   liri   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 parserri   r   s      r   test_broken_invalid_end_tagz.HTMLParserTestCase.test_broken_invalid_end_tag  s3    
 :b)$#68 	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   ry   r   r   r   )r   zThe r   )r   some_url)r   rainr   r    r$   r   )r   z in span)r   Spainr'   r  r   rz   z><div style="", foo = "bar" ><b>The <a href="some_url">rain</a>)r   ,N)r   r   ri   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   r
  za&b)r   abza&b )r   r   r8   r   r  za&b;r  r  ri   )r   r   r
   r   s       r   test_EOF_in_charrefz&HTMLParserTestCase.test_EOF_in_charref  s[     N#$^$%GHm%789	
 # 	,ND(OOD(+	,r   c                 4    d}g d}| j                  ||       y )Nz<! not really a comment ><! not a comment either --><! -- close enough --><!><!<-- this was an empty comment><!!! another bogus comment !!!>))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 !!!ri   r   s      r   test_broken_commentsz'HTMLParserTestCase.test_broken_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]>)r>   zif !(IE))r   zbroken condcom)r>   endif)r>   zif ! IEr$   link)r   zfavicon.tiff)r>   zif !IE 6ro   )rp   zfirefox.png)r>   zif !ie 6r   r   )r   r   r   )r>   zif (!IE)|(lt IE 9))rp   zmammoth.bmpri   r   s      r   test_broken_condcomsz'HTMLParserTestCase.test_broken_condcoms.  s~    M )&%'F%=$>?%(E$:#;<%(b!%2E$:#;<%#
& 	h'r   c                     t        d      }|j                  d       | j                  |j                         dddg fddd	g       y )
NTrU   zfoo <a>link</a> bar &amp; baz)r   zfoo r   r   )r   r  r   )r   z
 bar & baz)r   rZ   assertEqualr   )r   r   s     r   "test_convert_charrefs_dropped_textz5HTMLParserTestCase.test_convert_charrefs_dropped_textO  sO      634
C46F46	
r   N) r@   rA   rB   rj   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  rC   r   r   rg   rg   k   s    @	

L4<:0#@>I,("(%/R2B&(>KJ(4
((B,( (B

r   rg   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|       | j                  d|       | j                  d|       y )Nr   r   ))r   v)cr  )dr  )eNz<a b='v' c="v" d=v e>z<a  b = 'v' c = "v" d = v e>z<a
b
=
'v'
c
=
"v"
d
=
v
e>z<a	b	=	'v'	c	=	"v"	d	=	v	e>ri   r   s     r   test_attr_syntaxz#AttributesTestCase.test_attr_syntax^  sR    sM
N
 	3V<:FCCVLCVLr   c                     | j                  dddg d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)r  zyyy	
yyy)r  z	xyz
z<a b='' c="">)r   r   )r  r   z<e a=rgb(1,2,3)>r  )r   z
rgb(1,2,3)z<a href=mailto:xyz@example.com>)r   zmailto:xyz@example.comri   rW   s    r   test_attr_valuesz#AttributesTestCase.test_attr_valuesg  s    K$c ,> ? @	A 	+$cIy+ABC	E 	*$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   ro   )rp   z/foo/bar.png)altu   中文u+   <a title='テスト' href='テスト.html'>r   )titleu	   テスト)r   u   テスト.htmlu+   <a title="テスト" href="テスト.html">ri   rW   s    r   test_attr_nonasciiz%AttributesTestCase.test_attr_nonasciiv  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&><"'ri   rW   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.br  )zc:dr  )ze-fr  ri   rW   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;ri   rW   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   %r  )\/ri   rW   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   r2  z<a href='%s'>z<a href=%s>ri   )r   rm   s     r    test_entities_in_attribute_valuez3AttributesTestCase.test_entities_in_attribute_value  s|    7 	BFOOOf4(#?@BOOOf4(#?@BOOMF2(#?@B	Br   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 - bad4ri   r   s      r   test_malformed_attributesz,AttributesTestCase.test_malformed_attributes  sr    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""Nri   rW   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   ri   rW   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   )r  r   ri   rW   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')ri   rW   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   ri   rW   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   r9  trtd)alignleftfont)sizez-1)r   z- r   )r   z/rabota/r  )r?  en)r   z software-and-ir  r   )r   z/1/)r   z library)r'   rM  ri   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   ry   )r?  zbar,baz=asdr>  )z,bazasd)r?  zbar,)bazzasd,)r>  r  )rY  rX  r  r  )r?  z,bar)rY  z,asd)r?  z,"bar")rY  z,"asd")z,classr   )zclass,r   )zbaz,rX  ri   r   s      r   test_comma_between_attributesz0AttributesTestCase.test_comma_between_attributes  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|&#()valueri   rW   s    r   -test_weird_chars_in_unquoted_attribute_valuesz@AttributesTestCase.test_weird_chars_in_unquoted_attribute_values  s)    7'!> ?A:B 	Cr   N)r@   rA   rB   r  r!  r%  r'  r)  r+  r0  r3  r5  r7  r@  rB  rD  rG  rV  rZ  r^  rC   r   r   r  r  \  s_    MGH4
M
I0B((	.>:P
=(0(8Cr   r  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_called  sB     +, 	4002113	4 	4 	4s   +A  A	N)r@   rA   rB   r   rf  rC   r   r   r`  r`    s(    
,-
)*4 + .4r   r`  __main__)__doc__html.parserr
   r]   unittestunittest.mockr   r   r   r   rE   rJ   TestCaserR   rg   r  r`  r@   mainrC   r   r   <module>rn     s        6,T[[++ 6,rA. AL^ LE8$$ E0n
 n
bzC zCz4h'' 4 zHMMO r   