def _evaluate_parameters(self, arguments_scheme, context, this, *args): arg_names = list(arguments_scheme.keys()) parameter_values = {} i = 0 for arg in args: value = helpers.evaluate(arg, context) if isinstance(value, types.TupleType) and len(value) == 2 and isinstance(value[0], types.StringTypes): name = value[0] value = value[1] if name not in arguments_scheme: raise TypeError() else: if i >= len(arg_names): raise TypeError() name = arg_names[i] i += 1 if callable(value): value = value() arg_spec = arguments_scheme[name] parameter_values[name] = arg_spec.validate(value, this, self._root_context, self._object_store) for name, arg_spec in arguments_scheme.iteritems(): if name not in parameter_values: if not arg_spec.has_default: raise TypeError() parameter_context = self._create_context(this, this.type, context) parameter_values[name] = arg_spec.validate( helpers.evaluate(arg_spec.default, parameter_context), this, self._root_context, self._object_store ) return parameter_values
def execute(self, context, murano_class): if not self.code_block: return gpool = greenpool.GreenPool(helpers.evaluate(self._limit, context)) for expr in self.code_block: gpool.spawn_n(expr.execute, context, murano_class) gpool.waitall()
def execute(self, context, murano_class): count = helpers.evaluate(self._count, context) for t in range(0, count): try: self._code.execute(context, murano_class) except exceptions.BreakException: break
def execute(self, context, murano_class): match_value = helpers.evaluate(self._value, context) for key, value in self._switch.iteritems(): if key == match_value: CodeBlock(value).execute(context, murano_class) return if self._default is not None: self._default.execute(context, murano_class)
def execute(self, context, murano_class): collection = helpers.evaluate(self._collection, context) child_context = yaql.context.Context(context) for t in collection: child_context.set_data(t, self._var) try: self._code.execute(child_context, murano_class) except exceptions.BreakException: break
def test_evaluate(self): yaql_value = mock.Mock(spec=yaql_expression.YaqlExpression, evaluate=lambda context: 'atom') complex_value = {yaql_value: ['some', (1, yaql_value), lambda: 'hi!'], 'sample': [yaql_value, xrange(5)]} complex_literal = {'atom': ['some', (1, 'atom'), 'hi!'], 'sample': ['atom', [0, 1, 2, 3, 4]]} # tuple(evaluate(list)) transformation adds + 1 complex_literal_depth = 3 + 1 evaluated_value = helpers.evaluate(yaql_value, None, 1) non_evaluated_value = helpers.evaluate(yaql_value, None, 0) evaluated_complex_value = helpers.evaluate(complex_value, None) non_evaluated_complex_value = helpers.evaluate( complex_value, None, complex_literal_depth) self.assertEqual('atom', evaluated_value) self.assertNotEqual('atom', non_evaluated_value) self.assertEqual(complex_literal, evaluated_complex_value) self.assertNotEqual(complex_literal, non_evaluated_complex_value)
def _evaluate_parameters(self, arguments_scheme, context, this, *args): arg_names = list(arguments_scheme.keys()) parameter_values = {} i = 0 for arg in args: value = helpers.evaluate(arg, context) if isinstance(value, types.TupleType) and len(value) == 2 and \ isinstance(value[0], types.StringTypes): name = value[0] value = value[1] if name not in arguments_scheme: raise TypeError() else: if i >= len(arg_names): raise TypeError() name = arg_names[i] i += 1 if callable(value): value = value() arg_spec = arguments_scheme[name] parameter_values[name] = arg_spec.validate(value, this, self._root_context, self._object_store) for name, arg_spec in arguments_scheme.iteritems(): if name not in parameter_values: if not arg_spec.has_default: raise TypeError() parameter_context = self._create_context( this, this.type, context) parameter_values[name] = arg_spec.validate( helpers.evaluate(arg_spec.default, parameter_context), this, self._root_context, self._object_store) return parameter_values
def test_evaluate(self): yaql_value = mock.Mock(spec=yaql_expression.YaqlExpression, evaluate=lambda context: 'atom') complex_value = { yaql_value: ['some', (1, yaql_value), lambda: 'hi!'], 'sample': [yaql_value, xrange(5)] } complex_literal = { 'atom': ['some', (1, 'atom'), 'hi!'], 'sample': ['atom', [0, 1, 2, 3, 4]] } # tuple(evaluate(list)) transformation adds + 1 complex_literal_depth = 3 + 1 evaluated_value = helpers.evaluate(yaql_value, None, 1) non_evaluated_value = helpers.evaluate(yaql_value, None, 0) evaluated_complex_value = helpers.evaluate(complex_value, None) non_evaluated_complex_value = helpers.evaluate(complex_value, None, complex_literal_depth) self.assertEqual('atom', evaluated_value) self.assertNotEqual('atom', non_evaluated_value) self.assertEqual(complex_literal, evaluated_complex_value) self.assertNotEqual(complex_literal, non_evaluated_complex_value)
def execute(self, context, murano_class): matched = False for key, value in self._switch.iteritems(): if not isinstance( key, (yaql_expression.YaqlExpression, types.BooleanType)): raise SyntaxError() res = helpers.evaluate(key, context) if not isinstance(res, types.BooleanType): raise TypeError() if res: matched = True child_context = yaql.context.Context(context) CodeBlock(value).execute(child_context, murano_class) if self._default is not None and not matched: self._default.execute(context, murano_class)
def execute(self, context, murano_class): matched = False for key, value in self._switch.iteritems(): if not isinstance(key, (yaql_expression.YaqlExpression, types.BooleanType)): raise SyntaxError() res = helpers.evaluate(key, context) if not isinstance(res, types.BooleanType): raise TypeError() if res: matched = True child_context = yaql.context.Context(context) CodeBlock(value).execute(child_context, murano_class) if self._default is not None and not matched: self._default.execute(context, murano_class)
def execute(self, context, murano_class): raise exceptions.ReturnException( helpers.evaluate(self._value, context))
def execute(self, context, murano_class): raise exceptions.ReturnException(helpers.evaluate( self._value, context))
def execute(self, context, murano_class): result = helpers.evaluate(self.expression, context) if self.destination: self.destination(result, context, murano_class) return result