
    w:i                        d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZ  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 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edk    r ej        d           dS dS )    N)
IS_PYTHON2)
directivesMarkupTemplateTextTemplateTemplateRuntimeErrorTemplateSyntaxErrorc                   $    e Zd ZdZd Zd Zd ZdS )AttrsDirectiveTestCasez,Tests for the `py:attrs` template directive.c                     t          d          }ddiddig}|                     d|                    |                              d                     dS )	zM
        Verify that the directive has access to the loop variables.
        zt<doc xmlns:py="http://genshi.edgewall.org/">
          <elem py:for="item in items" py:attrs="item"/>
        </doc>id      z;<doc>
          <elem id="1"/><elem id="2"/>
        </doc>itemsNencodingr   assertEqualgeneraterender)selftmplr   s      ]/var/www/html/trac/venv/lib/python3.11/site-packages/genshi/template/tests/test_directives.pytest_combined_with_loopz.AttrsDirectiveTestCase.test_combined_with_loop   sz         T1I& ==u=--44d4CC	E 	E 	E 	E 	E    c                     t          d          }|                     d|                                                    d                     dS )}
        Verify that an attribute value that evaluates to `None` removes an
        existing attribute of that name.
        zu<doc xmlns:py="http://genshi.edgewall.org/">
          <elem class="foo" py:attrs="{'class': 'bar'}"/>
        </doc>z2<doc>
          <elem class="bar"/>
        </doc>Nr   r   r   r   s     r   test_update_existing_attrz0AttrsDirectiveTestCase.test_update_existing_attr'   ]    
     	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )r   zt<doc xmlns:py="http://genshi.edgewall.org/">
          <elem class="foo" py:attrs="{'class': None}"/>
        </doc>z&<doc>
          <elem/>
        </doc>Nr   r   r   s     r   test_remove_existing_attrz0AttrsDirectiveTestCase.test_remove_existing_attr3   r    r   N)__name__
__module____qualname____doc__r   r   r"    r   r   r
   r
      sJ        66
E 
E 
E
: 
: 
:
: 
: 
: 
: 
: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S )ChooseDirectiveTestCasezoTests for the `py:choose` template directive and the complementary
    directives `py:when` and `py:otherwise`.c                     t          d          }|                     d|                                                    d                     dS )zd
        Verify that, if multiple `py:when` bodies match, only the first is
        output.
        z<div xmlns:py="http://genshi.edgewall.org/" py:choose="">
          <span py:when="1 == 1">1</span>
          <span py:when="2 == 2">2</span>
          <span py:when="3 == 3">3</span>
        </div>z-<div>
          <span>1</span>
        </div>Nr   r   r   s     r   test_multiple_true_whensz0ChooseDirectiveTestCase.test_multiple_true_whensD   ]    
    
 	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/" py:choose="">
          <span py:when="False">hidden</span>
          <span py:otherwise="">hello</span>
        </div>z1<div>
          <span>hello</span>
        </div>r   r   r   s     r   test_otherwisez&ChooseDirectiveTestCase.test_otherwiseR   [        	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )z?
        Verify that `py:choose` blocks can be nested:
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="1">
            <div py:when="1" py:choose="3">
              <span py:when="2">2</span>
              <span py:when="3">3</span>
            </div>
          </div>
        </doc>zw<doc>
          <div>
            <div>
              <span>3</span>
            </div>
          </div>
        </doc>Nr   r   r   s     r   test_nestingz$ChooseDirectiveTestCase.test_nesting[   _         	  ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )z.
        Verify more complex nesting.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="1">
            <div py:when="1" py:choose="">
              <span py:when="2">OK</span>
              <span py:when="1">FAIL</span>
            </div>
          </div>
        </doc>x<doc>
          <div>
            <div>
              <span>OK</span>
            </div>
          </div>
        </doc>Nr   r   r   s     r   test_complex_nestingz,ChooseDirectiveTestCase.test_complex_nestingo   r2   r   c                     t          d          }|                     d|                                                    d                     dS )z>
        Verify more complex nesting using otherwise.
        a  <doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="1">
            <div py:when="1" py:choose="2">
              <span py:when="1">FAIL</span>
              <span py:otherwise="">OK</span>
            </div>
          </div>
        </doc>r4   Nr   r   r   s     r   test_complex_nesting_otherwisez6ChooseDirectiveTestCase.test_complex_nesting_otherwise   r2   r   c                     t          d          }|                     d|                                                    d                     dS )zs
        Verify that a when directive with a strip directive actually strips of
        the outer element.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="" py:strip="">
            <span py:otherwise="">foo</span>
          </div>
        </doc>z1<doc>
            <span>foo</span>
        </doc>Nr   r   r   s     r   test_when_with_stripz,ChooseDirectiveTestCase.test_when_with_strip   r,   r   c                     t          d          }|                     t          t          |                                           dS )zq
        Verify that a `when` directive outside of a `choose` directive is
        reported as an error.
        zZ<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:when="xy" />
        </doc>Nr   assertRaisesr   strr   r   s     r   test_when_outside_choosez0ChooseDirectiveTestCase.test_when_outside_choose   A    
     	.T]]__EEEEEr   c                     t          d          }|                     t          t          |                                           dS )zw
        Verify that an `otherwise` directive outside of a `choose` directive is
        reported as an error.
        z]<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:otherwise="" />
        </doc>Nr;   r   s     r   test_otherwise_outside_choosez5ChooseDirectiveTestCase.test_otherwise_outside_choose   r?   r   c                     t          d          }|                     t          t          |                                           dS )zw
        Verify that an `when` directive that doesn't have a `test` attribute
        is reported as an error.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="" py:strip="">
            <py:when>foo</py:when>
          </div>
        </doc>Nr;   r   s     r   test_when_without_testz.ChooseDirectiveTestCase.test_when_without_test   sA    
    
 	.T]]__EEEEEr   c                     t          d          }|                     d|                    d                              d                     dS )z
        Verify that an `when` directive that doesn't have a `test` attribute
        works as expected as long as the parent `choose` directive has a test
        expression.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="foo" py:strip="">
            <py:when>foo</py:when>
          </div>
        </doc>$<doc>
            foo
        </doc>YeahfooNr   r   r   s     r   ,test_when_without_test_but_with_choose_valuezDChooseDirectiveTestCase.test_when_without_test_but_with_choose_value   sh        
 	 ==V=,,33T3BB	D 	D 	D 	D 	Dr   c                     t          d          }|                     d|                                                    d                     dS )zf
        Verify that an `otherwise` directive can be used without a `test`
        attribute.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:choose="" py:strip="">
            <py:otherwise>foo</py:otherwise>
          </div>
        </doc>rE   Nr   r   r   s     r   test_otherwise_without_testz3ChooseDirectiveTestCase.test_otherwise_without_test   r,   r   c                     t          d          }|                     d|                                                    d                     dS )K
        Verify that the directive can also be used as an element.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:choose>
            <py:when test="1 == 1">1</py:when>
            <py:when test="2 == 2">2</py:when>
            <py:when test="3 == 3">3</py:when>
          </py:choose>
        </doc>z"<doc>
            1
        </doc>Nr   r   r   s     r   test_as_elementz'ChooseDirectiveTestCase.test_as_element   s]         	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )Q
        Verify that the directive works as expected in a text template.
        z#choose
          #when 1 == 1
            1
          #end
          #when 2 == 2
            2
          #end
          #when 3 == 3
            3
          #end
        #endz            1
Nr   r   r   r   r   r   s     r   test_in_text_templatez-ChooseDirectiveTestCase.test_in_text_template   s`      
 
 
 	.///>>	@ 	@ 	@ 	@ 	@r   N)r#   r$   r%   r&   r+   r.   r1   r5   r7   r9   r>   rA   rC   rI   rK   rN   rR   r'   r   r   r)   r)   @   s        0 0: : :: : :: : :(: : :(: : :(: : :F F FF F F
F 
F 
FD D D: : :: : :@ @ @ @ @r   r)   c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )DefDirectiveTestCasez*Tests for the `py:def` template directive.c                     t          d          }|                     d|                                                    d                     dS )z|
        Verify that a named template function with a strip directive actually
        strips of the outer element.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:def="echo(what)" py:strip="">
            <b>${what}</b>
          </div>
          ${echo('foo')}
        </doc>+<doc>
            <b>foo</b>
        </doc>Nr   r   r   s     r   test_function_with_stripz-DefDirectiveTestCase.test_function_with_strip  ]    
     	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <p py:def="echo(greeting, name='world')" class="message">
            ${greeting}, ${name}!
          </p>
          <div py:replace="echo('hello')"></div>
        </div>z[<div>
          <p class="message">
            hello, world!
          </p>
        </div>r   r   r   s     r   test_exec_in_replacez)DefDirectiveTestCase.test_exec_in_replace  ]        	  ==??))4)88		: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )rM   z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:def function="echo(what)">
            <b>${what}</b>
          </py:def>
          ${echo('foo')}
        </doc>rV   Nr   r   r   s     r   rN   z$DefDirectiveTestCase.test_as_element#  ]         	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                    d                              d                     dS )z
        Verify that a template function defined inside a conditional block can
        be called from outside that block.
        a*  <doc xmlns:py="http://genshi.edgewall.org/">
          <py:if test="semantic">
            <strong py:def="echo(what)">${what}</strong>
          </py:if>
          <py:if test="not semantic">
            <b py:def="echo(what)">${what}</b>
          </py:if>
          ${echo('foo')}
        </doc>z3<doc>
          <strong>foo</strong>
        </doc>T)semanticNr   r   r   s     r   test_nested_defsz%DefDirectiveTestCase.test_nested_defs1  sh    
     	 ==$=//666EE	G 	G 	G 	G 	Gr   c                     t          d          }|                     d|                                                    d                     dS )zN
        Verify that keyword arguments work with `py:def` directives.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <b py:def="echo(what, bold=False)" py:strip="not bold">${what}</b>
          ${echo('foo')}
        </doc>z"<doc>
          foo
        </doc>Nr   r   r   s     r   test_function_with_default_argz3DefDirectiveTestCase.test_function_with_default_argC  s]         	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <py:def function="echo(what)">${what or 'something'}</py:def>
          <p class="${echo('foo')}">bar</p>
        </doc>z5<doc>
          <p class="foo">bar</p>
        </doc>r   r   r   s     r   test_invocation_in_attributez1DefDirectiveTestCase.test_invocation_in_attributeO  r/   r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <py:def function="echo()">${None}</py:def>
          <p class="${echo()}">bar</p>
        </doc>z)<doc>
          <p>bar</p>
        </doc>r   r   r   s     r   !test_invocation_in_attribute_nonez6DefDirectiveTestCase.test_invocation_in_attribute_noneX  r/   r   c                     d }t          d          }|                     t          t          |                    |                     d S )Nc                      t           N)	TypeErrorr'   r   r   badfunczEDefDirectiveTestCase.test_function_raising_typeerror.<locals>.badfuncb  s    Or   z<html xmlns:py="http://genshi.edgewall.org/">
          <div py:def="dobadfunc()">
            ${badfunc()}
          </div>
          <div py:content="dobadfunc()"/>
        </html>)rk   )r   r<   rj   listr   )r   rk   r   s      r   test_function_raising_typeerrorz4DefDirectiveTestCase.test_function_raising_typeerrora  sS    	 	 	    	)T4===+I+IJJJJJr   c                     t          d          }|                     d|                                                    d                      d S )Na  <doc xmlns:py="http://genshi.edgewall.org/">
          <head py:match="head">${select('*')}</head>
          <head>
            <py:def function="maketitle(test)"><b py:replace="test" /></py:def>
            <title>${maketitle(True)}</title>
          </head>
        </doc>?<doc>
          <head><title>True</title></head>
        </doc>r   r   r   s     r   test_def_in_matchedz(DefDirectiveTestCase.test_def_in_matchedl  s[        	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )rP   z
          #def echo(greeting, name='world')
            ${greeting}, ${name}!
          #end
          ${echo('Hi', name='you')}
        z)
                      Hi, you!

        Nr   rQ   r   s     r   rR   z*DefDirectiveTestCase.test_in_text_templatex  s_         	  ]]__##T#22	4 	4 	4 	4 	4r   c                     t          d          }|                     d|                                                    d                     dS )zi
        Verify that a named template function using "star arguments" works as
        expected.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:def="f(*args, **kwargs)">
            ${repr(args)}
            ${repr(sorted(kwargs.items()))}
          </div>
          ${f(1, 2, a=3, b=4)}
        </doc>zi<doc>
          <div>
            [1, 2]
            [('a', 3), ('b', 4)]
          </div>
        </doc>Nr   r   r   s     r   test_function_with_star_argsz1DefDirectiveTestCase.test_function_with_star_args  s_    
     	 
 ==??))4)88	: 	: 	: 	: 	:r   N)r#   r$   r%   r&   rW   rZ   rN   r`   rb   rd   rf   rm   rp   rR   rs   r'   r   r   rT   rT     s        44: : :: : :: : :G G G$
: 
: 
:: : :: : :	K 	K 	K
: 
: 
:4 4 4: : : : :r   rT   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	ForDirectiveTestCasez*Tests for the `py:for` template directive.c           	          t          d          }|                     d|                    t          dd                                        d                     dS )zk
        Verify that the combining the `py:for` directive with `py:strip` works
        correctly.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:for="item in items" py:strip="">
            <b>${item}</b>
          </div>
        </doc>}<doc>
            <b>1</b>
            <b>2</b>
            <b>3</b>
            <b>4</b>
            <b>5</b>
        </doc>r      r   Nr   r   r   r   ranger   r   s     r   test_loop_with_stripz)ForDirectiveTestCase.test_loop_with_strip  sr    
    
 	  ==uQ{{=33::D:II	K 	K 	K 	K 	Kr   c           	          t          d          }|                     d|                    t          dd                                        d                     dS )rM   z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="item in items">
            <b>${item}</b>
          </py:for>
        </doc>rw   r   rx   r   Nr   ry   r   s     r   rN   z$ForDirectiveTestCase.test_as_element  sr        
 	  ==uQ{{=33::D:II	K 	K 	K 	K 	Kr   c                     t          d          }|                     d|                    d                              d                     dS )zC
        Verify that assignment to tuples works correctly.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="k, v in items">
            <p>key=$k, value=$v</p>
          </py:for>
        </doc>zX<doc>
            <p>key=a, value=1</p>
            <p>key=b, value=2</p>
        </doc>)ar   br   r   Nr   r   r   s     r   test_multi_assignmentz*ForDirectiveTestCase.test_multi_assignment  sd        
 	  ==';=<<--		/ 	/ 	/ 	/ 	/r   c           	          t          d          }|                     d|                    t          ddg                                        d                     dS )J
        Verify that assignment to nested tuples works correctly.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="idx, (k, v) in items">
            <p>$idx: key=$k, value=$v</p>
          </py:for>
        </doc>z^<doc>
            <p>0: key=a, value=1</p>
            <p>1: key=b, value=2</p>
        </doc>r~   r   r   Nr   )r   r   r   	enumerater   r   s     r   test_nested_assignmentz+ForDirectiveTestCase.test_nested_assignment  sp        
 	  ==y(H1E'F'F=GG--		/ 	/ 	/ 	/ 	/r   c                    t          dd          }	 t          |                    d                     |                     d           dS # t          $ r}t          |          dk    st          |          dk    sJ t          j                    \  }}}|j        }g }|j        r#|j        }|	                    |           |j        #t          rd	nd
}|                     d|z  |d         j        j        j                   |                     d|d         j        j        j                   |                     d|d         j                   Y d}~dS d}~ww xY w)r   z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="item in foo">
            $item
          </py:for>
        </doc>	test.htmlfilename   rG   zExpected TemplateRuntimeErrorziteration over non-sequencez'int' object is not iterablezu'iter(foo)'z'iter(foo)'z<Expression %s>r   N)r   rl   r   failrj   r=   sysexc_infotb_nextappendr   r   tb_framef_codeco_nameco_filename	tb_lineno)	r   r   eexc_type	exc_valueexc_tracebackframeframesexpected_iter_strs	            r   test_not_iterablez&ForDirectiveTestCase.test_not_iterable  s      (	) ) )
	62&&'''II566666 	6 	6 	6FF;;;FF<<<<<14.Hi!)EF- %e$$$ - % 3= O-.1BB#BZ07?A A A[#BZ07CE E EQr
 4555555555	6s   8A EC7EEc                 P   	 t          dd                                           |                     d           dS # t          $ r_}|                     d|j                   t          j        dd         dk    r!|                     d|j                   Y d}~dS Y d}~dS d}~ww xY w)z9
        Verify an empty 'for' value is an error
        z<doc xmlns:py="http://genshi.edgewall.org/">
              <py:for each="">
                empty
              </py:for>
            </doc>r   r   ExpectedTemplateSyntaxErrorNr   )r      )	r   r   r   r   r   r   r   version_infolinenor   r   s     r   test_for_with_empty_valuez.ForDirectiveTestCase.test_for_with_empty_value  s    
	.  !,	- - - .6XZZZII344444" 	. 	. 	.[!*555#e++  AH--------- ,+++++	.s   8< 
B%AB  B%N)
r#   r$   r%   r&   r{   rN   r   r   r   r   r'   r   r   ru   ru     sz        44K K K$K K K"/ / // / /6 6 68. . . . .r   ru   c                       e Zd ZdZd Zd ZdS )IfDirectiveTestCasez)Tests for the `py:if` template directive.c                     t          d          }|                     d|                    dd                              d                     dS )zj
        Verify that the combining the `py:if` directive with `py:strip` works
        correctly.
        zk<doc xmlns:py="http://genshi.edgewall.org/">
          <b py:if="foo" py:strip="">${bar}</b>
        </doc>$<doc>
          Hello
        </doc>THellorH   barNr   r   r   s     r   r{   z(IfDirectiveTestCase.test_loop_with_strip  sj    
     	 ==Tw=77>>>MM	O 	O 	O 	O 	Or   c                     t          d          }|                     d|                    dd                              d                     dS )rM   zf<doc xmlns:py="http://genshi.edgewall.org/">
          <py:if test="foo">${bar}</py:if>
        </doc>r   Tr   r   Nr   r   r   s     r   rN   z#IfDirectiveTestCase.test_as_element  sj         	 ==Tw=77>>>MM	O 	O 	O 	O 	Or   N)r#   r$   r%   r&   r{   rN   r'   r   r   r   r     s@        33
O 
O 
O	O 	O 	O 	O 	O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S )MatchDirectiveTestCasez,Tests for the `py:match` template directive.c                     t          d          }|                     d|                                                    d                     dS )
        Verify that a match template can produce the same kind of element that
        it matched without entering an infinite recursion.
        z<doc xmlns:py="http://genshi.edgewall.org/">
          <elem py:match="elem" py:strip="">
            <div class="elem">${select('text()')}</div>
          </elem>
          <elem>Hey Joe</elem>
        </doc>@<doc>
            <div class="elem">Hey Joe</div>
        </doc>Nr   r   r   s     r   test_with_stripz&MatchDirectiveTestCase.test_with_strip*  rX   r   c                     t          d          }|                     d|                                                    d                     dS )r   z<doc xmlns:py="http://genshi.edgewall.org/">
          <elem py:match="elem">
            <div class="elem">${select('text()')}</div>
          </elem>
          <elem>Hey Joe</elem>
        </doc>zc<doc>
          <elem>
            <div class="elem">Hey Joe</div>
          </elem>
        </doc>Nr   r   r   s     r   test_without_stripz)MatchDirectiveTestCase.test_without_strip9  s_    
     	  ==??))4)88		: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )rM   z<doc xmlns:py="http://genshi.edgewall.org/">
          <py:match path="elem">
            <div class="elem">${select('text()')}</div>
          </py:match>
          <elem>Hey Joe</elem>
        </doc>r   Nr   r   r   s     r   rN   z&MatchDirectiveTestCase.test_as_elementJ  r]   r   c                     t          d          }|                     d|                                                    d                     dS )z
        Match directives are applied recursively, meaning that they are also
        applied to any content they may have produced themselves:
        a#  <doc xmlns:py="http://genshi.edgewall.org/">
          <elem py:match="elem">
            <div class="elem">
              ${select('*')}
            </div>
          </elem>
          <elem>
            <subelem>
              <elem/>
            </subelem>
          </elem>
        </doc>z<doc>
          <elem>
            <div class="elem">
              <subelem>
              <elem>
            <div class="elem">
            </div>
          </elem>
            </subelem>
            </div>
          </elem>
        </doc>Nr   r   r   s     r   test_recursive_match_1z-MatchDirectiveTestCase.test_recursive_match_1X  s_    
     	  ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )z
        When two or more match templates match the same element and also
        themselves output the element they match, avoiding recursion is even
        more complex, but should work.
        aS  <html xmlns:py="http://genshi.edgewall.org/">
          <body py:match="body">
            <div id="header"/>
            ${select('*')}
          </body>
          <body py:match="body">
            ${select('*')}
            <div id="footer"/>
          </body>
          <body>
            <h1>Foo</h1>
          </body>
        </html>z<html>
          <body>
            <div id="header"/><h1>Foo</h1>
            <div id="footer"/>
          </body>
        </html>Nr   r   r   s     r   test_recursive_match_2z-MatchDirectiveTestCase.test_recursive_match_2v  s_         	 
 MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                      d S )Na1  <test xmlns:py="http://genshi.edgewall.org/">
          <py:match path="b[@type='bullet']">
            <bullet>${select('*|text()')}</bullet>
          </py:match>
          <py:match path="group[@type='bullet']">
            <ul>${select('*')}</ul>
          </py:match>
          <py:match path="b">
            <generic>${select('*|text()')}</generic>
          </py:match>

          <b>
            <group type="bullet">
              <b type="bullet">1</b>
              <b type="bullet">2</b>
            </group>
          </b>
        </test>
        z{<test>
            <generic>
            <ul><bullet>1</bullet><bullet>2</bullet></ul>
          </generic>
        </test>r   r   r   s     r   test_recursive_match_3z-MatchDirectiveTestCase.test_recursive_match_3  s]       & 	  MMOO**D*99		; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                     dS )z:
        See http://genshi.edgewall.org/ticket/77
        aM  <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:py="http://genshi.edgewall.org/">
          <body py:match="body" py:content="select('*')" />
          <h1 py:match="h1">
            ${select('text()')}
            Goodbye!
          </h1>
          <body>
            <h1>Hello!</h1>
          </body>
        </html>z<html xmlns="http://www.w3.org/1999/xhtml">
          <body><h1>
            Hello!
            Goodbye!
          </h1></body>
        </html>Nr   r   r   s     r   test_not_match_selfz*MatchDirectiveTestCase.test_not_match_self  s_      
 
 
 	 
 MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                     dS )zD
        See http://genshi.edgewall.org/ticket/77#comment:1
        av  <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:py="http://genshi.edgewall.org/">
          <body py:match="body" py:content="select('*')" />
          <h1 py:match="h1">
            <text>
              ${select('text()')}
            </text>
            Goodbye!
          </h1>
          <body>
            <h1>Hello!</h1>
          </body>
        </html>z<html xmlns="http://www.w3.org/1999/xhtml">
          <body><h1>
            <text>
              Hello!
            </text>
            Goodbye!
          </h1></body>
        </html>Nr   r   r   s     r   test_select_text_in_elementz2MatchDirectiveTestCase.test_select_text_in_element  s_         	  MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:match="elem" py:attrs="select('@*')">
            ${select('text()')}
          </div>
          <elem id="joe">Hey Joe</elem>
        </doc>zR<doc>
          <div id="joe">
            Hey Joe
          </div>
        </doc>r   r   r   s     r   test_select_all_attrsz,MatchDirectiveTestCase.test_select_all_attrs  r[   r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:match="elem" py:attrs="select('@*')">
            ${select('text()')}
          </div>
          <elem>Hey Joe</elem>
        </doc>zI<doc>
          <div>
            Hey Joe
          </div>
        </doc>r   r   r   s     r   test_select_all_attrs_emptyz2MatchDirectiveTestCase.test_select_all_attrs_empty  r[   r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <div py:match="elem">
            Hey ${select('text()')} ${select('@*')}
          </div>
          <elem title="Cool">Joe</elem>
        </doc>zN<doc>
          <div>
            Hey Joe Cool
          </div>
        </doc>r   r   r   s     r   test_select_all_attrs_in_bodyz4MatchDirectiveTestCase.test_select_all_attrs_in_body  r[   r   c                     t          d          }|                     d|                                                    d                      d S )Nz<doc xmlns:py="http://genshi.edgewall.org/">
          <py:def function="maketitle(test)"><b py:replace="test" /></py:def>
          <head py:match="head">${select('*')}</head>
          <head><title>${maketitle(True)}</title></head>
        </doc>ro   r   r   r   s     r   test_def_in_matchz(MatchDirectiveTestCase.test_def_in_match  s[       
 	 ==??))4)88	: 	: 	: 	: 	:r   c                    t          d          }|                     d|                    d                              d                      |                     d|                    d                              d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <span py:match="*[name()=$tagname]">
            Hello ${select('@name')}
          </span>
          <greeting name="Dude"/>
        </div>zN<div>
          <span>
            Hello Dude
          </span>
        </div>greeting)tagnamer   z6<div>
          <greeting name="Dude"/>
        </div>sayhellor   r   s     r   test_match_with_xpath_variablez5MatchDirectiveTestCase.test_match_with_xpath_variable  s        	  ===44;;T;JJ		L 	L 	L
 	 ===44;;T;JJ	L 	L 	L 	L 	Lr   c                     t          d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <div py:match="foo">I said <q py:content="select('text()')">something</q>.</div>
          <foo>bar</foo>
        </html>z><html>
          <div>I said <q>bar</q>.</div>
        </html>r   r   r   s     r   test_content_directive_in_matchz6MatchDirectiveTestCase.test_content_directive_in_match  s[        	 MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                      d S )Na[  <html xmlns:py="http://genshi.edgewall.org/">
          <body py:match="body">${select('*')}</body>
          <head py:match="head">${select('title')}</head>
          <body py:match="body">${select('*')}<hr /></body>
          <head><title>Welcome to Markup</title></head>
          <body><h2>Are you ready to mark up?</h2></body>
        </html>z<html>
          <head><title>Welcome to Markup</title></head>
          <body><h2>Are you ready to mark up?</h2><hr/></body>
        </html>r   r   r   s     r   test_cascaded_matchesz,MatchDirectiveTestCase.test_cascaded_matches$  s]        	  MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }d t          d          D             }t          d t          d          D                       }|                     d|                    ||                              d                      d S )Na_  <html xmlns:py="http://genshi.edgewall.org/">
          <input py:match="form//input" py:attrs="select('@*')"
                 value="${values[str(select('@name'))]}" />
          <form><p py:for="field in fields">
            <label>${field.capitalize()}</label>
            <input type="text" name="${field}" />
          </p></form>
        </html>c                     g | ]}d |z  S zhello_%sr'   .0is     r   
<listcomp>z@MatchDirectiveTestCase.test_multiple_matches.<locals>.<listcomp>:  s    333Q*q.333r      c                     g | ]	}d |z  |f
S r   r'   r   s     r   r   z@MatchDirectiveTestCase.test_multiple_matches.<locals>.<listcomp>;  s!    ===q
Q*===r   aY  <html>
          <form><p>
            <label>Hello_0</label>
            <input value="0" type="text" name="hello_0"/>
          </p><p>
            <label>Hello_1</label>
            <input value="1" type="text" name="hello_1"/>
          </p><p>
            <label>Hello_2</label>
            <input value="2" type="text" name="hello_2"/>
          </p><p>
            <label>Hello_3</label>
            <input value="3" type="text" name="hello_3"/>
          </p><p>
            <label>Hello_4</label>
            <input value="4" type="text" name="hello_4"/>
          </p></form>
        </html>)fieldsvaluesr   )r   rz   dictr   r   r   )r   r   r   r   s       r   test_multiple_matchesz,MatchDirectiveTestCase.test_multiple_matches1  s        43%((333==E!HH===>> " MMM??..%	0 	0 	0 	0 	0r   c                     t          d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/"
                                       xmlns:x="http://www.example.org/">
          <div py:match="x:foo">Foo</div>
          <foo xmlns="http://www.example.org/"/>
        </html>zQ<html xmlns:x="http://www.example.org/">
          <div>Foo</div>
        </html>r   r   r   s     r   test_namespace_contextz-MatchDirectiveTestCase.test_namespace_contextP  s[        	 MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <p py:match="body/p[1]" class="first">${select('*|text()')}</p>
          <body>
            <p>Foo</p>
            <p>Bar</p>
          </body>
        </html>zu<html>
          <body>
            <p class="first">Foo</p>
            <p>Bar</p>
          </body>
        </html>r   r   r   s     r   "test_match_with_position_predicatez9MatchDirectiveTestCase.test_match_with_position_predicate\  ]        	 
 MMOO**D*99	; 	; 	; 	; 	;r   c                     t          d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <p py:match="body//p" class="para">${select('*|text()')}</p>
          <body>
            <p>Foo</p>
            <div><p>Bar</p></div>
          </body>
        </html>z<html>
          <body>
            <p class="para">Foo</p>
            <div><p class="para">Bar</p></div>
          </body>
        </html>r   r   r   s     r   test_match_with_closurez.MatchDirectiveTestCase.test_match_with_closurek  r   r   c                     t          d          }|                     d|                                                    d                      d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <p py:match="body/p" class="para">${select('*|text()')}</p>
          <body>
            <p>Foo</p>
            <div><p>Bar</p></div>
          </body>
        </html>z<html>
          <body>
            <p class="para">Foo</p>
            <div><p>Bar</p></div>
          </body>
        </html>r   r   r   s     r   test_match_without_closurez1MatchDirectiveTestCase.test_match_without_closurez  r   r   c                     t          d          }|                     d|                                                    d                      d S )NaM  <html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body" once="true"><body>
            <div id="wrap">
              ${select("*")}
            </div>
          </body></py:match>
          <body>
            <p>Foo</p>
          </body>
          <body>
            <p>Bar</p>
          </body>
        </html>z<html>
          <body>
            <div id="wrap">
              <p>Foo</p>
            </div>
          </body>
          <body>
            <p>Bar</p>
          </body>
        </html>r   r   r   s     r   test_match_with_once_attributez5MatchDirectiveTestCase.test_match_with_once_attribute  s]        	 	 MMOO**D*99		; 		; 		; 		; 		;r   c                     t          d          }|                     d|                                                    d                      d S )NaF  <doc xmlns:py="http://genshi.edgewall.org/">
          <py:match path="elem" recursive="false"><elem>
            <div class="elem">
              ${select('*')}
            </div>
          </elem></py:match>
          <elem>
            <subelem>
              <elem/>
            </subelem>
          </elem>
        </doc>z<doc>
          <elem>
            <div class="elem">
              <subelem>
              <elem/>
            </subelem>
            </div>
          </elem>
        </doc>r   r   r   s     r   #test_match_with_recursive_attributez:MatchDirectiveTestCase.test_match_with_recursive_attribute  s]        	  ==??))4)88	: 	: 	: 	: 	:r   c                    t          d          }|                                                    dd          }t          j        d|          }|                     d |           |                     dt          |                     d S )Na6  <doc xmlns:py="http://genshi.edgewall.org/">
          <div py:match="div[@id='content']" py:attrs="select('@*')" once="true">
            <ul id="tabbed_pane" />
            ${select('*')}
          </div>

          <body py:match="body" once="true" buffer="false">
            ${select('*|text()')}
          </body>
          <body py:match="body" once="true" buffer="false">
              ${select('*|text()')}
          </body>

          <body>
            <div id="content">
              <h1>Ticket X</h1>
            </div>
          </body>
        </doc>xhtml)doctypetabbed_paner   )r   r   r   refindallassertNotEqualr   len)r   r   outputmatchess       r   -test_triple_match_produces_no_duplicate_itemszDMatchDirectiveTestCase.test_triple_match_produces_no_duplicate_items  s       & '''AA*]F33D'***CLL)))))r   c                     t          d          }|                     d|                                                                           d S )Nz<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body[@id='content']/h2" />
          <head py:match="head" />
          <head py:match="head" />
          <head />
          <body />
        </html>z:<html>
          <head/>
          <body/>
        </html>r   r   s     r   test_match_multiple_times1z1MatchDirectiveTestCase.test_match_multiple_times1  sX        	  MMOO**,,	. 	. 	. 	. 	.r   c                     t          d          }|                     d|                                                                           d S )Na  <html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body/div[@id='properties']" />
          <head py:match="head" />
          <head py:match="head" />
          <head/>
          <body>
            <div id="properties">Foo</div>
          </body>
        </html>zK<html>
          <head/>
          <body>
          </body>
        </html>r   r   s     r   test_match_multiple_times2z1MatchDirectiveTestCase.test_match_multiple_times2  sX        	  MMOO**,,		. 	. 	. 	. 	.r   c                     t          d          }|                     d|                                                                           d S )Na  <?xml version="1.0"?>
          <root xmlns:py="http://genshi.edgewall.org/">
            <py:match path="foo/bar">
              <zzzzz/>
            </py:match>
            <foo>
              <bar/>
              <bar/>
            </foo>
            <bar/>
          </root>z<?xml version="1.0"?>
<root>
            <foo>
              <zzzzz/>
              <zzzzz/>
            </foo>
            <bar/>
          </root>r   r   s     r   test_match_multiple_times3z1MatchDirectiveTestCase.test_match_multiple_times3  sX     
 
 
 	  mmoo,,..	0 	0 	0 	0 	0r   N)r#   r$   r%   r&   r   r   rN   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       66: : :: : :": : :: : :<; ; ;4; ; ;4; ; ;,; ; ;4: : :: : :: : :: : :L L L ; ; ;; ; ;0 0 0>
; 
; 
;; ; ;; ; ;; ; ;; ; ;2: : :0* * *2. . .. . ."0 0 0 0 0r   r   c                       e Zd ZdZd ZdS )ContentDirectiveTestCasez.Tests for the `py:content` template directive.c                    	 t          dd                                           |                     d           d S # t          $ rA}|                     d|j                   |                     d|j                   Y d }~d S d }~ww xY w)Nzq<doc xmlns:py="http://genshi.edgewall.org/">
              <py:content foo="">Foo</py:content>
            </doc>r   r   Expected TemplateSyntaxErrorr   r   r   r   r   r   r   r   r   s     r   rN   z(ContentDirectiveTestCase.test_as_element  s    	*  +- - --5XZZZII455555" 	* 	* 	*[!*555Q)))))))))	*   8< 
B6BBN)r#   r$   r%   r&   rN   r'   r   r   r   r     s)        88* * * * *r   r   c                       e Zd ZdZd Zd ZdS )ReplaceDirectiveTestCasez.Tests for the `py:replace` template directive.c                    	 t          dd                                           |                     d           dS # t          $ rA}|                     d|j                   |                     d|j                   Y d}~dS d}~ww xY w)zy
        Verify that the directive raises an apprioriate exception when an empty
        expression is supplied.
        zl<doc xmlns:py="http://genshi.edgewall.org/">
              <elem py:replace="">Foo</elem>
            </doc>r   r   r   r   Nr  r   s     r   test_replace_with_empty_valuez6ReplaceDirectiveTestCase.test_replace_with_empty_value'  s    
	*  +- - --5XZZZII455555" 	* 	* 	*[!*555Q)))))))))	*r  c                     t          dd          }|                     d|                    d                              d                      d S )Nzb<div xmlns:py="http://genshi.edgewall.org/">
          <py:replace value="title" />
        </div>r   r   z#<div>
          Test
        </div>Test)titler   r   r   s     r   rN   z(ReplaceDirectiveTestCase.test_as_element5  sn     ') ) ) 	 ==v=..55t5DD	F 	F 	F 	F 	Fr   N)r#   r$   r%   r&   r  rN   r'   r   r   r  r  $  s=        88* * *F F F F Fr   r  c                       e Zd ZdZd Zd ZdS )StripDirectiveTestCasez,Tests for the `py:strip` template directive.c                     t          d          }|                     d|                                                    d                      d S )Nzl<div xmlns:py="http://genshi.edgewall.org/">
          <div py:strip="False"><b>foo</b></div>
        </div>z4<div>
          <div><b>foo</b></div>
        </div>r   r   r   s     r   test_strip_falsez'StripDirectiveTestCase.test_strip_falseA  [        	 ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                      d S )Nzg<div xmlns:py="http://genshi.edgewall.org/">
          <div py:strip=""><b>foo</b></div>
        </div>z)<div>
          <b>foo</b>
        </div>r   r   r   s     r   test_strip_emptyz'StripDirectiveTestCase.test_strip_emptyI  r  r   N)r#   r$   r%   r&   r  r  r'   r   r   r  r  >  s8        66: : :: : : : :r   r  c                   N    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S )WithDirectiveTestCasez+Tests for the `py:with` template directive.c                     t          d          }|                     d|                    d                              d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          ${x}
          <span py:with="x = x * 2" py:replace="x"/>
          ${x}
        </div>z;<div>
          42
          84
          42
        </div>*   xr   r   r   s     r   test_shadowingz$WithDirectiveTestCase.test_shadowingU  sc       
 	  ==2=&&--t-<<		> 	> 	> 	> 	>r   c                     t          d          }|                     d|                    d                              d                      d S )Nzn<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x = x * 2">${x}</py:with>
        </div>z!<div>
          84
        </div>r  r  r   r   r   s     r   rN   z%WithDirectiveTestCase.test_as_elementa  a        	 ==2=&&--t-<<	> 	> 	> 	> 	>r   c                     t          d          }|                     d|                    d                              d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="
            foo = 'bar';
            foo = foo.replace('r', 'z')
          ">
            $foo
          </py:with>
        </div>z$<div>
            baz
        </div>r  r  r   r   r   s     r   test_multiple_vars_same_namez2WithDirectiveTestCase.test_multiple_vars_same_namei  sa        	 ==2=&&--t-<<	> 	> 	> 	> 	>r   c                     t          d          }|                     d|                    d                              d                      d S )Nz|<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x = y = z = 1">${x} ${y} ${z}</py:with>
        </div>z$<div>
          1 1 1
        </div>r  r  r   r   r   s     r   $test_multiple_vars_single_assignmentz:WithDirectiveTestCase.test_multiple_vars_single_assignmentv  r  r   c                     t          d          }|                     d|                    d                              d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x, (y, z) = (1, (2, 3))">${x} ${y} ${z}</py:with>
        </div>z$<div>
          1 2 3
        </div>r  r  r   r   r   s     r   "test_nested_vars_single_assignmentz8WithDirectiveTestCase.test_nested_vars_single_assignment~  r  r   c                     t          d          }|                     ddz  |                    d                              d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x = x * 2; y = x / 2;">${x} ${y}</py:with>
        </div>z$<div>
          84 %s
        </div>g      E@r  r  r   r   r   s     r   %test_multiple_vars_trailing_semicolonz;WithDirectiveTestCase.test_multiple_vars_trailing_semicolon  sn        	 "mmbm1188$8GG	I 	I 	I 	I 	Ir   c                     t          d          }|                     d|                                                    d                      d S )Nz<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x = 'here is a semicolon: ;'; y = 'here are two semicolons: ;;' ;">
            ${x}
            ${y}
          </py:with>
        </div>z_<div>
            here is a semicolon: ;
            here are two semicolons: ;;
        </div>r   r   r   s     r   test_semicolon_escapez+WithDirectiveTestCase.test_semicolon_escape  s]        	  ==??))4)88	: 	: 	: 	: 	:r   c                     t          d          }|                     d|                    ddi                              d                     dS )z
        Verify that the usual template expression AST transformations are
        applied despite the code being compiled to a `Suite` object.
        z<div xmlns:py="http://genshi.edgewall.org/">
          <span py:with="bar=foo.bar">
            $bar
          </span>
        </div>zF<div>
          <span>
            42
          </span>
        </div>r   r  rG   Nr   r   r   s     r   test_ast_transformationz-WithDirectiveTestCase.test_ast_transformation  sn    
    
 	  ==eR[=1188$8GG		I 	I 	I 	I 	Ir   c                     t          d          }|                     d|                                                    d                      d S )Nu   <div xmlns:py="http://genshi.edgewall.org/">
          <span py:with="weeks=(u'一', u'二', u'三', u'四', u'五', u'六', u'日')">
            $weeks
          </span>
        </div>uY   <div>
          <span>
            一二三四五六日
          </span>
        </div>r   r   r   s     r   test_unicode_exprz'WithDirectiveTestCase.test_unicode_expr  s]       
 	  ==??))4)88		: 	: 	: 	: 	:r   c                     t          d          }|                     d|                                                    d                     dS )zI
        Verify that an empty py:with works (useless, but legal)
        zY<div xmlns:py="http://genshi.edgewall.org/">
          <span py:with="">Text</span></div>z'<div>
          <span>Text</span></div>Nr   r   r   s     r   test_with_empty_valuez+WithDirectiveTestCase.test_with_empty_value  sb      0 1 1 	 %&*mmoo&<&<d&<&K&K	M 	M 	M 	M 	Mr   N)r#   r$   r%   r&   r  rN   r  r  r  r!  r#  r%  r'  r)  r'   r   r   r  r  R  s        55
> 
> 
>> > >> > >> > >> > >I I I
: 
: 
:I I I 
: 
: 
:M M M M Mr   r  c                     t          j                    } |                     t          j        t
                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                                |                     t           j                            t"                               | S ri   )unittest	TestSuiteaddTestdoctestDocTestSuiter   defaultTestLoaderloadTestsFromTestCaser
   r)   rT   ru   r   r   r   r  r  r  )suites    r   r2  r2    s     E	MM'&z22333	MM(,BBCYZZ[[[	MM(,BBCZ[[\\\	MM(,BBCWXXYYY	MM(,BBCWXXYYY	MM(,BBCVWWXXX	MM(,BBCYZZ[[[	MM(,BBC[\\]]]	MM(,BBC[\\]]]	MM(,BBCYZZ[[[	MM(,BBCXYYZZZLr   __main__r2  )defaultTest)r.  r   r   r+  genshi.compatr   genshi.templater   r   r   r   r   TestCaser
   r)   rT   ru   r   r   r   r  r  r  r2  r#   mainr'   r   r   <module>r9     s    				 



  $ $ $ $ $ $F F F F F F F F F F F F F F%: %: %: %: %:X. %: %: %:PA@ A@ A@ A@ A@h/ A@ A@ A@HT: T: T: T: T:8, T: T: T:nn. n. n. n. n.8, n. n. n.bO O O O O(+ O O O6^0 ^0 ^0 ^0 ^0X. ^0 ^0 ^0^* * * * *x0 * * *F F F F Fx0 F F F4: : : : :X. : : :(lM lM lM lM lMH- lM lM lM^   zHMg&&&&&& r   