%PDF- %PDF-
Direktori : /opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/ |
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/sandbox.cpython-37.pyc |
B ��R�4 � @ s4 d Z ddlZddlmZ ddlmZ ddlmZmZm Z m Z mZmZm Z mZ dZeddd d dg�Zedd dg�Zeddg�Zes�e� ZddlZejddedd� ddlmZ efZefZefZy6ddlmZmZ ddl m Z eeef7 Zee f7 ZW n e!k �r Y nX yddl"m#Z# ee#f7 ZW n e!k �r< Y nX y6ddlm$Z$m%Z%m&Z& ee$f7 Zee%f7 Zee&f7 ZW n e!k �r� Y nX ee'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,G d5d6� d6e�Z-G d7d8� 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�� Zfunc_closureZ func_codeZ func_dictZ func_defaultsZfunc_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�rotatec 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)�range�len� MAX_RANGE� OverflowError)�args�rng� r1 �?/opt/alt/python37/lib/python3.7/site-packages/jinja2/sandbox.py� safe_range` s r3 c C s d| _ | S )znMarks a function or method as unsafe. :: @unsafe def delete(self): pass T)�unsafe_callable)�fr1 r1 r2 �unsafek s r6 c C s� t | t�r|tkrzdS nbt | t�r8|tks2|tkrzdS nBt | t�rP|dkrzdS n*t | tttf�rddS t | 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�typer r r r �UNSAFE_GENERATOR_ATTRIBUTES� startswith)�obj�attrr1 r1 r2 �is_internal_attributex s rA c C s( x"t D ]\}}t| |�r||kS qW dS )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@ Ztypespecr6 r1 r1 r2 �modifies_known_mutable� s rC c @ s� e Zd ZdZdZejejejej ej ejejd�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**�%)rE rF 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 Fr1 )�self�operatorr1 r1 r2 �intercept_unop� s z#SandboxedEnvironment.intercept_unopc O s8 t j| f|�|� t| jd<