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__/markup.cpython-310.pyc
o

!�b�q�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZddlmZmZddlmZGd	d
�d
ej�Zdd�Zed
kriejdd�dSdS)�N)�BytesIO�StringIO)�Markup)�
Translator)�XML)�BadDirectiveError�TemplateSyntaxError)�TemplateLoader�TemplateNotFound��MarkupTemplatec@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�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`da�Z3dbdc�Z4ddde�Z5dfS)g�MarkupTemplateTestCasez%Tests for markup template processing.cC�,td�}t|�}|�dt|jdd���dS�Nz<root> ${var} $var</root>z<root> 42 42</root>�*��var)rr�assertEqual�str�generate)�self�fileobj�tmpl�r�>/usr/lib/python3/dist-packages/genshi/template/tests/markup.py�test_parse_fileobj$�z)MarkupTemplateTestCase.test_parse_fileobjcCrr)rrrrr)r�streamrrrr�test_parse_stream)rz(MarkupTemplateTestCase.test_parse_streamcCsTtd�}t|�}t�}t�||d�|�d�t�|�}|�dt|j	dd���dS)Nz<root>$var</root>�rz<root>42</root>rr)
rrr�pickle�dump�seek�loadrrr)rrr�buf�	unpickledrrr�test_pickle.s

z"MarkupTemplateTestCase.test_picklecC�$td�}|�dt|jdd���dSr�rrrr�rrrrr�test_interpolate_mixed37�z.MarkupTemplateTestCase.test_interpolate_mixed3cCr')Nz<root>${    foo    }</root>z<root>bar</root>�bar��foor(r)rrr�'test_interpolate_leading_trailing_space;r+z>MarkupTemplateTestCase.test_interpolate_leading_trailing_spacecCr')Nz:<root>${dict(
          bar = 'baz'
        )[foo]}</root>z<root>baz</root>r,r-r(r)rrr�test_interpolate_multiline?sz1MarkupTemplateTestCase.test_interpolate_multilinecC� td�}|�dt|����dS)Nz<root attr="${1}"/>z<root attr="1"/>r(r)rrr�!test_interpolate_non_string_attrsE�z8MarkupTemplateTestCase.test_interpolate_non_string_attrscCr')Nz<root>$foo</root>z<root>buzz</root>)�buzzr-r(r)rrr�test_interpolate_list_resultIr+z3MarkupTemplateTestCase.test_interpolate_list_resultcCs td�}|�dt|����dS)N�<root attr=""/>r(r)rrr�test_empty_attrMr3z&MarkupTemplateTestCase.test_empty_attrcCr')Nz<root attr="$attr"/>r6�)�attrr(r)rrr�test_empty_attr_interpolatedQr+z3MarkupTemplateTestCase.test_empty_attr_interpolatedc
CsZd}z	t|dd�}WdSty,}z|�d|j�|�d|j�WYd}~dSd}~ww)Nz<<p xmlns:py="http://genshi.edgewall.org/" py:do="nothing" />�	test.html��filename�)rrrr=�lineno�r�xmlr�errr�test_bad_directive_errorUs��z/MarkupTemplateTestCase.test_bad_directive_errorc
Cshd}zt|dd���}|�d�WdSty3}z|�d|j�|�d|j�WYd}~dSd}~ww)Nz9<p xmlns:py="http://genshi.edgewall.org/" py:if="bar'" />r;r<�Expected TemplateSyntaxErrorr>)rr�failrrr=r?r@rrr�!test_directive_value_syntax_error]s��z8MarkupTemplateTestCase.test_directive_value_syntax_errorc
C�dd}zt|dd�}|�d�WdSty1}z|�d|j�|�d|j�WYd}~dSd}~ww)Nz/<p>
          Foo <em>${bar"}</em>
        </p>r;r<rDr�rrErrr=r?r@rrr�test_expression_syntax_errorfs��z3MarkupTemplateTestCase.test_expression_syntax_errorc
CrG)Nz$<p><em></em>

 ${bar"}

        </p>r;r<rD�rHr@rrr�'test_expression_syntax_error_multi_lineqs��z>MarkupTemplateTestCase.test_expression_syntax_error_multi_linecCs(td�}|�dt|jtd�d���dS)zi
        Verify that outputting context data that is a `Markup` instance is not
        escaped.
        �L<div xmlns:py="http://genshi.edgewall.org/">
          $myvar
        </div>z)<div>
          <b>foo</b>
        </div>z
<b>foo</b>��myvarN)rrrrrr)rrr�test_markup_noescape~s�z+MarkupTemplateTestCase.test_markup_noescapecC�$td�}|�dt|jdd���dS)zb
        Verify that outputting context data in text nodes doesn't escape
        quotes.
        rLz$<div>
          "foo"
        </div>�"foo"rMNr(r)rrr�test_text_noescape_quotes�s�z0MarkupTemplateTestCase.test_text_noescape_quotescCrP)zR
        Verify that outputting context data in attribtes escapes quotes.
        z\<div xmlns:py="http://genshi.edgewall.org/">
          <elem class="$myvar"/>
        </div>z<<div>
          <elem class="&#34;foo&#34;"/>
        </div>rQrMNr(r)rrr�test_attr_escape_quotes�s�z.MarkupTemplateTestCase.test_attr_escape_quotescCr')Nze<div xmlns:py="http://genshi.edgewall.org/">
          <py:if test="myvar">bar</py:if>
        </div>z"<div>
          bar
        </div>rQrMr(r)rrr�test_directive_element�s�z-MarkupTemplateTestCase.test_directive_elementcCr1)NzV<div xmlns:py="http://genshi.edgewall.org/">
          <!-- foo bar -->
        </div>z/<div>
          <!-- foo bar -->
        </div>r(r)rrr�test_normal_comment�s
�z*MarkupTemplateTestCase.test_normal_commentcCr1)Nzi<div xmlns:py="http://genshi.edgewall.org/">
          <!-- !foo -->
          <!--!bar-->
        </div>z<div>
        </div>r(r)rrr�test_template_comment�s
�z,MarkupTemplateTestCase.test_template_commentcCr1)Nz�<div xmlns:py="http://genshi.edgewall.org/">
          <span xmlns:py="http://genshi.edgewall.org/">
          </span>
        </div>z7<div>
          <span>
          </span>
        </div>r(r)rrr�%test_parse_with_same_namespace_nested�s
�z<MarkupTemplateTestCase.test_parse_with_same_namespace_nestedcC�,td�d�dd�}|�dt�|����dS)Nu}<?xml version="1.0" encoding="iso-8859-1" ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ö
        </div>�
iso-8859-1��encodinguM<?xml version="1.0" encoding="iso-8859-1"?>
<div>
          ö
        </div>�r�encoder�six�	text_typerr)rrr� test_latin1_encoded_with_xmldecl�s��z7MarkupTemplateTestCase.test_latin1_encoded_with_xmldeclcCrX)NuH<div xmlns:py="http://genshi.edgewall.org/">
          ö
        </div>rYrZu!<div>
          ö
        </div>r\r)rrr�%test_latin1_encoded_explicit_encoding�s��z<MarkupTemplateTestCase.test_latin1_encoded_explicit_encodingcCstd�dS)z�
        Verify that a code block processing instruction with trailing space
        does not cause a syntax error (see ticket #127).
        zI<foo>
          <?python
            bar = 42
          ?>
        </foo>Nr)rrrr�test_exec_with_trailing_space�sz4MarkupTemplateTestCase.test_exec_with_trailing_spacecCr1)Nz�<?python from datetime import timedelta ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ${timedelta(days=2)}
        </div>z.<div>
          2 days, 0:00:00
        </div>r(r)rrr�test_exec_import�s
�z'MarkupTemplateTestCase.test_exec_importcCr1)Nz�
        <?python
        def foo():
            return 42
        ?>
        <div xmlns:py="http://genshi.edgewall.org/">
          ${foo()}
        </div>z!<div>
          42
        </div>r(r)rrr�
test_exec_def�s
�z$MarkupTemplateTestCase.test_exec_defcCs td�}|�dt|����dS)z�
        Verify that a namespace declaration on an element that is removed from
        the generated stream does not get pushed up to the next non-stripped
        element (see ticket #107).
        z�<?xml version="1.0"?>
        <Test xmlns:py="http://genshi.edgewall.org/">
          <Size py:if="0" xmlns:t="test">Size</Size>
          <Item/>
        </Test>zI<?xml version="1.0"?>
<Test>
          
          <Item/>
        </Test>Nr(r)rrr�test_namespace_on_removed_elem�s
�z5MarkupTemplateTestCase.test_namespace_on_removed_elemc	C��tjdd�}zVttj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d�W|��n|��wt|g�}|�	d�}|�
d|jd	d
�jdd��Wt
�|�dSt
�|�w)N�genshi_test��suffix�
tmpl1.html�w�<div>Included $idx</div>�
tmpl2.htmlz�<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="${name}.html" py:for="idx in range(3)" />
                </html>�p<html>
                  <div>Included 0</div><div>Included 1</div><div>Included 2</div>
                </html>�tmpl1��namerZ��tempfile�mkdtemp�open�os�path�join�write�closer	r#rr�render�shutil�rmtree�r�dirname�file1�file2�loaderrrrr�test_include_in_loop� 

�z+MarkupTemplateTestCase.test_include_in_loopc	Crf)Nrgrhrjrk�<div>Included</div>rmz�<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="${name}.html" />
                </html>�D<html>
                  <div>Included</div>
                </html>rorprZrrr~rrr�test_dynamic_include_hrefr�z0MarkupTemplateTestCase.test_dynamic_include_hrefc	C��tjdd�}zTttj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d�W|��n|��wt|g�}|�	d�}|�
d|��jdd	��Wt
�|�dSt
�|�w)
Nrgrhrjrkz<li>$item</li>rmac<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <ul py:match="ul">${select('li')}</ul>
                  <ul py:with="items=(1, 2, 3)">
                    <xi:include href="tmpl1.html" py:for="item in items" />
                  </ul>
                </html>zX<html>
                  <ul><li>1</li><li>2</li><li>3</li></ul>
                </html>rZrrr~rrr�test_select_included_elements9� 

�z4MarkupTemplateTestCase.test_select_included_elementsc	Cr�)
Nrgrhrjrkr�rm��<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"><xi:fallback>
                    Missing</xi:fallback></xi:include>
                </html>r�rZrrr~rrr� test_fallback_when_include_foundVs 

�z7MarkupTemplateTestCase.test_fallback_when_include_foundc	Cs�tjdd�}z8ttj�|d�d�}z|�d�W|��n|��wt|gdd�}|�	d�}|�
t|��j
�Wt�|�dSt�|�w)Nrgrhrmrkz{<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"/>
                </html>T��auto_reload)rsrtrurvrwrxryrzr	r#�assertRaisesr
rr{r|r}�rrr�r�rrrr�!test_error_when_include_not_foundps
z8MarkupTemplateTestCase.test_error_when_include_not_foundc	C�tjdd�}z9ttj�|d�d�}z|�d�W|��n|��wt|g�}|�	d�}|�
d|��jdd��Wt
�|�dSt
�|�w)Nrgrhrmrkz�<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl1.html"><xi:fallback>
                  Missing</xi:fallback></xi:include>
                </html>z8<html>
                  Missing
                </html>rZrrr�rrr�$test_fallback_when_include_not_found�s

�z;MarkupTemplateTestCase.test_fallback_when_include_not_foundc	Cs�tjdd�}z;ttj�|d�d�}z|�d�W|��n|��wt|gdd�}|�	d�}|�
d|��jdd	��Wt
�|�dSt
�|�w)
Nrgrhrmrkr�Tr�z:<html>
                    Missing
                </html>rZrrr�rrr�#test_fallback_when_auto_reload_true�s
�z:MarkupTemplateTestCase.test_fallback_when_auto_reload_truec	Cr�)
Nrgrhrjrkr��
tmpl3.html�s<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl2.html">
                    <xi:fallback>
                      <xi:include href="tmpl1.html">
                        <xi:fallback>Missing</xi:fallback>
                      </xi:include>
                    </xi:fallback>
                  </xi:include>
                </html>zH<html>
                      <div>Included</div>
                </html>rZrrr~rrr�test_include_in_fallback�s 


�z/MarkupTemplateTestCase.test_include_in_fallbackc	Cr�)Nrgrhr�rkr�z<<html>
                      Missing
                </html>rZrrr�rrr�test_nested_include_fallback�s


�z3MarkupTemplateTestCase.test_nested_include_fallbackc	Cr�)
Nrgrhrmrkr�r�a<html xmlns:xi="http://www.w3.org/2001/XInclude">
                  <xi:include href="tmpl2.html">
                    <xi:fallback>
                      <xi:include href="tmpl1.html" />
                    </xi:fallback>
                  </xi:include>
                </html>r�rZrrr~rrr�test_nested_include_in_fallback�r�z6MarkupTemplateTestCase.test_nested_include_in_fallbackc	Cs�tjdd�}z;ttj�|d�d�}z|�d�W|��n|��wt|g�}|�	d�}|�
d|jdd�jdd	��Wt
�|�dSt
�|�w)
Nrgrhrmrka6<html xmlns:xi="http://www.w3.org/2001/XInclude"
                      xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html"><xi:fallback>
                    <py:if test="True">tmpl1.html not found</py:if>
                  </xi:fallback></xi:include>
                </html>zG<html>
                    tmpl1.html not found
                </html>T)�debugrZrrr�rrr�$test_include_fallback_with_directive�s

�z;MarkupTemplateTestCase.test_include_fallback_with_directivec	Cs�tjdd�}z_ttj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d�W|��n|��wt|gdd	�}|�	d�}|�
d
t|j��|�
d|�
�jdd��Wt�|�dSt�|�w)
Nrgrhrjrkr�rmz�<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html" />
                </html>Fr��r�rZ)rsrtrurvrwrxryrzr	r#r�lenrrr{r|r}r~rrr�test_include_inlineds"
�z+MarkupTemplateTestCase.test_include_inlinedc	Cs�tjdd�}zVttj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d�W|��n|��wt|gdd	�}|�	d�}|�
d
|��jdd��Wt
�|�dSt
�|�w)Nrgrhrjrkrlrmz�<html xmlns:xi="http://www.w3.org/2001/XInclude"
                                     xmlns:py="http://genshi.edgewall.org/">
                  <xi:include href="tmpl1.html" py:for="idx in range(3)" />
                </html>Fr�rnrZrrr~rrr�test_include_inlined_in_loop0s 
�z3MarkupTemplateTestCase.test_include_inlined_in_loopc	Cs�tjdd�}zBttj�|d�d�}z|�d�W|��n|��wt|gdd�}|�	tj�|d��}|�
d|jd	d
�jdd��Wt
�|�dSt
�|�w)Nrgrhrjrkz�<div xmlns:xi="http://www.w3.org/2001/XInclude"                xmlns:py="http://genshi.edgewall.org/">$depth<py:with vars="depth = depth + 1"><xi:include href="tmpl1.html"            py:if="depth &lt; 3"/></py:with></div>Fr�z$<div>0<div>1<div>2</div></div></div>r)�depthrZrr)rrr�r�rrrr�test_include_inline_recursiveJs��z4MarkupTemplateTestCase.test_include_inline_recursivec
CsJd}zt|ddd�}|�d�WdSty$}zWYd}~dSd}~ww)N��<?python
          title = "A Genshi Template"
          ?>
          <html xmlns:py="http://genshi.edgewall.org/">
            <head>
              <title py:content="title">This is replaced.</title>
            </head>
        </html>r;F�r=�
allow_execzExpected SyntaxError)rrErr@rrr�test_allow_exec_falseds���z,MarkupTemplateTestCase.test_allow_exec_falsecCsd}t|ddd�}dS)Nr�r;Tr�r�rrArrrr�test_allow_exec_truetsz+MarkupTemplateTestCase.test_allow_exec_truecCs.d}t|ddd�}|�d|��jdd��dS)Nz�<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body/p">
            <?python title="wakka wakka wakka" ?>
            ${title}
          </py:match>
          <body><p>moot text</p></body>
        </html>r;Tr�zW<html>
          <body>
            wakka wakka wakka
          </body>
        </html>rZ�rrrr{r�rrr�test_exec_in_matchs
�z)MarkupTemplateTestCase.test_exec_in_matchcC�,d}t|dd�}|�d|��jdd��dS)Nz�<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body/p">
            <h1>${select('text()')}</h1>
            ${select('.')}
          </py:match>
          <body><p py:with="foo='bar'">${foo}</p></body>
        </html>r;r<zi<html>
          <body>
            <h1>bar</h1>
            <p>bar</p>
          </body>
        </html>rZr�r�rrr�test_with_in_match�s
�z)MarkupTemplateTestCase.test_with_in_matchc	Cs�tjdd�}zottj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d�W|��n|��wttj�|d�d�}z|�d	�W|��n|��wt|g�}|�	d�}|�
d
|��jdd��Wt
�|�dSt
�|�w)Nrgrhrjrkzl<html xmlns:py="http://genshi.edgewall.org/" py:strip="">
   <div class="target">Some content.</div>
</html>rmz�<html xmlns:py="http://genshi.edgewall.org/"
    xmlns:xi="http://www.w3.org/2001/XInclude">
  <body>
    <h1>Some full html document that includes file1.html</h1>
    <xi:include href="tmpl1.html" />
  </body>
</html>r�a
<html xmlns:py="http://genshi.edgewall.org/"
    xmlns:xi="http://www.w3.org/2001/XInclude" py:strip="">
  <div py:match="div[@class='target']" py:attrs="select('@*')">
    Some added stuff.
    ${select('*|text()')}
  </div>
  <xi:include href="tmpl2.html" />
</html>
z�
  <html>
  <body>
    <h1>Some full html document that includes file1.html</h1>
   <div class="target">
    Some added stuff.
    Some content.
  </div>
  </body>
</html>
rZrr)rrr�r��file3r�rrrr�test_nested_include_matches�s(



�z2MarkupTemplateTestCase.test_nested_include_matchescCr�)Nak<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body" once="true" buffer="false">
            <body>
              ${select('*|text')}
              And some other stuff...
            </body>
          </py:match>
          <body>
            <span py:match="span">Foo</span>
            <span>Bar</span>
          </body>
        </html>r;r<z�<html>
            <body>
              <span>Foo</span>
              And some other stuff...
            </body>
        </html>rZr�r�rrr�%test_nested_matches_without_buffering�s
�z<MarkupTemplateTestCase.test_nested_matches_without_bufferingcCr�)Na<html xmlns:py="http://genshi.edgewall.org/">
          <py:match path="body" buffer="false">
            <body>
              This replaces the other text.
            </body>
          </py:match>
          <body>
            This gets replaced.
          </body>
        </html>r;r<zi<html>
            <body>
              This replaces the other text.
            </body>
        </html>rZr�r�rrr�test_match_without_select�s

�z0MarkupTemplateTestCase.test_match_without_selectcCr�)Nal<rhyme xmlns:py="http://genshi.edgewall.org/">
          <py:match path="*[@type]">
            ${select('.')}
          </py:match>

          <lines>
            <first type="one">fish</first>
            <second type="two">fish</second>
            <third type="red">fish</third>
            <fourth type="blue">fish</fourth>
          </lines>
        </rhyme>r;r<z�<rhyme>
          <lines>
            <first type="one">fish</first>
            <second type="two">fish</second>
            <third type="red">fish</third>
            <fourth type="blue">fish</fourth>
          </lines>
        </rhyme>rZr�r�rrr�test_match_tail_handling�s
�z/MarkupTemplateTestCase.test_match_tail_handlingcCs:td�}tdd��}|�tj|�|�dt|����dS)Nz�<div xmlns:py="http://genshi.edgewall.org/">
            <py:for each="i in range(2)"><py:for each="j in range(1)">
                <span py:content="i + j"></span>
            </py:for></py:for>
        </div>cSs|S)Nr)�srrr�<lambda>szSMarkupTemplateTestCase.test_directive_single_line_with_translator.<locals>.<lambda>zR<div>
                <span>0</span>
                <span>1</span>
        </div>)rr�add_directives�	NAMESPACErrr)rr�
translatorrrr�*test_directive_single_line_with_translators
�zAMarkupTemplateTestCase.test_directive_single_line_with_translatorN)6�__name__�
__module__�__qualname__�__doc__rrr&r*r/r0r2r5r7r:rCrFrIrKrOrRrSrTrUrVrWr`rarbrcrdrer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr
!sh		

		
6r
cCs0t��}|�t�tj��|�t�td��|S)N�test)	�unittest�	TestSuite�addTest�doctest�DocTestSuiterr��	makeSuiter
)�suiterrrr�"sr��__main__)�defaultTest)r�rvr r|�sysrsr�r^�
genshi.compatrr�genshi.corer�genshi.filters.i18nr�genshi.inputr�genshi.template.baserr�genshi.template.loaderr	r
�genshi.template.markupr�TestCaser
r�r��mainrrrr�<module>s4
�

https://t.me/RX1948 - 2025