Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/module_utils/common/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/module_utils/common/validation.pyc

�
�Udac@`s�ddlmZmZmZeZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZddlmZdd	lmZdd
lmZmZmZmZd�Zd�Zd
�Zd�Zd�Z d�Z!d�Z"dd�Z$de%d�Z&e'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d�Z0d�Z1d�Z2dS(i(tabsolute_importtdivisiontprint_functionN(t	to_nativetto_text(tjson(tis_iterable(tjsonify(thuman_to_bytes(tboolean(tliteral_eval(tbinary_typet
integer_typeststring_typest	text_typecC`s1t|�s|g}ntt|�j|��S(s*Count the number of occurrences of a key in a given dictionary

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

    :returns: An integer that is the number of occurrences of the terms values
        in the provided dictionary.
    (Rtlentsettintersection(ttermstmodule_parameters((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcount_termss
cC`s�g}|dkr|Sx9|D]1}t||�}|dkr|j|�qqW|r�g|D]}dj|�^q_}ddj|�}tt|���n|S(swCheck 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 module parameters
    :arg module_parameters: Dictionary of module parameters

    :returns: Empty list or raises TypeError if the check fails.
    it|s%parameters are mutually exclusive: %ss, N(tNoneRtappendtjoint	TypeErrorR(RRtresultstchecktcountt	full_listtmsg((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_mutually_exclusive*s
"cC`s�g}|dkr|Sx9|D]1}t||�}|dkr|j|�qqW|r�x6|D]+}ddj|�}tt|���q_Wn|S(soCheck 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 module_parameters: Dictionary of module parameters

    :returns: Empty list or raises TypeError if the check fails.
    is$one of the following is required: %ss, N(RRRRRR(RRRttermRR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_required_one_ofGs


c	C`s�g}|dkr|Sx�|D]~}g|D]}t||�^q*}g|D]}|dkrL|^qL}t|�dkrd|kr�|j|�q�qqW|r�x6|D]+}ddj|�}tt|���q�Wn|S(s�Check each list of terms to ensure every parameter in each list exists
    in the given module 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 module_parameters.
    :arg module_parameters: Dictionary of module parameters

    :returns: Empty list or raises TypeError if the check fails.
    is$parameters are required together: %ss, N(RRRRRRR(	RRRR tfieldtcountstctnon_zeroR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_required_togetheres
"%
cC`s%i}|dkr|Sx�|j�D]�\}}||ks#||dkrQq#ng||<t|t�rv|g}nx>|D]6}||ks�||dkr}||j|�q}q}Wq#W|r!x]|j�D]L\}}t|�dkr�d|dj|�f}tt|���q�q�Wn|S(sSFor each key in requirements, check the corresponding list to see if they
    exist in module_parameters

    Accepts a single string or list of values for each key

    :arg requirements: Dictionary of requirements
    :arg module_parameters: Dictionary of module parameters

    :returns: Empty dictionary or raises TypeError if the
    is)missing parameter(s) required by '%s': %ss, N(	Rtitemst
isinstanceR
RRRRR(trequirementsRtresulttkeytvaluetrequiredtmissingR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_required_by�s$

cC`s�g}|dkr|SxN|j�D]@\}}|jdt�}|r#||kr#|j|�q#q#W|r�ddj|�}tt|���n|S(s�Check all paramaters in argument_spec and return a list of parameters
    that are required but not present in module_parameters

    Raises TypeError if the check fails

    :arg argument_spec: Argument spec dicitionary containing all parameters
        and their specification
    :arg module_paramaters: Dictionary of module parameters

    :returns: Empty list or raises TypeError if the check fails.
    R-smissing required arguments: %ss, N(RR'tgettFalseRRRR(t
argument_specRR.tktvR-R((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_required_arguments�s
cC`s�g}|dkr|Sx<|D]4}i}g|d<d}t}t|�dkrf|\}}}}n|\}}}|r�t|�}d|d<n
d|d<||kr�|||kr�x@|D]5}	t|	|�}
|
dkr�|dj|	�q�q�Wnt|d�rt|d�|kr||d<||d<||d	<|j|�qqW|r�xR|D]G}d
|d|d|ddj|d�f}tt|���qbWn|S(
s�Check parameters that are conditionally required

    Raises 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:
            required_if=[
                ['state', 'present', ('path',), True],
                ['someint', 99, ('bool_param', 'string_param')],
            ]

    :arg module_paramaters: Dictionary of module parameters

    :returns: Empty list or raises TypeError if the check fails.
        The results attribute of the exception contains a list of dictionaries.
        Each dictionary is the result of evaluting 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 paramater: Parameter name that has the requirement
            :key value: Original value of the paramater
            :key requirements: Original required parameters

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

    R.iitanytrequirestallt	parameterR,R)s0%s is %s but %s of the following are missing: %ss, N(RR1RRRRRR(R)RRtreqR.tmax_missing_countt	is_one_ofR+tvalRRR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_required_if�s>(




&



,cC`sxg}|dkr|Sx-|D]%}|j|�s|j|�qqW|rtddj|�}tt|���n|S(s�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 TypeError if any required parameters are missing

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

    :returns: Empty list or raises TypeError if the check fails.
    smissing required arguments: %ss, N(RR0RRRR(Rtrequired_parameterstmissing_paramstparamR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_missing_parameterss
cC`s�t|t�s#|r|dfS|Stjd|�rI|rE|dfS|Stjd|�ro|rk|dfS|Sy$t|�}|r�|dfS|SWn$tk
r�}|r�||fS|SXdS(Ns	\w\.\w+\(s
import \w+(R(R
RtretsearchR
t	Exception(R,tlocalstinclude_exceptionsR*te((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pyt	safe_eval3s*




cC`sNt|t�r|S|r)t|dd�Sdj|�}tt|���dS(ssVerify 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.
    terrorstsurrogate_or_stricts5'{0!r}' is not a string and conversion is not allowedN(R(R
RtformatR(R,tallow_conversionR((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_strOscC`stt|t�r|St|t�r/|jd�St|t�sMt|t�rZt|�gStdt|���dS(s�Verify that the value is a list or convert to a list

    A comma separated string will be split into a list. Rases a 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.
    t,s %s cannot be converted to a listN(	R(tlistR
tsplittinttfloattstrRttype(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_listgs

c	C`s�t|t�r|St|t�r�|jd�r�ytj|�SWq�tk
r�t|t�dt�\}}|dk	r�t
d��n|SXq�d|kr�g}g}t}t}x�|j�D]�}|r�|j
|�t}q�|dkr�t}q�|r|dkr|}q�|r2||kr2t}q�|rs|dkrsd
j|�}|rj|j
|�ng}q�|j
|�q�Wd
j|�}|r�|j
|�ntd�|D��St
d��nt
d
t|���dS(s�Verify that value is a dict or convert it to a dict and return it.

    Raises 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{RGs'unable to evaluate string as dictionaryt=s\s't"ROt tcs`s!|]}|jdd�VqdS(RXiN(RQ(t.0tx((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pys	<genexpr>�ss7dictionary requested, could not parse JSON or key=values %s cannot be converted to a dictN(s'RY(RORZ(R(tdictR
t
startswithRtloadsRERItTrueRRR1tstripRRRU(	R,R*texctfieldstfield_buffertin_quotet	in_escapeR$R"((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_dict~sL	

					cC`s[t|t�r|St|t�s7t|ttf�rAt|�Stdt|���dS(sOVerify that the value is a bool or convert it to a bool and return it.

    Raises 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
    s %s cannot be converted to a boolN(R(tboolR
RRRSR	RRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_bool�s

$
cC`sat|t�r|St|t�rGyt|�SWqGtk
rCqGXntdt|���dS(s�Verify that the value is an integer and return it or convert the value
    to an integer and return it

    Raises TypeError if unable to convert to an int

    :arg value: String or int to convert of verify

    :return: Int of given value
    s %s cannot be converted to an intN(R(RR
RRt
ValueErrorRRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_int�s

cC`sjt|t�r|St|tttf�rPyt|�SWqPtk
rLqPXntdt|���dS(s�Verify that value is a float or convert it to a float and return it

    Raises 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.
    s!%s cannot be converted to a floatN(R(RSRRRRRkRRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_float�s	
cC`s(t|�}tjjtjj|��S(sgVerify the provided value is a string or convert it to a string,
    then return the expanded path
    (RNtostpatht
expandusert
expandvars(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_path�scC`s|S(sReturns the raw value
    ((R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_raw�scC`s<yt|�SWn'tk
r7tdt|���nXdS(sgConvert a human-readable string value to bytes

    Raises TypeError if unable to covert the value
    s&%s cannot be converted to a Byte valueN(RRkRRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_bytess
cC`sByt|dt�SWn'tk
r=tdt|���nXdS(s�Convert a human-readable string bits value to bits in integer.

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

    Raises TypeError if unable to covert the value.
    tisbitss%%s cannot be converted to a Bit valueN(RRaRkRRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_bitss
cC`s[t|ttf�r|j�St|tttf�rAt|�Stdt	|���dS(s�Return a jsonified string. Sometimes the controller turns a json string
    into a dict/list so transform it back into json here

    Raises TypeError if unable to covert the value

    s'%s cannot be converted to a json stringN(
R(RRRbRPttupleR^RRRU(R,((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pytcheck_type_jsonargs


(3t
__future__RRRRUt
__metaclass__RnRCtansible.module_utils._textRRt(ansible.module_utils.common._json_compatRt'ansible.module_utils.common.collectionsRt+ansible.module_utils.common.text.convertersRt+ansible.module_utils.common.text.formattersRt)ansible.module_utils.parsing.convert_boolR	tansible.module_utils.pycompat24R
tansible.module_utils.sixRRR
RRRR!R&R/R5R>RRBR1RIRaRNRVRhRjRlRmRrRsRtRvRx(((sJ/usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.pyt<module>s>"				 	$		R		6							

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]