
[c           @   s}   d  Z  d d l Z e j d  j Z e j d  j Z e j d  Z e j d  Z e j d  Z [ d d
 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.

iNs   [a-zA-Z][-_.a-zA-Z0-9]*\s*s   (\'[^\']*\'|"[^"]*")\s*s   --\s*>s	   ]\s*]\s*>s   ]\s*>t
   ParserBasec           B   s   e  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"   |  j  t k r t d   n  d  S(   Ns(   markupbase.ParserBase must be subclassed(   t	   __class__R    t   RuntimeError(   t   self(    (    s    /usr/lib/python2.7/markupbase.pyt   __init__   s    c         C   s   t  d   d  S(   Ns.   subclasses of ParserBase must override error()(   t   NotImplementedError(   R   t   message(    (    s    /usr/lib/python2.7/markupbase.pyt   error!   s    c         C   s   d |  _  d |  _ d  S(   Ni   i    (   t   linenot   offset(   R   (    (    s    /usr/lib/python2.7/markupbase.pyt   reset%   s    	c         C   s   |  j  |  j f S(   s&   Return current line number and offset.(   R   R	   (   R   (    (    s    /usr/lib/python2.7/markupbase.pyt   getpos)   s    c         C   s   | | k r | S|  j  } | j d | |  } | rm |  j | |  _ | j d | |  } | | d |  _ n |  j | | |  _ | S(   Ns   
i   (   t   rawdatat   countR   t   rindexR	   (   R   t   it   jR   t   nlinest   pos(    (    s    /usr/lib/python2.7/markupbase.pyt	   updatepos1   s    	t    c   
      C   se  |  j  } | d } | | | !d k s2 t d   | | | d !d k rQ | d S| | | d !d k rl d St |  } | | | d !d	 k r |  j |  S| | d
 k r |  j |  S|  j | |  \ } } | d k  r | S| d k r d |  _ n  xe| | k  r`| | } | d k r`| | d | !} | d k rK|  j |  n |  j |  | d S| d k rt	 | |  } | sd S| j
   } n | d k r|  j | |  \ }	 } n | |  j k r| d } nv | d
 k r8| d k r|  j | d |  } qM| d k r(|  j d |  qM|  j d  n |  j d | |  | d k  r | Sq Wd S(   Ni   s   <!s$   unexpected call to parse_declarationi   t   >t   -R   is   --t   [i    t   doctypes   "'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   links   element(   R   t   AssertionErrort   lent   parse_commentt   parse_marked_sectiont
   _scan_namet   _decl_othercharst   handle_declt   unknown_declt   _declstringlit_matcht   endt   _parse_doctype_subsetR   (
   R   R   R   R   t   nt   decltypet   ct   datat   mt   name(    (    s    /usr/lib/python2.7/markupbase.pyt   parse_declarationA   sZ    	

i   c         C   s  |  j  } | | | d !d k s, t d   |  j | d |  \ } } | d k  rX | S| d k r} t j | | d  } nA | d k r t j | | d  } n |  j d | | d | ! | s d S| r | j d  } |  j | | d | ! n  | j	 d  S(   Ni   s   <![s)   unexpected call to parse_marked_section()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"   t   _markedsectioncloset   searcht   _msmarkedsectioncloseR   t   startR%   R'   (   R   R   t   reportR   t   sectNameR   t   match(    (    s    /usr/lib/python2.7/markupbase.pyR!      s     	#c         C   s   |  j  } | | | d !d k r0 |  j d  n  t j | | d  } | sP d S| r | j d  } |  j | | d | ! n  | j d  S(   Ni   s   <!--s"   unexpected call to parse_comment()ii    (   R   R   t   _commentcloseR9   R;   t   handle_commentR'   (   R   R   R<   R   R>   R   (    (    s    /usr/lib/python2.7/markupbase.pyR       s    	c   
      C   s  |  j  } t |  } | } x| | k  r| | } | d k r| | | d !} | d k ra d S| d k r |  j | | d  |  j d |  n  | d | k r d S| d | k r d S| | | d !d k r |  j | d	 d
 } | d
 k  r | Sq n  |  j | d |  \ } } | d k r+d S| d k r_|  j | | d  |  j d |  n  t |  d |  }	 |	 | |  } | d
 k  r| Sq | d k r | d | k rd S|  j | d |  \ } } | d
 k  r| S| | d k r| d } qq | d k r| d } x* | | k  rB| | j   rB| d } qW| | k  r| | d k rc| S|  j | |  |  j d  qd Sq | j   r| d } q |  j | |  |  j d |  q Wd S(   Nt   <i   is   <!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"   t   getattrt   isspace(
   R   R   t   declstartposR   R)   R   R+   t   sR.   t   meth(    (    s    /usr/lib/python2.7/markupbase.pyR(      sn    	

c         C   sY   |  j  | |  \ } } | d k r( d S|  j } d | | k rU | j d |  d Sd S(   NiR   i   (   R"   R   t   find(   R   R   RJ   R.   R   R   (    (    s    /usr/lib/python2.7/markupbase.pyt   _parse_doctype_element   s    	c         C   s  |  j  } |  j | |  \ } } | | | d !} | d k rB d S| d k rV | d Sx|  j | |  \ } } | d k  r | S| | | d !} | d k r d S| d k rd | | k r | j d |  d } n d Sx% | | | d !j   r| d } q W| | s,d Sn |  j | |  \ } } | | | d !} | sGd S| d k rt | |  } | rw| j   } n d S| | | d !} | sd Sn  | d	 k r| | d	 k rd S|  j | d |  \ } } | d k  r| S| | | d !} | sd Sn  | d k rY | d SqY d  S(
   Ni   R   iR   i    t   (t   )s   '"t   #(   R   R"   RM   RI   R&   R'   (   R   R   RJ   R   R.   R   R+   R-   (    (    s    /usr/lib/python2.7/markupbase.pyt   _parse_doctype_attlist  sZ    	
c         C   s   |  j  | |  \ } } | d k  r( | S|  j } x | | | d !} | sO d S| d k rc | d S| d k r t | |  } | s d S| j   } q4 |  j  | |  \ } } | d k  r4 | Sq4 d  S(   Ni    i   iR   s   '"(   R"   R   R&   R'   (   R   R   RJ   R.   R   R   R+   R-   (    (    s    /usr/lib/python2.7/markupbase.pyt   _parse_doctype_notation>  s$    	c         C   s1  |  j  } | | | d !d k rh | d } xA | | | d !} | sH d S| j   ra | d } q- Pq- n | } |  j | |  \ } } | d k  r | Sx |  j  | | d !} | s d S| d k r t | |  } | r | j   } q*d Sq | d k r| d S|  j | |  \ } } | d k  r | Sq d  S(   Ni   RE   ii    s   '"R   (   R   RI   R"   R&   R'   (   R   R   RJ   R   R   R+   R.   R-   (    (    s    /usr/lib/python2.7/markupbase.pyt   _parse_doctype_entityU  s8    	
c         C   s   |  j  } t |  } | | k r% d St | |  } | r | j   } | j   } | t |  | k rl d S| j   | j   f S|  j | |  |  j	 d | | | d ! d  S(   Nis   expected name token at %ri   (   Ni(   Ni(
   R   R   t   Nonet   _declname_matcht   groupt   stript   lowerR'   R   R   (   R   R   RJ   R   R)   R-   RK   R.   (    (    s    /usr/lib/python2.7/markupbase.pyR"   y  s    		c         C   s   d  S(   N(    (   R   R,   (    (    s    /usr/lib/python2.7/markupbase.pyR%     s    (   t   __name__t
   __module__t   __doc__R   R   R
   R   R   R#   R/   R!   R    R(   RN   RR   RS   RT   R"   R%   (    (    (    s    /usr/lib/python2.7/markupbase.pyR       s"   						R	C		9		$	(    (
   R\   t   ret   compileR>   RV   R&   R?   R8   R:   R    (    (    (    s    /usr/lib/python2.7/markupbase.pyt   <module>   s   