Did I find the right examples for you? yes no

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Override items in a target pdict. Target keys must already exist
unless there is a "__MANY__" placeholder in the right position.

        def m_override( target, sparse ):
    """Override items in a target pdict. Target keys must already exist
    unless there is a "__MANY__" placeholder in the right position."""
    if not sparse:
        target = OrderedDict()
        return
    for key,val in sparse.items():
        if isinstance( val, dict ):
            if key not in target:
                if '__MANY__' in target:
                    target[key] = OrderedDict()
                    replicate( target[key], target['__MANY__'] )
                else:
                    # TODO - validation prevents this, but handle properly for completeness.
                    raise Exception( "parsec dict override: no __MANY__ placeholder" )
            m_override( target[key], val )
        else:
            if key not in target:
                if '__MANY__' in target:
                    if isinstance( val, list ):
                        target[key] = val[:]
                    else:
                        target[key] = val
                else:
                    # TODO - validation prevents this, but handle properly for completeness.
                    raise Exception( "parsec dict override: no __MANY__ placeholder" )
            if isinstance( val, list ):
                target[key] = val[:]
            else:
                target[key] = val
        


src/c/y/cylc-HEAD/lib/parsec/validate.py   cylc(Download)
import sys, re
from OrderedDict import OrderedDict
from util import m_override, un_many, itemstr
from copy import copy
 
def expand( sparse, spec ):
    # get dense defaults
    dense = get_defaults(spec)
    # override defaults with sparse values
    m_override( dense, sparse )