
    w:iiI                         d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
  G d dej                  Zd Zedk    r ej        d	
           dS dS )    N)TEXT)TemplateLoader)MarkupTemplatec                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TemplateLoaderTestCasezTests for the template loader.c                 :    t          j        d          | _        d S )Nmarkup_test)suffix)tempfilemkdtempdirnameselfs    Y/var/www/html/trac/venv/lib/python3.11/site-packages/genshi/template/tests/test_loader.pysetUpzTemplateLoaderTestCase.setUp   s    '}===    c                 8    t          j        | j                   d S N)shutilrmtreer   r   s    r   tearDownzTemplateLoaderTestCase.tearDown   s    dl#####r   c                 X    t                      }|                     g |j                   d S r   )r   assertEqualsearch_pathr   loaders     r   test_search_path_emptyz-TemplateLoaderTestCase.test_search_path_empty"   s,    !!V/00000r   c                 p    t          | j                  }|                     | j        g|j                   d S r   )r   r   r   r   r   s     r   test_search_path_as_stringz1TemplateLoaderTestCase.test_search_path_as_string&   s4    --$,);<<<<<r   c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          | j        g          }|                    d          }| 	                    d|
                                                    d                      d S N
tmpl1.htmlw<div>Included</div>
tmpl2.htmlt<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="tmpl1.html" />
            </html><<html>
              <div>Included</div>
            </html>encodingopenospathjoinr   writecloser   loadr   generaterenderr   file1file2r   tmpls        r   test_relative_include_samedirz4TemplateLoaderTestCase.test_relative_include_samedir*   s%   RW\\$,==sCC	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM//{{<(( ...==	? 	? 	? 	? 	?   A A5,C C,c                    t          j        t           j                            | j        d                     t          t           j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          t           j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          | j        g          }|	                    d          }| 
                    d|                                                    d                      d S )	Nsubr"   r#   r$   r%   zx<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="sub/tmpl1.html" />
            </html>r'   r(   )r,   mkdirr-   r.   r   r+   r/   r0   r   r1   r   r2   r3   r4   s        r   test_relative_include_subdirz3TemplateLoaderTestCase.test_relative_include_subdir?   sI   
dlE22333RW\\$,|DDcJJ	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM//{{<(( ...==	? 	? 	? 	? 	?s   -B B-$D D$c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          j        t          j                            | j        d                     t          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          | j        g          }|	                    d          }| 
                    d|                                                    d 	                     d S )
Nr"   r#   r$   r;   r%   zw<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="../tmpl1.html" />
            </html>sub/tmpl2.htmlr'   r(   r+   r,   r-   r.   r   r/   r0   r<   r   r1   r   r2   r3   r4   s        r   test_relative_include_parentdirz6TemplateLoaderTestCase.test_relative_include_parentdirU   sJ   RW\\$,==sCC	KK1222KKMMMMEKKMMMM
dlE22333RW\\$,|DDcJJ	KK     KKMMMMEKKMMMM//{{+,, ...==	? 	? 	? 	? 	?s   A A5$D D$c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          j        t          j                            | j        d                     t          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          | j        g          }|	                    d          }| 
                    d	|                                                    d 
                     d S )Nr"   r#   z<div>Included tmpl1.html</div>r;   z"<div>Included sub/tmpl1.html</div>r%   r&   r?   zK<html>
              <div>Included sub/tmpl1.html</div>
            </html>r(   r@   r   r5   r6   file3r   r7   s         r    test_relative_include_samesubdirz7TemplateLoaderTestCase.test_relative_include_samesubdirk   s   RW\\$,==sCC	KK<===KKMMMMEKKMMMM
dlE22333RW\\$,|DDcJJ	KK@AAAKKMMMMEKKMMMMRW\\$,|DDcJJ	KK     KKMMMMEKKMMMM//{{+,, ...==	? 	? 	? 	? 	?#   A A5$D D$F Fc                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt                      }|                    t          j                            | j        d                    }| 	                    d|
                                                    d                      d S r!   r*   r4   s        r   )test_relative_include_without_search_pathz@TemplateLoaderTestCase.test_relative_include_without_search_path   s1   RW\\$,==sCC	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM!!{{27<<lCCDD ...==	? 	? 	? 	? 	?r9   c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          dt          j                            | j        d          d          }|                     d|	                                
                    d                      d S r!   r+   r,   r-   r.   r   r/   r0   r   r   r2   r3   r   r5   r6   r7   s       r   $test_relative_include_without_loaderz;TemplateLoaderTestCase.test_relative_include_without_loader   s2   RW\\$,==sCC	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM T\<@@,P P 	 ...==	? 	? 	? 	? 	?r9   c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          dt          j                            | j        d                    }|                     d|	                                
                    d                      d S )	Nr"   r#   r$   r%   r&   )filenamer'   r(   rJ   rK   s       r   -test_relative_include_without_loader_relativezDTemplateLoaderTestCase.test_relative_include_without_loader_relative   s6   RW\\$,==sCC	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM !#dlL!I!IK K K 	 ...==	? 	? 	? 	? 	?r9   c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt                      }|                    t          j                            | j        d                    }| 	                    d|
                                                    d 	                     d S )
Nr"   r#   r$   r%   zr<div xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="tmpl1.html" />
            </div>
tmpl3.htmlt<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="tmpl2.html" />
            </html>zc<html>
              <div>
              <div>Included</div>
            </div>
            </html>r(   r*   rC   s         r   0test_relative_include_without_search_path_nestedzGTemplateLoaderTestCase.test_relative_include_without_search_path_nested   s   RW\\$,==sCC	KK1222KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMMRW\\$,==sCC	KK     KKMMMMEKKMMMM!!{{27<<lCCDD  ...==		? 	? 	? 	? 	?s#   A A5,C C,#E E#c                    t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          | j        g          }t          dd|          }| 	                    d|
                                                    d                      d S )	Nr"   r#   r$   zo<html xmlns:xi="http://www.w3.org/2001/XInclude">
          <xi:include href="../tmpl1.html" />
        </html>zsubdir/tmpl2.html)rN   r   z4<html>
          <div>Included</div>
        </html>r(   )r+   r,   r-   r.   r   r/   r0   r   r   r   r2   r3   )r   r5   r   tmpl2s       r   ,test_relative_include_from_inmemory_templatezCTemplateLoaderTestCase.test_relative_include_from_inmemory_template   s    RW\\$,==sCC	KK1222KKMMMMEKKMMMM//  0A A A 	 NN$$++T+::	< 	< 	< 	< 	<   A A5c           	         t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          j        t          j                            | j        d                     t          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt                      }|	                    t          j        
                    t          j                            | j        dd                              }|                     d|                                                    d 	                     d S )
Nr"   r#   r$   r;   <div>Included from sub</div>r%   r&   E<html>
              <div>Included from sub</div>
            </html>r(   r+   r,   r-   r.   r   r/   r0   r<   r   r1   abspathr   r2   r3   rC   s         r   )test_relative_absolute_template_preferredz@TemplateLoaderTestCase.test_relative_absolute_template_preferred   s   RW\\$,==sCC	KK1222KKMMMMEKKMMMM
dlE22333RW\\$,|DDcJJ	KK:;;;KKMMMMEKKMMMMRW\\$,|DDcJJ	KK     KKMMMMEKKMMMM!!{{27??27<<e8D,F ,F G G H H ...==	? 	? 	? 	? 	?rF   c           	         t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          j        t          j                            | j        d                     t          t          j                            | j        dd          d          }	 |                    d| j        z             |                                 n# |                                 w xY wt                      }|	                    t          j        
                    t          j                            | j        dd                              }|                     d|                                                    d                      d S )	Nr"   r#   r$   r;   r%   zw<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="%s/tmpl1.html" />
            </html>r'   r(   r[   r4   s        r   test_absolute_includez,TemplateLoaderTestCase.test_absolute_include  s   RW\\$,==sCC	KK1222KKMMMMEKKMMMM
dlE22333RW\\$,|DDcJJ	KK & ' ' ' KKMMMMEKKMMMM!!{{27??27<<e8D,F ,F G G H H ...==	? 	? 	? 	? 	?s   A A5$D D,c                    t           j                            | j        d          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt           j                            | j        d          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |          }|	                    t           j                            |d                    }| 
                    d	|                                                    d 
                     d|j        v sJ d S )Nabsr"   r#   rR   r%   z!<div>Included from abspath.</div>
searchpathz$<div>Included from searchpath.</div>zM<html>
              <div>Included from searchpath.</div>
            </html>r(   )r,   r-   r.   r   r<   r+   r/   r0   r   r1   r   r2   r3   _cache)r   r\   r5   r6   rb   rD   r   tmpl1s           r   test_abspath_cachingz+TemplateLoaderTestCase.test_abspath_caching+  s   ',,t|U33
RW\\'<88#>>	KK     KKMMMMEKKMMMMRW\\'<88#>>	KK?@@@KKMMMMEKKMMMMW\\$,==

RW\\*l;;SAA	KKBCCCKKMMMMEKKMMMM
++BGLL,??@@ ((///>>	@ 	@ 	@ v},,,,,,s$   )B B)D DF0 0Gc                 4   t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wt          j        t          j                            | j        d                     t          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt          t          j                            | j        dd          d          }	 |                    d           |                                 n# |                                 w xY wt                      }|	                    t          j                            | j        d                    }| 
                    d|                                                    d 	                     |	                    t          j                            | j        dd                    }| 
                    d
|                                                    d 	                     d|j        vsJ d S )Nr"   r#   rR   r%   r$   r;   rY   r'   r(   rZ   )r+   r,   r-   r.   r   r/   r0   r<   r   r1   r   r2   r3   rc   )r   r5   r6   rD   file4r   rd   rU   s           r   0test_abspath_include_caching_without_search_pathzGTemplateLoaderTestCase.test_abspath_include_caching_without_search_pathK  s   RW\\$,==sCC	KK     KKMMMMEKKMMMMRW\\$,==sCC	KK1222KKMMMMEKKMMMM
dlE22333RW\\$,|DDcJJ	KK     KKMMMMEKKMMMMRW\\$,|DDcJJ	KK:;;;KKMMMMEKKMMMM!!BGLL|DDEE ((///>>	@ 	@ 	@ BGLLulKKLL ((///>>	@ 	@ 	@ 6=000000s/   A A5,C C,F FG= =Hc                 r   t          t          j                            | j        d          d          }	 |                    d                    d                     |                                 n# |                                 w xY wt          | j        gd          }|	                    d           d S )N	tmpl.htmlwb   <div>ö</div>
iso-8859-1default_encoding
r+   r,   r-   r.   r   r/   encoder0   r   r1   r   fr   s      r   test_load_with_default_encodingz6TemplateLoaderTestCase.test_load_with_default_encodingt  s    dlK88$??	GG&--l;;<<<GGIIIIAGGIIIINNNK        (A2 2Bc                 v   t          t          j                            | j        d          d          }	 |                    d                    d                     |                                 n# |                                 w xY wt          | j        gd          }|	                    dd           d S )Nrj   rk   rl   rm   zutf-8rn   r(   rp   rr   s      r    test_load_with_explicit_encodingz7TemplateLoaderTestCase.test_load_with_explicit_encoding}  s    dlK88$??	GG&--l;;<<<GGIIIIAGGIIIIIIIK,77777ru   c                 l   t          t          j                            | j        d          d          }	 |                    d           |                                 n# |                                 w xY wd }t          | j        g|          }|                    d          }| 	                    d|
                                                    d                      |                    d          }| 	                    d|
                                                    d                      d S )Nrj   r#   z5<html>
              <p>Hello</p>
            </html>c                 B    d }| j                             d|           d S )Nc              3      K   | D ]S\  }}}|t           u r=|                                r)d                    ||                                g          }|||fV  Td S )Nz, )r   stripr.   lower)streamctxtkinddataposs        r   	my_filterzZTemplateLoaderTestCase.test_load_with_callback.<locals>.template_loaded.<locals>.my_filter  sm      '- * *OD$t||

|#yy$

)=>>c/))))* *r   r   )filtersinsert)templater   s     r   template_loadedzGTemplateLoaderTestCase.test_load_with_callback.<locals>.template_loaded  s2    * * *
 ##Ay11111r   )callbackz<<html>
              <p>Hello, hello</p>
            </html>r(   r*   )r   fileobjr   r   r7   s        r   test_load_with_callbackz.TemplateLoaderTestCase.test_load_with_callback  s-   rw||DL+>>DD	MM     MMOOOOGMMOOOO	2 	2 	2  III{{;'' ...==	? 	? 	?
 {{;'' ...==	? 	? 	? 	? 	?rW   c                    t           j                            | j        d          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt           j                            | j        dd          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt           j                            | j        dd          }t          j        |           t          t           j                            |d	          d          }	 |                    d
           |                                 n# |                                 w xY wt          |t          j
        ||          g          }|                    d          }|                     d|                                                    d                     dS )a  
        Test prefix delegation with the following layout:
        
        templates/foo.html
        sub1/templates/tmpl1.html
        sub2/templates/tmpl2.html
        
        Where sub1 and sub2 are prefixes, and both tmpl1.html and tmpl2.html
        incldue foo.html.
        	templatesfoo.htmlr#   <div>Included foo</div>sub1r"   z<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="../foo.html" /> from sub1
            </html>sub2r%   <div>tmpl2</div>r   r   sub1/tmpl1.htmlzJ<html>
              <div>Included foo</div> from sub1
            </html>Nr(   r,   r-   r.   r   r<   r+   r/   r0   makedirsr   prefixedr1   r   r2   r3   )	r   dir1r5   dir2r6   dir3rD   r   r7   s	            r   %test_prefix_delegation_to_directoriesz<TemplateLoaderTestCase.test_prefix_delegation_to_directories  s    w||DL+66
RW\\$
33S99	KK5666KKMMMMEKKMMMMw||DL&+>>
DRW\\$55s;;	KK     KKMMMMEKKMMMMw||DL&+>>
DRW\\$55s;;	KK.///KKMMMMEKKMMMM~'>(
 (
 (
 !   {{,-- ...==	? 	? 	? 	? 	?s$   )B B)D? ?EG+ +Hc           	      R   t           j                            | j        d          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt           j                            | j        dd          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          t           j                            |d          d          }	 |                    d	           |                                 n# |                                 w xY wt           j                            | j        ddd
          }t          j        |           t          t           j                            |d          d          }	 |                    d           |                                 n# |                                 w xY wt          |t          j
        t           j                            |          t           j                            |                    g          }|                    d          }	|                     d|	                                                    d                     dS )a"  
        Test prefix delegation with the following layout:
        
        templates/foo.html
        sub1/templates/tmpl1.html
        sub1/templates/tmpl2.html
        sub1/templates/bar/tmpl3.html
        
        Where sub1 is a prefix, and tmpl1.html includes all the others.
        r   r   r#   r   r   r"   z<html xmlns:xi="http://www.w3.org/2001/XInclude">
              <xi:include href="../foo.html" /> from sub1
              <xi:include href="tmpl2.html" /> from sub1
              <xi:include href="bar/tmpl3.html" /> from sub1
            </html>r%   r   barrQ   z<div>bar/tmpl3</div>r   r   z<html>
              <div>Included foo</div> from sub1
              <div>tmpl2</div> from sub1
              <div>bar/tmpl3</div> from sub1
            </html>Nr(   r   )
r   r   r5   r   r6   rD   r   rg   r   r7   s
             r   2test_prefix_delegation_to_directories_with_subdirszITemplateLoaderTestCase.test_prefix_delegation_to_directories_with_subdirs  s    w||DL+66
RW\\$
33S99	KK5666KKMMMMEKKMMMMw||DL&+>>
DRW\\$55s;;	KK     KKMMMMEKKMMMMRW\\$55s;;	KK.///KKMMMMEKKMMMMw||DL&+uEE
DRW\\$55s;;	KK2333KKMMMMEKKMMMM~'>7<<%%7<<%%(
 (
 (
 !   {{,--  ...==		? 	? 	? 	? 	?s0   )B B)D? ?EF1 1G4I I4N)__name__
__module____qualname____doc__r   r   r   r   r8   r=   rA   rE   rH   rL   rO   rS   rV   r]   r_   re   rh   rt   rw   r   r   r    r   r   r   r      sg       ((> > >$ $ $1 1 1= = =? ? ?*? ? ?,? ? ?,? ? ?8? ? ?*? ? ?,? ? ?,? ? ?>< < < ? ? ?:? ? ?.- - -@'1 '1 '1R! ! !8 8 8? ? ?:,? ,? ,?\6? 6? 6? 6? 6?r   r   c                      t          j                    } |                     t          j        t
          j                             |                     t           j                            t                               | S r   )
unittest	TestSuiteaddTestdoctestDocTestSuiter   r   defaultTestLoaderloadTestsFromTestCaser   )suites    r   r   r   
  sY      E	MM'&~'@AABBB	MM(,BBCYZZ[[[Lr   __main__r   )defaultTest)r   r,   r   r   r   genshi.corer   genshi.template.loaderr   genshi.template.markupr   TestCaser   r   r   mainr   r   r   <module>r      s     				          1 1 1 1 1 1 1 1 1 1 1 1n? n? n? n? n?X. n? n? n?b   zHMg&&&&&& r   