%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/args.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZmZddlZddlZddlZddlZeje�Zejre	jde	j�Zne	jd�Zd�Zed	�Z d
�Z!edd�Z#d�Z$d
�Z%ejr�ddl&m'Z'e'dd�Z(d�Z)ndd�Z*d�Z+dd�Z,dd�Z-dd�Z.d�Z/dddd�Z0d�Z1d�Z2dS(u*
Functions used for CLI argument handling
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationError(tsix(tmaptzipu^([^\d\W][\w.-]*)=(?!=)(.*)$cK@sFi}x9tj|�D](\}}|jd�s|||<qqW|S(u�
    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)
    u__(Rt	iteritemst
startswith(tkwargstrettkeytval((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytclean_kwargs!s
cC@s�|rUt|t�rUgtj|�D]\}}dj||�^q%}|}qUndjdj|��}|r�t|��n|SdS(uD
    Raise a SaltInvocationError if invalid_kwargs is non-empty
    u{0}={1}u2The following keyword arguments are not valid: {0}u, N(t
isinstancetdictRRtformattjoinR(tinvalid_kwargst	raise_exctxtytnew_invalidtmsg((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyR6s1cC@s�g}x�|D]}}tjrLt|tj�rLtjjjtj|��sdtj	r}t|t
�r}|jtj|��q
|j|�q
Wt|t�r�|r�it
d6}x'tj|�D]\}}|||<q�W||gS|S(uG
    Return a single arg structure for the publisher to safely use
    u	__kwarg__(RtPY3Rt
integer_typestsalttutilstjidtis_jidt	text_typetPY2tlongtappendRtTrueR(targsR	R
targtkw_RR((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytcondition_inputKs
9
cC@s|dkrd}ng}i}x�|D]�}t|tj�r�t|�\}}|r}||krpt|�n|||<q�|jt|��q(t|t�r�|jdt	�t
kr�|j|�q�|j|�q(|j|�q(W|r�t||�S||fS(u�
    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.
    u	__kwarg__N((
tNoneRRtstring_typestparse_kwargtyamlify_argR!RtpoptFalseR"tupdateR&(R#t	conditiontno_parset_argst_kwargsR$targ_namet	arg_value((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytparse_input^s&	


cC@s0ytj|�j�SWntk
r+dSXdS(u�
    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.
    N(NN(tKWARG_REGEXtmatchtgroupstAttributeErrorR'(tstring_((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyR)�s
c	C@st|tj�s|S|j�dkr,|Sd|krgtg|j�D]}|dk^qH�rg|Sy�ddl}|}d|kr�|jjj|�}t|tj�s�|dkr�|S|S|dkr�d}n|jjj|�}t|t
�r)t|tj�r"|jd�r"|S|Sn�t|t�ret|tj�r^|jd	�r^|S|Sn�|dks�t|tt
tjtjf�r�|dkr�|dkr�|S|dkr�|j�jd�r�|S|dkr�|dkr�|S|Sn|SWntk
r|SXdS(
u 
    yaml.safe_load the arg
    uu_u0123456789_iNu#uNoneu{u[u|u!(u|u!(RRR(tstriptalltsalt.utils.yamlRtyamlt	safe_loadR'RRtlisttfloatRt	Exception(R$RRtoriginal_argt
parsed_arg((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyR*�sN7	!!
(t
namedtupleuArgSpecuargs varargs keywords defaultscC@sRtj|�\}}}}}}}|s0|r?td��nt||||�S(u�
        Python 3 wrapper for inspect.getargsspec

        inspect.getargsspec is deprecated and will be removed in Python 3.6.
        ucFunction has keyword-only arguments or annotations, use getfullargspec() API which can support them(tinspecttgetfullargspect
ValueErrort_ArgSpec(tfuncR#tvarargstvarkwtdefaultst
kwonlyargst_tann((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyt_getargspec�s$cC@s�t|�s$tdj|���ntjr�|tkrUtj|�}|jd=q�tj	|�rvtj|�}q�tj
|�r�tj|�}|jd=q�t|t�r�tj|j
�}|jd=q�tdj|���n�|tkrt|�}|jd=n�tj	|�r*t|�}nhtj
|�rRt|�}|jd=n@t|t�r}t|j
�}|jd=ntdj|���|S(u�
    A small wrapper around getargspec that also supports callable classes
    :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.
    u{0} is not a callableiu&Cannot inspect argument list for '{0}'(tcallablet	TypeErrorRRRR"REt
getargspecR#t
isfunctiontismethodRtobjectt__call__RP(RItis_class_methodtaspec((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytget_function_argspec�s<	





cK@sHt|tj�r@tjjjtjtjj	j
|�|��S|SdS(u,
    Only split if variable is a string
    N(RRR(RRtdatatdecodetshlextsplittstringutilstto_str(tsR	((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytshlex_split#s"cC@s�iid6}|dkr(t|�}n|jrmtt|jddd�|jddd���|d<ng|jD]}||dkrw|^qw|d<|S(u[
    Return a dict containing the arguments and default arguments to the
    function.
    ukwargsNi����uargs(R'RZRLRRR#(tfunRYR
R$((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyt
arg_lookup3s
	<0uc
C@s�i}d|ksd|kr�x�tj||�D]�}yt||�}Wntk
raq1nX|\}}}}i||<|r�|nd||d<|r�|nd||d<|r�tnd||d<|r�tnd||d<q1Wn�|d}	x�|D]�}|j|	�r�yt||�}Wntk
r=q�nX|\}}}}i||<|rf|nd||d<|r�|nd||d<|r�tnd||d<|r�tnd||d<q�q�W|S(us
    Pass in a functions dict as it is returned from the loader and return the
    argspec function signatures
    u*u.uargsudefaultsuvarargsukwargsN(tfnmatchtfilterRZRRR'R"R(
t	functionstmoduleR
RcRYR#RJR	RLt
module_dot((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytargspec_reportAs6

!



!cC@s�|dkrd�}nt|t�r:tt||��Sy9tt|g|jd�D]}|j�^qV��SWnLtk
r�tt|gtj|�jd�D]}|j�^q���SXdS(uT
    Take an input value and split it into a list, returning the resulting list
    cS@s|S(N((R((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyt<lambda>ssu,N(	R'RR?RR^R:R8RR(RtmapperR((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytsplit_inputns9
cK@svddl}xctj|�D]R\}}y/|j�dkrV|jjj|�rVtSWqtk
rmqqXqWt	S(u�
    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).
    iNutest(
t
salt.utilsRRtlowerRR[tis_trueR"R8R,(R	RR$tvalue((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyt	test_mode|s'
cC@s�|dk	r|pi}g|d<i|d<t|d|�}t||�}|d}|d}	|j�}g}
x9|	D]1}y|j|�|	|<Wqztk
r�qzXqzWxX|r	|jd�}y|dj|j|��Wq�tk
r|
j|�q�Xq�W|
rpt|d�t|�}
|
t|
�}tdj	|j
||dkr^dpad|
���n|dj|	�|jr�x=t
j|�D],\}}||kr�q�n||d|<q�W|Si}xBt
j|�D]1\}}||krq�ntj|�||<q�W|r�t|�dkrpd	j	t|j��|jd
dj	|j|j
���}nldj	d
jg|D]}dj	|�^q�d �t|j��d|jd
dj	|j|j
���}t|��n|S(u�
    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.
    uargsukwargsRXiu.{0} takes at least {1} argument{2} ({3} given)iusuu1'{0[0]}' is an invalid keyword argument for '{1}'ufullu{0}.{1}u5{0} and '{1}' are invalid keyword arguments for '{2}'u, u'{0}'i����N(R'RZRdtcopyR+tKeyErrorR!tlenRRt__name__R-tkeywordsRRtdeepcopyR?tkeystgett
__module__R(RcR[tinitial_rettexpected_extra_kwsRXR
RYtarg_dataR#R	tmissing_argsRR$tused_args_countt
args_countRqtextraRte((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytformat_call�sp





	
	!,c
	C@stj|dt�}d|_g}g}i}g}d}d}x+|D]#}|dkr_Pn|j|�qIW|s�|dkr�dSdj|�}g}t}	xC|D];}|dkr�|j|�|j|�q�|dks�|dkrW|rW|rdj|�||<n|r2|jdj|��n|dkrHt}	Pnd}g}q�|dkr�|s�|id	d
6dd6dd6|j�kr�Pn|j|�q�|d
kr�|r�dj|�}g}q�q�|j|�q�W|	r�|||fSdSdS(u�
    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.
    tposixu"'u(uu[{(u,u)u]})u]u[u}u{u=N(NNN(NNN(R]R"t
escapedquotesR'R!RR,R+(
RatshtwordR#R	tbracketsRttokentfnametgood((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytparse_functionsV	


	2
cC@szi}i}xatj|�D]P\}}||krS|dk	r|||<qqn|dk	r|||<qqW||fS(u
    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(RRR'(t
all_kwargstclass_init_kwargst
fun_kwargstinit_kwargstkargtwarg((s3/usr/lib/python2.7/site-packages/salt/utils/args.pytprepare_kwargs>s
((3t__doc__t
__future__RRRRsReREtloggingtreR]tsalt.exceptionsRtsalt.extRtsalt.ext.six.movesRRtsalt.utils.dataRtsalt.utils.jidtsalt.utils.versionsR<t	getLoggerRvtlogRtcompiletUNICODER5R
R"RR&R'R4R)R*tcollectionsRDRHRPRZRbRdRjRmRrR�R�R�(((s3/usr/lib/python2.7/site-packages/salt/utils/args.pyt<module>sN			#		M	1	-	r	;

Zerion Mini Shell 1.0