HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/args.cpython-310.pyc
o

;j�H�@s*dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
ZddlZddl
ZddlZddlZddlmZe�e�Ze�dej�Zdd�Zd)d	d
�Zdd�Zd*d
d�Zdd�Zdd�Ze	dd�Zd+dd�Zdd�Z d+dd�Z!d,dd�Z"d+dd�Z#d d!�Z$	d-d#d$�Z%d%d&�Z&d'd(�Z'dS).z*
Functions used for CLI argument handling
�N)�
namedtuple)�SaltInvocationErrorz^([^\d\W][\w.-]*)=(?!=)(.*)$cKs,i}|��D]
\}}|�d�s|||<q|S)a�
    Return a dict without any of the __pub* keys (or any other keys starting
    with a dunder) from the kwargs dict passed into the execution module
    functions. These keys are useful for tracking what was used to invoke
    the function call, but they may not be desirable to have if passing the
    kwargs forward wholesale.

    Usage example:

    .. code-block:: python

        kwargs = __utils__['args.clean_kwargs'](**kwargs)
    �__)�items�
startswith)�kwargs�ret�key�val�r�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/args.py�clean_kwargss
�r
TcCsD|rt|t�rdd�|��D�}|}d�d�|��}|r t|��|S)zD
    Raise a SaltInvocationError if invalid_kwargs is non-empty
    cSsg|]\}}|�d|���qS)�=r)�.0�x�yrrr�
<listcomp>6sz"invalid_kwargs.<locals>.<listcomp>z1The following keyword arguments are not valid: {}�, )�
isinstance�dictr�format�joinr)�invalid_kwargsZ	raise_excZnew_invalid�msgrrrr0s
�rcCs�g}|D]}t|t�rtjj�t|��r|�t|��q|�|�qt|t�r?|r?ddi}|�	�D]\}}|||<q1||gS|S)zG
    Return a single arg structure for the publisher to safely use
    �	__kwarg__T)
r�int�salt�utilsZjidZis_jid�str�appendrr)�argsrr�argZkw_r	r
rrr�condition_inputAs

r"cCs�|durd}g}i}|D]B}t|t�r0t|�\}}|r(||vr#t|�n|||<q|�t|��qt|t�rI|�dd�durC|�|�q|�|�q|�|�q|rVt||�S||fS)z�
    Parse out the args and kwargs from a list of input values. Optionally,
    return the args and kwargs without passing them to condition_input().

    Don't pull args with key=val apart if it has a newline in it.
    NrrFT)	rr�parse_kwarg�yamlify_argrr�pop�updater")r Z	conditionZno_parse�_args�_kwargsr!Zarg_nameZ	arg_valuerrr�parse_inputSs&
�

r)cCs&zt�|���WStyYdSw)z�
    Parses the string and looks for the following kwarg format:

    "{argument name}={argument value}"

    For example: "my_message=Hello world"

    Returns the kwarg name and value, or (None, None) if the regex was not
    matched.
    )NN)�KWARG_REGEX�match�groups�AttributeError)Zstring_rrrr#vs
�r#cs�t�t�s�S���dvr�Sd�vr tdd����D��r �St�fdd�dD��r-�Sz�dd	l}�}d
�vrN|jj���}t|t�sH|d	urK�WS|WS�dkrUd	�n|jj����t�t	�rqt|t�rn|�
d�sn|WS�WSt�t�r�t|t�r�|�
d
�s�|WS�WS�d	us�t�ttt
tf�r��dkr�|dvr�|WS�d	ur�|���
d
�r�|WS�d	ur�|dkr�|WS�WS|WSty�|YSw)z 
    yaml.safe_load the arg
    )�z---z...�_cSsg|]}|dv�qS)Z0123456789_r�rrrrrr��zyamlify_arg.<locals>.<listcomp>c3s�|]}|�vVqdS�Nr)rZnp_char�r!rr�	<genexpr>�s�zyamlify_arg.<locals>.<genexpr>)�	�
�
rN�#�None�{�[r.)�|�!r=)rr�strip�all�any�salt.utils.yamlrZyamlZ	safe_loadrr�list�floatr�	Exception)r!rZoriginal_argZ
parsed_argrr3rr$�sN


�r$ZArgSpeczargs varargs keywords defaultscCs�t|�st|�d���t|d�r|j}t|d�szt�|�}Wnty.td|�d���wg}g}d}}|j��D].}|j|j	krW|�
|j�|jtj
urV|�
|j�q<|j|jkra|j}q<|j|jkrj|j}q<|rp|d=t|||t|�pyd�S)a�
    A small wrapper around inspect.signature that also supports callable objects and wrapped functions

    If the given function is a wrapper around another function (i.e. has a
    ``__wrapped__`` attribute), return the functions specification of the underlying
    function.

    :param is_class_method: Pass True if you are sure that the function being passed
                            is an unbound method. The reason for this is that on
                            Python 3 unbound methods are classified as functions and
                            not methods, so ``self`` will not be removed from
                            the argspec unless ``is_class_method`` is True.
    z is not a callable�__wrapped__z"Cannot inspect argument list for '�'Nr)�callable�	TypeError�hasattrrE�inspectZ	signature�
parameters�values�kindZPOSITIONAL_OR_KEYWORDr�name�defaultZ_emptyZVAR_POSITIONALZVAR_KEYWORD�_ArgSpec�tuple)�func�is_class_method�sigr �defaults�varargs�keywords�paramrrr�get_function_argspec�s6

����rYcKs8t|t�rtjdkrtjj�|�Stj	|fi|��S|S)z0
    Only split if the variable is a string
    �win32)
rr�sys�platformrrZ
win_functions�shlex_split�shlex�split)�srrrrr]s


r]csddii�|durt|�}|jr$tt|jddd�|jddd����d<�fdd�|jD��d<�S)z[
    Return a dict containing the arguments and default arguments to the
    function.
    rN���csg|]
}|�dvr|�qS)rr)rr!�rrrr'szarg_lookup.<locals>.<listcomp>r )rYrUr�zipr )�fun�aspecrrbr�
arg_lookups*rfr.c
	CsZi}d|vs
d|vrYt�||�D]F}zt||�}Wn	ty#Yqw|\}}}}i||<|r2|nd||d<|r<|nd||d<|rFdnd||d<|rPdnd||d<q|S|d}	|D]K}|�|	�r�zt||�}Wn	tywYq_w|\}}}}i||<|r�|nd||d<|r�|nd||d<|r�dnd||d<|r�dnd||d<q_|S)	zs
    Pass in a functions dict as it is returned from the loader and return the
    argspec function signatures
    �*�.Nr rUTrVr)�fnmatch�filterrYrHr)
Z	functions�modulerrdrer rVrrUZ
module_dotrrr�argspec_report+s>��
��rlc
Cs~|durdd�}t|t�rtt||��Sztt|dd�|�d�D���WSty>tt|dd�t|��d�D���YSw)zT
    Take an input value and split it into a list, returning the resulting list
    NcSs|Sr2r)rrrr�mapper^szsplit_input.<locals>.mappercS�g|]}|���qSr�r>r0rrrrdr1zsplit_input.<locals>.<listcomp>�,cSrnrror0rrrrfr1)rrB�mapr_r-r)r
rmrrr�split_inputXs
 &�rrc	KsVddl}|��D] \}}z|��dkr|jj�|�rWdSWqty(YqwdS)z�
    Examines the kwargs passed and returns True if any kwarg which matching
    "Test" in any variation on capitalization (i.e. "TEST", "Test", "TeSt",
    etc) contains a True value (as determined by salt.utils.data.is_true).
    rN�testTF)Z
salt.utilsr�lowerr�dataZis_truer-)rrr!�valuerrr�	test_modeis��rwrc
Cs|dur|pi}g|d<i|d<t||d�}t||�}|d}|d}	|��}g}
|	D]}z	|�|�|	|<Wq+ty?Yq+w|rd|�d�}z|d�|�|��Wntya|
�|�Ynw|sB|
r�t|d�t|�}
|
t|
�}td�|j	||dkr�dp�d	|
���|d�
|	�|jr�|��D]\}}||vr�q�||d|<q�|Si}|��D]\}}||vr�q�t�
|�||<q�|�rt|�dkr�d
�t|���|�d|j�d|j	����}t|��d
�d�dd�|D�dd��t|���d|�d|j�d|j	����}t|��|S)a�
    Build the required arguments and keyword arguments required for the passed
    function.

    :param fun: The function to get the argspec from
    :param data: A dictionary containing the required data to build the
                 arguments and keyword arguments.
    :param initial_ret: The initial return data pre-populated as dictionary or
                        None
    :param expected_extra_kws: Any expected extra keyword argument names which
                               should not trigger a :ref:`SaltInvocationError`
    :param is_class_method: Pass True if you are sure that the function being passed
                            is a class method. The reason for this is that on Python 3
                            ``inspect.ismethod`` only returns ``True`` for bound methods,
                            while on Python 2, it returns ``True`` for bound and unbound
                            methods. So, on Python 3, in case of a class method, you'd
                            need the class to which the function belongs to be instantiated
                            and this is not always wanted.
    :returns: A dictionary with the function required arguments and keyword
              arguments.
    Nr r)rSrz*{} takes at least {} argument{} ({} given)�r`r.z1'{0[0]}' is an invalid keyword argument for '{1}'�fullrhz2{} and '{}' are invalid keyword arguments for '{}'rcSsg|]}d|�d��qS)rFr)r�errrr�szformat_call.<locals>.<listcomp>ra)rYrf�copyr%�KeyErrorr�lenrr�__name__r&rWr�deepcopyrB�keys�get�
__module__r)rdruZinitial_retZexpected_extra_kwsrSrreZarg_datar rZmissing_argsr	r!Zused_args_countZ
args_countrv�extrarrrr�format_call{s~
�
����
�����r�cCs\tj|dd�}d|_g}g}i}g}d}d}|D]
}|dkr n|�|�q|r,|dkr.dSd�|�}g}d}	|D]k}|d	vrJ|�|�|�|�q9|d
ksR|dkru|su|r^d�|�||<n
|rh|�d�|��|dkrpd}	n5d}g}q9|dvr�d
ddd�}
|r�||
|��kr�n|�|�q9|dkr�|s�d�|�}g}q9|�|�q9|	r�|||fSdS)a�
    Parse a python-like function call syntax.

    For example: module.function(arg, arg, kw=arg, kw=arg)

    This function takes care only about the function name and arguments list carying on quoting
    and bracketing. It doesn't perform identifiers and other syntax validity check.

    Returns a tuple of three values: function name string, arguments list and keyword arguments
    dictionary.
    T)�posixz"'N�()NNNr.Fz[{(rp�)z]})�]�})r;r:r�r)r^Z
escapedquotesrrr%)r`�sh�wordr rZbracketsr	�token�fnameZgoodZ	_bracketsrrr�parse_function�sX



r�cCsLi}i}|��D]\}}||vr|dur|||<q|dur!|||<q||fS)a
    Filter out the kwargs used for the init of the class and the kwargs used to
    invoke the command required.

    all_kwargs
        All the kwargs the Execution Function has been invoked.

    class_init_kwargs
        The kwargs of the ``__init__`` of the class.
    N)r)Z
all_kwargsZclass_init_kwargsZ
fun_kwargsZinit_kwargsZkargZwargrrr�prepare_kwargs(s�r�)T)TNr2)r.)NrN)(�__doc__r{rirJ�logging�rer^r[�collectionsrZsalt.utils.datarZsalt.utils.jidZsalt.utils.versionsZsalt.utils.win_functionsrAZsalt.exceptionsr�	getLoggerr~�log�compile�UNICODEr*r
rr"r)r#r$rPrYr]rfrlrrrwr�r�r�rrrr�<module>sD


#
[
+


-
�q<