HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/args.cpython-310.pyc
o

�N�gSI�@sdZddlZddlZddlZddlZddlZddlZddlmZddl	Z
ddlZ
ddlZ
ddl
Z
ddlmZe�e�Ze�dej�Zdd�Zd'd	d
�Zdd�Zd(d
d�Zdd�Zdd�Zd)dd�Zdd�Zd)dd�Zd*dd�Zd)dd�Z dd�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>4sz"invalid_kwargs.<locals>.<listcomp>z1The following keyword arguments are not valid: {}�, )�
isinstance�dictr�format�joinr)�invalid_kwargsZ	raise_excZnew_invalid�msgrrrr.s
�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_input?s

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_inputQs&
�

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#ts
�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$c	Cst|�st|�d���t|d�r|j}t|d�szt�|�}Wnty.td|�d���wtdd�}g}g}d}}|j��D].}|j	|j
kr\|�|j�|j
tjur[|�|j
�qA|j	|jkrf|j}qA|j	|jkro|j}qA|ru|d=||||t|�p~d�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 '�'ZArgSpeczargs varargs keywords defaultsNr)�callable�	TypeError�hasattrrE�inspectZ	signaturerZ
parameters�values�kindZPOSITIONAL_OR_KEYWORDr�name�defaultZ_emptyZVAR_POSITIONALZVAR_KEYWORD�tuple)	�func�is_class_method�sigZ_ArgSpecr �defaults�varargs�keywords�paramrrr�get_function_argspec�s8

��
��rWcKs4t|t�rtjj�tjtjj�	|�fi|���S|S)z,
    Only split if variable is a string
    )
rrrr�data�decode�shlex�splitZstringutilsZto_str)�srrrr�shlex_split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 )rWrSr�zipr )�fun�aspecrr_r�
arg_lookups*rcr.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 rSTrTr)�fnmatch�filterrWrHr)
Z	functions�modulerrarbr rTrrSZ
module_dotrrr�argspec_report*s>��
��ric
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rcr1zsplit_input.<locals>.<listcomp>�,cSrkrrlr0rrrrer1)rrB�mapr[r-r)r
rjrrr�split_inputWs
 &�roc	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�lowerrrXZis_truer-)rrr!�valuerrr�	test_modehs��rsrc
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)rQrz*{} takes at least {} argument{} ({} given)�r\r.z1'{0[0]}' is an invalid keyword argument for '{1}'�fullrez2{} and '{}' are invalid keyword arguments for '{}'rcSsg|]}d|�d��qS)rFr)r�errrr�szformat_call.<locals>.<listcomp>r^)rWrc�copyr%�KeyErrorr�lenrr�__name__r&rUr�deepcopyrB�keys�get�
__module__r)rarXZinitial_retZexpected_extra_kwsrQrrbZarg_datar rZmissing_argsr	r!Zused_args_countZ
args_countrr�extrarrrr�format_callzs~
�
����
�����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[{(rm�)z]})�]�})r;r:r�r)rZZ
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__rwrfrJ�logging�rerZ�collectionsrZsalt.utils.datarZsalt.utils.jidZsalt.utils.versionsrAZsalt.exceptionsr�	getLoggerrz�log�compile�UNICODEr*r
rr"r)r#r$rWr]rcrirorsr�r�r�rrrr�<module>s>


#
[,


-
�q<