ó
č¾bc           @   s©   d  Z  d d l m Z e d d d [ d d l Z d d l m Z d d	 g Z d	 e j f d
     YZ d e j	 f d     YZ
 e d  Z e d k r„ e   n  d S(   sv   HTML 2.0 parser.

See the HTML 2.0 specification:
http://www.w3.org/hypertext/WWW/MarkUp/html-spec/html-spec_toc.html
i’’’’(   t   warnpy3ks1   the htmllib module has been removed in Python 3.0t
   stackleveli   N(   t   AS_ISt
   HTMLParsert   HTMLParseErrorc           B   s   e  Z d  Z RS(   s3   Error raised when an HTML document can't be parsed.(   t   __name__t
   __module__t   __doc__(    (    (    s   /usr/lib/python2.7/htmllib.pyR      s   c           B   s3  e  Z d  Z d d l m 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 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/   Z0 d0   Z1 d1   Z2 d2   Z3 d3   Z4 d4   Z5 d5   Z6 d6   Z7 d7   Z8 d8   Z9 d9   Z: d:   Z; d;   Z< d<   Z= d=   Z> d d>  Z? d?   Z@ d@   ZA dA   ZB dB   ZC dC   ZD dD   ZE dE   ZF dF   ZG dG   ZH dH   ZI dI   ZJ dJ   ZK dK   ZL dL   ZM dM   ZN dN   ZO dO   ZP dP   ZQ dQ   ZR dR   ZS dS   ZT dT   ZU dU   ZV dV   ZW dW   ZX dX   ZY dY   ZZ dZ   Z[ RS([   sĢ   This is the basic HTML parser class.

    It supports all entity names required by the XHTML 1.0 Recommendation.
    It also defines handlers for all HTML 2.0 and many HTML 3.0 and 3.2
    elements.

    i’’’’(   t
   entitydefsi    c         C   s    t  j j |  |  | |  _ d S(   s   Creates an instance of the HTMLParser class.

        The formatter parameter is the formatter instance associated with
        the parser.

        N(   t   sgmllibt
   SGMLParsert   __init__t	   formatter(   t   selfR   t   verbose(    (    s   /usr/lib/python2.7/htmllib.pyR   "   s    c         C   s   t  |   d  S(   N(   R   (   R   t   message(    (    s   /usr/lib/python2.7/htmllib.pyt   error,   s    c         C   s\   t  j j |   d  |  _ d |  _ d  |  _ d  |  _ d  |  _ g  |  _	 d |  _
 g  |  _ d  S(   Ni    (   R	   R
   t   resett   Nonet   savedatat   isindext   titlet   baset   anchort
   anchorlistt   nofillt
   list_stack(   R   (    (    s   /usr/lib/python2.7/htmllib.pyR   /   s    							c         C   sR   |  j  d  k	 r" |  j  | |  _  n, |  j r> |  j j |  n |  j j |  d  S(   N(   R   R   R   R   t   add_literal_datat   add_flowing_data(   R   t   data(    (    s   /usr/lib/python2.7/htmllib.pyt   handle_data?   s
    	c         C   s   d |  _  d S(   sź   Begins saving character data in a buffer instead of sending it
        to the formatter object.

        Retrieve the stored data via the save_end() method.  Use of the
        save_bgn() / save_end() pair may not be nested.

        t    N(   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   save_bgnJ   s    c         C   s7   |  j  } d |  _  |  j s3 d j | j    } n  | S(   sH  Ends buffering character data and returns all data saved since
        the preceding call to the save_bgn() method.

        If the nofill flag is false, whitespace is collapsed to single
        spaces.  A call to this method without a preceding call to the
        save_bgn() method will raise a TypeError exception.

        t    N(   R   R   R   t   joint   split(   R   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   save_endT   s
    				c         C   s)   | |  _  |  j  r% |  j j |  n  d S(   s}  This method is called at the start of an anchor region.

        The arguments correspond to the attributes of the <A> tag with
        the same names.  The default implementation maintains a list of
        hyperlinks (defined by the HREF attribute for <A> tags) within
        the document.  The list of hyperlinks is available as the data
        attribute anchorlist.

        N(   R   R   t   append(   R   t   hreft   namet   type(    (    s   /usr/lib/python2.7/htmllib.pyt
   anchor_bgne   s    
		c         C   s3   |  j  r/ |  j d t |  j   d |  _  n  d S(   sŲ   This method is called at the end of an anchor region.

        The default implementation adds a textual footnote marker using an
        index into the list of hyperlinks created by the anchor_bgn()method.

        s   [%d]N(   R   R   t   lenR   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt
   anchor_ends   s    	c         G   s   |  j  |  d S(   s   This method is called to handle images.

        The default implementation simply passes the alt value to the
        handle_data() method.

        N(   R   (   R   t   srct   altt   args(    (    s   /usr/lib/python2.7/htmllib.pyt   handle_image   s    c         C   s   d  S(   N(    (   R   t   attrs(    (    s   /usr/lib/python2.7/htmllib.pyt
   start_html   R   c         C   s   d  S(   N(    (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_html   R   c         C   s   d  S(   N(    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_head   R   c         C   s   d  S(   N(    (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_head   R   c         C   s   d  S(   N(    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_body   R   c         C   s   d  S(   N(    (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_body   R   c         C   s   |  j    d  S(   N(   R    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_title   s    c         C   s   |  j    |  _ d  S(   N(   R$   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt	   end_title   s    c         C   s3   x, | D]$ \ } } | d k r | |  _  q q Wd  S(   NR&   (   R   (   R   R0   t   at   v(    (    s   /usr/lib/python2.7/htmllib.pyt   do_base   s    c         C   s   d |  _  d  S(   Ni   (   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   do_isindex”   s    c         C   s   d  S(   N(    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_link¤   s    c         C   s   d  S(   N(    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_meta§   s    c         C   s   d  S(   N(    (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   do_nextidŖ   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h1i    (   R@   i    i   i    (   R   t   end_paragrapht	   push_font(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h1±   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   t   pop_font(   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h1µ   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h2i    (   RF   i    i   i    (   R   RA   RB   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h2¹   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h2½   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h3i    (   RI   i    i   i    (   R   RA   RB   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h3Į   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h3Å   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h4i    (   RL   i    i   i    (   R   RA   RB   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h4É   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h4Ķ   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h5i    (   RO   i    i   i    (   R   RA   RB   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h5Ń   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h5Õ   s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t   h6i    (   RR   i    i   i    (   R   RA   RB   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_h6Ł   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_h6Ż   s    c         C   s   |  j  j d  d  S(   Ni   (   R   RA   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_pć   s    c         C   s@   |  j  j d  |  j  j t t t d f  |  j d |  _ d  S(   Ni   (   R   RA   RB   R   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   start_preę   s    c         C   s:   |  j  j d  |  j  j   t d |  j d  |  _ d  S(   Ni   i    (   R   RA   RD   t   maxR   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_preė   s    c         C   s   |  j  |  |  j d  d  S(   Nt   xmp(   RV   t
   setliteral(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   start_xmpš   s    c         C   s   |  j    d  S(   N(   RX   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_xmpō   s    c         C   s   |  j  |  |  j d  d  S(   Nt   listing(   RV   RZ   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_listing÷   s    c         C   s   |  j    d  S(   N(   RX   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_listingū   s    c         C   s0   |  j  j d  |  j  j t d t t f  d  S(   Ni    i   (   R   RA   RB   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_addressž   s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni    (   R   RA   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_address  s    c         C   s$   |  j  j d  |  j  j d  d  S(   Ni   t
   blockquote(   R   RA   t   push_margin(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_blockquote  s    c         C   s!   |  j  j d  |  j  j   d  S(   Ni   (   R   RA   t
   pop_margin(   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_blockquote
  s    c         C   sA   |  j  j |  j  |  j  j d  |  j j d d d g  d  S(   Nt   ult   *i    (   R   RA   R   Rc   R%   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_ul  s    c         C   s;   |  j  r |  j  d =n  |  j j |  j   |  j j   d  S(   Ni’’’’(   R   R   RA   Re   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_ul  s    	 c         C   sk   |  j  j d  |  j rH |  j d \ } } } } | d | d <} n d \ } } |  j  j | |  d  S(   Ni    i’’’’i   i   Rh   (   Rh   i    (   R   RA   R   t   add_label_data(   R   R0   t   dummyt   labelt   countert   top(    (    s   /usr/lib/python2.7/htmllib.pyt   do_li  s    	c         C   s   |  j  j |  j  |  j  j d  d } xH | D]@ \ } } | d k r1 t |  d k rh | d } n  | } q1 q1 W|  j j d | d g  d  S(   Nt   ols   1.R(   i   t   .i    (   R   RA   R   Rc   R*   R%   (   R   R0   Rm   R9   R:   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_ol#  s     c         C   s;   |  j  r |  j  d =n  |  j j |  j   |  j j   d  S(   Ni’’’’(   R   R   RA   Re   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_ol-  s    	 c         C   s   |  j  |  d  S(   N(   Ri   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_menu2  s    c         C   s   |  j    d  S(   N(   Rj   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_menu5  s    c         C   s   |  j  |  d  S(   N(   Ri   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   start_dir8  s    c         C   s   |  j    d  S(   N(   Rj   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_dir;  s    c         C   s-   |  j  j d  |  j j d d d g  d  S(   Ni   t   dlR   i    (   R   RA   R   R%   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_dl>  s    c         C   s'   |  j  d  |  j r# |  j d =n  d  S(   Ni   i’’’’(   t   ddpopR   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_dlB  s    	 c         C   s   |  j    d  S(   N(   R{   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_dtF  s    c         C   s7   |  j    |  j j d  |  j j d d d g  d  S(   Nt   ddR   i    (   R{   R   Rc   R   R%   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_ddI  s    
c         C   sQ   |  j  j |  |  j rM |  j d d d k rM |  j d =|  j  j   qM n  d  S(   Ni’’’’i    R~   (   R   RA   R   Re   (   R   t   bl(    (    s   /usr/lib/python2.7/htmllib.pyR{   N  s
    	
c         C   s   |  j  |  d  S(   N(   t   start_i(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_citeY  R   c         C   s   |  j    d  S(   N(   t   end_i(   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_citeZ  R   c         C   s   |  j  |  d  S(   N(   t   start_tt(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_code\  R   c         C   s   |  j    d  S(   N(   t   end_tt(   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_code]  R   c         C   s   |  j  |  d  S(   N(   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_em_  R   c         C   s   |  j    d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_em`  R   c         C   s   |  j  |  d  S(   N(   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   start_kbdb  R   c         C   s   |  j    d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_kbdc  R   c         C   s   |  j  |  d  S(   N(   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt
   start_sampe  R   c         C   s   |  j    d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_sampf  R   c         C   s   |  j  |  d  S(   N(   t   start_b(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   start_strongh  R   c         C   s   |  j    d  S(   N(   t   end_b(   R   (    (    s   /usr/lib/python2.7/htmllib.pyt
   end_strongi  R   c         C   s   |  j  |  d  S(   N(   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt	   start_vark  R   c         C   s   |  j    d  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_varl  R   c         C   s    |  j  j t d t t f  d  S(   Ni   (   R   RB   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyR   p  s    c         C   s   |  j  j   d  S(   N(   R   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyR   r  s    c         C   s    |  j  j t t d t f  d  S(   Ni   (   R   RB   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyR   u  s    c         C   s   |  j  j   d  S(   N(   R   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyR   w  s    c         C   s    |  j  j t t t d f  d  S(   Ni   (   R   RB   R   (   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyR   z  s    c         C   s   |  j  j   d  S(   N(   R   RD   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyR   |  s    c         C   s   d } d } d } xe | D]] \ } } | j    } | d k rF | } n  | d k r[ | } n  | d k r | j   } q q W|  j | | |  d  S(   NR   R&   R'   R(   (   t   stript   lowerR)   (   R   R0   R&   R'   R(   t   attrnamet   value(    (    s   /usr/lib/python2.7/htmllib.pyt   start_a  s    		c         C   s   |  j    d  S(   N(   R+   (   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   end_a  s    c         C   s   |  j  j   d  S(   N(   R   t   add_line_break(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_br  s    c         C   s   |  j  j   d  S(   N(   R   t   add_hor_rule(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_hr  s    c   
      C   s  d } d } d } d } d } d } xĪ | D]Ę \ } }	 | d k rL |	 } n  | d k ra |	 } n  | d k rv |	 } n  | d k r |	 } n  | d k r¾ y t  |	  } Wq¾ t k
 rŗ q¾ Xn  | d	 k r+ y t  |	  } Wqń t k
 rķ qń Xq+ q+ W|  j | | | | | |  d  S(
   NR   s   (image)i    t   alignR-   t   ismapR,   t   widtht   height(   t   intt
   ValueErrorR/   (
   R   R0   R   R-   R    R,   R”   R¢   R   R   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_img  s4    				    c         C   s   |  j  |  |  j   d  S(   N(   RV   t   setnomoretags(   R   R0   (    (    s   /usr/lib/python2.7/htmllib.pyt   do_plaintext¶  s    c         C   s   d  S(   N(    (   R   t   tagR0   (    (    s   /usr/lib/python2.7/htmllib.pyt   unknown_starttag¼  s    c         C   s   d  S(   N(    (   R   RØ   (    (    s   /usr/lib/python2.7/htmllib.pyt   unknown_endtagæ  s    (\   R   R   R   t   htmlentitydefsR   R   R   R   R   R    R$   R)   R+   R/   R1   R2   R3   R4   R5   R6   R7   R8   R;   R<   R=   R>   R?   RC   RE   RG   RH   RJ   RK   RM   RN   RP   RQ   RS   RT   RU   RV   RX   R[   R\   R^   R_   R`   Ra   Rd   Rf   Ri   Rj   Rp   Rs   Rt   Ru   Rv   Rw   Rx   Rz   R|   R}   R   R{   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R„   R§   R©   RŖ   (    (    (    s   /usr/lib/python2.7/htmllib.pyR      s²   
				
																																													
																																				c   	      C   sA  d d  l  } d d  l } |  s. | j d }  n  |  oA |  d d k } | rT |  d =n  |  rg |  d } n d } | d k r | j } nC y t | d  } Wn- t k
 rĒ } | Gd G| GH| j d  n X| j   } | | j k	 rš | j   n  | r| j	   } n | j
 | j    } t |  } | j |  | j   d  S(	   Ni’’’’i   i    s   -ss	   test.htmlt   -t   rt   :(   t   sysR   t   argvt   stdint   opent   IOErrort   exitt   readt   closet   NullFormattert   AbstractFormattert
   DumbWriterR   t   feed(	   R.   RÆ   R   t   silentt   filet   ft   msgR   t   p(    (    s   /usr/lib/python2.7/htmllib.pyt   testĆ  s2    
t   __main__(   R   t   warningsR    R	   R   R   t   __all__t   SGMLParseErrorR   R
   R   R   RĄ   R   (    (    (    s   /usr/lib/python2.7/htmllib.pyt   <module>   s   	’ ­'