%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/parsing/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/parsing/__pycache__/mod_args.cpython-39.pyc

a

�)g�5�@s�ddlmZmZmZeZddlmZddl	m
Z
mZmZddl
mZddlmZddlmZmZddlmZmZddlmZdd	lmZdd
lmZeej�Ze� ed��Z!eed��Z"Gd
d�d�Z#dS)�)�absolute_import�division�print_functionN)�AnsibleParserError�AnsibleError�AnsibleAssertionError)�string_types)�to_text)�parse_kv�
split_args)�
module_loader�
action_loader)�Templar)�add_internal_fqcns)�Sentinel)
�includeZinclude_vars�
include_tasks�include_role�import_tasks�import_roleZadd_hostZgroup_byZset_fact�meta)rrrrrrc@sFeZdZdZddd�Zdd�Zddd�Zd	d
�Zdd�Zddd�Z	dS)�ModuleArgsParsera?
    There are several ways a module and argument set can be expressed:

    # legacy form (for a shell command)
    - action: shell echo hi

    # common shorthand for local actions vs delegate_to
    - local_action: shell echo hi

    # most commonly:
    - copy: src=a dest=b

    # legacy form
    - action: copy src=a dest=b

    # complex args form, for passing structured data
    - copy:
        src: a
        dest: b

    # gross, but technically legal
    - action:
        module: copy
        args:
          src: a
          dest: b

    # Standard YAML form for command-type modules. In this case, the args specified
    # will act as 'defaults' and will be overridden by any args specified
    # in one of the other formats (complex args under the action, or
    # parsed from the k=v string
    - command: 'pwd'
      args:
        chdir: '/tmp'


    This class has some of the logic to canonicalize these into the form

    - module: <module_name>
      delegate_to: <optional>
      args: <args>

    Args may also be munged for certain shell command parameters.
    NcCs�|durin|}t|t�s*tdt|���||_||_ddlm}ddlm	}t
|j�|_|j�
t
|j��|j�
ddg�t|j�|_d|_dS)Nz3the type of 'task_ds' should be a dict, but is a %sr)�Task)�Handler�local_actionZstatic)�
isinstance�dictr�type�_task_ds�_collection_listZansible.playbook.taskrZansible.playbook.handlerr�setZfattributes�_task_attrs�update�	frozenset�resolved_action)�selfZtask_ds�collection_listrr�r'�</usr/lib/python3.9/site-packages/ansible/parsing/mod_args.py�__init__js
zModuleArgsParser.__init__cCsFt|�}t|�dkr2|d��d�|dd��fS|d��dfSdS)z�
        when module names are expressed like:
        action: copy src=a dest=b
        the first part of the string is the name of the module
        and the rest are strings pertaining to the arguments.
        �r� N�)r�len�strip�join)r%Z
module_string�tokensr'r'r(�_split_module_string}sz%ModuleArgsParser._split_module_stringc	Cs|durin|}t�}|rjt|t�rLtdd�}|�|�rB||d<qjtd��nt|t�rb|�|�ntd��|dur�|�||�}n@|�|�\}}|r�d|vr�|�	d�}t|t�r�t
|�}|�|�|r�|tvr�|D]&}t|�}|�
d�r�td||f��q�|�r|�|�||fS)	zC
        arguments can be fuzzy.  Deal with all the forms.
        N��loader�_variable_paramsz�Complex args containing variables cannot use bare variables (without Jinja2 delimiters), and must use the full variable style ('{{var_name}}')zAComplex args must be a dictionary or variable string ("{{var}}").�argsZ	_ansible_z1invalid parameter specified for action '%s': '%s')rrrr�is_templaterr"�_normalize_new_style_args�_normalize_old_style_args�popr
�FREEFORM_ACTIONSr	�
startswithr)	r%�thing�action�additional_argsZ
final_args�templarr5Ztmp_args�argr'r'r(�_normalize_parameters�s6










z&ModuleArgsParser._normalize_parameterscCsXt|t�r|}nDt|t�r0|tv}t||d�}n$|dur>d}ntdt|�|jd��|S)ak
        deals with fuzziness in new style module invocations
        accepting key=value pairs and dictionaries, and returns
        a dictionary of arguments

        possible example inputs:
            'echo hi', 'shell'
            {'region': 'xyz'}, 'ec2'
        standardized outputs like:
            { _raw_params: 'echo hi', _uses_shell: True }
        ��	check_rawN�'unexpected parameter type in action: %s��obj)rrrr:r
rrr)r%r<r=r5rCr'r'r(r7�s

z*ModuleArgsParser._normalize_new_style_argscCs�d}d}t|t�r^|��}d|vr�|�|d�\}}|��}|tv}|�t||d��|d=nDt|t�r�|�|�\}}|tv}t||d�}ntdt	|�|j
d��||fS)a\
        deals with fuzziness in old-style (action/local_action) module invocations
        returns tuple of (module_name, dictionary_args)

        possible example inputs:
           { 'shell' : 'echo hi' }
           'shell echo hi'
           {'module': 'ec2', 'x': 1 }
        standardized outputs like:
           ('ec2', { 'x': 1} )
        N�modulerBrDrE)rr�copyr1r:r"r
rrrr)r%r<r=r5Zmodule_argsrCr'r'r(r8�s 


z*ModuleArgsParser._normalize_old_style_argsFcs.d}d}�j�dt�}t�}�j�dt��}d�jvrT�jd}�j|||d�\}}d�jvr�|durttd�jd���j�dd	�}d
}�j|||d�\}}t�fdd��j��D��}|��D]�\}}	d}
d
}|tvr�d}nD|r�d}n:tj	|�j
d�}
|
j�stj	|�j
d�}
|
j�ot
|
j�}|r�|du�rDtd||f�jd��|
du�r^|
j�r^|
j�_|}|	}�j|||d�\}}q�|du�r�|�r�t|���d}td�|��jd��ntd�jd��nb|�dd	�d	k�r$|tv�r$tdd�}
|�d�}|
�|��r||d<ntd|d�t�f�jd��|||fS)z�
        Given a task in one of the supported forms, parses and returns
        returns the action, arguments, and delegate_to values for the
        task, dealing with all sorts of levels of fuzziness.
        N�delegate_tor5r=)r=r>rz.action and local_action are mutually exclusiverEr,Z	localhostc3s.|]&\}}|�jvr|�d�s||fVqdS)Zwith_N)r!r;)�.0�k�v�r%r'r(�	<genexpr>(�z)ModuleArgsParser.parse.<locals>.<genexpr>FT)r&z%conflicting action statements: %s, %srzwcouldn't resolve module/action '{0}'. This often indicates a misspelling, missing collection, or incorrect module path.z"no module/action detected in task.Z_raw_paramsr2r4zSthis task '%s' has extra params, which is only allowed in the following modules: %sz, )r�getrrrAr�items�
BUILTIN_TASKSr
Zfind_plugin_with_contextrZresolvedr�boolZ
redirect_listZ
resolved_fqcnr$�list�keys�format�RAW_PARAM_MODULESrr9r6r/)r%Zskip_action_validationr<r=rIr5r>Znon_task_ds�item�value�contextZis_action_candidateZ
bad_actionr?Z
raw_paramsr'rMr(�parsesp




���


��zModuleArgsParser.parse)NN)NN)F)
�__name__�
__module__�__qualname__�__doc__r)r1rAr7r8r[r'r'r'r(r;s-

7&r)$Z
__future__rrrrZ
__metaclass__Zansible.constantsZ	constants�CZansible.errorsrrrZansible.module_utils.sixrZansible.module_utils._textr	Zansible.parsing.splitterr
rZansible.plugins.loaderrr
Zansible.templaterZansible.utils.fqcnrZansible.utils.sentinelrr#ZMODULE_REQUIRE_ARGSr:�unionrWrRrr'r'r'r(�<module>s



Zerion Mini Shell 1.0