Esempio n. 1
0
 def default_context(self):
     """@return a NodeGeneratorContextStore instance whose fields are initialized with some sensible defaults. Those 
     can be obtained from any data source.
     The fields match our static field schema.
     The instance will include all fields used by our next() generators, recursively.
     @note this function is used by user interfaces to provide initial values, or options that can be changed"""
     # additive merge over all static schemas, don't allow overrides
     delegate = self.AdditiveMergeDelegateType()
     twoway = TwoWayDiff()
     base = delegate.DictType()
     
     for generator, depth in self._iter_(self, self.downstream, self.breadth_first):
         twoway.diff(delegate, base, generator._default_context().data())
         base = delegate.result()
     # end for each generator
     return self.NodeGeneratorContextStoreType(delegate.result())
Esempio n. 2
0
    def _aggregated_kvstore(self, aggregated_base=None, start_at = 0):
        """@return new context as aggregate of all contexts on our stack, bottom up"""
        # This delegate makes sure we don't let None values override non-null values
        delegate = StackAutoResolveAdditiveMergeDelegate()
        alg = TwoWayDiff()
        
        for eid in range(start_at, len(self._stack)):
            ctx = self._stack[eid]
            base = delegate.result()
            if base is NoValue:
                base = aggregated_base or OrderedDict()
            # end setup base
            alg.diff(delegate, base, ctx.settings()._data())
        # end for each Context
        self._num_aggregated_kvstores = len(self._stack)

        res = delegate.result()
        if res is NoValue:
            assert aggregated_base is not None
            assert isinstance(aggregated_base, OrderedDict)
            res = aggregated_base
        # end handle special case with empty dicts
        return self.ContextType.KeyValueStoreModifierType(res)