%PDF- %PDF-
Mini Shell

Mini Shell

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

a

�)g�J�@sJddlmZmZmZeZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZmZmZmZdd�Zd6dd�Zd7dd�Zd8dd�Zd9dd�Zd:dd�Z d;dd�Z!d<dd�Z"d=dd�Z#d>d d!�Z$d"d#�Z%d$d%�Z&d&d'�Z'd(d)�Z(d*d+�Z)d,d-�Z*d.d/�Z+d0d1�Z,d2d3�Z-d4d5�Z.dS)?�)�absolute_import�division�print_functionN)�literal_eval)�	to_native)�json)�is_iterable)�jsonify)�human_to_bytes)�boolean)�binary_type�
integer_types�string_types�	text_typecCs t|�s|g}tt|��|��S)aCount the number of occurrences of a key in a given dictionary

    :arg terms: String or iterable of values to check
    :arg parameters: Dictionary of parameters

    :returns: An integer that is the number of occurrences of the terms values
        in the provided dictionary.
    )r�len�set�intersection)�terms�
parameters�r�J/usr/lib/python3.9/site-packages/ansible/module_utils/common/validation.py�count_termss
rFc
Cs�t|t�s|r|dfS|St�d|�r6|r2|dfS|St�d|�rR|rN|dfS|Sz t|�}|rj|dfWS|WSWn@ty�}z(|r�||fWYd}~S|WYd}~Sd}~00dS)Nz	\w\.\w+\(z
import \w+)�
isinstancer�re�searchr�	Exception)�value�locals�include_exceptions�result�errr�	safe_eval*s*


r!cCs|g}|dur|S|D] }t||�}|dkr|�|�q|rxdd�|D�}dd�|�}|rld�|d�|��}tt|���|S)	a�Check mutually exclusive terms against argument parameters

    Accepts a single list or list of lists that are groups of terms that should be
    mutually exclusive with one another

    :arg terms: List of mutually exclusive parameters
    :arg parameters: Dictionary of parameters
    :kwarg options_context: List of strings of parent key names if ``terms`` are
        in a sub spec.

    :returns: Empty list or raises :class:`TypeError` if the check fails.
    N�cSsg|]}d�|��qS)�|)�join)�.0�checkrrr�
<listcomp>^�z,check_mutually_exclusive.<locals>.<listcomp>z%parameters are mutually exclusive: %s�, �{0} found in {1}� -> �r�appendr$�format�	TypeErrorr)rr�options_context�resultsr&�countZ	full_list�msgrrr�check_mutually_exclusiveFs
r4cCsxg}|dur|S|D] }t||�}|dkr|�|�q|rt|D]4}dd�|�}|rfd�|d�|��}tt|���q>|S)a�Check each list of terms to ensure at least one exists in the given module
    parameters

    Accepts a list of lists or tuples

    :arg terms: List of lists of terms to check. For each list of terms, at
        least one is required.
    :arg parameters: Dictionary of parameters
    :kwarg options_context: List of strings of parent key names if ``terms`` are
        in a sub spec.

    :returns: Empty list or raises :class:`TypeError` if the check fails.
    Nrz$one of the following is required: %sr)r*r+r,)rrr0r1�termr2r3rrr�check_required_one_ofgs
r6cs�g}|dur|S|D]B}�fdd�|D�}dd�|D�}t|�dkrd|vr|�|�q|r�|D]4}dd�|�}|r�d�|d	�|��}tt|���q`|S)
aCheck each list of terms to ensure every parameter in each list exists
    in the given parameters.

    Accepts a list of lists or tuples.

    :arg terms: List of lists of terms to check. Each list should include
        parameters that are all required when at least one is specified
        in the parameters.
    :arg parameters: Dictionary of parameters
    :kwarg options_context: List of strings of parent key names if ``terms`` are
        in a sub spec.

    :returns: Empty list or raises :class:`TypeError` if the check fails.
    Ncsg|]}t|���qSr)r)r%�field�rrrr'�r(z+check_required_together.<locals>.<listcomp>cSsg|]}|dkr|�qS)rr)r%�crrrr'�r(rz$parameters are required together: %sr)r*r+)rr-r$r.r/r)rrr0r1r5ZcountsZnon_zeror3rr8r�check_required_together�s r:c	Cs�i}|dur|S|��D]b\}}||vs||dur6qg||<t|t�rN|g}|D]&}||vsj||durR||�|�qRq|r�|��D]H\}}t|�dkr�d|d�|�f}|r�d�|d�|��}tt|���q�|S)a�For each key in requirements, check the corresponding list to see if they
    exist in parameters.

    Accepts a single string or list of values for each key.

    :arg requirements: Dictionary of requirements
    :arg parameters: Dictionary of parameters
    :kwarg options_context: List of strings of parent key names if ``requirements`` are
        in a sub spec.

    :returns: Empty dictionary or raises :class:`TypeError` if the
    Nrz)missing parameter(s) required by '%s': %sr)r*r+)	�itemsrrr-rr$r.r/r)	�requirementsrr0r�keyr�required�missingr3rrr�check_required_by�s(
r@cCs�g}|dur|S|��D]*\}}|�dd�}|r||vr|�|�q|r|dd�t|��}|rpd�|d�|��}tt|���|S)aCheck all parameters in argument_spec and return a list of parameters
    that are required but not present in parameters.

    Raises :class:`TypeError` if the check fails

    :arg argument_spec: Argument spec dictionary containing all parameters
        and their specification
    :arg parameters: Dictionary of parameters
    :kwarg options_context: List of strings of parent key names if ``argument_spec`` are
        in a sub spec.

    :returns: Empty list or raises :class:`TypeError` if the check fails.
    Nr>F�missing required arguments: %sr)r*r+)r;�getr-r$�sortedr.r/r)Z
argument_specrr0r?�k�vr>r3rrr�check_required_arguments�srFc
	CsJg}|dur|S|D]�}i}g|d<d}d}t|�dkrF|\}}	}}n
|\}}	}|rft|�}d|d<nd|d<||vr�|||	kr�|D]$}
t|
|�}|dkr�|d�|
�q�t|d�rt|d�|kr||d	<|	|d
<||d<|�|�q|�rF|D]N}d|d	|d
|dd
�|d�f}|�r8d�|d�|��}tt|���q�|S)aTCheck parameters that are conditionally required

    Raises :class:`TypeError` if the check fails

    :arg requirements: List of lists specifying a parameter, value, parameters
        required when the given parameter is the specified value, and optionally
        a boolean indicating any or all parameters are required.

    :Example:

    .. code-block:: python

        required_if=[
            ['state', 'present', ('path',), True],
            ['someint', 99, ('bool_param', 'string_param')],
        ]

    :arg parameters: Dictionary of parameters

    :returns: Empty list or raises :class:`TypeError` if the check fails.
        The results attribute of the exception contains a list of dictionaries.
        Each dictionary is the result of evaluating each item in requirements.
        Each return dictionary contains the following keys:

            :key missing: List of parameters that are required but missing
            :key requires: 'any' or 'all'
            :key parameter: Parameter name that has the requirement
            :key value: Original value of the parameter
            :key requirements: Original required parameters

        :Example:

        .. code-block:: python

            [
                {
                    'parameter': 'someint',
                    'value': 99
                    'requirements': ('bool_param', 'string_param'),
                    'missing': ['string_param'],
                    'requires': 'all',
                }
            ]

    :kwarg options_context: List of strings of parent key names if ``requirements`` are
        in a sub spec.
    Nr?rF��anyZrequires�allZ	parameterrr<z0%s is %s but %s of the following are missing: %sr)r*r+)rrr-r$r.r/r)
r<rr0r1Zreqr?Zmax_missing_countZ	is_one_ofr=�valr&r2r3rrr�check_required_if�sD0


�rKcCsPg}|dur|S|D]}|�|�s|�|�q|rLdd�|�}tt|���|S)a�This is for checking for required params when we can not check via
    argspec because we need more information than is simply given in the argspec.

    Raises :class:`TypeError` if any required parameters are missing

    :arg parameters: Dictionary of parameters
    :arg required_parameters: List of parameters to look for in the given parameters.

    :returns: Empty list or raises :class:`TypeError` if the check fails.
    NrAr))rBr-r$r/r)rZrequired_parametersZmissing_params�paramr3rrr�check_missing_parametersRs
rMT�cCs8t|t�r|S|rt|dd�Sd�|�}tt|���dS)asVerify that the value is a string or convert to a string.

    Since unexpected changes can sometimes happen when converting to a string,
    ``allow_conversion`` controls whether or not the value will be converted or a
    TypeError will be raised if the value is not a string and would be converted

    :arg value: Value to validate or convert to a string
    :arg allow_conversion: Whether to convert the string and return it or raise
        a TypeError

    :returns: Original value if it is a string, the value converted to a string
        if allow_conversion=True, or raises a TypeError if allow_conversion=False.
    Zsurrogate_or_strict)�errorsz5'{0!r}' is not a string and conversion is not allowedN)rrrr.r/)rZallow_conversionrL�prefixr3rrr�check_type_stros

rQcCsTt|t�r|St|t�r"|�d�St|t�s6t|t�r@t|�gStdt|���dS)a�Verify that the value is a list or convert to a list

    A comma separated string will be split into a list. Raises a :class:`TypeError`
    if unable to convert to a list.

    :arg value: Value to validate or convert to a list

    :returns: Original value if it is already a list, single item list if a
        float, int, or string without commas, or a multi-item list if a
        comma-delimited string.
    �,z %s cannot be converted to a listN)	r�listr�split�int�float�strr/�type�rrrr�check_type_list�s



rZc	Cs^t|t�r|St|t��rJ|�d�rnzt�|�WStyjt|t�dd�\}}|durbtd��|YS0n�d|v�rBg}g}d}d}|�	�D]�}|r�|�
|�d}q�|dkr�d}q�|s�|d	vr�|}q�|r�||kr�d}q�|�s
|d
v�r
d�|�}|�r|�
|�g}q�|�
|�q�d�|�}|�r0|�
|�tdd
�|D��Std��tdt|���dS)aVerify that value is a dict or convert it to a dict and return it.

    Raises :class:`TypeError` if unable to convert to a dict

    :arg value: Dict or string to convert to a dict. Accepts ``k1=v2, k2=v2``.

    :returns: value converted to a dictionary
    �{T)rNz'unable to evaluate string as dictionary�=F�\)�'�")rR� rNcss|]}|�dd�VqdS)r\r"N)rT)r%�xrrr�	<genexpr>�r(z"check_type_dict.<locals>.<genexpr>z7dictionary requested, could not parse JSON or key=valuez %s cannot be converted to a dict)
r�dictr�
startswithr�loadsrr!r/�stripr-r$rX)	rr�exc�fieldsZfield_bufferZin_quoteZ	in_escaper9r7rrr�check_type_dict�sL	







ricCsBt|t�r|St|t�s&t|ttf�r.t|�Stdt|���dS)aXVerify that the value is a bool or convert it to a bool and return it.

    Raises :class:`TypeError` if unable to convert to a bool

    :arg value: String, int, or float to convert to bool. Valid booleans include:
         '1', 'on', 1, '0', 0, 'n', 'f', 'false', 'true', 'y', 't', 'yes', 'no', 'off'

    :returns: Boolean True or False
    z %s cannot be converted to a boolN)r�boolrrUrVrr/rXrYrrr�check_type_bool�s


rkcCsJt|t�r|St|t�r6z
t|�WSty4Yn0tdt|���dS)z�Verify that the value is an integer and return it or convert the value
    to an integer and return it

    Raises :class:`TypeError` if unable to convert to an int

    :arg value: String or int to convert of verify

    :return: int of given value
    z %s cannot be converted to an intN)rr
rrU�
ValueErrorr/rXrYrrr�check_type_int�s



rmcCsPt|t�r|St|tttf�r<z
t|�WSty:Yn0tdt|���dS)z�Verify that value is a float or convert it to a float and return it

    Raises :class:`TypeError` if unable to convert to a float

    :arg value: float, int, str, or bytes to verify or convert and return.

    :returns: float of given value.
    z!%s cannot be converted to a floatN)rrVrrrUrlr/rXrYrrr�check_type_float�s	

rncCst|�}tj�tj�|��S)zgVerify the provided value is a string or convert it to a string,
    then return the expanded path
    )rQ�os�path�
expanduser�
expandvarsrYrrr�check_type_pathsrscCs|S)zReturns the raw valuerrYrrr�check_type_rawsrtcCs2z
t|�WSty,tdt|���Yn0dS)zpConvert a human-readable string value to bytes

    Raises :class:`TypeError` if unable to covert the value
    z&%s cannot be converted to a Byte valueN�r
rlr/rXrYrrr�check_type_bytess
rvcCs6zt|dd�WSty0tdt|���Yn0dS)z�Convert a human-readable string bits value to bits in integer.

    Example: ``check_type_bits('1Mb')`` returns integer 1048576.

    Raises :class:`TypeError` if unable to covert the value.
    T)Zisbitsz%%s cannot be converted to a Bit valueNrurYrrr�check_type_bits*srwcCsBt|ttf�r|��St|tttf�r.t|�Stdt	|���dS)z�Return a jsonified string. Sometimes the controller turns a json string
    into a dict/list so transform it back into json here

    Raises :class:`TypeError` if unable to covert the value

    z'%s cannot be converted to a json stringN)
rrrrfrS�tuplercr	r/rXrYrrr�check_type_jsonarg7s
ry)NF)N)N)N)N)N)N)N)TNrN)/Z
__future__rrrrXZ
__metaclass__ror�astrZansible.module_utils._textrZ(ansible.module_utils.common._json_compatrZ'ansible.module_utils.common.collectionsrZ+ansible.module_utils.common.text.convertersr	Z+ansible.module_utils.common.text.formattersr
Z)ansible.module_utils.parsing.convert_boolrZansible.module_utils.sixrr
rrrr!r4r6r:r@rFrKrMrQrZrirkrmrnrsrtrvrwryrrrr�<module>s>

!
"
$
(
!
\

6

Zerion Mini Shell 1.0