%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/__pycache__/security.cpython-37.pyc

B

,��Q<�@s�dZddlZddlmZddlmZddlmZmZm	Z	ddlm
Z
mZddlm
Z
mZmZddlmZGd	d
�d
e�ZGdd�de�ZGd
d�de�Zdd�ZdS)z�
    jinja2.testsuite.security
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Checks the sandbox and other security features.

    :copyright: (c) 2010 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
�N)�
JinjaTestCase)�Environment)�SandboxedEnvironment�ImmutableSandboxedEnvironment�unsafe)�Markup�escape)�
SecurityError�TemplateSyntaxError�TemplateRuntimeError)�	text_typec@s(eZdZdd�Zedd��Zdd�ZdS)�PrivateStuffcCsdS)N��)�selfrr�J/opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/security.py�barszPrivateStuff.barcCsdS)N�*r)rrrr�fooszPrivateStuff.foocCsdS)Nr
r)rrrr�__repr__!szPrivateStuff.__repr__N)�__name__�
__module__�__qualname__rrrrrrrrr
sr
c@s$eZdZdd�Zdd�Zdd�ZdS)�PublicStuffcCsdS)Nrr)rrrr�<lambda>&�zPublicStuff.<lambda>cCsdS)Nrr)rrrrr'rcCsdS)Nrr)rrrrr)szPublicStuff.__repr__N)rrrrZ_foorrrrrr%src@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�SandboxTestCasecCs�t�}|jt|�d�jt�d�|�|�d�jt�d�d�|jt|�d�jt�d�|�|�d�jt�d�d�|�|�d�jdd�d�|�|�d	�jd
d�d�d�|jt|�d�jdd�dS)
Nz{{ foo.foo() }})rz{{ foo.bar() }}Z23z{{ foo._foo() }}z{{ foo.__class__ }}r�z{{ foo.func_code }}cSsdS)Nrrrrrr9rz-SandboxTestCase.test_unsafe.<locals>.<lambda>z${{ foo.__class__.__subclasses__() }})r�
assert_raisesr	�from_string�renderr
Zassert_equalr)r�envrrr�test_unsafe/s


zSandboxTestCase.test_unsafecCs2t�}|�t|�d�j�|�t|�d�j�dS)Nz{{ [].append(23) }}z{{ {1:2}.clear() }})rrr	rr )rr!rrr�test_immutable_environment>s



z*SandboxTestCase.test_immutable_environmentcCs*t�}|�t|jd�|�t|jd�dS)Nz.{% for item.attribute in seq %}...{% endfor %}z,{% for foo, bar.baz in seq %}...{% endfor %})rrr
r)rr!rrr�test_restrictedEs


zSandboxTestCase.test_restrictedcCs�d}td�}||tt|��t|�ks,t�td�ddks@t�td�ddidksXt�ttd�d	�tkspt�td�}|��|ks�t�Gd
d�dt�}t|��dks�t�td
�|�dks�t�td�dks�t�td���dks�t�td���dks�t�dS)Nz?<script type="application/x-some-script">alert("foo");</script>z<em>username</em>z<em>%s</em>z
<bad user>z<em>&lt;bad user&gt;</em>z<em>%(username)s</em>Zusernamerrc@seZdZdd�Zdd�ZdS)z3SandboxTestCase.test_markup_operations.<locals>.FoocSsdS)Nz<em>awesome</em>r)rrrr�__html__bsz<SandboxTestCase.test_markup_operations.<locals>.Foo.__html__cSsdS)NZawesomer)rrrr�__unicode__dsz?SandboxTestCase.test_markup_operations.<locals>.Foo.__unicode__N)rrrr%r&rrrr�Fooasr'z<em>awesome</em>z<strong>%s</strong>z!<strong><em>awesome</em></strong>z"<>&'z&#34;&lt;&gt;&amp;&#39;z<em>Foo &amp; Bar</em>z	Foo & Barz&lt;test&gt;z<test>)	rrr�AssertionError�typer%�objectZ	striptagsZunescape)rrZsafe�xr'rrr�test_markup_operationsLs$ 



z&SandboxTestCase.test_markup_operationscCs|tdd�}|�d�}d}|��|ks(t�t|j�|ks:t�t|j�|ksLt�|j�d�|ks`t�t|j�d��|ksxt�dS)NT)Z
autoescapezf{% macro say_hello(name) %}<p>Hello {{ name }}!</p>{% endmacro %}{{ say_hello("<blink>foo</blink>") }}z,<p>Hello &lt;blink&gt;foo&lt;/blink&gt;!</p>z<blink>foo</blink>)rrr r(r�modulerZ	say_hello)rr!�tZescaped_outrrr�test_template_dataos

z"SandboxTestCase.test_template_datacCs&t�}|�d�}|jt|jtd�dS)Nz"{{ cls|attr("__subclasses__")() }})�cls)rrrr	r �int)rr!Ztmplrrr�test_attr_filter{s
z SandboxTestCase.test_attr_filtercCs�dd�}x�didfdddidffD]�\}}}t�}||jd	<|�d
|�}|�|�|ks\t�td	g�|_|�d
|�}y|�|�Wn"tk
r�}zWdd}~XYq"X|�d�q"WdS)NcSstd��dS)Nzthat operator so does not work)r)�left�rightrrr�
disable_op�szESandboxTestCase.test_binary_operator_intercepting.<locals>.disable_opz1 + 2�3za + 2�a��4�+z{{ %s }}zexpected runtime error)	rZbinop_tablerr r(�	frozensetZintercepted_binopsr�fail)rr5�expr�ctx�rvr!r.�errr�!test_binary_operator_intercepting�s$
z1SandboxTestCase.test_binary_operator_interceptingcCs�dd�}x�didfdddidffD]�\}}}t�}||jd<|�d	|�}|�|�|ks\t�tdg�|_|�d	|�}y|�|�Wn"tk
r�}zWdd}~XYq"X|�d
�q"WdS)NcSstd��dS)Nzthat operator so does not work)r)�argrrrr5�szDSandboxTestCase.test_unary_operator_intercepting.<locals>.disable_opz-1z-ar7r8z-2�-z{{ %s }}zexpected runtime error)	rZ
unop_tablerr r(r;Zintercepted_unopsrr<)rr5r=r>r?r!r.r@rrr� test_unary_operator_intercepting�s$
z0SandboxTestCase.test_unary_operator_interceptingN)rrrr"r#r$r,r/r2rArDrrrrr-s#rcCst��}|�t�t��|S)N)�unittestZ	TestSuiteZaddTestZ	makeSuiter)�suiterrrrF�srF)�__doc__rEZjinja2.testsuiterZjinja2rZjinja2.sandboxrrrrrZjinja2.exceptionsr	r
rZjinja2._compatrr*r
rrrFrrrr�<module>
s
v

Zerion Mini Shell 1.0