ó
è¾bc           @   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.

iÿÿÿÿNs   [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   iÿÿÿÿs   --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   R   R   (   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   R2   R3   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()iÿÿÿÿi    (   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   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(   R   R   RB   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(   NiÿÿÿÿR   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 Wd  S(
   Ni   R   iÿÿÿÿR   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 Wd  S(   Ni    i   iÿÿÿÿR   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   s3  |  j  } | | | d !d k ri | d } xB | | | d !} | sH d S| j ƒ  ra | d } q- Pq- Wn | } |  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š Wd  S(   Ni   RE   iÿÿÿÿi    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(   Niÿÿÿÿs   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   