
    w:iq                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ  G d	 d
ej                  Zd Zedk    r ej        d           dS dS )    N)	text_typeBytesIOStringIO)Markup)
Translator)XML)BadDirectiveErrorTemplateSyntaxError)TemplateLoaderTemplateNotFoundMarkupTemplatec                   >   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)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4S )5MarkupTemplateTestCasez%Tests for markup template processing.c                     t          d          }t          |          }|                     dt          |                    d                               d S Nz<root> ${var} $var</root>z<root> 42 42</root>*   var)r   r   assertEqualstrgenerate)selffileobjtmpls      Y/var/www/html/trac/venv/lib/python3.11/site-packages/genshi/template/tests/test_markup.pytest_parse_fileobjz)MarkupTemplateTestCase.test_parse_fileobj!   sP    677g&&.DMMbM4I4I0J0JKKKKK    c                     t          d          }t          |          }|                     dt          |                    d                               d S r   )r   r   r   r   r   )r   streamr   s      r   test_parse_streamz(MarkupTemplateTestCase.test_parse_stream&   sP    011f%%.DMMbM4I4I0J0JKKKKKr   c                 J   t          d          }t          |          }t                      }t          j        ||d           |                    d           t          j        |          }|                     dt          |	                    d                               d S )Nz<root>$var</root>   r   z<root>42</root>r   r   )
r   r   r   pickledumpseekloadr   r   r   )r   r    r   buf	unpickleds        r   test_picklez"MarkupTemplateTestCase.test_pickle+   s    ())f%%iiD#q!!!K$$	*C	0B0Br0B0J0J,K,KLLLLLr   c                     t          d          }|                     dt          |                    d                               d S r   r   r   r   r   r   r   s     r   test_interpolate_mixed3z.MarkupTemplateTestCase.test_interpolate_mixed34   sC    9::.DMMbM4I4I0J0JKKKKKr   c                     t          d          }|                     dt          |                    d                               d S )Nz<root>${    foo    }</root>z<root>bar</root>barfoor,   r-   s     r   'test_interpolate_leading_trailing_spacez>MarkupTemplateTestCase.test_interpolate_leading_trailing_space8   sC    ;<<+S51I1I-J-JKKKKKr   c                     t          d          }|                     dt          |                    d                               d S )Nz:<root>${dict(
          bar = 'baz'
        )[foo]}</root>z<root>baz</root>r0   r1   r,   r-   s     r   test_interpolate_multilinez1MarkupTemplateTestCase.test_interpolate_multiline<   sK        	+S51I1I-J-JKKKKKr   c                     t          d          }|                     dt          |                                                     d S )Nz<root attr="${1}"/>z<root attr="1"/>r,   r-   s     r   !test_interpolate_non_string_attrsz8MarkupTemplateTestCase.test_interpolate_non_string_attrsB   s=    344+S-A-ABBBBBr   c                     t          d          }|                     dt          |                    d                               d S )Nz<root>$foo</root>z<root>buzz</root>)buzzr1   r,   r-   s     r   test_interpolate_list_resultz3MarkupTemplateTestCase.test_interpolate_list_resultF   sC    122,c$--I-2N2N.O.OPPPPPr   c                     t          d          }|                     dt          |                                                     d S )N<root attr=""/>r,   r-   s     r   test_empty_attrz&MarkupTemplateTestCase.test_empty_attrJ   s=    /00*C,@,@AAAAAr   c                     t          d          }|                     dt          |                    d                               d S )Nz<root attr="$attr"/>r<    )attrr,   r-   s     r   test_empty_attr_interpolatedz3MarkupTemplateTestCase.test_empty_attr_interpolatedN   sC    455*C20F0F,G,GHHHHHr   c                     d}	 t          |d          }d S # t          $ rA}|                     d|j                   |                     d|j                   Y d }~d S d }~ww xY w)Nz<<p xmlns:py="http://genshi.edgewall.org/" py:do="nothing" />	test.htmlfilename   )r   r	   r   rE   linenor   xmlr   es       r   test_bad_directive_errorz/MarkupTemplateTestCase.test_bad_directive_errorR   s    L	*!#<<<DDD  	* 	* 	*[!*555Q)))))))))	*s    
A"6AA"c                    d}	 t          |d                                          }|                     d           d S # t          $ rA}|                     d|j                   |                     d|j                   Y d }~d S d }~ww xY w)Nz9<p xmlns:py="http://genshi.edgewall.org/" py:if="bar'" />rC   rD   Expected TemplateSyntaxErrorrF   )r   r   failr
   r   rE   rG   rH   s       r   !test_directive_value_syntax_errorz8MarkupTemplateTestCase.test_directive_value_syntax_errorZ   s    M	*!#<<<EEGGDII455555" 	* 	* 	*[!*555Q)))))))))	*s   8> 
B	6BB	c                     d}	 t          |d          }|                     d           d S # t          $ rA}|                     d|j                   |                     d|j                   Y d }~d S d }~ww xY w)Nz/<p>
          Foo <em>${bar"}</em>
        </p>rC   rD   rM   r#   r   rN   r
   r   rE   rG   rH   s       r   test_expression_syntax_errorz3MarkupTemplateTestCase.test_expression_syntax_errorc   s    	*!#<<<DII455555" 	* 	* 	*[!*555Q)))))))))	*   &, 
A76A22A7c                     d}	 t          |d          }|                     d           d S # t          $ rA}|                     d|j                   |                     d|j                   Y d }~d S d }~ww xY w)Nz$<p><em></em>

 ${bar"}

        </p>rC   rD   rM      rQ   rH   s       r   'test_expression_syntax_error_multi_linez>MarkupTemplateTestCase.test_expression_syntax_error_multi_linen   s    
	*!#<<<DII455555" 	* 	* 	*[!*555Q)))))))))	*rS   c           
          t          d          }|                     dt          |                    t	          d                                         dS )zi
        Verify that outputting context data that is a `Markup` instance is not
        escaped.
        L<div xmlns:py="http://genshi.edgewall.org/">
          $myvar
        </div>z)<div>
          <b>foo</b>
        </div>z
<b>foo</b>myvarN)r   r   r   r   r   r-   s     r   test_markup_noescapez+MarkupTemplateTestCase.test_markup_noescape{   sg    
     	 t}}6,+?+?}@@AA	C 	C 	C 	C 	Cr   c                     t          d          }|                     dt          |                    d                               dS )zb
        Verify that outputting context data in text nodes doesn't escape
        quotes.
        rX   z$<div>
          "foo"
        </div>"foo"rY   Nr,   r-   s     r   test_text_noescape_quotesz0MarkupTemplateTestCase.test_text_noescape_quotes   sZ    
     	 t}}7}3344	6 	6 	6 	6 	6r   c                     t          d          }|                     dt          |                    d                               dS )zR
        Verify that outputting context data in attribtes escapes quotes.
        z\<div xmlns:py="http://genshi.edgewall.org/">
          <elem class="$myvar"/>
        </div>z<<div>
          <elem class="&#34;foo&#34;"/>
        </div>r]   rY   Nr,   r-   s     r   test_attr_escape_quotesz.MarkupTemplateTestCase.test_attr_escape_quotes   sZ         	 t}}7}3344	6 	6 	6 	6 	6r   c                     t          d          }|                     dt          |                    d                               d S )Nze<div xmlns:py="http://genshi.edgewall.org/">
          <py:if test="myvar">bar</py:if>
        </div>z"<div>
          bar
        </div>r]   rY   r,   r-   s     r   test_directive_elementz-MarkupTemplateTestCase.test_directive_element   sX        	 t}}7}3344	6 	6 	6 	6 	6r   c                     t          d          }|                     dt          |                                                     d S )NzV<div xmlns:py="http://genshi.edgewall.org/">
          <!-- foo bar -->
        </div>z/<div>
          <!-- foo bar -->
        </div>r,   r-   s     r   test_normal_commentz*MarkupTemplateTestCase.test_normal_comment   sR        	 t}}''	) 	) 	) 	) 	)r   c                     t          d          }|                     dt          |                                                     d S )Nzi<div xmlns:py="http://genshi.edgewall.org/">
          <!-- !foo -->
          <!--!bar-->
        </div>z<div>
        </div>r,   r-   s     r   test_template_commentz,MarkupTemplateTestCase.test_template_comment   sR        	 t}}''	) 	) 	) 	) 	)r   c                     t          d          }|                     dt          |                                                     d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <span xmlns:py="http://genshi.edgewall.org/">
          </span>
        </div>z7<div>
          <span>
          </span>
        </div>r,   r-   s     r   %test_parse_with_same_namespace_nestedz<MarkupTemplateTestCase.test_parse_with_same_namespace_nested   sT        	  t}}''	) 	) 	) 	) 	)r   c                     t          d                    d          d          }|                     dt          |                                                     d S )Nu}   <?xml version="1.0" encoding="iso-8859-1" ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ö
        </div>
iso-8859-1encodinguM   <?xml version="1.0" encoding="iso-8859-1"?>
<div>
          ö
        </div>r   encoder   r   r   r-   s     r    test_latin1_encoded_with_xmldeclz7MarkupTemplateTestCase.test_latin1_encoded_with_xmldecl   sh      &&&? ? ? 	 T]]__--	/ 	/ 	/ 	/ 	/r   c                     t          d                    d          d          }|                     dt          |                                                     d S )NuH   <div xmlns:py="http://genshi.edgewall.org/">
          ö
        </div>rj   rk   u!   <div>
          ö
        </div>rm   r-   s     r   %test_latin1_encoded_explicit_encodingz<MarkupTemplateTestCase.test_latin1_encoded_explicit_encoding   sf     &&&? ? ? 	 T]]__--	/ 	/ 	/ 	/ 	/r   c                 $    t          d           dS )z
        Verify that a code block processing instruction with trailing space
        does not cause a syntax error (see ticket #127).
        zI<foo>
          <?python
            bar = 42
          ?>
        </foo>Nr   )r   s    r   test_exec_with_trailing_spacez4MarkupTemplateTestCase.test_exec_with_trailing_space   s%    
 	  	 	 	 	 	r   c                     t          d          }|                     dt          |                                                     d S )Nz<?python from datetime import timedelta ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ${timedelta(days=2)}
        </div>z.<div>
          2 days, 0:00:00
        </div>r,   r-   s     r   test_exec_importz'MarkupTemplateTestCase.test_exec_import   sR        	 t}}''	) 	) 	) 	) 	)r   c                     t          d          }|                     dt          |                                                     d S )Nz
        <?python
        def foo():
            return 42
        ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ${foo()}
        </div>z!<div>
          42
        </div>r,   r-   s     r   test_exec_defz$MarkupTemplateTestCase.test_exec_def   sR        	 t}}''	) 	) 	) 	) 	)r   c                     t          d          }|                     dt          |                                                     dS )z
        Verify that a namespace declaration on an element that is removed from
        the generated stream does not get pushed up to the next non-stripped
        element (see ticket #107).
        z<?xml version="1.0"?>
        <Test xmlns:py="http://genshi.edgewall.org/">
          <Size py:if="0" xmlns:t="test">Size</Size>
          <Item/>
        </Test>zI<?xml version="1.0"?>
<Test>
          
          <Item/>
        </Test>Nr,   r-   s     r   test_namespace_on_removed_elemz5MarkupTemplateTestCase.test_namespace_on_removed_elem   sV        
 	  ((	* 	* 	* 	* 	*r   c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                    d	
                              d                      t          j        |           d S # t          j        |           w xY w)Ngenshi_testsuffix
tmpl1.htmlw<div>Included $idx</div>
tmpl2.htmlz<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="${name}.html" py:for="idx in range(3)" />
                </html>p<html>
                  <div>Included 0</div><div>Included 1</div><div>Included 2</div>
                </html>tmpl1namerk   tempfilemkdtempopenospathjoinwritecloser   r'   r   r   rendershutilrmtreer   dirnamefile1file2loaderr   s         r   test_include_in_loopz+MarkupTemplateTestCase.test_include_in_loop  sd   "-888	#g|<<cBBE:;;;g|<<cBBE    
 #WI..F;;|,,D  MMwM77>>>MMO O O M'"""""FM'""""<   .E4 A0 E4 0B1E4 8C" E4 "C88A&E4 4F
c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                    d	
                              d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r~   r   <div>Included</div>r   z<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="${name}.html" />
                </html>D<html>
                  <div>Included</div>
                </html>r   r   rk   r   r   s         r   test_dynamic_include_hrefz0MarkupTemplateTestCase.test_dynamic_include_href  sd   "-888	#g|<<cBBE5666g|<<cBBE    
 #WI..F;;|,,D  MMwM77>>>MMO O O M'"""""FM'""""r   c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r~   r   z<li>$item</li>r   ac  <html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <ul py:match="ul">${select('li')}</ul>
                  <ul py:with="items=(1, 2, 3)">
                    <xi:include href="tmpl1.html" py:for="item in items" />
                  </ul>
                </html>zX<html>
                  <ul><li>1</li><li>2</li><li>3</li></ul>
                </html>rk   r   r   s         r   test_select_included_elementsz4MarkupTemplateTestCase.test_select_included_elements6  s^   "-888	#g|<<cBBE0111g|<<cBBE	     #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""<   .E2 A0 E2 0B1E2 8C" E2 "C88A$E2 2Fc                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r~   r   r   r   <html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"><xi:fallback>
                    Missing</xi:fallback></xi:include>
                </html>r   rk   r   r   s         r    test_fallback_when_include_foundz7MarkupTemplateTestCase.test_fallback_when_include_foundS  s^   "-888	#g|<<cBBE5666g|<<cBBE    
 #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""r   c                 "   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |gd          }|	                    d          }| 
                    t          |                                j                   t          j        |           d S # t          j        |           w xY w)Nr{   r|   r   r   z{<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"/>
                </html>Tauto_reload)r   r   r   r   r   r   r   r   r   r'   assertRaisesr   r   r   r   r   r   r   r   r   r   s        r   !test_error_when_include_not_foundz8MarkupTemplateTestCase.test_error_when_include_not_foundm  s    "-888	#g|<<cBBE     #WI4@@@F;;|,,D.0FGGGM'"""""FM'""""s$   .C8 A0 C8 0BAC8 8Dc                 2   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r   r   z<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"><xi:fallback>
                  Missing</xi:fallback></xi:include>
                </html>z8<html>
                  Missing
                </html>rk   r   r   s        r   $test_fallback_when_include_not_foundz;MarkupTemplateTestCase.test_fallback_when_include_not_found~  s   "-888	#g|<<cBBE    
 #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""$   .D  A0 D  0BA$D   Dc                 6   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |gd          }|	                    d          }| 
                    d|                                                    d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r   r   r   Tr   z:<html>
                    Missing
                </html>rk   r   r   s        r   #test_fallback_when_auto_reload_truez:MarkupTemplateTestCase.test_fallback_when_auto_reload_true  s   "-888	#g|<<cBBE    
 #WI4@@@F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""$   .D A0 D 0BA&D Dc                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r~   r   r   
tmpl3.htmls  <html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl2.html">
                    <xi:fallback>
                      <xi:include href="tmpl1.html">
                        <xi:fallback>Missing</xi:fallback>
                      </xi:include>
                    </xi:fallback>
                  </xi:include>
                </html>zH<html>
                      <div>Included</div>
                </html>rk   r   r   s         r   test_include_in_fallbackz/MarkupTemplateTestCase.test_include_in_fallback  s^   "-888	#g|<<cBBE5666g|<<cBBE     #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""r   c                 2   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r   r   r   z<<html>
                      Missing
                </html>rk   r   r   s        r   test_nested_include_fallbackz3MarkupTemplateTestCase.test_nested_include_fallback  s   "-888	#g|<<cBBE     #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""r   c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                                                    d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r   r   r   r   a  <html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl2.html">
                    <xi:fallback>
                      <xi:include href="tmpl1.html" />
                    </xi:fallback>
                  </xi:include>
                </html>r   rk   r   r   s         r   test_nested_include_in_fallbackz6MarkupTemplateTestCase.test_nested_include_in_fallback  s^   "-888	#g|<<cBBE5666g|<<cBBE	     #WI..F;;|,,D  MMOO22D2AAC C C M'"""""FM'""""r   c                 6   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d|                    d                              d 	                     t          j        |           d S # t          j        |           w xY w)
Nr{   r|   r   r   a6  <html xmlns:xi="http://www.w3.org/2001/XInclude"
                      xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html"><xi:fallback>
                    <py:if test="True">tmpl1.html not found</py:if>
                  </xi:fallback></xi:include>
                </html>zG<html>
                    tmpl1.html not found
                </html>T)debugrk   r   r   s        r   $test_include_fallback_with_directivez;MarkupTemplateTestCase.test_include_fallback_with_directive  s   "-888	#g|<<cBBE     #WI..F;;|,,D  MMM55<<d<KKM M M M'"""""FM'""""r   c                 j   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |gd	          }|	                    d          }| 
                    d
t          |j                             | 
                    d|                                                    d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r~   r   r   r   z<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html" />
                </html>Fr      r   rk   )r   r   r   r   r   r   r   r   r   r'   r   lenr    r   r   r   r   r   s         r   test_include_inlinedz+MarkupTemplateTestCase.test_include_inlined  s   "-888	#g|<<cBBE5666g|<<cBBE    
 #WI5AAAF;;|,,DQDK 0 0111  MMOO22D2AAC C C M'"""""FM'""""s<   .F A0 F 0B1F 8C" F "C88BF F2c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |gd	          }|	                    d          }| 
                    d
|                                                    d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r~   r   r   r   z<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html" py:for="idx in range(3)" />
                </html>Fr   r   rk   r   r   s         r   test_include_inlined_in_loopz3MarkupTemplateTestCase.test_include_inlined_in_loop-  sc   "-888	#g|<<cBBE:;;;g|<<cBBE    
 #WI5AAAF;;|,,D  MMOO22D2AAC C C M'"""""FM'""""r   c                 v   t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |gd          }|	                    t          j                            |d                    }| 
                    d|                    d	
                              d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r~   r   z<div xmlns:xi="http://www.w3.org/2001/XInclude"                xmlns:py="http://genshi.edgewall.org/">$depth<py:with vars="depth = depth + 1"><xi:include href="tmpl1.html"            py:if="depth &lt; 3"/></py:with></div>Fr   z$<div>0<div>1<div>2</div></div></div>r   )depthrk   r   )r   r   r   r   r   s        r   test_include_inline_recursivez4MarkupTemplateTestCase.test_include_inline_recursiveG  s   "-888	#g|<<cBBE	 	 	 #WI5AAAF;;rw||G\BBCCD6A&&--t-<<> > > M'"""""FM'""""s$   .D" A0 D" 0BBD" "D8c                     d}	 t          |dd          }|                     d           d S # t          $ r}Y d }~d S d }~ww xY w)N<?python
          title = "A Genshi Template"
          ?>
          <html xmlns:py="http://genshi.edgewall.org/">
            <head>
              <title py:content="title">This is replaced.</title>
            </head>
        </html>rC   FrE   
allow_execzExpected SyntaxError)r   rN   r
   rH   s       r   test_allow_exec_falsez,MarkupTemplateTestCase.test_allow_exec_falsea  sn    	!#-24 4 4DII,-----" 	 	 	DDDDD	s   '- 
AAc                 .    d}t          |dd          }d S )Nr   rC   Tr   r   r   rI   r   s      r   test_allow_exec_truez+MarkupTemplateTestCase.test_allow_exec_trueq  s#     cKDIIIr   c                     d}t          |dd          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body/p">
            <?python title="wakka wakka wakka" ?>
            ${title}
          </py:match>
          <body><p>moot text</p></body>
        </html>rC   Tr   zW<html>
          <body>
            wakka wakka wakka
          </body>
        </html>rk   r   r   r   r   r   s      r   test_exec_in_matchz)MarkupTemplateTestCase.test_exec_in_match|  sd     cKDIII  MMOO**D*99		; 	; 	; 	; 	;r   c                     d}t          |d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body/p">
            <h1>${select('text()')}</h1>
            ${select('.')}
          </py:match>
          <body><p py:with="foo='bar'">${foo}</p></body>
        </html>rC   rD   zi<html>
          <body>
            <h1>bar</h1>
            <p>bar</p>
          </body>
        </html>rk   r   r   s      r   test_with_in_matchz)MarkupTemplateTestCase.test_with_in_match  sb     cK888 
 MMOO**D*99	; 	; 	; 	; 	;r   c                    t          j        d          }	 t          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            |d          d          }	 |                    d	           |                                 n# |                                 w xY wt          |g          }|	                    d          }| 
                    d
|                                                    d                      t          j        |           d S # t          j        |           w xY w)Nr{   r|   r~   r   zl<html xmlns:py="http://genshi.edgewall.org/" py:strip="">
   <div class="target">Some content.</div>
</html>r   z<html xmlns:py="http://genshi.edgewall.org/"
    xmlns:xi="http://www.w3.org/2001/XInclude">
  <body>
    <h1>Some full html document that includes file1.html</h1>
    <xi:include href="tmpl1.html" />
  </body>
</html>r   a  <html xmlns:py="http://genshi.edgewall.org/"
    xmlns:xi="http://www.w3.org/2001/XInclude" py:strip="">
  <div py:match="div[@class='target']" py:attrs="select('@*')">
    Some added stuff.
    ${select('*|text()')}
  </div>
  <xi:include href="tmpl2.html" />
</html>
z
  <html>
  <body>
    <h1>Some full html document that includes file1.html</h1>
   <div class="target">
    Some added stuff.
    Some content.
  </div>
  </body>
</html>
rk   r   )r   r   r   r   file3r   r   s          r   test_nested_include_matchesz2MarkupTemplateTestCase.test_nested_include_matches  s   "-8881	#g|<<cBBE     g|<<cBBE	     g|<<cBBE     #WI..F;;|,,D 
 
]]__T**
, 
, 
, M'"""""FM'""""sT   .G$ A0 G$ 0B1G$ 8C" G$ "C881G$ *E ?G$ E**A$G$ $G:c                     d}t          |d          }|                     d|                                                    d                      d S )Nak  <html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body" once="true" buffer="false">
            <body>
              ${select('*|text')}
              And some other stuff...
            </body>
          </py:match>
          <body>
            <span py:match="span">Foo</span>
            <span>Bar</span>
          </body>
        </html>rC   rD   z<html>
            <body>
              <span>Foo</span>
              And some other stuff...
            </body>
        </html>rk   r   r   s      r   %test_nested_matches_without_bufferingz<MarkupTemplateTestCase.test_nested_matches_without_buffering  sb     cK888 
 MMOO**D*99	; 	; 	; 	; 	;r   c                     d}t          |d          }|                     d|                                                    d                      d S )Na  <html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body" buffer="false">
            <body>
              This replaces the other text.
            </body>
          </py:match>
          <body>
            This gets replaced.
          </body>
        </html>rC   rD   zi<html>
            <body>
              This replaces the other text.
            </body>
        </html>rk   r   r   s      r   test_match_without_selectz0MarkupTemplateTestCase.test_match_without_select  sb    	 cK888  MMOO**D*99		; 	; 	; 	; 	;r   c                     d}t          |d          }|                     d|                                                    d                      d S )Nal  <rhyme xmlns:py="http://genshi.edgewall.org/">
          <py:match path="*[@type]">
            ${select('.')}
          </py:match>

          <lines>
            <first type="one">fish</first>
            <second type="two">fish</second>
            <third type="red">fish</third>
            <fourth type="blue">fish</fourth>
          </lines>
        </rhyme>rC   rD   z<rhyme>
          <lines>
            <first type="one">fish</first>
            <second type="two">fish</second>
            <third type="red">fish</third>
            <fourth type="blue">fish</fourth>
          </lines>
        </rhyme>rk   r   r   s      r   test_match_tail_handlingz/MarkupTemplateTestCase.test_match_tail_handling  sb     cK888  ]]__++T+::	< 	< 	< 	< 	<r   c                     t          d          }t          d           }|                    t          j        |           |                     dt          |                                                     d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
            <py:for each="i in range(2)"><py:for each="j in range(1)">
                <span py:content="i + j"></span>
            </py:for></py:for>
        </div>c                     | S N )ss    r   <lambda>zSMarkupTemplateTestCase.test_directive_single_line_with_translator.<locals>.<lambda>  s    ! r   zR<div>
                <span>0</span>
                <span>1</span>
        </div>)r   r   add_directives	NAMESPACEr   r   r   )r   r   
translators      r   *test_directive_single_line_with_translatorzAMarkupTemplateTestCase.test_directive_single_line_with_translator  s|       
  ,,
J0*===  t}}''	) 	) 	) 	) 	)r   N)6__name__
__module____qualname____doc__r   r!   r*   r.   r3   r5   r7   r:   r=   rA   rK   rO   rR   rV   r[   r^   r`   rb   rd   rf   rh   ro   rq   rs   ru   rw   ry   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-       //L L L
L L L
M M ML L LL L LL L LC C CQ Q QB B BI I I* * ** * *	* 	* 	** * *
C 
C 
C
6 
6 
6	6 	6 	66 6 6) ) )) ) )) ) )/ / // / /	 	 	) ) )) ) )* * * # # #4# # #4# # #:# # #4# # #"# # #(# # #(# # #># # #2# # #:# # #,# # #8# # #4# # #4   	J 	J 	J; ; ;; ; ; 4# 4# 4#l; ; ;*; ; ;&< < <0) ) ) ) )r   r   c                      t          j                    } |                     t          j        t
          j                             |                     t           j                            t                               | S r   )
unittest	TestSuiteaddTestdoctestDocTestSuiter   r   defaultTestLoaderloadTestsFromTestCaser   )suites    r   r   r     sY      E	MM'&~'@AABBB	MM(,BBCYZZ[[[Lr   __main__r   )defaultTest)r   r   r$   r   r   r   genshi.compatr   r   r   genshi.corer   genshi.filters.i18nr   genshi.inputr   genshi.template.baser	   r
   genshi.template.loaderr   r   genshi.template.markupr   TestCaser   r   r   mainr   r   r   <module>r      sH    				     6 6 6 6 6 6 6 6 6 6       * * * * * *       G G G G G G G G C C C C C C C C 1 1 1 1 1 1~) ~) ~) ~) ~)X. ~) ~) ~)B   zHMg&&&&&& r   