Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_htmlparser.cpython-34.pyo

�
g f,��@sdZddlZddlZddlZddlmZGdd�dejj�Z	Gdd�de	�Z
Gdd	�d	e	�ZGd
d�dej�Z
Gdd
�d
e
�ZGdd�de�ZGdd�de
�ZGdd�de�Zedkrej�ndS)zTests for HTMLParser.py.�N)�supportc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�EventCollectorcOs5g|_|jj|_tjjj|||�dS)N)�events�append�html�parser�
HTMLParser�__init__)�self�args�kw�r
�9/opt/alt/python34/lib64/python3.4/test/test_htmlparser.pyr	s	zEventCollector.__init__cCs�g}d}xm|jD]b}|d}||ko=dknred|dd|df|d<n
|j|�|}qW||_|S)Nr�data����r)rr)r
�LZprevtypeZevent�typer
r
r�
get_eventss
#

	zEventCollector.get_eventscCs|jd||f�dS)N�starttag)r)r
�tag�attrsr
r
r�handle_starttag!szEventCollector.handle_starttagcCs|jd||f�dS)N�startendtag)r)r
rrr
r
r�handle_startendtag$sz!EventCollector.handle_startendtagcCs|jd|f�dS)N�endtag)r)r
rr
r
r�
handle_endtag'szEventCollector.handle_endtagcCs|jd|f�dS)N�comment)r)r
rr
r
r�handle_comment,szEventCollector.handle_commentcCs|jd|f�dS)N�charref)r)r
rr
r
r�handle_charref/szEventCollector.handle_charrefcCs|jd|f�dS)Nr)r)r
rr
r
r�handle_data2szEventCollector.handle_datacCs|jd|f�dS)N�decl)r)r
rr
r
r�handle_decl5szEventCollector.handle_declcCs|jd|f�dS)N�	entityref)r)r
rr
r
r�handle_entityref8szEventCollector.handle_entityrefcCs|jd|f�dS)N�pi)r)r
rr
r
r�	handle_pi;szEventCollector.handle_picCs|jd|f�dS)Nzunknown decl)r)r
r"r
r
r�unknown_decl>szEventCollector.unknown_declN)�__name__�
__module__�__qualname__r	rrrrrr r!r#r%r'r(r
r
r
rr	src@seZdZdd�ZdS)�EventCollectorExtracCs0tj|||�|jd|j�f�dS)N�
starttag_text)rrrZget_starttag_text)r
rrr
r
rrDsz#EventCollectorExtra.handle_starttagN)r)r*r+rr
r
r
rr,Bsr,c@s(eZdZdd�Zdd�ZdS)�EventCollectorCharrefscCs|jd�dS)Nz6This should never be called with convert_charrefs=True)�fail)r
rr
r
rr Ksz%EventCollectorCharrefs.handle_charrefcCs|jd�dS)Nz6This should never be called with convert_charrefs=True)r/)r
rr
r
rr%Nsz'EventCollectorCharrefs.handle_entityrefN)r)r*r+r r%r
r
r
rr.Isr.c@sCeZdZdd�Zddd�Zdd�Zdd	�ZdS)
�TestCaseBasecCs
t�dS)N)�NotImplementedError)r
r
r
r�
get_collectorTszTestCaseBase.get_collectorNcCs�|dkr|j�}n|}x|D]}|j|�q(W|j�|j�}||kr�|jddt|�dtj|�dtj|��ndS)Nz-received events did not match expected eventsz	
Source:
z
Expected:
z
Received:
)r2�feed�closerr/�repr�pprintZpformat)r
�sourceZexpected_events�	collectorr�srr
r
r�
_run_checkWs

zTestCaseBase._run_checkcCs |j||tdd��dS)N�convert_charrefsF)r:r,)r
r7rr
r
r�_run_check_extraeszTestCaseBase._run_check_extracsR|�fdd�}�jtjj��"�jt��|�WdQXWdQXdS)Ncs'�j�}|j|�|j�dS)N)r2r3r4)r7r)r
r
r�parsejs
z(TestCaseBase._parse_error.<locals>.parse)�assertRaisesrr�HTMLParseError�assertWarns�DeprecationWarning)r
r7r=r
)r
r�_parse_erroriszTestCaseBase._parse_error)r)r*r+r2r:r<rBr
r
r
rr0Rsr0c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+S),�HTMLParserStrictTestCasecCs9tjdtfdd��tdddd�SWdQXdS)N��quiteF�strictTr;)r�check_warningsrAr)r
r
r
rr2usz&HTMLParserStrictTestCase.get_collectorcCs*|jddg�|jddg�dS)Nz<?processing instruction>r&�processing instructionz<?processing instruction ?>�processing instruction ?)�pirH)rJrI)r:)r
r
r
r� test_processing_instruction_onlyys	
	z9HTMLParserStrictTestCase.test_processing_instruction_onlycCs_|jddddddgfdddddddddgfd d!d"d#d$d%d&g�dS)'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'rrr$�entityr�32r�4comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1b�img�src�Bar�ismap�sample
text
�x201C�comment2a-- --comment2br)�datarL)zdeclrM)rXrL)z	entityrefzentity)�charrefrO)rXrL)�commentrP)rXrL)zsrcrS)rTN)rXrU)rYrV)rXrL)rZrW)rXrL)zendtagzhtml)rXrL)r:)r
r
r
r�test_simple_html�s&z)HTMLParserStrictTestCase.test_simple_htmlcCsK|jdddgfd	d
g�|jdgddgfddg�dS)
Nz
<p>&#bad;</p>r�pr�&#bad;rz<div>&#bad;</div>�div)�datar])�endtagr\)r_r])r`r^)r:)r
r
r
r�test_malformatted_charref�s	
z2HTMLParserStrictTestCase.test_malformatted_charrefcCs|jdddg�dS)Nz&entityref foor$r� foo)�	entityrefrc)zdatarb)r:)r
r
r
r�test_unclosed_entityref�s	z0HTMLParserStrictTestCase.test_unclosed_entityrefcCs2|jdddgfddgfddg�dS)Nz<a><b></a></b>r�a�br)�endtagre)rgrf)r:)r
r
r
r�test_bad_nesting�s
	z)HTMLParserStrictTestCase.test_bad_nestingcCs|jddg�dS)N�#this text & contains & ampersands &r)zdatari)r:)r
r
r
r�test_bare_ampersands�s	z-HTMLParserStrictTestCase.test_bare_ampersandscCs|jddg�dS)N�.this < text > contains < bare>pointy< bracketsr)zdatark)r:)r
r
r
r�test_bare_pointy_brackets�s	z2HTMLParserStrictTestCase.test_bare_pointy_bracketscCs|jd�dS)Nz"<!spacer type="block" height="25">)rB)r
r
r
r�test_illegal_declarations�sz2HTMLParserStrictTestCase.test_illegal_declarationscCsB|jddddgfg�|jdddd	gfg�dS)
Nz	<a b='<'>rrerf�<z	<a b='>'>�>)rfrn)rfro)r:)r
r
r
r�test_starttag_end_boundary�sz3HTMLParserStrictTestCase.test_starttag_end_boundarycCs+ddd*gfg}|jdg|�|jddg|�|jdd	g|�|jd
dg|�|jdd
g|�|jddg|�ddd+gfg}|jdg|�|jddg|�|jddg|�|jd
dg|�|jdd
g|�|jddg|�d,g}|jddg|�|jddg|�|jddg|�|jddg|�|jdd g|�|jd!d"g|�|jd#d$g|�|jd%d&g|�|jd'd(g|�|jd)dg|�|jddg|�dS)-Nrrerfrnz	<a b='<'>z<a zb='<'>z<a bz='<'>z<a b=z'<'>z<a b='<z'>z<a b='<'roz	<a b='>'>zb='>'>z='>'>z'>'>z<a b='>z<a b='>'r�abcrDz
<!--abc-->z	!--abc-->z<!z--abc-->z<!-z-abc-->z<!--zabc-->z<!--azbc-->z<!--abzc-->z<!--abcz-->z<!--abc-z->z	<!--abc--)rfrn)rfro)zcommentzabc)r:)r
�outputr
r
r�test_buffer_artefacts�s4	z.HTMLParserStrictTestCase.test_buffer_artefactscCs�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�|jd�|jd
�|jd�|jd�|jd�|jd�dS)Nz</>z</$>z</z</az<a<a>z</a<a>z<!z<az<a foo='bar'z<a foo='barz
<a foo='>'z	<a foo='>z<a$>z<a$b>z<a$b/>z<a$b  >z<a$b  />)rB)r
r
r
r�test_starttag_junk_chars�s"















z1HTMLParserStrictTestCase.test_starttag_junk_charsc
CsZddddddddd	d
g
}x/|D]'}|jd|dd
|fg�q+WdS)NZHTMLzOHTML 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"zDOCTYPE )r:)r
ZdtdsZdtdr
r
r�test_valid_doctypess	

z,HTMLParserStrictTestCase.test_valid_doctypescCs|jd�dS)Nz<!DOCTYPE foo $ >)rB)r
r
r
r�test_declaration_junk_charssz4HTMLParserStrictTestCase.test_declaration_junk_charscCsm|jdddgfg�|jdddgfdg�|jdddgfdddgfd
g�dS)Nz<p/>rr\z<p></p>rrz<p><img src='foo' /></p>rQrR�foo)�endtagr\)zsrcrw)rxr\)r:)r
r
r
r�test_startendtags		
	z)HTMLParserStrictTestCase.test_startendtagcCs5d}|j|ddd	d
gfd|fg�dS)Nz <foo:bar   
   one="1"	two=2   >rzfoo:bar�one�1�two�2r-)rzr{)r|r})r<)r
r9r
r
r�test_get_starttag_text*s	z/HTMLParserStrictTestCase.test_get_starttag_textcCs�ddddddddd	d
dg}dd
ddddg}xq|D]i}x`|D]X}|j�}djd|d|�}|j|d|gfd|fd|fg�qSWqFWdS)Nz*<!-- not a comment --> &not-an-entity-ref;z<not a='start tag'>z<a href="" /> <p> <span></span>zfoo = "</scr" + "ipt>";zfoo = "</SCRIPT" + ">";zfoo = <
/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;
// -->
zfoo = "</sty" + "le>";u<!-- ☃ -->�script�styleZSCRIPTZSTYLEZScriptZStylez <{element}>{content}</{element}>�element�contentrrr)�lower�formatr:)r
�contents�elementsr�r��
element_lowerr9r
r
r�test_cdata_content0s(	

		z+HTMLParserStrictTestCase.test_cdata_contentcCs�Gdd�dt�}d}x�dddddd	gD]m}|j�j�}d
jd|d|�}|j|d
|gfd|fd|fgd|dd��q5WdS)Nc@seZdZdd�ZdS)zHHTMLParserStrictTestCase.test_cdata_with_closing_tags.<locals>.CollectorcSs|jS)N)r)r
r
r
rrUszSHTMLParserStrictTestCase.test_cdata_with_closing_tags.<locals>.Collector.get_eventsN)r)r*r+rr
r
r
r�	CollectorTsr�z�<!-- not a comment --> &not-an-entity-ref;
                  <a href="" /> </p><p> <span></span></style>
                  '</script' + '>'z scriptzscript z script z
scriptzscript
z
script
z<script>{content}</{element}>r�r�rrrr8r;F)rr��stripr�r:)r
r�r�r�r�r9r
r
r�test_cdata_with_closing_tagsOs		z5HTMLParserStrictTestCase.test_cdata_with_closing_tagscCs5d}d
ddd
dddg}|j||�dS)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!�--rD�--I have many hyphens--� I have a > in the middle � and I have -- in the middle! )�commentr�)r�r�)r�r�)r�rD)r�r�)r�r�)r�r�)r:)r
r�expectedr
r
r�
test_commentses	z&HTMLParserStrictTestCase.test_commentscCs)d}dddg}|j||�dS)	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]�f IE 8]>condcoms<![endif]�[if lte IE 7]>pretty?<![endif])�commentr�)r�r�)r�r�)r:)r
rr�r
r
r�
test_condcomsvs
	z&HTMLParserStrictTestCase.test_condcomscCs�dd�}|j|�j�ddddddg}d	d
d!gfd"d#g}x0|D](}|jdj|�|d|��qYWd$d	d
d%d&d'gfd(d)d*g}x0|D](}|jdj|�|d|��q�Wx�|D]�}dj|gd�}d+d	dgfd
|fd,d-d	dgfd
|fd.d/g	}|jdj||�|d|��q�Wd}xStdt|��D]<}|j|d|�d
|d|�fgd|��q�W|jd d0gd|��dS)1NcSs
tdd�S)Nr;T)r.r
r
r
r�<lambda>�sz@HTMLParserStrictTestCase.test_convert_charrefs.<locals>.<lambda>z&quot;z&#34;z&#x22;z&quotz&#34z&#x22rre�href�foo"zarr�a"zrz<a href="foo{0}zar">a{0}z</a>r8�"�x�y�"X�z�X"z*{0}<a x="{0}" y="{0}X" z="X{0}">{0}</a>{0}�X�rr�z/{1}<script>{0}</script>{1}<style>{0}</style>{1}z&quo &# &#xr�no charrefs here)r�r�)�datar�)�endtagre)r�r�)r�r�)r�r�)r�r�)r�r�)r�re)r�r�)r�r�)r�zscript)r�r�)r�zstyle)r�r�)r�r�)Z
assertTruer;r:r��join�range�len)r
r8Zcharrefsr�r�textrr�r
r
r�test_convert_charrefss>


	,z.HTMLParserStrictTestCase.test_convert_charrefsN)r)r*r+r2rKr[rardrhrjrlrmrprsrtrurvryr~r�r�r�r�r�r
r
r
rrCss* 
	rCc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�HTMLParserTolerantTestCasecCs
tdd�S)Nr;F)r)r
r
r
rr2�sz(HTMLParserTolerantTestCase.get_collectorc"Cs�|jt��t�WdQX|jt��tdd�WdQX|jt��tdd�WdQX|jtjj��+|jt��t�jd�WdQXWdQXdS)NrFTF�test)r@rArr>rrr?�error)r
r
r
r�test_deprecation_warnings�s
z4HTMLParserTolerantTestCase.test_deprecation_warningscCsG|jddddgfddddd
dgfddddg	�dS)NzF<html <html>te>>xt&a<<bc</a></html>
<img src="URL><//img></html</html>rr�<htmlr�te>>xtr$rernzbc<r�
<img src="URL>r�/img�html<)r�N)�datar�)z	entityrefre)r�rn)reN)�endtagzhtml)r�r�)zcommentr�)r�r�)r:)r
r
r
r�test_tolerant_parsing�s	z0HTMLParserTolerantTestCase.test_tolerant_parsingcCsz|jdg�|jddg�|jddg�|jddg�|jdd	d
gfg�|jddg�|jd
dg�|jdd g�|jdd!g�|jdd"g�|jdd#g�|jdd$g�|jdd	dgfg�|jdd	dgfg�|jdddgfg�|jdd	dgfg�|jdddgfg�dS)%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$>za$z<a$b>za$bz<a$b/>rz<a$b  >z<a$b  />)zcommentr�)�datar�)r�r�)zendtagr�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r:)r
r
r
rrt�s"z3HTMLParserTolerantTestCase.test_starttag_junk_charscCs%|jddddgfg�d}ddddddddd d!gfg}|j||�d}ddd"d#d$gfddd%d&d'gfg}|j||�d}ddgfddgfddgfddgfddgfddgfddgfddgfg}|j||�dS)(Nz<a foo="var"/>rrerw�varzj<img width=902 height=250px src="/sites/default/files/images/homepage/foo.jpg" /*what am I doing here*/ />rQ�width�902�height�250pxrR�,/sites/default/files/images/homepage/foo.jpg�*what�am�i�doing�here*z9<a / /foo/ / /=/ / /bar/ / /><a / /foo/ / /=/ / /bar/ / >�=�barrzD<meta><meta / ><meta // ><meta / / ><meta/><meta /><meta //><meta//>�meta)�foozvar)zwidthr�)r�r�)zsrcr�)r�N)r�N)r�N)r�N)r�N)r�N)r�N)r�N)r�N)r�N)r�N)r:)r
rr�r
r
r�test_slashes_in_starttag�s$	z3HTMLParserTolerantTestCase.test_slashes_in_starttagcCs|jddg�dS)Nz<!DOCTYPE foo $ >r"�DOCTYPE foo $ )zdeclr�)r:)r
r
r
rrv�sz6HTMLParserTolerantTestCase.test_declaration_junk_charscCs|jddg�dS)Nz"<!spacer type="block" height="25">r�spacer type="block" height="25")zcommentr�)r:)r
r
r
rrm�s	z4HTMLParserTolerantTestCase.test_illegal_declarationscCs�d}ddgfddd#d$gfdd	d%d&d'gfddgfddd(gfddd)gfd*ddd+gfddd,gfd-d.d/d0ddd1gfddd2gfd3d4d5d6g}|j||�dS)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>rrZbody�bgcolor�d0ca90r��181008�table�cellspacing�0�cellpaddingr{r��100%ZtrZtd�align�leftZfont�size�-1r�- rer��/rabota/�span�class�en� software-and-ir�/1/� library)r�r�)ztextr�)r�r�)r�r{)zwidthr�)r�zleft)zsizer�)�datar�)�hrefr�)�classr�)r�r�)�endtag�span)r�re)r�r�)r�r�)r�r�)r�r�)r�r�)r�re)r�ztable)r:)r
rr�r
r
r�test_with_unquoted_attributes�sz8HTMLParserTolerantTestCase.test_with_unquoted_attributescCs)|jdddd	d
dgfg�dS)Nz7<form action="/xxx.php?a=1&amp;b=2&amp", method="post">r�form�action�/xxx.php?a=1&b=2&�,�method�post)zactionr�)r�N)zmethodr�)r:)r
r
r
r�test_comma_between_attributess	z8HTMLParserTolerantTestCase.test_comma_between_attributescCs#|jddddgfg�dS)Nz<form action=bogus|&#()value>rr�r��bogus|&#()value)zactionr�)r:)r
r
r
r�-test_weird_chars_in_unquoted_attribute_valuess	zHHTMLParserTolerantTestCase.test_weird_chars_in_unquoted_attribute_valuescCs�d}ddgfd
ddgfdddgfdddgfd
ddgfdddgfddgfg}|j||�dS)Nzn<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br></li class="unit"><br></li
						</ul><br></><br>r�brr�label<r^r�<h4�li)�endtagr�)r�zdiv)zcommentr�)r�r�)r�r�)r:)r
rr�r
r
r�test_invalid_end_tags sz0HTMLParserTolerantTestCase.test_invalid_end_tagscCs5d}ddgfdd	d
g}|j||�dS)Nz(<b>This</b attr=">"> confuses the parserrrfr�Thisr�"> confuses the parser)�datar)zendtagrf)rr)r:)r
rr�r
r
r�test_broken_invalid_end_tag:s	z6HTMLParserTolerantTestCase.test_broken_invalid_end_tagcCs�d}dddgfddgfddd	dgfdddddgfdddgfdd d!d"g}|j||�d}ddd#d$d%gfddgfd&dd	d'gfd(d)g}|j||�dS)*Nz[<div style=""    ><b>The <a href="some_url">rain</a> <br /> in <span>Spain</span></b></div>rr^r�rDrfr�The rer��some_url�rainr� rr�� in r��Spainz><div style="", foo = "bar" ><b>The <a href="some_url">rain</a>r�rwr�)�stylerD)�datar)�hrefr)rr)�endtagre)rr)rr)rr	)r
zspan)r
rf)r
zdiv)r
rD)r�N)zfoozbar)rr)rr)rr)r
re)r:)r
rr�r
r
r�$test_correct_detection_of_start_tagsFs0		z?HTMLParserTolerantTestCase.test_correct_detection_of_start_tagscCsjddgfddgfdd
ddgfd
ddgfg}x$|D]\}}|j||�qFWdS)N�a&rza&b�abza&b rer$rfrza&b;)�datar)rr)rre)�	entityrefrf)rr)rre)rrf)r:)r
rrr�r
r
r�test_EOF_in_charrefgsz.HTMLParserTolerantTestCase.test_EOF_in_charrefcCs[ddlm}|j�}|jt��*d}|j|j|�||��WdQXdS)Nr)�unescapez%&quot;&#34;&#x22;&quot&#34&#x22&#bad;)rrr2r@rA�assertEqual)r
rr\r9r
r
r�test_unescape_methodus
z/HTMLParserTolerantTestCase.test_unescape_methodcCs2d}d	d
ddd
dg}|j||�dS)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 --rD�<-- this was an empty comment�!! another bogus comment !!!)�commentr)rr)rr)rrD)rr)rr)r:)r
rr�r
r
r�test_broken_comments|s	z/HTMLParserTolerantTestCase.test_broken_commentscCs�d}dddddd	dgfdddd
dgfdd ddgfd!d"d#d$dd
d%gfd&g}|j||�dS)'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 6rQrR�firefox.png�if !ie 6rrfrwr�if (!IE)|(lt IE 9)�mammoth.bmp)rr)�datar )rr!)rr")zhrefr$)rr!)rr%)�srcr&)rr!)rr')r*zfoo)zendtagrf)rr!)rr()r+r))rr!)r:)r
rr�r
r
r�test_broken_condcoms�s&	z/HTMLParserTolerantTestCase.test_broken_condcomscCsNtdd�}|jd�|j|j�dddgfdd
dg�dS)Nr;Tzfoo <a>link</a> bar &amp; bazr�foo rrer#r�
 bar & baz)�datar-)r/zlink)zendtagre)r/r.)rr3rr)r
rr
r
r�"test_convert_charrefs_dropped_text�s
	z=HTMLParserTolerantTestCase.test_convert_charrefs_dropped_textN)r)r*r+r2r�r�rtr�rvrmr�r�r�r�rrrrrr,r0r
r
r
rr��s$
!!r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�AttributesStrictTestCasecCs9tjdtfdd��tdddd�SWdQXdS)NrDrEFrFTr;)rrGrAr)r
r
r
rr2�sz&AttributesStrictTestCase.get_collectorcCsbdddd
ddgfg}|jd|�|jd	|�|jd
|�|jd|�dS)Nrrerf�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>)rfr2)r3r2)r4r2)r5N)r:)r
rrr
r
r�test_attr_syntax�s
z)AttributesStrictTestCase.test_attr_syntaxcCs�|jddddddgfg�|jd
ddddgfg�|jddd
dgfg�|jddddgfg�dS)Nz'<a b='xxx
	xxx' c="yyy	
yyy" d='	xyz
'>rrerf�xxx
	xxxr3�yyy	
yyyr4�	xyz
z
<a b='' c="">rDz<e a=rgb(1,2,3)>r5�
rgb(1,2,3)z<a href=mailto:xyz@example.com>r��mailto:xyz@example.com)rfr7)r3r8)r4r9)rfrD)r3rD)rer:)zhrefr;)r:)r
r
r
r�test_attr_values�s				z)AttributesStrictTestCase.test_attr_valuescCsj|jdddddgfg�|jddd	ddgfg�|jddd	ddgfg�dS)Nu!<img src=/foo/bar.png alt=中文>rrQrR�/foo/bar.png�alt�中文u+<a title='テスト' href='テスト.html'>re�title�	テストr��テスト.htmlu+<a title="テスト" href="テスト.html">)zsrcr=)r>r?)�titlerA)�hrefrB)rCrA)rDrB)r:)r
r
r
r�test_attr_nonascii�s			z+AttributesStrictTestCase.test_attr_nonasciicCs#|jddddgfg�dS)Nz!<a b='&amp;&gt;&lt;&quot;&apos;'>rrerf�&><"')rfrF)r:)r
r
r
r�test_attr_entity_replacement�sz5AttributesStrictTestCase.test_attr_entity_replacementcCs)|jddddd	d
gfg�dS)Nz<a a.b='v' c:d=v e-f=v>rre�a.br2�c:d�e-f)rHr2)rIr2)rJr2)r:)r
r
r
r�test_attr_funky_names�sz.AttributesStrictTestCase.test_attr_funky_namescCs#|jddddgfg�dS)Nz0<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>rrrw�€&aa&unsupported;)zfoorL)r:)r
r
r
r�test_entityrefs_in_attributes�sz6AttributesStrictTestCase.test_entityrefs_in_attributesN)
r)r*r+r2r6r<rErGrKrMr
r
r
rr1�s	r1c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�AttributesTolerantTestCasecCs
tdd�S)Nr;F)r)r
r
r
rr2�sz(AttributesTolerantTestCase.get_collectorcCsA|jdddd
gfdddgfdddgfg�dS)
Nz<a $><b $=%><c \=/>rrer�rf�%r3�\�/)r�N)r�rO)rPrQ)r:)r
r
r
r�test_attr_funky_names2�s
z1AttributesTolerantTestCase.test_attr_funky_names2cCs�x�ddddgD]o}|jd|dddgfg�|jd	|dddgfg�|jd
|ddd
gfg�qWdS)N�&z&amp;z&#38;z&#x26;z
<a href="%s">rrer�z
<a href='%s'>z<a href=%s>)�hrefrS)rTrS)rTrS)r:)r
rNr
r
r� test_entities_in_attribute_values


z;AttributesTolerantTestCase.test_entities_in_attribute_valuec
Cstd}dddgfdddddgfdddddgfdddddgfddg}|j||�dS)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>rrer��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)�hrefrV)�datarW)�endtagre)r^rX)r_rY)r`re)r^rZ)r_r[)r`re)r^r\)r_r])r`re)r:)r
rr�r
r
r�test_malformed_attributessz4AttributesTolerantTestCase.test_malformed_attributescCsf|jdddgfdddd
gfdg�|jd
ddgfddddgfdg�dS)Nz<x><y z=""o"" /></x>rr�rr�r�rD�o""rz<x><y z="""" /></x>�"")r�rD)rbN)�endtagr�)r�rD)rcN)rdr�)r:)r
r
r
r�"test_malformed_adjacent_attributes"s	
	z=AttributesTolerantTestCase.test_malformed_adjacent_attributescCsH|jdddd
dgfg�|jdddddgfg�dS)Nz<a width="100%"cellspacing=0>rrer��100%r�r�z<a id="foo"class="bar">�idrwr�r�)zwidthrf)zcellspacingr�)zidzfoo)zclasszbar)r:)r
r
r
r�test_adjacent_attributes.s		z3AttributesTolerantTestCase.test_adjacent_attributescCs#|jddddgfg�dS)Nz<a v=>rrer2rD)r2rD)r:)r
r
r
r�test_missing_attribute_value7s	z7AttributesTolerantTestCase.test_missing_attribute_valuecCs#|jddddgfg�dS)Nz-<a href=javascript:popup('/popup/help.html')>rrer��$javascript:popup('/popup/help.html'))zhrefrj)r:)r
r
r
r�test_javascript_attribute_value;s	z:AttributesTolerantTestCase.test_javascript_attribute_valuecCs)|jdddd	gfd
dg�dS)Nz-<a href='http://www.example.org/">;'>spam</a>rrer��http://www.example.org/">;r�spamr)zhrefrl)zdatarm)zendtagre)r:)r
r
r
r�test_end_tag_in_attribute_value@s		z:AttributesTolerantTestCase.test_end_tag_in_attribute_valueN)r)r*r+r2rRrUrarerhrirkrnr
r
r
rrN�s
	rN�__main__)�__doc__Zhtml.parserrr6Zunittestr�rrrrr,r.ZTestCaser0rCr�r1rNr)�mainr
r
r
r�<module>s 9	!�4�>P