
    -hhP                        S r SSKrSSKrSSKJr  SSKJr  S/r\R                  " S5      r
\R                  " S5      r\R                  " S5      r\R                  " S	5      r\R                  " S
5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S\R*                  5      r\R                  " S\R*                  5      r\R                  " S\R*                  5      r\R                  " S5      r\R                  " S5      rS rS r " S S\R:                  5      rg)zA parser for HTML and XHTML.    N)unescape)html5
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]z6&(#[0-9]+|#[xX][0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*)[;=]?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                     U R                  S5      nUR                  S5      (       a  [        U5      $ UR                  S5      (       d  USS  [        ;   a  [        U5      $ U$ )Nr   &#=   )group
startswithr   endswithhtml5_entities)matchrefs     4/opt/python-3.13.8/usr/lib/python3.13/html/parser.py_replace_attr_charrefr   \   sU    
++a.C
~~d} <<QRN!:}J    c                 6    [         R                  [        U 5      $ N)attr_charrefsubr   )ss    r   _unescape_attrvaluer   h   s    1155r   c                      ^  \ rS rSrSrSrSrSS.U 4S jjrU 4S jrS	 r	S
 r
SrS rSS.S jrS rS%S jrS rS rS%S jrS&S jrS rS rS rS rS rS rS rS rS rS rS  rS! rS" r S# r!S$r"U =r#$ )'r   l   a  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.
)scriptstyle)textareatitleT)convert_charrefsc                N   > [         TU ]  5         Xl        U R                  5         g)zInitialize and reset this instance.

If convert_charrefs is True (the default), all character references
are automatically converted to the corresponding Unicode characters.
N)super__init__r    reset)selfr    	__class__s     r   r#   HTMLParser.__init__   s     	 0

r   c                 ~   > SU l         SU l        [        U l        SU l        SU l        SU l        [        TU ]!  5         g)z1Reset this instance.  Loses all unprocessed data. z???NT)	rawdatalasttaginteresting_normalinteresting
cdata_elem_support_cdata
_escapabler"   r$   )r%   r&   s    r   r$   HTMLParser.reset   s8    -"r   c                 N    U R                   U-   U l         U R                  S5        g)zyFeed 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%   datas     r   feedHTMLParser.feed   s     ||d*Qr   c                 &    U R                  S5        g)zHandle any buffered data.r
   N)r3   r%   s    r   closeHTMLParser.close   s    Qr   Nc                     U R                   $ )z)Return full source of start tag: '<...>'.)_HTMLParser__starttag_textr9   s    r   get_starttag_textHTMLParser.get_starttag_text   s    ###r   F	escapablec                   UR                  5       U l        X l        U(       aZ  U R                  (       dI  [        R
                  " SU R                  -  [        R                  [        R                  -  5      U l        g [        R
                  " SU R                  -  [        R                  [        R                  -  5      U l        g )Nz&|</%s(?=[\t\n\r\f />])z</%s(?=[\t\n\r\f />]))	lowerr.   r0   r    recompile
IGNORECASEASCIIr-   )r%   elemrA   s      r   set_cdata_modeHTMLParser.set_cdata_mode   s}    **,#T22!zz*Dt*V*,--*@ BD  "zz*BT__*T*,--*@ BDr   c                 6    [         U l        S U l        SU l        g )NT)r,   r-   r.   r0   r9   s    r   clear_cdata_modeHTMLParser.clear_cdata_mode   s    -r   c                     Xl         g)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%   flags     r   _set_support_cdataHTMLParser._set_support_cdata   s
     #r   c                    U R                   nSn[        U5      nX4:  Ga  U R                  (       a|  U R                  (       dk  UR	                  SU5      nUS:  aR  UR                  S[        X4S-
  5      5      nUS:  a,  [        R                  " S5      R                  X&5      (       d  GO=UnOHU R                  R                  X#5      nU(       a  UR                  5       nOU R                  (       a  GOUnX5:  aR  U R                  (       a.  U R                  (       a  U R                  [        X#U 5      5        OU R                  X#U 5        U R                  X55      nX4:X  a  GOUR                   nU" SU5      (       Ga  ["        R%                  X#5      (       a  U R'                  U5      n	OU" SU5      (       a  U R)                  U5      n	OU" SU5      (       a  U R+                  U5      n	OiU" SU5      (       a  U R-                  U5      n	OIU" S	U5      (       a  U R/                  U5      n	O)US
-   U:  d  U(       a  U R                  S5        US
-   n	OGOU	S:  Ga  U(       d  GO["        R%                  X#5      (       a  GOrU" SU5      (       aP  US-   U:X  a  U R                  S5        GOH[0        R%                  X#5      (       a  GO,U R3                  X#S-   S  5        GOU" SU5      (       aK  UnS H,  n
UR5                  XS-   5      (       d  M  U[        U
5      -  n  O   U R3                  X#S-   U 5        OU" SU5      (       a(  U R6                  (       a  U R9                  X#S-   S  5        OX#US-    R;                  5       S:X  a  U R=                  X#S-   S  5        OUU" S	U5      (       a  U R3                  X#S-   S  5        O0U" SU5      (       a  U R?                  X#S-   S  5        O[A        S5      eUn	U R                  X95      nGOU" SU5      (       a  [B        R%                  X#5      nU(       a^  URE                  5       SS nU RG                  U5        URI                  5       n	U" SU	S
-
  5      (       d  U	S
-
  n	U R                  X95      nGMu  SX#S  ;   a*  U R                  X#US-    5        U R                  X3S-   5      nGO$U" SU5      (       Ga  [J        R%                  X#5      nU(       a\  URE                  S
5      nU RM                  U5        URI                  5       n	U" SU	S
-
  5      (       d  U	S
-
  n	U R                  X95      nGM0  [N        R%                  X#5      nU(       aI  U(       aA  URE                  5       X#S  :X  a+  URI                  5       n	X::  a  Un	U R                  X3S
-   5      nO8US
-   U:  a&  U R                  S5        U R                  X3S
-   5      nOOX4:  a  GM  U(       ah  X4:  ac  U R                  (       a.  U R                  (       a  U R                  [        X#U 5      5        OU R                  X#U 5        U R                  X45      nX#S  U l         g )Nr   <&"   z[\t\n\r\f ;]z</<!--z<?z<!r
      )z--!z---   	<![CDATA[   	   	<!doctypezwe should not get here!r   ;)(r*   lenr    r.   findrfindmaxrD   rE   searchr-   startr0   handle_datar   	updateposr   starttagopenr   parse_starttagparse_endtagparse_commentparse_piparse_html_declaration
endtagopenhandle_commentr   r/   unknown_declrC   handle_decl	handle_piAssertionErrorcharrefr   handle_charrefend	entityrefhandle_entityref
incomplete)r%   rv   r*   injampposr   r   ksuffixnames               r   r3   HTMLParser.goahead   sg   ,,Le$$T__LLa(q5 %]]3At=F!JJ7>>wOOA((//;AAu((T__$$Xgl%;<$$Wq\2q$Avu ++J#q!!%%g11++A.Aa(())!,A****1-Aa((a(Aa((33A6A!eq[C$$S)AAq5#))'55#D!,,q5A: ,,T2'--g99  !//!>#FA..&8F&//!<< !S[ 0 % '9 ++GaCN;#K338K8K))'A#$-8 1Q3--/;>((17#D!,,++GaCDM:#D!,,wst}5,-FGGANN1(D!$$g1 ;;=2.D''-		A%c1Q3//Eq,Agbk)((1Q38 NN1c2C##!3 ;;q>D))$/		A%c1Q3//Eq,A"((4u{{};!IIK6 !A NN1!e4!eq[ $$S)qa%0As ez 15$$  'A,!78  1.q$Ar{r   c                    U R                   nX!US-    S:X  a  U R                  U5      $ X!US-    S:X  aH  U R                  (       a7  UR                  SUS-   5      nUS:  a  gU R	                  X!S-   U 5        US-   $ X!US-    R                  5       S	:X  a7  UR                  S
US-   5      nUS:X  a  gU R                  X!S-   U 5        US-   $ U R                  U5      $ )NrY   rV   r\   rZ   z]]>r   r^   r[   r]   r   rW   r
   )r*   rk   r/   ra   rp   rC   rq   parse_bogus_comment)r%   rz   r*   r|   gtposs        r   rm   !HTMLParser.parse_html_declarationW  s    ,, QqS>V#%%a((qs^{*t/B/BUAaC(A1ugc1o.q5Lqs^!!#{2LLac*E{WqS/07N++A..r   c                    U R                   n[        R                  X1S-   5      nU(       d   [        R	                  X1S-   5      nU(       d  gU(       a&  UR                  5       nU R                  X1S-   U 5        UR                  5       $ )NrY   r^   )r*   commentcloserd   commentabruptcloser   re   ro   rv   )r%   rz   reportr*   r   r|   s         r   rk   HTMLParser.parse_commentp  sl    ,,##GqS1&,,Wc:EA!Q0yy{r   c                     U R                   nUR                  SUS-   5      nUS:X  a  gU(       a  U R                  X1S-   U 5        US-   $ )Nr   rW   r^   r
   )r*   ra   ro   )r%   rz   r   r*   poss        r   r   HTMLParser.parse_bogus_comment  sN    ,, ll3!$"9!C 01Qwr   c                     U R                   n[        R                  X!S-   5      nU(       d  gUR                  5       nU R	                  X!S-   U 5        UR                  5       nU$ )NrW   r^   )r*   picloserd   re   rr   rv   r%   rz   r*   r   r|   s        r   rl   HTMLParser.parse_pi  sR    ,,w!,KKMwsA'IIKr   c                    S U l         U R                  U5      nUS:  a  U$ U R                  nX1U U l         / n[        R	                  X1S-   5      nUR                  5       nUR                  S5      R                  5       =U l        nXb:  a  [        R	                  X65      nU(       d  OUR                  SSS5      u  pnU
(       d  S nO0US S Ss=:X  a	  USS  :X  d  O  US S Ss=:X  a	  USS  :X  a  O  OUSS nU(       a  [        U5      nUR                  U	R                  5       U45        UR                  5       nXb:  a  M  X6U R                  5       nUS;  a  U R                  X1U 5        U$ UR                  S	5      (       a  U R                  Xt5        U$ U R!                  Xt5        XpR"                  ;   a  U R%                  U5        U$ XpR&                  ;   a  U R%                  US
S9  U$ )Nr   r
   rW   r[   'r^   ")r   />r   Tr@   )r=   check_for_whole_start_tagr*   tagfind_tolerantr   rv   r   rC   r+   attrfind_tolerantr   appendstriprf   r   handle_startendtaghandle_starttagCDATA_CONTENT_ELEMENTSrI   RCDATA_CONTENT_ELEMENTS)r%   rz   endposr*   attrsr   r~   tagmattrnamerest	attrvaluerv   s                r   ri   HTMLParser.parse_starttag  s     $//2A:M,,&0  &&w!4IIK"[[^1133sj!''3A()1a(8%HI 	2A$8)BC.82A#7237%aO	/	:	LL(..*I67A j %%'k!Wv./M<<##C/    ,111##C(  444##C4#8r   c                     U R                   n[        R                  X!S-   5      nUR                  5       nX$S-
     S:w  a  gU$ )Nr
   r   r^   )r*   locatetagendr   rv   r   s        r   r   $HTMLParser.check_for_whole_start_tag  s@    ,,""7aC0IIKQ3<3r   c                    U R                   nUR                  SUS-   5      S:  a  g[        R                  X!5      (       d$  X!S-   US-    S:X  a  US-   $ U R	                  U5      $ [
        R                  X!S-   5      nUR                  5       nX$S-
     S:w  a  g[        R                  X!S-   5      nUR                  S5      R                  5       nU R                  U5        U R                  5         U$ )Nr   rW   r   r^   r[   r
   )r*   ra   rn   r   r   r   rv   r   r   rC   handle_endtagrL   )r%   rz   r*   r   r|   r   s         r   rj   HTMLParser.parse_endtag  s     ,,<<QqS!A%++s1Q33&s
//22""7aC0IIKQ3<3 !&&w!4kk!n""$3r   c                 H    U R                  X5        U R                  U5        g r   )r   r   r%   r   r   s      r   r   HTMLParser.handle_startendtag  s    S(3r   c                     g r    r   s      r   r   HTMLParser.handle_starttag      r   c                     g r   r   )r%   r   s     r   r   HTMLParser.handle_endtag  r   r   c                     g r   r   r%   r   s     r   ru   HTMLParser.handle_charref  r   r   c                     g r   r   r   s     r   rx   HTMLParser.handle_entityref   r   r   c                     g r   r   r4   s     r   rf   HTMLParser.handle_data  r   r   c                     g r   r   r4   s     r   ro   HTMLParser.handle_comment  r   r   c                     g r   r   )r%   decls     r   rq   HTMLParser.handle_decl  r   r   c                     g r   r   r4   s     r   rr   HTMLParser.handle_pi  r   r   c                     g r   r   r4   s     r   rp   HTMLParser.unknown_decl  r   r   )__starttag_textr0   r/   r.   r    r-   r+   r*   )T)r
   )$__name__
__module____qualname____firstlineno____doc__r   r   r#   r$   r6   r:   r=   r>   rI   rL   rP   r3   rm   rk   r   rl   ri   r   rj   r   r   r   ru   rx   rf   ro   rq   rr   rp   __static_attributes____classcell__)r&   s   @r   r   r   l   s    * 13+/   O$ 16 B
# G#X/2		,`< 
 r   )r   rD   _markupbasehtmlr   html.entitiesr   r   __all__rE   r,   ry   rw   rt   r   rh   rn   r   r   r   r   VERBOSEr   r   locatestarttagend_tolerant	endendtag
endtagfindr   r   
ParserBaser   r   r   r   <module>r      sY   " 
   1 . ZZ' ZZ%
JJ>?	
**@
AzzSTzz+&ZZ%

**S/zz(#ZZ'  ::QR JJ   ZZ  zz  ZZ   ZZ ) ZZ  JJsO	ZZ>?

6h'' hr   