
    MhC?                         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dS )z*Tests of the bs4.element.PageElement class    N)BeautifulSoup)AttributeValueListComment)SoupStrainer   )SoupTestc                   H    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S )TestEncodingz0Test the ability to encode objects into strings.c                     d}|                      |          }|j        j                            d          d                    d          k    sJ d S )N
   <b>☃</b>utf-8   ☃)soupbstringencodeselfhtmlr   s      Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/bs4/tests/test_pageelement.py"test_unicode_string_can_be_encodedz/TestEncoding.test_unicode_string_can_be_encoded   sM    #yyv}##G,,0D0DW0M0MMMMMMM    c                     d}|                      |          }|j                            d          |                    d          k    sJ d S )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   sG    #yyv}}W%%W)=)=======r   c                 t    d}|                      |          }|j                            d          dk    sJ d S )Nr   asciis   <b>&#9731;</b>r   r   s      r   <test_encoding_substitutes_unrecognized_characters_by_defaultzITestEncoding.test_encoding_substitutes_unrecognized_characters_by_default!   s<    #yyv}}W%%):::::::r   c                     d}|                      |          }t          j        t                    5  |                    dd           d d d            d S # 1 swxY w Y   d S )Nr   r   strict)errors)r   pytestraisesUnicodeEncodeErrorr   r   s      r    test_encoding_can_be_made_strictz-TestEncoding.test_encoding_can_be_made_strict&   s    #yy]-.. 	2 	2KKK111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   AAAc                 r    d}|                      |          }d|j                                        k    sJ d S )Nr   r   )r   r   decode_contentsr   s      r   test_decode_contentsz!TestEncoding.test_decode_contents,   s;    #yy 6 6 8 8888888r   c                     d}|                      |          }d                    d          |j                            d          k    sJ d S )Nr   r   utf8)encoding)r   r   r   encode_contentsr   s      r   test_encode_contentsz!TestEncoding.test_encode_contents1   sN    #yy##F++tv/E/Ev/E/V/VVVVVVVr   c                     t          j                    dz   }d|z  }|                     |          }|                                }||                    d          k    sJ d S )Nr   <span>s   <span>)sysgetrecursionlimitr   r   count)r   limitmarkupr   encodeds        r   "test_encode_deeply_nested_documentz/TestEncoding.test_encode_deeply_nested_document6   sb     %''!+E!yy  ++--i00000000r   c                 j   d}|                      |          }t          j        d          5 }|                                 d                    d          |j                                        k    sJ 	 d d d            n# 1 swxY w Y   d |D             }t          d |D                       sJ d S )Nr   T)recordr   r*   c                 6    g | ]}t          |j                  S  )strmessage).0warnings     r   
<listcomp>z?TestEncoding.test_deprecated_renderContents.<locals>.<listcomp>F   s"    666GO$$666r   c              3   "   K   | ]
}|d k    V  dS )zjCall to deprecated method renderContents. (Replaced by encode_contents) -- Deprecated since version 4.0.0.Nr:   )r=   xs     r   	<genexpr>z>TestEncoding.test_deprecated_renderContents.<locals>.<genexpr>G   sA       
 
  {|
 
 
 
 
 
r   )r   warningscatch_warningsrenderContentsr   r   all)r   r   r   wmsgss        r   test_deprecated_renderContentsz+TestEncoding.test_deprecated_renderContents@   s'   #yy$D111 	KQ!!! ''//463H3H3J3JJJJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 76A666 
 
 
 
 
 
 
 	
 	
 	
 	
 	
s   ABBBc                 ^    d}|                      |          }|t          |          k    sJ d S Nr   )r   reprr   s      r   	test_reprzTestEncoding.test_reprM   s3    #yytDzz!!!!!!r   N)__name__
__module____qualname____doc__r   r   r   r%   r(   r-   r6   rI   rM   r:   r   r   r
   r
      s        ::N N N
> > >
; ; ;
2 2 29 9 9
W W W
1 1 1
 
 
" " " " "r   r
   c                   x    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dS )TestFormatterszrTest the formatting feature, used by methods like decode() and
    prettify(), and the formatters themselves.
    c                     d}|                      |          }|                    d          }||                     d          k    sJ d S 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   a    Wyy  ++	+22$++R
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S )N'   <br><b>&lt;&lt;Sacré bleu!&gt;&gt;</b>r   rX   z.<br/><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rZ   r]   s       r   test_formatter_htmlz"TestFormatters.test_formatter_htmla   sf    V 	 yy  +++//$++<
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S )Nrb   html5rX   z-<br><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rZ   r]   s       r   test_formatter_html5z#TestFormatters.test_formatter_html5k   sf    V 	 yy  +++00$++;
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S rU   rZ   r]   s       r   test_formatter_minimalz%TestFormatters.test_formatter_minimalu   r`   r   c                     d}|                      |          }|                    d           }||                     d          k    sJ d S )NrV   rX   u   <b><<Sacré bleu!>></b>rZ   r]   s       r   test_formatter_nullz"TestFormatters.test_formatter_null~   sc    Wyy  +++-- $++F
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d           }||                     d          k    sJ d S )Nz!<b>&lt;foo&gt;</b><b>bar</b><br/>c                 *    |                                  S NupperrA   s    r   <lambda>z6TestFormatters.test_formatter_custom.<locals>.<lambda>   s    !'')) r   rX   z<b><FOO></b><b>BAR</b><br/>rZ   r]   s       r   test_formatter_customz$TestFormatters.test_formatter_custom   sW    4yy  ++(;(;+<< $++,IJJJJJJJJr   c                 d   d}|                      |          }|j        }d}||                                k    sJ ||                    d          k    sJ d}||                    d          k    sJ ||                    d           k    sJ d}||                    d           k    sJ d S )	Nu%   <a href="http://a.com?a=b&c=é">e</a>u)   <a href="http://a.com?a=b&amp;c=é">e</a>rW   rX   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                 *    |                                  S rm   rn   rp   s    r   rq   zJTestFormatters.test_formatter_is_run_on_attribute_values.<locals>.<lambda>   s    AGGII r   )r   ar[   )r   r4   r   ru   expect_minimalexpect_htmlexpect_uppers          r   )test_formatter_is_run_on_attribute_valuesz8TestFormatters.test_formatter_is_run_on_attribute_values   s    8yy  FD++++I!>!>>>>>Gahhh888888D111111>qxx2E2ExFFFFFFFFr   c                 Z    d}t          |d                                          }d|v sJ d S )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3::<<((((((r   c                 Z    d}t          |d                                          }d|v sJ d S )NzF
  <style type="text/css">
   console.log("< < hey > > ");
  </style>
r{   r|   r}   r~   s      r   1test_formatter_skips_style_tag_for_html_documentsz@TestFormatters.test_formatter_skips_style_tag_for_html_documents   r   r   c                 n    |                      d          }d|j                                        k    sJ d S )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   sM    yya
 
 jx  ""# # # # # #r   c                 v    d}d}|                      |          }||j                                        k    sJ d S )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   sH     yy  **,,,,,,,,r   c                 `    t          dd          }|                    d           }d|v sJ d S )Nz<html><body>foo</body></html>r{   c                 *    |                                  S rm   rn   rp   s    r   rq   zITestFormatters.test_prettify_accepts_formatter_function.<locals>.<lambda>   s    17799 r   rX   FOO)r   r   )r   r   prettys      r   (test_prettify_accepts_formatter_functionz7TestFormatters.test_prettify_accepts_formatter_function   s:    <mLL)<)<==r   c                     |                      d          }t          t          |                                          u sJ d S )N<a></a>)r   r;   typer   r   s     r   (test_prettify_outputs_unicode_by_defaultz7TestFormatters.test_prettify_outputs_unicode_by_default   s:    yy##d4==??++++++++r   c                     |                      d          }t          t          |                    d                    u sJ d S )Nr   r   )r   bytesr   r   r   s     r   test_prettify_can_encode_dataz,TestFormatters.test_prettify_can_encode_data   s>    yy##T]]73344444444r   c                     d}|                      |          }|j                            d          }||                    d          k    sJ d S )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   sN    Gyy  &--((&--00000000r   c                 X   d}|                      |          }|j        d         dk    sJ |                    d          }d|v sJ |                    d          }d|v sJ |                    d          }d	|v sJ |                    d
                              d
          }d|v sJ d S )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   r[   )r   meta_tagr   utf_8r   	shift_jisutf_16_us          r   test_encoding_substitutionz)TestFormatters.test_encoding_substitution   s     W 	 yy"" y#'BBBBB G$$5((((X&& F****KK,,	#y0000;;x((//998++++++r   c                     d}t          d          }|                     ||          }|j        d         j        dk    sJ d S )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  sQ    ? 	  &&yyHy55}Q$------r   N)rN   rO   rP   rQ   r_   rc   rf   rh   rj   rr   ry   r   r   r   r   r   r   r   r   r   r   r:   r   r   rS   rS   S   s#        
 
 

 
 

 
 

 
 

 
 
K K KG G G") ) )) ) )	
 	
 	
- - -0  
, , ,5 5 51 1 1, , ,2. . . . .r   rS   c                   T    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S )TestPersistencez*Testing features like pickle and deepcopy.c                 R    d| _         |                     | j                   | _        d S )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&    	  IIdi((			r   c                     t          j        | j        d          }t          j        |          }|j        t
          k    sJ |                                | j                                        k    sJ d S )N   )pickledumpsr   loads	__class__r   r[   )r   dumpedloadeds      r   !test_pickle_and_unpickle_identityz1TestPersistence.test_pickle_and_unpickle_identity&  sg     di++f%%=0000}}$)"2"2"4"4444444r   c                     t          j        | j                  }|                                | j                                        k    sJ d S rm   )copydeepcopyr   r[   )r   copieds     r   test_deepcopy_identityz&TestPersistence.test_deepcopy_identity.  s@    ty))}}$)"2"2"4"4444444r   c                     t          j                    dz   }d|z  }|                     |          }t          j        |           t          j        |           d S )Nr   r/   )r0   r1   r   r   r   )r   r3   r4   r   s       r    test_copy_deeply_nested_documentz0TestPersistence.test_copy_deeply_nested_document3  sU     %''!+E!yy  	$dr   c                     t          dd          }|j        }|                                }dt          |          k    sJ ||j        k    sJ d S )Ns   <p>&nbsp;</p>r{   u	   <p> </p>)r   original_encoding__copy__r;   )r   r   r+   r   s       r   test_copy_preserves_encodingz,TestPersistence.test_copy_preserves_encoding?  sX    -}==)}}c$ii''''41111111r   c                 V   |                      d          j        }d|_        d|_        |                                }|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 d S )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NNNr   c                     d}|                      |          }t          j        |t          j                  }t          j        |          }|                                |                                k    sJ d S rK   )r   r   r   HIGHEST_PROTOCOLr   r[   )r   r   r   r   r   s        r   test_unicode_picklez#TestPersistence.test_unicode_pickleX  s`    #yydF$;<<f%%}}$++--//////r   c                    d}|                      |          }|                    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 d S )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$$Yr]]Rxxxxry    r&&&&2?****r&&&&r*******r   c                     d}|                      |          }|j        }t          j        |          }||k    sJ t          |t                    sJ d S )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  sS    "yy[Yr]]Rxxxx"g&&&&&&&r   c                 l    d}|                      |          }t          j        |          }||k    sJ d S )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IdOO	y      r   c                    d}|                      |          }|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 |                    d          j        u sJ d |                    d          j        usJ |d         |d         usJ |d                             d           d	                                |d         k    sJ d	                                |d         k    sJ t          |d         t                    sJ d S )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   r;   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  si   Hyyh9S>> 3xx3x==((((h ("""" x&&&&x00000x}}E}22?????3885811>>>>> 7|8G#44444GC     CL0000}}(7"33333(7+-?@@@@@@@r   N)rN   rO   rP   rQ   r   r   r   r   r   r   r   r   r   r   r   r:   r   r   r   r     s        00) ) )&5 5 55 5 5

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



               $ # # # # #     
<" <" <" <" <"8 <" <" <"~z. z. z. z. z.X z. z. z.zDA DA DA DA DAh DA DA DANK K K K K8 K K K K Kr   