B
    u9a9  ã               @   sR   d dl Z e  d¡jZe  d¡jZe  d¡Ze  d¡Ze  d¡Z[ G dd„ dƒZdS )	é    Nz[a-zA-Z][-_.a-zA-Z0-9]*\s*z(\'[^\']*\'|"[^"]*")\s*z--\s*>z	]\s*]\s*>z]\s*>c               @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdZdd„ Z	d"dd„Z
d#dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )$Ú
ParserBasec             C   s   | j tkrtdƒ‚d S )Nz)_markupbase.ParserBase must be subclassed)Ú	__class__r   ÚRuntimeError)Úself© r   ú!/usr/lib/python3.7/_markupbase.pyÚ__init__   s    
zParserBase.__init__c             C   s   t dƒ‚d S )Nz.subclasses of ParserBase must override error())ÚNotImplementedError)r   Úmessager   r   r   Úerror    s    zParserBase.errorc             C   s   d| _ d| _d S )Né   r   )ÚlinenoÚoffset)r   r   r   r   Úreset$   s    zParserBase.resetc             C   s   | j | jfS )N)r   r   )r   r   r   r   Úgetpos(   s    zParserBase.getposc             C   sb   ||kr|S | j }| d||¡}|rN| j| | _| d||¡}||d  | _n| j| | | _|S )NÚ
r   )ÚrawdataÚcountr   Úrindexr   )r   ÚiÚjr   ZnlinesÚposr   r   r   Ú	updatepos0   s    zParserBase.updateposÚ c       
      C   sÊ  | j }|d }|||d … dkr*|d S |||d … dkrBdS t|ƒ}|||d … dkrh|  |¡S || dkr~|  |¡S |  ||¡\}}|dk rš|S |d	kr¨d
| _x||k rÄ|| }|dk rþ||d |… }|d	krì|  |¡ n
|  |¡ |d S |dkr&t||ƒ}|sdS | 	¡ }n|dkrB|  ||¡\}	}nt|| jkrX|d }n^|dkr¤|d	kr~|  
|d |¡}n$|dkr˜|  d| ¡ n
|  d¡ n|  d||  ¡ |dk r¬|S q¬W dS )Né   r   ú>)ú-r   éÿÿÿÿz--ú[r   Zdoctyper   z"'Z4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ>   ÚlinktypeÚlinkÚattlistÚelementz&unsupported '[' char in %s declarationz"unexpected '[' char in declarationz!unexpected %r char in declaration)r   ÚlenÚparse_commentÚparse_marked_sectionÚ
_scan_nameÚ_decl_othercharsZhandle_declÚunknown_declÚ_declstringlit_matchÚendÚ_parse_doctype_subsetr   )
r   r   r   r   ÚnZdecltypeÚcÚdataÚmÚnamer   r   r   Úparse_declaration@   sX    











zParserBase.parse_declarationr   c             C   sª   | j }|  |d |¡\}}|dk r&|S |dkr@t ||d ¡}n4|dkrZt ||d ¡}n|  d||d |…  ¡ |s|dS |r | d¡}|  ||d |… ¡ | d¡S )Né   r   >   ÚtempÚincludeÚignoreÚcdataÚrcdata>   ÚendifÚelseÚifz+unknown status keyword %r in marked sectionr   )	r   r&   Ú_markedsectioncloseÚsearchÚ_msmarkedsectioncloser   Ústartr(   r*   )r   r   Úreportr   ZsectNamer   Úmatchr   r   r   r%   ’   s    
zParserBase.parse_marked_sectionc             C   sj   | j }|||d … dkr$|  d¡ t ||d ¡}|s<dS |r`| d¡}|  ||d |… ¡ | d¡S )Né   z<!--z"unexpected call to parse_comment()r   r   )r   r   Ú_commentcloser<   r>   Zhandle_commentr*   )r   r   r?   r   r@   r   r   r   r   r$   ¨   s    

zParserBase.parse_commentc       
      C   s4  | j }t|ƒ}|}x||k r.|| }|dkr4|||d … }|dkrNdS |dkrt|  ||d ¡ |  d| ¡ |d |kr„dS |d |kr”dS |||d … dkrÄ| j|d	d
}|d	k r|S q|  |d |¡\}}|dkrädS |dkr|  ||d ¡ |  d| ¡ t| d| ƒ}	|	||ƒ}|d	k r,|S q|dkrŠ|d |krPdS |  |d |¡\}}|d	k rr|S || dkr,|d }q|dkrþ|d }x&||k rÂ||  ¡ rÂ|d }qžW ||k rø|| dkrà|S |  ||¡ |  d¡ ndS q| ¡ r|d }q|  ||¡ |  d| ¡ qW dS )Nú<r   r   z<!r   z*unexpected char in internal subset (in %r)rA   z<!--r   )r?   >   r!   ÚnotationÚentityr"   z)unknown declaration %r in internal subsetZ_parse_doctype_ú%ú;ú]r   z%unexpected char after internal subsetz%unexpected char %r in internal subset)r   r#   r   r   r$   r&   ÚgetattrÚisspace)
r   r   Údeclstartposr   r,   r   r-   Úsr0   Zmethr   r   r   r+   ¶   sn    











z ParserBase._parse_doctype_subsetc             C   sF   |   ||¡\}}|dkrdS | j}d||d … krB| d|¡d S dS )Nr   r   r   )r&   r   Úfind)r   r   rK   r0   r   r   r   r   r   Ú_parse_doctype_elementù   s    z!ParserBase._parse_doctype_elementc             C   sÀ  | j }|  ||¡\}}|||d … }|dkr2dS |dkrB|d S xv|  ||¡\}}|dk rb|S |||d … }|dkr~dS |dkràd||d … kr¨| d|¡d }ndS x |||d …  ¡ rÌ|d }q®W ||d … sðdS n|  ||¡\}}|||d … }|s
dS |dkrLt||ƒ}|r.| ¡ }ndS |||d … }|sLdS |d	kr¨||d … d	krldS |  |d |¡\}}|dk rŽ|S |||d … }|s¨dS |dkrF|d S qFW d S )
Nr   r   r   r   r   ú(ú)z'"ú#)r   r&   rM   rJ   r)   r*   )r   r   rK   r   r0   r   r-   r/   r   r   r   Ú_parse_doctype_attlist  sZ    




z!ParserBase._parse_doctype_attlistc             C   s”   |   ||¡\}}|dk r|S | j}xl|||d … }|s<dS |dkrL|d S |dkrpt||ƒ}|sfdS | ¡ }q$|   ||¡\}}|dk r$|S q$W d S )Nr   r   r   r   z'")r&   r   r)   r*   )r   r   rK   r0   r   r   r-   r/   r   r   r   Ú_parse_doctype_notation=  s$    

z"ParserBase._parse_doctype_notationc             C   sì   | j }|||d … dkrV|d }x6|||d … }|s<dS | ¡ rN|d }q$P q$W n|}|  ||¡\}}|dk rv|S xp| j ||d … }|s’dS |dkr¸t||ƒ}|r²| ¡ }qädS qx|dkrÈ|d S |  ||¡\}}|dk rx|S qxW d S )Nr   rF   r   r   z'"r   )r   rJ   r&   r)   r*   )r   r   rK   r   r   r-   r0   r/   r   r   r   Ú_parse_doctype_entityT  s8    


z ParserBase._parse_doctype_entityc             C   s†   | j }t|ƒ}||krdS t||ƒ}|r\| ¡ }| ¡ }|t|ƒ |krLdS | ¡ | ¡ fS |  ||¡ |  d|||d …  ¡ d S )N)Nr   zexpected name token at %ré   )	r   r#   Ú_declname_matchÚgroupÚstripÚlowerr*   r   r   )r   r   rK   r   r,   r/   rL   r0   r   r   r   r&   x  s    
zParserBase._scan_namec             C   s   d S )Nr   )r   r.   r   r   r   r(   Š  s    zParserBase.unknown_declN)r   )r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r'   r1   r%   r$   r+   rN   rR   rS   rT   r&   r(   r   r   r   r   r      s    R

C9$r   )	ÚreÚcompiler@   rV   r)   rB   r;   r=   r   r   r   r   r   Ú<module>   s   


