
    n9d7                         d 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	m
Z
 ddlm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)Comment	ResultSet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      :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_contents.   sb    #yy##F++tv/E/E 0F 0
 0
 
 
 
 
 
 
r   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_document5   sb     %''!+E!yy  ++--i00000000r   c                     d}|                      |          }|                                 d                    d          |j                                        k    sJ d S )Nr   r   r*   )r   renderContentsr   r   r   s      r   test_deprecated_renderContentsz+TestEncoding.test_deprecated_renderContents?   s[    #yy##F++tv/D/D/F/FFFFFFFr   c                 ^    d}|                      |          }|t          |          k    sJ d S Nr   )r   reprr   s      r   	test_reprzTestEncoding.test_reprE   s3    #yytDzz!!!!!!r   N)__name__
__module____qualname____doc__r   r   r   r%   r(   r-   r6   r9   r=    r   r   r
   r
      s        ::N N N
> > >
; ; ;
2 2 29 9 9

 
 
1 1 1G G G" " " " "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_minimalP   a    Wyy  ++	+22$++V
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S )N'   <br><b>&lt;&lt;Sacré bleu!&gt;&gt;</b>r   rI   z.<br/><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rK   rN   s       r   test_formatter_htmlz"TestFormatters.test_formatter_htmlY   sa    [yy  +++//$++<
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S )NrS   html5rI   z-<br><b>&lt;&lt;Sacr&eacute; bleu!&gt;&gt;</b>rK   rN   s       r   test_formatter_html5z#TestFormatters.test_formatter_html5a   sa    [yy  +++00$++;
 
 
 
 
 
 
 
r   c                     d}|                      |          }|                    d          }||                     d          k    sJ d S rF   rK   rN   s       r   test_formatter_minimalz%TestFormatters.test_formatter_minimali   rQ   r   c                     d}|                      |          }|                    d           }||                     d          k    sJ d S )NrG   rI   u   <b><<Sacré bleu!>></b>rK   rN   s       r   test_formatter_nullz"TestFormatters.test_formatter_nullr   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xs    r   <lambda>z6TestFormatters.test_formatter_custom.<locals>.<lambda>   s    AGGII r   rI   z<b><FOO></b><b>BAR</b><br/>rK   rN   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>rH   rI   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 r^   r_   ra   s    r   rc   zJTestFormatters.test_formatter_is_run_on_attribute_values.<locals>.<lambda>   s    AGGII r   )r   arL   )r   r4   r   rg   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>
rm   rn   ro   rp   s      r   1test_formatter_skips_style_tag_for_html_documentsz@TestFormatters.test_formatter_skips_style_tag_for_html_documents   rs   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   s`    yynoo mptpx  qB  qB  qD  qD  D  D  D  D  D  D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>
rw   )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>rm   c                 *    |                                  S r^   r_   ra   s    r   rc   zITestFormatters.test_prettify_accepts_formatter_function.<locals>.<lambda>   s    QWWYY r   rI   FOO)r   ry   )r   r   prettys      r   (test_prettify_accepts_formatter_functionz7TestFormatters.test_prettify_accepts_formatter_function   s:    <mLL+>+>??r   c                     |                      d          }t          t          |                                          k    sJ d S )N<a></a>)r   strtypery   rz   s     r   (test_prettify_outputs_unicode_by_defaultz7TestFormatters.test_prettify_outputs_unicode_by_default   s:    yy##d4==??++++++++r   c                     |                      d          }t          t          |                    d                    k    sJ d S )Nr   r   )r   bytesr   ry   rz   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   rL   )r   meta_tagr   utf_8r   	shift_jisutf_16_us          r   test_encoding_substitutionz)TestFormatters.test_encoding_substitution   s    2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   sO    G  &&yyHy55}Q$------r   N)r>   r?   r@   rA   rP   rT   rW   rY   r[   rd   rk   rr   ru   r{   r~   r   r   r   r   r   r   rB   r   r   rD   rD   K   s&        
 
 

 
 

 
 

 
 

 
 
K K KG G G") ) )) ) )D D D- - -0  
, , ,5 5 51 1 1, , ,0	. 	. 	. 	. 	.r   rD   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   rL   )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 r^   )copydeepcopyr   rL   )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   r   s        r    test_copy_deeply_nested_documentz0TestPersistence.test_copy_deeply_nested_document  sR     %''!+E!yy  4t$$r   c                     t          dd          }|j        }|                                }dt          |          k    sJ ||j        k    sJ d S )Ns   <p>&nbsp;</p>rm   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_information2  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 r;   )r   r   r   HIGHEST_PROTOCOLr   rL   )r   r   r   r   r   s        r   test_unicode_picklez#TestPersistence.test_unicode_pickleE  s`    #yydF$;<<f%%}}$++--//////r   c                    d}|                      |          }|                    d          }t          j        |          }||k    sJ d |j        k    sJ d |j        k    sJ d |j        k    sJ d |j        k    sJ d |j        k    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_treeM  s    ,yyYYeY$$Yr]]Rxxxxry    r&&&&r&&&&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_typeY  sS    "yy[Yr]]Rxxxx"g&&&&&&&r   c                 l    d}|                      |          }t          j        |          }||k    sJ d S )N)<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_soupa  s:    :yyIdOO	y      r   c                    d}|                      |          }|j        }t          j        |          }t          |          t          |          k    sJ ||k    sJ ||usJ d |j        k    sJ d |j        k    sJ d |                    d          j        k    sJ d |                    d          j        k    sJ d S )Nr   Barr   )r   rx   r   r   r   r   r   r   )r   r   r   rx   div_copys        r   test_copy_tag_copies_contentsz-TestPersistence.test_copy_tag_copies_contentsg  s    :yyh9S>> 3xx3x==((((h ("""" x&&&&x00000x}}E}22?????sxxux--:::::::r   N)r>   r?   r@   rA   r   r   r   r   r   r   r   r   r   r   r   rB   r   r   r   r      s        00) ) )&5 5 55 5 5

% 
% 
%2 2 2O O O&0 0 0
+ 
+ 
+' ' '! ! !; ; ; ; ;r   r   )rA   r   r   r"   r0   bs4r   bs4.elementr   r   r    r   r
   rD   r   rB   r   r   <module>r      s-   0 0    



               
     7" 7" 7" 7" 7"8 7" 7" 7"tn. n. n. n. n.X n. n. n.b}; }; }; }; };h }; }; }; }; };r   