How to use the yaql.language.yaqltypes 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 / yaql / yaql / language / specs.py View on Github external
function_name=self.name or self.payload.__name__,
                param_name=name)

        yaql_type = value_type
        p_nullable = nullable
        if value_type is None:
            if p_nullable is None:
                p_nullable = True
            base_type = object \
                if default in (None, NO_DEFAULT, utils.NO_VALUE) \
                else type(default)
            yaql_type = yaqltypes.PythonType(base_type, p_nullable)
        elif not isinstance(value_type, yaqltypes.SmartType):
            if p_nullable is None:
                p_nullable = default is None
            yaql_type = yaqltypes.PythonType(value_type, p_nullable)

        pd = ParameterDefinition(
            name, yaql_type, position, alias, default
        )
        self.parameters[arg_name] = pd
        return pd
github openstack / yaql / yaql / __init__.py View on Github external
        @specs.inject('engine', yaqltypes.Engine())
        @specs.name('#finalize')
        def finalize(obj, limiter, engine):
            if engine.options.get('yaql.convertOutputData', True):
                return utils.convert_output_data(obj, limiter, engine)
            return obj
github openstack / yaql / yaql / standard_library / legacy.py View on Github external
@specs.parameter('expr', yaqltypes.Lambda(with_context=True, method=True))
@specs.name('#operator_.')
def op_dot_context(receiver, expr):
    return expr(receiver['$0'], receiver)
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.parameter('collection', yaqltypes.Iterable())
@specs.parameter('key_selector', yaqltypes.Lambda())
@specs.parameter('value_selector', yaqltypes.Lambda())
@specs.method
def to_dict(collection, engine, key_selector, value_selector=None):
    """:yaql:dict

    Returns dict built on collection where keys are keySelector applied to
    collection elements and values are valueSelector applied to collection
    elements.

    :signature: collection.toDict(keySelector, valueSelector => null)
    :receiverArg collection: collection to build dict from
    :argType collection: iterable
    :arg keySelector: lambda function to get keys from collection elements
    :argType keySelector: lambda
    :arg valueSelector: lambda function to get values from collection elements.
github openstack / yaql / yaql / standard_library / branching.py View on Github external
@specs.parameter('args', yaqltypes.Lambda())
def select_all_cases(*args):
    """:yaql:selectAllCases

    Evaluates input predicates and returns an iterator to collection of
    zero-based indexes of predicates which were evaluated to true. The actual
    evaluation is done lazily as the iterator advances, not during the
    function call.

    :signature: selectAllCases([args])
    :arg [args]: predicates to check for true
    :argType [args]: chain of predicates
    :returnType: iterator

    .. code::

        yaql> selectAllCases("ab" > "abc", "ab" <= "abc", "ab" < "abc")
github openstack / yaql / yaql / language / specs.py View on Github external
def _infer_parameter_type(name):
    if name == 'context' or name == '__context':
        return yaqltypes.Context()
    elif name == 'engine' or name == '__engine':
        return yaqltypes.Engine()
    elif name == 'yaql_interface' or name == '__yaql_interface':
        return yaqltypes.YaqlInterface()
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.parameter('attribute', yaqltypes.Keyword(expand=False))
@specs.inject('operator', yaqltypes.Delegate('#operator_.'))
@specs.name('#operator_.')
def collection_attribution(collection, attribute, operator):
    """:yaql:operator .

    Retrieves the value of an attribute for each element in a collection and
    returns a list of results.

    :signature: collection.attribute
    :arg collection: input collection
    :argType collection: iterable
    :arg attribute: attribute to get on every collection item
    :argType attribute: keyword
    :returnType: list

    .. code::
github openstack / murano / murano / dsl / yaql_integration.py View on Github external
position=position, default=dsl.NO_VALUE)
        check_first_arg = False
        fd.parameters[name] = p
        i += 1

    if not varargs:
        fd.parameters['*'] = specs.ParameterDefinition(
            '*',
            value_type=yaqltypes.PythonType(object, nullable=True),
            position=i)
    if not kwargs:
        fd.parameters['**'] = specs.ParameterDefinition(
            '**', value_type=yaqltypes.PythonType(object, nullable=True))

    fd.set_parameter(specs.ParameterDefinition(
        '__context', yaqltypes.Context(), 0))

    fd.meta[constants.META_MURANO_METHOD] = murano_method
    return fd
github openstack / murano / murano / dsl / lhs_expression.py View on Github external
    @specs.parameter('name', yaqltypes.StringConstant())
    def get_context_data(context, name):
        root_context = context['#root_context']

        def set_data(value):
            if not name or name == '$' or name == '$this':
                raise ValueError('Cannot assign to {0}'.format(name))
            ctx = root_context
            while constants.CTX_VARIABLE_SCOPE not in ctx:
                ctx = ctx.parent
            ctx[name] = value

        return _Property(lambda: root_context[name], set_data)