File: //snap/core20/2599/lib/python3/dist-packages/jinja2/__pycache__/sandbox.cpython-38.pyc
U
��g�E � @ s> d Z ddlZddlZzddlmZ W n ddlmZ Y nX ddlmZ ddlm Z ddl
mZ ddlm
Z
mZ ddlmZ dd lmZ dd
lmZ dZer�edd
dddg�Zne� Zedddg�Zeddg�Zeddg�Zeddg�ZddlZejddedd� zddlmZ W n" e k
�r6 ddlmZ Y nX efZ!e"fZ#e$fZ%z6ddl&m&Z&m'Z' dd l(m(Z( e#e&e'f7 Z#e!e(f7 Z!W n e k
�r� Y nX zdd!l)m*Z* e!e*f7 Z!W n e k
�r� Y nX zdd"lm+Z+m,Z,m-Z- W n dd"lm+Z+m,Z,m-Z- Y nX e!e+f7 Z!e#e,f7 Z#e%e-f7 Z%e!e.d#d$d%d&d'd(d)d*g�fe#e.d$d'd+d,d*g�fe%e.d-d.d/d0d1d(g�fee.d-d2d$d1d3d'd4d(d5g �ffZ/G d6d7� d7e�Z0d8d9� Z1d:d;� Z2d<d=� Z3d>d?� Z4G d@dA� dAe �Z5G dBdC� dCe5�Z6zddDl7m8Z8 W n e k
�r dEdF� Z8Y nX G dGdH� dHe9�Z:G dIdJ� dJe:e�Z;G dKdL� dLe:e�Z<dS )Maj
jinja2.sandbox
~~~~~~~~~~~~~~
Adds a sandbox layer to Jinja as it was the default behavior in the old
Jinja 1 releases. This sandbox is slightly different from Jinja 1 as the
default behavior is easier to use.
The behavior can be changed by subclassing the environment.
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
� N)�Mapping)�update_wrapper)�Environment)�
SecurityError)�string_types�PY2)�Markup)�EscapeFormatter)� Formatteri�� Zfunc_closureZ func_codeZ func_dictZ
func_defaultsZfunc_globalsZim_classZim_funcZim_self�gi_frame�gi_code�cr_frame�cr_code�ag_code�ag_frame�ignorezthe sets modulezjinja2.sandbox)�module)�deque)�UserDict� DictMixin)�UserList)�Set)�
MutableSet�MutableMapping�MutableSequence�add�clear�difference_update�discard�pop�remove�symmetric_difference_update�update�popitem�
setdefault�append�reverse�insert�sort�extend�
appendleft�
extendleft�popleft�rotatec @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�_MagicFormatMappingz�This class implements a dummy wrapper to fix a bug in the Python
standard library for string formatting.
See https://bugs.python.org/issue13598 for information about why
this is necessary.
c C s || _ || _d| _d S )Nr )�_args�_kwargs�_last_index��self�args�kwargs� r6 �0/usr/lib/python3/dist-packages/jinja2/sandbox.py�__init__ s z_MagicFormatMapping.__init__c C sP |dkrF| j }| j d7 _ z| j| W S tk
r< Y nX t|�}| j| S )N� � )r1 r/ �LookupError�strr0 )r3 �key�idxr6 r6 r7 �__getitem__� s z_MagicFormatMapping.__getitem__c C s
t | j�S �N)�iterr0 �r3 r6 r6 r7 �__iter__� s z_MagicFormatMapping.__iter__c C s
t | j�S r@ )�lenr0 rB r6 r6 r7 �__len__� s z_MagicFormatMapping.__len__N)�__name__�
__module__�__qualname__�__doc__r8 r? rC rE r6 r6 r6 r7 r. w s
r. c G s$ t | � }t|�tkr tdt ��|S )zWA range that can't generate ranges with a length of more than
MAX_RANGE items.
z+range too big, maximum size for range is %d)�rangerD � MAX_RANGE�
OverflowError)r4 �rngr6 r6 r7 �
safe_range� s �rN c C s
d| _ | S )znMarks a function or method as unsafe.
::
@unsafe
def delete(self):
pass
T)�unsafe_callable)�fr6 r6 r7 �unsafe� s rQ c C s� t | tj�r|tkr�dS n�t | tj�r<|tks6|tkr�dS n�t | t�rT|dkr�dS nzt | tjtjtj f�rndS t | tj
�r�|tkr�dS nFttd�r�t | tj
�r�|tkr�dS n"ttd�r�t | tj�r�|tkr�dS |�d�S )a� Test if the attribute given is an internal python attribute. For
example this function returns `True` for the `func_code` attribute of
python objects. This is useful if the environment method
:meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
>>> from jinja2.sandbox import is_internal_attribute
>>> is_internal_attribute(str, "mro")
True
>>> is_internal_attribute(str, "upper")
False
T�mro�
CoroutineType�AsyncGeneratorType�__)�
isinstance�types�FunctionType�UNSAFE_FUNCTION_ATTRIBUTES�
MethodType�UNSAFE_METHOD_ATTRIBUTES�type�CodeType�
TracebackType� FrameType�
GeneratorType�UNSAFE_GENERATOR_ATTRIBUTES�hasattrrS �UNSAFE_COROUTINE_ATTRIBUTESrT �!UNSAFE_ASYNC_GENERATOR_ATTRIBUTES�
startswith)�obj�attrr6 r6 r7 �is_internal_attribute� s. �
rh c C s( t D ]\}}t| |�r||k S qdS )a� This function checks if an attribute on a builtin mutable object
(list, dict, set or deque) would modify it if called. It also supports
the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and
with Python 2.6 onwards the abstract base classes `MutableSet`,
`MutableMapping`, and `MutableSequence`.
>>> modifies_known_mutable({}, "clear")
True
>>> modifies_known_mutable({}, "keys")
False
>>> modifies_known_mutable([], "append")
True
>>> modifies_known_mutable([], "index")
False
If called with an unsupported object (such as unicode) `False` is
returned.
>>> modifies_known_mutable("foo", "upper")
False
F)�
_mutable_specrV )rf rg ZtypespecrQ r6 r6 r7 �modifies_known_mutable� s
rj c @ s� e Zd ZdZdZejejejej ej
ejejd�Z
ejejd�Ze� Ze� Zdd� Zdd� Zd d
� Zdd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )�SandboxedEnvironmenta� The sandboxed environment. It works like the regular environment but
tells the compiler to generate sandboxed code. Additionally subclasses of
this environment may override the methods that tell the runtime what
attributes or functions are safe to access.
If the template tries to access insecure code a :exc:`SecurityError` is
raised. However also other exceptions may occur during the rendering so
the caller has to ensure that all exceptions are caught.
T)�+�-�*�/z//z**�%)rl rm c C s dS )a� Called during template compilation with the name of a unary
operator to check if it should be intercepted at runtime. If this
method returns `True`, :meth:`call_unop` is excuted for this unary
operator. The default implementation of :meth:`call_unop` will use
the :attr:`unop_table` dictionary to perform the operator with the
same logic as the builtin one.
The following unary operators are interceptable: ``+`` and ``-``
Intercepted calls are always slower than the native operator call,
so make sure only to intercept the ones you are interested in.
.. versionadded:: 2.6
Fr6 )r3 �operatorr6 r6 r7 �intercept_unop. s z#SandboxedEnvironment.intercept_unopc O s8 t j| f|�|� t| jd<