How to use the yaql.language.utils function in yaql

To help you get started, we’ve selected a few yaql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / murano / murano / dsl / lhs_expression.py View on Github external
def setter(src_property, value):
            src = src_property.get()
            if isinstance(src, utils.MappingType):
                src_property.set(
                    utils.FrozenDict(
                        itertools.chain(
                            src.items(),
                            ((key, value),))))
            elif isinstance(src, dsl_types.MuranoObject):
                src.set_property(key, value, context['#root_context'])
            elif isinstance(src, (
                    dsl_types.MuranoTypeReference,
                    dsl_types.MuranoType)):
                if isinstance(src, dsl_types.MuranoTypeReference):
                    mc = src.type
                else:
                    mc = src
                helpers.get_executor().set_static_property(
                    mc, key, value, context['#root_context'])
github openstack / murano / murano / dsl / type_scheme.py View on Github external
def _map_list(self, data, spec, context, path):
        if utils.is_iterator(data):
            data = list(data)
        elif not utils.is_sequence(data):
            if data is None or data is dsl.NO_VALUE:
                data = []
            else:
                data = [data]
        if len(spec) < 1:
            return data
        shift = 0
        max_length = -1
        min_length = 0
        if isinstance(spec[-1], int):
            min_length = spec[-1]
            shift += 1
        if len(spec) >= 2 and isinstance(spec[-2], int):
            max_length = min_length
            min_length = spec[-2]
            shift += 1
github openstack / murano / murano / dsl / executor.py View on Github external
elif definition.usage == dsl_types.MethodArgumentUsages.KwArgs:
                kwargs_arg = name
                parameter_values[name] = kwarg_values

        for i, arg in enumerate(args):
            name = None if i >= len(arg_names) else arg_names[i]
            if name is None or name in (varargs_arg, kwargs_arg):
                if varargs_arg:
                    vararg_values.append(arg)
                else:
                    raise yaql_exceptions.NoMatchingMethodException(
                        method_name, receiver)
            else:
                parameter_values[name] = arg

        for name, value in utils.filter_parameters_dict(kwargs).items():
            if name in arguments_scheme and name not in (
                    varargs_arg, kwargs_arg):
                parameter_values[name] = value
            elif kwargs_arg:
                kwarg_values[name] = value
            else:
                raise yaql_exceptions.NoMatchingMethodException(
                    method_name, receiver)
        return tuple(), parameter_values
github openstack / murano / murano / dsl / contracts / contracts.py View on Github external
def _map_dict(self, data, spec, context, path):
        if data is None or data is dsl.NO_VALUE:
            data = {}
        if not isinstance(data, utils.MappingType):
            raise exceptions.ContractViolationException(
                'Value {0} is not of a dictionary type'.format(
                    helpers.format_scalar(data)))
        if not spec:
            return data
        result = {}
        yaql_key = None
        for key, value in spec.items():
            if isinstance(key, dsl_types.YaqlExpression):
                if yaql_key is not None:
                    raise exceptions.DslContractSyntaxError(
                        'Dictionary contract '
                        'cannot have more than one expression key')
                else:
                    yaql_key = key
            else:
github openstack / yaql / yaql / standard_library / collections.py View on Github external
Returns sequence repeated count times.

    :signature: left * right
    :arg left: input sequence
    :argType left: sequence
    :arg right: multiplier
    :argType right: integer
    :returnType: sequence

    .. code::

        yaql> [1, 2] * 2
        [1, 2, 1, 2]
    """
    utils.limit_memory_usage(engine, (-right + 1, []), (right, left))
    return left * right
github openstack / yaql / yaql / standard_library / legacy.py View on Github external
.. code::

        yaql> 15.switch($ < 3 => "a", $ < 7 => "b", $ => "c")
        "c"
    """
    context = context.create_child_context()
    context[''] = value
    for cond in conditions:
        res = cond(context)
        if isinstance(res, tuple):
            if len(res) != 2:
                raise ValueError('switch() tuples must be of size 2')
            if res[0]:
                return res[1]
        elif isinstance(res, utils.MappingRule):
            if res.source:
                return res.destination
        else:
            raise ValueError('switch() must have tuple or mapping parameters')
    return None
github openstack / murano / murano / dsl / yaql_functions.py View on Github external
@specs.parameter('__extra', utils.MappingType)
@specs.parameter('__owner', dsl.MuranoObjectParameter(
    nullable=True, decorate=False))
@specs.parameter('__object_name', yaqltypes.String(True))
def new(__context, __type_name, __owner=None, __object_name=None, __extra=None,
        **parameters):

    data = {
        __type_name: parameters,
        'name': __object_name
    }
    for key, value in (__extra or {}).items():
        if key.startswith('_'):
            data[key] = value

    object_store = helpers.get_object_store()
    return object_store.load(data, __owner, context=__context,
github openstack / murano / murano / dsl / type_scheme.py View on Github external
def _map(self, data, spec, context, path):
        child_context = context.create_child_context()
        if isinstance(spec, dsl_types.YaqlExpression):
            child_context[''] = data
            try:
                result = spec(context=child_context)
                return result
            except exceptions.ContractViolationException as e:
                e.path = path
                raise
        elif isinstance(spec, utils.MappingType):
            return self._map_dict(data, spec, child_context, path)
        elif utils.is_sequence(spec):
            return self._map_list(data, spec, child_context, path)
        else:
            return self._map_scalar(data, spec)
github openstack / murano / murano / dsl / lhs_expression.py View on Github external
def getter(src):
            if isinstance(src, utils.MappingType):
                return src.get(key, {})
            elif isinstance(src, dsl_types.MuranoObject):
                try:
                    return src.get_property(key, context['#root_context'])
                except exceptions.UninitializedPropertyAccessError:
                    return {}
            elif isinstance(src, (
                    dsl_types.MuranoTypeReference,
                    dsl_types.MuranoType)):
                if isinstance(src, dsl_types.MuranoTypeReference):
                    mc = src.type
                else:
                    mc = src
                return helpers.get_executor().get_static_property(
                    mc, key, context['#root_context'])
            else: