
ĆIX                 @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z Gd d   d e j j  Z	 Gd d   d e	  Z
 Gd d	   d	 e	  Z Gd
 d   d e j  Z Gd d   d e  Z Gd d   d e  Z e d k r e j   d S)zTests for HTMLParser.py.    N)supportc               @   s   e  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 d   Z d d   Z d d   Z d S)EventCollectorc             O   s5   g  |  _  |  j  j |  _ t j j j |  | |  d  S)N)eventsappendhtmlparser
HTMLParser__init__)selfargskw r   M/afs/.cs.wisc.edu/s/python-3.5.2/amd64_ubu16/lib/python3.5/test_htmlparser.pyr	      s    	zEventCollector.__init__c             C   s   g  } d  } xm |  j  D]b } | d } | | k o= d k n re d | d d | d f | d <n | j |  | } q W| |  _  | S)Nr   data   r   )r   r   )r
   LZprevtypeeventtyper   r   r   
get_events   s    
#
	zEventCollector.get_eventsc             C   s   |  j  d | | f  d  S)Nstarttag)r   )r
   tagattrsr   r   r   handle_starttag!   s    zEventCollector.handle_starttagc             C   s   |  j  d | | f  d  S)Nstartendtag)r   )r
   r   r   r   r   r   handle_startendtag$   s    z!EventCollector.handle_startendtagc             C   s   |  j  d | f  d  S)Nendtag)r   )r
   r   r   r   r   handle_endtag'   s    zEventCollector.handle_endtagc             C   s   |  j  d | f  d  S)Ncomment)r   )r
   r   r   r   r   handle_comment,   s    zEventCollector.handle_commentc             C   s   |  j  d | f  d  S)Ncharref)r   )r
   r   r   r   r   handle_charref/   s    zEventCollector.handle_charrefc             C   s   |  j  d | f  d  S)Nr   )r   )r
   r   r   r   r   handle_data2   s    zEventCollector.handle_datac             C   s   |  j  d | f  d  S)Ndecl)r   )r
   r   r   r   r   handle_decl5   s    zEventCollector.handle_declc             C   s   |  j  d | f  d  S)N	entityref)r   )r
   r   r   r   r   handle_entityref8   s    zEventCollector.handle_entityrefc             C   s   |  j  d | f  d  S)Npi)r   )r
   r   r   r   r   	handle_pi;   s    zEventCollector.handle_pic             C   s   |  j  d | f  d  S)Nzunknown decl)r   )r
   r#   r   r   r   unknown_decl>   s    zEventCollector.unknown_declN)__name__
__module____qualname__r	   r   r   r   r   r   r!   r"   r$   r&   r(   r)   r   r   r   r   r   	   s   r   c               @   s   e  Z d  Z d d   Z d S)EventCollectorExtrac             C   s0   t  j |  | |  |  j d |  j   f  d  S)Nstarttag_text)r   r   r   Zget_starttag_text)r
   r   r   r   r   r   r   D   s    z#EventCollectorExtra.handle_starttagN)r*   r+   r,   r   r   r   r   r   r-   B   s   r-   c               @   s(   e  Z d  Z d d   Z d d   Z d S)EventCollectorCharrefsc             C   s   |  j  d  d  S)Nz6This should never be called with convert_charrefs=True)fail)r
   r   r   r   r   r!   K   s    z%EventCollectorCharrefs.handle_charrefc             C   s   |  j  d  d  S)Nz6This should never be called with convert_charrefs=True)r0   )r
   r   r   r   r   r&   N   s    z'EventCollectorCharrefs.handle_entityrefN)r*   r+   r,   r!   r&   r   r   r   r   r/   I   s   r/   c               @   s7   e  Z d  Z d d   Z d d d  Z d d   Z d S)TestCaseBasec             C   s   t  d d  S)Nconvert_charrefsF)r   )r
   r   r   r   get_collectorT   s    zTestCaseBase.get_collectorNc             C   s   | d  k r |  j    } | } x | D] } | j |  q% W| j   | j   } | | k r |  j d d t |  d t j |  d t j |   d  S)Nz-received events did not match expected eventsz	
Source:
z
Expected:
z
Received:
)r3   feedcloser   r0   reprpprintZpformat)r
   sourceZexpected_events	collectorr   sr   r   r   r   
_run_checkW   s    
zTestCaseBase._run_checkc             C   s    |  j  | | t d d   d  S)Nr2   F)r;   r-   )r
   r8   r   r   r   r   _run_check_extrae   s    zTestCaseBase._run_check_extra)r*   r+   r,   r3   r;   r<   r   r   r   r   r1   R   s   r1   c               @   s  e  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 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/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z  d= d>   Z! d? d@   Z" dA dB   Z# dC S)DHTMLParserTestCasec             C   s*   |  j  d d g  |  j  d d g  d  S)Nz<?processing instruction>r'   processing instructionz<?processing instruction ?>processing instruction ?)pir>   )r@   r?   )r;   )r
   r   r   r    test_processing_instruction_onlyl   s    	
	z3HTMLParserTestCase.test_processing_instruction_onlyc             C   s_   |  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  d  S)'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#   DOCTYPE html PUBLIC 'foo'r   r   r%   entityr    32r   4comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1bimgsrcBarismapsample
text
x201Ccomment2a-- --comment2br   )datarB   )zdeclrC   )rN   rB   )z	entityrefzentity)charrefrE   )rN   rB   )commentrF   )rN   rB   )zsrcrI   )rJ   N)rN   rK   )rO   rL   )rN   rB   )rP   rM   )rN   rB   )zendtagzhtml)rN   rB   )r;   )r
   r   r   r   test_simple_htmlt   s&    z#HTMLParserTestCase.test_simple_htmlc             C   sK   |  j  d d d g  f d	 d
 g  |  j  d g d d g  f d d g  d  S)Nz<p>&#bad;</p>r   pr   &#bad;r   z<div>&#bad;</div>div)datarS   )endtagrR   )rU   rS   )rV   rT   )r;   )r
   r   r   r   test_malformatted_charref   s    	
z,HTMLParserTestCase.test_malformatted_charrefc             C   s   |  j  d d d g  d  S)Nz&entityref foor%   r    foo)	entityrefrY   )zdatarX   )r;   )r
   r   r   r   test_unclosed_entityref   s    	z*HTMLParserTestCase.test_unclosed_entityrefc             C   s2   |  j  d d d g  f d d g  f d d g  d  S)Nz<a><b></a></b>r   abr   )endtagr[   )r]   r\   )r;   )r
   r   r   r   test_bad_nesting   s
    	z#HTMLParserTestCase.test_bad_nestingc             C   s   |  j  d d g  d  S)N#this text & contains & ampersands &r   )zdatar_   )r;   )r
   r   r   r   test_bare_ampersands   s    	z'HTMLParserTestCase.test_bare_ampersandsc             C   s   |  j  d d g  d  S)N.this < text > contains < bare>pointy< bracketsr   )zdatara   )r;   )r
   r   r   r   test_bare_pointy_brackets   s    	z,HTMLParserTestCase.test_bare_pointy_bracketsc             C   sB   |  j  d d d d g f g  |  j  d d d d	 g f g  d  S)
Nz	<a b='<'>r   r[   r\   <z	<a b='>'>>)r\   rc   )r\   rd   )r;   )r
   r   r   r   test_starttag_end_boundary   s    z-HTMLParserTestCase.test_starttag_end_boundaryc             C   s+  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 |  d  S)-Nr   r[   r\   rc   z	<a b='<'>z<a zb='<'>z<a bz='<'>z<a b=z'<'>z<a b='<z'>z<a b='<'rd   z	<a b='>'>zb='>'>z='>'>z'>'>z<a b='>z<a b='>'r   abc z
<!--abc-->z	!--abc-->z<!z--abc-->z<!-z-abc-->z<!--zabc-->z<!--azbc-->z<!--abzc-->z<!--abcz-->z<!--abc-z->z	<!--abc--)r\   rc   )r\   rd   )zcommentzabc)r;   )r
   outputr   r   r   test_buffer_artefacts   s4    	z(HTMLParserTestCase.test_buffer_artefactsc          
   C   sZ   d d d d d d d d d	 d
 g
 } x/ | D]' } |  j  d | d d | f g  q+ Wd  S)NZ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#   zDOCTYPE )r;   )r
   ZdtdsZdtdr   r   r   test_valid_doctypes   s    	z&HTMLParserTestCase.test_valid_doctypesc             C   sm   |  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  d  S)Nz<p/>r   rR   z<p></p>r   r   z<p><img src='foo' /></p>rG   rH   foo)endtagrR   )zsrcrk   )rl   rR   )r;   )r
   r   r   r   test_startendtag   s    		
	z#HTMLParserTestCase.test_startendtagc             C   s5   d } |  j  | d d d	 d
 g f d | f g  d  S)Nz <foo:bar   
   one="1"	two=2   >r   zfoo:barone1two2r.   )rn   ro   )rp   rq   )r<   )r
   r:   r   r   r   test_get_starttag_text  s    	z)HTMLParserTestCase.test_get_starttag_textc             C   s   d d d d d d d d d	 d
 d g } d d d d d d g } xq | D]i } x` | D]X } | j    } d j d | d |  } |  j | d | g  f d | f d | f g  qS WqF Wd  S)Nz*<!-- 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styleZSCRIPTZSTYLEZScriptZStylez <{element}>{content}</{element}>elementcontentr   r   r   )lowerformatr;   )r
   contentselementsrv   ru   element_lowerr:   r   r   r   test_cdata_content
  s(    			z%HTMLParserTestCase.test_cdata_contentc             C   s   Gd d   d t   } d } x d d d d d d	 g D]m } | j   j   } d
 j d | d |  } |  j | d | g  f d | f d | f g d | d d  q5 Wd  S)Nc               @   s   e  Z d  Z d d   Z d S)zBHTMLParserTestCase.test_cdata_with_closing_tags.<locals>.Collectorc             S   s   |  j  S)N)r   )r
   r   r   r   r   /  s    zMHTMLParserTestCase.test_cdata_with_closing_tags.<locals>.Collector.get_eventsN)r*   r+   r,   r   r   r   r   r   	Collector.  s   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}>ru   rv   r   r   r   r9   r2   F)r   rw   striprx   r;   )r
   r}   rv   ru   r{   r:   r   r   r   test_cdata_with_closing_tags)  s    		z/HTMLParserTestCase.test_cdata_with_closing_tagsc             C   s5   d } d
 d d d d d d g } |  j  | |  d  S)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    I'm a valid comment me too!--rg   --I have many hyphens-- I have a > in the middle  and I have -- in the middle! )commentr   )r   r   )r   r   )r   rg   )r   r   )r   r   )r   r   )r;   )r
   r   expectedr   r   r   test_comments?  s    	z HTMLParserTestCase.test_commentsc             C   s)   d } d d d g } |  j  | |  d  S)	Nzs<!--[if IE & !(lte IE 8)]>aren't<![endif]--><!--[if IE 8]>condcoms<![endif]--><!--[if lte IE 7]>pretty?<![endif]-->r   %[if IE & !(lte IE 8)]>aren't<![endif][if IE 8]>condcoms<![endif][if lte IE 7]>pretty?<![endif])commentr   )r   r   )r   r   )r;   )r
   r   r   r   r   r   test_condcomsP  s
    	z HTMLParserTestCase.test_condcomsc             C   s  d d   } |  j  |   j  d d d d d d g } d	 d
 d! g f d" d# g } x0 | D]( } |  j d j |  | d |   qY Wd$ d	 d
 d% d& d' g f d( d) d* g } x0 | D]( } |  j d j |  | d |   q Wx | D] } d j | g d  } d+ d	 d g  f d | f d, d- d	 d g  f d | f d. d/ g	 } |  j d j | |  | d |   q Wd } xS t d t |   D]< } |  j | d  |  d | d  |  f g d |   qW|  j d  d0 g d |   d  S)1Nc               S   s   t    S)N)r/   r   r   r   r   <lambda>[  s    z:HTMLParserTestCase.test_convert_charrefs.<locals>.<lambda>z&quot;z&#34;z&#x22;z&quotz&#34z&#x22r   r[   hreffoo"zarr   a"zr   z<a href="foo{0}zar">a{0}z</a>r9   "xy"XzX"z*{0}<a x="{0}" y="{0}X" z="X{0}">{0}</a>{0}X   rs   rt   z/{1}<script>{0}</script>{1}<style>{0}</style>{1}z&quo &# &#xr   no charrefs here)r   r   )datar   )endtagr[   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r[   )r   r   )r   r   )r   zscript)r   r   )r   zstyle)r   r   )r   r   )Z
assertTruer2   r;   rx   joinrangelen)r
   r9   Zcharrefsr   r    textr   r   r   r   r   test_convert_charrefsY  s>    	,z(HTMLParserTestCase.test_convert_charrefsc             C   sG   |  j  d d d d g f d d d d d
 d g f d d d d g	  d  S)NzF<html <html>te>>xt&a<<bc</a></html>
<img src="URL><//img></html</html>r   r   <htmlr   te>>xtr%   r[   rc   zbc<r   
<img src="URL>r   /imghtml<)r   N)datar   )z	entityrefr[   )r   rc   )r[   N)endtagzhtml)r   r   )zcommentr   )r   r   )r;   )r
   r   r   r   test_tolerant_parsing  s    	z(HTMLParserTestCase.test_tolerant_parsingc             C   sz  |  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  d  S)%Nz</>z</$>r   $</r   </az<a<a>r   a<az</a<a>r   <!<a<a foo='bar'<a foo='bar
<a foo='>'	<a foo='>z<a$>za$z<a$b>za$bz<a$b/>r   z<a$b  >z<a$b  />)zcommentr   )datar   )r   r   )zendtagr   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r;   )r
   r   r   r   test_starttag_junk_chars  s"    z+HTMLParserTestCase.test_starttag_junk_charsc             C   s%  |  j  d d d d g f g  d } d d d d d d d d d  d! g f g } |  j  | |  d } d d d" d# d$ g f d d d% d& d' g 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  | |  d  S)(Nz<a foo="var"/>r   r[   rk   varzj<img width=902 height=250px src="/sites/default/files/images/homepage/foo.jpg" /*what am I doing here*/ />rG   width902height250pxrH   ,/sites/default/files/images/homepage/foo.jpg*whatamidoinghere*z9<a / /foo/ / /=/ / /bar/ / /><a / /foo/ / /=/ / /bar/ / >=barr   zD<meta><meta / ><meta // ><meta / / ><meta/><meta /><meta //><meta//>meta)foozvar)zwidthr   )r   r   )zsrcr   )r   N)zamN)r   N)r   N)r   N)r   N)r   N)r   N)r   N)r   N)r   N)r;   )r
   r   r   r   r   r   test_slashes_in_starttag  s$    	z+HTMLParserTestCase.test_slashes_in_starttagc             C   s   |  j  d d g  d  S)Nz<!DOCTYPE foo $ >r#   DOCTYPE foo $ )zdeclr   )r;   )r
   r   r   r   test_declaration_junk_chars  s    z.HTMLParserTestCase.test_declaration_junk_charsc             C   s   |  j  d d g  d  S)Nz"<!spacer type="block" height="25">r   spacer type="block" height="25")zcommentr   )r;   )r
   r   r   r   test_illegal_declarations  s    	z,HTMLParserTestCase.test_illegal_declarationsc             C   s   d } d d g  f d d d# d$ g f d d	 d% d& d' g 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/ d0 d d d1 g f d d d2 g f d3 d4 d5 d6 g } |  j  | |  d  S)7Nz<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   Zbodybgcolord0ca90r   181008tablecellspacing0cellpaddingro   r   100%trZtdalignleftZfontsize-1r   - r[   r   /rabota/spanclassen software-and-ir   /1/ library)r   r   )ztextr   )r   r   )r   ro   )zwidthr   )r   zleft)zsizer   )datar   )hrefr   )classen)r   r   )endtagspan)r   r[   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r[   )r   ztable)r;   )r
   r   r   r   r   r   test_with_unquoted_attributes  s    z0HTMLParserTestCase.test_with_unquoted_attributesc             C   s)   |  j  d d d d	 d
 d g f g  d  S)Nz7<form action="/xxx.php?a=1&amp;b=2&amp", method="post">r   formaction/xxx.php?a=1&b=2&,methodpost)zactionr   )r   N)zmethodr   )r;   )r
   r   r   r   test_comma_between_attributes  s    	z0HTMLParserTestCase.test_comma_between_attributesc             C   s#   |  j  d d d d g f g  d  S)Nz<form action=bogus|&#()value>r   r   r   bogus|&#()value)zactionr   )r;   )r
   r   r   r   -test_weird_chars_in_unquoted_attribute_values  s    	z@HTMLParserTestCase.test_weird_chars_in_unquoted_attribute_valuesc             C   s   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  | |  d  S)Nzn<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br></li class="unit"><br></li
						</ul><br></><br>r   brr   label<rT   r   <h4li)endtagr   )r   zdiv)zcommentr   )r   r   )r   r   )r;   )r
   r   r   r   r   r   test_invalid_end_tags  s    z(HTMLParserTestCase.test_invalid_end_tagsc             C   s5   d } d d g  f d d	 d
 g } |  j  | |  d  S)Nz(<b>This</b attr=">"> confuses the parserr   r\   r   Thisr   "> confuses the parser)datar   )zendtagr\   )r   r   )r;   )r
   r   r   r   r   r   test_broken_invalid_end_tag  s    	z.HTMLParserTestCase.test_broken_invalid_end_tagc             C   s   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 d# d$ d% g f d d g  f d& d d	 d' g f d( d) g } |  j  | |  d  S)*Nz[<div style=""    ><b>The <a href="some_url">rain</a> <br /> in <span>Spain</span></b></div>r   rT   rt   rg   r\   r   The r[   r   some_urlrainr    r   r    in r   Spainz><div style="", foo = "bar" ><b>The <a href="some_url">rain</a>r   rk   r   )stylerg   )datar   )hrefr   )r   r   )endtagr[   )r   r   )r   r   )r   r   )r  zspan)r  r\   )r  zdiv)r   rg   )r   N)zfoozbar)r   r   )r  r   )r   r   )r  r[   )r;   )r
   r   r   r   r   r   $test_correct_detection_of_start_tags  s0    		z7HTMLParserTestCase.test_correct_detection_of_start_tagsc             C   sj   d d g f d d g f d d d d g f d
 d d g f g } x$ | D] \ } } |  j  | |  qF Wd  S)Na&r   za&babza&b r[   r%   r\   r   za&b;)datar  )r  zab)r  r[   )	entityrefr\   )r  r   )r  r[   )r  r\   )r;   )r
   r   r   r   r   r   r   test_EOF_in_charref3  s    z&HTMLParserTestCase.test_EOF_in_charrefc             C   s\   d d l  m } |  j   } |  j t  * d } |  j | j |  | |   Wd  QRXd  S)Nr   )unescapez%&quot;&#34;&#x22;&quot&#34&#x22&#bad;)r   r	  r3   ZassertWarnsDeprecationWarningassertEqual)r
   r	  rR   r:   r   r   r   test_unescape_methodA  s
    z'HTMLParserTestCase.test_unescape_methodc             C   s2   d } d	 d
 d d d d g } |  j  | |  d  S)Nz<! not really a comment ><! not a comment either --><! -- close enough --><!><!<-- this was an empty comment><!!! another bogus comment !!!>r    not really a comment  not a comment either -- -- close enough --rg   <-- this was an empty comment!! another bogus comment !!!)commentr  )r  r  )r  r  )r  rg   )r  r  )r  r  )r;   )r
   r   r   r   r   r   test_broken_commentsH  s    	z'HTMLParserTestCase.test_broken_commentsc             C   s   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  | |  d  S)'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]>unknown declif !(IE)r   broken condcomendifif ! IEr   linkr   favicon.tiffif !IE 6rG   rH   firefox.pngif !ie 6r   r\   rk   r   if (!IE)|(lt IE 9)mammoth.bmp)r  r  )datar  )r  r  )r  r  )zhrefr  )r  r  )r  r  )srcr  )r  r  )r  r  )r   zfoo)zendtagr\   )r  r  )r  r  )r!  r  )r  r  )r;   )r
   r   r   r   r   r   test_broken_condcomsX  s&    	z'HTMLParserTestCase.test_broken_condcomsc             C   sN   t  d d  } | j d  |  j | j   d d d g  f d d d g  d  S)Nr2   Tzfoo <a>link</a> bar &amp; bazr   foo r   r[   r  r   
 bar & baz)datar#  )r%  zlink)zendtagr[   )r%  r$  )r   r4   r  r   )r
   r   r   r   r   "test_convert_charrefs_dropped_texty  s    	z5HTMLParserTestCase.test_convert_charrefs_dropped_textN)$r*   r+   r,   rA   rQ   rW   rZ   r^   r`   rb   re   ri   rj   rm   rr   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=   j   sB    	)!!r=   c               @   s   e  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 d   Z d d   Z d d   Z d d   Z d d   Z d S)AttributesTestCasec             C   sb   d d d d d d g f g } |  j  d |  |  j  d	 |  |  j  d
 |  |  j  d |  d  S)Nr   r[   r\   vcdez<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>)r\   r(  )r)  r(  )r*  r(  )r+  N)r;   )r
   rh   r   r   r   test_attr_syntax  s
    z#AttributesTestCase.test_attr_syntaxc             C   s   |  j  d 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  d  S)Nz'<a b='xxx
	xxx' c="yyy	
yyy" d='	xyz
'>r   r[   r\   xxx
	xxxr)  yyy	
yyyr*  	xyz
z<a b='' c="">rg   z<e a=rgb(1,2,3)>r+  
rgb(1,2,3)z<a href=mailto:xyz@example.com>r   mailto:xyz@example.com)r\   r-  )r)  r.  )r*  r/  )r\   rg   )r)  rg   )r[   r0  )zhrefr1  )r;   )r
   r   r   r   test_attr_values  s    				z#AttributesTestCase.test_attr_valuesc             C   sj   |  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  d  S)Nu!   <img src=/foo/bar.png alt=中文>r   rG   rH   /foo/bar.pngalt   中文u+   <a title='テスト' href='テスト.html'>r[   title	   テストr      テスト.htmlu+   <a title="テスト" href="テスト.html">)zsrcr3  )r4  r5  )titler7  )hrefr8  )r9  r7  )r:  r8  )r;   )r
   r   r   r   test_attr_nonascii  s    			z%AttributesTestCase.test_attr_nonasciic             C   s#   |  j  d d d d g f g  d  S)Nz!<a b='&amp;&gt;&lt;&quot;&apos;'>r   r[   r\   &><"')r\   r<  )r;   )r
   r   r   r   test_attr_entity_replacement  s    z/AttributesTestCase.test_attr_entity_replacementc             C   s)   |  j  d d d d d	 d
 g f g  d  S)Nz<a a.b='v' c:d=v e-f=v>r   r[   a.br(  c:de-f)r>  r(  )r?  r(  )r@  r(  )r;   )r
   r   r   r   test_attr_funky_names  s    z(AttributesTestCase.test_attr_funky_namesc             C   s#   |  j  d d d d g f g  d  S)Nz0<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>r   r   rk      €&aa&unsupported;)zfoorB  )r;   )r
   r   r   r   test_entityrefs_in_attributes  s    z0AttributesTestCase.test_entityrefs_in_attributesc             C   sA   |  j  d d d d
 g f d d d g f d d d g f g  d  S)Nz<a $><b $=%><c \=/>r   r[   r   r\   %r)  \/)r   N)r   rD  )rE  rF  )r;   )r
   r   r   r   test_attr_funky_names2  s
    z)AttributesTestCase.test_attr_funky_names2c             C   s   x d d d d g D]o } |  j  d | d d d g f g  |  j  d	 | d d d g f g  |  j  d
 | d d d g f g  q Wd  S)N&z&amp;z&#38;z&#x26;z<a href="%s">r   r[   r   z<a href='%s'>z<a href=%s>)hrefrH  )rI  rH  )rI  rH  )r;   )r
   rD   r   r   r    test_entities_in_attribute_value  s    z3AttributesTestCase.test_entities_in_attribute_valuec             C   st   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  | |  d  S)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   test'style='color:red;bad1'r   test - bad1r   test'+style='color:red;ba2'test - bad2   test' style='color:red;bad3'test - bad3   test' style='color:red;bad4'test - bad4)hrefrK  )datarL  )endtagr[   )rS  rM  )rT  rN  )rU  r[   )rS  rO  )rT  rP  )rU  r[   )rS  rQ  )rT  rR  )rU  r[   )r;   )r
   r   r   r   r   r   test_malformed_attributes  s    z,AttributesTestCase.test_malformed_attributesc             C   sf   |  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  d  S)Nz<x><y z=""o"" /></x>r   r   r   r   r   rg   o""r   z<x><y z="""" /></x>"")r   rg   )rW  N)endtagr   )r   rg   )rX  N)rY  r   )r;   )r
   r   r   r   "test_malformed_adjacent_attributes  s    	
	z5AttributesTestCase.test_malformed_adjacent_attributesc             C   sH   |  j  d d d d d g f g  |  j  d d d d d g f g  d  S)Nz<a width="100%"cellspacing=0>r   r[   r   100%r   r   z<a id="foo"class="bar">idrk   r   r   )zwidthr[  )zcellspacingr   )zidzfoo)zclasszbar)r;   )r
   r   r   r   test_adjacent_attributes  s    		z+AttributesTestCase.test_adjacent_attributesc             C   s#   |  j  d d d d g f g  d  S)Nz<a v=>r   r[   r(  rg   )r(  rg   )r;   )r
   r   r   r   test_missing_attribute_value  s    	z/AttributesTestCase.test_missing_attribute_valuec             C   s#   |  j  d d d d g f g  d  S)Nz-<a href=javascript:popup('/popup/help.html')>r   r[   r   $javascript:popup('/popup/help.html'))zhrefr_  )r;   )r
   r   r   r   test_javascript_attribute_value  s    	z2AttributesTestCase.test_javascript_attribute_valuec             C   s)   |  j  d d d d	 g f d
 d g  d  S)Nz-<a href='http://www.example.org/">;'>spam</a>r   r[   r   http://www.example.org/">;r   spamr   )zhrefra  )zdatarb  )zendtagr[   )r;   )r
   r   r   r   test_end_tag_in_attribute_value  s    		z2AttributesTestCase.test_end_tag_in_attribute_valueN)r*   r+   r,   r,  r2  r;  r=  rA  rC  rG  rJ  rV  rZ  r]  r^  r`  rc  r   r   r   r   r'    s   	
	r'  __main__)__doc__Zhtml.parserr   r7   Zunittesttestr   r   r   r   r-   r/   ZTestCaser1   r=   r'  r*   mainr   r   r   r   <module>   s   9	  