
    MhmH                        d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	m
Z
mZ d dlmZ d dl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S )    N)utf8
native_str
to_unicode)Template
DictLoader
ParseErrorLoader)
ObjectDictc                       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 ej        d          d             Zd ZdS )TemplateTestc                 x    t          d          }|                     |                    d          d           d S NzHello {{ name }}!Benname
   Hello Ben!r   assertEqualgenerateselftemplates     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/test/template_test.pytest_simplezTemplateTest.test_simple   s=    /00***66FFFFF    c                     t          d          }|                     |                    t          d                    d           d S r   r   r   r   r   r   s     r   
test_byteszTemplateTest.test_bytes   sC    /00**U*<<mLLLLLr   c                 t    t          d          }|                     |                                d           d S )Nz2 + 2 = {{ 2 + 2 }}s	   2 + 2 = 4r   r   s     r   test_expressionszTemplateTest.test_expressions   s8    122**,,l;;;;;r   c                     t          d          }|                     |                    t          d                    d           d S )Nz Hello{# TODO i18n #} {{ name }}!r   r   r   r   r   s     r   test_commentzTemplateTest.test_comment   sC    >??**U*<<mLLLLLr   c                     t          ddd          }|                     |                    d                                          d           d S )Nz%{% include "header.html" %}
body textzheader text)
index.htmlzheader.htmlr$   s   header text
body textr   r   loadr   r   loaders     r   test_includezTemplateTest.test_include   sc    F, 
 
 	KK%%..002K	
 	
 	
 	
 	
r   c                     t          ddd          }|                     |                    d                                          d           d S )Nzj<title>{% block title %}default title{% end %}</title>
<body>{% block body %}default body{% end %}</body>
zb{% extends "base.html" %}
{% block title %}page title{% end %}
{% block body %}page body{% end %}
)	base.html	page.htmlr,   s1   <title>page title</title>
<body>page body</body>
r%   r'   s     r   test_extendszTemplateTest.test_extends(   sg    
 

 
 	KK$$--//B	
 	
 	
 	
 	
r   c                     t          dddd          }|                     |                    d                                          d           d S )Nz{% include '2.html' %}z{% include '../b/3.html' %}ok)a/1.htmlza/2.htmlzb/3.htmlr0   s   okr%   r'   s     r   test_relative_loadzTemplateTest.test_relative_load;   sZ    49  
 
 	Z0099;;UCCCCCr   c                    |                      t          d            |                      t          d            |                     t          d                                          d           |                     t          d                                          d           |                     t          d                                          d           |                     t          d	                                          d
           d S )Nc                       t          d          S )Nz{{r    r   r   <lambda>z,TemplateTest.test_escaping.<locals>.<lambda>F       htnn r   c                       t          d          S )Nz{%r4   r5   r   r   r6   z,TemplateTest.test_escaping.<locals>.<lambda>G   r7   r   z{{!s   {{z{%!s   {%z{#!s   {#z{{ 'expr' }} {{!jquery expr}}s   expr {{jquery expr}})assertRaisesr   r   r   r   r   s    r   test_escapingzTemplateTest.test_escapingE   s    *&<&<===*&<&<===%1133U;;;%1133U;;;%1133U;;;455>>@@#	
 	
 	
 	
 	
r   c                     t          t          d                    }|                     |                                t          d                     d S )N   ér   r   r   r   r   s     r   test_unicode_templatez"TemplateTest.test_unicode_templateP   sC    DNN++**,,d8nn=====r   c                     t          t          d                    }|                     |                                t          d                     d S )Nu
   {{ "é" }}r=   r>   r   s     r   test_unicode_literal_expressionz,TemplateTest.test_unicode_literal_expressionT   sH    
 D!12233**,,d8nn=====r   c                     t          ddidd i          }|                     |                    d                                          d           d S )N	test.htmlz{{ inc(5) }}incc                     | dz   S )N   r5   xs    r   r6   z4TemplateTest.test_custom_namespace.<locals>.<lambda>^   s
    q1u r   	namespace   6r%   r'   s     r   test_custom_namespacez"TemplateTest.test_custom_namespace\   s]    .)e__5M
 
 
 	[11::<<dCCCCCr   c                     d }t          t          d                    }|                     |                    |          d           d S )Nc                 *    |                                  S Nupperss    r   rQ   z&TemplateTest.test_apply.<locals>.upperc   s    7799r   z{% apply upper %}foo{% end %}rP   s   FOOr>   r   rQ   r   s      r   
test_applyzTemplateTest.test_applyb   sV    	 	 	 D!@AABB***77@@@@@r   c                     d }t          t          d                    }|                     |                    |          t          d                     d S )Nc                 D    t          |                                           S rO   )r   rQ   rR   s    r   rQ   z.TemplateTest.test_unicode_apply.<locals>.upperj   s    a==&&(((r       {% apply upper %}foo é{% end %}rP      FOO Ér>   rT   s      r   test_unicode_applyzTemplateTest.test_unicode_applyi   s^    	) 	) 	) D!GHHII***77l9K9KLLLLLr   c                     d }t          t          d                    }|                     |                    |          t          d                     d S )Nc                 ^    t          t          |                                                     S rO   )r   r   rQ   rR   s    r   rQ   z,TemplateTest.test_bytes_apply.<locals>.upperq   s"    
1++--...r   rX   rP   rY   r>   rT   s      r   test_bytes_applyzTemplateTest.test_bytes_applyp   s^    	/ 	/ 	/ D!GHHII***77l9K9KLLLLLr   c                     t          t          d                    }|                     |                    d          d           |                     |                    d          d           d S )Nz&{% if x > 4 %}yes{% else %}no{% end %}   rG   s   yes   s   nor>   r   s     r   test_ifzTemplateTest.test_ifw   sl    D!IJJKK**Q*//888**Q*//77777r   c                     t          t          d                    }|                     |                                d           d S )Nz {% if True %}{% else %}{% end %}r   r>   r   s     r   test_if_empty_bodyzTemplateTest.test_if_empty_body|   s@    D!CDDEE**,,c22222r   c                     t          t          d                    }|                     |                    d          d           |                     |                    d          d           d S )Nzb{% try %}
try{% set y = 1/x %}
{% except %}-except
{% else %}-else
{% finally %}-finally
{% end %}rF   rG   s   
try
-else
-finally
r   s   
try-except
-finally
r>   r   s     r   test_tryzTemplateTest.test_try   s{     	
 	
 	**Q*//1LMMM**Q*//1LMMMMMr   c                     t          t          d                    }|                     |                                d           d S )Nz{% comment blah blah %}foos   foor>   r   s     r   test_comment_directivez#TemplateTest.test_comment_directive   s@    D!=>>??**,,f55555r   c                     t          t          d                    }|                                }d                    |                                          }|                     |d           d S )Nz{% for i in range(10) %}
    {% if i == 2 %}
        {% continue %}
    {% end %}
    {{ i }}
    {% if i == 6 %}
        {% break %}
    {% end %}
{% end %}r   s   013456)r   r   r   joinsplitr   )r   r   results      r   test_break_continuez TemplateTest.test_break_continue   sk    	 
 
 ""$$&,,..))+++++r   c                     |                      t          d          5  t          t          d                     d d d            d S # 1 swxY w Y   d S )NDid not get expected exceptionmsgz{% break %}r9   r   r   r   r:   s    r   test_break_outside_loopz$TemplateTest.test_break_outside_loop   s    z/OPP 	* 	*T-(()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*   AAAc                     |                      t          d          5  t          t          d                     d d d            d S # 1 swxY w Y   d S )Nrn   ro   z={% for i in [] %}{% apply foo %}{% break %}{% end %}{% end %}rq   r:   s    r   test_break_in_applyz TemplateTest.test_break_in_apply   s     z/OPP 	 	TUU  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rs   zno testable future importsc                     |                      dd           t          d          }|                      |                                d           d S )Ng      ?z{{ 1 / 2 }}0)r   r   r   r   s     r   test_no_inherit_futurez#TemplateTest.test_no_inherit_future   sO     	$$$M****,,c22222r   c                     t          ddi          }|                     |                    d                                          d           d S )Nu
   tést.htmlhellos   hellor%   r'   s     r   test_non_ascii_namez TemplateTest.test_non_ascii_name   sJ    -w788%566??AA8LLLLLr   N)__name__
__module____qualname__r   r   r    r"   r)   r-   r1   r;   r?   rA   rL   rU   rZ   r]   ra   rc   re   rg   rl   rr   ru   unittestskiprx   r{   r5   r   r   r   r      s       G G GM M M< < <M M M	
 	
 	

 
 
&D D D	
 	
 	
> > >> > >D D DA A AM M MM M M8 8 8
3 3 3N N N6 6 6, , ,(* * *   X]/00	3 	3 10	3M M M M Mr   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	StackTraceTestc                    t          ddi          }	 |                    d                                           |                     d           d S # t          $ r, |                     dt          j                    v            Y d S w xY w)NrC   zone
two{{1/0}}
three
        did not get expected exception# test.html:2r   r&   r   failZeroDivisionError
assertTrue	traceback
format_excr'   s     r   !test_error_line_number_expressionz0StackTraceTest.test_error_line_number_expression        
 
	GKK$$--///II677777  	G 	G 	GOOOy/C/E/EEFFFFFF	G   <A 2BBc                    t          ddi          }	 |                    d                                           |                     d           d S # t          $ r, |                     dt          j                    v            Y d S w xY w)NrC   z'one
two{%if 1/0%}
three{%end%}
        r   r   r   r'   s     r    test_error_line_number_directivez/StackTraceTest.test_error_line_number_directive   r   r   c                 |   d fd}t          ddddt          |          i          	                     d                                           |                     d	           d S # t
          $ rE t          j                    }|                     d
|v            |                     d|v            Y d S w xY w)Nc                 L    J                       |           j        di |S )Nr5   r&   r   )pathkwargsr(   s     r   load_generatezCStackTraceTest.test_error_line_number_module.<locals>.load_generate   s4    %%%-6;;t$$-77777r   z!{% module Template('sub.html') %}{{1/0}}r+   sub.html_tt_modulesr4   rI   r+   r   # base.html:1z# sub.html:1)	r   r
   r&   r   r   r   r   r   r   )r   r   	exc_stackr(   s      @r   test_error_line_number_modulez,StackTraceTest.test_error_line_number_module   s    	8 	8 	8 	8 	8 =9UU$j-&H&H&HI
 
 
	9KK$$--///II677777  	9 	9 	9!,..IOOOy8999OONi7888888	9s   <A, ,AB;:B;c                    t          ddd          }	 |                    d                                           |                     d           d S # t          $ r, |                     dt          j                    v            Y d S w xY w)Nz{% include 'sub.html' %}r   r   r+   r   z# sub.html:1 (via base.html:1)r   r'   s     r   test_error_line_number_includez-StackTraceTest.test_error_line_number_include   s    4)LL
 
	XKK$$--///II677777  	X 	X 	XOO<	@T@V@VVWWWWWW	Xs   <A 2BBc                    t          ddd          }	 |                    d                                           |                     d           n## t          $ r t          j                    }Y nw xY w|                     d|           d S )Nr   z{% extends 'base.html' %}r   r   r   r   )r   r&   r   r   r   r   r   assertIn)r   r(   r   s      r   )test_error_line_number_extends_base_errorz8StackTraceTest.test_error_line_number_extends_base_error   s    #1LMM
 
	/KK
##,,...II67777  	/ 	/ 	/!,..III	/oy11111s   <A A10A1c                    t          ddd          }	 |                    d                                           |                     d           d S # t          $ r+ |                     dt          j                               Y d S w xY w)Nz{% block 'block' %}{% end %}zM
{% extends 'base.html' %}
{% block 'block' %}
{{1/0}}
{% end %}
            r   r   r   z# sub.html:4 (via base.html:1)r   r&   r   r   r   r   r   r   r'   s     r   (test_error_line_number_extends_sub_errorz7StackTraceTest.test_error_line_number_extends_sub_error
  s    ; 

 

	TKK
##,,...II677777  	T 	T 	TMM:I<P<R<RSSSSSS	Ts   <A 1BBc                    t          dddd          }	 |                    d                                           |                     d           d S # t          $ r+ |                     dt          j                               Y d S w xY w)Nz{% include 'b.html' %}z{% include 'c.html' %}r   )a.htmlzb.htmlzc.htmlr   r   z## c.html:1 (via b.html:1, a.html:1)r   r'   s     r   test_multi_includesz"StackTraceTest.test_multi_includes  s    22# 
 
	YKK!!**,,,II677777  	Y 	Y 	YMM?AUAWAWXXXXXX	Ys   <A 1BBN)
r|   r}   r~   r   r   r   r   r   r   r   r5   r   r   r   r      s        G G GG G G9 9 9&X X X	2 	2 	2T T T$Y Y Y Y Yr   r   c                       e Zd Zd Zd ZdS )ParseErrorDetailTestc                    t          ddi          }|                     t                    5 }|                    d           d d d            n# 1 swxY w Y   |                     dt          |j                             |                     d|j        j                   |                     d|j        j                   d S )Nfoo.htmlz

{{z'Missing end expression }} at foo.html:3r`   )	r   r9   r   r&   r   str	exceptionfilenamelineno)r   r(   cms      r   test_detailsz!ParseErrorDetailTest.test_details,  s    Z233z** 	$bKK
###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$BCDUDUVVVR\%:;;;BL/00000s   AAAc                 f    |                      dt          t          d                               d S )Nzasdf at None:0asdf)r   r   r   r:   s    r   test_custom_parse_errorz,ParseErrorDetailTest.test_custom_parse_error4  s1     	)3z&/A/A+B+BCCCCCr   N)r|   r}   r~   r   r   r5   r   r   r   r   +  s7        1 1 1D D D D Dr   r   c                   P    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 )AutoEscapeTestc                 ,    ddddddddd	d
dd| _         d S )Nz'{% autoescape xhtml_escape %}{{ name }}z{% autoescape None %}{{ name }}z
{{ name }}zvescaped: {% include 'escaped.html' %}
unescaped: {% include 'unescaped.html' %}
default: {% include 'default.html' %}
zF{% autoescape xhtml_escape %}{% block name %}base: {{ name }}{% end %}z>{% autoescape None %}{% block name %}base: {{ name }}{% end %}zA{% autoescape xhtml_escape %}{% extends "unescaped_block.html" %}zn{% autoescape xhtml_escape %}{% extends "unescaped_block.html" %}{% block name %}extended: {{ name }}{% end %}z7{% autoescape None %}{% extends "escaped_block.html" %}zd{% autoescape None %}{% extends "escaped_block.html" %}{% block name %}extended: {{ name }}{% end %}zA{% autoescape xhtml_escape %}expr: {{ name }}
raw: {% raw name %})escaped.htmlunescaped.htmldefault.htmlinclude.htmlescaped_block.htmlunescaped_block.htmlescaped_extends_unescaped.html escaped_overrides_unescaped.htmlunescaped_extends_escaped.html unescaped_overrides_escaped.htmlraw_expression.html)	templatesr:   s    r   setUpzAutoEscapeTest.setUp;  sE    E?(
#-%-
/(11/&11$?#
 #
r   c                    t          | j        d           }d}|                     |                    d                              |          d           |                     |                    d                              |          d           |                     |                    d                              |          d           |                     |                    d	                              |          d
           d S )N
autoescapeBobby <table>sr   r      Bobby &lt;table&gt;sr      Bobby <table>sr   r   sP   escaped: Bobby &lt;table&gt;s
unescaped: Bobby <table>s
default: Bobby <table>s
r   r   r   r&   r   r   r(   r   s      r   test_default_offzAutoEscapeTest.test_default_offa  s   DNt<<<KK''00d0;;=T	
 	
 	
 	KK())222==?P	
 	
 	
 	KK''00d0;;=N	
 	
 	
 	KK''00d0;;)	
 	
 	
 	
 	
r   c                    t          | j        d          }d}|                     |                    d                              |          d           |                     |                    d                              |          d           |                     |                    d	                              |          d           |                     |                    d
                              |          d           d S )Nxhtml_escaper   r   r   r   r   r   r   r   r   sV   escaped: Bobby &lt;table&gt;s
unescaped: Bobby <table>s
default: Bobby &lt;table&gt;s
r   r   s      r   test_default_onzAutoEscapeTest.test_default_onu  s   DN~FFFKK''00d0;;=T	
 	
 	
 	KK())222==?P	
 	
 	
 	KK''00d0;;=T	
 	
 	
 	KK''00d0;;/	
 	
 	
 	
 	
r   c                 &   t          | j                  }d}|                     |                    d                              |          d           |                     |                    d                              |          d           d S )N<script>r   r      base: &lt;script&gt;r      base: <script>r   r   s      r   test_unextended_blockz$AutoEscapeTest.test_unextended_block  s    DN++KK,--66D6AA#	
 	
 	
 	KK.//88d8CCEV	
 	
 	
 	
 	
r   c                 2   t          | j                  fd}|                      |d          d           |                      |d          d           |                      |d          d           |                      |d          d	           d S )
Nc                 V                         |                               d          S )Nr   r   r   r   r(   s    r   renderz2AutoEscapeTest.test_extended_block.<locals>.render  s&    ;;t$$--:->>>r   r   r   r   s   extended: &lt;script&gt;r   r   r   s   extended: <script>r   r   r   r   r   r(   s     @r   test_extended_blockz"AutoEscapeTest.test_extended_block  s    DN++	? 	? 	? 	? 	? 	 @AACTUUUF5668S	
 	
 	
 	F3446M	
 	
 	
 	F5668M	
 	
 	
 	
 	
r   c                 x    t          | j                  fd}|                      |d          d           d S )Nc                 V                         |                               d          S )Nz<>&"r   r   r   s    r   r   z2AutoEscapeTest.test_raw_expression.<locals>.render  s&    ;;t$$--6-:::r   r   s#   expr: &lt;&gt;&amp;&quot;
raw: <>&"r   r   s     @r   test_raw_expressionz"AutoEscapeTest.test_raw_expression  s`    DN++	; 	; 	; 	; 	; 	F())+V	
 	
 	
 	
 	
r   c                     t          ddi           fdfd}                      |dd          d                                 |dd          d                                 |dd	g          d
           d S )Nzfoo.pyz){% autoescape py_escape %}s = {{ name }}
c                                          t          |           t                     t          t	          |                     S rO   )r   typebytesreprr   )rS   r   s    r   	py_escapez4AutoEscapeTest.test_custom_escape.<locals>.py_escape  s3    T!WWe,,,
1&&&r   c                 X                         |                               |          S )N)r   r   r   )r   r   r(   r   s     r   r   z1AutoEscapeTest.test_custom_escape.<locals>.render  s(    ;;x((11ID1QQQr   z<html>s   s = '<html>'
z';sys.exit()s   s = "';sys.exit()"
znot a strings   s = "['not a string']"
)r   r   )r   r   r(   r   s   ` @@r   test_custom_escapez!AutoEscapeTest.test_custom_escape  s    X'STUU	' 	' 	' 	' 	'	R 	R 	R 	R 	R 	R 	(335FGGG.99;VWWWF8n-..0O	
 	
 	
 	
 	
r   c                     t          ddi          }|                     |                    d                              t	          d                    d           d S )Nzfoo.txtzG{% for i in items
  %}{% if i > 0 %}, {% end %}{#
  #}{{i
  }}{% end
%}r_   )itemss   0, 1, 2, 3, 4)r   r   r&   r   ranger'   s     r   test_manual_minimize_whitespacez.AutoEscapeTest.test_manual_minimize_whitespace  sm      	
 	
 	KK	""++%((+;;=M	
 	
 	
 	
 	
r   c                 ~   t          dddddd          }|                     |                    d                                          d           |                     |                    d	                                          d
           |                     |                    d                                          d           |                     |                    d                                          d           |                     |                    d                                          d           d S )Nz   
	
 asdf	   z 


	 qwer     z	    zxcv

z  {% include baz.txt %} 
 z		{% include foo.html %}    )r   bar.jsbaz.txtr   include.txtr   s   
asdf r   s   
qwer r   s   	    zxcv

r   s    	    zxcv


r   s   		
asdf     r%   r'   s     r   test_whitespace_by_filenamez*AutoEscapeTest.test_whitespace_by_filename  s   1/+ =? 
 
 	Z0099;;ZHHHX..7799:FFFY//88::<MNNN 	^44==??AUVVV]33<<>>@RSSSSSr   c                 :   ddd}t          |d          }|                     |                    d                                          d           |                     |                    d                                          d	           t          |d
          }|                     |                    d                                          d           |                     |                    d                                          d           t          |d          }|                     |                    d                                          d           |                     |                    d                                          d           d S )Nz		foo

z		bar

)r   bar.txtall)
whitespacer   s   		foo

r   s   		bar

singles    foo
s    bar
onelines    foo s    bar r%   )r   r   r(   s      r   test_whitespace_by_loaderz(AutoEscapeTest.test_whitespace_by_loader  s_   !.=II	I%888Z0099;;^LLLY//88::NKKKI(;;;Z0099;;YGGGY//88::IFFFI)<<<Z0099;;XFFFY//88::HEEEEEr   c                     t          ddi          }|                     |                    d                                          d           d S )Nr   zz{% whitespace oneline %}
    {% for i in range(3) %}
        {{ i }}
    {% end %}
{% whitespace all %}
    pre	formatted
s     0  1  2  
    pre	formatted
r%   r'   s     r   test_whitespace_directivez(AutoEscapeTest.test_whitespace_directive  s`     	
 
 	KK
##,,..0T	
 	
 	
 	
 	
r   N)r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r5   r   r   r   r   :  s        $
 $
 $
L
 
 
(
 
 
(	
 	
 	

 
 
$
 
 

 
 
 
 
 
$T T T.F F F
 
 
 
 
r   r   c                       e Zd Zd Zd ZdS )TemplateLoaderTestc                     t          t          j                            t          j                            t
                    d                    | _        d S )Nr   )r	   osr   ri   dirname__file__r(   r:   s    r   r   zTemplateLoaderTest.setUp
  s3    RW\\"'//(*C*C[QQRRr   c                     | j                             d          }|                                }|                     t	          |                                          d           d S )Nz	utf8.htmlu   Héllo)r(   r&   r   r   r   strip)r   tmplrk   s      r   test_utf8_in_filez$TemplateLoaderTest.test_utf8_in_file  sT    {,,F++1133\BBBBBr   N)r|   r}   r~   r   r  r5   r   r   r   r   	  s:        S S SC C C C Cr   r   )r   r   r   tornado.escaper   r   r   tornado.templater   r   r   r	   tornado.utilr
   typingTestCaser   r   r   r   r   r5   r   r   <module>r
     s   				      7 7 7 7 7 7 7 7 7 7 E E E E E E E E E E E E # # # # # # tM tM tM tM tM8$ tM tM tMneY eY eY eY eYX& eY eY eYPD D D D D8, D D DL
 L
 L
 L
 L
X& L
 L
 L
^C C C C C* C C C C Cr   