관리-도구
편집 파일: conditional.cpython-39.opt-1.pyc
a �����)g�'����������������������@���s����d�dl�mZmZmZ�eZd�dlZd�dlZd�dlm Z �d�dl mZ�d�dlm Z�d�dlmZmZmZ�d�dlmZ�d�dlmZmZ�d�d lmZ�d�d lmZ�e��Ze�d�Ze�d�Ze�d �Z G�dd��d�Z!dS�)�����)�absolute_import�division�print_functionN)�generate)�UndefinedError)� constants)�AnsibleError�AnsibleUndefinedVariable�AnsibleTemplateError)� text_type)� to_native�to_text)�FieldAttribute)�DisplayzF(hostvars\[.+\]|[\w_]+)\s+(not\s+is|is|is\s+not)\s+(defined|undefined)zlookup\s*\(z^[_A-Za-z][_a-zA-Z0-9]*$c�����������������������sR���e�Zd�ZdZededdd�Zd��fdd� Zdd ��Zd d��Z dd ��Z dd��Z���ZS�)�Conditionalz� This is a mix-in class, to be used with Base to allow the object to be run conditionally when a condition is met or skipped. �listT)Zisa�default�extendZprependNc��������������������s4���t�|�d�s"|d�u�rtd��n||�_tt|������d�S�)N�_loaderz<a loader must be specified when using Conditional() directly)�hasattrr���r����superr����__init__)�self�loader�� __class__���@/usr/lib/python3.9/site-packages/ansible/playbook/conditional.pyr���3���s ���� zConditional.__init__c�����������������C���s���t�|t�st|�||g��d�S��N)� isinstancer����setattr)r����attr�name�valuer���r���r����_validate_when>���s���� zConditional._validate_whenc�����������������C���sD���g�}|}t��|�}|r@|�|�����||���d���}t��|�}q|S�r���)� DEFINED_REGEX�search�append�groups�end)r����conditional�resultsZcond�mr���r���r����extract_defined_undefinedB���s���� z%Conditional.extract_defined_undefinedc�������������� ���C���s����d}t�|�d�rt|�d�}d}zf|�jD�]Z}|du�s8|dkr>d}nt|t�rN|}n|��|||�}|rd|}t�d||f���|s$�q�q$W�n@�ty��}�z(t dt |�t |�f�|d��W�Y�d}~n d}~0�0�|S�)z} Loops through the conditionals set on this object, returning False if any of them evaluate as such. NZ_dsT��zEvaluated conditional (%s): %sz4The conditional check '%s' failed. The error was: %s)�obj)r����getattr�whenr����bool�_check_conditional�display�debug� Exceptionr���r���)r����templar�all_varsZds�resultr*����res�er���r���r����evaluate_conditionalN���s&���� 2z Conditional.evaluate_conditionalc��������������������s*���}|����rt�d����||_�zt�d��|j��d��t�t�rP�dkrV�W�S�t�d�rhtd��G�����fdd�dt j ���zB|j��dd�}t ||jdd�}t j|d d �}����}|�|��W�n4�ty��}�ztdt|����W�Y�d}~n d}~0�0�d��} |j| �d����} | d k�r$W�dS�| dk�r4W�dS�td|���W�n��ttf�y$�}�z�z�t�d��t|�����d�}|����}|D�]`\} }}|�dd�| �dd�k�r�d|v�|dkk}|�r��W�W�Y�d}~dS��W�W�Y�d}~dS��q���W�n$�t�y���td||f���Y�n0�W�Y�d}~n d}~0�0�dS�)z� This method does the low-level evaluation of each conditional set on this object, using jinja2 to wrap the conditionals for evaluation. zjconditional statements should not include jinja2 templating delimiters such as {{ }} or {%% %%}. Found: %sZ __UNSAFE__)�disable_lookupsr.���z9Conditional is marked as unsafe, and cannot be evaluated.c�����������������������s���e�Zd�Zd����fdd� ZdS�)z<Conditional._check_conditional.<locals>.CleansingNodeVisitorFc��������������������s����t�|tj�rd}ndt�|tj�r$d}nRt�|tj�rv�rv|rR|j�d�rRtd����n$|rvtj|jdd�}����}|� |��t� |�D�]}|�j|||d��q�d�S�)NT�__z-Invalid access found in the conditional: '%s'�exec��mode)�inside_call�inside_yield)r����astZCallZYieldZStr�s� startswithr����parse�visitZiter_child_nodes� generic_visit)r���ZnoderB���rC����parsed�cnvZ child_node��CleansingNodeVisitorr*���r=���r���r���rI�������s(����� �zJConditional._check_conditional.<locals>.CleansingNodeVisitor.generic_visitN)FF)�__name__� __module__�__qualname__rI���r���rL���r���r���rM�������s���rM���Nr?���r@���z Invalid conditional detected: %sz3{%% if %s %%} True {%% else %%} False {%% endif %%}�TrueT�FalseFz"unable to evaluate conditional: %sz&'(hostvars\[.+\]|[\w_]+)' is undefinedr����'�"�notZdefinedz+error while evaluating conditional (%s): %s)Zis_templater4���ZwarningZavailable_variablesr����templater���r���r ���rD���ZNodeVisitorZenvironmentrG���r���rH���r6���r���r����stripr ���r����re�compiler&����strr(���r-����replace)r���r*���r7���r8����originalr:���rJ���rK���r;���Z presented�valZvar_nameZ def_undefZdu_varZlogic�stateZshould_existr���rL���r���r3���t���sT���� � & zConditional._check_conditional)N) rN���rO���rP����__doc__r���r���r1���r���r$���r-���r<���r3���� __classcell__r���r���r���r���r���*���s���&r���)"Z __future__r���r���r����typeZ __metaclass__rD���rX���Zjinja2.compilerr���Zjinja2.exceptionsr���Zansibler����CZansible.errorsr���r ���r ���Zansible.module_utils.sixr���Zansible.module_utils._textr���r ���Zansible.playbook.attributer���Zansible.utils.displayr���r4���rY���r%���ZLOOKUP_REGEXZVALID_VAR_REGEXr���r���r���r���r����<module>���s ���