
    (phC?                         S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJr  SSKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      rg)z*Tests of the bs4.element.PageElement class    N)BeautifulSoup)AttributeValueListComment)SoupStrainer   )SoupTestc                   N    \ 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g)TestEncoding   z0Test the ability to encode objects into strings.c                     SnU R                  U5      nUR                  R                  R                  S5      SR                  S5      :X  d   eg )N
   <b>☃</b>utf-8   ☃)soupbstringencodeselfhtmlr   s      M/var/www/html/venv/lib/python3.13/site-packages/bs4/tests/test_pageelement.py"test_unicode_string_can_be_encoded/TestEncoding.test_unicode_string_can_be_encoded   s@    #yyvv}}##G,0D0DW0MMMM    c                     SnU R                  U5      nUR                  R                  S5      UR                  S5      :X  d   eg )Nr   r   r   r   r   r   s      r   1test_tag_containing_unicode_string_can_be_encoded>TestEncoding.test_tag_containing_unicode_string_can_be_encoded   s8    #yyvv}}W%W)====r   c                 l    SnU R                  U5      nUR                  R                  S5      S:X  d   eg )Nr   asciis   <b>&#9731;</b>r   r   s      r   <test_encoding_substitutes_unrecognized_characters_by_defaultITestEncoding.test_encoding_substitutes_unrecognized_characters_by_default!   s0    #yyvv}}W%)::::r   c                     SnU R                  U5      n[        R                  " [        5         UR	                  SSS9  S S S 5        g ! , (       d  f       g = f)Nr   r    strict)errors)r   pytestraisesUnicodeEncodeErrorr   r   s      r    test_encoding_can_be_made_strict-TestEncoding.test_encoding_can_be_made_strict&   s=    #yy]]-.KKK1 /..s   A
Ac                 j    SnU R                  U5      nSUR                  R                  5       :X  d   eg )Nr   r   )r   r   decode_contentsr   s      r   test_decode_contents!TestEncoding.test_decode_contents,   s/    #yy 6 6 8888r   c                     SnU R                  U5      nSR                  S5      UR                  R                  SS9:X  d   eg )Nr   r   utf8)encoding)r   r   r   encode_contentsr   s      r   test_encode_contents!TestEncoding.test_encode_contents1   s?    #yy##F+tvv/E/Ev/E/VVVVr   c                     [         R                  " 5       S-   nSU-  nU R                  U5      nUR                  5       nXR	                  S5      :X  d   eg )Nr   <span>s   <span>)sysgetrecursionlimitr   r   count)r   limitmarkupr   encodeds        r   "test_encode_deeply_nested_document/TestEncoding.test_encode_deeply_nested_document6   sO     %%'!+E!yy ++-i0000r   c                    SnU R                  U5      n[        R                  " SS9 nUR                  5         SR	                  S5      UR
                  R                  5       :X  d   e S S S 5        W Vs/ s H  n[        UR                  5      PM     nn[        S U 5       5      (       d   eg ! , (       d  f       NM= fs  snf )Nr   T)recordr   r0   c              3   ,   #    U  H
  nUS :H  v   M     g7f)zjCall to deprecated method renderContents. (Replaced by encode_contents) -- Deprecated since version 4.0.0.N ).0xs     r   	<genexpr>>TestEncoding.test_deprecated_renderContents.<locals>.<genexpr>G   s"      
  {|s   )	r   warningscatch_warningsrenderContentsr   r   strmessageall)r   r   r   wwarningmsgss         r   test_deprecated_renderContents+TestEncoding.test_deprecated_renderContents@   s    #yy$$D1Q! ''/4663H3H3JJJJ 2 566AGOO$A6 
 
 
 
 	
 
	 21 7s   A B05C0
B>c                 L    SnU R                  U5      nU[        U5      :X  d   eg Nr   )r   reprr   s      r   	test_reprTestEncoding.test_reprM   s&    #yytDz!!!r   rB   N)__name__
__module____qualname____firstlineno____doc__r   r   r!   r)   r-   r3   r=   rP   rU   __static_attributes__rB   r   r   r
   r
      s4    :N
>
;
29
W
1
"r   r
   c                   ~    \ 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S rS rS rS rS rSrg)TestFormattersS   zjTest the formatting feature, used by methods like decode() and
prettify(), and the formatters themselves.
c                 t    SnU R                  U5      nUR                  SS9nX0R                  S5      :X  d   eg N#   <b>&lt;&lt;Sacré bleu!&gt;&gt;</b>minimal	formatterr   decodedocument_forr   r;   r   decodeds       r   !test_default_formatter_is_minimal0TestFormatters.test_default_formatter_is_minimalX   E    Wyy ++	+2++R
 
 	
 
r   c                 t    SnU R                  U5      nUR                  SS9nX0R                  S5      :X  d   eg )N'   <br><b>&lt;&lt;Sacré bleu!&gt;&gt;</b>r   rd   z.<br/><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rf   ri   s       r   test_formatter_html"TestFormatters.test_formatter_htmla   sJ    V 	 yy +++/++<
 
 	
 
r   c                 t    SnU R                  U5      nUR                  SS9nX0R                  S5      :X  d   eg )Nro   html5rd   z-<br><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rf   ri   s       r   test_formatter_html5#TestFormatters.test_formatter_html5k   sJ    V 	 yy +++0++;
 
 	
 
r   c                 t    SnU R                  U5      nUR                  SS9nX0R                  S5      :X  d   eg ra   rf   ri   s       r   test_formatter_minimal%TestFormatters.test_formatter_minimalu   rm   r   c                 t    SnU R                  U5      nUR                  S S9nX0R                  S5      :X  d   eg )Nrb   rd   u   <b><<Sacré bleu!>></b>rf   ri   s       r   test_formatter_null"TestFormatters.test_formatter_null~   sG    Wyy +++- ++F
 
 	
 
r   c                 v    SnU R                  U5      nUR                  S S9nX0R                  S5      :X  d   eg )Nz!<b>&lt;foo&gt;</b><b>bar</b><br/>c                 "    U R                  5       $ NupperrD   s    r   <lambda>6TestFormatters.test_formatter_custom.<locals>.<lambda>   s
    !'')r   rd   z<b><FOO></b><b>BAR</b><br/>rf   ri   s       r   test_formatter_custom$TestFormatters.test_formatter_custom   s@    4yy ++(;+< ++,IJJJJr   c                    SnU R                  U5      nUR                  nSnXCR                  5       :X  d   eXCR                  SS9:X  d   eSnXSR                  SS9:X  d   eXR                  S S9:X  d   eSnXcR                  S S9:X  d   eg )	Nu%   <a href="http://a.com?a=b&c=é">e</a>u)   <a href="http://a.com?a=b&amp;c=é">e</a>rc   rd   z/<a href="http://a.com?a=b&amp;c=&eacute;">e</a>r   u%   <a href="HTTP://A.COM?A=B&C=É">E</a>c                 "    U R                  5       $ r~   r   r   s    r   r   JTestFormatters.test_formatter_is_run_on_attribute_values.<locals>.<lambda>   s
    AGGIr   )r   arg   )r   r;   r   r   expect_minimalexpect_htmlexpect_uppers          r   )test_formatter_is_run_on_attribute_values8TestFormatters.test_formatter_is_run_on_attribute_values   s    8yy FFD+++I!>>>>Ghhh8888D1111>xx2ExFFFFr   c                 L    Sn[        US5      R                  5       nSU;   d   eg )NzO
  <script type="text/javascript">
   console.log("< < hey > > ");
  </script>
html.parser   < < hey > >r   r   r   docr<   s      r   2test_formatter_skips_script_tag_for_html_documentsATestFormatters.test_formatter_skips_script_tag_for_html_documents   .    
  ]3::<(((r   c                 L    Sn[        US5      R                  5       nSU;   d   eg )NzF
  <style type="text/css">
   console.log("< < hey > > ");
  </style>
r   r   r   r   s      r   1test_formatter_skips_style_tag_for_html_documents@TestFormatters.test_formatter_skips_style_tag_for_html_documents   r   r   c                 f    U R                  S5      nSUR                  R                  5       :X  d   eg )NzN<div>  foo  <pre>  	bar
  
  </pre>  baz  <textarea> eee
fff	</textarea></div>zP<div>
 foo
 <pre>  	bar
  
  </pre>
 baz
 <textarea> eee
fff	</textarea>
</div>
r   divprettifyr   r   s     r   ,test_prettify_leaves_preformatted_text_alone;TestFormatters.test_prettify_leaves_preformatted_text_alone   s8    yya
 jxx  "#	
#r   c                 l    SnSnU R                  U5      nX#R                  R                  5       :X  d   eg )NzR<div><pre><code>some
<script><pre>code</pre></script> for you 
</code></pre></div>zV<div>
 <pre><code>some
<script><pre>code</pre></script> for you 
</code></pre>
</div>
r   )r   r;   expectr   s       r   0test_prettify_handles_nested_string_literal_tags?TestFormatters.test_prettify_handles_nested_string_literal_tags   s9     yy **,,,,r   c                 L    [        SS5      nUR                  S S9nSU;   d   eg )Nz<html><body>foo</body></html>r   c                 "    U R                  5       $ r~   r   r   s    r   r   ITestFormatters.test_prettify_accepts_formatter_function.<locals>.<lambda>   s
    1779r   rd   FOO)r   r   )r   r   prettys      r   (test_prettify_accepts_formatter_function7TestFormatters.test_prettify_accepts_formatter_function   s,    <mL)<=r   c                 j    U R                  S5      n[        [        UR                  5       5      L d   eg )N<a></a>)r   rJ   typer   r   s     r   (test_prettify_outputs_unicode_by_default7TestFormatters.test_prettify_outputs_unicode_by_default   s)    yy#d4==?++++r   c                 l    U R                  S5      n[        [        UR                  S5      5      L d   eg )Nr   r   )r   bytesr   r   r   s     r   test_prettify_can_encode_data,TestFormatters.test_prettify_can_encode_data   s,    yy#T]]734444r   c                     SnU R                  U5      nUR                  R                  S5      nX1R                  S5      :X  d   eg )Nu   <b>Sacré bleu!</b>r   r   )r   r;   r   r<   s       r   ,test_html_entity_substitution_off_by_default;TestFormatters.test_html_entity_substitution_off_by_default   s<    Gyy &&--(--0000r   c                 :   SnU R                  U5      nUR                  S   S:X  d   eUR                  S5      nSU;   d   eUR                  S5      nSU;   d   eUR                  S5      nS	U;   d   eUR                  S
5      R                  S
5      nSU;   d   eg )NzE<meta content="text/html; charset=x-sjis" http-equiv="Content-type"/>contentztext/html; charset=x-sjisr   s   charset=utf-8euc_jps   charset=euc_jpz	shift-jiss   charset=shift-jiszutf-16zcharset=utf-16)r   metar   rg   )r   meta_tagr   utf_8r   	shift_jisutf_16_us          r   test_encoding_substitution)TestFormatters.test_encoding_substitution   s     W 	 yy" yy#'BBBB G$5(((X& F***KK,	#y000;;x(//98+++r   c                 z    Sn[        S5      nU R                  XS9nUR                  S   R                  S:X  d   eg )Nz`<head><meta content="text/html; charset=x-sjis" http-equiv="Content-type"/></head><pre>foo</pre>pre)
parse_onlyr   )r   r   contentsname)r   r;   strainerr   s       r   ;test_encoding_substitution_doesnt_happen_if_tag_is_strainedJTestFormatters.test_encoding_substitution_doesnt_happen_if_tag_is_strained  sE    ? 	  &yyy5}}Q$$---r   rB   N)rW   rX   rY   rZ   r[   rk   rp   rt   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r\   rB   r   r   r^   r^   S   s^    




KG"))	
-0
,51,2.r   r^   c                   Z    \ 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g)TestPersistencei  z*Testing features like pickle and deepcopy.c                 R    SU l         U R                  U R                   5      U l        g )Nay  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Beautiful Soup: We called him Tortoise because he taught us.</title>
<link rev="made" href="mailto:leonardr@segfault.org">
<meta name="Description" content="Beautiful Soup: an HTML parser optimized for screen-scraping.">
<meta name="generator" content="Markov Approximation 1.4 (module: leonardr)">
<meta name="author" content="Leonard Richardson">
</head>
<body>
<a href="foo">foo</a>
<a href="foo"><b>bar</b></a>
</body>
</html>)pager   tree)r   s    r   setup_methodTestPersistence.setup_method  s!    	  IIdii(	r   c                     [         R                  " U R                  S5      n[         R                  " U5      nUR                  [
        :X  d   eUR                  5       U R                  R                  5       :X  d   eg )N   )pickledumpsr   loads	__class__r   rg   )r   dumpedloadeds      r   !test_pickle_and_unpickle_identity1TestPersistence.test_pickle_and_unpickle_identity&  s[     dii+f%=000}}$))"2"2"4444r   c                     [         R                  " U R                  5      nUR                  5       U R                  R                  5       :X  d   eg r~   )copydeepcopyr   rg   )r   copieds     r   test_deepcopy_identity&TestPersistence.test_deepcopy_identity.  s5    tyy)}}$))"2"2"4444r   c                     [         R                  " 5       S-   nSU-  nU R                  U5      n[        R                  " U5        [        R                  " U5        g )Nr   r6   )r7   r8   r   r   r   )r   r:   r;   r   s       r    test_copy_deeply_nested_document0TestPersistence.test_copy_deeply_nested_document3  sF     %%'!+E!yy 		$dr   c                     [        SS5      nUR                  nUR                  5       nS[        U5      :X  d   eX#R                  :X  d   eg )Ns   <p>&nbsp;</p>r   u	   <p> </p>)r   original_encoding__copy__rJ   )r   r   r1   r   s       r   test_copy_preserves_encoding,TestPersistence.test_copy_preserves_encoding?  sI    -}=))}}c$i'''11111r   c                    U R                  S5      R                  nSUl        SUl        UR	                  5       nUR                  UR                  :X  d   eUR                  UR                  :X  d   eUR
                  UR
                  :X  d   eUR                  UR                  :X  d   eUR                  UR                  :X  d   eUR                  UR                  :X  d   eg )Nz<p></p>
   !   )	r   p
sourceline	sourceposr   can_be_empty_elementcdata_list_attributespreserve_whitespace_tagsinteresting_string_types)r   tagr   s      r   'test_copy_preserves_builder_information7TestPersistence.test_copy_preserves_builder_informationF  s    ii	"$$  ~~!2!2222}} 0 0000''6+F+FFFF((F,H,HHHH++v/N/NNNN++v/N/NNNNr   c                     SnU R                  U5      n[        R                  " U[        R                  5      n[        R                  " U5      nUR                  5       UR                  5       :X  d   eg rS   )r   r   r   HIGHEST_PROTOCOLr   rg   )r   r   r   r   r   s        r   test_unicode_pickle#TestPersistence.test_unicode_pickleX  sR    #yydF$;$;<f%}}$++-///r   c                 ,   SnU R                  U5      nUR                  SS9n[        R                  " U5      nX4:X  d   eS UR                  L d   eS UR                  L d   eS UR
                  Ld   eS UR
                  L d   eS UR                  L d   eg )Nz<b>Foo<a></a></b><b>Bar</b>Foor   )r   findr   parentnext_elementnext_siblingprevious_elementr   r   r   s1s2s        r   1test_copy_navigablestring_is_not_attached_to_treeATestPersistence.test_copy_navigablestring_is_not_attached_to_tree`  s    ,yyYYeY$YYr]xxryy   r&&&2??***r&&&r*****r   c                     SnU R                  U5      nUR                  n[        R                  " U5      nX4:X  d   e[        U[        5      (       d   eg )Nz<b><!--Foo--></b>)r   r   r   
isinstancer   r  s        r   0test_copy_navigablestring_subclass_has_same_type@TestPersistence.test_copy_navigablestring_subclass_has_same_typel  sF    "yy[[YYr]xx"g&&&&r   c                 d    SnU R                  U5      n[        R                  " U5      nX#:X  d   eg )Nz)<div><b>Foo<a></a></b><b>Bar</b></div>end)r   r   )r   r   r   	soup_copys       r   test_copy_entire_soup%TestPersistence.test_copy_entire_soupt  s-    :yyIIdO	   r   c                 R   SnU R                  U5      nUR                  n[        R                  " U5      n[        U5      [        U5      :X  d   eX4:X  d   eX4Ld   eS UR                  L d   eS UR
                  L d   eS UR                  SS9R                  L d   eS UR                  SS9R                  Ld   eUS   US   Ld   eUS   R                  S5        SR                  5       US   :X  d   eSR                  5       US   :X  d   e[        US   [        5      (       d   eg )Nz7<div class='a b c'><b>Foo<a></a></b><b>Bar</b></div>endBarr   classdza b c dza b c)r   r   r   rJ   r   r  r   r   appendsplitr	  r   )r   r   r   r   div_copys        r   test_copy_tag_copies_contents-TestPersistence.test_copy_tag_copies_contentsz  s6   Hyyhh99S> 3x3x=((( """ x&&&x00000x}}E}2?????388581>>>>> 7|8G#4444GC  CL000}}(7"3333(7+-?@@@@r   )r   r   N)rW   rX   rY   rZ   r[   r   r   r   r   r   r   r   r  r
  r  r  r\   rB   r   r   r   r     s>    0)&55

2O$0
+'!Ar   r   c                        \ rS rSrS rS rSrg)TestEqualityi  c                     U R                  S5      nUR                  S5      u  p#UR                  SS9u  pEX#:X  d   eXEs=:X  a  S:X  d   e   eUS:w  d   eg )N<a>string</a> <a>string</a>r   r   r   s   string)r   find_allr   r   first_asecond_afirst_stringsecond_strings         r   test_comparisonTestEquality.test_comparison  sl    yy67 MM#.&*mm8m&D# """ 888888 y(((r   c                 0   U R                  S5      nUR                  S5      u  p#UR                  SS9u  pE[        U5      [        U5      :X  d   e[        U5      [        U5      :w  d   e[        U5      [        U5      s=:X  a  [        S5      :X  d   e   eg )Nr  r   r   r   )r   r  hashidr  s         r   	test_hashTestEquality.test_hash  s    yy67 MM#.&*mm8m&D# G}X... '{bl*** L!T-%8JDNJJJJJr   rB   N)rW   rX   rY   rZ   r#  r(  r\   rB   r   r   r  r    s    )Kr   r  )r[   r   r   r&   r7   rG   bs4r   bs4.elementr   r   
bs4.filterr    r   r
   r^   r   r  rB   r   r   <module>r.     sd    0    
   $
<"8 <"~z.X z.zDAh DANK8 Kr   