Ñò
mÈKc           @   s_  d  Z  d d k l Z e d d d ƒ[ d d k Z d d k Z d d g Z e i d	 ƒ Z e i d
 ƒ Z e i d ƒ Z	 e i d ƒ Z
 e i d ƒ Z e i d ƒ Z e i d ƒ Z e i d ƒ Z e i d ƒ Z e i d ƒ Z e i d ƒ Z d e f d „  ƒ  YZ d e i f d „  ƒ  YZ d e f d „  ƒ  YZ e d „ Z e d j o e ƒ  n d S(   s;   A parser for SGML, using the derived class as a static DTD.iÿÿÿÿ(   t   warnpy3ks1   the sgmllib module has been removed in Python 3.0t
   stackleveli   Nt
   SGMLParsert   SGMLParseErrors   [&<]sN   &([a-zA-Z][a-zA-Z0-9]*|#[0-9]*)?|<([a-zA-Z][^<>]*|/([a-zA-Z][^<>]*)?|![^<>]*)?s%   &([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]s   &#([0-9]+)[^0-9]s
   <[>a-zA-Z]s   <[a-zA-Z][-.a-zA-Z0-9]*/s"   <([a-zA-Z][-.a-zA-Z0-9]*)/([^/]*)/t   >s   [<>]s   [a-zA-Z][-_.a-zA-Z0-9]*se   \s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*(\'[^\']*\'|"[^"]*"|[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?c           B   s   e  Z d  Z RS(   s&   Exception raised for all parse errors.(   t   __name__t
   __module__t   __doc__(    (    (    s   /usr/lib/python2.6/sgmllib.pyR   ,   s   c           B   si  e  Z e i d  ƒ Z d 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 d „  Z d „  Z d „  Z h d d 6d d 6d d 6d d  6d! d" 6Z d# „  Z d$ „  Z d% „  Z d& „  Z  d' „  Z! d( „  Z" d) „  Z# d* „  Z$ d+ „  Z% d, „  Z& RS(-   s+   &(?:([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+))(;?)i    c         C   s   | |  _  |  i ƒ  d S(   s#   Initialize and reset this instance.N(   t   verboset   reset(   t   selfR   (    (    s   /usr/lib/python2.6/sgmllib.pyt   __init__B   s    	c         C   sJ   d |  _ d |  _ g  |  _ d |  _ d |  _ d |  _ t i i	 |  ƒ d S(   s0   Reset this instance. Loses all unprocessed data.t    s   ???i    N(
   t   Nonet   _SGMLParser__starttag_textt   rawdatat   stackt   lasttagt
   nomoretagst   literalt
   markupbaset
   ParserBaseR	   (   R
   (    (    s   /usr/lib/python2.6/sgmllib.pyR	   G   s    						c         C   s   d |  _  |  _ d S(   sY   Enter literal mode (CDATA) till EOF.

        Intended for derived classes only.
        i   N(   R   R   (   R
   (    (    s   /usr/lib/python2.6/sgmllib.pyt   setnomoretagsQ   s    c         G   s   d |  _  d S(   sP   Enter literal mode (CDATA).

        Intended for derived classes only.
        i   N(   R   (   R
   t   args(    (    s   /usr/lib/python2.6/sgmllib.pyt
   setliteralX   s    c         C   s!   |  i  | |  _  |  i d ƒ d S(   sã   Feed some data to the parser.

        Call this as often as you want, with as little or as much text
        as you want (may include '
').  (This just saves the text,
        all the processing is done by goahead().)
        i    N(   R   t   goahead(   R
   t   data(    (    s   /usr/lib/python2.6/sgmllib.pyt   feed_   s    c         C   s   |  i  d ƒ d S(   s   Handle the remaining data.i   N(   R   (   R
   (    (    s   /usr/lib/python2.6/sgmllib.pyt   closej   s    c         C   s   t  | ƒ ‚ d  S(   N(   R   (   R
   t   message(    (    s   /usr/lib/python2.6/sgmllib.pyt   errorn   s    c   	      C   sy  |  i  } d } t | ƒ } x| | j  o
|  i o |  i | | | !ƒ | } Pn t i | | ƒ } | o | i ƒ  } n | } | | j  o |  i | | | !ƒ n | } | | j o Pn | | d j oÀt i | | ƒ oZ |  i	 o" |  i | | ƒ | d } q n |  i
 | ƒ } | d j  o Pn | } q n | i d | ƒ o7 |  i | ƒ } | d j  o Pn | } d |  _	 q n |  i	 o4 | | d j o |  i d ƒ | d } q Pq n | i d | ƒ o. |  i | ƒ } | d j  o Pn | } q n | i d | ƒ o2 |  i | ƒ } | d j  o Pn | | } q n | i d | ƒ o. |  i | ƒ } | d j  o Pn | } q q»n+| | d j o|  i	 o" |  i | | ƒ | d } q n t i | | ƒ } | oU | i d ƒ } |  i | ƒ | i d ƒ } | | d d	 j o | d } q q n t i | | ƒ } | oU | i d ƒ } |  i | ƒ | i d ƒ } | | d d	 j o | d } q q q»n |  i d
 ƒ t i | | ƒ } | p" |  i | | ƒ | d } q n | i d ƒ } | | j o Pn |  i | | | !ƒ | } q W| o+ | | j  o |  i | | | !ƒ | } n | | |  _  d  S(   Ni    t   <i   s   </s   <!--s   <?s   <!t   &t   ;s   neither < nor & ??(   R   t   lenR   t   handle_datat   interestingt   searcht   startt   starttagopent   matchR   t   parse_starttagt
   startswitht   parse_endtagt   parse_commentt   parse_pit   parse_declarationt   charreft   groupt   handle_charreft   endt	   entityreft   handle_entityrefR   t
   incomplete(	   R
   R2   R   t   it   nR(   t   jt   kt   name(    (    s   /usr/lib/python2.6/sgmllib.pyR   t   sÀ    	 
  

  	
  
 

  

t   =c         C   s’   |  i  } | | | d !d j o |  i d ƒ n t i | | d ƒ } | p d S| i d ƒ } |  i | | d | !ƒ | i d ƒ } | | S(   Ni   s   <?s   unexpected call to parse_pi()iÿÿÿÿi    (   R   R   t   picloseR%   R&   t	   handle_piR2   (   R
   R6   R   R(   R8   (    (    s   /usr/lib/python2.6/sgmllib.pyR-   Þ   s    	c         C   s   |  i  S(   N(   R   (   R
   (    (    s   /usr/lib/python2.6/sgmllib.pyt   get_starttag_textê   s    c         C   s¼  d  |  _ | } |  i } t i | | ƒ o t i | | ƒ } | p d S| i d d ƒ \ } } d | |  _ | i ƒ  } | i d ƒ } |  i	 | | ƒ | | | i d ƒ d !|  _ | St
 i | | d ƒ } | p d S| i d ƒ } g  }	 | | | d !d j o | } |  i } n^ t i | | d ƒ } | p |  i d ƒ n | i d ƒ } | | d | !i ƒ  } | |  _ xü | | j  oî t i | | ƒ } | p Pn | i d d d ƒ \ }
 } } | p
 |
 } nv | d  d	 j o | d j n p& | d  d
 j o | d j n o | d d !} n |  i i |  i | ƒ } |	 i |
 i ƒ  | f ƒ | i d ƒ } q}W| | d j o | d } n | | | !|  _ |  i | |	 ƒ | S(   Niÿÿÿÿi   i   s   <%s/i    s   <>s!   unexpected call to parse_starttagi   t   't   "R   (   R   R   R   t   shorttagopenR(   t   shorttagR0   t   lowerR2   t   finish_shorttagt
   endbracketR%   R&   R   t   tagfindR   t   attrfindt   entity_or_charreft   subt   _convert_reft   appendt   finish_starttag(   R
   R6   t	   start_posR   R(   t   tagR   R9   R8   t   attrst   attrnamet   restt	   attrvalue(    (    s   /usr/lib/python2.6/sgmllib.pyR)   î   s`    			  
&&	c         C   sŒ   | i  d ƒ o, |  i | i  d ƒ ƒ p d | i ƒ  d S| i  d ƒ o+ |  i | i  d ƒ ƒ p d | i  d ƒ Sd | i  d ƒ Sd  S(   Ni   s   &#%s%si   i   s   &%s;s   &%s(   R0   t   convert_charreft   groupst   convert_entityref(   R
   R(   (    (    s   /usr/lib/python2.6/sgmllib.pyRJ   ,  s    c         C   s‡   |  i  } t i | | d ƒ } | p d S| i d ƒ } | | d | !i ƒ  i ƒ  } | | d j o | d } n |  i | ƒ | S(   Ni   iÿÿÿÿi    i   R   (   R   RE   R%   R&   t   stripRC   t   finish_endtag(   R
   R6   R   R(   R8   RN   (    (    s   /usr/lib/python2.6/sgmllib.pyR+   7  s    	c         C   s.   |  i  | g  ƒ |  i | ƒ |  i | ƒ d  S(   N(   RL   R#   RW   (   R
   RN   R   (    (    s   /usr/lib/python2.6/sgmllib.pyRD   D  s    c         C   s­   y t  |  d | ƒ } Wnh t j
 o\ y t  |  d | ƒ } Wn$ t j
 o |  i | | ƒ d SX|  i | | | ƒ d Sn) X|  i i | ƒ |  i | | | ƒ d Sd  S(   Nt   start_t   do_iÿÿÿÿi    i   (   t   getattrt   AttributeErrort   unknown_starttagt   handle_starttagR   RK   (   R
   RN   RO   t   method(    (    s   /usr/lib/python2.6/sgmllib.pyRL   K  s    	c         C   sq  | p6 t  |  i ƒ d } | d j  o |  i | ƒ d  Sn¡ | |  i j oL y t |  d | ƒ } Wn  t j
 o |  i | ƒ n X|  i | ƒ d  St  |  i ƒ } x2 t | ƒ D]$ } |  i | | j o
 | } qµ qµ Wx t  |  i ƒ | j ov |  i d } y t |  d | ƒ } Wn t j
 o d  } n X| o |  i | | ƒ n |  i | ƒ |  i d =qà Wd  S(   Ni   i    t   end_iÿÿÿÿ(	   R"   R   t   unknown_endtagRZ   R[   t   report_unbalancedt   rangeR   t   handle_endtag(   R
   RN   t   foundR^   R6   (    (    s   /usr/lib/python2.6/sgmllib.pyRW   ]  s8    	   c         C   s   | | ƒ d  S(   N(    (   R
   RN   R^   RO   (    (    s   /usr/lib/python2.6/sgmllib.pyR]   |  s    c         C   s   | ƒ  d  S(   N(    (   R
   RN   R^   (    (    s   /usr/lib/python2.6/sgmllib.pyRc   €  s    c         C   s+   |  i  o d | d GHd G|  i GHn d  S(   Ns   *** Unbalanced </R   s
   *** Stack:(   R   R   (   R
   RN   (    (    s   /usr/lib/python2.6/sgmllib.pyRa   „  s    
c         C   sW   y t  | ƒ } Wn t j
 o d SXd | j o
 d j n p d S|  i | ƒ S(   s/   Convert character reference, may be overridden.Ni    i   (   t   intt
   ValueErrort   convert_codepoint(   R
   R:   R7   (    (    s   /usr/lib/python2.6/sgmllib.pyRS   ‰  s    c         C   s
   t  | ƒ S(   N(   t   chr(   R
   t	   codepoint(    (    s   /usr/lib/python2.6/sgmllib.pyRg   “  s    c         C   s>   |  i  | ƒ } | d j o |  i | ƒ n |  i | ƒ d S(   s0   Handle character reference, no need to override.N(   RS   R   t   unknown_charrefR#   (   R
   R:   t   replacement(    (    s   /usr/lib/python2.6/sgmllib.pyR1   –  s    R   t   ltR   t   gtR    t   ampR@   t   quots   't   aposc         C   s'   |  i  } | | j o	 | | Sd Sd S(   sµ   Convert entity references.

        As an alternative to overriding this method; one can tailor the
        results by setting up the self.entitydefs mapping appropriately.
        N(   t
   entitydefs(   R
   R:   t   table(    (    s   /usr/lib/python2.6/sgmllib.pyRU   ¢  s    		c         C   s>   |  i  | ƒ } | d j o |  i | ƒ n |  i | ƒ d S(   s.   Handle entity references, no need to override.N(   RU   R   t   unknown_entityrefR#   (   R
   R:   Rk   (    (    s   /usr/lib/python2.6/sgmllib.pyR4   ®  s    c         C   s   d  S(   N(    (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyR#   ·  s    c         C   s   d  S(   N(    (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyt   handle_comment»  s    c         C   s   d  S(   N(    (   R
   t   decl(    (    s   /usr/lib/python2.6/sgmllib.pyt   handle_decl¿  s    c         C   s   d  S(   N(    (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyR=   Ã  s    c         C   s   d  S(   N(    (   R
   RN   RO   (    (    s   /usr/lib/python2.6/sgmllib.pyR\   Ç  s    c         C   s   d  S(   N(    (   R
   RN   (    (    s   /usr/lib/python2.6/sgmllib.pyR`   È  s    c         C   s   d  S(   N(    (   R
   t   ref(    (    s   /usr/lib/python2.6/sgmllib.pyRj   É  s    c         C   s   d  S(   N(    (   R
   Rw   (    (    s   /usr/lib/python2.6/sgmllib.pyRs   Ê  s    ('   R   R   t   ret   compileRH   R   R	   R   R   R   R   R   R   t   _decl_othercharsR-   R>   R)   RJ   R+   RD   RL   RW   R]   Rc   Ra   RS   Rg   R1   Rq   RU   R4   R#   Rt   Rv   R=   R\   R`   Rj   Rs   (    (    (    s   /usr/lib/python2.6/sgmllib.pyR   <   sF   	
						g			>									
		
)										t   TestSGMLParserc           B   se   e  Z d  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z RS(   i    c         C   s   d |  _  t i |  | ƒ d  S(   NR   (   t   testdataR   R   (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyR   Ï  s    	c         C   s>   |  i  | |  _  t t |  i  ƒ ƒ d j o |  i ƒ  n d  S(   NiF   (   R|   R"   t   reprt   flush(   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyR#   Ó  s    c         C   s0   |  i  } | o d |  _  d Gt | ƒ GHn d  S(   NR   s   data:(   R|   R}   (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyR~   Ø  s    		c         C   sP   |  i  ƒ  t | ƒ } t | ƒ d j o | d  d | d } n d G| GHd  S(   NiD   i    s   ...iàÿÿÿs   comment:(   R~   R}   R"   (   R
   R   t   r(    (    s   /usr/lib/python2.6/sgmllib.pyRt   Þ  s
    
c         C   s^   |  i  ƒ  | p d | d GHn9 d | Gx( | D]  \ } } | d d | d Gq1 Wd GHd  S(   Ns   start tag: <R   R;   R@   (   R~   (   R
   RN   RO   R:   t   value(    (    s   /usr/lib/python2.6/sgmllib.pyR\   å  s    
 c         C   s   |  i  ƒ  d | d GHd  S(   Ns   end tag: </R   (   R~   (   R
   RN   (    (    s   /usr/lib/python2.6/sgmllib.pyR`   ï  s    
c         C   s   |  i  ƒ  d | d GHd  S(   Ns   *** unknown entity ref: &R!   (   R~   (   R
   Rw   (    (    s   /usr/lib/python2.6/sgmllib.pyRs   ó  s    
c         C   s   |  i  ƒ  d | d GHd  S(   Ns   *** unknown char ref: &#R!   (   R~   (   R
   Rw   (    (    s   /usr/lib/python2.6/sgmllib.pyRj   ÷  s    
c         C   s   |  i  ƒ  d | d GHd  S(   Ns   *** unknown decl: [t   ](   R~   (   R
   R   (    (    s   /usr/lib/python2.6/sgmllib.pyt   unknown_declû  s    
c         C   s   t  i |  ƒ |  i ƒ  d  S(   N(   R   R   R~   (   R
   (    (    s   /usr/lib/python2.6/sgmllib.pyR   ÿ  s    (   R   R   R   R#   R~   Rt   R\   R`   Rs   Rj   R‚   R   (    (    (    s   /usr/lib/python2.6/sgmllib.pyR{   Í  s   				
				c   	   	   C   s5  d d  k  } |  d  j o | i d }  n |  o% |  d d j o |  d }  t } n t } |  o |  d } n d } | d j o | i } nF y t | d ƒ } Wn/ t j
 o# } | Gd G| GH| i d ƒ n X| i	 ƒ  } | | i j	 o | i
 ƒ  n | ƒ  } x | D] } | i | ƒ qW| i
 ƒ  d  S(	   Niÿÿÿÿi   i    s   -ss	   test.htmlt   -R   t   :(   t   sysR   t   argvR   R{   t   stdint   opent   IOErrort   exitt   readR   R   (	   R   R…   t   klasst   filet   ft   msgR   t   xt   c(    (    s   /usr/lib/python2.6/sgmllib.pyt   test  s2    

	 t   __main__(   R   t   warningsR    R   Rx   t   __all__Ry   R$   R5   R3   R/   R'   RA   RB   R<   RE   RF   RG   t   RuntimeErrorR   R   R   R{   R   R’   R   (    (    (    s   /usr/lib/python2.6/sgmllib.pyt   <module>   s4   		ÿ ’7$