Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@specs.parameter('right', yaqltypes.Number())
@specs.name('#operator_/')
def division(left, right):
if isinstance(left, six.integer_types) and isinstance(
right, six.integer_types):
return left // right
return left / right
@specs.name('#operator_.')
def op_dot(receiver, expr, context, engine):
""":yaql:operator .
Evaluates expression on receiver and returns its result.
:signature: receiver.expr
:arg receiver: yaqlized receiver
:argType receiver: yaqlized object, initialized with
yaqlize_methods equal to True
:arg expr: expression to be evaluated
:argType expr: expression
:returnType: any (expression return type)
"""
settings = yaqlization.get_yaqlization_settings(receiver)
mappings = _remap_name(expr.name, settings)
@specs.parameter('value', nullable=True)
@specs.method
def int_(value):
if value is dsl.NO_VALUE:
value = default
if value is None:
return None
try:
return int(value)
except Exception:
raise exceptions.ContractViolationException(
'Value {0} violates int() contract'.format(
format_scalar(value)))
@specs.parameter('composer', yaqltypes.Lambda())
@specs.extension_method
def pselect(collection, composer):
return helpers.parallel_select(collection, composer)
@specs.parameter('__object', dsl.MuranoObjectParameter(nullable=True))
@specs.name('invoke')
@specs.method
def method_invoke(context, method, __object, *args, **kwargs):
return method.invoke(__object, args, kwargs, context)
@specs.name('datetime')
@specs.parameter('year', int)
@specs.parameter('month', int)
@specs.parameter('day', int)
@specs.parameter('hour', int)
@specs.parameter('minute', int)
@specs.parameter('second', int)
@specs.parameter('microsecond', int)
@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.parameter('kwargs', yaqltypes.Lambda(with_context=True))
def with_original(context, **kwargs):
new_context = context.create_child_context()
original_context = context[constants.CTX_ORIGINAL_CONTEXT]
for k, v in kwargs.items():
new_context['$' + k] = v(original_context)
return new_context
@specs.parameter('name', yaqltypes.StringConstant())
@specs.name('#get_context_data')
def get_context_data(name, context):
""":yaql:getContextData
Returns the context value by its name. This function is system
and can be overridden to change the way of getting context data.
:signature: getContextData(name)
:arg name: value's key name
:argType name: string
:returnType: any (value type)
"""
return context[name]
@specs.name('#operator_=>')
def build_tuple(left, right, context, engine):
""":yaql:operator =>
Returns tuple.
:signature: left => right
:arg left: left value for tuple
:argType left: any
:arg right: right value for tuple
:argType right: any
:returnType: tuple
.. code::
yaql> a => b
["a", "b"]