ó
5Þ	Pc           @   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   sb  |  j  } | d } | | | !d k s/ t d ‚ | | | d !d k rN | d S| | | d !d k ri 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 rH|  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 r5| d k r|  j | d | ƒ } qJ| d k r%|  j d | ƒ qJ|  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   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  rU | S| d k rz 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   ignores   includeR4   (   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(   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(   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 d  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 d  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   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   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_entityQ  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"   u  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"   						N	C		9		$	(    (
   R\   t   ret   compileR>   RV   R&   R?   R8   R:   R    (    (    (    s    /usr/lib/python2.7/markupbase.pyt   <module>   s   