B
    u9aº  ã               @   s–   d Z ddlZddlZddlZG dd„ dejjƒZG dd„ deƒZG dd„ deƒZ	G d	d
„ d
ej
ƒZG dd„ deƒZG dd„ deƒZedkr’e ¡  dS )zTests for HTMLParser.py.é    Nc               @   sl   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   s*   g | _ | j j| _tjjj| f|ž|Ž d S )N)ÚeventsÚappendÚhtmlÚparserÚ
HTMLParserÚ__init__)ÚselfÚargsÚkw© r   ú%/usr/lib/python3.7/test_htmlparser.pyr   
   s    
zEventCollector.__init__c             C   sn   g }d }xZ| j D ]P}|d }||  kr0dkrRn nd|d d |d  f|d< n
| |¡ |}qW || _ |S )Nr   Údataéÿÿÿÿé   )r   r   )r	   ÚLZprevtypeZeventÚtyper   r   r   Ú
get_events   s    
zEventCollector.get_eventsc             C   s   |   d||f¡ d S )NÚstarttag)r   )r	   ÚtagÚattrsr   r   r   Úhandle_starttag    s    zEventCollector.handle_starttagc             C   s   |   d||f¡ d S )NÚstartendtag)r   )r	   r   r   r   r   r   Úhandle_startendtag#   s    z!EventCollector.handle_startendtagc             C   s   |   d|f¡ d S )NÚendtag)r   )r	   r   r   r   r   Úhandle_endtag&   s    zEventCollector.handle_endtagc             C   s   |   d|f¡ d S )NÚcomment)r   )r	   r   r   r   r   Úhandle_comment+   s    zEventCollector.handle_commentc             C   s   |   d|f¡ d S )NÚcharref)r   )r	   r   r   r   r   Úhandle_charref.   s    zEventCollector.handle_charrefc             C   s   |   d|f¡ d S )Nr   )r   )r	   r   r   r   r   Úhandle_data1   s    zEventCollector.handle_datac             C   s   |   d|f¡ d S )NÚdecl)r   )r	   r   r   r   r   Úhandle_decl4   s    zEventCollector.handle_declc             C   s   |   d|f¡ d S )NÚ	entityref)r   )r	   r   r   r   r   Úhandle_entityref7   s    zEventCollector.handle_entityrefc             C   s   |   d|f¡ d S )NÚpi)r   )r	   r   r   r   r   Ú	handle_pi:   s    zEventCollector.handle_pic             C   s   |   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   s$   t  | ||¡ |  d|  ¡ f¡ d S )NÚstarttag_text)r   r   r   Zget_starttag_text)r	   r   r   r   r   r   r   C   s    z#EventCollectorExtra.handle_starttagN)r(   r)   r*   r   r   r   r   r   r+   A   s   r+   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚEventCollectorCharrefsc             C   s   |   d¡ d S )Nz6This should never be called with convert_charrefs=True)Úfail)r	   r   r   r   r   r   J   s    z%EventCollectorCharrefs.handle_charrefc             C   s   |   d¡ d S )Nz6This should never be called with convert_charrefs=True)r.   )r	   r   r   r   r   r$   M   s    z'EventCollectorCharrefs.handle_entityrefN)r(   r)   r*   r   r$   r   r   r   r   r-   H   s   r-   c               @   s&   e Zd Zdd„ Zddd„Zdd„ ZdS )	ÚTestCaseBasec             C   s
   t ddS )NF)Úconvert_charrefs)r   )r	   r   r   r   Úget_collectorS   s    zTestCaseBase.get_collectorNc             C   sv   |d kr|   ¡ }|}x|D ]}| |¡ qW | ¡  | ¡ }||krr|  dt|ƒ d t |¡ d t |¡ ¡ d S )Nz6received events did not match expected events
Source:
z
Expected:
z
Received:
)r1   ÚfeedÚcloser   r.   ÚreprÚpprintZpformat)r	   ÚsourceZexpected_eventsÚ	collectorr   Úsr   r   r   r   Ú
_run_checkV   s    
zTestCaseBase._run_checkc             C   s   |   ||tdd¡ d S )NF)r0   )r9   r+   )r	   r6   r   r   r   r   Ú_run_check_extrad   s    zTestCaseBase._run_check_extra)N)r(   r)   r*   r1   r9   r:   r   r   r   r   r/   Q   s   
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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d1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCS )DÚHTMLParserTestCasec             C   s    |   ddg¡ |   ddg¡ d S )Nz<?processing instruction>)r%   zprocessing instructionz<?processing instruction ?>)r%   zprocessing instruction ?)r9   )r	   r   r   r   Ú test_processing_instruction_onlyk   s    z3HTMLParserTestCase.test_processing_instruction_onlyc             C   sB   |   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!   zDOCTYPE html PUBLIC 'foo'r   r   )r#   Úentity)r   Z32)r   z4comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1bÚimg)ÚsrcZBar)ZismapN)r   zsample
text
)r   Zx201C)r   zcomment2a-- --comment2b)r   r   )r9   )r	   r   r   r   Útest_simple_htmls   s&    z#HTMLParserTestCase.test_simple_htmlc             C   s6   |   dddg fddg¡ |   dgddg fddg¡ d S )	Nz<p>&#bad;</p>r   Úp)r   z&#bad;)r   rB   z<div>&#bad;</div>Údiv)r   rC   )r9   )r	   r   r   r   Útest_malformatted_charref“   s    z,HTMLParserTestCase.test_malformatted_charrefc             C   s   |   dddg¡ d S )Nz&entityref foo)r#   r#   )r   z foo)r9   )r	   r   r   r   Útest_unclosed_entityref    s    z*HTMLParserTestCase.test_unclosed_entityrefc             C   s$   |   dddg fddg fddg¡ d S )Nz<a><b></a></b>r   ÚaÚb)r   rF   )r   rG   )r9   )r	   r   r   r   Útest_bad_nesting¦   s
    z#HTMLParserTestCase.test_bad_nestingc             C   s   |   ddg¡ d S )Nz#this text & contains & ampersands &)r   z#this text & contains & ampersands &)r9   )r	   r   r   r   Útest_bare_ampersands±   s    z'HTMLParserTestCase.test_bare_ampersandsc             C   s   |   ddg¡ d S )Nz.this < text > contains < bare>pointy< brackets)r   z.this < text > contains < bare>pointy< brackets)r9   )r	   r   r   r   Útest_bare_pointy_brackets¶   s    z,HTMLParserTestCase.test_bare_pointy_bracketsc             C   s0   |   ddddgfg¡ |   ddddgfg¡ d S )Nz	<a b='<'>r   rF   )rG   ú<z	<a b='>'>)rG   ú>)r9   )r	   r   r   r   Útest_starttag_end_boundary»   s    z-HTMLParserTestCase.test_starttag_end_boundaryc             C   s’  dddgfg}|   dg|¡ |   ddg|¡ |   ddg|¡ |   d	d
g|¡ |   ddg|¡ |   ddg|¡ dddgfg}|   dg|¡ |   ddg|¡ |   ddg|¡ |   d	dg|¡ |   ddg|¡ |   ddg|¡ dg}|   ddg|¡ |   ddg|¡ |   ddg|¡ |   ddg|¡ |   dd g|¡ |   d!d"g|¡ |   d#d$g|¡ |   d%d&g|¡ |   d'd(g|¡ |   d)dg|¡ |   ddg|¡ d S )*Nr   rF   )rG   rK   z	<a b='<'>z<a zb='<'>z<a bz='<'>z<a b=z'<'>z<a b='<z'>z<a b='<'rL   )rG   rL   z	<a b='>'>zb='>'>z='>'>z'>'>z<a b='>z<a b='>')r   ÚabcÚ z
<!--abc-->rK   z	!--abc-->z<!z--abc-->z<!-z-abc-->z<!--zabc-->z<!--azbc-->z<!--abzc-->z<!--abcz-->z<!--abc-z->z	<!--abc--)r9   )r	   Úoutputr   r   r   Útest_buffer_artefacts¿   s4    z(HTMLParserTestCase.test_buffer_artefactsc          
   C   sD   ddddddddd	d
g
}x&|D ]}|   d| dd| fg¡ qW d 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"z‚html 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 )r9   )r	   ZdtdsZdtdr   r   r   Útest_valid_doctypesÝ   s    

z&HTMLParserTestCase.test_valid_doctypesc             C   sN   |   dddg fg¡ |   dddg fdg¡ |   dddg fddd	gfdg¡ d S )
Nz<p/>r   rB   z<p></p>r   )r   rB   z<p><img src='foo' /></p>r?   )r@   Úfoo)r9   )r	   r   r   r   Útest_startendtagõ   s    
z#HTMLParserTestCase.test_startendtagc             C   s&   d}|   |ddddgfd|fg¡ d S )Nz <foo:bar   
   one="1"	two=2   >r   zfoo:bar)ZoneÚ1)ZtwoÚ2r,   )r:   )r	   r8   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}xP|D ]H}xB|D ]:}|  ¡ }dj||d}|  |d|g fd|fd|fg¡ q:W q0W d 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Úformatr9   )r	   ÚcontentsÚelementsr[   rZ   Úelement_lowerr8   r   r   r   Útest_cdata_content	  s(    

z%HTMLParserTestCase.test_cdata_contentc             C   sj   G dd„ dt ƒ}d}xPdD ]H}| ¡  ¡ }dj||d}| j|d|g fd|fd	|fg|d
dd qW d 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   rb   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}>)rZ   r[   r   r   r   F)r0   )r7   )r   r\   Ústripr]   r9   )r	   rb   r[   rZ   r`   r8   r   r   r   Útest_cdata_with_closing_tags(  s    
z/HTMLParserTestCase.test_cdata_with_closing_tagsc             C   s&   d}dddddddg}|   ||¡ 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   z I'm a valid comment )r   zme too!)r   z--)r   rO   )r   z--I have many hyphens--)r   z I have a > in the middle )r   z and I have -- in the middle! )r9   )r	   r   Úexpectedr   r   r   Útest_comments>  s    z HTMLParserTestCase.test_commentsc             C   s   d}dddg}|   ||¡ d S )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])r9   )r	   r   re   r   r   r   Útest_condcomsO  s
    z HTMLParserTestCase.test_condcomsc          
   C   s^  dd„ }|   |ƒ j¡ ddddddg}d	d
dgfddg}x$|D ]}| jd |¡||ƒ d q>W dd	d
dddgfdddg}x$|D ]}| jd |¡||ƒ d q~W x`|D ]X}d |gd ¡}dd	dg fd|fddd	dg fd|fddg	}| jd ||¡||ƒ d q¤W d}x@tdt|ƒƒD ].}| j|d |… d|d |… fg|ƒ d qW | jdd g|ƒ d d S )!Nc               S   s   t ƒ S )N)r-   r   r   r   r   Ú<lambda>Z  ó    z:HTMLParserTestCase.test_convert_charrefs.<locals>.<lambda>z&quot;z&#34;z&#x22;z&quotz&#34z&#x22r   rF   )Úhrefzfoo"zar)r   za"z)r   rF   z<a href="foo{0}zar">a{0}z</a>)r7   )r   ú")Úxrk   )Úyz"X)ÚzzX"z*{0}<a x="{0}" y="{0}X" z="X{0}">{0}</a>{0}ÚXé   rX   r   )r   rX   rY   )r   rY   z/{1}<script>{0}</script>{1}<style>{0}</style>{1}z&quo &# &#xr   zno charrefs here)r   zno charrefs here)Z
assertTruer0   r9   r]   ÚjoinÚrangeÚlen)r	   r7   Zcharrefsre   r   Útextr   rl   r   r   r   Útest_convert_charrefsX  s>    





z(HTMLParserTestCase.test_convert_charrefsc             C   s2   |   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   )z<htmlN)r   zte>>xt)r#   rF   )r   rK   zbc<)rF   N)r   r   )r   z
<img src="URL>)r   z/img)r   zhtml<)r9   )r	   r   r   r   Útest_tolerant_parsing  s    

z(HTMLParserTestCase.test_tolerant_parsingc             C   s  |   dg ¡ |   ddg¡ |   ddg¡ |   ddg¡ |   dd	d
g fg¡ |   ddg¡ |   ddg¡ |   ddg¡ |   ddg¡ |   ddg¡ |   ddg¡ |   ddg¡ |   dd	dg fg¡ |   dd	dg fg¡ |   dddg fg¡ |   dd	dg fg¡ |   d ddg fg¡ d S )!Nz</>z</$>)r   ú$z</)r   z</z</a)r   z</az<a<a>r   za<az</a<a>)r   za<az<!)r   z<!z<a)r   z<az<a foo='bar')r   z<a foo='bar'z<a foo='bar)r   z<a foo='barz
<a foo='>')r   z
<a foo='>'z	<a foo='>)r   z	<a foo='>z<a$>za$z<a$b>za$bz<a$b/>r   z<a$b  >z<a$b  />)r9   )r	   r   r   r   Útest_starttag_junk_charsŽ  s"    z+HTMLParserTestCase.test_starttag_junk_charsc          
   C   sÊ   |   ddddgfg¡ d}ddddd	d
ddddgfg}|   ||¡ d}dddddgfdddddgfg}|   ||¡ 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}|   ||¡ d S )Nz<a foo="var"/>r   rF   )rS   Úvarzj<img width=902 height=250px src="/sites/default/files/images/homepage/foo.jpg" /*what am I doing here*/ />r?   )ÚwidthZ902)ZheightZ250px)r@   z,/sites/default/files/images/homepage/foo.jpg)z*whatN)ÚamN)ÚiN)ZdoingN)zhere*Nz9<a / /foo/ / /=/ / /bar/ / /><a / /foo/ / /=/ / /bar/ / >)rS   N)ú=N)ÚbarNr   zD<meta><meta / ><meta // ><meta / / ><meta/><meta /><meta //><meta//>Úmeta)r9   )r	   r   re   r   r   r   Útest_slashes_in_starttag¡  s$    z+HTMLParserTestCase.test_slashes_in_starttagc             C   s   |   ddg¡ d S )Nz<!DOCTYPE foo $ >)r!   zDOCTYPE foo $ )r9   )r	   r   r   r   Útest_declaration_junk_charsÀ  s    z.HTMLParserTestCase.test_declaration_junk_charsc             C   s   |   ddg¡ d S )Nz"<!spacer type="block" height="25">)r   zspacer type="block" height="25")r9   )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ddddgfdddgfddddg}|   ||¡ d S )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   Zbody)ZbgcolorZd0ca90)rt   Z181008Útable)ÚcellspacingÚ0)ZcellpaddingrU   )rz   z100%ÚtrZtd)ZalignÚleftZfont)Úsizez-1)r   z- rF   )rj   z/rabota/Úspan)ÚclassÚen)r   z software-and-i)r   r‰   )r   rF   )rj   z/1/)r   z library)r   rƒ   )r9   )r	   r   re   r   r   r   Útest_with_unquoted_attributesÇ  s    



z0HTMLParserTestCase.test_with_unquoted_attributesc             C   s   |   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)Úactionz/xxx.php?a=1&b=2&)ú,N)ÚmethodZpost)r9   )r	   r   r   r   Útest_comma_between_attributesß  s    z0HTMLParserTestCase.test_comma_between_attributesc             C   s   |   ddddgfg¡ d S )Nz<form action=bogus|&#()value>r   r   )rŽ   zbogus|&#()value)r9   )r	   r   r   r   Ú-test_weird_chars_in_unquoted_attribute_valuesæ  s    z@HTMLParserTestCase.test_weird_chars_in_unquoted_attribute_valuesc             C   sZ   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}|   ||¡ d S )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   rC   )r   z<h4)r   Zli)r9   )r	   r   re   r   r   r   Útest_invalid_end_tagsë  s    z(HTMLParserTestCase.test_invalid_end_tagsc             C   s&   d}ddg fdddg}|   ||¡ d S )Nz(<b>This</b attr=">"> confuses the parserr   rG   )r   ZThis)r   rG   )r   z"> confuses the parser)r9   )r	   r   re   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}|   ||¡ d}dddddgfddg fddddgfd	d
g}|   ||¡ d S )Nz[<div style=""    ><b>The <a href="some_url">rain</a> <br /> in <span>Spain</span></b></div>r   rC   )rY   rO   rG   )r   zThe rF   )rj   Zsome_url)r   Zrain)r   rF   )r   ú r   r“   )r   z in r‰   )r   ZSpain)r   r‰   )r   rG   )r   rC   z><div style="", foo = "bar" ><b>The <a href="some_url">rain</a>)r   N)rS   r~   )r9   )r	   r   re   r   r   r   Ú$test_correct_detection_of_start_tags  s0    


z7HTMLParserTestCase.test_correct_detection_of_start_tagsc             C   sL   ddgfddgfddddgfd	ddgfg}x|D ]\}}|   ||¡ q0W d S )
Nza&)r   za&za&b)r   Zabza&b )r   rF   )r#   rG   )r   r–   za&b;)r9   )r	   r   r   re   r   r   r   Útest_EOF_in_charref2  s    z&HTMLParserTestCase.test_EOF_in_charrefc          	   C   sH   ddl m} |  ¡ }|  t¡  d}|  | |¡||ƒ¡ W d Q R X d S )Nr   )Úunescapez%&quot;&#34;&#x22;&quot&#34&#x22&#bad;)r   r™   r1   ZassertWarnsÚDeprecationWarningÚassertEqual)r	   r™   rB   r8   r   r   r   Útest_unescape_method@  s
    z'HTMLParserTestCase.test_unescape_methodc             C   s$   d}ddddddg}|   ||¡ d S )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   rO   )r   z<-- this was an empty comment)r   z!! another bogus comment !!!)r9   )r	   r   re   r   r   r   Útest_broken_commentsG  s    z'HTMLParserTestCase.test_broken_commentsc             C   sX   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}|   ||¡ 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]>)zunknown declzif !(IE))r   zbroken condcom)zunknown declZendif)zunknown declzif ! IEr   Úlink)rj   zfavicon.tiff)zunknown declzif !IE 6r?   )r@   zfirefox.png)zunknown declzif !ie 6r   rG   )r   rS   )r   rG   )zunknown declzif (!IE)|(lt IE 9))r@   zmammoth.bmp)r9   )r	   r   re   r   r   r   Útest_broken_condcomsW  s&    


z'HTMLParserTestCase.test_broken_condcomsc             C   s8   t dd}| d¡ |  | ¡ dddg fddd	g¡ d S )
NT)r0   zfoo <a>link</a> bar &amp; baz)r   zfoo r   rF   )r   rž   )r   rF   )r   z
 bar & baz)r   r2   r›   r   )r	   r   r   r   r   Ú"test_convert_charrefs_dropped_textx  s    

z5HTMLParserTestCase.test_convert_charrefs_dropped_textN)$r(   r)   r*   r<   rA   rD   rE   rH   rI   rJ   rM   rQ   rR   rT   rW   ra   rd   rf   rg   ru   rv   rx   r€   r   r‚   rŒ   r‘   r’   r”   r•   r—   r˜   rœ   r   rŸ   r    r   r   r   r   r;   i   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   sH   ddddddgfg}|   d|¡ |   d|¡ |   d	|¡ |   d
|¡ d S )Nr   rF   )rG   Ú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>)r9   )r	   rP   r   r   r   Útest_attr_syntax‡  s
    z#AttributesTestCase.test_attr_syntaxc             C   sb   |   ddddddgfg¡ |   ddddd	gfg¡ |   d
dddgfg¡ |   ddddgfg¡ d S )Nz'<a b='xxx
	xxx' c="yyy	
yyy" d='	xyz
'>r   rF   )rG   zxxx
	xxx)r£   zyyy	
yyy)r¤   z	xyz
z<a b='' c="">)rG   rO   )r£   rO   z<e a=rgb(1,2,3)>r¥   )rF   z
rgb(1,2,3)z<a href=mailto:xyz@example.com>)rj   zmailto:xyz@example.com)r9   )r	   r   r   r   Útest_attr_values  s    z#AttributesTestCase.test_attr_valuesc             C   sL   |   dddddgfg¡ |   ddddd	gfg¡ |   d
dddd	gfg¡ d S )Nu!   <img src=/foo/bar.png alt=ä¸­æ–‡>r   r?   )r@   z/foo/bar.png)Zaltu   ä¸­æ–‡u+   <a title='ãƒ†ã‚¹ãƒˆ' href='ãƒ†ã‚¹ãƒˆ.html'>rF   )Útitleu	   ãƒ†ã‚¹ãƒˆ)rj   u   ãƒ†ã‚¹ãƒˆ.htmlu+   <a title="ãƒ†ã‚¹ãƒˆ" href="ãƒ†ã‚¹ãƒˆ.html">)r9   )r	   r   r   r   Útest_attr_nonasciiŸ  s    z%AttributesTestCase.test_attr_nonasciic             C   s   |   ddddgfg¡ d S )Nz!<a b='&amp;&gt;&lt;&quot;&apos;'>r   rF   )rG   z&><"')r9   )r	   r   r   r   Útest_attr_entity_replacement®  s    z/AttributesTestCase.test_attr_entity_replacementc             C   s   |   ddddddgfg¡ d S )Nz<a a.b='v' c:d=v e-f=v>r   rF   )za.br¢   )zc:dr¢   )ze-fr¢   )r9   )r	   r   r   r   Útest_attr_funky_names³  s    z(AttributesTestCase.test_attr_funky_namesc             C   s   |   ddddgfg¡ d S )Nz0<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>r   r   )rS   u   â‚¬&aa&unsupported;)r9   )r	   r   r   r   Útest_entityrefs_in_attributes¸  s    z0AttributesTestCase.test_entityrefs_in_attributesc             C   s.   |   ddddgfdddgfdddgfg¡ d S )	Nz<a $><b $=%><c \=/>r   rF   )rw   NrG   )rw   ú%r£   )ú\ú/)r9   )r	   r   r   r   Útest_attr_funky_names2¾  s
    

z)AttributesTestCase.test_attr_funky_names2c             C   s`   xZdD ]R}|   d| dddgfg¡ |   d| dddgfg¡ |   d| dddgfg¡ qW d S )N)ú&z&amp;z&#38;z&#x26;z<a href="%s">r   rF   )rj   r±   z<a href='%s'>z<a href=%s>)r9   )r	   r>   r   r   r   Ú test_entities_in_attribute_valueÅ  s    



z3AttributesTestCase.test_entities_in_attribute_valuec             C   sP   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}|   ||¡ 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   rF   )rj   ztest'style='color:red;bad1')r   ztest - bad1)r   rF   )rj   ztest'+style='color:red;ba2')r   ztest - bad2)rj   u   test'Â style='color:red;bad3')r   ztest - bad3)rj   u   test'Â style='color:red;bad4')r   ztest - bad4)r9   )r	   r   re   r   r   r   Útest_malformed_attributesÏ  s    



z,AttributesTestCase.test_malformed_attributesc             C   sH   |   dddg fddddgfdg¡ |   d	ddg fdddd
gfdg¡ d S )Nz<x><y z=""o"" /></x>r   rl   r   rm   )rn   rO   )zo""N)r   rl   z<x><y z="""" /></x>)z""N)r9   )r	   r   r   r   Ú"test_malformed_adjacent_attributesã  s    z5AttributesTestCase.test_malformed_adjacent_attributesc             C   s4   |   dddddgfg¡ |   dddddgfg¡ d S )	Nz<a width="100%"cellspacing=0>r   rF   )rz   z100%)r„   r…   z<a id="foo"class="bar">)ÚidrS   )rŠ   r~   )r9   )r	   r   r   r   Útest_adjacent_attributesï  s    z+AttributesTestCase.test_adjacent_attributesc             C   s   |   ddddgfg¡ d S )Nz<a v=>r   rF   )r¢   rO   )r9   )r	   r   r   r   Útest_missing_attribute_valueø  s    z/AttributesTestCase.test_missing_attribute_valuec             C   s   |   ddddgfg¡ d S )Nz-<a href=javascript:popup('/popup/help.html')>r   rF   )rj   z$javascript:popup('/popup/help.html'))r9   )r	   r   r   r   Útest_javascript_attribute_valueü  s    z2AttributesTestCase.test_javascript_attribute_valuec             C   s   |   ddddgfddg¡ d S )Nz-<a href='http://www.example.org/">;'>spam</a>r   rF   )rj   zhttp://www.example.org/">;)r   Zspam)r   rF   )r9   )r	   r   r   r   Útest_end_tag_in_attribute_value  s    z2AttributesTestCase.test_end_tag_in_attribute_valueN)r(   r)   r*   r¦   r§   r©   rª   r«   r¬   r°   r²   r³   r´   r¶   r·   r¸   r¹   r   r   r   r   r¡   …  s   	
	r¡   Ú__main__)Ú__doc__Zhtml.parserr   r5   Zunittestr   r   r   r+   r-   ZTestCaser/   r;   r¡   r(   Úmainr   r   r   r   Ú<module>   s    9	      