+
    Ŝi                       a  R t*0 t R tRt^ RIt^ RIHt ^ RIHt ^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHtHtHtHtHtHt ]'       d   ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RItR	 R
 ltRR R llt ! R R]4      tR R ltRt ] ^ k Rt!] ^k R R R llt"R!R R llt#R"R R llt$R#R R llt%R$R R llt&]'R8X  d#   ]! ]PP                  PS                  4       4       R# R# )%z=Diagnostic functions, mainly for use when doing tech support.MITN)BytesIO)
HTMLParser)BeautifulSoup__version__)builder_registry)AnyIOListOptionalTupleTYPE_CHECKING)_IncomingMarkupc                     V ^8  d   QhRRRR/# )   datar   returnN )formats   "U/Users/mibo/.openclaw/workspace/.venv-ak/lib/python3.14/site-packages/bs4/diagnose.py__annotate__r       s     5 5$ 5 5    c           	        \        R\        ,          4       \        R\        P                  ,          4       . ROpV FP  p\        P
                   F  pW#P                  9   g   K   K+  	  VP                  V4       \        RV,          4       KR  	  RV9   dR   TP                  R4        ^ RI	H
p \        RR	P                  \        \        VP                  4      4      ,          4       RV9   d"    ^ RIp\        RVP                  ,          4       \#        V R4      '       d   V P%                  4       p V Fd  p\        RV,          4       Rp \'        WR7      pRpV'       d,   \        RV,          4       \        XP/                  4       4       \        R4       Kf  	  R#   \         d    \        R
4        Li ; i  \         d    \        R4        Li ; i  \(         d+    \        RT,          4       \*        P,                  ! 4         Li ; i)zDiagnostic suite for isolating common problems.

:param data: Some markup that needs to be explained.
:return: None; diagnostics are printed to standard output.
z'Diagnostic running on Beautiful Soup %szPython version %shtml5liblxmlz;I noticed that %s is not installed. Installing it may help.zlxml-xmletreezFound lxml version %s.z.lxml is not installed or couldn't be imported.NzFound html5lib version %sz2html5lib is not installed or couldn't be imported.readz#Trying to parse your markup with %sF)featuresT%s could not parse the markup.z#Here's what %s did with the markup:)html.parserr   r   zP--------------------------------------------------------------------------------)printr   sysversionr   buildersr   removeappendr   r   joinmapstrLXML_VERSIONImportErrorr   hasattrr   r   	Exception	traceback	print_excprettify)	r   basic_parsersnamebuilderr   r   parsersuccesssoups	   &        r   diagnoser8       s    
4{BD	,.7M'00G''' 1   &NQUU  Z(	D"*SXXc#u?Q?Q6R-SSU ]"	H.1E1EEG tVyy{4v=?	" 7DG 86AC4==?$x    	DBC	D  	HFG	H  	"3f<>!	"s6   *?F 1 F; GF87F8;GG2HHc                8    V ^8  d   QhRRR\         R\        RR/# )r   r   r   htmlkwargsr   N)boolr   )r   s   "r   r   r   X   s/     D D& Dd DS DT Dr   c                \   ^ RI Hp VP                  RR4      p\        V \        4      '       d   V P                  R4      p \        V \        4      '       g   \        V 4      pVP                  ! X3RVRV/VB  F0  w  rg\        V: RVP                  :R RVP                  : 24       K2  	  R# )	a  Print out the lxml events that occur during parsing.

This lets you see how lxml parses a document when no Beautiful
Soup code is running. You can use this to determine whether
an lxml-specific problem is in Beautiful Soup's lxml tree builders
or in lxml itself.

:param data: Some markup.
:param html: If True, markup will be parsed with lxml's HTML parser.
   if False, lxml's XML parser will be used.
r   recoverTutf8r:   z, z>4N)r   r   pop
isinstancer*   encoder	   r   	iterparser"   tagtext)r   r:   r;   r   r>   readereventelements   &&,     r   
lxml_tracerI   X   s     jjD)G${{6"dB//&WtWWWPVWw{{GLLAC Xr   c                      a  ] tR t^ot o RtV 3R lR ltRV 3R lR lltRV 3R lR lltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )AnnouncingParserzSubclass of HTMLParser that announces parse events, without doing
anything else.

You can use this to get a picture of how html.parser sees a given
document. The easiest way to do this is to call `htmlparser_trace`.
c                $   < V ^8  d   QhRS[ RR/# )r   sr   Nr*   )r   __classdict__s   "r   r   AnnouncingParser.__annotate__w   s      C D r   c                    \        V4       R # )N)r"   )selfrM   s   &&r   _pAnnouncingParser._pw   s	    ar   c                f   < V ^8  d   QhRS[ RS[S[S[ S[S[ ,          3,          ,          RS[RR/# )r   r3   attrshandle_empty_elementr   N)r*   r
   r   r   r<   )r   rO   s   "r   r   rP   z   sF     ) )) E#x},-.) #	)
 
)r   c                4    V P                  V R V R24       R# ) z STARTNrS   )rR   r3   rV   rW   s   &&&&r   handle_starttag AnnouncingParser.handle_starttagz   s     	4&%'(r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r3   check_already_closedr   N)r*   r<   )r   rO   s   "r   r   rP      s"     ! !# !T !T !r   c                6    V P                  R V,          4       R# )z%s ENDNrZ   )rR   r3   r^   s   &&&r   handle_endtagAnnouncingParser.handle_endtag   s    4 r   c                $   < V ^8  d   QhRS[ RR/# r   r   r   NrN   )r   rO   s   "r   r   rP           " " " "r   c                6    V P                  R V,          4       R# )z%s DATANrZ   rR   r   s   &&r   handle_dataAnnouncingParser.handle_data       	D !r   c                $   < V ^8  d   QhRS[ RR/# r   r3   r   NrN   )r   rO   s   "r   r   rP           % %3 %4 %r   c                6    V P                  R V,          4       R# )z
%s CHARREFNrZ   rR   r3   s   &&r   handle_charrefAnnouncingParser.handle_charref       t#$r   c                $   < V ^8  d   QhRS[ RR/# rk   rN   )r   rO   s   "r   r   rP      s     ' 'S 'T 'r   c                6    V P                  R V,          4       R# )z%s ENTITYREFNrZ   rn   s   &&r   handle_entityref!AnnouncingParser.handle_entityref   s    %&r   c                $   < V ^8  d   QhRS[ RR/# rc   rN   )r   rO   s   "r   r   rP      rl   r   c                6    V P                  R V,          4       R# )z
%s COMMENTNrZ   rf   s   &&r   handle_commentAnnouncingParser.handle_comment   rq   r   c                $   < V ^8  d   QhRS[ RR/# rc   rN   )r   rO   s   "r   r   rP      rd   r   c                6    V P                  R V,          4       R# )z%s DECLNrZ   rf   s   &&r   handle_declAnnouncingParser.handle_decl   ri   r   c                $   < V ^8  d   QhRS[ RR/# rc   rN   )r   rO   s   "r   r   rP      s     * * * *r   c                6    V P                  R V,          4       R# )z%s UNKNOWN-DECLNrZ   rf   s   &&r   unknown_declAnnouncingParser.unknown_decl   s    !D()r   c                $   < V ^8  d   QhRS[ RR/# rc   rN   )r   rO   s   "r   r   rP      s        c  d  r   c                6    V P                  R V,          4       R# )z%s PINrZ   rf   s   &&r   	handle_piAnnouncingParser.handle_pi   s    $r   r   NT)__name__
__module____qualname____firstlineno____doc__rS   r[   r`   rg   ro   rt   rx   r|   r   r   __static_attributes____classdictcell__)rO   s   @r   rK   rK   o   sn      ) )! !" "% %' '% %" "* *   r   rK   c                (    V ^8  d   QhR\         RR/# rc   rN   )r   s   "r   r   r      s     	 	3 	4 	r   c                <    \        4       pVP                  V 4       R# )zPrint out the HTMLParser events that occur during parsing.

This lets you see how HTMLParser parses a document when no
Beautiful Soup code is running.

:param data: Some markup.
N)rK   feed)r   r5   s   & r   htmlparser_tracer      s     F
KKr   aeioubcdfghjklmnpqrstvwxyzc                0    V ^8  d   QhR\         R\        /# r   lengthr   intr*   )r   s   "r   r   r      s      # c r   c                    Rp\        V 4       F;  pV^,          ^ 8X  d   \        pM\        pV\        P                  ! V4      ,          pK=  	  V# )z4Generate a random word-like string.

:meta private:
 )range_consonants_vowelsrandomchoice)r   rM   its   &   r   rwordr      sF    
 	A6]q5A:AA	V]]1  Hr   c                0    V ^8  d   QhR\         R\        /# r   r   )r   s   "r   r   r      s     H Hc H# Hr   c                D    RP                  R \        V 4       4       4      # )z8Generate a random sentence-like string.

:meta private:
rY   c              3   b   "   T F%  p\        \        P                  ! ^^	4      4      x  K'  	  R# 5i)   N)r   r   randint).0r   s   & r   	<genexpr>rsentence.<locals>.<genexpr>   s#     GAE&..A.//s   -/)r(   r   )r   s   &r   	rsentencer      s    
 88GvGGGr   c                0    V ^8  d   QhR\         R\        /# )r   num_elementsr   r   )r   s   "r   r   r      s     6 6s 6c 6r   c           	        . ROp. p\        V 4       F  p\        P                  ! ^ ^4      pV^ 8X  d1   \        P                  ! V4      pVP	                  RV,          4       KQ  V^8X  d2   VP	                  \        \        P                  ! ^^4      4      4       K  V^8X  g   K  \        P                  ! V4      pVP	                  RV,          4       K  	  RRP                  V4      ,           R,           # )z<Randomly generate an invalid HTML document.

:meta private:
z<%s>z</%s>z<html>
z</html>)pdivspanr   bscripttable)r   r   r   r   r'   r   r(   )r   	tag_nameselementsr   r   tag_names   &     r   rdocr      s    
 BIH< 1%Q;}}Y/HOOFX-.q[OOIfnnQ&:;<q[}}Y/HOOGh./ ! dii))I55r   c                (    V ^8  d   QhR\         RR/# )r   r   r   N)r   )r   s   "r   r   r      s      B  BC  BT  Br   c                L   \        R\        ,          4       \        V 4      p\        R\        V4      ,          4       RRR.RR3 Fb  pRp \        P                  ! 4       p\        W4       \        P                  ! 4       pRpV'       g   KG  \        R
VXX,
          3,          4       Kd  	  ^ RI	H
p \        P                  ! 4       pVP                  V4       \        P                  ! 4       p\        RWT,
          ,          4       ^ RIpVP                  4       p\        P                  ! 4       pVP                  V4       \        P                  ! 4       p\        RWT,
          ,          4       R#   \         d,    \        R	T,          4       \        P                  ! 4         EL i ; i)z.Very basic head-to-head performance benchmark.z1Comparative parser benchmark on Beautiful Soup %sz3Generated a large invalid HTML document (%d bytes).r   r:   r   r!   FTr    z"BS4+%s parsed the markup in %.2fs.r   z$Raw lxml parsed the markup in %.2fs.Nz(Raw html5lib parsed the markup in %.2fs.)r"   r   r   lentimer   r.   r/   r0   r   r   HTMLr   r   parse)	r   r   parser_namer6   ar   r   r   r5   s	   &        r   benchmark_parsersr      s5   	>LND	@3t9LN 0*mL	"		A$,		AG 77;A:NNP M 		A	JJt		A	1QU;=  "F		A
LL		A	5?A'  	"3kAC!	"s   7E--2F#"F#c                4    V ^8  d   QhR\         R\        RR/# )r   r   r5   r   Nr   )r   s   "r   r   r      s!     + +# + + +r   c                "   \         P                  ! 4       pVP                  p\        V 4      p\	        \
        WAR7      p\        P                  ! RWUV4       \        P                  ! V4      pVP                  R4       VP                  R^24       R# )z7Use Python's profiler on a randomly generated document.)bs4r   r5   zbs4.BeautifulSoup(data, parser)
cumulativez_html5lib|bs4N)tempfileNamedTemporaryFiler3   r   dictr   cProfilerunctxpstatsStats
sort_statsprint_stats)r   r5   
filehandlefilenamer   varsstatss   &&     r   profiler      sl    ,,.JHDCd2DOO5t8LLL"E	\"	or*r   __main__c                h    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   d
   \        ;R&   # )r   r   r   )__conditional_annotations__r*   )r   s   "r   r   r      s2     C CL   M DN + *S *O Dr   r   )   )r   )i  )順 )r   r   )+r   r   __license__r   ior   html.parserr   r   r   r   bs4.builderr   typingr   r	   r
   r   r   r   bs4._typingr   r   r   r   r   r/   r#   r8   rI   rK   r   r   r   r   r   r   r   r   r   stdinr   r   )r   s   @r   <module>r      s    C    " 
 * (  +      
5pD.) z ) X	  * *H6, BF+  zSYY^^ r   