Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def call_func(context, op_dot, base, name, args, kwargs,
receiver=utils.NO_VALUE):
if isinstance(receiver, (dsl_types.MuranoObject,
dsl_types.MuranoTypeReference)):
kwargs = utils.filter_parameters_dict(kwargs)
args += tuple(
expressions.MappingRuleExpression(expressions.KeywordConstant(key),
value)
for key, value in kwargs.items())
function = expressions.Function(name, *args)
return op_dot(context, receiver, function)
else:
return base(context, name, args, kwargs, receiver)
: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"]
yaql> null => 1 => []
[null, 1, []]
"""
if isinstance(left, expressions.BinaryOperator) and left.operator == '=>':
return left(utils.NO_VALUE, context, engine) + (right,)
else:
return left(utils.NO_VALUE, context, engine), right
context = context.create_child_context()
trap = utils.create_marker('trap')
context['$'] = trap
@specs.parameter('name', yaqltypes.StringConstant())
@specs.name('#get_context_data')
def get_context_data(name, context):
res = context[name]
if res is trap:
raise yaql_exceptions.ResolutionError()
return res
context.register_function(get_context_data)
try:
return expressions.Statement(expr, engine).evaluate(context=context)
except yaql_exceptions.YaqlException:
return None
def call_func(context, op_dot, base, name, args, kwargs,
receiver=utils.NO_VALUE):
if isinstance(receiver, (dsl_types.MuranoObject,
dsl_types.MuranoTypeReference)):
kwargs = utils.filter_parameters_dict(kwargs)
args += tuple(
expressions.MappingRuleExpression(expressions.KeywordConstant(key),
value)
for key, value in kwargs.items())
function = expressions.Function(name, *args)
return op_dot(context, receiver, function)
else:
return base(context, name, args, kwargs, receiver)
def check(self, value, context, engine, *args, **kwargs):
if isinstance(value, expressions.Constant):
value = value.value
if not super(GenericType, self).check(
value, context, engine, *args, **kwargs):
return False
if value is None or isinstance(value, expressions.Expression):
return True
if not self.checker:
return True
return self.checker(value, context, *args, **kwargs)
def check(self, value, context, *args, **kwargs):
if not self._expression_types:
return isinstance(value, expressions.Expression)
return any(t == type(value) for t in self._expression_types)
def p_binary(this, p):
alias = this._aliases.get(p.slice[2].type)
p[0] = expressions.BinaryOperator(p[2], p[1], p[3], alias)
def check(self, value, context, engine, *args, **kwargs):
if isinstance(value, expressions.Constant):
value = value.value
if not super(GenericType, self).check(
value, context, engine, *args, **kwargs):
return False
if value is None or isinstance(value, expressions.Expression):
return True
if not self.checker:
return True
return self.checker(value, context, *args, **kwargs)
def __init__(self, expression, version):
self._version = version
if isinstance(expression, str):
self._expression = str(expression)
self._parsed_expression = yaql_integration.parse(
self._expression, version)
self._file_position = None
elif isinstance(expression, YaqlExpression):
self._expression = expression._expression
self._parsed_expression = expression._parsed_expression
self._file_position = expression._file_position
elif isinstance(expression, expressions.Statement):
self._expression = str(expression)
self._parsed_expression = expression
self._file_position = None
else:
raise TypeError('expression is not of supported types')
def translate_args(without_kwargs, args, kwargs):
if without_kwargs:
if len(kwargs) > 0:
raise exceptions.ArgumentException(six.next(iter(kwargs)))
return args, {}
pos_args = []
kw_args = {}
for t in args:
if isinstance(t, expressions.MappingRuleExpression):
param_name = t.source
if isinstance(param_name, expressions.KeywordConstant):
param_name = param_name.value
else:
raise exceptions.MappingTranslationException()
kw_args[param_name] = t.destination
else:
pos_args.append(t)
for key, value in six.iteritems(kwargs):
if key in kw_args:
raise exceptions.MappingTranslationException()
else:
kw_args[key] = value
return tuple(pos_args), kw_args