Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@parameter('b', custom_validator=_is_a_number)
def divide(a, b):
if isinstance(a, six.integer_types) and isinstance(b, six.integer_types):
return a // b
return a / b
@parameter('a', custom_validator=_is_a_number)
@parameter('b', custom_validator=_is_a_number)
def minus(a, b):
return a - b
@parameter('start', arg_type=int)
@parameter('end', arg_type=int)
def _range_limited(start, end):
for i in six.moves.range(int(start), int(end)):
yield i
def collection_parameter(name):
return parameter(name, arg_type=collections.Iterable,
custom_validator=
lambda v: not isinstance(v, six.string_types))
@parameter('arg1', lazy=True,
custom_validator=lambda v: v.key != 'operator_=>')
def build_new_tuple(arg1, arg2):
return arg1(), arg2
@parameter('conditions', lazy=True)
def switch(self, *conditions):
for cond in conditions:
res = cond(self)
if not isinstance(res, tuple):
raise YaqlExecutionException("Switch must have tuple parameters")
if len(res) != 2:
raise YaqlExecutionException("Switch tuples must be of size 2")
if res[0]:
return res[1]
return None
@parameter('att_name', constant_only=True)
@parameter('self', custom_validator=_is_object)
def obj_attribution(self, att_name):
try:
return getattr(self, att_name)
except AttributeError:
raise YaqlExecutionException("Unable to retrieve object attribute")
@parameter('arg1', lazy=True,
custom_validator=lambda v: v.key == 'operator_=>')
def append_tuple(arg1, arg2):
res = []
for tup in arg1():
res.append(tup)
res.append(arg2)
return tuple(res)
@parameter('b', arg_type=six.string_types)
def string_concatenation(a, b):
return a + b
@parameter('b', arg_type=bool)
def _or(a, b):
return a or b