o
    ¯N iW?  ã                   @   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u r	tdƒ‚d S )Nz)_markupbase.ParserBase must be subclassed)Ú	__class__r   ÚRuntimeError©Úself© r   úP/home/ubuntu/.local/lib/python3.10/site-packages/future/backports/_markupbase.pyÚ__init__6   s
   
ÿÿzParserBase.__init__c                 C   s   t dƒ‚)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   sd   ||kr|S | j }| d||¡}|r(| j| | _| d||¡}||d  | _|S | 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J dƒ‚|||d … dkr!|d S |||d … dv r-dS t|ƒ}|||d … dkr@|  |¡S || d	krK|  |¡S |  ||¡\}}|d
k rY|S |dkr`d| _||k rí|| }|dkrŠ||d |… }|dkr|  |¡ |d S |  |¡ |d S |dv rœt||ƒ}|s—dS | 	¡ }nG|dv r©|  ||¡\}	}n:|| jv r³|d }n0|d	krÚ|dkrÄ|  
|d |¡}n|tg d¢ƒv rÔ|  d| ¡ n|  d¡ n	|  d||  ¡ |d
k ré|S ||k sdd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   Ú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J dƒ‚|  |d |¡\}}|dk r!|S |tg d¢ƒv r2t ||d ¡}n|tg d¢ƒv rCt ||d ¡}n|  d||d |…  ¡ |sTdS |rf| 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,   r3   Ú_markedsectioncloseÚsearchÚ_msmarkedsectioncloser   Ústartr/   r1   )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 |r0| d¡}|  ||d |… ¡ | d¡S )Né   ú<!--z"unexpected call to parse_comment()r!   r   )r   r   Ú_commentcloserE   rG   Úhandle_commentr1   )r   r   rH   r   rJ   r   r   r   r   r*   Ã   s   


zParserBase.parse_commentc           
      C   s.  | j }t|ƒ}|}||k r|| }|dkr™|||d … }|dkr$dS |dkr7|  ||d ¡ |  d| ¡ |d |kr?dS |d |krGdS |||d … dkr_| j|d	d
}|d	k r^|S q	|  |d |¡\}}|dkrodS |tg d¢ƒvr†|  ||d ¡ |  d| ¡ t| d| ƒ}	|	||ƒ}|d	k r˜|S nx|dkrÀ|d |kr¥dS |  |d |¡\}}|d	k rµ|S || dkr¿|d }nQ|dkrú|d }||k rà||  ¡ rà|d }||k rà||  ¡ sÒ||k rø|| dkrì|S |  ||¡ |  d¡ ndS | ¡ r|d }n|  ||¡ |  d| ¡ ||k sdS )Nú<r   r!   r   r   z*unexpected char in internal subset (in %r)rK   rL   r   )rH   )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,   r3   ÚgetattrÚisspace)
r   r   Údeclstartposr   r4   r   r6   Úsr9   Úmethr   r   r   r2   Ñ   sx   
ÿ
ÿ€ÿ

Æ<z ParserBase._parse_doctype_subsetc                 C   sF   |   ||¡\}}|dkrdS | j}d||d … v r!| d|¡d S dS )Nr!   r   r   )r,   r   Úfind)r   r   rX   r9   r   r   r   r   r   Ú_parse_doctype_element  s   z!ParserBase._parse_doctype_elementc                 C   s¶  | j }|  ||¡\}}|||d … }|dkrdS |dkr!|d S 	 |  ||¡\}}|dk r0|S |||d … }|dkr>dS |dkrvd||d … v rS| d|¡d }ndS |||d …  ¡ rm|d }|||d …  ¡ s_||d … sudS n|  ||¡\}}|||d … }|sŠdS |dv r¨t||ƒ}|rš| ¡ }ndS |||d … }|s¨dS |d	krÒ||d … d	kr¶dS |  |d |¡\}}|dk rÆ|S |||d … }|sÒdS |dkrÚ|d S q")
Nr   r   r!   r   r   ú(ú)ú'"ú#)r   r,   r[   rW   r0   r1   )r   r   rX   r   r9   r   r6   r8   r   r   r   Ú_parse_doctype_attlist  s`   ÿþ

Òz!ParserBase._parse_doctype_attlistc                 C   sŽ   |   ||¡\}}|dk r|S | j}	 |||d … }|sdS |dkr&|d S |dv r8t||ƒ}|s3dS | ¡ }n|   ||¡\}}|dk rF|S q)Nr   r   r!   r   r_   )r,   r   r0   r1   )r   r   rX   r9   r   r   r6   r8   r   r   r   Ú_parse_doctype_notationX  s&   

ñz"ParserBase._parse_doctype_notationc                 C   sâ   | j }|||d … dkr*|d }	 |||d … }|sdS | ¡ r'|d }nnqn|}|  ||¡\}}|dk r:|S 	 | j ||d … }|sHdS |dv rZt||ƒ}|rX| ¡ }ndS |dkrb|d S |  ||¡\}}|dk rp|S q;)Nr   rS   r!   r   r_   r   )r   rW   r,   r0   r1   )r   r   rX   r   r   r6   r9   r8   r   r   r   Ú_parse_doctype_entityo  s>   
ù

ñz ParserBase._parse_doctype_entityc                 C   s†   | j }t|ƒ}||krdS t||ƒ}|r.| ¡ }| ¡ }|t|ƒ |kr&dS | ¡ | ¡ fS |  ||¡ |  d|||d …  ¡ d S )N)Nr!   zexpected name token at %ré   )	r   r)   Ú_declname_matchÚgroupÚstripÚlowerr1   r   r   )r   r   rX   r   r4   r8   rY   r9   r   r   r   r,   “  s   

ÿzParserBase._scan_namec                 C   s   d S )Nr   )r   r7   r   r   r   r/   ¥  s   zParserBase.unknown_declN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r-   r:   r+   r*   r2   r\   ra   rb   rc   r,   r/   r   r   r   r   r   2   s$    
R
C9$r   )rl   ÚreÚcompilerJ   re   r0   rM   rD   rF   Úobjectr   r   r   r   r   Ú<module>   s    "


