How to use the yaql.language.yaqltypes.Delegate 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 / standard_library / system.py View on Github external
@specs.inject('func', yaqltypes.Delegate(use_convention=False))
def get_property(func, obj, name):
    """:yaql:operator .

    Returns value of 'name' property.

    :signature: left.right
    :arg left: object
    :argType left: any
    :arg right: object property name
    :argType right: keyword
    :returnType: any

    .. code::

        yaql> now().year
        2016
github openstack / yaql / yaql / standard_library / strings.py View on Github external
@specs.inject('str_delegate', yaqltypes.Delegate('str'))
@specs.method
def join(sequence, separator, str_delegate):
    """:yaql:join

    Returns a string with sequence elements joined by the separator.

    :signature: sequence.join(separator)
    :receiverArg sequence: chain of values to be joined
    :argType sequence: sequence of strings
    :arg separator: value to be placed between joined pairs
    :argType separator: string
    :returnType: string

    .. code::

        yaql> ["abc", "de", "f"].join("")
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.inject('delegate', yaqltypes.Delegate('to_set', method=True))
def set_(delegate, *args):
    """:yaql:set

    Returns set initialized with args.

    :signature: set([args])
    :arg [args]: args to build a set
    :argType [args]: chain of any type
    :returnType: set

    .. code::

        yaql> set(0, "", [1, 2])
        [0, "", [1, 2]]
    """
    def rec(seq):
github openstack / murano / murano / engine / system / logger.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from oslo_log import log as logging
from yaql.language import specs
from yaql.language import yaqltypes

from murano.dsl import dsl

NAME_TEMPLATE = u'applications.{0}'

inject_format = specs.inject(
    '_Logger__yaql_format_function',
    yaqltypes.Delegate('format'))


@dsl.name('io.murano.system.Logger')
class Logger(object):
    """Logger object for MuranoPL.

    Instance of this object returned by 'logger' YAQL function
    and should not be instantiated directly
    """

    def __init__(self, logger_name):
        self._underlying_logger = logging.getLogger(
            NAME_TEMPLATE.format(logger_name))

    @specs.parameter('_Logger__message', yaqltypes.String())
    @inject_format
github openstack / murano / murano / engine / system / yaql_functions.py View on Github external
@specs.inject('delegate', yaqltypes.Delegate('substring', method=True))
@specs.extension_method
def substr(delegate, string, start, length=-1):
    return delegate(string, start, length)
github openstack / yaql / yaql / standard_library / collections.py View on Github external
@specs.inject('delegate', yaqltypes.Delegate('to_list', method=True))
def list_(delegate, *args):
    """:yaql:list

    Returns list of provided args and unpacks arg element if it's iterable.

    :signature: list([args])
    :arg [args]: arguments to create a list
    :argType [args]: chain of any types
    :returnType: list

    .. code::

        yaql> list(1, "", range(2))
        [1, "", 0, 1]
    """
    def rec(seq):
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.inject('operator_gt', yaqltypes.Delegate('#operator_>'))
@specs.inject('operator_lt', yaqltypes.Delegate('#operator_<'))
@specs.method
def order_by(collection, selector, operator_lt, operator_gt):
    """:yaql:orderBy

    Returns an iterator over collection elements sorted in ascending order.
    Selector is applied to each element of the collection to extract
    sorting key.

    :signature: collection.orderBy(selector)
    :receiverArg collection: collection to be ordered
    :argType collection: iterable
    :arg selector: specifies a function of one argument that is used to
        extract a comparison key from each element
    :argType selector: lambda
    :returnType: iterator
github openstack / yaql / yaql / standard_library / queries.py View on Github external
@specs.inject('func', yaqltypes.Delegate('min'))
@specs.method
def min_(func, collection, initial=utils.NO_VALUE):
    """:yaql:min

    Returns min value in collection. Considers initial if specified.

    :signature: collection.min(initial => NoValue)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg initial: value to start with. NoValue by default
    :argType initial: collection's elements type
    :returnType: collection's elements type

    .. code::

        yaql> [3, 1, 2].min()
github openstack / yaql / yaql / __init__.py View on Github external
        @specs.inject('limiter', yaqltypes.Delegate('#iter'))
        @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