mň
­fIc           @   sz   d  Z  d k Z e i d  i Z e i d  i Z e i d  Z e i d  Z e i d  Z [ d f  d     YZ	 d S(	   sü   Shared support for scanning document type declarations in HTML and XHTML.

This module is used as a foundation for the HTMLParser and sgmllib
modules (indirectly, for htmllib as well).  It has no documented
public API and should not be used directly.

Ns   [a-zA-Z][-_.a-zA-Z0-9]*\s*s   (\'[^\']*\'|"[^"]*")\s*s   --\s*>s	   ]\s*]\s*>s   ]\s*>t
   ParserBasec           B   sĄ   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d Z d   Z	 d d	  Z
 d d
  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   si   Parser base class which provides some common support methods used
    by the SGML/HTML and XHTML parsers.c         C   s$   |  i t j o t d   n d  S(   Ns(   markupbase.ParserBase must be subclassed(   t   selft	   __class__R    t   RuntimeError(   R   (    (    t'   /mit/python/lib/python2.4/markupbase.pyt   __init__   s    c         C   s   t  d   d  S(   Ns.   subclasses of ParserBase must override error()(   t   NotImplementedError(   R   t   message(    (    R   t   error!   s    c         C   s   d |  _ d |  _ d  S(   Ni   i    (   R   t   linenot   offset(   R   (    (    R   t   reset%   s    	c         C   s   |  i |  i f S(   s&   Return current line number and offset.N(   R   R	   R
   (   R   (    (    R   t   getpos)   s     c         C   s   | | j o | Sn |  i } | i d | |  } | o: |  i | |  _ | i d | |  } | | d |  _	 n |  i	 | | |  _	 | S(   Ns   
i   (
   t   it   jR   t   rawdatat   countt   nlinesR	   t   rindext   posR
   (   R   R   R   R   R   R   (    (    R   t	   updatepos1   s    	t    c   
      C   s\  |  i } | d } | | | d !d j o d Sn t |  } | | | d !d j o |  i |  Sn; | | d j o |  i |  Sn |  i | |  \ } } | d j  o | Sn | d	 j o d |  _
 n x| | j  ov| | } | d
 j oH | | d | !}	 | d	 j o |  i |	  n |  i |	  | d Sn | d j o. t | |  } | p d Sn | i   } nÄ | d j o |  i | |  \ } } n | |  i
 j o | d } n} | d j oZ | d	 j o |  i | d |  } q>| d j o |  i d |  q>|  i d  n |  i d | |  | d j  o | SqÔ qÔ Wd S(   Ni   i   t   -R   i˙˙˙˙s   --t   [i    t   doctypet   >s   "'t4   abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZt   attlistt   linktypet   linkt   elements&   unsupported '[' char in %s declarations"   unexpected '[' char in declarations!   unexpected %r char in declaration(   R   R   (   R   R   s   linkR   (   R   R   R   R   t   lent   nt   parse_commentt   parse_marked_sectiont
   _scan_namet   decltypet   _decl_othercharst   ct   datat   handle_declt   unknown_declt   _declstringlit_matcht   mt   endt   namet   _parse_doctype_subsetR   (
   R   R   R&   R$   R-   R   R+   R    R   R'   (    (    R   t   parse_declarationA   sV    	
  
i   c         C   sň   |  i } |  i | d |  \ } } | d j  o | Sn | d j o t i | | d  } nD | d j o t	 i | | d  } n |  i
 d | | d | ! | p d Sn | o+ | i d  } |  i | | d | ! n | i d  S(   Ni   i    t   tempt   cdatat   ignoret   includet   rcdatat   ift   elset   endifs+   unknown status keyword %r in marked sectioni˙˙˙˙(   R0   R1   s   ignoreR3   R4   (   R5   R6   R7   (   R   R   R#   R   t   sectNameR   t   _markedsectioncloset   searcht   matcht   _msmarkedsectioncloseR   t   reportt   startR)   R,   (   R   R   R=   R8   R   R   R;   (    (    R   R"      s     	 c         C   s   |  i } | | | d !d j o |  i d  n t i | | d  } | p d Sn | o+ | i d  } |  i
 | | d | ! n | i d  S(   Ni   s   <!--s"   unexpected call to parse_comment()i˙˙˙˙i    (   R   R   R   R   t   _commentcloseR:   R;   R=   R>   R   t   handle_commentR,   (   R   R   R=   R   R   R;   (    (    R   R!   ˘   s    	c   
      C   s  |  i } t |  } | } xî| | j  oŕ| | } | d j oy| | | d !} | d j o d Sn | d j o) |  i | | d  |  i
 d |  n | d | j o d Sn | d | j o d Sn | | | d !d j o1 |  i | d	 d
 } | d
 j  o | Sq q n |  i | d |  \ } } | d j o d Sn | d j o) |  i | | d  |  i
 d |  n t |  d |  }	 |	 | |  } | d
 j  o | Sqq | d j om | d | j o d Sn |  i | d |  \ } } | d
 j  o | Sn | | d j o | d } qq | d j o | d } x- | | j  o | | i   o | d } qOW| | j  o: | | d j o | Sn |  i | |  |  i
 d  qd Sq | i   o | d } q |  i | |  |  i
 d |  q Wd S(   Nt   <i   i˙˙˙˙s   <!i   s*   unexpected char in internal subset (in %r)i   s   <!--R=   i    R   R   t   entityt   notations)   unknown declaration %r in internal subsett   _parse_doctype_t   %t   ;t   ]R   s%   unexpected char after internal subsets%   unexpected char %r in internal subset(   s   attlists   elementRB   RC   (   R   R   R   R    R   R   R&   t   sR   t   declstartposR   R!   R#   R-   t   getattrt   metht   isspace(
   R   R   RI   R-   R   R&   R    RH   R   RK   (    (    R   R.   °   sp    	 

 c         C   sc   |  i | |  \ } } | d j o d Sn |  i } d | | j o | i d |  d Sn d S(   Ni˙˙˙˙R   i   (   R   R#   R   RI   R-   R   R   t   find(   R   R   RI   R-   R   R   (    (    R   t   _parse_doctype_elementó   s    	c         C   sc  |  i } |  i | |  \ } } | | | d !} | d j o d Sn | d j o | d Sn xü|  i | |  \ } } | d j  o | Sn | | | d !} | d j o d Sn | d j op d | | j o | i d |  d } n d Sx' | | | d !i	   o | d } qő W| | p d SqKn |  i | |  \ } } | | | d !} | p d Sn | d j oN t
 | |  } | o | i   } n d S| | | d !} | p d SqĆn | d	 j on | | d	 j o d Sn |  i | d |  \ } } | d j  o | Sn | | | d !} | p d SqAn | d j o | d Sqc qc Wd  S(
   Ni   R   i˙˙˙˙R   i    t   (t   )s   '"t   #(   R   R   R#   R   RI   R-   R   R&   RM   RL   R*   R+   R,   (   R   R   RI   R-   R   R+   R&   R   (    (    R   t   _parse_doctype_attlistţ   s^    	   c         C   să   |  i | |  \ } } | d j  o | Sn |  i } xŚ | | | d !} | p d Sn | d j o | d Sn | d j o. t | |  } | p d Sn | i
   } q9 |  i | |  \ } } | d j  o | Sq9 q9 Wd  S(   Ni    i   i˙˙˙˙R   s   '"(   R   R#   R   RI   R-   R   R   R&   R*   R+   R,   (   R   R   RI   R-   R   R+   R&   R   (    (    R   t   _parse_doctype_notation7  s&    	  c         C   sV  |  i } | | | d !d j oR | d } xK | | | d !} | p d Sn | i   o | d } q. Pq. Wn | } |  i | |  \ } } | d j  o | Sn xŠ |  i | | d !} | p d Sn | d j o. t	 | |  } | o | i   } qMd SqŠ | d j o | d SqŠ |  i | |  \ } } | d j  o | SqŠ qŠ Wd  S(   Ni   RE   i˙˙˙˙i    s   '"R   (   R   R   R   R   R&   RL   R#   RI   R-   R*   R+   R,   (   R   R   RI   R&   R-   R   R+   R   (    (    R   t   _parse_doctype_entityN  s<    	
  
  c         C   sÁ   |  i } t |  } | | j o d Sn t | |  } | oQ | i   } | i
   } | t |  | j o d Sn | i   | i   f Sn- |  i | |  |  i d | | | d ! d  S(   Ni˙˙˙˙s   expected name token at %ri   (   Ni˙˙˙˙(   Ni˙˙˙˙(   R   R   R   R    R   t   Nonet   _declname_matchR+   t   groupRH   t   stripR-   t   lowerR,   R   RI   R   (   R   R   RI   R-   R+   R    RH   R   (    (    R   R#   r  s    	c         C   s   d  S(   N(    (   R   R'   (    (    R   R)     s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R%   R/   R"   R!   R.   RN   RR   RS   RT   R#   R)   (    (    (    R   R       s"    						K	C		9		$	(
   R\   t   ret   compileR;   RV   R*   R?   R9   R<   R    (   R?   R    R9   RV   R*   R]   R<   (    (    R   t   ?   s   	