%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/aggregation.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlmZddl	m
Z
dddd	d
gZeje
�Zdefd��YZd
eefd��YZdeefd��YZd�Zd�Zeed�Zeeed�ZdS(u/
    salt.utils.aggregation
    ~~~~~~~~~~~~~~~~~~~~~~

    This library makes it possible to introspect dataset and aggregate nodes
    when it is instructed.

    .. note::

        The following examples with be expressed in YAML for convenience's sake:

        - !aggr-scalar will refer to Scalar python function
        - !aggr-map will refer to Map python object
        - !aggr-seq will refer for Sequence python object


    How to instructs merging
    ------------------------

    This yaml document has duplicate keys:

    .. code-block:: yaml

        foo: !aggr-scalar first
        foo: !aggr-scalar second
        bar: !aggr-map {first: foo}
        bar: !aggr-map {second: bar}
        baz: !aggr-scalar 42

    but tagged values instruct Salt that overlapping values they can be merged
    together:

    .. code-block:: yaml

        foo: !aggr-seq [first, second]
        bar: !aggr-map {first: foo, second: bar}
        baz: !aggr-seq [42]


    Default merge strategy is keep untouched
    ----------------------------------------

    For example, this yaml document still has duplicate keys, but does not
    instruct aggregation:

    .. code-block:: yaml

        foo: first
        foo: second
        bar: {first: foo}
        bar: {second: bar}
        baz: 42

    So the late found values prevail:

    .. code-block:: yaml

        foo: second
        bar: {second: bar}
        baz: 42


    Limitations
    -----------

    Aggregation is permitted between tagged objects that share the same type.
    If not, the default merge strategy prevails.

    For example, these examples:

    .. code-block:: yaml

        foo: {first: value}
        foo: !aggr-map {second: value}

        bar: !aggr-map {first: value}
        bar: 42

        baz: !aggr-seq [42]
        baz: [fail]

        qux: 42
        qux: !aggr-scalar fail

    are interpreted like this:

    .. code-block:: yaml

        foo: !aggr-map{second: value}

        bar: 42

        baz: [fail]

        qux: !aggr-seq [fail]


    Introspection
    -------------

    TODO: write this part

i(tabsolute_importtprint_functiontunicode_literalsN(tOrderedDict(tsixu	aggregateu	AggregateuMapuScalaruSequencet	AggregatecB@seZdZRS(u
    Aggregation base.
    (t__name__t
__module__t__doc__(((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pyRzstMapcB@seZdZRS(u
    Map aggregation.
    (RRR(((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pyR	�stSequencecB@seZdZRS(u
    Sequence aggregation.
    (RRR(((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pyR
�scC@s
t|g�S(u]
    Shortcut for Sequence creation

    >>> Scalar('foo') == Sequence(['foo'])
    True
    (R
(tobj((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pytScalar�scC@s�|sttfS|tkr&ttfSt|t�rCt|dfSy/t|d�|d}}t|�|fSWn#tk
r�}tj|��nXdS(u�
    Describe which levels are allowed to do deep merging.

    level can be:

    True
        all levels are True

    False
        all levels are False

    an int
        only the first levels are True, the others are False

    a sequence
        it describes which levels are True, it can be:

        * a list of bool and int values
        * a string of 0 and 1 characters

    iiN(tFalsetTruet
isinstancetinttboolt	Exceptiontlogtwarning(tleveltdeeptsubsterror((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pytlevelise�s


cC@s_t|t�r|St|t�r,||�St|tttf�rN||�S||g�SdS(u0
    Convert obj into an Aggregate instance
    N(RRtdicttlistttupletset(Rt	map_classtsequence_class((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pytmark�s

c
	C@s�t|�\}}|rKt|d|d|�}t|d|d|�}nt|t�rt|t�rt|t�r�t|t�r�tj|�}ntj|�}xRtj|�D]A\}}	||kr�t|||	|||�}	n|	||<q�W|St|t	�r`t|t	�r`|j
|�}x*|D]"}	|	|kr6|j|	�q6q6W|Stj|�}t|t�s�t|t�r�tj
d�|Stjd�|S(um
    Merge obj_b into obj_a.

    >>> aggregate('first', 'second', True) == ['first', 'second']
    True
    RRu6only one value marked as aggregate. keep `obj_b` valueu0no value marked as aggregate. keep `obj_b` value(RR RRRtcopyRt	iteritemst	aggregateR
t	__class__tappendRtinfotdebug(
tobj_atobj_bRRRRtsubdeeptresponsetkeytvalue((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pyR#�s4



(Rt
__future__RRRR!tloggingtsalt.utils.odictRtsalt.extRt__all__t	getLoggerRRtobjectRR	RR
RRR R
R#(((s:/usr/lib/python2.7/site-packages/salt/utils/aggregation.pyt<module>hs		%

Zerion Mini Shell 1.0