관리-도구
편집 파일: sandbox.cpython-39.pyc
a ������+b�8����������������������@���s���U�d�Z�ddlZddlZddlZddlmZ�ddlmZ�ddlm Z �ddl mZ�ddlm Z �ddlmZ�d d lmZ�d dlmZ�d dlmZ�d d lmZ�ejdejdejf�d�ZdZe��Zeje�ed<�e��Z eje�ed<�ddhZ!ddhZ"ddhZ#ej$e%g�d��fej&e%g�d��fej'e%g�d��fe e%g�d��ffZ(ej)ej)ej*ej+e�f�df�ed<�ejej,e�d�d d!�Z-e.e/d"�d#d$�Z0eed%�d&d'�Z1ejee2d(�d)d*�Z3ejee2d(�d+d,�Z4G�d-d.��d.e�Z5G�d/d0��d0e5�Z6G�d1d2��d2e�Z7G�d3d4��d4e7e �Z8dS�)5z�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)� 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)r���r����popitem� setdefaultr���)�append�reverse�insert�sort�extendr���) r!���� appendleftr���r%���� extendleftr����popleftr����rotate� _mutable_spec)�callable�returnc�����������������C���s8���t�|�tjtjf�r|�jdvr d�S�|�j}t�|t�r4|S�d�S�)N)�format� format_map)� isinstance�types� MethodType�BuiltinMethodType�__name__�__self__�str)r+����obj��r7����B/usr/lib/python3.9/site-packages/ansible/_vendor/jinja2/sandbox.py�inspect_format_methodS���s������ r9���)�argsr,���c������������������G���s(���t�|���}t|�tkr$tdt��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:����rngr7���r7���r8���� safe_rangea���s������r@���)�fr,���c�����������������C���s ���d|�_�|�S�)z�Marks a function or method as unsafe. .. code-block: python @unsafe def delete(self): pass T)�unsafe_callable)rA���r7���r7���r8����unsafep���s���� rC���)r6����attrr,���c�����������������C���s����t�|�tj�r|tv�r�dS�n�t�|�tj�r<|tv�s6|tv�r�dS�n�t�|�t�rT|dkr�dS�nzt�|�tjtjtj f�rndS�t�|�tj �r�|tv�r�dS�nFttd�r�t�|�tj �r�|tv�r�dS�n"ttd�r�t�|�tj�r�|tv�r�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�__)r/���r0����FunctionTyper���r1���r����type�CodeType� TracebackType� FrameType� GeneratorType�UNSAFE_GENERATOR_ATTRIBUTES�hasattrrF����UNSAFE_COROUTINE_ATTRIBUTESrG����!UNSAFE_ASYNC_GENERATOR_ATTRIBUTES� startswith)r6���rD���r7���r7���r8����is_internal_attribute}���s.���� �rT���c�����������������C���s(���t�D�]\}}t|�|�r||v���S�qdS�)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*���r/���)r6���rD���ZtypespecrC���r7���r7���r8����modifies_known_mutable����s���� rU���c�����������������������s���e�Zd�ZU�dZdZejejejej ej ejejd�Z ejeejejejgejf�f�ed<�ejejd�Zejeejejgejf�f�ed<�e��Zeje�ed<�e��Zeje�ed<�ejejd d ���fdd�Zejeejed �dd�Zejed�dd�Zeeejejejd�dd�Z eeejejd�dd�Z!ejej"eejf�ej"eje#f�d�dd�Z$ejeej"eje#f�d�dd�Z%ejee#d�dd �Z&d(eej'ejd!f�ejeejf�ej(ej�ed"�d#d$�Z)eejejejejd%�d&d'�Z*���Z+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)rW���rX����default_unop_table�intercepted_binops�intercepted_unopsN)r:����kwargsr,���c��������������������s8���t���j|i�|���t|�jd<�|�j���|�_|�j���|�_d�S�)Nr;���) �super�__init__r@����globalsr\����copy�binop_tabler]���� unop_table)�selfr:���r`����� __class__r7���r8���rb�������s���� zSandboxedEnvironment.__init__�r6���rD����valuer,���c�����������������C���s���|��d�pt||��S�)aY��The 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. �_)rS���rT����rg���r6���rD���rk���r7���r7���r8����is_safe_attribute��s����z&SandboxedEnvironment.is_safe_attribute)r6���r,���c�����������������C���s���t�|dd�pt�|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``. rB���FZalters_data)�getattr)rg���r6���r7���r7���r8����is_safe_callable��s�����z%SandboxedEnvironment.is_safe_callable)�context�operator�left�rightr,���c�����������������C���s���|�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 )re���)rg���rq���rr���rs���rt���r7���r7���r8���� call_binop��s���� zSandboxedEnvironment.call_binop)rq���rr����argr,���c�����������������C���s���|�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 )rf���)rg���rq���rr���rv���r7���r7���r8���� call_unop!��s����zSandboxedEnvironment.call_unop)r6����argumentr,���c�����������������C���s����z ||�W�S��t�tfy����t|t�r�zt|�}W�n�tyD���Y�nJ0�zt||�}W�n�tyf���Y�n(0�|��|||�r~|�Y�S�|��||��Y�S�Y�n0�|�j ||d�S�)z(Subscribe an object from sandboxed code.�r6����name) � TypeError�LookupErrorr/���r5���� Exceptionro����AttributeErrorrn����unsafe_undefined� undefined)rg���r6���rx���rD���rk���r7���r7���r8����getitem*��s ���� zSandboxedEnvironment.getitem)r6���� attributer,���c�����������������C���st���zt�||�}W�n8�tyF���z||�W��Y�S��ttfy@���Y�n0�Y�n 0�|��|||�rZ|S�|��||�S�|�j||d�S�)z�Subscribe an object from sandboxed code and prefer the attribute. The attribute passed *must* be a bytestring. ry���)ro���r~���r{���r|���rn���r���r����)rg���r6���r����rk���r7���r7���r8���ro���A��s����zSandboxedEnvironment.getattrc�����������������C���s&���|�j�d|�dt|�j�d�||td�S�)z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)rz���r6����exc)r����rJ���r3���r ���)rg���r6���r����r7���r7���r8���r���R��s������z%SandboxedEnvironment.unsafe_undefined.)�sr:���r`����format_funcr,���c�����������������C���s����t�|t�rt|�|jd�}nt|��}|durl|jdkrlt|�dksD|r`tdt|�|du���d���|d�}d}|�|||�}t |�|�S�) z�If a format call is detected, then this is routed through this method so that our safety sandbox can be used for it. )�escapeNr.���r���z(format_map() takes exactly one argument z givenr���r7���) r/���r����SandboxedEscapeFormatterr�����SandboxedFormatterr3���r<���r{���ZvformatrJ���)rg���r����r:���r`���r����� formatter�rvr7���r7���r8���� format_string\��s���� ��z"SandboxedEnvironment.format_string)�_SandboxedEnvironment__context�_SandboxedEnvironment__objr:���r`���r,���c�����������������O���sP���t�|�}|dur |��||||�S�|��|�s8t|�d���|j|g|�R�i�|��S�)z#Call an object from sandboxed code.Nz is not safely callable)r9���r����rp���r ����call)Z_SandboxedEnvironment__selfr����r����r:���r`����fmtr7���r7���r8���r����y��s���� zSandboxedEnvironment.call)N),r3���� __module__�__qualname__�__doc__Z sandboxedrr���r����sub�mul�truediv�floordiv�pow�modr\����t�Dictr5����Callable�Any�__annotations__�pos�negr]���� frozensetr^���� FrozenSetr_���rb����boolrn���rp���r���ru���rw����Unionr���r����ro���r����Tuple�Optionalr����r����� __classcell__r7���r7���rh���r8���rV�������sR��� �,�( � � �� ��rV���c�����������������������s0���e�Zd�ZdZejeejed���fdd�Z���Z 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. rj���c��������������������s ���t����|||�sdS�t||��S�)NF)ra���rn���rU���rm���rh���r7���r8���rn������s����z/ImmutableSandboxedEnvironment.is_safe_attribute) r3���r����r����r����r����r����r5���r����rn���r����r7���r7���rh���r8���r�������s���r����c�����������������������s\���e�Zd�Zeejdd���fdd�Zeejej�ej eejf�ej ejef�d�dd�Z���ZS�)r����N)�envr`���r,���c��������������������s���||�_�t��jf�i�|���d�S��N)�_envra���rb���)rg���r����r`���rh���r7���r8���rb������s����zSandboxedFormatter.__init__)� field_namer:���r`���r,���c����������� ������C���sR���t�|�\}}|��|||�}|D�]*\}}|r:|�j�||�}q|�j�||�}q||fS�r����)r���Z get_valuer����ro���r����) rg���r����r:���r`����first�restr6���Zis_attr�ir7���r7���r8���� get_field���s����zSandboxedFormatter.get_field) r3���r����r����r ���r����r����rb���r5����Sequence�Mappingr����r����r����r7���r7���rh���r8���r�������s����r����c�������������������@���s���e�Zd�ZdS�)r����N)r3���r����r����r7���r7���r7���r8���r�������s���r����)9r����rr���r0����typingr����Z_stringr����collectionsr���r����stringr���Z markupsafer���r���Zenvironmentr ���� exceptionsr ���Zruntimer���r����TypeVarr����r����r ���r=����setr����Setr5���r����r���rO���rQ���rR���� MutableSetr�����MutableMapping�MutableSequencer*���r�����Typer����r����r9����intr;���r@���rC���r����rT���rU���rV���r����r����r����r7���r7���r7���r8����<module>���s^����� � ����(+ %�R