a
    #Rîh!P  ã                   @   sÞ   d Z ddlZddlZddlmZ dgZe d¡Ze d¡Ze d¡Z	e d¡Z
e d	¡Ze d
¡Ze d¡Ze d¡Ze d¡Ze d¡Ze dej¡Ze dej¡Ze dej¡Ze d¡Ze d¡ZG dd„ dejƒZdS )zA parser for HTML and XHTML.é    N)ÚunescapeÚ
HTMLParserz[&<]z
&[a-zA-Z#]z%&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]z)&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]z	<[a-zA-Z]z
</[a-zA-Z]ú>z--!?>z-?>z0([a-zA-Z][^\t\n\r\f />]*)(?:[\t\n\r\f ]|/(?!>))*a{  
  (
    (?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]*  # attribute name
   )
  ([\t\n\r\f ]*=[\t\n\r\f ]*        # value indicator
    ('[^']*'                        # LITA-enclosed value
    |"[^"]*"                        # LIT-enclosed value
    |(?!['"])[^>\t\n\r\f ]*         # bare value
    )
   )?
  (?:[\t\n\r\f ]|/(?!>))*           # possibly followed by a space
a  
  [a-zA-Z][^\t\n\r\f />]*           # tag name
  [\t\n\r\f /]*                     # optional whitespace before attribute name
  (?:(?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]*  # attribute name
    (?:[\t\n\r\f ]*=[\t\n\r\f ]*    # value indicator
      (?:'[^']*'                    # LITA-enclosed value
        |"[^"]*"                    # LIT-enclosed value
        |(?!['"])[^>\t\n\r\f ]*     # bare value
       )
     )?
    [\t\n\r\f /]*                   # possibly followed by a space
   )*
   >?
aF  
  <[a-zA-Z][^\t\n\r\f />\x00]*       # tag name
  (?:[\s/]*                          # optional whitespace before attribute name
    (?:(?<=['"\s/])[^\s/>][^\s/=>]*  # attribute name
      (?:\s*=+\s*                    # value indicator
        (?:'[^']*'                   # LITA-enclosed value
          |"[^"]*"                   # LIT-enclosed value
          |(?!['"])[^>\s]*           # bare value
         )
        \s*                          # possibly followed by a space
       )?(?:\s|/(?!>))*
     )*
   )?
  \s*                                # trailing whitespace
z#</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>c                   @   sþ   e Zd ZdZdZdZddœdd„Zdd	„ Zd
d„ Zdd„ Z	dZ
dd„ Zddœdd„Zdd„ Zd>dd„Zd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d0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z dS )Ar   aE  Find tags and other markup and call handler functions.

    Usage:
        p = HTMLParser()
        p.feed(data)
        ...
        p.close()

    Start tags are handled by calling self.handle_starttag() or
    self.handle_startendtag(); end tags by self.handle_endtag().  The
    data between tags is passed from the parser to the derived class
    by calling self.handle_data() with the data as argument (the data
    may be split up in arbitrary chunks).  If convert_charrefs is
    True the character references are converted automatically to the
    corresponding Unicode character (and self.handle_data() is no
    longer split in chunks), otherwise they are passed by calling
    self.handle_entityref() or self.handle_charref() with the string
    containing respectively the named or numeric reference as the
    argument.
    )ZscriptÚstyle)ZtextareaÚtitleT)Úconvert_charrefsc                C   s   || _ |  ¡  dS )zÆInitialize and reset this instance.

        If convert_charrefs is True (the default), all character references
        are automatically converted to the corresponding Unicode characters.
        N)r   Úreset)Úselfr   © r
   ú3/opt/python-3.9.24/usr/lib/python3.9/html/parser.pyÚ__init__s   s    zHTMLParser.__init__c                 C   s4   d| _ d| _t| _d| _d| _d| _tj 	| ¡ dS )z1Reset this instance.  Loses all unprocessed data.Ú z???NT)
ÚrawdataÚlasttagÚinteresting_normalÚinterestingÚ
cdata_elemÚ_support_cdataÚ
_escapableÚ_markupbaseÚ
ParserBaser   ©r	   r
   r
   r   r   |   s    zHTMLParser.resetc                 C   s   | j | | _ |  d¡ dS )z‘Feed data to the parser.

        Call this as often as you want, with as little or as much text
        as you want (may include '\n').
        r   N)r   Úgoahead©r	   Údatar
   r
   r   Úfeed†   s    zHTMLParser.feedc                 C   s   |   d¡ dS )zHandle any buffered data.é   N)r   r   r
   r
   r   Úclose   s    zHTMLParser.closeNc                 C   s   | j S )z)Return full source of start tag: '<...>'.)Ú_HTMLParser__starttag_textr   r
   r
   r   Úget_starttag_text•   s    zHTMLParser.get_starttag_textF©Ú	escapablec                C   sX   |  ¡ | _|| _|r8| js8t d| j tjtjB ¡| _nt d| j tjtjB ¡| _d S )Nz&|</%s(?=[\t\n\r\f />])z</%s(?=[\t\n\r\f />]))	Úlowerr   r   r   ÚreÚcompileÚ
IGNORECASEÚASCIIr   )r	   Úelemr!   r
   r
   r   Úset_cdata_mode™   s    


ÿ
ÿzHTMLParser.set_cdata_modec                 C   s   t | _d | _d| _d S )NT)r   r   r   r   r   r
   r
   r   Úclear_cdata_mode£   s    zHTMLParser.clear_cdata_modec                 C   s
   || _ dS )a  Enable or disable support of the CDATA sections.
        If enabled, "<[CDATA[" starts a CDATA section which ends with "]]>".
        If disabled, "<[CDATA[" starts a bogus comments which ends with ">".

        This method is not called by default. Its purpose is to be called
        in custom handle_starttag() and handle_endtag() methods, with
        value that depends on the adjusted current node.
        See https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
        for details.
        N)r   )r	   Úflagr
   r
   r   Ú_set_support_cdata¨   s    zHTMLParser._set_support_cdatac                 C   s4  | j }d}t|ƒ}||k rÌ| jrv| jsv| d|¡}|dk r | dt||d ƒ¡}|dkrpt d¡ 	||¡spqÌ|}n*| j
 	||¡}|r’| ¡ }n| jrœqÌ|}||k rÞ| jrÌ| jrÌ|  t|||… ƒ¡ n|  |||… ¡ |  ||¡}||kröqÌ|j}|d|ƒr<t ||¡r"|  |¡}	nŒ|d|ƒr:|  |¡}	nt|d|ƒrR|  |¡}	n\|d|ƒrj|  |¡}	nD|d	|ƒr‚|  |¡}	n,|d
 |k s–|rÌ|  d¡ |d
 }	nqÌ|	dk r.|sÂqÌt ||¡rÔnV|d|ƒr$|d |krú|  d¡ n&t ||¡r
n|  ||d d … ¡ n|d|ƒr||}dD ]*}
| |
|d ¡r8|t|
ƒ8 } qdq8|  ||d |… ¡ n®|d|ƒr¨| jr¨|  ||d d … ¡ n‚|||d …  ¡ dkrÚ|  ||d d … ¡ nP|d	|ƒrþ|  ||d d … ¡ n,|d|ƒr"|  ||d d … ¡ nt dƒ‚|}	|  ||	¡}q|d|ƒrât! ||¡}|r¤| "¡ dd… }|  #|¡ | $¡ }	|d|	d
 ƒs”|	d
 }	|  ||	¡}qn<d||d … v rÌ|  |||d … ¡ |  ||d ¡}qÌq|d|ƒrt% ||¡}|r@| "d
¡}|  &|¡ | $¡ }	|d|	d
 ƒs2|	d
 }	|  ||	¡}qt' ||¡}|rš|rÌ| "¡ ||d … krÌ| $¡ }	|	|kr„|}	|  ||d
 ¡}qÌn.|d
 |k rÌ|  d¡ |  ||d
 ¡}nqÌqq|r"||k r"| jr| jr|  t|||… ƒ¡ n|  |||… ¡ |  ||¡}||d … | _ d S )Nr   ú<ú&é"   z[\t\n\r\f ;]z</ú<!--z<?z<!r   é   )z--!z--ú-é   ú	<![CDATA[é   é	   ú	<!doctypezwe should not get here!z&#éÿÿÿÿú;)(r   Úlenr   r   ÚfindÚrfindÚmaxr#   r$   Úsearchr   Ústartr   Úhandle_datar   Z	updateposÚ
startswithÚstarttagopenÚmatchÚparse_starttagÚparse_endtagÚparse_commentÚparse_piÚparse_html_declarationÚ
endtagopenÚhandle_commentÚendswithr   Úunknown_declr"   Úhandle_declÚ	handle_piÚAssertionErrorÚcharrefÚgroupÚhandle_charrefÚendÚ	entityrefÚhandle_entityrefÚ
incomplete)r	   rR   r   ÚiÚnÚjZampposrB   r@   ÚkÚsuffixÚnamer
   r
   r   r   ¸   sâ    
ÿ










zHTMLParser.goaheadc                 C   sX  | j }|||d … dkr$|  |¡S |||d … dkrx| jrx| d|d ¡}|dk rZdS |  ||d |… ¡ |d S |||d …  ¡ d	krÊ| d
|d ¡}|dkr¬dS |  ||d |… ¡ |d S |||d … dkrJ| d
|d ¡}|dk  rþdS ||d  dkr,|  ||d |d … ¡ n|  ||d |… ¡ |d S |  |¡S d S )Nr2   r/   r5   r3   z]]>r   r7   r4   r6   r   r0   r   z<![ú])	r   rE   r   r:   rK   r"   rL   rI   Úparse_bogus_comment)r	   rV   r   rX   Zgtposr
   r
   r   rG   D  s0    

z!HTMLParser.parse_html_declarationc                 C   s\   | j }t ||d ¡}|s2t ||d ¡}|s2dS |rT| ¡ }|  ||d |… ¡ | ¡ S )Nr2   r7   )r   Úcommentcloser=   ÚcommentabruptcloserB   r>   rI   rR   )r	   rV   Úreportr   rB   rX   r
   r
   r   rE   f  s    zHTMLParser.parse_commentr   c                 C   sD   | j }| d|d ¡}|dkr"dS |r<|  ||d |… ¡ |d S )Nr   r0   r7   r   )r   r:   rI   )r	   rV   r`   r   Úposr
   r
   r   r]   u  s    zHTMLParser.parse_bogus_commentc                 C   sH   | j }t ||d ¡}|sdS | ¡ }|  ||d |… ¡ | ¡ }|S )Nr0   r7   )r   Úpicloser=   r>   rM   rR   ©r	   rV   r   rB   rX   r
   r
   r   rF     s    zHTMLParser.parse_pic                 C   sú  d | _ |  |¡}|dk r|S | j}|||… | _ g }t ||d ¡}| ¡ }| d¡ ¡  | _}||k r t	 ||¡}|s~q | ddd¡\}	}
}|
sœd }nZ|d d… d  krÀ|dd … ksên |d d… d  kræ|dd … krön n|dd… }|rt
|ƒ}| |	 ¡ |f¡ | ¡ }q`|||…  ¡ }|dvrž|  ¡ \}}d	| j v rz|| j  d	¡ }t| j ƒ| j  d	¡ }n|t| j ƒ }|  |||… ¡ |S | d
¡r¸|  ||¡ n>|  ||¡ || jv rÜ|  |¡ n|| jv rö| j|dd |S )Nr   r   r0   r4   ú'r7   ú")r   ú/>Ú
rf   Tr    )r   Úcheck_for_whole_start_tagr   Útagfind_tolerantrB   rR   rP   r"   r   Úattrfind_tolerantr   ÚappendÚstripZgetposÚcountr9   r;   r?   rJ   Úhandle_startendtagÚhandle_starttagÚCDATA_CONTENT_ELEMENTSr(   ÚRCDATA_CONTENT_ELEMENTS)r	   rV   Úendposr   ÚattrsrB   rY   ÚtagÚmÚattrnameÚrestZ	attrvaluerR   ÚlinenoÚoffsetr
   r
   r   rC     s\    

&ÿ
ÿ



ÿzHTMLParser.parse_starttagc                 C   s6   | j }t ||d ¡}| ¡ }||d  dkr2dS |S )Nr   r   r7   )r   ÚlocatetagendrB   rR   rc   r
   r
   r   rh   Ä  s    z$HTMLParser.check_for_whole_start_tagc                 C   s´   | j }| d|d ¡dk rdS t ||¡sT||d |d … dkrJ|d S |  |¡S t ||d ¡}| ¡ }||d  dkr€dS t ||d ¡}| d¡ 	¡ }|  
|¡ |  ¡  |S )Nr   r0   r   r7   r4   r   )r   r:   rH   rB   r]   rz   rR   ri   rP   r"   Úhandle_endtagr)   )r	   rV   r   rB   rX   rt   r
   r
   r   rD   Î  s     

zHTMLParser.parse_endtagc                 C   s   |   ||¡ |  |¡ d S ©N)ro   r{   ©r	   rt   rs   r
   r
   r   rn   ì  s    zHTMLParser.handle_startendtagc                 C   s   d S r|   r
   r}   r
   r
   r   ro   ñ  s    zHTMLParser.handle_starttagc                 C   s   d S r|   r
   )r	   rt   r
   r
   r   r{   õ  s    zHTMLParser.handle_endtagc                 C   s   d S r|   r
   ©r	   r[   r
   r
   r   rQ   ù  s    zHTMLParser.handle_charrefc                 C   s   d S r|   r
   r~   r
   r
   r   rT   ý  s    zHTMLParser.handle_entityrefc                 C   s   d S r|   r
   r   r
   r
   r   r?     s    zHTMLParser.handle_datac                 C   s   d S r|   r
   r   r
   r
   r   rI     s    zHTMLParser.handle_commentc                 C   s   d S r|   r
   )r	   Zdeclr
   r
   r   rL   	  s    zHTMLParser.handle_declc                 C   s   d S r|   r
   r   r
   r
   r   rM     s    zHTMLParser.handle_pic                 C   s   d S r|   r
   r   r
   r
   r   rK     s    zHTMLParser.unknown_decl)T)T)r   )!Ú__name__Ú
__module__Ú__qualname__Ú__doc__rp   rq   r   r   r   r   r   r   r(   r)   r+   r   rG   rE   r]   rF   rC   rh   rD   rn   ro   r{   rQ   rT   r?   rI   rL   rM   rK   r
   r
   r
   r   r   Z   s>   	
	

 "

7
)r‚   r#   r   Zhtmlr   Ú__all__r$   r   rU   rS   rO   rA   rH   rb   r^   r_   ri   ÚVERBOSErj   rz   Zlocatestarttagend_tolerantZ	endendtagZ
endtagfindr   r   r
   r
   r
   r   Ú<module>   s4   











õóò

