Ñò
à"Ic           @   s½   d  Z  d d k Z d d k Z d d k Z d d k l Z d e i f d „  ƒ  YZ d e f d „  ƒ  YZ d e i f d	 „  ƒ  YZ	 d
 e	 f d „  ƒ  YZ
 d „  Z e d j o e ƒ  n d S(   s   Tests for HTMLParser.py.iÿÿÿÿN(   t   test_supportt   EventCollectorc           B   st   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 RS(   c         C   s,   g  |  _  |  i  i |  _ t i i |  ƒ d  S(   N(   t   eventst   appendt
   HTMLParsert   __init__(   t   self(    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR      s    	c         C   sŒ   g  } d  } xp |  i D]e } | d } | | j o
 d j n o$ d | d d | d f | d <n | i | ƒ | } q W| |  _ | S(   Ni    t   dataiÿÿÿÿi   (   t   NoneR   R   (   R   t   Lt   prevtypet   eventt   type(    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt
   get_events   s    
 
$
	c         C   s   |  i  d | | f ƒ d  S(   Nt   starttag(   R   (   R   t   tagt   attrs(    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_starttag!   s    c         C   s   |  i  d | | f ƒ d  S(   Nt   startendtag(   R   (   R   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_startendtag$   s    c         C   s   |  i  d | f ƒ d  S(   Nt   endtag(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_endtag'   s    c         C   s   |  i  d | f ƒ d  S(   Nt   comment(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_comment,   s    c         C   s   |  i  d | f ƒ d  S(   Nt   charref(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_charref/   s    c         C   s   |  i  d | f ƒ d  S(   NR   (   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_data2   s    c         C   s   |  i  d | f ƒ d  S(   Nt   decl(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_decl5   s    c         C   s   |  i  d | f ƒ d  S(   Nt	   entityref(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   handle_entityref8   s    c         C   s   |  i  d | f ƒ d  S(   Nt   pi(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt	   handle_pi;   s    c         C   s   |  i  d | f ƒ d  S(   Ns   unknown decl(   R   (   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   unknown_decl>   s    (   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R   R    R!   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR   	   s   											t   EventCollectorExtrac           B   s   e  Z d  „  Z RS(   c         C   s0   t  i |  | | ƒ |  i d |  i ƒ  f ƒ d  S(   Nt   starttag_text(   R   R   R   t   get_starttag_text(   R   R   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR   D   s    (   R"   R#   R   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR$   B   s   t   TestCaseBasec           B   s&   e  Z e d  „ Z d „  Z d „  Z RS(   c         C   s}   | ƒ  } x | D] } | i  | ƒ q W| i ƒ  | i ƒ  } | | j o/ |  i d t i | ƒ d t i | ƒ ƒ n d  S(   Ns8   received events did not match expected events
Expected:
s   
Received:
(   t   feedt   closeR   t   failt   pprintt   pformat(   R   t   sourcet   expected_eventst	   collectort   parsert   sR   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt
   _run_checkK   s    	 
c         C   s   |  i  | | t ƒ d  S(   N(   R2   R$   (   R   R-   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   _run_check_extraV   s    c         C   s#   | d „ } |  i  t i | ƒ d  S(   Nc         S   s'   t  i  ƒ  } | i |  ƒ | i ƒ  d  S(   N(   R   R(   R)   (   R-   R0   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   parseZ   s    (   t   assertRaisesR   t   HTMLParseError(   R   R-   R4   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   _parse_errorY   s    (   R"   R#   R   R2   R3   R7   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR'   I   s   	t   HTMLParserTestCasec           B   s¼   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 RS(   c         C   s*   |  i  d d g ƒ |  i  d d g ƒ d  S(   Ns   <?processing instruction>R   s   processing instructions   <?processing instruction ?>s   processing instruction ?(   s   pis   processing instruction(   s   pis   processing instruction ?(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt    test_processing_instruction_onlyc   s    	
	c         C   s_   |  i  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('   NsÂ   
<!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   s   
R   s   DOCTYPE html PUBLIC 'foo'R   t   htmlR   t   entityR   t   32R   s4   comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1bt   imgt   srct   Bart   ismaps   sample
text
t   x201Cs   comment2a-- --comment2bR   (   s   datas   
(   s   decls   DOCTYPE html PUBLIC 'foo'(   s   datas   
(   s	   entityrefR;   (   s   charrefR<   (   s   datas   
(   s   comments4   comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1b(   s   datas   
(   R>   R?   (   R@   N(   s   datas   sample
text
(   s   charrefRA   (   s   datas   
(   s   comments   comment2a-- --comment2b(   s   datas   
(   s   endtagR:   (   s   datas   
(   R2   R   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_simple_htmlk   s&    c         C   s   |  i  d d d g ƒ d  S(   Ns   &entityref fooR   R   s    foo(   s	   entityrefs	   entityref(   s   datas    foo(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_unclosed_entityref‹   s    	c         C   s'   d } |  i  d | d | f g ƒ d  S(   Ns‘  DOCTYPE html [
  <!ELEMENT html - O EMPTY>
  <!ATTLIST html
      version CDATA #IMPLIED
      profile CDATA 'DublinCore'>
  <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
  <!ENTITY myEntity 'internal parsed entity'>
  <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
  <!ENTITY % paramEntity 'name|name|name'>
  %paramEntity;
  <!-- comment -->
]s   <!%s>R   (   R2   (   R   t   inside(    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_doctype_decl‘   s    c         C   s2   |  i  d d d g  f d d g  f d d g ƒ d  S(   Ns   <a><b></a></b>R   t   at   bR   (   s   endtagRF   (   s   endtagRG   (   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_bad_nesting£   s
    	c         C   s   |  i  d d g ƒ d  S(   Ns#   this text & contains & ampersands &R   (   s   datas#   this text & contains & ampersands &(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_bare_ampersands®   s    	c         C   s   |  i  d d g ƒ d  S(   Ns.   this < text > contains < bare>pointy< bracketsR   (   s   datas.   this < text > contains < bare>pointy< brackets(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_bare_pointy_brackets³   s    	c         C   sb   d d d d d d g f g } |  i d | ƒ |  i d	 | ƒ |  i d
 | ƒ |  i d | ƒ d  S(   NR   RF   RG   t   vt   ct   dt   es   <a b='v' c="v" d=v e>s   <a  b = 'v' c = "v" d = v e>s   <a
b
=
'v'
c
=
"v"
d
=
v
e>s   <a	b	=	'v'	c	=	"v"	d	=	v	e>(   RG   RK   (   RL   RK   (   RM   RK   (   RN   N(   R   R2   (   R   t   output(    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_attr_syntax¸   s
    c         C   s‰   |  i  d d d d d d g f g ƒ |  i  d
 d d d d g f g ƒ |  i  d d d d g f g ƒ |  i  d d d d g f g ƒ d  S(   Ns'   <a b='xxx
	xxx' c="yyy	
yyy" d='	xyz
'>R   RF   RG   s   xxx
	xxxRL   s   yyy	
yyyRM   s   	xyz
s   <a b='' c="">t    s   <e a=rgb(1,2,3)>RN   s
   rgb(1,2,3)s   <a href=mailto:xyz@example.com>t   hrefs   mailto:xyz@example.com(   RG   s   xxx
	xxx(   RL   s   yyy	
yyy(   RM   s   	xyz
(   RG   RQ   (   RL   RQ   (   RF   s
   rgb(1,2,3)(   RR   s   mailto:xyz@example.com(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_attr_valuesÁ   s    					c         C   s#   |  i  d d d d g f g ƒ d  S(   Ns!   <a b='&amp;&gt;&lt;&quot;&apos;'>R   RF   RG   s   &><"'(   RG   s   &><"'(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_attr_entity_replacementÓ   s    	c         C   s)   |  i  d d d d d	 d
 g f g ƒ d  S(   Ns   <a a.b='v' c:d=v e-f=v>R   RF   s   a.bRK   s   c:ds   e-f(   s   a.bRK   (   s   c:dRK   (   s   e-fRK   (   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_attr_funky_namesØ   s    	c         C   s   |  i  d ƒ d  S(   Ns"   <!spacer type="block" height="25">(   R7   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_illegal_declarationsÝ   s    c         C   sB   |  i  d d d d g f g ƒ |  i  d d d d	 g f g ƒ d  S(
   Ns	   <a b='<'>R   RF   RG   t   <s	   <a b='>'>t   >(   RG   RW   (   RG   RX   (   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_starttag_end_boundaryà   s    c         C   s+  d d d* g f g } |  i  d g | ƒ |  i  d d g | ƒ |  i  d d	 g | ƒ |  i  d
 d g | ƒ |  i  d d g | ƒ |  i  d d g | ƒ d d d+ g f g } |  i  d g | ƒ |  i  d d g | ƒ |  i  d d g | ƒ |  i  d
 d g | ƒ |  i  d d g | ƒ |  i  d d g | ƒ d, g } |  i  d d g | ƒ |  i  d d g | ƒ |  i  d d g | ƒ |  i  d d g | ƒ |  i  d d  g | ƒ |  i  d! d" g | ƒ |  i  d# d$ g | ƒ |  i  d% d& g | ƒ |  i  d' d( g | ƒ |  i  d) d g | ƒ |  i  d d g | ƒ d  S(-   NR   RF   RG   RW   s	   <a b='<'>s   <a s   b='<'>s   <a bs   ='<'>s   <a b=s   '<'>s   <a b='<s   '>s   <a b='<'RX   s	   <a b='>'>s   b='>'>s   ='>'>s   '>'>s   <a b='>s   <a b='>'R   t   abcRQ   s
   <!--abc-->s	   !--abc-->s   <!s   --abc-->s   <!-s   -abc-->s   <!--s   abc-->s   <!--as   bc-->s   <!--abs   c-->s   <!--abcs   -->s   <!--abc-s   ->s	   <!--abc--(   RG   RW   (   RG   RX   (   s   comments   abc(   R2   (   R   RO   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_buffer_artefactsä   s4    	c         C   sº   |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d	 ƒ |  i  d
 ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ |  i  d ƒ d  S(   Ns   </>s   </$>s   </s   </as   <a<a>s   </a<a>s   <!s   <a $>s   <as   <a foo='bar's   <a foo='bars
   <a foo='>'s	   <a foo='>s   <a foo=>(   R7   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_starttag_junk_chars  s    c         C   s   |  i  d ƒ d  S(   Ns   <!DOCTYPE foo $ >(   R7   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_declaration_junk_chars  s    c         C   sm   |  i  d d d g  f g ƒ |  i  d d d g  f d g ƒ |  i  d d d g  f d d d g f d g ƒ d  S(   Ns   <p/>R   t   ps   <p></p>R   R   s   <p><img src='foo' /></p>R=   R>   t   foo(   s   endtagR^   (   s   srcR_   (   s   endtagR^   (   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_startendtag  s    		
	c         C   s5   d } |  i  | d d d	 d
 g f d | f g ƒ d  S(   Ns    <foo:bar   
   one="1"	two=2   >R   s   foo:bart   onet   1t   twot   2R%   (   Ra   Rb   (   Rc   Rd   (   R3   (   R   R1   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_get_starttag_text#  s    	c         C   sT   d } |  i  | d d g  f d	 d
 g ƒ d } |  i  | d d g  f d d g ƒ d  S(   Ns=   <script> <!-- not a comment --> &not-an-entity-ref; </script>R   t   scriptR   s,    <!-- not a comment --> &not-an-entity-ref; R   s&   <script> <not a='start tag'> </script>s    <not a='start tag'> (   s   datas,    <!-- not a comment --> &not-an-entity-ref; (   s   endtags   script(   s   datas    <not a='start tag'> (   s   endtags   script(   R2   (   R   R1   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_cdata_content)  s    	
	c         C   s#   |  i  d d d d g f g ƒ d  S(   Ns0   <html foo='&euro;&amp;&#97;&#x61;&unsupported;'>R   R:   R_   u   â‚¬&aa&unsupported;(   s   foou   â‚¬&aa&unsupported;(   R2   (   R   (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   test_entityrefs_in_attributes7  s    	(   R"   R#   R9   RB   RC   RE   RH   RI   RJ   RP   RS   RT   RU   RV   RY   R[   R\   R]   R`   Re   Rg   Rh   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyR8   a   s(   		 																		c           C   s   t  i t ƒ d  S(   N(   R    t   run_unittestR8   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt	   test_main=  s    t   __main__(   t   __doc__R   R+   t   unittestt   testR    R   R$   t   TestCaseR'   R8   Rj   R"   (    (    (    s1   /mit/python/lib/python2.6/test/test_htmlparser.pyt   <module>   s   9Ü	