o
    MK&h                     @   s  U d Z 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mZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZm Z m!Z!m"Z" z
ddl#m$Z$ dZ%W n e&yx   dZ%Y nw ej'(dduZ)zddl*Z+dZ,e+j-j.Z.W n e&y   dZ,dZ.Y nw eZ/e"e e0d< dZ1e2e0d< G dd de3Z4G dd de4Z5G dd de5Z6G dd de5Z7G dd de6Z8dS )zHelper classes for tests.MIT    N)BeautifulSoup)
AttributeValueListCharsetMetaAttributeValueCommentContentMetaAttributeValueDoctypePageElementPYTHON_SPECIFIC_ENCODINGSScript
StylesheetTag)SoupStrainer)XMLParsedAsHTMLWarning)_IncomingMarkup)TreeBuilder)HTMLParserTreeBuilder)AnyIterableOptionalTupleType)SelectorSyntaxErrorTFhtml5lib)r   default_builderu-
  A bare string
<!DOCTYPE xsl:stylesheet SYSTEM "htmlent.dtd">
<!DOCTYPE xsl:stylesheet PUBLIC "htmlent.dtd">
<div><![CDATA[A CDATA section where it doesn't belong]]></div>
<div><svg><![CDATA[HTML5 does allow CDATA sections in SVG]]></svg></div>
<div>A <meta> tag</div>
<div>A <br> tag that supposedly has contents.</br></div>
<div>AT&T</div>
<div><textarea>Within a textarea, markup like <b> tags and <&<&amp; should be treated as literal</textarea></div>
<div><script>if (i < 2) { alert("<b>Markup within script tags should be treated as literal.</b>"); }</script></div>
<div>This numeric entity is missing the final semicolon: <x t="pi&#241ata"></div>
<div><a href="http://example.com/</a> that attribute value never got closed</div>
<div><a href="foo</a>, </a><a href="bar">that attribute value was closed by the subsequent tag</a></div>
<! This document starts with a bogus declaration ><div>a</div>
<div>This document contains <!an incomplete declaration <div>(do you see it?)</div>
<div>This document ends with <!an incomplete declaration
<div><a style={height:21px;}>That attribute value was bogus</a></div>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">The doctype is invalid because it contains extra whitespace
<div><table><td nowrap>That boolean attribute had no value</td></table></div>
<div>Here's a nonexistent entity: &#foo; (do you see it?)</div>
<div>This document ends before the entity finishes: &gt
<div><p>Paragraphs shouldn't contain block display elements, but this one does: <dl><dt>you see?</dt></p>
<b b="20" a="1" b="10" a="2" a="3" a="4">Multiple values for the same attribute.</b>
<div><table><tr><td>Here's a table</td></tr></table></div>
<div><table id="1"><tr><td>Here's a nested table:<table id="2"><tr><td>foo</td></tr></table></td></div>
<div>This tag contains nothing but whitespace: <b>    </b></div>
<div><blockquote><p><b>This p tag is cut off by</blockquote></p>the end of the blockquote tag</div>
<div><table><div>This table contains bare markup</div></table></div>
<div><div id="1">
 <a href="link1">This link is never closed.
</div>
<div id="2">
 <div id="3">
   <a href="link2">This link is closed.</a>
  </div>
</div></div>
<div>This document contains a <!DOCTYPE surprise>surprise doctype</div>
<div><a><B><Cd><EFG>Mixed case tags are folded to lowercase</efg></CD></b></A></div>
<div><our☃>Tag name contains Unicode characters</our☃></div>
<div><a ☃="snowman">Attribute name contains Unicode characters</a></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
BAD_DOCUMENTc                   @   s   e Zd Zedee fddZdedede	fddZ
dededefdd	Z	
ddedee dd
fddZeZdedd
fddZ	ddededee fddZdee dee dd
fddZdee dee dd
fddZd
S )SoupTestreturnc                 C   s   t S N)r   self r!   E/var/www/html/venv/lib/python3.10/site-packages/bs4/tests/__init__.pyr   f   s   zSoupTest.default_buildermarkupkwargsc                 K   s"   | d| j}t|fd|i|S )z*Build a Beautiful Soup object from markup.builder)popr   r   )r    r#   r$   r%   r!   r!   r"   soupj   s   zSoupTest.soupc                 K   s   | j di ||S )z[Turn an HTML fragment into a document.

        The details depend on the builder.
        Nr!   )r   test_fragment_to_document)r    r#   r$   r!   r!   r"   document_foro   s   zSoupTest.document_forNto_parsecompare_parsed_toc                 C   s   | j }t||d}|du rt|tsJ |}| | |ks!J tdd t|j	 D s1J |j
gdd |jD ks?J dS )ziParse some markup using Beautiful Soup and verify that
        the output markup is as expected.
        r%   Nc                 s   s    | ]}|d kV  qdS )r   Nr!   ).0vr!   r!   r"   	<genexpr>   s    z'SoupTest.assert_soup.<locals>.<genexpr>c                 S      g | ]}|j qS r!   namer-   xr!   r!   r"   
<listcomp>       z(SoupTest.assert_soup.<locals>.<listcomp>)r   r   
isinstancestrdecoder)   alllistopen_tag_countervaluesROOT_TAG_NAMEtagStack)r    r*   r+   r%   objr!   r!   r"   assert_soupv   s     zSoupTest.assert_soupelementc                 C   s8   d}|j D ]}|r||jksJ ||jksJ |}qdS )zyEnsure that next_element and previous_element are properly
        set for all descendants of the given element.
        N)descendantsnext_elementprevious_element)r    rB   earlierer!   r!   r"   assertConnectedness   s   
zSoupTest.assertConnectednessFel_recursive_callc           	   	   C   s  d}|j du r4|jdu sJ d||jd|jdu s%J d||jd|jdu s4J d||jdd}d}d}t|jd }|jD ]}d}|dkr|j dur~|j|u s`J d||j||j|u soJ d||j||jdu s~J d||jdn\|j|j|d  u sJ d	||j|j|d  |j|d  j|u sJ d
|j|d  |j|d  j||dur|j|u sJ d||j||j j|j|u sJ d||j|t|t	r|jr| 
|d}|dusJ |jdu sJ d
||jd|dur|}n|}||kr|jdu sJ d
||jd|d7 }qD|dur)|n|}|du r2|}|su|duru|}	 |du rU|jdu sRJ d||jd	 dS |jdurp|j|ju smJ d||j|j	 dS |j }q=|S )z.Ensure proper linkage throughout the document.Nz3Bad previous_element
NODE: {}
PREV: {}
EXPECTED: {}z3Bad previous_sibling
NODE: {}
PREV: {}
EXPECTED: {}z/Bad next_sibling
NODE: {}
NEXT: {}
EXPECTED: {}r      z/Bad next_element
NODE: {}
NEXT: {}
EXPECTED: {}z2Bad previous_sibling
NODE: {}
PREV {}
EXPECTED: {}z1Bad previous_sibling
NODE: {}
PREV {}
EXPECTED {}z-Bad next_sibling
NODE: {}
NEXT {}
EXPECTED {}z=Bad previous_element
NODE: {}
PREV {}
EXPECTED {}
CONTENTS {}z-Bad next_element
NODE: {}
NEXT {}
EXPECTED {}T)parentrE   formatprevious_siblingnext_siblinglencontentsrD   r7   r   linkage_validator)	r    rI   rJ   
descendantidxchild
last_childlast_idxtargetr!   r!   r"   rR      s   


	





zSoupTest.linkage_validatortagsshould_matchc                 C      dd |D |ksJ dS )zMake sure that the given tags have the correct text.

        This is used in tests that define a bunch of tags, each
        containing a single string, and then select certain strings by
        some mechanism.
        c                 S   r0   r!   stringr-   tagr!   r!   r"   r5   '  r6   z+SoupTest.assert_selects.<locals>.<listcomp>Nr!   r    rY   rZ   r!   r!   r"   assert_selects   s   zSoupTest.assert_selectsc                 C   r[   )zMake sure that the given tags have the correct IDs.

        This is used in tests that define a bunch of tags, each
        containing a single string, and then select certain strings by
        some mechanism.
        c                 S   s   g | ]}|d  qS idr!   r^   r!   r!   r"   r5   2  s    z/SoupTest.assert_selects_ids.<locals>.<listcomp>Nr!   r`   r!   r!   r"   assert_selects_ids)  s   	zSoupTest.assert_selects_idsr   )F)__name__
__module____qualname__propertyr   r   r   r   r   r   r'   r8   r)   r   rA   assertSoupEqualsr   rH   boolr	   rR   r   ra   rd   r!   r!   r!   r"   r   e   s@    

 	r   c                   @   s   e Zd Zejddi edgdddgigdd Zejdedgd	ddgigd
d Zdd Z	dd Z
dd Zdd ZdS )TreeBuilderSmokeTestmulti_valued_attributesNclass)b*notclassc                 C   s(   d}| j ||d}|jd dksJ d S )NzC<html xmlns="http://www.w3.org/1999/xhtml"><a class="a b c"></html>rl   rm   za b cr'   ar    rl   r#   r'   r!   r!   r"   test_attribute_not_multi_valued8  s   z4TreeBuilderSmokeTest.test_attribute_not_multi_valued)rs   c                 C   s,   d}| j ||d}|jd g dksJ d S )Nz<a class="a b c">rq   rm   )rs   rn   crr   rt   r!   r!   r"   test_attribute_multi_valued@  s   z0TreeBuilderSmokeTest.test_attribute_multi_valuedc                 C   s    d}|  | d}|  | d S )Nz<![if word]>content<![endif]>z<!DOCTYPE html]ff>)r'   r    r#   r!   r!   r"   test_invalid_doctypeH  s   
z)TreeBuilderSmokeTest.test_invalid_doctypec                 C   s4   d}| j |tddd}tdd |jD rJ d S )Nz<!DOCTYPE html>
<html>
</html>htmlr1   
parse_onlyc                 s   s    | ]}t |tV  qd S r   )r7   r   r3   r!   r!   r"   r/   S  s    z=TreeBuilderSmokeTest.test_doctype_filtered.<locals>.<genexpr>)r'   r   anyrC   r    r#   r'   r!   r!   r"   test_doctype_filteredP  s   z*TreeBuilderSmokeTest.test_doctype_filteredc                 C   s   G dd dt }d}| j|d}| j||d}|j}t|j|s"J d|d ks*J d|d	< d|d	 ks6J d
}|| ks@J d S )Nc                       s&   e Zd Zdedef fddZ  ZS )zNTreeBuilderSmokeTest.test_custom_attribute_dict_class.<locals>.MyAttributeDictkeyvaluec                    s   t  |d d S )N
OVERRIDDEN)super__setitem__)r    r   r   	__class__r!   r"   r   W  s   zZTreeBuilderSmokeTest.test_custom_attribute_dict_class.<locals>.MyAttributeDict.__setitem__)re   rf   rg   r8   r   r   __classcell__r!   r!   r   r"   MyAttributeDictV  s    r   "<a attr1="val1" attr2="val2">f</a>)attribute_dict_classr,   r   attr1Tattr3zA<a attr1="OVERRIDDEN" attr2="OVERRIDDEN" attr3="OVERRIDDEN">f</a>)dictr   r'   rs   r7   attrsr9   )r    r   r#   r%   r'   r_   expectr!   r!   r"    test_custom_attribute_dict_classU  s   z5TreeBuilderSmokeTest.test_custom_attribute_dict_classc                 C   sz   G dd dt }| jdtdgi|d}d}| j||d}|j}|d d	ks(J |d d
dgks2J t|d |s;J d S )Nc                       s   e Zd Z fddZ  ZS )z_TreeBuilderSmokeTest.test_custom_attribute_value_list_class.<locals>.MyCustomAttributeValueListc                    s    t  j|i | | d d S )Nextra)r   __init__append)r    argsr$   r   r!   r"   r   j  s   zhTreeBuilderSmokeTest.test_custom_attribute_value_list_class.<locals>.MyCustomAttributeValueList.__init__)re   rf   rg   r   r   r!   r!   r   r"   MyCustomAttributeValueListi  s    r   ro   attr2)rl   attribute_value_list_classr   r,   r   val1val2r   )r   r   setr'   rs   r7   )r    r   r%   r#   r'   r_   r!   r!   r"   &test_custom_attribute_value_list_classh  s   z;TreeBuilderSmokeTest.test_custom_attribute_value_list_class)re   rf   rg   pytestmarkparametrizer   ru   rw   ry   r   r   r   r!   r!   r!   r"   rk   5  s    

rk   c                	   @   s<  e Zd ZdZdd Zdd Zdd Zdd	 Zd
eddfddZ		dd
edede
eef fddZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGdH Z(dIdJ Z)dKdL Z*dMdN Z+dOdP Z,dQdR Z-dSdT Z.dUdV Z/dWdX Z0dYdZ Z1d[d\ Z2d]d^ Z3d_d` Z4dadb Z5dcdd Z6dedf Z7dgdh Z8didj Z9dkdl Z:dmdn Z;dodp Z<dqdr Z=dsdt Z>dudv Z?dwdx Z@dydz ZAd{d| ZBd}d~ ZCdd ZDdd ZEdd ZFdd ZGdd ZHdS )HTMLTreeBuilderSmokeTestaC  A basic test of a treebuilder's competence.

    Any HTML treebuilder, present or future, should be able to pass
    these tests. With invalid markup, there's room for interpretation,
    and different parsers can handle it differently. But with the
    markup in these tests, there's not much room for interpretation.
    c                 C   sH   dD ]}|  d}||}|jdu sJ q| dd | dd dS )zmVerify that all HTML4 and HTML5 empty element (aka void element) tags
        are handled correctly.
        )areabasebrcolembedhrimginputkeygenlinkmenuitemmetaparamsourcetrackwbrspacerframe Tz<br/><br/><br/>z<br /><br /><br />N)r'   new_tagis_empty_elementrA   )r    r2   r'   r   r!   r!   r"   test_empty_element_tags  s   

z0HTMLTreeBuilderSmokeTest.test_empty_element_tagsc                 C   sp   |  d}t|jjtsJ t|jjtsJ |  d}t|jjts%J |jjdks-J t|jjts6J d S )Nz7<style>Some CSS</style><script>Some Javascript</script>z<style><!--Some CSS--></style>z<!--Some CSS-->)r'   r7   styler]   r   scriptr   r    r'   r!   r!   r"   test_special_string_containers  s   

z7HTMLTreeBuilderSmokeTest.test_special_string_containersc                 C   sH   |  d}t|tj}t|}|jtksJ | | ks"J d S )N<a><b>foo</a>)r'   pickledumpsHIGHEST_PROTOCOLloadsr   r   r9   r    treedumpedloadedr!   r!   r"   !test_pickle_and_unpickle_identity  s
   

z:HTMLTreeBuilderSmokeTest.test_pickle_and_unpickle_identityc                 C   s:   d}|  |}t|tj}t|}|jjdu sJ d S )Nz
<!DOCTYPE html>
<html lang="en">
<head><title>blabla</title></head>
<body><?xml encoding="utf-8" ?><html></html></body>
</html>
F)r'   r   r   r   r   r%   is_xml)r    r#   r'   pickledr!   r!   r"   #test_pickle_and_unpickle_bad_markup  s
   

z<HTMLTreeBuilderSmokeTest.test_pickle_and_unpickle_bad_markupdoctype_fragmentr   Nc                 C   sv   |  |\}}|jd }|jtksJ ||ksJ |ddt| |ks(J |jdus/J |jjd dks9J dS )z8Assert that a given doctype string is handled correctly.r   utf8Nfoo_document_with_doctyperQ   r   r   encoderP   pr    r   doctype_strr'   doctyper!   r!   r"   assertDoctypeHandled  s   
z-HTMLTreeBuilderSmokeTest.assertDoctypeHandledDOCTYPEdoctype_stringc                 C   s,   d||f }|d }|  |}|d|fS )z5Generate and parse a document with the given doctype.z<!%s %s>z
<p>foo</p>r   r'   r   )r    r   r   r   r#   r'   r!   r!   r"   r     s   
z/HTMLTreeBuilderSmokeTest._document_with_doctypec                 C   s   |  d |  d dS )z?Make sure normal, everyday HTML doctypes are handled correctly.rz   z4html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"Nr   r   r!   r!   r"   test_normal_doctypes  s   
z-HTMLTreeBuilderSmokeTest.test_normal_doctypesc                 C   s(   |  d}|jd }d| ksJ d S )Nz
<!DOCTYPE>r   r   )r'   rQ   strip)r    r'   r   r!   r!   r"   test_empty_doctype  s   

z+HTMLTreeBuilderSmokeTest.test_empty_doctypec                 C   st   dD ]5}|  d|\}}|jd }|jtksJ |dksJ |dd t| dks-J |jjd dks7J qd S )N)r   DocTyperz   r   r   s   <!DOCTYPE html>r   r   r   r!   r!   r"   test_mixed_case_doctype  s   
z0HTMLTreeBuilderSmokeTest.test_mixed_case_doctypec                 C      d}|  | d S )Nznhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"r   )r    r   r!   r!   r"   test_public_doctype_with_url     z5HTMLTreeBuilderSmokeTest.test_public_doctype_with_urlc                 C      |  d d S )Nz$foo SYSTEM "http://www.example.com/"r   r   r!   r!   r"   test_system_doctype     z,HTMLTreeBuilderSmokeTest.test_system_doctypec                 C   r   )Nz#xsl:stylesheet SYSTEM "htmlent.dtd"r   r   r!   r!   r"   test_namespaced_system_doctype     z7HTMLTreeBuilderSmokeTest.test_namespaced_system_doctypec                 C   r   )Nz#xsl:stylesheet PUBLIC "htmlent.dtd"r   r   r!   r!   r"   test_namespaced_public_doctype  r   z7HTMLTreeBuilderSmokeTest.test_namespaced_public_doctypec                 C   sl   d}t jdd}| |}W d   n1 sw   Y  |ddd|ddks.J |g ks4J dS )zJA real XHTML document should come out more or less the same as it went in.   <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Hello.</title></head>
<body>Goodbye.</body>
</html>TrecordNutf-8   
    )warningscatch_warningsr'   r   replacer    r#   wr'   r!   r!   r"   test_real_xhtml_document  s   "z1HTMLTreeBuilderSmokeTest.test_real_xhtml_documentc                 C   s`   d}t jdd}| |}W d    n1 sw   Y  dt|dks(J g |ks.J d S )Ns.   <ns1:foo>content</ns1:foo><ns1:foo/><ns2:foo/>Tr      zns1:foo)r   r   r'   rP   find_allr   r!   r!   r"   test_namespaced_html  s   z-HTMLTreeBuilderSmokeTest.test_namespaced_htmlc                 C   sx   d}t jdd}| |}|jjdksJ W d    n1 s w   Y  |\}t|jts0J t|jtj	ks:J d S )Ns7   <?xml version="1.0" encoding="utf-8"?><tag>string</tag>Tr   r]   )
r   r   r'   r_   r]   r7   messager   r8   MESSAGE)r    r#   r   r'   warningr!   r!   r"   test_detect_xml_parsed_as_html$  s   
z7HTMLTreeBuilderSmokeTest.test_detect_xml_parsed_as_htmlc                 C   sB   d}|  |}|| ksJ d}|  |}||dksJ d S )Nz<?PITarget PIContent?>s   <?PITarget PIContent?>r   )r'   r9   r   r~   r!   r!   r"   test_processing_instruction4  s   

z4HTMLTreeBuilderSmokeTest.test_processing_instructionc                 C   s   t | j dS )zMake sure you can copy the tree builder.

        This is important because the builder is part of a
        BeautifulSoup object, and we want to be able to copy that.
        N)copydeepcopyr   r   r!   r!   r"   test_deepcopyA  s   z&HTMLTreeBuilderSmokeTest.test_deepcopyc                 C   s,   |  d}|jjrJ t|jdksJ dS )zA <p> tag is never designated as an empty-element tag.

        Even if the markup shows it as an empty-element tag, it
        shouldn't be presented that way.
        <p/><p></p>N)r'   r   r   r8   r   r!   r!   r"   !test_p_tag_is_never_empty_elementI     
z:HTMLTreeBuilderSmokeTest.test_p_tag_is_never_empty_elementc                 C   s(   |  dd |  dd |  dd dS )zA tag that's not closed by the end of the document should be closed.

        This applies to all tags except empty-element tags.
        <p>r   z<b>z<b></b>z<br><br/>NrA   r   r!   r!   r"   test_unclosed_tags_get_closedS  s   z6HTMLTreeBuilderSmokeTest.test_unclosed_tags_get_closedc                 C   s,   |  d}|jjsJ t|jdksJ dS )zA <br> tag is designated as an empty-element tag.

        Some parsers treat <br></br> as one <br/> tag, some parsers as
        two tags, but it should always be an empty-element tag.
        z	<br></br>r   N)r'   r   r   r8   r   r!   r!   r"   #test_br_is_always_empty_element_tag]  r   z<HTMLTreeBuilderSmokeTest.test_br_is_always_empty_element_tagc                 C   r   )Nz<em><em></em></em>r  r   r!   r!   r"   test_nested_formatting_elementsg  r   z8HTMLTreeBuilderSmokeTest.test_nested_formatting_elementsc                 C   s(   d}|  |}d|dd ksJ d S )Nz<!DOCTYPE html>
<html>
<head>
<title>Ordinary HEAD element test</title>
</head>
<script type="text/javascript">
alert("Help!");
</script>
<body>
Hello, world!
</body>
</html>
ztext/javascriptr   type)r'   find)r    rz   r'   r!   r!   r"   test_double_headj  s   
z)HTMLTreeBuilderSmokeTest.test_double_headc                 C   sj   d}|  | | |}|jdd}|jtksJ |jdd}||jks&J |jdd}||jks3J d S )Nz<p>foo<!--foobar-->baz</p>foobarr\   r   baz)rA   r'   r  r   r   rD   rE   )r    r#   r'   commentr   r	  r!   r!   r"   test_comment{  s   

z%HTMLTreeBuilderSmokeTest.test_commentc                 C   st   d}d}|  | |  | | |}|j |ksJ | |}|j |ks*J | d}|j dks8J dS )zWhitespace must be preserved in <pre> and <textarea> tags,
        even if that would mean not prettifying the markup.
        z<pre>a   z</pre>
z <textarea> woo
woo  </textarea>
z<textarea></textarea>z<textarea></textarea>
N)rA   r'   preprettifytextarea)r    
pre_markuptextarea_markupr'   r!   r!   r"   -test_preserved_whitespace_in_pre_and_textarea  s   




zFHTMLTreeBuilderSmokeTest.test_preserved_whitespace_in_pre_and_textareac                 C   s.   d}|  | d}|  | d}|  | dS )z+Inline elements can be nested indefinitely.z<b>Inside a B tag</b>z!<p>A <i>nested <b>tag</b></i></p>z/<p>A <a>doubly <i>nested <b>tag</b></i></a></p>Nr  )r    b_tagnested_b_tagdouble_nested_b_tagr!   r!   r"   test_nested_inline_elements  s   

z4HTMLTreeBuilderSmokeTest.test_nested_inline_elementsc                 C   s6   |  d}|j}|jjjdksJ |jjdksJ dS )zBlock elements can be nested.z*<blockquote><p><b>Foo</b></p></blockquote>FooN)r'   
blockquoter   rn   r]   )r    r'   r  r!   r!   r"    test_nested_block_level_elements  s   
z9HTMLTreeBuilderSmokeTest.test_nested_block_level_elementsc                 C   s   d}|  |d |  d dS )z$One table can go inside another one.z[<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>zh<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td></tr></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>Nr  rx   r!   r!   r"   test_correctly_nested_tables  s   	z5HTMLTreeBuilderSmokeTest.test_correctly_nested_tablesc                 C   s@   d}|  |}ddg|jd ksJ |j|jdddksJ d S )Nz<div class=" foo bar	 "></a>r   barrm   divzfoo bar)class_)r'   r  r  r~   r!   r!   r"   *test_multivalued_attribute_with_whitespace  s   
zCHTMLTreeBuilderSmokeTest.test_multivalued_attribute_with_whitespacec                 C   s(   d}|  |}dg|jjd ksJ d S )Nz1<table><div><div class="css"></div></div></table>cssrm   )r'   r  r~   r!   r!   r"   (test_deeply_nested_multivalued_attribute     
zAHTMLTreeBuilderSmokeTest.test_deeply_nested_multivalued_attributec                 C   (   d}|  |}ddg|jd ksJ d S )Nz<html class="a b"></html>rs   rn   rm   )r'   rz   r~   r!   r!   r"   "test_multivalued_attribute_on_html  r   z;HTMLTreeBuilderSmokeTest.test_multivalued_attribute_on_htmlc                 C      |  dd d S )Nz<a b="<a>"></a>z<a b="&lt;a&gt;"></a>r  r   r!   r!   r"   3test_angle_brackets_in_attribute_values_are_escaped     zLHTMLTreeBuilderSmokeTest.test_angle_brackets_in_attribute_values_are_escapedc                 C   r#  )Nz$<p>&bull; AT&T is in the s&p 500</p>u)   <p>• AT&amp;T is in the s&amp;p 500</p>r  r   r!   r!   r"   3test_strings_resembling_character_entity_references  s   zLHTMLTreeBuilderSmokeTest.test_strings_resembling_character_entity_referencesc                 C   r#  )Nz<p>Bob&apos;s Bar</p>z<p>Bob's Bar</p>r  r   r!   r!   r"   test_apos_entity  s   z)HTMLTreeBuilderSmokeTest.test_apos_entityc                 C   "   d}|  |}d|jjksJ d S )Nz%<p>&#147;Hello&#148; &#45;&#9731;</p>u   “Hello” -☃r'   r   r]   r~   r!   r!   r"   *test_entities_in_foreign_document_encoding  s   
zCHTMLTreeBuilderSmokeTest.test_entities_in_foreign_document_encodingc                 C   8   d}|  d| |  d| |  d| |  d| d S )Nu   <p id="piñata"></p>z<p id="pi&#241;ata"></p>z<p id="pi&#xf1;ata"></p>z<p id="pi&#Xf1;ata"></p>z<p id="pi&ntilde;ata"></p>r  r    r   r!   r!   r"   0test_entities_in_attributes_converted_to_unicode  
   zIHTMLTreeBuilderSmokeTest.test_entities_in_attributes_converted_to_unicodec                 C   r+  )Nu   <p>piñata</p>z<p>pi&#241;ata</p>z<p>pi&#xf1;ata</p>z<p>pi&#Xf1;ata</p>z<p>pi&ntilde;ata</p>r  r,  r!   r!   r"   *test_entities_in_text_converted_to_unicode  r.  zCHTMLTreeBuilderSmokeTest.test_entities_in_text_converted_to_unicodec                 C   r#  )Nz#<p>I said &quot;good day!&quot;</p>z<p>I said "good day!"</p>r  r   r!   r!   r"   ,test_quot_entity_converted_to_quotation_mark  s   zEHTMLTreeBuilderSmokeTest.test_quot_entity_converted_to_quotation_markc                 C   s,   d}|  d| |  d| |  d| d S )Nu   �z&#10000000000000;z&#x10000000000000;z&#1000000000;r  r,  r!   r!   r"   test_out_of_range_entity  s   z1HTMLTreeBuilderSmokeTest.test_out_of_range_entityc                 C   s<   |  d}d|jjjjksJ d|jjksJ | | dS )zDMostly to prevent a recurrence of a bug in the html5lib treebuilder.z!<html><h2>
foo</h2><p></p></html>r   N)r'   h2r]   rD   r2   r   rH   r   r!   r!   r"   test_multipart_strings  s   
z/HTMLTreeBuilderSmokeTest.test_multipart_stringsc                 C   sD   d}|  |}d|j ksJ d}|  |}d|j ks J d S )Nz<p>a &nosuchentity b</p>z<p>a &amp;nosuchentity b</p>z<p>a &nosuchentity; b</p>z<p>a &amp;nosuchentity; b</p>)r'   r   r9   r~   r!   r!   r"   test_invalid_html_entity  s   

z1HTMLTreeBuilderSmokeTest.test_invalid_html_entityc                 C   s,   d}|  |}|jjdusJ | | dS )8Prevent recurrence of a bug in the html5lib treebuilder.z?<html><head></head>
  <link></link>
  <body>foo</body>
</html>
N)r'   rz   bodyrH   r    contentr'   r!   r!   r"   #test_head_tag_between_head_and_body,  s   
z<HTMLTreeBuilderSmokeTest.test_head_tag_between_head_and_bodyc                 C   s   d}|  |}| |j dS )r5  z<!DOCTYPE html>
<html>
 <body>
   <article id="a" >
   <div><a href="1"></div>
   <footer>
     <a href="2"></a>
   </footer>
  </article>
  </body>
</html>
N)r'   rH   articler7  r!   r!   r"   test_multiple_copies_of_a_tag7  s   
z6HTMLTreeBuilderSmokeTest.test_multiple_copies_of_a_tagc                 C   sX   d}|  |}|| ksJ d|jd ksJ d|jd ks!J d|jd ks*J dS )	zParsers don't need to *understand* namespaces, but at the
        very least they should not choke on namespaces or lose
        data.s   <html xmlns="http://www.w3.org/1999/xhtml" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg"><head></head><body><mathml:msqrt>4</mathml:msqrt><b svg:fill="red"></b></body></html>http://www.w3.org/1999/xhtmlxmlns"http://www.w3.org/1998/Math/MathMLzxmlns:mathmlhttp://www.w3.org/2000/svgz	xmlns:svgN)r'   r   rz   r~   r!   r!   r"   test_basic_namespacesH  s   
z.HTMLTreeBuilderSmokeTest.test_basic_namespacesc                 C   r!  )Ns   <a class="foo bar">r   r  rm   rr   r~   r!   r!   r"   -test_multivalued_attribute_value_becomes_listT  s   
zFHTMLTreeBuilderSmokeTest.test_multivalued_attribute_value_becomes_listc                 C   r(  )NuD   <html><head><meta encoding="euc-jp"></head><body>Sacré bleu!</body>   Sacré bleu!)r'   r6  r]   r~   r!   r!   r"   test_can_parse_unicode_document`  s   
z8HTMLTreeBuilderSmokeTest.test_can_parse_unicode_documentc                 C   s*   t d}| jd|d}| dksJ dS )z2Parsers should be able to work with SoupStrainers.rn   z&A <b>bold</b> <meta/> <i>statement</i>r{   z<b>bold</b>N)r   r'   r9   )r    strainerr'   r!   r!   r"   test_soupstrainerh  s   z*HTMLTreeBuilderSmokeTest.test_soupstrainerc                 C   r#  )Nz<foo attr='bar'></foo>z<foo attr="bar"></foo>r  r   r!   r!   r"   7test_single_quote_attribute_values_become_double_quotesn  r%  zPHTMLTreeBuilderSmokeTest.test_single_quote_attribute_values_become_double_quotesc                 C   r   )N'<foo attr='bar "brawls" happen'>a</foo>r  )r    textr!   r!   r"   7test_attribute_values_with_nested_quotes_are_left_aloneq  r   zPHTMLTreeBuilderSmokeTest.test_attribute_values_with_nested_quotes_are_left_alonec                 C   s.   d}|  |}d|jd< | |j d d S )NrG  zBrawls happen at "Bob's Bar"attrz:<foo attr="Brawls happen at &quot;Bob's Bar&quot;">a</foo>)r'   r   rA   r9   )r    rH  r'   r!   r!   r"   :test_attribute_values_with_double_nested_quotes_get_quotedu  s   

zSHTMLTreeBuilderSmokeTest.test_attribute_values_with_double_nested_quotes_get_quotedc                 C   s   |  dd |  dd d S )Nz+<this is="really messed up & stuff"></this>z/<this is="really messed up &amp; stuff"></this>z.<a href="http://example.org?a=1&b=2;3">foo</a>z2<a href="http://example.org?a=1&amp;b=2;3">foo</a>r  r   r!   r!   r"   .test_ampersand_in_attribute_value_gets_escaped~  s   zGHTMLTreeBuilderSmokeTest.test_ampersand_in_attribute_value_gets_escapedc                 C   r   )Nz/<a href="http://example.org?a=1&amp;b=2;3"></a>r  r   r!   r!   r"   7test_escaped_ampersand_in_attribute_value_is_left_alone  r   zPHTMLTreeBuilderSmokeTest.test_escaped_ampersand_in_attribute_value_is_left_alonec                 C   s   d}d}|  || d S )N-<p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>#   <p>&lt;&lt;sacré bleu!&gt;&gt;</p>r  )r    rH  expectedr!   r!   r"   1test_entities_in_strings_converted_during_parsing  s   zJHTMLTreeBuilderSmokeTest.test_entities_in_strings_converted_during_parsingc                 C   s&   d}| j |dd}|jjdksJ d S )Ns   <p>Foo</p>zwindows-1252from_encodingu	   ‘Foo’r)  )r    quoter'   r!   r!   r"   )test_smart_quotes_converted_on_the_way_in  s
   zBHTMLTreeBuilderSmokeTest.test_smart_quotes_converted_on_the_way_inc                 C   s   |  d}|jjdksJ d S )Nz<a>&nbsp;&nbsp;</a>u     )r'   rs   r]   r   r!   r!   r"   0test_non_breaking_spaces_converted_on_the_way_in     
zIHTMLTreeBuilderSmokeTest.test_non_breaking_spaces_converted_on_the_way_inc                 C   s0   d}d d}| |}|j d|ksJ d S )NrN  rO  r   )r   r'   r   )r    rH  rP  r'   r!   r!   r"   &test_entities_converted_on_the_way_out  s   
z?HTMLTreeBuilderSmokeTest.test_entities_converted_on_the_way_outc                 C   sH   d}| d}| |}| d}|dd}| d}||ks"J d S )Nu   <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-type"/></head><body><p>Sacré bleu!</p></body></html>z
iso-8859-1r   z
ISO-8859-1)r   r'   r   )r    unicode_htmliso_latin_htmlr'   resultrP  r!   r!   r"   test_real_iso_8859_document  s   



z4HTMLTreeBuilderSmokeTest.test_real_iso_8859_documentc                 C   sL   d}| d}| |}|d|dksJ |d|dks$J d S )Nsk   <html><head></head><body><pre>Shift-JISŃR[fBOꂽ{̃t@CłB</pre></body></html>	shift-jisr   euc_jp)r9   r'   r   )r    shift_jis_htmlrY  r'   r!   r!   r"   test_real_shift_jis_document  s   

z5HTMLTreeBuilderSmokeTest.test_real_shift_jis_documentc                 C   sB   d}| j |dd}|jdv sJ |d|ddksJ d S )Ns   <html><head><title>Hebrew (ISO 8859-8) in Visual Directionality</title></head><body><h1>Hebrew (ISO 8859-8) in Visual Directionality</h1></body></html>	iso8859-8rR  )ra  z
iso-8859-8r   )r'   original_encodingr   r9   )r    hebrew_documentr'   r!   r!   r"   test_real_hebrew_document  s   z2HTMLTreeBuilderSmokeTest.test_real_hebrew_documentc                 C   s   d}d| }|  |}|dddi}|d }d|ksJ t|ts$J d|d	ks-J d
|d	v s6J d|dv s?J d S )NzE<meta content="text/html; charset=x-sjis" http-equiv="Content-type"/>j<html><head>
%s
<meta http-equiv="Content-language" content="ja"/></head><body>Shift-JIS markup goes here.r   z
http-equivzContent-typer8  ztext/html; charset=x-sjisztext/html; charset=utf8r   s   charset=utf8s   charset=shift-jisr]  )r'   r  r7   r   substitute_encodingr   )r    meta_tagr_  r'   parsed_metar8  r!   r!   r"   'test_meta_tag_reflects_current_encoding  s   
z@HTMLTreeBuilderSmokeTest.test_meta_tag_reflects_current_encodingc                 C   s   d}d| }|  |}|jddd}|d }d|ksJ t|ts#J d|dks,J d	|dv s5J d
|dv s>J d S )Nz'<meta id="encoding" charset="x-sjis" />re  r   encodingrb   charsetzx-sjisr   s   charset="utf8"s   charset="shift-jis"r]  )r'   r  r7   r   rf  r   )r    rg  r_  r'   rh  rk  r!   r!   r"   3test_html5_style_meta_tag_reflects_current_encoding  s   
zLHTMLTreeBuilderSmokeTest.test_html5_style_meta_tag_reflects_current_encodingc                 C   sT   dD ]%}|  |}tD ]}|dv rq||}d|v sJ |d|vs&J qqd S )N)sB   <meta charset="utf8"></head><meta id="encoding" charset="utf-8" />idnambcsoem	undefinedstring_escapezstring-escapes   meta charset=""asciir'   r
   r   r    r#   r'   rj  encodedr!   r!   r"   2test_python_specific_encodings_not_used_in_charset&  s   

zKHTMLTreeBuilderSmokeTest.test_python_specific_encodings_not_used_in_charsetc                 C   s*   |  d}d|jd< d|j ksJ d S )Nz<a>text</a>r  r   z<a foo="bar">text</a>)r'   rs   r9   )r    datar!   r!   r"   5test_tag_with_no_attributes_can_have_attributes_added@  s   

zNHTMLTreeBuilderSmokeTest.test_tag_with_no_attributes_can_have_attributes_addedc                 C   s    |  d}d|j ksJ d S )Nz0<body><div><p>text1</p></span>text2</div></body>z)<body><div><p>text1</p>text2</div></body>)r'   r6  r9   r   r!   r!   r"   $test_closing_tag_with_no_opening_tagE  s   
z=HTMLTreeBuilderSmokeTest.test_closing_tag_with_no_opening_tagc                 C      |  t}| | dS z3Test the worst case (currently) for linking issues.Nr'   r   rR   r   r!   r!   r"   test_worst_caseM     
z(HTMLTreeBuilderSmokeTest.test_worst_case)r   )Ire   rf   rg   __doc__r   r   r   r   r8   r   r   bytesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r"  r$  r&  r'  r*  r-  r/  r0  r1  r3  r4  r9  r;  r@  rA  rC  rE  rF  rI  rK  rL  rM  rQ  rU  rV  rX  r\  r`  rd  ri  rl  rw  ry  rz  r~  r!   r!   r!   r"   r   z  s    	

	


		
#r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+S ),XMLTreeBuilderSmokeTestc                 C   sF   |  d}t|d}t|}|jtksJ | | ks!J d S )Nr   r   )r'   r   r   r   r   r   r9   r   r!   r!   r"   r   U  s
   

z9XMLTreeBuilderSmokeTest.test_pickle_and_unpickle_identityc                 C   s   |  d}| dksJ d S )N<root/>s.   <?xml version="1.0" encoding="utf-8"?>
<root/>r   r   r!   r!   r"   test_docstring_generated^  rW  z0XMLTreeBuilderSmokeTest.test_docstring_generatedc                 C   $   d}|  |}||dksJ d S )Ns,   <?xml version="1.0" encoding="utf8"?>
<foo/>r   r   r~   r!   r!   r"   test_xml_declarationb     
z,XMLTreeBuilderSmokeTest.test_xml_declarationc                 C   sN   d}|  |}tD ]}|dv rq	||}d|v sJ |d|vs$J q	d S )Ns   <?xml version="1.0"?>
<foo/>rm  s   <?xml version="1.0"?>rs  rt  ru  r!   r!   r"   :test_python_specific_encodings_not_used_in_xml_declarationg  s   

zRXMLTreeBuilderSmokeTest.test_python_specific_encodings_not_used_in_xml_declarationc                 C   r  )Ns<   <?xml version="1.0" encoding="utf8"?>
<?PITarget PIContent?>r   r   r~   r!   r!   r"   r   ~  r  z3XMLTreeBuilderSmokeTest.test_processing_instructionc                 C   $   d}|  |}|d|ksJ dS )zGA real XHTML document should come out *exactly* the same as it went in.r   r   Nr   r~   r!   r!   r"   r     s   
z0XMLTreeBuilderSmokeTest.test_real_xhtml_documentc                 C   s"   d}|  |}|| ksJ d S )Ns  <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<parent xmlns="http://ns1/">
<child xmlns="http://ns2/" xmlns:ns3="http://ns3/">
<grandchild ns3:attr="value" xmlns="http://ns4/"/>
</child>
</parent>r   r    docr'   r!   r!   r"   test_nested_namespaces  s   
z.XMLTreeBuilderSmokeTest.test_nested_namespacesc                 C   s.   d}t |d}d|j_| }d|v sJ d S )Nz/
  <script type="text/javascript">
  </script>
zlxml-xmlzconsole.log("< < hey > > ");s   &lt; &lt; hey &gt; &gt;)r   r   r]   r   )r    r  r'   rv  r!   r!   r"   5test_formatter_processes_script_tag_for_xml_documents  s
   
zMXMLTreeBuilderSmokeTest.test_formatter_processes_script_tag_for_xml_documentsc                 C   r(  )Nu?   <?xml version="1.0" encoding="euc-jp"><root>Sacré bleu!</root>rB  r'   rootr]   r~   r!   r!   r"   rC       
z7XMLTreeBuilderSmokeTest.test_can_parse_unicode_documentc                 C   r(  )NuB   ﻿<?xml version="1.0" encoding="euc-jp"><root>Sacré bleu!</root>rB  r  r~   r!   r!   r"   1test_can_parse_unicode_document_begining_with_bom  r  zIXMLTreeBuilderSmokeTest.test_can_parse_unicode_document_begining_with_bomc                 C   $   d}|  |}t|j|ksJ d S )Nz<rss xmlns:dc="foo"><dc:creator>b</dc:creator><dc:date>2012-07-02T20:33:42Z</dc:date><dc:rights>c</dc:rights><image>d</image></rss>)r'   r8   rssr~   r!   r!   r"   test_popping_namespaced_tag  r  z3XMLTreeBuilderSmokeTest.test_popping_namespaced_tagc                 C   s    |  d}|ddksJ d S )Nr  latin1s/   <?xml version="1.0" encoding="latin1"?>
<root/>r   r   r!   r!   r"   (test_docstring_includes_correct_encoding  s   
z@XMLTreeBuilderSmokeTest.test_docstring_includes_correct_encodingc                 C   r  )z<A large XML document should come out the same as it went in.s4  <?xml version="1.0" encoding="utf-8"?>
<root>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</root>r   Nr   r~   r!   r!   r"   test_large_xml_document  s   
z/XMLTreeBuilderSmokeTest.test_large_xml_documentc                 C   s   |  dd |  d d S )Nr   r   z
<p>foo</p>r  r   r!   r!   r"   9test_tags_are_empty_element_if_and_only_if_they_are_empty  s   zQXMLTreeBuilderSmokeTest.test_tags_are_empty_element_if_and_only_if_they_are_emptyc                 C   s8   d}|  |}|j}d|d ksJ d|d ksJ d S )Nz<root xmlns:a="http://example.com/" xmlns:b="http://example.net/"><a:foo>This tag is in the a namespace</a:foo><b:foo>This tag is in the b namespace</b:foo></root>zhttp://example.com/zxmlns:azhttp://example.net/zxmlns:b)r'   r  )r    r#   r'   r  r!   r!   r"   test_namespaces_are_preserved  s
   
z5XMLTreeBuilderSmokeTest.test_namespaces_are_preservedc                 C   r  )NzN<p xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>20010504</dc:date></p>)r'   r8   r   r~   r!   r!   r"   test_closing_namespaced_tag  r  z3XMLTreeBuilderSmokeTest.test_closing_namespaced_tagc                 C   r  )Nzs<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><bar xsi:schemaLocation="http://www.example.com"/></foo>r'   r8   r   r~   r!   r!   r"   test_namespaced_attributes  r  z2XMLTreeBuilderSmokeTest.test_namespaced_attributesc                 C   r  )Nz<foo xml:lang="fr">bar</foo>r  r~   r!   r!   r"   (test_namespaced_attributes_xml_namespace  r  z@XMLTreeBuilderSmokeTest.test_namespaced_attributes_xml_namespacec                 C   sV   d}|  |}dt|dksJ dt|dksJ dt|dks(J 	 d S )Na  <?xml version="1.0" encoding="utf-8"?>
<Document xmlns="http://example.com/ns0"
    xmlns:ns1="http://example.com/ns1"
    xmlns:ns2="http://example.com/ns2">
    <ns1:tag>foo</ns1:tag>
    <ns1:tag>bar</ns1:tag>
    <ns2:tag key="value">baz</ns2:tag>
</Document>
   r_   r   zns1:tagrK   zns2:tag)r'   rP   r   r  r!   r!   r"   test_find_by_prefixed_name  s   
	z2XMLTreeBuilderSmokeTest.test_find_by_prefixed_namec                 C   s2   d}|  |}|j}t|}|j|jksJ d S )Nzf<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://example.com/ns0"/>)r'   documentr   prefix)r    xmlr'   r_   	duplicater!   r!   r"   !test_copy_tag_preserves_namespace  s
   

z9XMLTreeBuilderSmokeTest.test_copy_tag_preserves_namespacec                 C   r{  r|  r}  r   r!   r!   r"   r~    r  z'XMLTreeBuilderSmokeTest.test_worst_caseN)re   rf   rg   r   r  r  r  r   r   r  r  rC  r  r  r  r  r  r  r  r  r  r  r  r~  r!   r!   r!   r"   r  T  s,    	
r  c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )HTML5TreeBuilderSmokeTestz2Smoke test for a tree builder that supports HTML5.c                 C   s   d S r   r!   r   r!   r!   r"   r   	  s   z2HTML5TreeBuilderSmokeTest.test_real_xhtml_documentc                 C   r(  )Nz<a>r<  )r'   rs   	namespacer~   r!   r!   r"   test_html_tags_have_namespace  r  z7HTML5TreeBuilderSmokeTest.test_html_tags_have_namespacec                 C   6   d}|  |}d}||jjksJ ||jjksJ d S )Nz<svg><circle/></svg>r?  )r'   svgr  circler    r#   r'   r  r!   r!   r"   test_svg_tags_have_namespace  
   
z6HTML5TreeBuilderSmokeTest.test_svg_tags_have_namespacec                 C   r  )Nz<math><msqrt>5</msqrt></math>r>  )r'   mathr  msqrtr  r!   r!   r"   test_mathml_tags_have_namespace  r  z9HTML5TreeBuilderSmokeTest.test_mathml_tags_have_namespacec                 C   sN   d}|  |}t|jd tsJ |jd dksJ d|jd jjks%J d S )Nz3<?xml version="1.0" encoding="utf-8"?><html></html>r   z$?xml version="1.0" encoding="utf-8"?rz   )r'   r7   rQ   r   rD   r2   r~   r!   r!   r"   $test_xml_declaration_becomes_comment!  s
   
z>HTML5TreeBuilderSmokeTest.test_xml_declaration_becomes_commentN)	re   rf   rg   r  r   r  r  r  r  r!   r!   r!   r"   r    s    r  )9r  __license__r   	importlibr   r   r   bs4r   bs4.elementr   r   r   r   r   r	   r
   r   r   r   
bs4.filterr   bs4.builderr   bs4._typingr   r   bs4.builder._htmlparserr   typingr   r   r   r   r   	soupsiever   SOUP_SIEVE_PRESENTImportErrorutil	find_specHTML5LIB_PRESENT
lxml.etreelxmlLXML_PRESENTetreeLXML_VERSIONr   __annotations__r   r8   objectr   rk   r   r  r  r!   r!   r!   r"   <module>   sX   0% QE     _ 3