def evaluate(value, context, freeze=True): list_type = tuple if freeze else list dict_type = yaqlutils.FrozenDict if freeze else dict set_type = frozenset if freeze else set if isinstance(value, (dsl_types.YaqlExpression, yaql.language.expressions.Statement)): return value(context) elif isinstance(value, yaqlutils.MappingType): return dict_type( (evaluate(d_key, context, freeze), evaluate(d_value, context, freeze)) for d_key, d_value in six.iteritems(value)) elif yaqlutils.is_sequence(value): return list_type(evaluate(t, context, freeze) for t in value) elif isinstance(value, yaqlutils.SetType): return set_type(evaluate(t, context, freeze) for t in value) elif yaqlutils.is_iterable(value): return list_type( evaluate(t, context, freeze) for t in yaqlutils.limit_iterable( value, constants.ITERATORS_LIMIT)) elif isinstance(value, dsl_types.MuranoObjectInterface): return value.object else: return value
def evaluate(value, context, freeze=True): list_type = tuple if freeze else list dict_type = yaqlutils.FrozenDict if freeze else dict set_type = frozenset if freeze else set if isinstance( value, (dsl_types.YaqlExpression, yaql.language.expressions.Statement)): return value(context) elif isinstance(value, yaqlutils.MappingType): return dict_type((evaluate(d_key, context, freeze), evaluate(d_value, context, freeze)) for d_key, d_value in value.items()) elif yaqlutils.is_sequence(value): return list_type(evaluate(t, context, freeze) for t in value) elif isinstance(value, yaqlutils.SetType): return set_type(evaluate(t, context, freeze) for t in value) elif yaqlutils.is_iterable(value): return list_type( evaluate(t, context, freeze) for t in yaqlutils.limit_iterable( value, CONF.murano.dsl_iterators_limit)) elif isinstance(value, dsl_types.MuranoObjectInterface): return value.object else: return value
def to_mutable(obj, yaql_engine): def converter(value, limit_func, engine, rec): if isinstance(value, dsl_types.MuranoObject): return MuranoObjectInterface(value) else: return utils.convert_output_data(value, limit_func, engine, rec) limiter = lambda it: utils.limit_iterable(it, constants.ITERATORS_LIMIT) return converter(obj, limiter, yaql_engine, converter)
def to_mutable(obj, yaql_engine=None): if yaql_engine is None: yaql_engine = helpers.get_yaql_engine() def converter(value, limit_func, engine, rec): if isinstance(value, dsl_types.MuranoObject): return MuranoObjectInterface.create(value) else: return utils.convert_output_data(value, limit_func, engine, rec) limiter = lambda it: utils.limit_iterable(it, CONF.murano. dsl_iterators_limit) return converter(obj, limiter, yaql_engine, converter)
def evaluate(value, context): if isinstance(value, (dsl_types.YaqlExpression, yaql.language.expressions.Statement)): return value(context) elif isinstance(value, yaqlutils.MappingType): return yaqlutils.FrozenDict( (evaluate(d_key, context), evaluate(d_value, context)) for d_key, d_value in six.iteritems(value) ) elif yaqlutils.is_sequence(value): return tuple(evaluate(t, context) for t in value) elif isinstance(value, yaqlutils.SetType): return frozenset(evaluate(t, context) for t in value) elif yaqlutils.is_iterable(value): return tuple(evaluate(t, context) for t in yaqlutils.limit_iterable(value, constants.ITERATORS_LIMIT)) elif isinstance(value, dsl_types.MuranoObjectInterface): return value.object else: return value
def evaluate(value, context): if isinstance(value, (dsl_types.YaqlExpression, yaql.language.expressions.Statement)): return value(context) elif isinstance(value, yaqlutils.MappingType): return yaqlutils.FrozenDict( (evaluate(d_key, context), evaluate(d_value, context)) for d_key, d_value in six.iteritems(value)) elif yaqlutils.is_sequence(value): return tuple(evaluate(t, context) for t in value) elif isinstance(value, yaqlutils.SetType): return frozenset(evaluate(t, context) for t in value) elif yaqlutils.is_iterable(value): return tuple( evaluate(t, context) for t in yaqlutils.limit_iterable( value, constants.ITERATORS_LIMIT)) elif isinstance(value, dsl_types.MuranoObjectInterface): return value.object else: return value
def convert(self, value, receiver, context, function_spec, engine, *args, **kwargs): res = super(Iterable, self).convert( value, receiver, context, function_spec, engine, *args, **kwargs) return None if res is None else utils.limit_iterable(res, engine)
def get_limited_if_need(data, engine): if (yaqlutils.is_iterable(data) or yaqlutils.is_sequence(data) or isinstance(data, (yaqlutils.MappingType, yaqlutils.SetType))): return yaqlutils.limit_iterable(data, engine) return data
def convert(self, value, receiver, context, function_spec, engine, *args, **kwargs): res = super(Iterable, self).convert(value, receiver, context, function_spec, engine, *args, **kwargs) return None if res is None else utils.limit_iterable(res, engine)
def limiter(it): return utils.limit_iterable(it, CONF.murano.dsl_iterators_limit)