%PDF- %PDF-
Mini Shell

Mini Shell

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

B

��R�4�@s4dZddlZddlmZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
mZdZeddd	d
dg�Zedd
dg�Zeddg�Zes�e�ZddlZejddedd�ddlmZefZefZefZy6ddlmZmZddl m Z eeef7Zee f7ZWne!k
�r
YnXyddl"m#Z#ee#f7ZWne!k
�r<YnXy6ddlm$Z$m%Z%m&Z&ee$f7Zee%f7Zee&f7ZWne!k
�r�YnXee'ddddddd d!g�fee'ddd"d#d!g�fee'd$d%d&d'd(dg�fee'd$d)dd(d*dd+dd,g	�ffZ(d-d.�Z)d/d0�Z*d1d2�Z+d3d4�Z,Gd5d6�d6e�Z-Gd7d8�d8e-�Z.dS)9aj
    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) 2010 by the Jinja Team.
    :license: BSD.
�N)�Environment)�
SecurityError)�string_types�
function_type�method_type�traceback_type�	code_type�
frame_type�generator_type�PY2i��Zfunc_closureZ	func_codeZ	func_dictZ
func_defaultsZfunc_globalsZim_classZim_funcZim_self�gi_frame�gi_code�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�rotatecGs$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)�range�len�	MAX_RANGE�
OverflowError)�args�rng�r1�?/opt/alt/python37/lib/python3.7/site-packages/jinja2/sandbox.py�
safe_range`s
r3cCs
d|_|S)znMarks a function or method as unsafe.

    ::

        @unsafe
        def delete(self):
            pass
    T)�unsafe_callable)�fr1r1r2�unsafeks	r6cCs�t|t�r|tkrzdSnbt|t�r8|tks2|tkrzdSnBt|t�rP|dkrzdSn*t|tttf�rddSt|t	�rz|t
krzdS|�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(lambda: None, "func_code")
    True
    >>> is_internal_attribute((lambda x:x).func_code, 'co_code')
    True
    >>> is_internal_attribute(str, "upper")
    False
    T�mro�__)�
isinstancer�UNSAFE_FUNCTION_ATTRIBUTESr�UNSAFE_METHOD_ATTRIBUTES�typerrr	r
�UNSAFE_GENERATOR_ATTRIBUTES�
startswith)�obj�attrr1r1r2�is_internal_attributexs 



rAcCs(x"tD]\}}t||�r||kSqWdS)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_specr9)r?r@Ztypespecr6r1r1r2�modifies_known_mutable�s
rCc@s�eZdZdZdZejejejej	ej
ejejd�Z
ejejd�Ze�Ze�Zdd�Zdd�Zd	d
�Zdd�Zd
d�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 occour during the rendering so
    the caller has to ensure that all exceptions are catched.
    T)�+�-�*�/z//z**�%)rErFcCsdS)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
        Fr1)�self�operatorr1r1r2�intercept_unop�sz#SandboxedEnvironment.intercept_unopcOs8tj|f|�|�t|jd<|j��|_|j��|_dS)Nr+)	r�__init__r3�globals�default_binop_table�copy�binop_table�default_unop_table�
unop_table)rJr/�kwargsr1r1r2rMs
zSandboxedEnvironment.__init__cCs|�d�pt||�S)aYThe sandboxed environment will call this method to check if the
        attribute of an object is safe to access.  Per default all attributes
        starting with an underscore are considered private as well as the
        special attributes of internal python objects as returned by the
        :func:`is_internal_attribute` function.
        �_)r>rA)rJr?r@�valuer1r1r2�is_safe_attributesz&SandboxedEnvironment.is_safe_attributecCst|dd�pt|dd�S)aCheck if an object is safely callable.  Per default a function is
        considered safe unless the `unsafe_callable` attribute exists and is
        True.  Override this method to alter the behavior, but this won't
        affect the `unsafe` decorator from this module.
        r4FZalters_data)�getattr)rJr?r1r1r2�is_safe_callablesz%SandboxedEnvironment.is_safe_callablecCs|j|||�S)z�For intercepted binary operator calls (:meth:`intercepted_binops`)
        this function is executed instead of the builtin operator.  This can
        be used to fine tune the behavior of certain operators.

        .. versionadded:: 2.6
        )rQ)rJ�contextrK�left�rightr1r1r2�
call_binopszSandboxedEnvironment.call_binopcCs|j||�S)z�For intercepted unary operator calls (:meth:`intercepted_unops`)
        this function is executed instead of the builtin operator.  This can
        be used to fine tune the behavior of certain operators.

        .. versionadded:: 2.6
        )rS)rJrZrK�argr1r1r2�	call_unop'szSandboxedEnvironment.call_unopcCs�y||Sttfk
r�t|t�r�yt|�}Wntk
rFYnDXyt||�}Wntk
rjYn X|�|||�r~|S|�	||�SYnX|j
||d�S)z(Subscribe an object from sandboxed code.)r?�name)�	TypeError�LookupErrorr9r�str�	ExceptionrX�AttributeErrorrW�unsafe_undefined�	undefined)rJr?Zargumentr@rVr1r1r2�getitem0s 
zSandboxedEnvironment.getitemcCsryt||�}Wn6tk
rDy||Sttfk
r>YnXYn X|�|||�rX|S|�||�S|j||d�S)z�Subscribe an object from sandboxed code and prefer the
        attribute.  The attribute passed *must* be a bytestring.
        )r?r`)rXrerarbrWrfrg)rJr?�	attributerVr1r1r2rXEszSandboxedEnvironment.getattrcCs|jd||jjf||td�S)z1Return an undefined object for unsafe attributes.z.access to attribute %r of %r object is unsafe.)r`r?�exc)rg�	__class__�__name__r)rJr?rir1r1r2rfVs
z%SandboxedEnvironment.unsafe_undefinedcOs*|�|�std|f��|j|f|�|�S)z#Call an object from sandboxed code.z%r is not safely callable)rYr�call)Z_SandboxedEnvironment__selfZ_SandboxedEnvironment__contextZ_SandboxedEnvironment__objr/rTr1r1r2rm^s
zSandboxedEnvironment.callN)rl�
__module__�__qualname__�__doc__Z	sandboxedrKr�sub�mul�truediv�floordiv�pow�modrO�pos�negrR�	frozensetZintercepted_binopsZintercepted_unopsrLrMrWrYr]r_rhrXrfrmr1r1r1r2rD�s.	

				rDc@seZdZdZdd�ZdS)�ImmutableSandboxedEnvironmentz�Works exactly like the regular `SandboxedEnvironment` but does not
    permit modifications on the builtin mutable objects `list`, `set`, and
    `dict` by using the :func:`modifies_known_mutable` function.
    cCs t�||||�sdSt||�S)NF)rDrWrC)rJr?r@rVr1r1r2rWmsz/ImmutableSandboxedEnvironment.is_safe_attributeN)rlrnrorprWr1r1r1r2rzgsrz)/rprKZjinja2.environmentrZjinja2.exceptionsrZjinja2._compatrrrrrr	r
rr-�setr:r;r=�warnings�filterwarnings�DeprecationWarning�collectionsrZ_mutable_set_types�dictZ_mutable_mapping_types�listZ_mutable_sequence_typesrrr�ImportErrorZsetsrrrrryrBr3r6rArCrDrzr1r1r1r2�<module>sl(





 4

Zerion Mini Shell 1.0