%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/jinja2/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/jinja2/__pycache__/sandbox.cpython-312.pyc

�

Ab{g�:��|�UdZddlZddlZddlZddlmZddlmZ	ddl	m
Z
ddlm
Z
ddlmZddlmZdd	lmZd
dlmZd
dlmZd
d
lmZd
dlmZej4dej6dej8f��ZdZe�Z ejBe"e#d<e�Z$ejBe"e#d<ddhZ%ddhZ&ddhZ'ejPe)gd��fejTe)gd��fejVe)gd��fe
e)gd��ffZ,ejZejZej\ej^e"fdfe#d<d e0d!e1fd"�Z2d#ed!efd$�Z3d%ej8d&e"d!e4fd'�Z5d%ej8d&e"d!e4fd(�Z6Gd)�d*e�Z7Gd+�d,e7�Z8Gd-�d.e�Z9Gd/�d0e9e�Z:y#e$r
ddlm
Z
Y���wxYw)1z�A sandbox layer that ensures unsafe operations cannot be performed.
Useful when the template itself comes from an untrusted source.
�N)�formatter_field_name_split)�abc)�deque)�update_wrapper)�	Formatter)�EscapeFormatter)�Markup�)�Environment)�
SecurityError)�Context)�	Undefined�F.)�boundi���UNSAFE_FUNCTION_ATTRIBUTES�UNSAFE_METHOD_ATTRIBUTES�gi_frame�gi_code�cr_frame�cr_code�ag_code�ag_frame)�add�clear�difference_update�discard�pop�remove�symmetric_difference_update�update)rr�popitem�
setdefaultr )�append�reverse�insert�sort�extendr)	r#�
appendleftrr'�
extendleftr�popleftr�rotate�
_mutable_spec�args�returnc�`�t|�}t|�tkDrtdt�d���|S)zWA range that can't generate ranges with a length of more than
    MAX_RANGE items.
    z@Range too big. The sandbox blocks ranges larger than MAX_RANGE (z).)�range�len�	MAX_RANGE�
OverflowError)r-�rngs  �0/usr/lib/python3/dist-packages/jinja2/sandbox.py�
safe_ranger6Ws>����,�C�
�3�x�)���
�$�+�R�
)�
�	
�
�J��fc��d|_|S)z�Marks a function or method as unsafe.

    .. code-block: python

        @unsafe
        def delete(self):
            pass
    T)�unsafe_callable)r8s r5�unsafer;fs���A���Hr7�obj�attrc�t�t|tj�r
|tv�ryt|tj�r|tvs|t
vr�yt|t�r|dk(r�yt|tjtjtjf�ryt|tj�r	|tvrgyttd�r#t|tj�r	|tvr4yttd�r#t|tj�r	|t vry|j#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�FunctionTyper�
MethodTyper�type�CodeType�
TracebackType�	FrameType�
GeneratorType�UNSAFE_GENERATOR_ATTRIBUTES�hasattrr@�UNSAFE_COROUTINE_ATTRIBUTESrA�!UNSAFE_ASYNC_GENERATOR_ATTRIBUTES�
startswith)r<r=s  r5�is_internal_attributerQss����#�u�)�)�*��-�-��	�C��)�)�	*��-�-��9Q�1Q��	�C��	��5�=��	�C�%�.�.�%�*=�*=�u���O�	P��	�C��,�,�	-��.�.��	���	(�Z��U�=P�=P�-Q��.�.��	��,�	-�*��U�
%�
%�3��4�4���?�?�4� � r7c�D�tD]\}}t||�s�||vcSy)a�This function checks if an attribute on a builtin mutable object
    (list, dict, set or deque) or the corresponding ABCs would modify it
    if called.

    >>> 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, ``False`` is returned.

    >>> modifies_known_mutable("foo", "upper")
    False
    F)r,rC)r<r=�typespecr;s    r5�modifies_known_mutablerT�s1��&*�"���&��c�8�$��6�>�!�"�r7c
�\��eZdZUdZdZejejejejejejejd�Z
ejeej"ej$ej$gej$ffed<ej(ej*d�Zejeej"ej$gej$ffed<e�Zej2eed<e�Zej2eed<d	ej$d
ej$ddf�fd
�Zdej$dedej$defd�Zdej$defd�Zdededej$dej$dej$f
d�Z dededej$dej$fd�Z!dej$dejDeej$fdejDej$e#ffd�Z$dej$dedejDej$e#ffd�Z%dej$dede#fd�Z&dej$dejNej"deffd �Z(d!ed"ej$d	ej$d
ej$dej$f
d#�Z)�xZ*S)$�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**�%�default_binop_table)rWrX�default_unop_table�intercepted_binops�intercepted_unopsr-�kwargsr.Nc����t�|�|i|��t|jd<|jj�|_|jj�|_y)Nr0)	�super�__init__r6�globalsr\�copy�binop_tabler]�
unop_table)�selfr-r`�	__class__s   �r5rczSandboxedEnvironment.__init__�sP���
���$�)�&�)� *����W���3�3�8�8�:����1�1�6�6�8��r7r<r=�valuec�B�|jd�xst||�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.
        �_)rPrQ)rhr<r=rjs    r5�is_safe_attributez&SandboxedEnvironment.is_safe_attribute�s#���O�O�C�(�L�,A�#�t�,L�M�Mr7c�<�t|dd�xs
t|dd�S)z�Check if an object is safely callable. By default callables
        are considered safe unless decorated with :func:`unsafe`.

        This also recognizes the Django convention of setting
        ``func.alters_data = True``.
        r:F�alters_data)�getattr)rhr<s  r5�is_safe_callablez%SandboxedEnvironment.is_safe_callables*��
�C�*�E�2�X�g�c�=�RW�6X�
�	
r7�context�operator�left�rightc�.�|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
        )rf)rhrrrsrtrus     r5�
call_binopzSandboxedEnvironment.call_binops��*�t����)�$��6�6r7�argc�,�|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
        )rg)rhrrrsrxs    r5�	call_unopzSandboxedEnvironment.call_unops��)�t���x�(��-�-r7�argumentc�p�	||S#ttf$r�t|t�ry	t|�}	t	||�}|j|�}|�|cYS|j
|||�r|cYS|j||�cYS#t$rYnwxYw#t$rYnwxYwYnwxYw|j||��S)z(Subscribe an object from sandboxed code.�r<�name)�	TypeError�LookupErrorrC�strrp�wrap_str_formatrm�unsafe_undefined�AttributeError�	Exception�	undefined)rhr<r{r=rj�fmts      r5�getitemzSandboxedEnvironment.getitem s���	D��x�=� ���;�'�	D��(�C�(�D��x�=�D�
D� '��T� 2��#�2�2�5�9���?�#&�J��1�1�#�x��G�#(�L�#�4�4�S�(�C�C��*�����!�����		D��$�~�~�#�H�~�5�5sZ��B"�B�B�B"�B"�-B"�	B
�
B"�B
�
B"�	B�B"�B�B"�!B"�	attributec��	t||�}|j|�}|�|S|j|||�r|S|j||�S#t$r 	||cYS#t
tf$rYnwxYwYnwxYw|j||��S)z�Subscribe an object from sandboxed code and prefer the
        attribute.  The attribute passed *must* be a bytestring.
        r})rpr�rmr�r�rr�r�)rhr<r�rjr�s     r5rpzSandboxedEnvironment.getattr:s���
	9��C��+�E��&�&�u�-�C����
��%�%�c�9�e�<����(�(��i�8�8���	�
��9�~�%���{�+�
��
���		���~�~�#�I�~�6�6s5�A
�
	A3�A�A3�A-�*A3�,A-�-A3�2A3c�h�|jd|�dt|�j�d�||t��S)z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)r~r<�exc)r�rG�__name__r)rhr<r�s   r5r�z%SandboxedEnvironment.unsafe_undefinedNsE���~�~�"�9�-�0��S�	�"�"�%�%7�
9�����
�	
r7.c�������t|tjtjf�r|jdvry|j
�t�t�syt���|jdk(�t�t�rt|�j��}nt|�}|j�dtjdtjdtf����fd�}t||�S)	aIf the given value is a ``str.format`` or ``str.format_map`` method,
        return a new function than handles sandboxing. This is done at access
        rather than in :meth:`call`, so that calls made without ``call`` are
        also sandboxed.
        )�format�
format_mapNr�)�escaper-r`r.c����r:|rtd��t|�dk7rtdt|��d���|d}d}���||��S)Nz'format_map() takes no keyword argumentsr
z)format_map() takes exactly one argument (z given)r�)rr1)r-r`�f_self�
is_format_map�str_type�vformats  ����r5�wrapperz5SandboxedEnvironment.wrap_str_format.<locals>.wrapperssa�����#�$M�N�N��t�9��>�#�C�C��I�;�g�V����a������G�F�D�&�9�:�:r7)rCrDrF�BuiltinMethodTyper��__self__r�rGr	�SandboxedEscapeFormatterr��SandboxedFormatterr��t�Anyr)rhrj�	formatterr�r�r�r�r�s    @@@@r5r�z$SandboxedEnvironment.wrap_str_formatXs������E�$�$�e�&=�&=�>�
�
�^�^�#;�
;�������&�#�&�� $�V������,�6�
��f�f�%�0��f�m�m�L�I�*�4�0�I��#�#��
	;�1�5�5�
	;�A�E�E�
	;�c�
	;�
	;��g�u�-�-r7�_SandboxedEnvironment__context�_SandboxedEnvironment__objc�l�|j|�st|�d���|j|g|��i|��S)z#Call an object from sandboxed code.z is not safely callable)rqr�call)�_SandboxedEnvironment__selfr�r�r-r`s     r5r�zSandboxedEnvironment.call�s@���&�&�u�-��5�)�+B� C�D�D��y�~�~�e�5�d�5�f�5�5r7)+r��
__module__�__qualname__�__doc__�	sandboxedrsr�sub�mul�truediv�floordiv�pow�modr\r��Dictr��Callabler��__annotations__�pos�negr]�	frozensetr^�	FrozenSetr_rc�boolrmrqr
rwrz�Unionrr�rpr��Optionalr�r��
__classcell__�ris@r5rVrV�s������I��\�\�
�\�\�
�\�\�
�
�
�����l�l�
�\�\�K������Q�Z�Z�����������0E�%F� F�G���\�\�
�\�\�C�����s�A�J�J����w����~�$>�>�?��&,5�;�����C�(�6�+4�+��q�{�{�3�'�5�9�a�e�e�9�q�u�u�9��9�N�Q�U�U�N�#�N�a�e�e�N��N�	
�A�E�E�	
�d�	
�	7��	7�*-�	7�56�U�U�	7�CD�5�5�	7�	
���	7�.��.�C�.�a�e�e�.����.�6��5�5�6�$%�G�G�C����J�$7�6�	
������	�!�	"�6�47�1�5�5�7�S�7�Q�W�W�Q�U�U�I�=M�5N�7�(
�A�E�E�
�c�
�i�
�*.�Q�U�U�*.�q�z�z�!�*�*�S�#�X�:N�/O�*.�X
6��
6��u�u�
6��u�u�	
6�
�%�%�
6�
���

6r7rVc�\��eZdZdZdej
dedej
def�fd�Z�xZ	S)�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.
    r<r=rjr.c�B��t�|�|||�syt||�S)NF)rbrmrT)rhr<r=rjris    �r5rmz/ImmutableSandboxedEnvironment.is_safe_attribute�s'����w�(��d�E�:��)�#�t�4�4�4r7)
r�r�r�r�r�r�r�r�rmr�r�s@r5r�r��s6����
5�Q�U�U�5�#�5�a�e�e�5��5�5r7r�c
����eZdZdedej
ddf�fd�Zdedejej
dejeej
fdejej
effd�Z�xZS)	r��envr`r.Nc�2��||_t�|�di|��y)Nr�)�_envrbrc)rhr�r`ris   �r5rczSandboxedFormatter.__init__�s�����	�
���"�6�"r7�
field_namer-c���t|�\}}|j|||�}|D]@\}}|r|jj||�}�%|jj	||�}�B||fS)N)r�	get_valuer�rpr�)	rhr�r-r`�first�restr<�is_attr�is	         r5�	get_fieldzSandboxedFormatter.get_field�sr��1��<���t��n�n�U�D�&�1���	0�J�G�Q���i�i�'�'��Q�/���i�i�'�'��Q�/��		0�
�E�z�r7)
r�r�r�rr�r�rcr��Sequence�Mapping�Tupler�r�r�s@r5r�r��su���#�K�#�1�5�5�#�T�#�
��
�%&�Z�Z����%6�
�@A�	�	�#�q�u�u�*�@U�
�	
��������	�
r7r�c��eZdZy)r�N)r�r�r�r�r7r5r�r��s��r7r�);r�rsrD�typingr��_stringr�collectionsr�collections.abcr�ImportError�	functoolsr�stringr�
markupsaferr	�environmentr�
exceptionsr�runtimer
r�TypeVarr�r�rr2�setr�Setr�r�rrLrNrO�
MutableSetr��MutableMapping�MutableSequencer,r��Typer��intr0r6r;r�rQrTrVr�r�r�r�r7r5�<module>r�s������.��"�%�%��&��$�%���
�A�I�I�c����C����J�/�0��
�	�*-���A�E�E�#�J�.�(+�u��!�%�%��*�,� *�9�5�� *�9�5��&/�
�$;�!�	����	
�	
�� 	����E�F��
	����M�N��
	��

�	
��1(B�
�q�w�w�q�w�w�q�v�v�q�{�{�3�'7�7�8�#�=�>�(�V�c��e��

�a�

�A�

�"!�q�u�u�"!�C�"!�D�"!�J�����S��T��2`6�;�`6�F
5�$8�
5����$	�1�?�	��Q
�"�!�!�"�s�F,�,F;�:F;

Zerion Mini Shell 1.0