o
    ׹i                     @   s   d dl Z d dlZdZdZdZdZdZdZdZd	Z	G d
d de j
ZG dd de j
ZG dd de j
ZG dd de j
ZG dd de j
Zdd Zdd ZdS )    Na  <?xml version="1.0"?>
<root xmlns:meld="https://github.com/Supervisor/supervisor">
  <list meld:id="list">
    <item meld:id="item">
       <name meld:id="name">Name</name>
       <description meld:id="description">Description</description>
    </item>
  </list>
</root>z<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:meld="https://github.com/Supervisor/supervisor">
   <body meld:id="body">Hello!</body>
</html>z<html>
  <body>
    <area/><base/><basefont/><br/><col/><frame/><hr/><img/><input/><isindex/>
    <link/><meta/><param/>
  </body>
</html>a?  <html>
  <body>
  <tag selected="true"/>
  <tag checked="true"/>
  <tag compact="true"/>
  <tag declare="true"/>
  <tag defer="true"/>
  <tag disabled="true"/>
  <tag ismap="true"/>
  <tag multiple="true"/>
  <tag nohref="true"/>
  <tag noresize="true"/>
  <tag noshade="true"/>
  <tag nowrap="true"/>
  </body>
</html>z^
<html>
<head></head>
<body>
  <!-- test entity references -->
  <p>&nbsp;</p>
</body>
</html>a:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:meld="https://github.com/Supervisor/supervisor"
      xmlns:bar="http://foo/bar">
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
    <title meld:id="title">This will be escaped in html output: &amp;</title>
    <script>this won't be escaped in html output: &amp;</script>
    <script type="text/javascript">
            //<![CDATA[
              // this won't be escaped in html output
              function match(a,b) {
                 if (a < b && a > 0) then { return 1 }
                }
             //]]>
    </script>
    <style>this won't be escaped in html output: &amp;</style>
  </head>
  <!-- a comment -->
  <body>
    <div bar:baz="slab"/>
    <div meld:id="content_well">
      <form meld:id="form1" action="." method="POST">
      <img src="foo.gif"/>
      <table border="0" meld:id="table1">
        <tbody meld:id="tbody">
          <tr meld:id="tr" class="foo">
            <td meld:id="td1">Name</td>
            <td meld:id="td2">Description</td>
          </tr>
        </tbody>
      </table>
      <input type="submit" name="submit" value=" Next "/>
      </form>
    </div>
  </body>
</html>a  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <title meld:id="title">test doc</title>
</head>
<body>
 <!-- comment! -->
 Oh yeah...<br>
<br>
<table style="text-align: left; width: 100px;" border="1" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td>Yup</td>
      <td>More </td>
      <td>Stuff</td>
      <td>Oh Yeah</td>
    </tr>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>
<br>
<a href=".">And an image...</a><br>
<br>
<img style="width: 2048px; height: 1536px;" alt="dumb" src="IMG_0102.jpg">
</body>
</html>aO  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Emergency Contacts</title>
</head>
<body>
   <div class="header">Emergency Contacts</div>

   <form action="." method="POST">
    <table>

      <tbody meld:id="tbody">

	<tr>
	  <th>Title</th>
	  <td>
	    <input type="text" name="honorific" size="6" value=""
		   meld:id="honorific"/>
	  </td>
	</tr>

	<tr>
	  <th>First Name</th>
	  <td>
	    <input type="text" name="firstname" size="20" value=""
		   meld:id="firstname"/>
	  </td>
	</tr>

	<tr>
	  <th>Middle Name</th>
	  <td>
	    <input type="text" name="middlename" size="15" value=""
		   meld:id="middlename"/>
	  </td>
	</tr>

	<tr>
	  <th>Last Name</th>
	  <td>
	    <input type="text" name="lastname" size="20" value=""
		   meld:id="lastname"/>
	  </td>
	</tr>

	<tr>

	  <th>Suffix</th>
	  <td style="width: 554px;">
          <select name="suffix" meld:id="suffix">
	      <option value="Jr.">Jr.</option>
	      <option value="Sr.">Sr.</option>
	      <option value="III">III</option>
	    </select>
          </td>

        </tr>

	<tr>
	  <th>Address 1</th>
	  <td>
	    <input type="text" name="address1" size="30" value=""
		   meld:id="address1"/>
	  </td>
	</tr>

	<tr>
	  <th>Address 2</th>
	  <td>
	    <input type="text" name="address2" size="30" value=""
		   meld:id="address2"/>
	  </td>
	</tr>

	<tr>
	  <th>City</th>
	  <td>
	    <input type="text" name="city" size="20" value=""
		   meld:id="city"/>
	  </td>
	</tr>

	<tr>
	  <th>State</th>
	  <td>
	    <input type="text" name="state" size="5" value=""
		   meld:id="state"/>
	  </td>
	</tr>

	<tr>
	  <th>ZIP</th>
	  <td>
	    <input type="text" name="zip" size="8" value=""
		   meld:id="zip"/>
	  </td>
	</tr>

	<tr>
	  <th>Home Phone</th>
	  <td>
	    <input type="text" name="homephone" size="12" value=""
		   meld:id="homephone"/>
	  </td>
	</tr>

	<tr>
	  <th>Cell/Mobile Phone</th>
	  <td>
	    <input type="text" name="cellphone" size="12" value=""
		   meld:id="cellphone"/>
	  </td>
	</tr>

	<tr>
	  <th>Email Address</th>
	  <td>
	    <input type="text" name="email" size="20" value=""
		   meld:id="email"/>
	  </td>
	</tr>

	<tr>
	  <th>Over 18? (Checkbox Boolean)</th>
	  <td>
            <input type="checkbox" name="over18" meld:id="over18"
                   value="true" checked="true"/>
	  </td>
	</tr>

	<tr>

	  <th>Mail OK? (Checkbox Ternary)</th>
          <td style="width: 554px;" meld:id="mailok:inputgroup">
            <input type="hidden" name="mailok:default"
                   value="false"/>
            <input type="checkbox" name="mailok"
                   value="true" checked/>
            <input type="checkbox" name="mailok"
                   value="false"/>
          </td>

        </tr>

	<tr>

	  <th>Favorite Color (Radio)</th>
          <td style="width: 554px;" meld:id="favorite_color:inputgroup">
            Red   <input type="radio" name="favorite_color"
                         value="Red"/>
            Green <input type="radio" name="favorite_color"
                         value="Green"/>
            Blue  <input type="radio" name="favorite_color"
                         value="Blue"/>
          </td>

        </tr>

	<tr>
	  <th></th>
	  <td>
	    <input type="submit" value=" Update " name="edit:method" />
	  </td>
	</tr>

      </tbody>
    </table>
    </form>

<p><a href="..">Return to list</a></p>
</body>
</html>
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S ) MeldAPITestsc                 C      ddl m} ||S Nr   parse_xmlstringsupervisor.templatingr   )selfstringr    r   ]/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/supervisor/tests/test_templating.py_makeElement7     zMeldAPITests._makeElementc                 C   r   Nr   parse_htmlstringr   r   )r	   r
   r   r   r   r   _makeElementFromHTML;  r   z!MeldAPITests._makeElementFromHTMLc                 C   s>   |  t}|d}| |jd |d}| |jd d S )NitemnameName)r   _SIMPLE_XMLfindmeldassertEqualtagtext)r	   rootr   r   r   r   r   test_findmeld?  s
   


zMeldAPITests.test_findmeldc                 C   sP   |  t}|d}| |jd |dd}| |d | |dd  d S )Nr   unknownfoo)r   r   r   r   r   )r	   r   r   r   r   r   r   test_findmeld_defaultF  s   

z"MeldAPITests.test_findmeld_defaultc                 C   s   |  t}|d}| |jd ddddddg}||D ]\}}|d |d_|d |d_q | |d	 jd | |d
 jd d S )Nr   Jeff Buckleyetherealr   descriptionSlipknotheavyr   r$   r      r   r   r   r   r   repeatr   )r	   r   r   dataelementdr   r   r   test_repeat_nochildN  s   

z MeldAPITests.test_repeat_nochildc                 C   s   |  t}|d}| |jd ddddddg}||dD ]\}}|d |d_|d	 |d	_q!| |d
 d
 jd | |d
 d jd | |d d
 jd | |d d jd d S )Nlistr!   r"   r#   r%   r&   r   r   r$   r   r'   r(   )r	   r   r.   r*   r+   r,   r   r   r   test_repeat_childZ  s   

zMeldAPITests.test_repeat_childc                 C   sL   |  t}|ddd  |d}| |jd |d}| |jd d S )Nr   bar)r$   r   r   r$   )r   r   r   r   r   )r	   r   r   descr   r   r   test_modh  s   


zMeldAPITests.test_modc                 C   sJ   |  t}|jdi ddd}|d}| |jd | |dg d S )Nr   a)r$   jammyjamr$   r4   r   )r   r   	fillmeldsr   r   r   )r	   r   unfilledr1   r   r   r   test_fillmeldsp  s
   

zMeldAPITests.test_fillmeldsc           	      C   s  i ddddddddd	d
dddddddddddddddddddddd i dddd!dd"dd#d	d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/i dd!dd"dd#d	d$dd%dd&dd'dd(dd)dd*dd+dd0dd-dd.dd1d2d3g}|  t}| }|jd9i |d4 }| |g  | |djd5 d | |djd5 d |d}| |jd5 d |d}| |d3 jd6 d6 | |djd7 d7 |d}| |d3 jd7 d7 |d}| |d3 jd7 d7 | }|jd9i |d3 }| |dg | |djd7d  |d}| |d8 jd7 d7 | |d3 jd7d  | }|jd9i |d8 }| t|d2dg | |dj	d  |d}| |d8 jd7 d7 | |d3 jd7d  d S ):N	honorificzMr.	firstnameChris
middlenamePhillipslastname	McDonoughaddress1z802 Caroline St.address2zApt. 2BcityFredericksburgstateVAzip22401	homephonez555-1212	cellphonez555-1313emailzuser@example.comsuffixzSr.over18Tzmailok:inputgrouptruezfavorite_color:inputgroupGreenFred Rogersz1 Imaginary LanezApt. 3AzNever Never LandLA00001z555-1111z555-4444zfred@neighborhood.comzJr.FfalseYellowIVBluenottherer'   r   valueselectedchecked   r   )
r   _FILLMELDFORM_HTMLclonefillmeldhtmlformr   r   attribgetsortedr   )	r	   r*   r   r]   r6   r;   rJ   mailokfavoritecolorr   r   r   test_fillmeldhtmlformw  s   






z"MeldAPITests.test_fillmeldhtmlformc                 C   sX   ddl m} | t}|d}|d |d }| |j| | t|	 d d S )Nr   Replacer.   this is a textual replacementr'   )
r   rf   r   r   r   replacer   r   lengetchildren)r	   rf   r   LRr   r   r   !test_replace_removes_all_elements  s   


z.MeldAPITests.test_replace_removes_all_elementsc                 C   s  ddl m} | t}|d}|d | t| d |d }| |j	d | t| d |d }| |j	d | t| d |d }| |j	d	 | t| d |d }| |j	| | |j
d | t| d | |jd
 d S Nr   re   r$   rg   r'   r.   r   r[   r   F)r   rf   r   r   r   rh   r   ri   rj   r   r   	structure)r	   rf   r   Drk   INr   r   r   'test_replace_replaces_the_right_element  s&   


z4MeldAPITests.test_replace_replaces_the_right_elementc                 C   s*  ddl m} | t}|d}|d | t| d |d }| |j	d | t| d |d }| |j	d | t| d |d }| |j	d	 | t| d |d }| |j	d | |j
d  | t| d |d }| |j	| | |j
d | |jd
 d S rn   )r   rf   r   r   r   contentr   ri   rj   r   r   ro   )r	   rf   r   rp   rk   rq   rr   Tr   r   r   test_content  s,   


zMeldAPITests.test_contentc                 C   s\   ddl m} | t}|d}|jddddd | |jd	dd
ddddddd|di d S )Nr   _MELD_IDform1r0   12#)r   bazgactionr   r}   r~   methodPOSTr   )r   rx   r   _COMPLEX_XHTMLr   
attributesr   r_   )r	   rx   r   rp   r   r   r   test_attributes  s   


zMeldAPITests.test_attributesc                 C   s|   ddl m} ddlm} | t}|d}|j|ddd|dddd	 | |j	d
|dddddd|ddd|di d S )Nr   rw   	as_stringry   r0   latin1encodingr|   )r   r   r   r   r   r   )
r   rx   supervisor.compatr   r   r   r   r   r   r_   )r	   rx   r   r   rp   r   r   r   test_attributes_unicode  s   



z$MeldAPITests.test_attributes_unicodec                 C   s    |  d}| jt|jdd d S )N<root></root>r'   )r   )r   assertRaises
ValueErrorr   )r	   r   r   r   r   $test_attributes_nonstringtype_raises  s   
z1MeldAPITests.test_attributes_nonstringtype_raisesN)__name__
__module____qualname__r   r   r   r    r-   r/   r2   r7   rd   rm   rs   rv   r   r   r   r   r   r   r   r   6  s     7	
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+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=S )>MeldElementInterfaceTestsc                 C   s   ddl m} |S )Nr   )_MeldElementInterface)r   r   )r	   r   r   r   r   _getTargetClass  s   z)MeldElementInterfaceTests._getTargetClassc                 O   s   |   }||i |S N)r   )r	   argkwklassr   r   r   _makeOne  s   z"MeldElementInterfaceTests._makeOnec                 C   s  |  di }ddlm} |  d|di}|  d|di}|  d|di}|  d|di}|| || || || dd	d
ddd
g}||D ]\}}	|	d |d_|	d |d_qO| t|d |d }
| t|
d |
d }| t|d |d }|d }| |jd | |jd	 |d }| t|d |d }| t|d |d }|d }| |jd | |jd d S )Nr   r   rw   r   recordr   r$   r!   r"   r#   r%   r&   r[   r'   )	r   r   rx   appendr)   r   r   r   ri   )r	   r   rx   r   r   r   r$   r*   r+   r,   item1record1name1desc1item2record2name2desc2r   r   r   test_repeat  sB   



z%MeldElementInterfaceTests.test_repeatc                 C   s~   |  dddi}|d | t|jd |jd }| |j| | |jd | |jd ddlm	} | |j
| d S )	Ndividthedivhellor'   r   Fre   r   rt   r   ri   	_childrenparentr   ro   r   rf   r   r	   elreplacenoderf   r   r   r   test_content_simple_nostructure.  s   

z9MeldElementInterfaceTests.test_content_simple_nostructurec                 C   s   |  dddi}|jddd | t|jd |jd }| |j| | |jd | |jd dd	lm	} | |j
| d S )
Nr   r   r   r   Tro   r'   r   re   r   r   r   r   r   test_content_simple_structure9  s   
z7MeldElementInterfaceTests.test_content_simple_structurec                 C   s2   ddl m} | d|di}| |d| d S )Nr   rw   r   r   )r   rx   r   r   r   )r	   rx   r   r   r   r   test_findmeld_simpleD  s   z.MeldElementInterfaceTests.test_findmeld_simplec                 C   sL   ddl m} | d|di}| d|di}|| | |d| d S )Nr   rw   r   r   spanthespanr   rx   r   r   r   r   )r	   rx   r   r   r   r   r   !test_findmeld_simple_oneleveldownI  s
   
z;MeldElementInterfaceTests.test_findmeld_simple_oneleveldownc                 C   sf   ddl m} | d|di}| d|di}| d|di}|| || | |d| d S )	Nr   rw   r   r   r   r   r3   thear   )r	   rx   r   r   r3   r   r   r   "test_findmeld_simple_twolevelsdownP  s   

z<MeldElementInterfaceTests.test_findmeld_simple_twolevelsdownc                 C   sB   |  dddi}| |jd  | |jd | |jddi d S )Nr   r   r   )r   r   r   r   r_   )r	   ifacer   r   r   	test_ctorY  s   z#MeldElementInterfaceTests.test_ctorc                 C   s<   |  dddi}| }| t|d | |d | d S )Nr   r   r   r'   r   )r   getiteratorr   ri   )r	   r   iteratorr   r   r   test_getiterator_simple_  s   z1MeldElementInterfaceTests.test_getiterator_simplec                 C   s   |  dddi}|  di }|  dddi}|  dddi}d|_d	|_|| || || | }| t|d
 | |d | | |d | | |d | | |d | d S )Nr   r   r   r   r{   span33abc     r   r'   r[      r   r   tailr   r   r   ri   r	   r   r   span2r   itr   r   r   test_getiteratore  s   


z*MeldElementInterfaceTests.test_getiteratorc                 C   s   |  dddi}|  di }|  dddi}|  dddi}d|_d	|_|| || || |jdd
}| t|d | |d | | |d | | |d | | |d | d S )Nr   r   r   r   r{   r   r   r   r   )r   r   r   r'   r[   r   r   r   r   r   r   test_getiterator_tag_ignoredw  s   


z6MeldElementInterfaceTests.test_getiterator_tag_ignoredc                 C   sJ   |  dddi}|  di }|| | |d jd | |j| d S )Nr   r   r   r   r   )r   r   r   r   r   r	   r   r   r   r   r   test_append  s
   
z%MeldElementInterfaceTests.test_appendc                 C   s|   |  dddi}|  di }|  dddi}|| ||d< | |d jd | |d jddi | |d j| d S )Nr   r   r   r   r{   r   )r   r   r   r   r_   r   r	   r   r   r   r   r   r   test__setitem__  s   
z)MeldElementInterfaceTests.test__setitem__c                 C   s   |  dddi}|  di }|  dddi}|| |d| | |d jd | |d jddi | |d j| | |d jd | |d ji  | |d j| d S )Nr   r   r   r   r{   r   r'   )r   r   insertr   r   r_   r   r   r   r   r   test_insert  s   
z%MeldElementInterfaceTests.test_insertc                 C   s>   |  dddi}d|_d|_|  di }|| |  d S )Nr   r   r   r   z   r   )r   r   r   r   r]   r   r   r   r   test_clone_simple  s   
z+MeldElementInterfaceTests.test_clone_simplec                 C   s"  |  dddi}|  di }|  dddi}|  dddi}d|_d	|_|| || || | }| |j|j | |j|j | |d
 j|d
 j | |d
 j|d
 j | |d
 d
 j|d
 d
 j | |d
 d
 j|d
 d
 j | |d
 d
 d
 j|d
 d
 d
 j | |d
 d
 d
 j|d
 d
 d
 j | |d
 d
 d
 j|d
 d
 d
 j | |d
 d
 d
 j|d
 d
 d
 j | t	|t	| | t	|d
 t	|d
  | t	|d
 d
 t	|d
 d
  | t	|d
 d
 d
 t	|d
 d
 d
  d S )Nr   r   r   r   r{   r   r   r   r   r   )
r   r   r   r   r]   r   r   r_   assertNotEqualr   )r	   r   r   r   r   div2r   r   r   
test_clone  s0   


  (((($0z$MeldElementInterfaceTests.test_clonec                 C   s4   |  di }| |jd  |  | |jd  d S )Nr   )r   r   r   deparent)r	   r   r   r   r   test_deparent_noparent  s   z0MeldElementInterfaceTests.test_deparent_noparentc                 C   s   |  di }| |jd  |  di }|| | |jd  | |j| | |d | |  | |jd  | t|jd d S )Nr   childr   )r   r   r   r   r   r   
IndexError__getitem__)r	   r   r   r   r   r   test_deparent_withparent  s   
z2MeldElementInterfaceTests.test_deparent_withparentc                 C   s   |  di }|  di }|  di }|  di }|||f}||dd< | |j| | |j| | |j| | |jt| d S )Nr   child1child2child3r   r[   )r   r   r   r   r.   r	   r   r   r   r   childrenr   r   r   test_setslice  s   
z'MeldElementInterfaceTests.test_setslicec                 C   s   |  di }|  di }|  di }|  di }|||f}||dd< |dd= | |jd  | |jd  | |j| | t|jd d S )Nr   r   r   r   r   r[   r'   )r   r   r   ri   r   r   r   r   r   test_delslice  s   

z'MeldElementInterfaceTests.test_delslicec                 C   sP   |  di }|  di }|| || | |jd  | t|jd d S )Nr   r   r   )r   r   remover   r   ri   r   )r	   r   r   r   r   r   test_remove  s   

z%MeldElementInterfaceTests.test_removec                 C   s  ddl m} | d|di}| d|di}| d|di}| d|di}| d|d	i}| d|d
i}| d|di}| di }	| d|di}
|| || || ||	 |	| || || ||
 dd }| || dg | || ddg | || g d | || g d | ||	 g d | || g d | || g d | || g d | ||
 ddg d S )Nr   rw   r   div1r   span1r   r   span4span5span6r   c                 S   s   dd | D S )Nc                 S      g | ]}|  qS r   meldid.0xr   r   r   
<listcomp>      zGMeldElementInterfaceTests.test_lineage.<locals>.ids.<locals>.<listcomp>r   )rk   r   r   r   ids  s   z3MeldElementInterfaceTests.test_lineage.<locals>.ids)r   r   r   )r   r   r   r   )Nr   r   r   r   )r   Nr   r   r   r   )r   r   Nr   r   r   r   )r   r   r   Nr   r   r   r   )r   rx   r   r   r   lineage)r	   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   test_lineage  s8   







z&MeldElementInterfaceTests.test_lineagec                 C   s   ddl m} | dddi}| di }| dddi}| dddi}|| || || | }| ||d	d
d d S )Nr   as_bytesr   r   r   r   r{   r   zM<div id="div1"><span><span id="2"></span></span><div2 id="div2"></div2></div>r   r   )r   r   r   r   	shortreprr   )r	   r   r   r   r   r   rr   r   r   test_shortrepr(  s   


z(MeldElementInterfaceTests.test_shortreprc                 C   s@   ddl m} ddlm} |t}| }| ||ddd d S )Nr   r   r   z<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
     [...]
</head>
  <!--  a comment  -->
   [...]
</html>r   r   )r   r   r   r   r   r   r   )r	   r   r   r   r   r   r   r   test_shortrepr26  s   z)MeldElementInterfaceTests.test_shortrepr2c                    s  ddl m} ddl m  |t}| }| d di}|| |d}|  |d}|  || |	|}|d } fd	d
|d D }	 fdd
|d D }
 fdd
|d D }|	
  |

  |
  | |	dg | |
g d | |dg |d } fdd
|d D }	 fdd
|d D }
 fdd
|d D }|	
  |

  |
  | |	dg | |
dg | |dg d S )Nr   r   rw   r   newdivtrtitle	unreducedc                       g | ]}|j   qS r   r_   r   rw   r   r   r   U      z<MeldElementInterfaceTests.test_diffmeld1.<locals>.<listcomp>addedc                    r   r   r   r   rw   r   r   r   V  r  removedc                    r   r   r   r   rw   r   r   r   W  r  moved)td1td2r   reducedc                    r   r   r   r   rw   r   r   r   a  r  c                    r   r   r   r   rw   r   r   r   b  r  c                    r   r   r   r   rw   r   r   r   c  r  )r   r   rx   r   r]   r   r   r   r   diffmeldsortr   )r	   r   r   r]   r   r   r   diffchanges	addedtagsremovedtags	movedtagsr   rw   r   test_diffmeld1E  s@   




z(MeldElementInterfaceTests.test_diffmeld1c           	      C   s  d}d}ddl m} ||}||}||}dd |d d D }d	g}| || d
d |d d D }g }| || dd |d d D }g }| || dd |d d D }d	g}| || dd |d d D }g }| || dd |d d D }g }| || d S )Nzi
        <root>
          <a meld:id="a">
             <b meld:id="b"></b>
          </a>
        </root>zd
        <root>
          <a meld:id="a"></a>
          <b meld:id="b"></b>
        </root>
        r   r   c                 S   r   r   r   r   r   r   r   r   ~  r   z<MeldElementInterfaceTests.test_diffmeld2.<locals>.<listcomp>r   r  bc                 S   r   r   r   r   r   r   r   r     r   r  c                 S   r   r   r   r   r   r   r   r     r   r  c                 S   r   r   r   r   r   r   r   r     r   r  c                 S   r   r   r   r   r   r   r   r     r   c                 S   r   r   r   r   r   r   r   r     r   r   r   r  r   	r	   sourcetargetr   source_roottarget_rootr  actualexpectedr   r   r   test_diffmeld2k  s0   
z(MeldElementInterfaceTests.test_diffmeld2c           	      C   s(  d}d}ddl m} ||}||}||}dd |d d D }d	d
g}| || dd |d d D }ddg}| || dd |d d D }ddg}| || dd |d d D }d	g}| || dd |d d D }dg}| || dd |d d D }dg}| || d S )Nz
        <root>
          <a meld:id="a">
             <b meld:id="b">
               <c meld:id="c"></c>
             </b>
          </a>
          <z meld:id="z">
            <y meld:id="y"></y>
          </z>
        </root>
        z
        <root>
          <b meld:id="b">
            <c meld:id="c"></c>
          </b>
          <a meld:id="a"></a>
          <d meld:id="d">
             <e meld:id="e"></e>
          </d>
        </root>
        r   r   c                 S   r   r   r   r   r   r   r   r     r   z<MeldElementInterfaceTests.test_diffmeld3.<locals>.<listcomp>r   r  r  cc                 S   r   r   r   r   r   r   r   r     r   r  r,   ec                 S   r   r   r   r   r   r   r   r     r   r  zyc                 S   r   r   r   r   r   r   r   r     r   r  c                 S   r   r   r   r   r   r   r   r     r   c                 S   r   r   r   r   r   r   r   r     r   r  r  r   r   r   test_diffmeld3  s0   
z(MeldElementInterfaceTests.test_diffmeld3c           	      C   s*  d}d}ddl m} ||}||}||}dd |d d D }d	d
g}| || dd |d d D }ddg}| || dd |d d D }g d}| || dd |d d D }d	g}| || dd |d d D }dg}| || dd |d d D }ddg}| || d S )N!  
        <root>
          <a meld:id="a">
             <b meld:id="b">
               <c meld:id="c">
                 <d meld:id="d"></d>
               </c>
             </b>
          </a>
          <z meld:id="z">
            <y meld:id="y"></y>
          </z>
        </root>
        a  
        <root>
          <p>
            <a meld:id="a">
               <b meld:id="b"></b>
            </a>
          </p>
          <p>
            <m meld:id="m">
              <n meld:id="n"></n>
            </m>
          </p>
        </root>
        r   r   c                 S   r   r   r   r   r   r   r   r     r   z<MeldElementInterfaceTests.test_diffmeld4.<locals>.<listcomp>r   r  r3   r  c                 S   r   r   r   r   r   r   r   r     r   r  mnc                 S   r   r   r   r   r   r   r   r     r   r  )r  r,   r  r  c                 S   r   r   r   r   r   r   r   r     r   r  c                 S   r   r   r   r   r   r   r   r     r   c                 S   r   r   r   r   r   r   r   r     r   r  r  r  r  r   r   r   test_diffmeld4  s0   
z(MeldElementInterfaceTests.test_diffmeld4c           	      C   s  d}d}ddl m} ||}||}||}dd |d d D }g d	}| || d
d |d d D }g }| || dd |d d D }g }| || dd |d d D }ddg}| || dd |d d D }g }| || dd |d d D }g }| || d S )Nr  a}  
        <root>
          <p>
            <a meld:id="a">
               <b meld:id="b">
                 <p>
                   <c meld:id="c">
                     <d meld:id="d"></d>
                   </c>
                 </p>
               </b>
            </a>
          </p>
          <z meld:id="z">
            <y meld:id="y"></y>
          </z>
        </root>
        r   r   c                 S   r   r   r   r   r   r   r   r   2  r   z<MeldElementInterfaceTests.test_diffmeld5.<locals>.<listcomp>r   r  )r3   r  r  r,   c                 S   r   r   r   r   r   r   r   r   6  r   r  c                 S   r   r   r   r   r   r   r   r   :  r   r  c                 S   r   r   r   r   r   r   r   r   ?  r   r  r3   r  c                 S   r   r   r   r   r   r   r   r   C  r   c                 S   r   r   r   r   r   r   r   r   G  r   r  r  r   r   r   test_diffmeld5  s0   
z(MeldElementInterfaceTests.test_diffmeld5N)!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"  r#  r   r   r   r   r     s>    '	
*&-7<r   c                   @   sL   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S )ParserTestsc                 G      ddl m} || }|S r   r   )r	   argsr   r   r   r   r   _parseN     zParserTests._parsec                 G   r%  r   r   )r	   r&  r   r   r   r   r   _parse_htmlS  r(  zParserTests._parse_htmlc                 C   s  ddl m} | t}| |jd | |jd  |d }| |jd | |j| | |j| d |d }| |jd | |j| | |j| d |d }|d }| |jd | |j| | |j| d | |jd | |j| | |j| d d S )	Nr   rw   r   r.   r   r'   r   r$   )r   rx   r'  r   r   r   r   r_   )r	   rx   r   l1str   r   r$   r   r   r   test_parse_simple_xmlX  s(   
z!ParserTests.test_parse_simple_xmlc                 C   s   d}ddl m} | t}| |j|d  | |ji  | |jd  |d }| |j|d  | |j| d | |j| d S )N {http://www.w3.org/1999/xhtml}%sr   rw   htmlbody)r   rx   r'  _SIMPLE_XHTMLr   r   r_   r   )r	   xhtml_nsrx   r   r.  r   r   r   test_parse_simple_xhtmln  s   
z#ParserTests.test_parse_simple_xhtmlc                 C   sl  d}ddl m} | t}| |j|d  | |ji  | |jd  |d }| |j|d  | |ji  | |j| |d }| |j|d  | |jd d | |j| |d	 }| |j|d
  | |j| d
 | |j| |d }| |j|d  | |ji  | |j| |d }| |j|d  | |jddi | |j| |d	 }	| |	j|d  | |	j| d | |	j| |	d }
| |
j|d  | |
j| d | |
jd d | |
jd d | |
j|	 |
d }| |j|d  | |j|
 |
d	 }| |j|d  | |j| d | |jd d | |j|
 |d }| |j|d  | |j| d | |j| |d }| |j|d  | |j| d | |jd d | |j| |d }| |j|d   | |j| d! | |j| |d	 }| |j|d   | |j| d" | |j| d S )#Nr,  r   rw   r-  headmetart   text/html; charset=ISO-8859-1r'   r   r[   r.  r   z{http://foo/bar}bazslabcontent_wellformry   r   .r   r   imgtabletable1border0tbodyr   classr   tdr  r  )r   rx   r'  r   r   r   r_   r   )r	   r0  rx   r   r2  r3  r   r.  r   r   r7  r9  r:  r>  r   r  r  r   r   r   test_parse_complex_xhtml{  s~   
z$ParserTests.test_parse_complex_xhtmlc                 C   s  ddl m} ddl m} | t}| |jd | |ji  | |jd  |d }| |jd | |ji  | |j| |d }| |jd | |jd d |d	 }| |jd
 | |j| d
 | |j| |d	 }| |jd | |ji  | |j| |d }| |j| |d }	| |	jd | |	jddddd | |	j| |d }
| |
jd |d }| |jd d S )Nr   rw   )Commentr-  r2  r3  rt   r4  r'   r   r.  r   r:  ztext-align: left; width: 100px;rz   r{   )styler<  cellpaddingcellspacing   r3      r9  )	r   rx   rB  r)  	_NVU_HTMLr   r   r_   r   )r	   rx   rB  r   r2  r3  r   r.  commentr:  hrefr9  r   r   r   test_nvu_html  sL   
zParserTests.test_nvu_htmlc                 C       d}d| }|  t| j| d S Nz(https://github.com/Supervisor/supervisorzF<html xmlns:meld="%s" meld:id="repeat"><body meld:id="repeat"/></html>)r   r   r'  r	   meld_nsrepeatedr   r   r   !test_dupe_meldids_fails_parse_xml  
   z-ParserTests.test_dupe_meldids_fails_parse_xmlc                 C   rL  rM  )r   r   r)  rN  r   r   r   "test_dupe_meldids_fails_parse_html  rR  z.ParserTests.test_dupe_meldids_fails_parse_htmlN)r   r   r   r'  r)  r+  r1  rA  rK  rQ  rS  r   r   r   r   r$  M  s    J*r$  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )	UtilTestsc                 C   ,   ddl m} d}||}d}| || d S )Nr   insert_doctyper   z<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><root></root>r   rW  r   r	   rW  origr  r  r   r   r   test_insert_xhtml_doctype  
   z#UtilTests.test_insert_xhtml_doctypec                 C   rU  )Nr   rV  5<?xml version="1.0" encoding="latin-1"?><root></root>z<?xml version="1.0" encoding="latin-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><root></root>rX  rY  r   r   r   !test_insert_doctype_after_xmldecl  r\  z+UtilTests.test_insert_doctype_after_xmldeclc                 C   rU  )Nr   )insert_meld_ns_declr]  zk<?xml version="1.0" encoding="latin-1"?><root xmlns:meld="https://github.com/Supervisor/supervisor"></root>)r   r_  r   )r	   r_  rZ  r  r  r   r   r   test_insert_meld_ns_decl  r\  z"UtilTests.test_insert_meld_ns_declc                 C   rU  )Nr   prefeedzD<?xml version="1.0" encoding="latin-1"?><root xmlns:meld="#"></root>z<?xml version="1.0" encoding="latin-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><root xmlns:meld="#"></root>r   rb  r   )r	   rb  rZ  r  r  r   r   r   'test_prefeed_preserves_existing_meld_ns  r\  z1UtilTests.test_prefeed_preserves_existing_meld_nsc                 C   s(   ddl m} d}||}| || d S )Nr   ra  z<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><root xmlns:meld="https://github.com/Supervisor/supervisor"></root>rc  )r	   rb  rZ  r  r   r   r   'test_prefeed_preserves_existing_doctype  s   z1UtilTests.test_prefeed_preserves_existing_doctypeN)r   r   r   r[  r^  r`  rd  re  r   r   r   r   rT    s    rT  c                   @   sD  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+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)dOS )PWriterTestsc                 C      ddl m} ||}|S r   r   )r	   xmlr   r   r   r   r   r'     r(  zWriterTests._parsec                 C   rg  r   r   )r	   rh  r   r   r   r   r   r)  %  r(  zWriterTests._parse_htmlc                 K   sR   zddl m} W n
   ddlm} Y | }||fi | |d | }|S )Nr   )BytesIO)StringIO)iori  rj  seekread)r	   fnr   ri  outr  r   r   r   _write*  s   
zWriterTests._writec                 K      | j |jfi |S r   )rp  	write_xmlr	   noder   r   r   r   
_write_xml5     zWriterTests._write_xmlc                 K   rq  r   )rp  
write_htmlrs  r   r   r   _write_html8  rv  zWriterTests._write_htmlc                 K   rq  r   )rp  write_xhtmlrs  r   r   r   _write_xhtml;  rv  zWriterTests._write_xhtmlc                 C   <   ddl m} t||dd}t||dd}| || d S Nr   r   r   r   r   r   normalize_xmlr   r	   r3   r  r   r   r   r   assertNormalizedXMLEqual>     z$WriterTests.assertNormalizedXMLEqualc                 C   r{  r|  r}  r  r   r   r   assertNormalizedHTMLEqualD  r  z%WriterTests.assertNormalizedHTMLEqualc                 C   s   |  t}| |}d}| || |ddD ]\}}t|d |d_t|d |d_q| |}d}| || d S )	Nz<?xml version="1.0"?><root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r   ))r'   r[   r   r   r'   r$   z<?xml version="1.0"?><root>
  <list>
    <item>
       <name>1</name>
       <description>2</description>
    </item>
  </list>
</root>)r'  r   ru  r  r   r)   strr   )r	   r   r  r  r   r*   r   r   r   test_write_simple_xmlJ  s   


z!WriterTests.test_write_simple_xmlc                 C   (   |  t}| |}d}| || d S )N<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><body>Hello!</body></html>r'  r/  rz  r  r	   r   r  r  r   r   r   test_write_simple_xhtmle  s   

z#WriterTests.test_write_simple_xhtmlc                 C   r  )Nz<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <body>Hello!</body>
</html>)r'  r/  rx  r  r  r   r   r   test_write_simple_xhtml_as_htmlk  s   

z+WriterTests.test_write_simple_xhtml_as_htmlc                 C   r  )Na  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>This will be escaped in html output: &amp;</title>
    <script>this won't be escaped in html output: &</script>
    <script type="text/javascript">
            //
              // this won't be escaped in html output
              function match(a,b) {
                 if (a < b && a > 0) then { return 1 }
                }
             //
    </script>
    <style>this won't be escaped in html output: &</style>
  </head>
  <!-- a comment -->
  <body>
    <div></div>
    <div>
      <form action="." method="POST">
      <img src="foo.gif">
      <table border="0">
        <tbody>
          <tr class="foo">
            <td>Name</td>
            <td>Description</td>
          </tr>
        </tbody>
      </table>
      <input name="submit" type="submit" value=" Next ">
      </form>
    </div>
  </body>
</html>)r'  r   rx  r  r  r   r   r    test_write_complex_xhtml_as_htmlt  s   

$z,WriterTests.test_write_complex_xhtml_as_htmlc                 C   r  )NaV  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
    <title>This will be escaped in html output: &amp;</title>
    <script>this won't be escaped in html output: &amp;</script>
    <script type="text/javascript">
            //
              // this won't be escaped in html output
              function match(a,b) {
                 if (a &lt; b &amp;&amp; a > 0) then { return 1 }
                }
             //
    </script>
    <style>this won't be escaped in html output: &amp;</style>
  </head>
  <!--  a comment  -->
  <body>
    <div ns0:baz="slab" xmlns:ns0="http://foo/bar" />
    <div>
      <form action="." method="POST">
      <img src="foo.gif" />
      <table border="0">
        <tbody>
          <tr class="foo">
            <td>Name</td>
            <td>Description</td>
          </tr>
        </tbody>
      </table>
      <input name="submit" type="submit" value=" Next " />
      </form>
    </div>
  </body>
</html>)r'  r   rz  r  r  r   r   r   !test_write_complex_xhtml_as_xhtml  s   

#z-WriterTests.test_write_complex_xhtml_as_xhtmlc                 C   s<   ddl m} | t}| |}d}| ||dd| d S )Nr   r   z<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <body>
    <area><base><basefont><br><col><frame><hr><img><input><isindex>
    <link><meta><param>
  </body>
</html>r   r   )r   r   r'  _EMPTYTAGS_HTMLrx  r   )r	   r   r   r  r  r   r   r   test_write_emptytags_html  s
   

z%WriterTests.test_write_emptytags_htmlc                 C   r  )Na  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <body>
  <tag selected></tag>
  <tag checked></tag>
  <tag compact></tag>
  <tag declare></tag>
  <tag defer></tag>
  <tag disabled></tag>
  <tag ismap></tag>
  <tag multiple></tag>
  <tag nohref></tag>
  <tag noresize></tag>
  <tag noshade></tag>
  <tag nowrap></tag>
  </body>
</html>)r'  _BOOLEANATTRS_XHTMLrx  r  r  r   r   r   %test_write_booleanattrs_xhtml_as_html  s   

z1WriterTests.test_write_booleanattrs_xhtml_as_htmlc                 C   ,   |  t}| j|dd}d}| || d S )NTpipelinez<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><body ns0:id="body" xmlns:ns0="https://github.com/Supervisor/supervisor">Hello!</body></html>r  r  r   r   r    test_write_simple_xhtml_pipeline     
z,WriterTests.test_write_simple_xhtml_pipelinec                 C   r  )NTr  a  <?xml version="1.0"?><root>
  <list ns0:id="list" xmlns:ns0="https://github.com/Supervisor/supervisor">
    <item ns0:id="item">
       <name ns0:id="name">Name</name>
       <description ns0:id="description">Description</description>
    </item>
  </list>
</root>r'  r   ru  r  r  r   r   r   test_write_simple_xml_pipeline     
z*WriterTests.test_write_simple_xml_pipelinec                 C   r  )Nlatin-1r   z<?xml version="1.0" encoding="latin-1"?><root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r  r  r   r   r   'test_write_simple_xml_override_encoding  r  z3WriterTests.test_write_simple_xml_override_encodingc                 C   r  )NTfragment<root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r  r  r   r   r   !test_write_simple_xml_as_fragment  r  z-WriterTests.test_write_simple_xml_as_fragmentc                 C   :   |  t}ddlm} | j||jd}d}| || d S )Nr   doctypea  <?xml version="1.0"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r'  r   r   r  ru  xhtmlr  r	   r   r  r  r  r   r   r   "test_write_simple_xml_with_doctype  s
   
	z.WriterTests.test_write_simple_xml_with_doctypec                 C   <   |  t}ddlm} | j|d|jd}d}| || d S )Nr   r  Fdeclarationr  z<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r  r  r   r   r   +test_write_simple_xml_doctype_nodeclaration,  s   
z7WriterTests.test_write_simple_xml_doctype_nodeclarationc                 C   >   |  t}ddlm} | j|d|jdd}d}| || d S )Nr   r  Tr  r  r  r  r  r  r   r   r   <test_write_simple_xml_fragment_kills_doctype_and_declaration;  s   
zHWriterTests.test_write_simple_xml_fragment_kills_doctype_and_declarationc                 C   s.   |  t}| j|ddd}d}| || d S )Nr  T)r   r  z<?xml version="1.0" encoding="latin-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><body>Hello!</body></html>r  r  r   r   r   )test_write_simple_xhtml_override_encodingJ  s   
z5WriterTests.test_write_simple_xhtml_override_encodingc                 C   r  NTr   <html><body>Hello!</body></html>r  r  r   r   r   #test_write_simple_xhtml_as_fragmentP  r  z/WriterTests.test_write_simple_xhtml_as_fragmentc                 C   r  )Nr   r  r  r'  r/  r   r  rz  r  r  r  r   r   r   $test_write_simple_xhtml_with_doctypeV  s
   
z0WriterTests.test_write_simple_xhtml_with_doctypec                 C   r  )Nr   r  Fr  r  r  r  r   r   r   -test_write_simple_xhtml_doctype_nodeclaration]  s   
z9WriterTests.test_write_simple_xhtml_doctype_nodeclarationc                 C   r  )Nr   r  Tr  r  r  r  r   r   r   >test_write_simple_xhtml_fragment_kills_doctype_and_declaratione  s   
zJWriterTests.test_write_simple_xhtml_fragment_kills_doctype_and_declarationc                 C   r  r  r'  r/  rx  r  r  r   r   r   (test_write_simple_xhtml_as_html_fragmentm  r  z4WriterTests.test_write_simple_xhtml_as_html_fragmentc                 C   r  )Nz
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>Hello!</body></html>r  r  r   r   r   ,test_write_simple_xhtml_with_doctype_as_htmls  s   

z8WriterTests.test_write_simple_xhtml_with_doctype_as_htmlc                 C   r  )Nr   r  z|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><body>Hello!</body></html>)r'  r/  r   r  rx  html_strictr  r  r   r   r   +test_write_simple_xhtml_as_html_new_doctype{  s
   
z7WriterTests.test_write_simple_xhtml_as_html_new_doctypec                 C   s&   ddl m} | |jtf| jd d S )Nr   )expatz.<html><head></head><body>&fleeb;</body></html>)xml.parsersr  r   errorSyntaxErrorr'  )r	   r  r   r   r   test_unknown_entity  s   zWriterTests.test_unknown_entityc                 C   @   |  t}|d}|jddd | |}d}| || d S )Nr$   description &<foo>&amp;<bar>Fr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          <description>description &amp;&lt;foo>&amp;&lt;bar></description>
        </item>
        </list>
        </root>r'  r   r   rt   ru  r  r	   r   rp   r  r  r   r   r   test_content_nostructure     


	z$WriterTests.test_content_nostructurec                 C   r  )Nr$   description &<foo> <bar>Tr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          <description>description &<foo> <bar></description>
        </item>
        </list>
        </root>r  r  r   r   r   test_content_structure  r  z"WriterTests.test_content_structurec                 C   r  )Nr$   r  Fr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          description &amp;&lt;foo>&amp;&lt;bar>
        </item>
        </list>
        </root>r'  r   r   rh   ru  r  r  r   r   r   test_replace_nostructure  r  z$WriterTests.test_replace_nostructurec                 C   r  )Nr$   r  Tr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          description &<foo> <bar>
        </item>
        </list>
        </root>r  r  r   r   r   test_replace_structure  r  z"WriterTests.test_replace_structurec                 C   s8   ddl m} ddlm} d}| |ddd|| d S )Nr   r   _escape_cdataO< > &lt;&amp; &&apos; && &foo "" http://www.example.com?foo=bar&bang=baz &#123;zf&lt; > &lt;&amp; &amp;&apos; &amp;&amp; &amp;foo "" http://www.example.com?foo=bar&amp;bang=baz &#123;r   r   )r   r   r   r  r   )r	   r   r  r3   r   r   r   test_escape_cdata  s   zWriterTests.test_escape_cdatac                 C   V   ddl m} ddlm} ddlm} ||ddddd}| |ddd||d	 d S )
Nr   r  r   r      r   r   &#128;ascii)r   r  r   r   r   r   )r	   r  r   r   r3   r   r   r   test_escape_cdata_unicodeerror     z*WriterTests.test_escape_cdata_unicodeerrorc                 C   s:   ddl m} ddlm} d}| |ddd||d  d S )Nr   _escape_attribr   r  zp&lt; > &lt;&amp; &amp;&apos; &amp;&amp; &amp;foo &quot;&quot; http://www.example.com?foo=bar&amp;bang=baz &#123;r   r   )r   r  r   r   r   )r	   r  r   r3   r   r   r   test_escape_attrib  s   zWriterTests.test_escape_attribc                 C   r  )
Nr   r  r   r   r  r   r   r  r  )r   r  r   r   r   r   )r	   r  r   r   r3   r   r   r   test_escape_attrib_unicodeerror  r  z+WriterTests.test_escape_attrib_unicodeerrorN)*r   r   r   r'  r)  rp  ru  rx  rz  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  r  r   r   r   r   rf    sP    	)/	rf  c                 C   s    t dd| } t dd| } | S )Nz[ \t]+ z/>>resubsr   r   r   normalize_html  s   r  c                 C   s.   t dd| } t dd| } t dd| } | S )Nz\s+r  z(?s)\s+<<z(?s)>\s+r  r  r  r   r   r   r~    s   r~  )unittestr  r   r/  r  r  _ENTITIES_XHTMLr   rH  r\   TestCaser   r   r$  rT  rf  r  r~  r   r   r   r   <module>   s6   
	&' 0 I    S /$   U