o
    Kûˆg:M  ã                   @   s  d Z ddlmZmZmZmZ ddlT ddlmZ ddl	Z	ddl
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¡Ze	 de	j¡Ze	 de	j¡Ze	 d¡Ze	 d¡ZG dd„ deƒZG dd„ dejƒZdS )zLA parser for HTML and XHTML.

Backported for python-future from Python 3.3.
é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literals)Ú*)Ú_markupbaseNz[&<]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--\s*>z(([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*z[a-zA-Z][^	
 /> ]*zJ\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?z]((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*aê  
  <[a-zA-Z][-.a-zA-Z0-9:_]*          # tag name
  (?:\s+                             # whitespace before attribute name
    (?:[a-zA-Z_][-.:a-zA-Z0-9_]*     # attribute name
      (?:\s*=\s*                     # value indicator
        (?:'[^']*'                   # LITA-enclosed value
          |\"[^\"]*\"                # LIT-enclosed value
          |[^'\">\s]+                # bare value
         )
       )?
     )
   )*
  \s*                                # trailing whitespace
aF  
  <[a-zA-Z][-.a-zA-Z0-9:_]*          # 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 comma
       )?(?:\s|/(?!>))*
     )*
   )?
  \s*                                # trailing whitespace
z#</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚHTMLParseErrorz&Exception raised for all parse errors.©NNc                 C   s&   |sJ ‚|| _ |d | _|d | _d S )Nr   é   ©ÚmsgÚlinenoÚoffset)Úselfr   Úposition© r   úa/var/www/html/status_management/venv/lib/python3.10/site-packages/future/backports/html/parser.pyÚ__init__U   s   
zHTMLParseError.__init__c                 C   s>   | j }| jd ur|d| j  }| jd ur|d| jd   }|S )Nz, at line %dz, column %dr   r   )r   Úresultr   r   r   Ú__str__[   s   

zHTMLParseError.__str__N)r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r	   R   s    
r	   c                   @   sì   e Zd ZdZdZd:dd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dZ
dd„ Zdd„ Zdd„ Zdd„ Z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*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ ZdS )<Ú
HTMLParseraÇ  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).  Entity references are
    passed by calling self.handle_entityref() with the entity
    reference as the argument.  Numeric character references are
    passed to self.handle_charref() with the string containing the
    reference as the argument.
    )ÚscriptÚstyleFc                 C   s&   |r
t jdtdd || _|  ¡  dS )zßInitialize and reset this instance.

        If strict is set to False (the default) the parser will parse invalid
        markup, otherwise it will raise an error.  Note that the strict mode
        is deprecated.
        zThe strict mode is deprecated.é   )Ú
stacklevelN)ÚwarningsÚwarnÚDeprecationWarningÚstrictÚreset)r   r#   r   r   r   r   z   s   ÿzHTMLParser.__init__c                 C   s(   d| _ d| _t| _d| _tj | ¡ dS )z1Reset this instance.  Loses all unprocessed data.Ú z???N)ÚrawdataÚlasttagÚinteresting_normalÚinterestingÚ
cdata_elemr   Ú
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.r   N)r-   r,   r   r   r   Úclose˜   s   zHTMLParser.closec                 C   s   t ||  ¡ ƒ‚©N)r	   Úgetpos)r   Úmessager   r   r   Úerrorœ   s   zHTMLParser.errorNc                 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_textc                 C   s$   |  ¡ | _t d| j tj¡| _d S )Nz</\s*%s\s*>)Úlowerr*   ÚreÚcompileÚIr)   )r   Úelemr   r   r   Úset_cdata_mode¥   s   
zHTMLParser.set_cdata_modec                 C   s   t | _d | _d S r2   )r(   r)   r*   r,   r   r   r   Úclear_cdata_mode©   s   
zHTMLParser.clear_cdata_modec           
      C   sŽ  | j }d}t|ƒ}||k r£| j ||¡}|r| ¡ }n| jr!n‚|}||k r0|  |||… ¡ |  ||¡}||kr<ng|j}|d|ƒrØt	 
||¡rP|  |¡}nG|d|ƒr[|  |¡}n<|d|ƒrf|  |¡}n1|d|ƒrq|  |¡}n&|d|ƒr…| jr|  |¡}n|  |¡}n|d |k r•|  d¡ |d }nn|dk rÑ|sŸn| jr§|  d¡ | d	|d ¡}|dk rÄ| d|d ¡}|dk rÃ|d }n|d7 }|  |||… ¡ |  ||¡}nÇ|d
|ƒr$t 
||¡}|r| ¡ dd… }	|  |	¡ | ¡ }|d|d ƒs|d }|  ||¡}q	d||d … v r#|  |dd… ¡ |  |d¡}n|d|ƒr›t 
||¡}|rT| d¡}	|  |	¡ | ¡ }|d|d ƒsM|d }|  ||¡}q	t 
||¡}|r…|r„| ¡ ||d … kr„| jru|  d¡ n||kr||}|  ||d ¡}n|d |k rš|  d¡ |  ||d ¡}nnJ dƒ‚||k s|r¾||k r¾| js¾|  |||… ¡ |  ||¡}||d … | _ d S )Nr   ú<ú</ú<!--ú<?ú<!r   zEOF in middle of constructr   ú&#r   éÿÿÿÿú;ú&z#EOF in middle of entity or char refzinteresting.search() lied)r&   Úlenr)   ÚsearchÚstartr*   Úhandle_dataÚ	updateposÚ
startswithÚstarttagopenÚmatchÚparse_starttagÚparse_endtagÚparse_commentÚparse_pir#   Úparse_declarationÚparse_html_declarationr5   ÚfindÚcharrefÚgroupÚhandle_charrefÚendÚ	entityrefÚhandle_entityrefÚ
incomplete)
r   rZ   r&   ÚiÚnrO   ÚjrM   ÚkÚnamer   r   r   r-   °   s°   









€




¦\zHTMLParser.goaheadc                 C   sº   | j }|||d … dksJ dƒ‚|||d … dkr |  |¡S |||d … dkr/|  |¡S |||d …  ¡ d	krX| d
|d ¡}|dkrIdS |  ||d |… ¡ |d S |  |¡S )Nr   rC   z+unexpected call to parse_html_declaration()é   rA   é   z<![é	   z	<!doctyper   rE   r   )r&   rR   Úparse_marked_sectionr8   rV   Úhandle_declÚparse_bogus_comment)r   r^   r&   Úgtposr   r   r   rU     s   


z!HTMLParser.parse_html_declarationr   c                 C   s`   | j }|||d … dv sJ dƒ‚| d|d ¡}|dkrdS |r,|  ||d |… ¡ |d S )Nr   )rC   r@   z"unexpected call to parse_comment()r   rE   r   )r&   rV   Úhandle_comment)r   r^   Úreportr&   Úposr   r   r   rh   -  s   zHTMLParser.parse_bogus_commentc                 C   sd   | j }|||d … dksJ dƒ‚t ||d ¡}|sdS | ¡ }|  ||d |… ¡ | ¡ }|S )Nr   rB   zunexpected call to parse_pi()rE   )r&   ÚpicloserI   rJ   Ú	handle_pirZ   )r   r^   r&   rO   r`   r   r   r   rS   9  s   zHTMLParser.parse_pic                 C   s"  d | _ |  |¡}|dk r|S | j}|||… | _ g }t ||d ¡}|s(J dƒ‚| ¡ }| d¡ ¡  | _}||k r¡| j	rDt
 ||¡}nt ||¡}|sMnT| ddd¡\}	}
}|
s\d }n-|d d… d  krn|dd … ksƒn |d d… d  kr|dd … kr‰n n|dd… }|r|  |¡}| |	 ¡ |f¡ | ¡ }||k s:|||…  ¡ }|d	vrñ|  ¡ \}}d
| j v rÌ|| j  d
¡ }t| j ƒ| j  d
¡ }n|t| j ƒ }| j	ræ|  d|||… d d… f ¡ |  |||… ¡ |S | d¡rþ|  ||¡ |S |  ||¡ || jv r|  |¡ |S )Nr   r   z#unexpected call to parse_starttag()r   rd   ú'rE   ú")r   ú/>Ú
z junk characters in start tag: %ré   rq   )r6   Úcheck_for_whole_start_tagr&   ÚtagfindrO   rZ   rX   r8   r'   r#   ÚattrfindÚattrfind_tolerantÚunescapeÚappendÚstripr3   ÚcountrH   Úrfindr5   rK   ÚendswithÚhandle_startendtagÚhandle_starttagÚCDATA_CONTENT_ELEMENTSr=   )r   r^   Úendposr&   ÚattrsrO   ra   ÚtagÚmÚattrnameÚrestÚ	attrvaluerZ   r   r   r   r   r   rP   E  sd   
&(
ð

ÿÿ
ý
zHTMLParser.parse_starttagc                 C   s  | j }| jrt ||¡}nt ||¡}|r}| ¡ }|||d … }|dkr)|d S |dkrY| d|¡r7|d S | d|¡r?dS | jrO|  ||d ¡ |  d¡ ||krU|S |d S |dkr_dS |d	v redS | jrs|  ||¡ |  d
¡ ||kry|S |d S t	dƒ‚)Nr   r   ú/rq   r   rE   zmalformed empty start tagr%   z6abcdefghijklmnopqrstuvwxyz=/ABCDEFGHIJKLMNOPQRSTUVWXYZzmalformed start tagzwe should not get here!)
r&   r#   ÚlocatestarttagendrO   Úlocatestarttagend_tolerantrZ   rM   rL   r5   ÚAssertionError)r   r^   r&   r„   r`   Únextr   r   r   rt   ~  s>   

z$HTMLParser.check_for_whole_start_tagc                 C   sJ  | j }|||d … dksJ dƒ‚t ||d ¡}|sdS | ¡ }t ||¡}|s|| jd ur9|  |||… ¡ |S | jrH|  	d|||… f ¡ t
 ||d ¡}|se|||d … dkr`|d S |  |¡S | ¡  ¡ }| d	| ¡ ¡}|  |¡ |d S | d¡ ¡ }| jd ur˜|| jkr˜|  |||… ¡ |S |  | ¡ ¡ |  ¡  |S )
Nr   r@   zunexpected call to parse_endtagr   rE   zbad end tag: %rrd   z</>r   )r&   Ú	endendtagrI   rZ   Ú
endtagfindrO   r*   rK   r#   r5   Útagfind_tolerantrh   rX   r8   rV   Úhandle_endtagr>   )r   r^   r&   rO   ri   Ú	namematchÚtagnamer<   r   r   r   rQ   ©  s<   




zHTMLParser.parse_endtagc                 C   s   |   ||¡ |  |¡ d S r2   )r   r   ©r   rƒ   r‚   r   r   r   r~   Ó  s   zHTMLParser.handle_startendtagc                 C   ó   d S r2   r   r“   r   r   r   r   Ø  ó   zHTMLParser.handle_starttagc                 C   r”   r2   r   )r   rƒ   r   r   r   r   Ü  r•   zHTMLParser.handle_endtagc                 C   r”   r2   r   ©r   rb   r   r   r   rY   à  r•   zHTMLParser.handle_charrefc                 C   r”   r2   r   r–   r   r   r   r\   ä  r•   zHTMLParser.handle_entityrefc                 C   r”   r2   r   r.   r   r   r   rK   è  r•   zHTMLParser.handle_datac                 C   r”   r2   r   r.   r   r   r   rj   ì  r•   zHTMLParser.handle_commentc                 C   r”   r2   r   )r   Údeclr   r   r   rg   ð  r•   zHTMLParser.handle_declc                 C   r”   r2   r   r.   r   r   r   rn   ô  r•   zHTMLParser.handle_pic                 C   s   | j r|  d|f ¡ d S d S )Nzunknown declaration: %r)r#   r5   r.   r   r   r   Úunknown_decl÷  s   ÿzHTMLParser.unknown_declc                 C   s"   d|vr|S dd„ }t  d||¡S )NrG   c                 S   sü   |   ¡ d } z-| d dkr2| dd … } | d dv r&t| dd …  d¡dƒ}nt|  d¡ƒ}t|ƒW S W n ty@   d|   Y S w ddlm} | |v rO||  S |  d¡rXd	|  S td
t	| ƒƒD ]}| d |… |v ry|| d |…  | |d …    S q_d	|  S )Nr   ú#r   )ÚxÚXrF   é   rD   )Úhtml5rG   r   )
ÚgroupsÚintÚrstripÚchrÚ
ValueErrorÚfuture.backports.html.entitiesr   r}   ÚrangerH   )ÚsÚcr   rš   r   r   r   ÚreplaceEntitiesÿ  s,   
úÿ
 ÿz,HTMLParser.unescape.<locals>.replaceEntitiesz&&(#?[xX]?(?:[0-9a-fA-F]+;|\w{1,32};?)))r9   Úsub)r   r¥   r§   r   r   r   rx   ü  s   ÿzHTMLParser.unescape)F)r   ) r   r   r   r   r€   r   r$   r0   r1   r5   r6   r7   r=   r>   r-   rU   rh   rS   rP   rt   rQ   r~   r   r   rY   r\   rK   rj   rg   rn   r˜   rx   r   r   r   r   r   d   s<    
	h
9+*r   ) r   Ú
__future__r   r   r   r   Úfuture.builtinsÚfuture.backportsr   r9   r    r:   r(   r]   r[   rW   rN   rm   Úcommentcloseru   r   rv   rw   ÚVERBOSEr‰   rŠ   r   rŽ   Ú	Exceptionr	   r+   r   r   r   r   r   Ú<module>   s>    








ÿÿóò

