
    (ph#                         S r SSKrSSKrSSKJr  SSKJr  SSKJrJ	r	  \R                  R                  \(       + SS9 " S	 S
\	5      5       rg)zDTests to ensure that the html5lib tree builder generates good trees.    N)BeautifulSoup)SoupStrainer   )HTML5LIB_PRESENTHTML5TreeBuilderSmokeTestz?html5lib seems not to be present, not testing its tree builder.)reasonc                       \ rS rSrSr\S 5       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\R.                  R1                  SSSS/4/5      S 5       rS rSrg)TestHTML5LibBuilder   z"See ``HTML5TreeBuilderSmokeTest``.c                     SSK Jn  U$ )Nr   )HTML5TreeBuilder)bs4.builderr   )selfr   s     J/var/www/html/venv/lib/python3.13/site-packages/bs4/tests/test_html5lib.pydefault_builder#TestHTML5LibBuilder.default_builder   s    0    c                 D   [        S5      nSn[        R                  " SS9 n[        USUS9nS S S 5        WR	                  5       U R                  U5      :X  d   eWu  nUR                  [        :X  d   eS[        UR                  5      ;   d   eg ! , (       d  f       Ni= f)Nbz<p>A <b>bold</b> statement.</p>Trecordhtml5lib)
parse_onlyz4the html5lib tree builder doesn't support parse_only)
r   warningscatch_warningsr   decodedocument_forfilename__file__strmessage)r   strainermarkupwsoupwarnings         r   test_soupstrainer%TestHTML5LibBuilder.test_soupstrainer   s    $2$$D1Q ID 2{{} 1 1& 9999	8+++EOOJ
 
 	
 
 21s   B
Bc                 N    SnU R                  US5        U R                  S5        g)z8html5lib inserts <tbody> tags where other parsers don't.z[<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>z<table id="1"><tbody><tr><td>Here's another table:<table id="2"><tbody><tr><td>foo</td></tr></tbody></table></td></tr></tbody></table>z{<table><thead><tr><td>Foo</td></tr></thead><tbody><tr><td>Bar</td></tr></tbody><tfoot><tr><td>Baz</td></tr></tfoot></table>N)assert_soup)r   r#   s     r   test_correctly_nested_tables0TestHTML5LibBuilder.test_correctly_nested_tables)   s9     	 	)	
 	;	
r   c                 j    SnU R                  U5      nSUR                  R                  5       :X  d   eg )Nzy<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
   <p>foo</p>
  </body>
</html>s
   <p>foo</p>)r%   pencoder   r#   r%   s      r   (test_xml_declaration_followed_by_doctype<TestHTML5LibBuilder.test_xml_declaration_followed_by_doctypeA   s1     yy ///r   c                     SnU R                  U5      nSUR                  R                  5       :X  d   eS[        UR	                  S5      5      :X  d   eg )Nz%<p><em>foo</p>
<p>bar<a></a></em></p>zD<body><p><em>foo</em></p><em>
</em><p><em>bar<a></a></em></p></body>   r.   r%   bodyr   lenfind_allr0   s      r   test_reparented_markup*TestHTML5LibBuilder.test_reparented_markupO   sU    9yy Syy!"	
" Cc*++++r   c                     SnU R                  U5      nSUR                  R                  5       :X  d   eS[        UR	                  S5      5      :X  d   eg )Nz&<p><em>foo</p>
<p>bar<a></a></em></p>
zE<body><p><em>foo</em></p><em>
</em><p><em>bar<a></a></em></p>
</body>r4   r.   r5   r0   s      r   +test_reparented_markup_ends_with_whitespace?TestHTML5LibBuilder.test_reparented_markup_ends_with_whitespaceX   sU    ;yy Uyy!"	
" Cc*++++r   c                     SnU R                  U5      nUR                  SS9u  p4UR                  S5      u  pVUR                  UL d   eUR                  UL d   eg)zsVerify that we keep the two whitespace nodes in this
document distinct when reparenting the adjacent <tbody> tags.
z,<table> <tbody><tbody><ims></tbody> </table> stringtbodyN)r%   r8   next_element)r   r#   r%   space1space2tbody1tbody2s          r   <test_reparented_markup_containing_identical_whitespace_nodesPTestHTML5LibBuilder.test_reparented_markup_containing_identical_whitespace_nodesa   sb     @yy c2w/""f,,,""f,,,r   c                     SnU R                  U5      nUR                  nSUR                  :X  d   eUR                  SS9nUR	                  SS9S   nXTR                  :X  d   eXER
                  :X  d   eg )NzF<div><a>aftermath<p><noscript>target</noscript>aftermath</a></p></div>targetr@   	aftermath)r%   noscriptrC   findr8   previous_element)r   r#   r%   rN   rK   final_aftermaths         r   *test_reparented_markup_containing_children>TestHTML5LibBuilder.test_reparented_markup_containing_childrenl   s    T 	 yy ==800000(+ --{-;B?
 "5"555599999r   c                 l    SnU R                  U5      n[        U5      R                  S5      (       d   eg)z(Processing instructions become comments.s   <?PITarget PIContent?>z<!--?PITarget PIContent?-->N)r%   r    
startswithr0   s      r   test_processing_instruction/TestHTML5LibBuilder.test_processing_instruction~   s1    .yy 4y##$ABBBBr   c                 j    SnU R                  U5      nUR                  S5      u  p4X4:X  d   eX4Ld   eg )Ns   <a class="my_class"><p></a>a)r%   r8   )r   r#   r%   a1a2s        r   test_cloned_multivalue_node/TestHTML5LibBuilder.test_cloned_multivalue_node   s8    3yy s#xx||r   c                 j    SnU R                  U5      nSUR                  R                  5       :X  d   eg )Ns   <table><td></tbody>Az><body>A<table><tbody><tr><td></td></tr></tbody></table></body>)r%   r6   r   r0   s      r   test_foster_parenting)TestHTML5LibBuilder.test_foster_parenting   s7    ,yy Lyy!"	
"r   c                    SnU R                  U5      nU" S5       Vs/ s H  o3R                  5       PM       nU" S5       Vs/ s H  o3R                  5       PM       n[        UR                  S5      5      S:X  d   egs  snf s  snf )zh
Test that extraction does not destroy the tree.

https://bugs.launchpad.net/beautifulsoup/+bug/1782928
zW
<html><head></head>
<style>
</style><script></script><body><p>hello</p></body></html>
scriptstyler.   r   N)r%   extractr7   r8   )r   r#   r%   ss       r   test_extraction#TestHTML5LibBuilder.test_extraction   sq    
 yy "8n-nn-"7m,mm,4==%&!+++ 	.,s   A?Bc                     SnU R                  U5      n/ nUR                  S5       H#  nUR                  UR                  S5      5        M%     [        U5      S:X  d   eg)zj
Test that empty comment does not break structure.

https://bugs.launchpad.net/beautifulsoup/+bug/1806598
zI
<html>
<body>
<form>
<!----><input type="text">
</form>
</body>
</html>
forminputr   N)r%   r8   extendr7   )r   r#   r%   inputsri   s        r   test_empty_comment&TestHTML5LibBuilder.test_empty_comment   sX     yy MM&)DMM$--01 *6{ar   c                 |   SnU R                  U5      nSUR                  R                  :X  d   eSUR                  R                  :X  d   eSUR                  R	                  S5      R
                  :X  d   eU R                  USS9nS UR                  R                  L d   eS UR                  R                  L d   eg )Nz=
   <p>

<sourceline>
<b>text</b></sourceline><sourcepos></p>r4      
sourcelineF)store_line_numbers)r%   r.   rq   	sourceposrO   namer0   s      r   test_tracking_line_numbers.TestHTML5LibBuilder.test_tracking_line_numbers   s     Uyy DFF%%%%%DFF$$$$$tvv{{<8===== yyEy:tvv(((((tvv'''''r   c                     g N r   s    r   test_special_string_containers2TestHTML5LibBuilder.test_special_string_containers   s     	r   c                     S Hl  u  pnSU-  nU R                  U5      R                  nUR                  5       nSUR                  S5      -  nXg:X  d   eUR                  SS9nSU-  nX:X  a  Ml   e   g )N))z&RightArrowLeftArrow;u   ⇄s   &rlarr;)z&models;u   ⊧s   &models;)z&Nfr;u   𝔑s   &Nfr;)z&ngeqq;u   ≧̸s   &ngeqq;)z&not;   ¬s   &not;)z&Not;u   ⫬s   &Not;)z&quot;"   ")z&there4;   ∴   &there4;)z&Therefore;r   r   )z&therefore;r   r   )z&fjlig;fjs   fj)z&sqcup;u   ⊔s   &sqcup;)z&sqcups;u   ⊔︀s   &sqcups;)z&apos;'   ')z&verbar;|   |z<div>%s</div>s   <div>%s</div>utf8html)	formatter)r%   divr/   )	r   input_elementoutput_unicodeoutput_elementr#   r   without_elementexpectwith_elements	            r   test_html5_attributes)TestHTML5LibBuilder.test_html5_attributes   s    >
9M>" %}4F))F#''C!jjlO%(=(=f(EEF",,,:::7L%6F)))3>
r   z
name,value)document_declared_encodingr   exclude_encodingsr   c                    U R                  5       nX0n[        R                  " SS9 n[        UR                  " S0 UD65        S S S 5        Wu  n[        UR                  5      nUSU SU S3:X  d   eg ! , (       d  f       N7= f)NTr   zYou provided a value for z0, but the html5lib tree builder doesn't support .)rY   )r   r   r   listprepare_markupr    r!   )r   rt   valuebuilderkwargsr$   r&   msgs           r   test_prepare_markup_warnings0TestHTML5LibBuilder.test_prepare_markup_warnings   s     &&($$D1Q''6v67 2	'//"*4&0`ae`ffghi	
i 21s   A55
Bc                     g rx   ry   rz   s    r   test_doctype_filtered)TestHTML5LibBuilder.test_doctype_filtered  s     	r   ry   N)__name__
__module____qualname____firstlineno____doc__propertyr   r'   r+   r1   r9   r<   rH   rR   rV   r\   r_   rf   rm   ru   r{   r   pytestmarkparametrizer   r   __static_attributes__ry   r   r   r
   r
      s    
 -   


00,,	-:$C
,$ ,("*H [[	/2Ex1PQ
	
r   r
   )r   r   r   bs4r   
bs4.filterr    r   r   r   skipifr
   ry   r   r   <module>r      sU    J    # L  v3 v	vr   