
    kc                     @   d dl Z 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e j                        Z G d de j                        Z G d de j                        Z G d de j                        Z G d de j                        Zd Zd Zd Zd Zedk(  r e        yy)    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                   f    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)MeldAPITestsc                     ddl m}  ||      S Nr   parse_xmlstringsupervisor.templatingr   )selfstringr   s      B/usr/lib/python3/dist-packages/supervisor/tests/test_templating.py_makeElementzMeldAPITests._makeElement8  s    9v&&    c                     ddl m}  ||      S Nr   parse_htmlstringr
   r   )r   r   r   s      r   _makeElementFromHTMLz!MeldAPITests._makeElementFromHTML<  s    :''r   c                     | j                  t              }|j                  d      }| j                  |j                  d       |j                  d      }| j                  |j
                  d       y )NitemnameName)r   _SIMPLE_XMLfindmeldassertEqualtagtext)r   rootr   r   s       r   test_findmeldzMeldAPITests.test_findmeld@  sV      -}}V$6*}}V$F+r   c                    | j                  t              }|j                  d      }| j                  |j                  d       |j                  dd      }| j                  |d       | j                  |j                  d      d        y )Nr   unknownfoo)r   r   r   r   r   )r   r   r   r"   s       r   test_findmeld_defaultz"MeldAPITests.test_findmeld_defaultG  sm      -}}V$6*--	51%(y148r   c                    | j                  t              }|j                  d      }| j                  |j                  d       ddddddg}|j                  |      D ]7  \  }}|d   |j                  d      _        |d   |j                  d      _        9 | j                  |d	   j                  d       | j                  |d
   j                  d       y )Nr   Jeff Buckleyetherealr   descriptionSlipknotheavyr   r)   r      r   r   r   r   r   repeatr   )r   r   r   dataelementds         r   test_repeat_nochildz MeldAPITests.test_repeat_nochildO  s      -}}V$6*&jA"':<++d+ 	DJGQ,-fIGV$)34]3CG]+0	D 	a~6az2r   c                 D   | j                  t              }|j                  d      }| j                  |j                  d       ddddddg}|j                  |d      D ]7  \  }}|d   |j                  d      _        |d	   |j                  d	      _        9 | j                  |d
   d
   j                  d       | j                  |d
   d   j                  d       | j                  |d   d
   j                  d       | j                  |d   d   j                  d       y )Nlistr&   r'   r(   r*   r+   r   r   r)   r   r,   r-   )r   r   r4   r/   r0   r1   s         r   test_repeat_childzMeldAPITests.test_repeat_child[  s     -}}V$6*&jA"':<++dF3 	DJGQ,-fIGV$)34]3CG]+0	D 	a.9a*5a*5a'2r   c                     | j                  t              }|dddz   |j                  d      }| j                  |j                  d       |j                  d      }| j                  |j                  d       y )Nr#   bar)r)   r   r   r)   )r   r   r   r   r   )r   r   r   descs       r   test_modzMeldAPITests.test_modi  sc      -eE22}}V$E*}}]+E*r   c                     | j                  t              } |j                  di ddd}|j                  d      }| j	                  |j
                  d       | j	                  |dg       y )Nr#   a)r)   jammyjamr)   r<    )r   r   	fillmeldsr   r   r   )r   r   unfilledr8   s       r   test_fillmeldszMeldAPITests.test_fillmeldsq  s^      -!4>>J5S$IJ}}]+E*J<0r   c                    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}| j                  t              }|j                         } |j                  d9i |d4   }| j	                  |g        | j	                  |j                  d      j                  d5   d       | j	                  |j                  d      j                  d5   d       |j                  d      }| j	                  |j                  d5   d       |j                  d      }| j	                  |d3   j                  d6   d6       | j	                  |j                  d      j                  d7   d7       |j                  d      }| j	                  |d3   j                  d7   d7       |j                  d      }| j	                  |d3   j                  d7   d7       |j                         } |j                  d9i |d3   }| j	                  |dg       | j	                  |j                  d      j                  j                  d7      d        |j                  d      }| j	                  |d8   j                  d7   d7       | j	                  |d3   j                  j                  d7      d        |j                         } |j                  d9i |d8   }| j	                  t        |      d2dg       | j	                  |j                  d      j                  d        |j                  d      }| j	                  |d8   j                  d7   d7       | j	                  |d3   j                  j                  d7      d        y ):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   rg   r?   rE   rT   mailokfavoritecolors	            r   test_fillmeldhtmlformz"MeldAPITests.test_fillmeldhtmlformx  s#   N[ NG N\* NN%/0BN	N#)*:N<CTN 7N (
N 5@
N '	N *2%	N :B$	N
 !N
 *EWNP[ PF PL PP",-?P	P#)*<P>EtP 7P (
P 5@
P ,	P /7u	P ?Gu	P
 !P
 *EXP[ b ",-?	#)*<>Et 7 (
 5@
 ,	 /7t	 >Fe	
 !
 +Ff * (();<

)5))4DG42&4;;GDeL4;;GDgN^^L1
**73Z@)))*5zB188CYO 34)))4i@'BCq)00;YG

)5))4DG4$?#@A188<<YGN 34)))4i@))--i8$?

)5))4DG4)J+AB4994@'BCq)00;YGq)0044Y?Fr   c                    ddl m} | j                  t              }|j	                  d      }|j                  d       |d   }| j                  |j                  |       | j                  t        |j                               d       y )Nr   Replacer4   this is a textual replacementr,   )
r
   rq   r   r   r   replacer   r   lengetchildren)r   rq   r   LRs        r   !test_replace_removes_all_elementsz.MeldAPITests.test_replace_removes_all_elements  sk    1  -MM&!			12G(T--/0!4r   c                    ddl m} | j                  t              }|j	                  d      }|j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d	       | j                  t        |j                               d       |d   }| j                  |j                  |       | j                  |j                  d       | j                  t        |j                               d       | j                  |j                  d
       y Nr   rp   r)   rr   r,   r4   r   re   r   F)r
   rq   r   r   r   rs   r   rt   ru   r   r   	structure)r   rq   r   Drv   INs          r   'test_replace_replaces_the_right_elementz4MeldAPITests.test_replace_replaces_the_right_element  sW   1  -MM-(			12T--/0!4G'Q]]_-q1aD'Q]]_-q1aD'Q]]_-q1aD(!@AQ]]_-q1e,r   c                 
   ddl m} | j                  t              }|j	                  d      }|j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d       | j                  t        |j                               d       |d   }| j                  |j                  d	       | j                  t        |j                               d       |d   }| j                  |j                  d       | j                  |j                  d        | j                  t        |j                               d       |d   }| j                  |j                  |       | j                  |j                  d       | j                  |j                  d
       y rz   )r
   rq   r   r   r   contentr   rt   ru   r   r   r{   )r   rq   r   r|   rv   r}   r~   Ts           r   test_contentzMeldAPITests.test_content  s   1  -MM-(			12T--/0!4G'Q]]_-q1aD'Q]]_-q1aD'Q]]_-q1aD.&Q]]_-q1aD(!@Ae,r   c                     ddl m} | j                  t              }|j	                  d      }|j                  dddd       | j                  |j                  d	dd
ddddddd|di       y )Nr   _MELD_IDform1r7   12#)r#   bazgactionr#   r   r   methodPOSTr   )r
   r   r   _COMPLEX_XHTMLr   
attributesr   ri   )r   r   r   r|   s       r   test_attributeszMeldAPITests.test_attributes  sk    2  0MM'"	C3s;%sCVXcg$ 	 r   c                    ddl m} ddlm} | j	                  t
              }|j                  d      }|j                   |dd       |dd      	       | j                  |j                  d
 |dd      ddd |dd      |di       y )Nr   r   	as_stringr   r7   latin1encodingr   )r#   r   r#   r   r   r   )
r
   r   supervisor.compatr   r   r   r   r   r   ri   )r   r   r   r   r|   s        r   test_attributes_unicodez$MeldAPITests.test_attributes_unicode  s    2/  0MM'"	58<%cH= 	 	?)EH5VXyx'Hg$ 	 r   c                 j    | j                  d      }| j                  t        |j                  d       y )N<root></root>r,   )r#   )r   assertRaises
ValueErrorr   )r   r   s     r   $test_attributes_nonstringtype_raisesz1MeldAPITests.test_attributes_nonstringtype_raises  s+      1*doo1=r   N)__name__
__module____qualname__r   r   r    r$   r2   r5   r9   r@   rn   rx   r   r   r   r   r   r=   r   r   r   r   7  sO    '(,9
33+15Gn5-*-0 
 >r   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z y) MeldElementInterfaceTestsc                     ddl m} |S )Nr   )_MeldElementInterface)r
   r   )r   r   s     r   _getTargetClassz)MeldElementInterfaceTests._getTargetClass   s    ?$$r   c                 2    | j                         } ||i |S N)r   )r   argkwklasss       r   _makeOnez"MeldElementInterfaceTests._makeOne  s     $$&c R  r   c                 D   | j                  di       }ddlm} | j                  d|di      }| j                  d|di      }| j                  d|di      }| j                  d|di      }|j                  |       |j                  |       |j                  |       |j                  |       dd	d
ddd
g}|j	                  |      D ]7  \  }}	|	d   |j                  d      _        |	d   |j                  d      _        9 | j                  t        |      d       |d   }
| j                  t        |
      d       |
d   }| j                  t        |      d       |d   }|d   }| j                  |j                  d       | j                  |j                  d	       |d   }| j                  t        |      d       |d   }| j                  t        |      d       |d   }|d   }| j                  |j                  d       | j                  |j                  d       y )Nr   r   r   r   recordr   r)   r&   r'   r(   r*   r+   re   r,   )	r   r
   r   appendr.   r   r   r   rt   )r   r   r   r   r   r   r)   r/   r0   r1   item1record1name1desc1item2record2name2desc2s                     r   test_repeatz%MeldElementInterfaceTests.test_repeat  s   }}VR(2}}Vhv%67x(8)<=}}Vhv%67mmMH]3KLdk"FD&jA"':< ++d+ 	DJGQ,-fIGV$)34]3CG]+0	D 	TA&QUQ'(Wq)

^4Z0QUQ'(Wq)

Z0W-r   c                    | j                  dddi      }|j                  d       | j                  t        |j                        d       |j                  d   }| j                  |j
                  |       | j                  |j                  d       | j                  |j                  d       ddlm	} | j                  |j                  |       y )	Ndividthedivhellor,   r   Frp   r   r   r   rt   	_childrenparentr   r{   r
   rq   r   r   elreplacenoderq   s       r   test_content_simple_nostructurez9MeldElementInterfaceTests.test_content_simple_nostructure/  s    ]]54/2


7R\\*A.ll1o++R0))73..61'2r   c                    | j                  dddi      }|j                  dd       | j                  t        |j                        d       |j                  d   }| j                  |j
                  |       | j                  |j                  d       | j                  |j                  d       dd	lm	} | j                  |j                  |       y )
Nr   r   r   r   Tr{   r,   r   rp   r   r   s       r   test_content_simple_structurez7MeldElementInterfaceTests.test_content_simple_structure:  s    ]]54/2


7d
+R\\*A.ll1o++R0))73..51'2r   c                 z    ddl m} | j                  d|di      }| j                  |j	                  d      |       y )Nr   r   r   r   )r
   r   r   r   r   )r   r   r   s      r   test_findmeld_simplez.MeldElementInterfaceTests.test_findmeld_simpleE  s3    2]]58H"56X.3r   c                     ddl m} | j                  d|di      }| j                  d|di      }|j                  |       | j	                  |j                  d      |       y )Nr   r   r   r   spanthespanr
   r   r   r   r   r   )r   r   r   r   s       r   !test_findmeld_simple_oneleveldownz;MeldElementInterfaceTests.test_findmeld_simple_oneleveldownJ  sS    2]]58H"56}}Vhy%9:
		$Y/6r   c                    ddl m} | j                  d|di      }| j                  d|di      }| j                  d|di      }|j                  |       |j                  |       | j	                  |j                  d      |       y )	Nr   r   r   r   r   r   r;   thear   )r   r   r   r   r;   s        r   "test_findmeld_simple_twolevelsdownz<MeldElementInterfaceTests.test_findmeld_simple_twolevelsdownQ  ss    2]]58H"56}}Vhy%9:MM#01A
		$V,a0r   c                     | j                  dddi      }| j                  |j                  d        | j                  |j                  d       | j                  |j                  ddi       y )Nr   r   r   )r   r   r   r   ri   )r   ifaces     r   	test_ctorz#MeldElementInterfaceTests.test_ctorZ  sV    ed8_5t,E*X7r   c                     | j                  dddi      }|j                         }| j                  t        |      d       | j                  |d   |       y )Nr   r   r   r,   r   )r   getiteratorr   rt   )r   r   iterators      r   test_getiterator_simplez1MeldElementInterfaceTests.test_getiterator_simple`  sJ    mmED?3??$X*!c*r   c                     | j                  dddi      }| j                  di       }| j                  dddi      }| j                  dddi      }d|_        d	|_        |j                  |       |j                  |       |j                  |       |j	                         }| j                  t        |      d
       | j                  |d   |       | j                  |d   |       | j                  |d   |       | j                  |d   |       y )Nr   r   r   r   r   span33abc     r   r,   re      r   r   tailr   r   r   rt   r   r   r   span2r   its         r   test_getiteratorz*MeldElementInterfaceTests.test_getiteratorf  s    mmED?3}}VR(ftCj1gSz2



4EU__R!$A$A%A&A&r   c                 $   | j                  dddi      }| j                  di       }| j                  dddi      }| j                  dddi      }d|_        d	|_        |j                  |       |j                  |       |j                  |       |j	                  d
      }| j                  t        |      d       | j                  |d   |       | j                  |d   |       | j                  |d   |       | j                  |d   |       y )Nr   r   r   r   r   r   r   r   r   )r   r   r   r,   re   r   r   r   s         r   test_getiterator_tag_ignoredz6MeldElementInterfaceTests.test_getiterator_tag_ignoredx  s    mmED?3}}VR(ftCj1gSz2



4EU___'R!$A$A%A&A&r   c                     | j                  dddi      }| j                  di       }|j                  |       | j                  |d   j                  d       | j                  |j                  |       y )Nr   r   r   r   r   )r   r   r   r   r   r   r   r   s      r   test_appendz%MeldElementInterfaceTests.test_append  s^    mmED?3}}VR(

4QV,c*r   c                 b   | j                  dddi      }| j                  di       }| j                  dddi      }|j                  |       ||d<   | j                  |d   j                  d       | j                  |d   j                  ddi       | j                  |d   j
                  |       y )Nr   r   r   r   r   r   )r   r   r   r   ri   r   r   r   r   r   s       r   test__setitem__z)MeldElementInterfaceTests.test__setitem__  s    mmED?3}}VR(ftCj1

4AQV,Qc
3Q,r   c                 6   | j                  dddi      }| j                  di       }| j                  dddi      }|j                  |       |j                  d|       | j                  |d   j                  d       | j                  |d   j
                  ddi       | j                  |d   j                  |       | j                  |d   j                  d       | j                  |d   j
                  i        | j                  |d   j                  |       y )Nr   r   r   r   r   r   r,   )r   r   insertr   r   ri   r   r   s       r   test_insertz%MeldElementInterfaceTests.test_insert  s    mmED?3}}VR(ftCj1

4

1eQV,Qc
3Q,QV,Q+Q,r   c                     | j                  dddi      }d|_        d|_        | j                  di       }|j                  |       |j	                          y )Nr   r   r   r   z   r   )r   r   r   r   rg   r   s      r   test_clone_simplez+MeldElementInterfaceTests.test_clone_simple  sI    mmED?3}}VR(

4		r   c                 z   | j                  dddi      }| j                  di       }| j                  dddi      }| j                  dddi      }d|_        d	|_        |j                  |       |j                  |       |j                  |       |j	                         }| j                  |j                  |j                         | j                  |j                  |j                         | j                  |d
   j                  |d
   j                         | j                  |d
   j                  |d
   j                         | j                  |d
   d
   j                  |d
   d
   j                         | j                  |d
   d
   j                  |d
   d
   j                         | j                  |d
   d
   d
   j                  |d
   d
   d
   j                         | j                  |d
   d
   d
   j                  |d
   d
   d
   j                         | j                  |d
   d
   d
   j                  |d
   d
   d
   j                         | j                  |d
   d
   d
   j                  |d
   d
   d
   j                         | j                  t        |      t        |             | j                  t        |d
         t        |d
                | j                  t        |d
   d
         t        |d
   d
                | j                  t        |d
   d
   d
         t        |d
   d
   d
                y )Nr   r   r   r   r   r   r   r   r   r   )
r   r   r   r   rg   r   r   ri   assertNotEqualr   )r   r   r   r   r   div2s         r   
test_clonez$MeldElementInterfaceTests.test_clone  s   mmED?3}}VR(ftCj1gSz2



4EUyy{$((+T[[1QT!W[[1QQ7QQ
7Q))471:+<+<=Q1))471:a=+<+<=Q1,,d1gajm.B.BCQ1**DGAJqM,>,>?Q1**DGAJqM,>,>?BsGRX.Bs1vJ474Bs1vayM2d1gaj>:Bs1vay|,baA.?@r   c                     | j                  di       }| j                  |j                  d        |j                          | j                  |j                  d        y )Nr   )r   r   r   deparent)r   r   s     r   test_deparent_noparentz0MeldElementInterfaceTests.test_deparent_noparent  sC    mmE2&T*T*r   c                    | j                  di       }| j                  |j                  d        | j                  di       }|j                  |       | j                  |j                  d        | j                  |j                  |       | j                  |d   |       |j	                          | j                  |j                  d        | j                  t        |j                  d       y )Nr   childr   )r   r   r   r   r   r   
IndexError__getitem__)r   r   r   s      r   test_deparent_withparentz2MeldElementInterfaceTests.test_deparent_withparent  s    x,-gr*e-v.E*t,*f&8&8!<r   c                    | j                  di       }| j                  di       }| j                  di       }| j                  di       }|||f}||dd | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  t	        |             y )Nr   child1child2child3r   re   )r   r   r   r   r4   r   r   r  r  r  childrens         r   test_setslicez'MeldElementInterfaceTests.test_setslice  s    x,x,x,x,FF+q///))4>:r   c                    | j                  di       }| j                  di       }| j                  di       }| j                  di       }|||f}||dd |dd= | j                  |j                  d        | j                  |j                  d        | j                  |j                  |       | j                  t        |j                        d       y )Nr   r  r  r  r   re   r,   )r   r   r   rt   r   r  s         r   test_delslicez'MeldElementInterfaceTests.test_delslice  s    x,x,x,x,FF+q1Q3K--/V--.2r   c                    | j                  di       }| j                  di       }|j                  |       |j                  |       | j                  |j                  d        | j                  t        |j                        d       y )Nr   r  r   )r   r   remover   r   rt   r   )r   r   r  s      r   test_removez%MeldElementInterfaceTests.test_remove  si    x,x,ff-V--.2r   c                 X   ddl m} | j                  d|di      }| j                  d|di      }| j                  d|di      }| j                  d|di      }| j                  d|d	i      }| j                  d|d
i      }| j                  d|di      }| j                  di       }	| j                  d|di      }
|j                  |       |j                  |       |j                  |       |j                  |	       |	j                  |       |j                  |       |j                  |       |j                  |
       d }| j	                   ||j                               dg       | j	                   ||j                               ddg       | j	                   ||j                               g d       | j	                   ||j                               g d       | j	                   ||	j                               g d       | j	                   ||j                               g d       | j	                   ||j                               g d       | j	                   ||j                               g d       | j	                   ||
j                               ddg       y )Nr   r   r   div1r   span1r   r   span4span5span6r   c                 H    | D cg c]  }|j                          c}S c c}w r   )meldid)rv   xs     r   idsz3MeldElementInterfaceTests.test_lineage.<locals>.ids  s    )*,AQXXZ,,,s   )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
   r   r   r   r   lineage)r   r   r  r  r   r   r  r  r  r"   r   r  s               r   test_lineagez&MeldElementInterfaceTests.test_lineage  sJ   2}}UXf$56fx&89fx&89fx&89fx&89fx&89fx&89--+}}Vhv%67EUUWuUUD	-T\\^,vh7U]]_-/@AU]]_-/IJU]]_- 0< 	=W__./ 2: 	; 	U]]_- 0@ 	A 	U]]_- 0@ 	A 	U]]_- 0D 	E 	T\\^,vv.>?r   c                 f   ddl m} | j                  dddi      }| j                  di       }| j                  dddi      }| j                  dddi      }|j                  |       |j                  |       |j                  |       |j	                         }| j                  | |d	d
             y )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   rs          r   test_shortreprz(MeldElementInterfaceTests.test_shortrepr)  s    .mmED=1}}VR(ftCj1}}Vd6]3

4E

4MMO 5?GI	Jr   c                     ddl m} ddlm}  |t              }|j                         }| j                  | |dd             y )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  s        r   test_shortrepr2z)MeldElementInterfaceTests.test_shortrepr27  s@    9.~.NN  $,-	.r   c                    ddl m} ddl m}  |t              }|j	                         }| j                  d|di      }|j                  |       |j                  d      }|j                          |j                  d      }|j                          |j                  |       |j                  |      }|d   }	|	d	   D 
cg c]  }
|
j                  |    }}
|	d
   D 
cg c]  }
|
j                  |    }}
|	d   D 
cg c]  }
|
j                  |    }}
|j                          |j                          |j                          | j                  |dg       | j                  |g d       | j                  |dg       |d   }	|	d	   D 
cg c]  }
|
j                  |    }}
|	d
   D 
cg c]  }
|
j                  |    }}
|	d   D 
cg c]  }
|
j                  |    }}
|j                          |j                          |j                          | j                  |dg       | j                  |dg       | j                  |dg       y c c}
w c c}
w c c}
w c c}
w c c}
w c c}
w )Nr   r   r   r   newdivtrtitle	unreducedaddedremovedmoved)td1td2r"  reduced)r
   r   r   r   rg   r   r   r   r   diffmeldri   sortr   )r   r   r   r   rg   r   r"  r#  diffchangesr  	addedtagsremovedtags	movedtagss                 r   test_diffmeld1z(MeldElementInterfaceTests.test_diffmeld1F  s'   92~.

mmEHX#67S^^D!
w'U }}U#{#29'2BDQahhx(D	D3:93EGaqxx)GG29'2BDQahhx(D	DH:.%9:WI. y/29'2BDQahhx(D	D3:93EGaqxx)GG29'2BDQahhx(D	DH:.dV,WI.) EGD EGDs$   >I
I<I
I)II#c                 .   d}d}ddl m}  ||      } ||      }|j                  |      }|d   d   D cg c]  }|j                          }}dg}	| j	                  |	|       |d   d   D cg c]  }|j                          }}g }	| j	                  |	|       |d   d	   D cg c]  }|j                          }}g }	| j	                  |	|       |d
   d   D cg c]  }|j                          }}dg}	| j	                  |	|       |d
   d   D cg c]  }|j                          }}g }	| j	                  |	|       |d
   d	   D cg c]  }|j                          }}g }	| j	                  |	|       y c c}w c c}w c c}w c c}w c c}w c c}w )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   r$  r'  br%  r&  r*  r
   r   r+  r  r   
r   sourcetargetr   source_roottarget_rootr.  r  actualexpecteds
             r   test_diffmeld2z(MeldElementInterfaceTests.test_diffmeld2l  s    	;&v.&v.&&{3 '.k&:7&CD!((*DD56*&-k&:7&CD!((*DD6*&-k&:9&EF!((*FF6* '.i&8&AB!((*BB56*&-i&8&AB!((*BB6*&-i&8&CD!((*DD6*/ E E G
 C C Es#   E9.E>%FFFFc                 <   d}d}ddl m}  ||      } ||      }|j                  |      }|d   d   D cg c]  }|j                          }}ddg}	| j	                  |	|       |d   d	   D cg c]  }|j                          }}d
dg}	| j	                  |	|       |d   d   D cg c]  }|j                          }}ddg}	| j	                  |	|       |d   d   D cg c]  }|j                          }}dg}	| j	                  |	|       |d   d	   D cg c]  }|j                          }}d
g}	| j	                  |	|       |d   d   D cg c]  }|j                          }}dg}	| j	                  |	|       y c c}w c c}w c c}w c c}w c c}w c c}w )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   r$  r'  r4  cr%  r1   er&  zyr*  r5  r6  s
             r   test_diffmeld3z(MeldElementInterfaceTests.test_diffmeld3  s   
 	;&v.&v.&&{3 '.k&:7&CD!((*DD:6*&-k&:7&CD!((*DD:6*&-k&:9&EF!((*FF:6* '.i&8&AB!((*BB56*&-i&8&AB!((*BB56*&-i&8&CD!((*DD56*/ E E G
 C C Es#   F /F(F
!FFFc                 >   d}d}ddl m}  ||      } ||      }|j                  |      }|d   d   D cg c]  }|j                          }}ddg}	| j	                  |	|       |d   d	   D cg c]  }|j                          }}d
dg}	| j	                  |	|       |d   d   D cg c]  }|j                          }}g d}	| j	                  |	|       |d   d   D cg c]  }|j                          }}dg}	| j	                  |	|       |d   d	   D cg c]  }|j                          }}d
g}	| j	                  |	|       |d   d   D cg c]  }|j                          }}ddg}	| j	                  |	|       y c c}w c c}w c c}w c c}w c c}w c c}w )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   r$  r'  r;   r4  r%  mnr&  )r?  r1   rA  rB  r*  r?  rA  r5  r6  s
             r   test_diffmeld4z(MeldElementInterfaceTests.test_diffmeld4  s    	;&v.&v.&&{3 '.k&:7&CD!((*DD:6*&-k&:7&CD!((*DD:6*&-k&:9&EF!((*FF'6* '.i&8&AB!((*BB56*&-i&8&AB!((*BB56*&-i&8&CD!((*DD:6*/ E E G
 C C Es#   F/F(F!FFFc                 2   d}d}ddl m}  ||      } ||      }|j                  |      }|d   d   D cg c]  }|j                          }}g d}	| j	                  |	|       |d   d   D cg c]  }|j                          }}g }	| j	                  |	|       |d   d	   D cg c]  }|j                          }}g }	| j	                  |	|       |d
   d   D cg c]  }|j                          }}ddg}	| j	                  |	|       |d
   d   D cg c]  }|j                          }}g }	| j	                  |	|       |d
   d	   D cg c]  }|j                          }}g }	| j	                  |	|       y c c}w c c}w c c}w c c}w c c}w c c}w )NrE  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   r$  r'  )r;   r4  r?  r1   r%  r&  r*  r;   r?  r5  r6  s
             r   test_diffmeld5z(MeldElementInterfaceTests.test_diffmeld5  s   $ 	;&v.&v.&&{3 '.k&:7&CD!((*DD'6*&-k&:7&CD!((*DD6*&-k&:9&EF!((*FF6* '.i&8&AB!((*BB:6*&-i&8&AB!((*BB6*&-i&8&CD!((*DD6*/ E E G
 C C Es#   E;/F &FF
FFN)!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  r2  r=  rC  rH  rJ  r=   r   r   r   r     s    %!%.N	3	34
718+'$'$+--A8+
=
;33'@TJ.$/L*+Z5+n:+x>+r   r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
ParserTestsc                     ddl m}  || }|S r   r	   )r   argsr   r   s       r   _parsezParserTests._parseO  s    9%r   c                     ddl m}  || }|S r   r   )r   rN  r   r   s       r   _parse_htmlzParserTests._parse_htmlT  s    :&r   c                    ddl m} | j                  t              }| j	                  |j
                  d       | j	                  |j                  d        |d   }| j	                  |j
                  d       | j	                  |j                  |       | j	                  |j                  |   d       |d   }| j	                  |j
                  d       | j	                  |j                  |       | j	                  |j                  |   d       |d   }|d   }| j	                  |j
                  d       | j	                  |j                  |       | j	                  |j                  |   d       | j	                  |j
                  d       | j	                  |j                  |       | j	                  |j                  |   d       y )	Nr   r   r   r4   r   r,   r   r)   )r
   r   rO  r   r   r   r   ri   )r   r   r   l1str   r   r)   s          r   test_parse_simple_xmlz!ParserTests.test_parse_simple_xmlY  sg   2{{;'6*d+Aw6*d+X.7Aw6*d+X.7Aw1g6*d+X.7-8++T2++H5}Er   c                    d}ddl m} | j                  t              }| j	                  |j
                  |dz         | j	                  |j                  i        | j	                  |j                  d        |d   }| j	                  |j
                  |dz         | j	                  |j                  |   d       | j	                  |j                  |       y )N {http://www.w3.org/1999/xhtml}%sr   r   htmlbody)r
   r   rO  _SIMPLE_XHTMLr   r   ri   r   )r   xhtml_nsr   r   rX  s        r   test_parse_simple_xhtmlz#ParserTests.test_parse_simple_xhtmlo  s    52{{=)8f#45b)d+Aw8f#45X.7d+r   c                 >   d}ddl m} | j                  t              }| j	                  |j
                  |dz         | j	                  |j                  i        | j	                  |j                  d        |d   }| j	                  |j
                  |dz         | j	                  |j                  i        | j	                  |j                  |       |d   }| j	                  |j
                  |dz         | j	                  |j                  d   d       | j	                  |j                  |       |d	   }| j	                  |j
                  |d
z         | j	                  |j                  |   d
       | j	                  |j                  |       |d   }| j	                  |j
                  |dz         | j	                  |j                  i        | j	                  |j                  |       |d   }| j	                  |j
                  |dz         | j	                  |j                  ddi       | j	                  |j                  |       |d	   }	| j	                  |	j
                  |dz         | j	                  |	j                  |   d       | j	                  |	j                  |       |	d   }
| j	                  |
j
                  |dz         | j	                  |
j                  |   d       | j	                  |
j                  d   d       | j	                  |
j                  d   d       | j	                  |
j                  |	       |
d   }| j	                  |j
                  |dz         | j	                  |j                  |
       |
d	   }| j	                  |j
                  |dz         | j	                  |j                  |   d       | j	                  |j                  d   d       | j	                  |j                  |
       |d   }| j	                  |j
                  |dz         | j	                  |j                  |   d       | j	                  |j                  |       |d   }| j	                  |j
                  |dz         | j	                  |j                  |   d       | j	                  |j                  d   d       | j	                  |j                  |       |d   }| j	                  |j
                  |d z         | j	                  |j                  |   d!       | j	                  |j                  |       |d	   }| j	                  |j
                  |d z         | j	                  |j                  |   d"       | j	                  |j                  |       y )#NrV  r   r   rW  headmetar   text/html; charset=ISO-8859-1r,   r#  re   rX  r   z{http://foo/bar}bazslabcontent_wellformr   r   .r   r   imgtabletable1border0tbodyr"  classr#   tdr(  r)  )r
   r   rO  r   r   r   ri   r   )r   rZ  r   r   r]  r^  r#  rX  r  r   rb  rd  re  ri  r"  r(  r)  s                    r   test_parse_complex_xhtmlz$ParserTests.test_parse_complex_xhtml|  s   52{{>*8f#45b)d+Aw8f#45b)d+Aw8f#45Y/8	:d+QHw$67h/9t,Aw8f#45b)d+Aw8e#34'<f&EFd+Aw8e#34X.?d+Aw8f#45X.8X.4X.7d+1g(U"23T*QHw$67h/:h/5t,aHw$67h/9u-1XD18,d37+U3E*e(T/2H-u5R(e(T/2H-u5R(r   c                    ddl m} ddl m} | j                  t              }| j                  |j                  d       | j                  |j                  i        | j                  |j                  d        |d   }| j                  |j                  d       | j                  |j                  i        | j                  |j                  |       |d   }| j                  |j                  d       | j                  |j                  d   d       |d	   }| j                  |j                  d
       | j                  |j                  |   d
       | j                  |j                  |       |d	   }| j                  |j                  d       | j                  |j                  i        | j                  |j                  |       |d   }| j                  |j                  |       |d   }	| j                  |	j                  d       | j                  |	j                  ddddd       | j                  |	j                  |       |d   }
| j                  |
j                  d       |d   }| j                  |j                  d       y )Nr   r   )CommentrW  r]  r^  r   r_  r,   r#  rX  r   re  ztext-align: left; width: 100px;r   r   )stylerg  cellpaddingcellspacing   r;      rd  )	r
   r   rn  rQ  	_NVU_HTMLr   r   ri   r   )r   r   rn  r   r]  r^  r#  rX  commentre  hrefrd  s               r   test_nvu_htmlzParserTests.test_nvu_html  s   21	*6*b)d+Aw6*b)d+Aw6*Y/8	:QG,h/9t,Aw6*b)d+q'g.QG,(I146969	(; 	<
 	t,Aw3'1g%(r   c                 T    d}d|z  }| j                  t        | j                  |       y Nz(https://github.com/Supervisor/supervisorzF<html xmlns:meld="%s" meld:id="repeat"><body meld:id="repeat"/></html>)r   r   rO  r   meld_nsrepeateds      r   !test_dupe_meldids_fails_parse_xmlz-ParserTests.test_dupe_meldids_fails_parse_xml  s-    <68?@*dkk8<r   c                 T    d}d|z  }| j                  t        | j                  |       y ry  )r   r   rQ  rz  s      r   "test_dupe_meldids_fails_parse_htmlz.ParserTests.test_dupe_meldids_fails_parse_html  s/    <68?@*d&6&6Ar   N)r   r   r   rO  rQ  rT  r[  rl  rw  r}  r  r=   r   r   rL  rL  N  s/    

F,,H)T')T=Br   rL  c                   *    e Zd Zd Zd Zd Zd Zd Zy)	UtilTestsc                 L    ddl m} d} ||      }d}| j                  ||       y )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
   r  r   r   r  origr;  r<  s        r   test_insert_xhtml_doctypez#UtilTests.test_insert_xhtml_doctype  s,    8% \*r   c                 L    ddl m} d} ||      }d}| j                  ||       y )Nr   r  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>r  r  s        r   !test_insert_doctype_after_xmldeclz+UtilTests.test_insert_doctype_after_xmldecl  s,    8F% D*r   c                 L    ddl m} d} ||      }d}| j                  ||       y )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  r  r;  r<  s        r   test_insert_meld_ns_declz"UtilTests.test_insert_meld_ns_decl  s,    =F$T* A*r   c                 L    ddl m} d} ||      }d}| j                  ||       y )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
   r  r   )r   r  r  r;  r<  s        r   'test_prefeed_preserves_existing_meld_nsz1UtilTests.test_prefeed_preserves_existing_meld_ns  s+    1U S*r   c                 H    ddl m} d} ||      }| j                  ||       y )Nr   r  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>r  )r   r  r  r;  s       r   'test_prefeed_preserves_existing_doctypez1UtilTests.test_prefeed_preserves_existing_doctype  s&    1 B&r   N)r   r   r   r  r  r  r  r  r=   r   r   r  r    s    ++++'r   r  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)y())WriterTestsc                 "    ddl m}  ||      }|S r   r	   )r   xmlr   r   s       r   rO  zWriterTests._parse!  s    9s#r   c                 "    ddl m}  ||      }|S r   r   )r   r  r   r   s       r   rQ  zWriterTests._parse_html&  s    :$r   c                     	 ddl m}  |       } ||fi | |j                  d       |j	                         }|S #  ddlm} Y =xY w)Nr   )BytesIO)StringIO)ior  r  seekread)r   fnr   r  outr;  s         r   _writezWriterTests._write+  sC    	5" i
3"	54s	   ; Ac                 <     | j                   |j                  fi |S r   )r  	write_xmlr   noder   s      r   
_write_xmlzWriterTests._write_xml6  s    t{{4>>0R00r   c                 <     | j                   |j                  fi |S r   )r  
write_htmlr  s      r   _write_htmlzWriterTests._write_html9  s    t{{4??1b11r   c                 <     | j                   |j                  fi |S r   )r  write_xhtmlr  s      r   _write_xhtmlzWriterTests._write_xhtml<  s    t{{4++2r22r   c                     ddl m} t         ||d            }t         ||d            }| j                  ||       y Nr   r   r   r   r   r   normalize_xmlr   r   r;   r4  r   s       r   assertNormalizedXMLEqualz$WriterTests.assertNormalizedXMLEqual?  7    /)A9:)A9:Ar   c                     ddl m} t         ||d            }t         ||d            }| j                  ||       y r  r  r  s       r   assertNormalizedHTMLEqualz%WriterTests.assertNormalizedHTMLEqualE  r  r   c                    | j                  t              }| j                  |      }d}| j                  ||       |j	                  d      j                  d      D ]I  \  }}t        |d         |j	                  d      _        t        |d         |j	                  d      _        K | j                  |      }d}| j                  ||       y )	Nz<?xml version="1.0"?><root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r   ))r,   re   r   r   r,   r)   z<?xml version="1.0"?><root>
  <list>
    <item>
       <name>1</name>
       <description>2</description>
    </item>
  </list>
</root>)rO  r   r  r  r   r.   strr   )r   r   r;  r<  r   r/   s         r   test_write_simple_xmlz!WriterTests.test_write_simple_xmlK  s    {{;'& 	%%fh7f-44X> 	;HB'*47|BKK$.1$q'lBKK&+	; & 	%%fh7r   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )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>rO  rY  r  r  r   r   r;  r<  s       r   test_write_simple_xhtmlz#WriterTests.test_write_simple_xhtmlf  s8    {{=)""4( s%%fh7r   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )Nz<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <body>Hello!</body>
</html>)rO  rY  r  r  r  s       r   test_write_simple_xhtml_as_htmlz+WriterTests.test_write_simple_xhtml_as_htmll  s9    {{=)!!$' 	&&vx8r   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )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>)rO  r   r  r  r  s       r    test_write_complex_xhtml_as_htmlz,WriterTests.test_write_complex_xhtml_as_htmlu  s:    {{>*!!$'"H 	&&vx8r   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )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>)rO  r   r  r  r  s       r   !test_write_complex_xhtml_as_xhtmlz-WriterTests.test_write_complex_xhtml_as_xhtml  s<     {{>*""4("F 	%%fh7r   c                     ddl m} | j                  t              }| j	                  |      }d}| j                   ||d      |       y )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   rO  _EMPTYTAGS_HTMLr  r   )r   r   r   r;  r<  s        r   test_write_emptytags_htmlz%WriterTests.test_write_emptytags_html  sC    /{{?+!!$' 	6H=xHr   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )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>)rO  _BOOLEANATTRS_XHTMLr  r  r  s       r   %test_write_booleanattrs_xhtml_as_htmlz1WriterTests.test_write_booleanattrs_xhtml_as_html  s:    {{./!!$'" 	&&vx8r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y )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  s       r    test_write_simple_xhtml_pipelinez,WriterTests.test_write_simple_xhtml_pipeline  s=    {{=)""4$"7 v%%fh7r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y )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>rO  r   r  r  r  s       r   test_write_simple_xml_pipelinez*WriterTests.test_write_simple_xml_pipeline  ;    {{;'5 	%%fh7r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y )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  s       r   'test_write_simple_xml_override_encodingz3WriterTests.test_write_simple_xml_override_encoding  s;    {{;'	: 	%%fh7r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y )NTfragment<root>
  <list>
    <item>
       <name>Name</name>
       <description>Description</description>
    </item>
  </list>
</root>r  r  s       r   !test_write_simple_xml_as_fragmentz-WriterTests.test_write_simple_xml_as_fragment  r  r   c                     | j                  t              }ddlm} | j	                  ||j
                        }d}| j                  ||       y )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>rO  r   r
   r  r  xhtmlr  r   r   r  r;  r<  s        r   "test_write_simple_xml_with_doctypez.WriterTests.test_write_simple_xml_with_doctype  sB    {{;'1w}}= 	%%fh7r   c                     | j                  t              }ddlm} | j	                  |d|j
                        }d}| j                  ||       y )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  s        r   +test_write_simple_xml_doctype_nodeclarationz7WriterTests.test_write_simple_xml_doctype_nodeclaration-  sJ    {{;'15)0 ! 8 	%%fh7r   c                     | j                  t              }ddlm} | j	                  |d|j
                  d      }d}| j                  ||       y )Nr   r  Tr  r  r  r  r  r  s        r   <test_write_simple_xml_fragment_kills_doctype_and_declarationzHWriterTests.test_write_simple_xml_fragment_kills_doctype_and_declaration<  sM    {{;'14)0 ! G 	%%fh7r   c                 ~    | j                  t              }| j                  |dd      }d}| j                  ||       y )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  s       r   )test_write_simple_xhtml_override_encodingz5WriterTests.test_write_simple_xhtml_override_encodingK  s?    {{=)""4)"N [%%fh7r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y NTr   <html><body>Hello!</body></html>r  r  s       r   #test_write_simple_xhtml_as_fragmentz/WriterTests.test_write_simple_xhtml_as_fragmentQ  s:    {{=)""4$"79%%fh7r   c                     | j                  t              }ddlm} | j	                  ||j
                        }d}| j                  ||       y )Nr   r  r  rO  rY  r
   r  r  r  r  r  s        r   $test_write_simple_xhtml_with_doctypez0WriterTests.test_write_simple_xhtml_with_doctypeW  sD    {{=)1""4"? s%%fh7r   c                     | j                  t              }ddlm} | j	                  |d|j
                        }d}| j                  ||       y )Nr   r  Fr  r  r  r  s        r   -test_write_simple_xhtml_doctype_nodeclarationz9WriterTests.test_write_simple_xhtml_doctype_nodeclaration^  sK    {{=)1""4U)0 # 8 s%%fh7r   c                     | j                  t              }ddlm} | j	                  |d|j
                  d      }d}| j                  ||       y )Nr   r  Tr  r  r  r  s        r   >test_write_simple_xhtml_fragment_kills_doctype_and_declarationzJWriterTests.test_write_simple_xhtml_fragment_kills_doctype_and_declarationf  sK    {{=)1""4T)0 # G9%%fh7r   c                 |    | j                  t              }| j                  |d      }d}| j                  ||       y r  rO  rY  r  r  r  s       r   (test_write_simple_xhtml_as_html_fragmentz4WriterTests.test_write_simple_xhtml_as_html_fragmentn  s:    {{=)!!$!69%%fh7r   c                 x    | j                  t              }| j                  |      }d}| j                  ||       y )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  s       r   ,test_write_simple_xhtml_with_doctype_as_htmlz8WriterTests.test_write_simple_xhtml_with_doctype_as_htmlt  s9    {{=)!!$'$ 	%%fh7r   c                     | j                  t              }ddlm} | j	                  ||j
                        }d}| j                  ||       y )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>)rO  rY  r
   r  r  html_strictr  r  s        r   +test_write_simple_xhtml_as_html_new_doctypez7WriterTests.test_write_simple_xhtml_as_html_new_doctype|  sG    {{=)1!!$0C0C!D$ 	%%fh7r   c                 j    ddl m} | j                  |j                  t        f| j
                  d       y )Nr   )expatz.<html><head></head><body>&fleeb;</body></html>)xml.parsersr   r   errorSyntaxErrorrO  )r   r   s     r   test_unknown_entityzWriterTests.test_unknown_entity  s(    %5;;4dkkJ	Lr   c                     | j                  t              }|j                  d      }|j                  dd       | j	                  |      }d}| j                  ||       y )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>rO  r   r   r   r  r  r   r   r|   r;  r<  s        r   test_content_nostructurez$WriterTests.test_content_nostructure  V    {{;'MM-(			0E	B& 	%%fh7r   c                     | j                  t              }|j                  d      }|j                  dd       | j	                  |      }d}| j                  ||       y )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  s        r   test_content_structurez"WriterTests.test_content_structure  V    {{;'MM-(			,	=& 	%%fh7r   c                     | j                  t              }|j                  d      }|j                  dd       | j	                  |      }d}| j                  ||       y )Nr)   r  Fr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          description &amp;&lt;foo>&amp;&lt;bar>
        </item>
        </list>
        </root>rO  r   r   rs   r  r  r  s        r   test_replace_nostructurez$WriterTests.test_replace_nostructure  r
  r   c                     | j                  t              }|j                  d      }|j                  dd       | j	                  |      }d}| j                  ||       y )Nr)   r  Tr   z<?xml version="1.0"?>
        <root>
        <list>
        <item>
        <name>Name</name>
          description &<foo> <bar>
        </item>
        </list>
        </root>r  r  s        r   test_replace_structurez"WriterTests.test_replace_structure  r  r   c                 `    ddl m} ddlm} d}| j	                   |dd       ||             y )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  r;   s       r   test_escape_cdatazWriterTests.test_escape_cdata  s8    .7> J&( !		r   c                     ddl m} ddlm} ddlm}  | |dd      d      }| j                   |dd       ||d	             y )
Nr   r  r  r      r   r   &#128;ascii)r
   r  r   r  r   r   )r   r  r  r   r;   s        r   test_escape_cdata_unicodeerrorz*WriterTests.test_escape_cdata_unicodeerror  s?    7./hv9HM(X>&q'2	4r   c                 b    ddl m} ddlm} d}| j	                   |dd       ||d              y )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  r;   s       r   test_escape_attribzWriterTests.test_escape_attrib  s<    8.> J '( 1d#	%r   c                     ddl m} ddlm} ddlm}  | |dd      d      }| j                   |dd       ||d	             y )
Nr   r  r  r   r  r   r   r  r  )r
   r   r   r  r   r   )r   r   r  r   r;   s        r   test_escape_attrib_unicodeerrorz+WriterTests.test_escape_attrib_unicodeerror  s?    8./hv9HM(X>'73	5r   N)*r   r   r   rO  rQ  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=   r   r   r  r     s    

	1238689'9R-8^I9,888888888888888L8 8 8 8 	4
%5r   r  c                 b    t        j                  dd|       } t        j                  dd|       } | S )Nz[ \t]+ z/>>resubss    r   normalize_htmlr,    s+    
y#q!A
uc1AHr   c                     t        j                  dd|       } t        j                  dd|       } t        j                  dd|       } | S )Nz\s+r%  z(?s)\s+<<z(?s)>\s+r&  r'  r*  s    r   r  r    s=    
vsAA
{C#A
{C#AHr   c                  V    t        j                  t        j                  t                 S r   )unittestfindTestCasessysmodulesr   r=   r   r   
test_suiter4    s    !!#++h"788r   c                  0    t        j                  d       y )Nr4  )defaultTest)r0  mainr=   r   r   r7  r7     s    MMl+r   __main__)r0  r(  r2  r   rY  r  r  _ENTITIES_XHTMLr   rt  rf   TestCaser   r   rL  r  r  r,  r  r4  r7  r   r=   r   r   <module>r;     s     	 

 "$L%	Nm ^F>8$$ F>PK	+ 1 1 K	+^lB(## lB\"'!! "'HP5(## P5d
9, zF r   