mò
­fIc           @   sº   d  Z  d k Z d k Z d k Z d k Z 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.N(   s   test_supportt   EventCollectorc           B   st   t  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(   Nc         C   s,   g  |  _ |  i i |  _ t i i |  ƒ d  S(   N(   t   selft   eventst   appendt
   HTMLParsert   __init__(   R   (    (    t1   /mit/python/lib/python2.4/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   Lt   Nonet   prevtypeR   R   t   eventt   typeR   (   R   R   R
   R   R   (    (    R   t
   get_events   s    
 
$
	c         C   s   |  i d | | f ƒ d  S(   Nt   starttag(   R   R   t   tagt   attrs(   R   R   R   (    (    R   t   handle_starttag"   s    c         C   s   |  i d | | f ƒ d  S(   Nt   startendtag(   R   R   R   R   (   R   R   R   (    (    R   t   handle_startendtag%   s    c         C   s   |  i d | f ƒ d  S(   Nt   endtag(   R   R   R   (   R   R   (    (    R   t   handle_endtag(   s    c         C   s   |  i d | f ƒ d  S(   Nt   comment(   R   R   R   (   R   R   (    (    R   t   handle_comment-   s    c         C   s   |  i d | f ƒ d  S(   Nt   charref(   R   R   R   (   R   R   (    (    R   t   handle_charref0   s    c         C   s   |  i d | f ƒ d  S(   NR   (   R   R   R   (   R   R   (    (    R   t   handle_data3   s    c         C   s   |  i d | f ƒ d  S(   Nt   decl(   R   R   R   (   R   R   (    (    R   t   handle_decl6   s    c         C   s   |  i d | f ƒ d  S(   Nt	   entityref(   R   R   R   (   R   R   (    (    R   t   handle_entityref9   s    c         C   s   |  i d | f ƒ d  S(   Nt   pi(   R   R   R   (   R   R   (    (    R   t	   handle_pi<   s    c         C   s   |  i d | f ƒ d  S(   Ns   unknown decl(   R   R   R   (   R   R   (    (    R   t   unknown_decl?   s    (   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R   R    R!   (    (    (    R   R    
   s   											t   EventCollectorExtrac           B   s   t  Z d „  Z RS(   Nc         C   s0   t  i |  | | ƒ |  i d |  i ƒ  f ƒ d  S(   Nt   starttag_text(   R    R   R   R   R   R   t   get_starttag_text(   R   R   R   (    (    R   R   E   s    (   R"   R#   R   (    (    (    R   R$   C   s   t   TestCaseBasec           B   s&   t  Z e d „ Z d „  Z d „  Z RS(   Nc         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	   collectort   parsert   sourcet   st   feedt   closeR   R   t   expected_eventsR   t   failt   pprintt   pformat(   R   R*   R.   R(   R)   R+   R   (    (    R   t
   _run_checkL   s    	 
c         C   s   |  i | | t ƒ d  S(   N(   R   R2   R*   R   R$   (   R   R*   R   (    (    R   t   _run_check_extraW   s    c         C   s#   | d „ } |  i t i | ƒ d  S(   Nc         C   s'   t  i  ƒ  } | i |  ƒ | i ƒ  d  S(   N(   R   R)   R,   R*   R-   (   R*   R)   (    (    R   t   parse[   s    (   R*   R4   R   t   assertRaisesR   t   HTMLParseError(   R   R*   R4   (    (    R   t   _parse_errorZ   s    (   R"   R#   R    R2   R3   R7   (    (    (    R   R'   J   s   	t   HTMLParserTestCasec           B   s³   t  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(   Nc         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 ?(   R   R2   (   R   (    (    R   t    test_processing_instruction_onlyd   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   
(   R   R2   R	   (   R   (    (    R   t   test_simple_htmll   s    c         C   s   |  i d d d g ƒ d  S(   Ns   &entityref fooR   R   s    foo(   s	   entityrefs	   entityref(   s   datas    foo(   R   R2   (   R   (    (    R   t   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   (   t   insideR   R2   (   R   RD   (    (    R   t   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   (   R   R2   (   R   (    (    R   t   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 &(   R   R2   (   R   (    (    R   t   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(   R   R2   (   R   (    (    R   t   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	   t   outputR   R2   (   R   RO   (    (    R   t   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(   R   R2   (   R   (    (    R   t   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   &><"'(   R   R2   (   R   (    (    R   t   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   (   R   R2   (   R   (    (    R   t   test_attr_funky_namesÙ   s    c         C   s   |  i d ƒ d  S(   Ns"   <!spacer type="block" height="25">(   R   R7   (   R   (    (    R   t   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   (   R   R2   (   R   (    (    R   t   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   commentRZ   (   RO   R   R2   (   R   RO   (    (    R   t   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=>(   R   R7   (   R   (    (    R   t   test_starttag_junk_chars  s    c         C   s   |  i d ƒ d  S(   Ns   <!DOCTYPE foo $ >(   R   R7   (   R   (    (    R   t   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^   (   R   R2   (   R   (    (    R   t   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   (   R+   R   R3   (   R   R+   (    (    R   t   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(   R+   R   R2   (   R   R+   (    (    R   t   test_cdata_content*  s    "(   R"   R#   R9   RB   RC   RE   RH   RI   RJ   RP   RS   RT   RU   RV   RY   R[   R\   R]   R`   Re   Rg   (    (    (    R   R8   b   s&   		 																	c           C   s   t  i t ƒ d  S(   N(   t   test_supportt   run_unittestR8   (    (    (    R   t	   test_main9  s    t   __main__(   t   __doc__R   R0   t   syst   unittestt   testRh   R    R$   t   TestCaseR'   R8   Rj   R"   (
   Rh   R8   R'   Rn   R0   Rm   R    R   Rj   R$   (    (    R   t   ?   s   				9×	