%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/data.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZy ddl	m
Z
mZmZWn-e
k
r�ddlm
Z
mZmZnXddlZddlZddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZeje �Z!defd��YZ"e#d
�Z$e#d�Z%e#d�Z&ed�ddd��Z(ed�ddd��Z)dde#e#e#e#e#d�Z*dde#e#e#e#e#d�Z+dde#e#e#e#e#d�Z,dde#e#e#e#d�Z-dde#e#e#d�Z.ed�ed�dde#e#e#d���Z/ed�ed�dde#e#e#d���Z0dde#e#d �Z1ed!�d"d#��Z2ed$�d%��Z3dd&dd'�Z4ded(�Z5ed)�ded*��Z6ee#e#d+�Z7ed,�d-��Z8d.�Z9e#e#ddd/�Z:ed0�d1��Z;ed2�ej<d3��Z=ed4�d5��Z>dd6�Z?ed7�d8��Z@d9�ZAd:�ZBdS(;uc
Functions for manipulating, inspecting, or otherwise working with data types
and data structures.
i(tabsolute_importtprint_functiontunicode_literalsN(tMappingtMutableMappingtSequence(tDEFAULT_TARGET_DELIM(t
SaltException(tjinja_filter(tOrderedDict(tsix(trangetCaseInsensitiveDictcB@skeZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
RS(uq
    Inspired by requests' case-insensitive dict implementation, but works with
    non-string keys as well.
    cK@s&t�|_|j|pi|�dS(uy
        Force internal dict to be ordered to ensure a consistent iteration
        order, irrespective of case.
        N(R	t_datatupdate(tselftinittkwargs((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__init__)scC@s
t|j�S(N(tlenR
(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__len__1scC@s||f|jt|�<dS(N(R
tto_lowercase(Rtkeytvalue((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__setitem__4scC@s|jt|�=dS(N(R
R(RR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__delitem__8scC@s|jt|�dS(Ni(R
R(RR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__getitem__;scC@sd�tj|j�D�S(Ncs@s|]}|dVqdS(iN((t.0titem((s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>?s(R
t
itervaluesR
(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__iter__>scC@s;t|t�stSt|j��tt|�j��kS(N(t
isinstanceRtFalsetdicttitems_lowerR(Rtrval((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__eq__AscC@stttj|���S(N(treprR!R
t	iteritems(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt__repr__GscC@sd�tj|j�D�S(up
        Returns a generator iterating over keys and values, with the keys all
        being lowercase.
        cs@s%|]\}}||dfVqdS(iN((RRtval((s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>Os(R
R&R
(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR"JscC@sttj|j��S(u.
        Returns a copy of the object
        (RR
R&R
(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytcopyQsN(t__name__t
__module__t__doc__tNoneRRRRRRR$R'R"R)(((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR$s								c@s�yt|���SWntk
r'nX|j}t|t�rr�rL|nt��fd�tj|�D��St|t�r�|��fd�|D��S|SdS(Nc3@s9|]/\}}t|���t|���fVqdS(N(t
__change_case(RRR((tattrtpreserve_dict_class(s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>bsc3@s!|]}t|���VqdS(N(R.(RR(R/R0(s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>hs(	tgetattrtAttributeErrort	__class__RRR!R
R&R(tdataR/R0t	data_type((R/R0s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR.Xs
	cC@st|d|�S(Nulower(R.(R4R0((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRmscC@st|d|�S(Nuupper(R.(R4R0((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytto_uppercaseqsu
compare_dictscC@s�i}x�t|pi�j|p$i�D]�}||krYidd6||d6||<q(||kr�idd6||d6||<q(||||kr(i||d6||d6||<q(q(W|S(u�
    Compare before and after results from various salt functions, returning a
    dict describing the changes that were made.
    uuoldunew(tsettunion(toldtnewtretR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt
compare_dictsus(

u
compare_listscC@sat�}x'|D]}||kr||d<qqWx'|D]}||kr:||d<q:q:W|S(u�
    Compare before and after results from various salt functions, returning a
    dict describing the changes that were made
    unewuold(R!(R9R:R;R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt
compare_lists�s	

ustrictc		C@s!|stjjjntjjj}t|t�rRt||||||||�St|t�r�t	||||||||�St|t
�r�|r�t|||||||�St	||||||||�Sy|||||�}Wn-tk
r�nt
k
r|s�qnX|SdS(ua
    Generic function which will decode whichever type is passed, if necessary.
    Optionally use to_str=True to ensure strings are str types and not unicode
    on Python 2.

    If `strict` is True, and `keep` is False, and we fail to decode, a
    UnicodeDecodeError will be raised. Passing `keep` as True allows for the
    original value to silently be returned in cases where decoding fails. This
    can be useful for cases where the data passed to this function is likely to
    contain binary blobs, such as in the case of cp.recv.

    If `normalize` is True, then unicodedata.normalize() will be used to
    normalize unicode strings down to a single code point per glyph. It is
    recommended not to normalize unless you know what you're doing. For
    instance, if `data` contains a dictionary, it is possible that normalizing
    will lead to data loss because the following two strings will normalize to
    the same value:

    - u'\u044f\u0438\u0306\u0446\u0430.txt'
    - u'\u044f\u0439\u0446\u0430.txt'

    One good use case for normalization is in the test suite. For example, on
    some platforms such as Mac OS, os.listdir() will produce the first of the
    two strings above, in which "й" is represented as two code points (i.e. one
    for the base character, and one for the breve mark). Normalizing allows for
    a more reliable test case.
    N(tsalttutilststringutilst
to_unicodetto_strRRtdecode_dicttlisttdecode_listttupletdecode_tuplet	TypeErrortUnicodeDecodeError(	R4tencodingterrorstkeept	normalizeR0tpreserve_tuplesRBt_decode_func((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytdecode�s(

"



c
C@s|stjjjntjjj}|r6|j�ni}	x�tj|�D]�\}
}t|
t	�r�|r�t
|
||||||�nt|
|||||||�}
nIy||
|||�}
Wn-tk
r�nt
k
r�|s��q�nXt|t�r+t||||||||�}n�t|t	�r�|r^t
|||||||�nt||||||||�}n|t|t�r�t||||||||�}nIy|||||�}Wn-tk
r�nt
k
r�|s��q�nX||	|
<qLW|	S(u�
    Decode all string values to Unicode. Optionally use to_str=True to ensure
    strings are str types and not unicode on Python 2.
    (R>R?R@RARBR3R
R&RRFRGRERHRIRDRRC(R4RJRKRLRMR0RNRBROtrvRR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRC�sD$


$


c
C@sR|stjjjntjjj}g}	x!|D]}
t|
t�rjt|
|||||||�}
n�t|
t�r�|r�t	|
||||||�nt|
|||||||�}
n|t|
t
�r�t|
|||||||�}
nIy||
|||�}
Wn-tk
r nt
k
r<|s=�q=nX|	j|
�q1W|	S(u�
    Decode all string values to Unicode. Optionally use to_str=True to ensure
    strings are str types and not unicode on Python 2.
    (R>R?R@RARBRRDRERFRGRRCRHRItappend(R4RJRKRLRMR0RNRBRORQR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyREs.
$


c
C@s%tt||||||t|��S(u�
    Decode all string values to Unicode. Optionally use to_str=True to ensure
    strings are str types and not unicode on Python 2.
    (RFREtTrue(R4RJRKRLRMR0RB((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRG:scC@s�t|t�r(t||||||�St|t�rPt||||||�St|t�r�|r{t|||||�St||||||�Sytjj	j
|||�SWn-tk
r�ntk
r�|s��q�nX|SdS(u�
    Generic function which will encode whichever type is passed, if necessary

    If `strict` is True, and `keep` is False, and we fail to encode, a
    UnicodeEncodeError will be raised. Passing `keep` as True allows for the
    original value to silently be returned in cases where encoding fails. This
    can be useful for cases where the data passed to this function is likely to
    contain binary blobs.
    N(
RRtencode_dictRDtencode_listRFtencode_tupleR>R?R@tto_bytesRHtUnicodeEncodeError(R4RJRKRLR0RN((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytencodeFs$





ujson_decode_dictujson_encode_dictc	C@s�|r|j�ni}x�tj|�D]�\}}t|t�r|rat|||||�nt||||||�}nOytjj	j
|||�}Wn-tk
r�ntk
r�|s��q�nXt|t
�r�t||||||�}n�t|t�rF|r(t|||||�nt||||||�}n|t|t�rst||||||�}nOytjj	j
|||�}Wn-tk
r�ntk
r�|s��q�nX|||<q(W|S(u+
    Encode all string values to bytes
    (R3R
R&RRFRVRUR>R?R@RWRHRXRDRRT(	R4RJRKRLR0RNRQRR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRTjs@





ujson_decode_listujson_encode_listcC@sg}x|D]}t|t�r@t||||||�}n�t|t�r�|rmt|||||�nt||||||�}n|t|t�r�t||||||�}nOytjj	j
|||�}Wn-tk
r�ntk
r|s�qnX|j
|�q
W|S(u+
    Encode all string values to bytes
    (RRDRURFRVRRTR>R?R@RWRHRXRR(R4RJRKRLR0RNRQR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRU�s*



cC@stt|||||t��S(u-
    Encode all string values to Unicode
    (RFRURS(R4RJRKRLR0((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRV�suexactly_n_trueic@s9t|��t�fd�t|�D��o8t��S(ub
    Tests that exactly N items in an iterable are "truthy" (neither None,
    False, nor 0).
    c3@s|]}t��VqdS(N(tany(Rtj(ti(s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>�s(titertallRRZ(tltn((R\s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt	exactly_n�suexactly_one_truecC@s
t|�S(uI
    Check if only one item is not None, False, or 0 in an iterable.
    (Ra(R_((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytexactly_one�sudefaultc
C@s�d}t||g�}x�t|t�r0|n|gD]�}x||D]t}	t|	tj�rb|	ntj|	�}
t|tj�r�|ntj|�}tj||
�rD||	}PqDqDW|dk	r7Pq7q7W|dkr�|j	|d�}n|rv||krv||}|dkr"|}qvt|t
�rvt|t
�sOtd��ntj
jjtj|�|�}qvn|r�t|t
�s�td��n|dkr�|}q�tj
jj|tj|��n|S(uF
    Common code to filter data structures like grains and pillar
    u?filter_by default and look-up values must both be dictionaries.u.filter_by merge argument must be a dictionary.N(R-ttraverse_dict_and_listRRDR
tstring_typest	text_typetfnmatchtfnmatchcasetgetRRR>R?t
dictupdateRR)tdeepcopy(
tlookup_dicttlookupttraversetmergetdefaulttbaseR;R(teachRttest_keyt	test_eachtbase_values((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt	filter_by�s@	%


	'	"cC@sP|}y(x!|j|�D]}||}qWWntttfk
rK|SX|S(u
    Traverse a dict using a colon-delimited (or otherwise delimited, using the
    'delimiter' param) target string. The target 'foo:bar:baz' will return
    data['foo']['bar']['baz'] if this value exists, and will otherwise return
    the dict in the default argument.
    (tsplittKeyErrort
IndexErrorRH(R4RRot	delimitertptrRq((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt
traverse_dictsutraversec	C@s�|}x�|j|�D]�}t|t�r�yt|�}Wnetk
r�t}xAd�|D�D]/}y||}t}PWqbtk
r�qbXqbW|s�|Sq�Xy||}Wq�tk
r�|SXqy||}Wqtt	fk
r�|SXqW|S(u	
    Traverse a dict or list using a colon-delimited (or otherwise delimited,
    using the 'delimiter' param) target string. The target 'foo:bar:0' will
    return data['foo']['bar'][0] if this value exists, and will otherwise
    return the dict in the default argument.
    Function will automatically determine the target type.
    The target 'foo:bar:0' will return data['foo']['bar'][0] if data like
    {'foo':{'bar':['baz']}} , if data like {'foo':{'bar':{'0':'baz'}}}
    then return data['foo']['bar']['0']
    cs@s$|]}t|t�r|VqdS(N(RR!(Rtx((s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>:s(
RvRRDtintt
ValueErrorR RSRwRxRH(	R4RRoRyRzRqtidxtembed_matchtembedded((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyRc&s2



	c	@s�ttd��tt��fd��|j|�}t|�}|dkrRtS|j|�}t|�}|dkr}tSxnt|ddd�D]V}|j|| �}|dkr�|}	|}
n+|j||�}	t||id|�}
tjd|	||�|
ikrq�nt|
t	�rO�|
|	d	|d
|�r�t
Sq�nt|
ttf�r�x^|
D]V}t|t	�r��||	d	|d
|�r�t
Sn�||	d	|d
|�rkt
SqkWq�n�|
|	d	|d
|�r�t
Sq�WtS(uf
    Check for a match in a dictionary using a delimiter character to denote
    levels of subdicts, and also allowing the delimiter character to be
    matched. Thus, 'foo:bar:baz' will match data['foo'] == 'bar:baz' and
    data['foo']['bar'] == 'baz'. The latter would take priority over the
    former, as more deeply-nested matches are tried first.
    cS@s�ytj|�j�}Wn,tk
rGtjjj|�j�}nXytj|�j�}Wn,tk
r�tjjj|�j�}nX|r�ytj	||�SWq�t
k
r�tjd|�t
SXn |r�||kStj||�SdS(NuInvalid regex '%s' in match(R
RetlowerRIR>R?R@RAtretmatcht	ExceptiontlogterrorR Rf(ttargettpatterntregex_matchtexact_match((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt_match]s 



c	@s%|jd�}|r"|d}n|dkr2tS||krBtSt||d|d|�ratS|r!x�|D]�}t||t�r��|||d|d|�rtSqnt||t�r�xW||D]%}�||d|d|�r�tSq�Wqn�|||d|d|�rntSqnWntS(Nu*:iu*R�R�(t
startswithRSt
subdict_matchRR!RDR (R�R�R�R�twildcardRR(t_dict_matchR�(s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR�zsB
	

		
	iii����u*Ryu5Attempting to match '%s' in '%s' using delimiter '%s'R�R�(
R RvRRtjoinRcR�tdebugRR!RSRDRF(R4texprRyR�R�tsplitst
num_splitsRRtmatchstrR�tmember((R�R�s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR�Qs`&		
	
			usubstring_in_listc@st�fd�|D��S(u�
    Return a boolean value that indicates whether or not a given
    string is present in any of the strings which comprise a list
    c3@s|]}�|kVqdS(N((Rts(tstring_to_search_for(s3/usr/lib/python2.7/site-packages/salt/utils/data.pys	<genexpr>�s(RZ(R�tlist_to_search((R�s3/usr/lib/python2.7/site-packages/salt/utils/data.pytsubstr_in_list�scC@sTt|t�rPx:|D]2}t|t�rDt|�dkrHtSqtSqWtStS(uy
    Returns True if data is a list of one-element dicts (as found in many SLS
    schemas), otherwise returns False
    i(RRDR!RR RS(R4telement((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytis_dictlist�s
cC@st|tj�r^ytjjj|�}Wq^tjjjjk
rZ}t	j
|�iSXn|d	krvd�}n|d	kr�d�}ntjtjt
f}t|t�r'x�|D]g}t||�r�q�q�t|t�rt|�dkr t	j
d|�iSq�t	j
d|�iSq�Wnt	j
d|�iSi}x�|D]�}t||�rpd	|||�<qHtt|��}	||	}
t|
�r�|r�t|
d|�|||	�<q	|r�t	j
d�iS||	|
�|||	�<qH||	|
�|||	�<qHW|S(
ut
    Takes a list of one-element dicts (as found in many SLS schemas) and
    repacks into a single dictionary.
    cS@s|S(N((R|((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt<lambda>scS@s|S(N((R|ty((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR�siucInvalid input for repack_dictlist: key/value pairs must contain only one element (data passed: %s).uPInvalid input for repack_dictlist: element %s is not a string/dict/numeric valueuAInvalid input for repack_dictlist, data passed is not a list (%s)trecurseuUInvalid input for repack_dictlist: nested dictlist found, but recurse is set to FalseN(RR
RdR>R?tyamlt	safe_loadtparsertParserErrorR�R�R-t
integer_typestfloatRDR!RtnextR]R�trepack_dictlist(R4tstrictR�tkey_cbtval_cbterrtvalid_non_dictR�R;RR(((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR��sZ	



uis_listcC@s
t|t�S(u(
    Check if a variable is a list.
    (RRD(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytis_list9suis_itercC@sD|rt||�rtSyt|�tSWntk
r?tSXdS(u�
    Test if an object is iterable, but not a string type.

    Test if an object is an iterator or is iterable itself. By default this
    does not return True for string objects.

    The `ignore` argument defaults to a list of string types that are not
    considered iterable. This can be used to also exclude things like
    dictionaries or named tuples.

    Based on https://bitbucket.org/petershinners/yter
    N(RR R]RSRH(R�tignore((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytis_iterAs

usorted_ignorecasecC@st|dd��S(u�
    Sort a list of strings ignoring case.

    >>> L = ['foo', 'Foo', 'bar', 'Bar']
    >>> sorted(L)
    ['Bar', 'Foo', 'bar', 'foo']
    >>> sorted(L, key=lambda x: x.lower())
    ['bar', 'Bar', 'foo', 'Foo']
    >>>
    RcS@s
|j�S(N(R�(R|((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR�es(tsorted(tto_sort((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytsorted_ignorecaseYscC@s�yt|�}Wnttfk
r)nXyt|�}Wnttfk
rSnXt|tjtf�rv|dkSt|tj�r�tj|�j	�dkSt
|�SdS(u
    Returns a boolean value representing the "truth" of the value passed. The
    rules for what is a "True" value are:

        1. Integer/float values greater than 0
        2. The string values "True" and "true"
        3. Any object for which bool(obj) returns True
    iutrueN(R}R~RHR�RR
R�RdReR�tbool(R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pytis_truehs

u
mysql_to_dictc
C@si}dg}x�|D]�}|s(qn|jd�r=qn|jd�}x.tt|��D]}||j�||<q_Wt|�dkrt|�d}i}xGt|�D]9}	|	dkr�q�q�tjjj||	�|||	<q�W||||<q|}qW|S(u;
    Convert MySQL-style output to a python dictionary
    uu+u|i(	R�RvRRtstripR>R?R@tto_num(
R4RR;theaderstlinetcompstcomptindextrowtfield((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt
mysql_to_dict�s(	
%
cC@s�|dkr|Stjtjtjttf}tt|�ttg�}t	|ttf�r�g}xl|D]d}|dk	r�t	|t
tf�r�t|�}q�t	||�s�t|�}q�n|j
|�qlW|St	|t
�r�i}x�tj|�D]�\}}|dk	r4t	||�r4t|�}n|dk	rgt	|t
ttf�rgt|�}n+|dk	r�t	||�r�t|�}n|||<q�W|S|S(ug
    Convert the data list, dictionary into simple types, i.e., int, float, string,
    bool, etc.
    N(R-R
RdReR�R�R�RFRDRR!tsimple_types_filterR%RRR&(R4tsimpletypes_keystsimpletypes_valuestsimplearrayRt
simpledictR((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyR��s4
$cC@s|g}xo|D]g}tjrCt|t�rCtjjj|�}n$t|tj�sgtj	|�}n|j
|�q
W|S(uu
    Given an iterable, returns its items as a list, with any non-string items
    converted to unicode strings.
    (R
tPY2RtstrR>R?R@RARdReRR(R4R;R((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt	stringify�s
(CR,t
__future__RRRR)RftloggingR�tcollections.abcRRRtImportErrortcollectionstsalt.utils.dictupdateR>tsalt.utils.stringutilstsalt.utils.yamlt
salt.defaultsRtsalt.exceptionsRtsalt.utils.decorators.jinjaRtsalt.utils.odictR	tsalt.extR
tsalt.ext.six.movesRt	getLoggerR*R�RR R.RR6R-R<R=RPRCRERGRYRTRURVRaRbRuR{RcR�R�R�R�R�RdR�R�R�R�R�R�(((s3/usr/lib/python2.7/site-packages/salt/utils/data.pyt<module>s� 
 4				9	9	&		#			2			!			2	,�		B		%

Zerion Mini Shell 1.0