Example #1
0
@specs.parameter('offset', TIMESPAN_TYPE)
def build_datetime(year,
                   month,
                   day,
                   hour=0,
                   minute=0,
                   second=0,
                   microsecond=0,
                   offset=ZERO_TIMESPAN):
    zone = _get_tz(offset)
    return DATETIME_TYPE(year, month, day, hour, minute, second, microsecond,
                         zone)


@specs.name('datetime')
@specs.parameter('timestamp', yaqltypes.Number())
@specs.parameter('offset', TIMESPAN_TYPE)
def datetime_from_timestamp(timestamp, offset=ZERO_TIMESPAN):
    zone = _get_tz(offset)
    return datetime.datetime.fromtimestamp(timestamp, tz=zone)


@specs.name('datetime')
@specs.parameter('string', yaqltypes.String())
@specs.parameter('format__', yaqltypes.String(True))
def datetime_from_string(string, format__=None):
    if not format__:
        result = parser.parse(string)
    else:
        result = DATETIME_TYPE.strptime(string, format__)
    if not result.tzinfo:
Example #2
0
    :argType string: string
    :arg [args]: chain of strings to check input string with
    :argType [args]: strings
    :returnType: boolean

    .. code::

        yaql> "abcd".endsWith("cd", "xx")
        true
        yaql> "abcd".endsWith("yy", "xx", "zz")
        false
    """
    return string.endswith(suffixes)


@specs.parameter('num', yaqltypes.Number(nullable=True))
def hex_(num):
    """:yaql:hex

    Returns a string with hexadecimal representation of num.

    :signature: hex(num)
    :arg num: input number to be converted to hexademical
    :argType num: number
    :returnType: string

    .. code::

        yaql> hex(256)
        "0x100"
    """
Example #3
0
@specs.extension_method
def require(value):
    if value is None:
        raise ValueError('Required value is missing')
    return value


@specs.parameter('obj', dsl.MuranoObjectParameter())
@specs.parameter('murano_class_ref', dsl.MuranoTypeParameter())
@specs.extension_method
def find(obj, murano_class_ref):
    return obj.find_owner(murano_class_ref, optional=True)


@specs.parameter('seconds', yaqltypes.Number())
def sleep_(seconds):
    eventlet.sleep(seconds)


@specs.parameter('object_', dsl.MuranoObjectParameter(nullable=True))
def type_(object_):
    return None if object_ is None else object_.type.get_reference()


@specs.name('type')
@specs.parameter('object_', dsl.MuranoObjectParameter(nullable=True))
def type_legacy(object_):
    return None if object_ is None else object_.type.name

Example #4
0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, 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.

import random

import six

from yaql.language import specs
from yaql.language import yaqltypes


@specs.parameter('left', yaqltypes.Number())
@specs.parameter('right', yaqltypes.Number())
@specs.name('#operator_+')
def binary_plus(left, right):
    return left + right


@specs.parameter('left', yaqltypes.Number())
@specs.parameter('right', yaqltypes.Number())
@specs.name('#operator_-')
def binary_minus(left, right):
    return left - right


@specs.parameter('left', yaqltypes.Number())
@specs.parameter('right', yaqltypes.Number())