
    hC?                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ  G d d	e      Z G d
 de      Z G d de      Z G d de      Zy)z*Tests of the bs4.element.PageElement class    N)BeautifulSoup)AttributeValueListComment)SoupStrainer   )SoupTestc                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestEncodingz0Test the ability to encode objects into strings.c                     d}| j                  |      }|j                  j                  j                  d      dj                  d      k(  sJ y )N
   <b>☃</b>utf-8   ☃)soupbstringencodeselfhtmlr   s      /var/labsstorage/home/kalaiyarasan.offl.2004/htdocs/course/socket/myenv/lib/python3.12/site-packages/bs4/tests/test_pageelement.py"test_unicode_string_can_be_encodedz/TestEncoding.test_unicode_string_can_be_encoded   s@    #yyvv}}##G,0D0DW0MMMM    c                     d}| j                  |      }|j                  j                  d      |j                  d      k(  sJ y )Nr   r   r   r   r   r   s      r   1test_tag_containing_unicode_string_can_be_encodedz>TestEncoding.test_tag_containing_unicode_string_can_be_encoded   s8    #yyvv}}W%W)====r   c                 j    d}| j                  |      }|j                  j                  d      dk(  sJ y )Nr   asciis   <b>&#9731;</b>r   r   s      r   <test_encoding_substitutes_unrecognized_characters_by_defaultzITestEncoding.test_encoding_substitutes_unrecognized_characters_by_default!   s0    #yyvv}}W%)::::r   c                     d}| j                  |      }t        j                  t              5  |j	                  dd       d d d        y # 1 sw Y   y xY w)Nr   r   strict)errors)r   pytestraisesUnicodeEncodeErrorr   r   s      r    test_encoding_can_be_made_strictz-TestEncoding.test_encoding_can_be_made_strict&   sF    #yy]]-. 	2KKK1	2 	2 	2s   A

Ac                 h    d}| j                  |      }d|j                  j                         k(  sJ y )Nr   r   )r   r   decode_contentsr   s      r   test_decode_contentsz!TestEncoding.test_decode_contents,   s/    #yy 6 6 8888r   c                     d}| j                  |      }dj                  d      |j                  j                  d      k(  sJ y )Nr   r   utf8)encoding)r   r   r   encode_contentsr   s      r   test_encode_contentsz!TestEncoding.test_encode_contents1   s?    #yy##F+tvv/E/Ev/E/VVVVr   c                     t        j                         dz   }d|z  }| j                  |      }|j                         }||j	                  d      k(  sJ y )Nr   <span>s   <span>)sysgetrecursionlimitr   r   count)r   limitmarkupr   encodeds        r   "test_encode_deeply_nested_documentz/TestEncoding.test_encode_deeply_nested_document6   sQ     %%'!+E!yy ++-i0000r   c                 t   d}| j                  |      }t        j                  d      5 }|j                          dj	                  d      |j
                  j                         k(  sJ 	 d d d        D cg c]  }t        |j                         }}t        d |D              sJ y # 1 sw Y   @xY wc c}w )Nr   T)recordr   r*   c              3   &   K   | ]	  }|d k(    yw)zjCall to deprecated method renderContents. (Replaced by encode_contents) -- Deprecated since version 4.0.0.N ).0xs     r   	<genexpr>z>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_renderContentsz+TestEncoding.test_deprecated_renderContents@   s    #yy$$D1 	KQ! ''/4663H3H3JJJJ	K 566GOO$66 
 
 
 	
 
		K 	K 7s   ?B)6B5)B2c                 J    d}| j                  |      }|t        |      k(  sJ y Nr   )r   reprr   s      r   	test_reprzTestEncoding.test_reprM   s&    #yytDz!!!r   N)__name__
__module____qualname____doc__r   r   r   r%   r(   r-   r6   rG   rK   r:   r   r   r
   r
      s4    :N
>
;
29
W
1
"r   r
   c                   v    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestFormatterszrTest the formatting feature, used by methods like decode() and
    prettify(), and the formatters themselves.
    c                 z    d}| j                  |      }|j                  d      }|| j                  d      k(  sJ y N#   <b>&lt;&lt;Sacré bleu!&gt;&gt;</b>minimal	formatterr   decodedocument_forr   r4   r   decodeds       r   !test_default_formatter_is_minimalz0TestFormatters.test_default_formatter_is_minimalX   G    Wyy ++	+2$++R
 
 	
 
r   c                 z    d}| j                  |      }|j                  d      }|| j                  d      k(  sJ y )N'   <br><b>&lt;&lt;Sacré bleu!&gt;&gt;</b>r   rV   z.<br/><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rX   r[   s       r   test_formatter_htmlz"TestFormatters.test_formatter_htmla   sL    V 	 yy +++/$++<
 
 	
 
r   c                 z    d}| j                  |      }|j                  d      }|| j                  d      k(  sJ y )Nr`   html5rV   z-<br><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rX   r[   s       r   test_formatter_html5z#TestFormatters.test_formatter_html5k   sL    V 	 yy +++0$++;
 
 	
 
r   c                 z    d}| j                  |      }|j                  d      }|| j                  d      k(  sJ y rS   rX   r[   s       r   test_formatter_minimalz%TestFormatters.test_formatter_minimalu   r^   r   c                 z    d}| j                  |      }|j                  d       }|| j                  d      k(  sJ y )NrT   rV   u   <b><<Sacré bleu!>></b>rX   r[   s       r   test_formatter_nullz"TestFormatters.test_formatter_null~   sI    Wyy +++- $++F
 
 	
 
r   c                 |    d}| j                  |      }|j                  d       }|| j                  d      k(  sJ y )Nz!<b>&lt;foo&gt;</b><b>bar</b><br/>c                 "    | j                         S Nupperr<   s    r   <lambda>z6TestFormatters.test_formatter_custom.<locals>.<lambda>   s    !'') r   rV   z<b><FOO></b><b>BAR</b><br/>rX   r[   s       r   test_formatter_customz$TestFormatters.test_formatter_custom   sB    4yy ++(;+< $++,IJJJJr   c                 2   d}| j                  |      }|j                  }d}||j                         k(  sJ ||j                  d      k(  sJ d}||j                  d      k(  sJ ||j                  d       k(  sJ d}||j                  d       k(  sJ y )	Nu%   <a href="http://a.com?a=b&c=é">e</a>u)   <a href="http://a.com?a=b&amp;c=é">e</a>rU   rV   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                 "    | j                         S rk   rl   rn   s    r   ro   zJTestFormatters.test_formatter_is_run_on_attribute_values.<locals>.<lambda>   s    AGGI r   )r   arY   )r   r4   r   rs   expect_minimalexpect_htmlexpect_uppers          r   )test_formatter_is_run_on_attribute_valuesz8TestFormatters.test_formatter_is_run_on_attribute_values   s    8yy FFD+++I!>>>>Gahhh8888D1111>qxx2ExFFFFr   c                 H    d}t        |d      j                         }d|v sJ y )NzO
  <script type="text/javascript">
   console.log("< < hey > > ");
  </script>
html.parser   < < hey > >r   r   r   docr5   s      r   2test_formatter_skips_script_tag_for_html_documentszATestFormatters.test_formatter_skips_script_tag_for_html_documents   .    
  ]3::<(((r   c                 H    d}t        |d      j                         }d|v sJ y )NzF
  <style type="text/css">
   console.log("< < hey > > ");
  </style>
ry   rz   r{   r|   s      r   1test_formatter_skips_style_tag_for_html_documentsz@TestFormatters.test_formatter_skips_style_tag_for_html_documents   r   r   c                 d    | j                  d      }d|j                  j                         k(  sJ y )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_alonez;TestFormatters.test_prettify_leaves_preformatted_text_alone   s8    yya
 jxx  "#	
#r   c                 l    d}d}| j                  |      }||j                  j                         k(  sJ y )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   r4   expectr   s       r   0test_prettify_handles_nested_string_literal_tagsz?TestFormatters.test_prettify_handles_nested_string_literal_tags   s;     yy **,,,,r   c                 N    t        dd      }|j                  d       }d|v sJ y )Nz<html><body>foo</body></html>ry   c                 "    | j                         S rk   rl   rn   s    r   ro   zITestFormatters.test_prettify_accepts_formatter_function.<locals>.<lambda>   s    1779 r   rV   FOO)r   r   )r   r   prettys      r   (test_prettify_accepts_formatter_functionz7TestFormatters.test_prettify_accepts_formatter_function   s,    <mL)<=r   c                 h    | j                  d      }t        t        |j                               u sJ y )N<a></a>)r   rA   typer   r   s     r   (test_prettify_outputs_unicode_by_defaultz7TestFormatters.test_prettify_outputs_unicode_by_default   s)    yy#d4==?++++r   c                 j    | j                  d      }t        t        |j                  d            u sJ y )Nr   r   )r   bytesr   r   r   s     r   test_prettify_can_encode_dataz,TestFormatters.test_prettify_can_encode_data   s,    yy#T]]734444r   c                     d}| j                  |      }|j                  j                  d      }||j                  d      k(  sJ y )Nu   <b>Sacré bleu!</b>r   r   )r   r4   r   r5   s       r   ,test_html_entity_substitution_off_by_defaultz;TestFormatters.test_html_entity_substitution_off_by_default   s>    Gyy &&--(&--0000r   c                 (   d}| j                  |      }|j                  d   dk(  sJ |j                  d      }d|v sJ |j                  d      }d|v sJ |j                  d      }d	|v sJ |j                  d
      j                  d
      }d|v sJ y )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   rY   )r   meta_tagr   utf_8r   	shift_jisutf_16_us          r   test_encoding_substitutionz)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                     d}t        d      }| j                  ||      }|j                  d   j                  dk(  sJ y )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   r4   strainerr   s       r   ;test_encoding_substitution_doesnt_happen_if_tag_is_strainedzJTestFormatters.test_encoding_substitution_doesnt_happen_if_tag_is_strained  sG    ? 	  &yyHy5}}Q$$---r   N)rL   rM   rN   rO   r]   ra   rd   rf   rh   rp   rw   r~   r   r   r   r   r   r   r   r   r   r:   r   r   rQ   rQ   S   s^    




KG"))	
-0
,51,2.r   rQ   c                   R    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)TestPersistencez*Testing features like pickle and deepcopy.c                 R    d| _         | j                  | j                         | _        y )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_methodzTestPersistence.setup_method  s!    	  IIdii(	r   c                     t        j                  | j                  d      }t        j                  |      }|j                  t
        k(  sJ |j                         | j                  j                         k(  sJ y )N   )pickledumpsr   loads	__class__r   rY   )r   dumpedloadeds      r   !test_pickle_and_unpickle_identityz1TestPersistence.test_pickle_and_unpickle_identity&  s[     dii+f%=000}}$))"2"2"4444r   c                     t        j                  | j                        }|j                         | j                  j                         k(  sJ y rk   )copydeepcopyr   rY   )r   copieds     r   test_deepcopy_identityz&TestPersistence.test_deepcopy_identity.  s5    tyy)}}$))"2"2"4444r   c                     t        j                         dz   }d|z  }| j                  |      }t        j                  |       t        j                  |       y )Nr   r/   )r0   r1   r   r   r   )r   r3   r4   r   s       r    test_copy_deeply_nested_documentz0TestPersistence.test_copy_deeply_nested_document3  sF     %%'!+E!yy 		$dr   c                     t        dd      }|j                  }|j                         }dt        |      k(  sJ ||j                  k(  sJ y )Ns   <p>&nbsp;</p>ry   u	   <p> </p>)r   original_encoding__copy__rA   )r   r   r+   r   s       r   test_copy_preserves_encodingz,TestPersistence.test_copy_preserves_encoding?  sK    -}=))}}c$i'''411111r   c                    | j                  d      j                  }d|_        d|_        |j	                         }|j                  |j                  k(  sJ |j                  |j                  k(  sJ |j
                  |j
                  k(  sJ |j                  |j                  k(  sJ |j                  |j                  k(  sJ |j                  |j                  k(  sJ y )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_informationz7TestPersistence.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                     d}| j                  |      }t        j                  |t        j                        }t        j                  |      }|j                         |j                         k(  sJ y rI   )r   r   r   HIGHEST_PROTOCOLr   rY   )r   r   r   r   r   s        r   test_unicode_picklez#TestPersistence.test_unicode_pickleX  sR    #yydF$;$;<f%}}$++-///r   c                 &   d}| j                  |      }|j                  d      }t        j                  |      }||k(  sJ d |j                  u sJ d |j                  u sJ d |j
                  usJ d |j
                  u sJ d |j                  u sJ y )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_treezATestPersistence.test_copy_navigablestring_is_not_attached_to_tree`  s    ,yyYYeY$YYr]Rxxryy   r&&&2??***r&&&r*****r   c                     d}| j                  |      }|j                  }t        j                  |      }||k(  sJ t        |t              sJ y )Nz<b><!--Foo--></b>)r   r   r   
isinstancer   r   s        r   0test_copy_navigablestring_subclass_has_same_typez@TestPersistence.test_copy_navigablestring_subclass_has_same_typel  sE    "yy[[YYr]Rxx"g&&&r   c                 b    d}| j                  |      }t        j                  |      }||k(  sJ y )Nz)<div><b>Foo<a></a></b><b>Bar</b></div>end)r   r   )r   r   r   	soup_copys       r   test_copy_entire_soupz%TestPersistence.test_copy_entire_soupt  s/    :yyIIdO	y   r   c                 B   d}| j                  |      }|j                  }t        j                  |      }t        |      t        |      k(  sJ ||k(  sJ ||usJ d |j                  u sJ d |j
                  u sJ d |j                  d      j                  u sJ d |j                  d      j                  usJ |d   |d   usJ |d   j                  d       dj                         |d   k(  sJ dj                         |d   k(  sJ t        |d   t              sJ y )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   rA   r   r   r   r   appendsplitr   r   )r   r   r   r   div_copys        r   test_copy_tag_copies_contentsz-TestPersistence.test_copy_tag_copies_contentsz  s7   Hyyhh99S> 3x3x=(((h (""" 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   N)rL   rM   rN   rO   r   r   r   r   r   r   r   r   r   r   r   r:   r   r   r   r     s>    0)&55

2O$0
+'!Ar   r   c                       e Zd Zd Zd Zy)TestEqualityc                     | j                  d      }|j                  d      \  }}|j                  d      \  }}||k(  sJ ||cxk(  rdk(  sJ  J |dk7  sJ y )N<a>string</a> <a>string</a>rs   r   r   s   string)r   find_allr   r   first_asecond_afirst_stringsecond_strings         r   test_comparisonzTestEquality.test_comparison  st    yy67 MM#.&*mm8m&D#m (""" }888888 y(((r   c                 2   | j                  d      }|j                  d      \  }}|j                  d      \  }}t        |      t        |      k(  sJ t        |      t        |      k7  sJ t        |      t        |      cxk(  rt        d      k(  sJ  J y )Nr   rs   r   r   )r   r   hashidr   s         r   	test_hashzTestEquality.test_hash  s    yy67 MM#.&*mm8m&D#m G}X... '{bl*** L!T-%8JDNJJJJJr   N)rL   rM   rN   r   r   r:   r   r   r   r     s    )Kr   r   )rO   r   r   r"   r0   r>   bs4r   bs4.elementr   r   
bs4.filterr    r   r
   rQ   r   r   r:   r   r   <module>r      sd    0    
   $
<"8 <"~z.X z.zDAh DANK8 Kr   