U
    hW?                     @   sX   d Z 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	e	Z
dS )
a  Shared support for scanning document type declarations in HTML and XHTML.

Backported for python-future from Python 3.3. Reason: ParserBase is an
old-style class in the Python 2.7 source of markupbase.py, which I suspect
might be the cause of sporadic unit-test failures on travis-ci.org with
test_htmlparser.py.  The test failures look like this:

    ======================================================================

ERROR: test_attr_entity_replacement (future.tests.test_htmlparser.AttributesStrictTestCase)

----------------------------------------------------------------------

Traceback (most recent call last):
  File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 661, in test_attr_entity_replacement
    [("starttag", "a", [("b", "&><"'")])])
  File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 93, in _run_check
    collector = self.get_collector()
  File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 617, in get_collector
    return EventCollector(strict=True)
  File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 27, in __init__
    html.parser.HTMLParser.__init__(self, *args, **kw)
  File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 135, in __init__
    self.reset()
  File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 143, in reset
    _markupbase.ParserBase.reset(self)

TypeError: unbound method reset() must be called with ParserBase instance as first argument (got EventCollector instance instead)

This module is used as a foundation for the html.parser module.  It has no
documented public API and should not be used directly.

    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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 )%
ParserBaseziParser 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d S )Nz)_markupbase.ParserBase must be subclassed)	__class__r   RuntimeErrorself r   N/var/www/html/venv/lib/python3.8/site-packages/future/backports/_markupbase.py__init__6   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offsetr   r   r   r   reset?   s    zParserBase.resetc                 C   s   | j | jfS )z&Return current line number and offset.r   r   r   r   r   getposC   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   nlinesposr   r   r   	updateposK   s    zParserBase.updatepos c           
      C   s  | j }|d }||| dks&td|||d  dkrB|d S |||d  dkrZdS t|}|||d  dkr| |S || d	kr| |S | ||\}}|d
k r|S |dkrd| _||k r|| }|dkr||d | }|dkr| | n
| | |d S |dkr<t	||}|s2dS |
 }n|dkrX| ||\}	}n|| jkrn|d }nj|d	kr|dkr| |d |}n0|tddddgkr| d|  n
| d n| d||   |d
k r|S qdS )N   <!z$unexpected call to parse_declarationr   >)-r   z--[r   doctyper   z"'4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZattlistlinktypelinkelementz&unsupported '[' char in %s declarationz"unexpected '[' char in declarationz!unexpected %r char in declaration)r   AssertionErrorlenparse_commentparse_marked_section
_scan_name_decl_othercharshandle_declunknown_decl_declstringlit_matchend_parse_doctype_subsetsetr   )
r   r   r   r   ndecltypecdatamnamer   r   r   parse_declaration[   s\    













zParserBase.parse_declarationr   c                 C   s   | j }|||d  dks"td| |d |\}}|dk rB|S |tddddd	gkrjt||d }n>|td
ddgkrt||d }n| d||d |   |sdS |r|d}| 	||d |  |
dS )N   z<![z)unexpected call to parse_marked_section()r   tempcdataignoreincludercdataifelseendifz+unknown status keyword %r in marked sectionr!   )r   r)   r-   r4   _markedsectionclosesearch_msmarkedsectioncloser   startr0   r2   )r   r   reportr   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"unexpected call to parse_comment()r!   r   )r   r   _commentcloserF   rH   handle_commentr2   )r   r   rI   r   rK   r   r   r   r   r+      s    

zParserBase.parse_commentc           
      C   s6  | j }t|}|}||k r2|| }|dkr<|||d  }|dkrJdS |dkrp| ||d  | d|  |d |krdS |d |krdS |||d  dkr| j|d	d
}|d	k r|S q| |d |\}}|dkrdS |tddddgkr| ||d  | d|  t| d| }	|	||}|d	k r0|S q|dkr|d |krXdS | |d |\}}|d	k rz|S || dkr0|d }q|dkr|d }||k r||  r|d }q||k r|| dkr|S | || | d ndS q| r|d }q| || | d|  qdS )N<r   r!   r   r   z*unexpected char in internal subset (in %r)rL   rM   r   )rI   r%   r(   entitynotationz)unknown declaration %r in internal subset_parse_doctype_%;]r   z%unexpected char after internal subsetz%unexpected char %r in internal subset)	r   r*   r   r   r+   r-   r4   getattrisspace)
r   r   declstartposr   r5   r   r7   sr:   methr   r   r   r3      sp    










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   rY   r:   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 | ||\}}|dk r^|S |||d  }|dkrzdS |dkrd||d  kr|d|d }ndS |||d   r|d }q||d  sdS n| ||\}}|||d  }|sdS |dkrDt||}|r&| }ndS |||d  }|sDdS |d	kr||d  d	krddS | |d |\}}|dk r|S |||d  }|sdS |dkrB|d S qBd S )
Nr   r   r!   r   r   ()'"#)r   r-   r\   rX   r1   r2   )r   r   rY   r   r:   r   r7   r9   r   r   r   _parse_doctype_attlist  sX    





z!ParserBase._parse_doctype_attlistc                 C   s   |  ||\}}|dk r|S | j}|||d  }|s:dS |dkrJ|d S |dkrnt||}|sddS | }q"|  ||\}}|dk r"|S q"d S )Nr   r   r!   r   r`   )r-   r   r1   r2   )r   r   rY   r:   r   r   r7   r9   r   r   r   _parse_doctype_notationX  s"    

z"ParserBase._parse_doctype_notationc                 C   s   | j }|||d  dkrR|d }|||d  }|s:dS | rP|d }q"qVq"n|}| ||\}}|dk rr|S | j ||d  }|sdS |dkrt||}|r| }qdS qr|dkr|d S | ||\}}|dk rr|S qrd S )Nr   rT   r!   r   r`   r   )r   rX   r-   r1   r2   )r   r   rY   r   r   r7   r:   r9   r   r   r   _parse_doctype_entityo  s4    


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lowerr2   r   r   )r   r   rY   r   r5   r9   rZ   r:   r   r   r   r-     s    
zParserBase._scan_namec                 C   s   d S )Nr   )r   r8   r   r   r   r0     s    zParserBase.unknown_declN)r   )r   )__name__
__module____qualname____doc__r	   r   r   r   r   r.   r;   r,   r+   r3   r]   rb   rc   rd   r-   r0   r   r   r   r   r   2   s"   R

C9$r   )rm   recompilerK   rf   r1   rN   rE   rG   objectr   r   r   r   r   <module>   s   "


