コード例 #1
0
    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

        context = yaql.create_context(False)
        evaluated_value = helpers.evaluate(yaql_value, context, 1)
        non_evaluated_value = helpers.evaluate(yaql_value, context, 0)
        evaluated_complex_value = helpers.evaluate(complex_value, context)
        non_evaluated_complex_value = helpers.evaluate(complex_value, context,
                                                       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)
コード例 #2
0
    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, None, 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, None, self._root_context, self._object_store)

        return parameter_values
コード例 #3
0
 def stub(*args, **kwargs):
     context = self.context
     args = tuple(helpers.evaluate(arg, context) for arg in args)
     kwargs = dict((key, helpers.evaluate(value, context))
                   for key, value in kwargs.iteritems())
     return to_mutable(
         context(item, self.engine, self.sender)(*args, **kwargs),
         self.engine)
コード例 #4
0
ファイル: dsl.py プロジェクト: Magic-Mirror/murano
 def stub(*args, **kwargs):
     context = self.context
     args = tuple(helpers.evaluate(arg, context) for arg in args)
     kwargs = dict((key, helpers.evaluate(value, context))
                   for key, value in six.iteritems(kwargs))
     return to_mutable(
         context(item, self.engine, self.sender)(*args, **kwargs),
         self.engine)
コード例 #5
0
 def execute(self, context, murano_class):
     if not self.code_block:
         return
     limit = helpers.evaluate(self._limit, context)
     gpool = greenpool.GreenPool(helpers.evaluate(limit, context))
     for expr in self.code_block:
         gpool.spawn_n(expr.execute, context, murano_class)
     gpool.waitall()
コード例 #6
0
ファイル: dsl.py プロジェクト: Magic-Mirror/murano
 def __call__(self, __expression, *args, **kwargs):
     context = helpers.get_context().create_child_context()
     for i, param in enumerate(args):
         context['$' + str(i + 1)] = helpers.evaluate(param, context)
     for arg_name, arg_value in six.iteritems(kwargs):
         context['$' + arg_name] = helpers.evaluate(arg_value, context)
     parsed = self.engine(__expression)
     res = parsed.evaluate(context=context)
     return to_mutable(res, self.engine)
コード例 #7
0
 def __call__(self, __expression, *args, **kwargs):
     context = helpers.get_context().create_child_context()
     for i, param in enumerate(args):
         context['$' + str(i + 1)] = helpers.evaluate(param, context)
     for arg_name, arg_value in kwargs.iteritems():
         context['$' + arg_name] = helpers.evaluate(arg_value, context)
     parsed = self.engine(__expression)
     res = parsed.evaluate(context=context)
     return to_mutable(res, self.engine)
コード例 #8
0
 def execute(self, context):
     stacktrace = stack_trace.create_stack_trace(context, False)
     cause = None
     if self._cause:
         cause = helpers.evaluate(self._cause, context).get_property(
             'nativeException')
     raise dsl_exception.MuranoPlException(
         list(self._resolve_names(helpers.evaluate(self._names, context),
                                  context)),
         helpers.evaluate(self._message, context),
         stacktrace, self._extra, cause)
コード例 #9
0
ファイル: virtual_exceptions.py プロジェクト: ddovbii/murano
 def execute(self, context, murano_class):
     stacktrace = yaql_functions.new('io.murano.StackTrace', context,
                                     includeNativeFrames=False)
     cause = None
     if self._cause:
         cause = helpers.evaluate(self._cause, context).get_property(
             'nativeException')
     raise dsl_exception.MuranoPlException(
         list(self._resolve_names(helpers.evaluate(self._names, context),
                                  context)),
         helpers.evaluate(self._message, context),
         stacktrace, self._extra, cause)
コード例 #10
0
ファイル: virtual_exceptions.py プロジェクト: ldreamke/murano
 def execute(self, context):
     stacktrace = stack_trace.create_stack_trace(context, False)
     cause = None
     if self._cause:
         cause = helpers.evaluate(self._cause,
                                  context).get_property('nativeException')
     raise dsl_exception.MuranoPlException(
         list(
             self._resolve_names(helpers.evaluate(self._names, context),
                                 context)),
         helpers.evaluate(self._message, context), stacktrace, self._extra,
         cause)
コード例 #11
0
 def execute(self, context, murano_class):
     stacktrace = yaql_functions.new('io.murano.StackTrace',
                                     context,
                                     includeNativeFrames=False)
     cause = None
     if self._cause:
         cause = helpers.evaluate(self._cause,
                                  context).get_property('nativeException')
     raise dsl_exception.MuranoPlException(
         list(
             self._resolve_names(helpers.evaluate(self._names, context),
                                 context)),
         helpers.evaluate(self._message, context), stacktrace, self._extra,
         cause)
コード例 #12
0
    def test_evaluate(self):
        yaql_value = mock.Mock(yaql_expression.YaqlExpression,
                               return_value='atom')
        complex_value = {yaql_value: ['some', (1, yaql_value), 'hi!'],
                         'sample': [yaql_value, xrange(5)]}
        complex_literal = utils.FrozenDict({
            'atom': ('some', (1, 'atom'), 'hi!'),
            'sample': ('atom', (0, 1, 2, 3, 4))
        })
        context = yaql.create_context()
        evaluated_value = helpers.evaluate(yaql_value, context)
        evaluated_complex_value = helpers.evaluate(complex_value, context)

        self.assertEqual('atom', evaluated_value)
        self.assertEqual(complex_literal, evaluated_complex_value)
コード例 #13
0
ファイル: test_engine.py プロジェクト: Magic-Mirror/murano
    def test_evaluate(self):
        yaql_value = mock.Mock(yaql_expression.YaqlExpression,
                               return_value='atom')
        complex_value = {yaql_value: ['some', (1, yaql_value), 'hi!'],
                         'sample': [yaql_value, six.moves.range(5)]}
        complex_literal = utils.FrozenDict({
            'atom': ('some', (1, 'atom'), 'hi!'),
            'sample': ('atom', (0, 1, 2, 3, 4))
        })
        context = yaql.create_context()
        evaluated_value = helpers.evaluate(yaql_value, context)
        evaluated_complex_value = helpers.evaluate(complex_value, context)

        self.assertEqual('atom', evaluated_value)
        self.assertEqual(complex_literal, evaluated_complex_value)
コード例 #14
0
ファイル: yaql_integration.py プロジェクト: HarborOS/murano
 def extension_payload(__context, __receiver, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         executor, murano_method.declaring_type,
         (__receiver,) + args, kwargs, __context, True), __context)
コード例 #15
0
ファイル: murano_object.py プロジェクト: tianshangjun/murano
    def set_property(self, name, value, context=None):
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_property(name)
        if context is None:
            context = self.object_store.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_property(name)
            values_to_assign = []
            for mc in declared_properties:
                spec = mc.get_property(name)
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and (spec.usage not in typespec.PropertyUsages.Writable
                             or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                default = self.__config.get(name, spec.default)
                default = self.__defaults.get(name, default)
                default = helpers.evaluate(default, context)

                obj = self.cast(mc)
                values_to_assign.append((obj, spec.validate(
                    value, self.real_this,
                    self.real_this, default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
コード例 #16
0
 def extension_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(
         murano_method.invoke(murano_method.declaring_type,
                              (__receiver, ) + args, kwargs, __context,
                              True), __context)
コード例 #17
0
 def payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         __context[constants.CTX_NAMES_SCOPE] = murano_class
         result = helpers.evaluate(cls(*args, **kwargs), __context)
         __receiver.object.extension = result
コード例 #18
0
ファイル: yaql_integration.py プロジェクト: HarborOS/murano
 def payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         __context[constants.CTX_NAMES_SCOPE] = \
             murano_class
         return helpers.evaluate(cls(*args, **kwargs), __context)
コード例 #19
0
ファイル: macros.py プロジェクト: bopopescu/OpenStack-Ocata
 def execute(self, context):
     if not self.code_block:
         return
     limit = helpers.evaluate(self._limit, context)
     helpers.parallel_select(
         self.code_block,
         lambda expr: expr.execute(context.create_child_context()), limit)
コード例 #20
0
ファイル: macros.py プロジェクト: nastya-kuz/murano
 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
コード例 #21
0
ファイル: macros.py プロジェクト: AleptNamrata/murano
 def execute(self, context):
     if not self.code_block:
         return
     limit = helpers.evaluate(self._limit, context)
     helpers.parallel_select(
         self.code_block,
         lambda expr: expr.execute(context.create_child_context()),
         limit)
コード例 #22
0
 def execute(self, context):
     match_value = helpers.evaluate(self._value, context)
     for key, value in self._switch.iteritems():
         if key == match_value:
             CodeBlock(value).execute(context)
             return
     if self._default is not None:
         self._default.execute(context)
コード例 #23
0
ファイル: macros.py プロジェクト: bopopescu/OpenStack-Stein
    def execute(self, context):
        matched = False
        for key, value in self._switch.items():
            if helpers.evaluate(key, context):
                matched = True
                CodeBlock(value).execute(context)

        if self._default is not None and not matched:
            self._default.execute(context)
コード例 #24
0
ファイル: macros.py プロジェクト: nastya-kuz/murano
 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
コード例 #25
0
ファイル: macros.py プロジェクト: AleptNamrata/murano
    def execute(self, context):
        matched = False
        for key, value in six.iteritems(self._switch):
            if helpers.evaluate(key, context):
                matched = True
                CodeBlock(value).execute(context)

        if self._default is not None and not matched:
            self._default.execute(context)
コード例 #26
0
 def execute(self, context):
     count = helpers.evaluate(self._count, context)
     for _ in range(0, count):
         try:
             self._code.execute(context)
         except exceptions.BreakException:
             break
         except exceptions.ContinueException:
             continue
コード例 #27
0
 def execute(self, context):
     collection = helpers.evaluate(self._collection, context)
     for t in collection:
         context[self._var] = t
         try:
             self._code.execute(context)
         except exceptions.BreakException:
             break
         except exceptions.ContinueException:
             continue
コード例 #28
0
ファイル: type_scheme.py プロジェクト: tianshangjun/murano
    def __call__(self, data, context, this, owner, default):
        # TODO(ativelkov, slagun): temporary fix, need a better way of handling
        # composite defaults
        # A bug (#1313694) has been filed

        if data is dsl.NO_VALUE:
            data = helpers.evaluate(default, context)

        context = self.prepare_context(context, this, owner, default)
        return self._map(data, self._spec, context)
コード例 #29
0
    def validate(self, data, context, default):
        if data is dsl.NO_VALUE:
            data = helpers.evaluate(default, context)

        context = self.prepare_validate_context(context)
        try:
            self._map(data, self._spec, context, '')
            return True
        except exceptions.ContractViolationException:
            return False
コード例 #30
0
    def __call__(self, data, context, this, owner, default):
        # TODO(ativelkov, slagun): temporary fix, need a better way of handling
        # composite defaults
        # A bug (#1313694) has been filed

        if data is dsl.NO_VALUE:
            data = helpers.evaluate(default, context)

        context = self.prepare_context(context, this, owner, default)
        return self._map(data, self._spec, context, '')
コード例 #31
0
 def execute(self, context):
     try:
         result = helpers.evaluate(self.expression, context)
         if self.destination:
             self.destination(result, context)
         return result
     except dsl_exception.MuranoPlException:
         raise
     except Exception as e:
         raise dsl_exception.MuranoPlException.from_python_exception(e, context)
コード例 #32
0
 def execute(self, context, murano_class):
     collection = helpers.evaluate(self._collection, context)
     for t in collection:
         context.set_data(t, self._var)
         try:
             self._code.execute(context, murano_class)
         except exceptions.BreakException:
             break
         except exceptions.ContinueException:
             continue
コード例 #33
0
 def execute(self, context):
     try:
         result = helpers.evaluate(self.expression, context)
         if self.destination:
             self.destination(result, context)
         return result
     except dsl_exception.MuranoPlException:
         raise
     except Exception as e:
         raise dsl_exception.MuranoPlException.from_python_exception(
             e, context)
コード例 #34
0
ファイル: test_engine.py プロジェクト: OndrejVojta/murano
    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

        context = yaql.create_context(False)
        evaluated_value = helpers.evaluate(yaql_value, context, 1)
        non_evaluated_value = helpers.evaluate(yaql_value, context, 0)
        evaluated_complex_value = helpers.evaluate(complex_value, context)
        non_evaluated_complex_value = helpers.evaluate(
            complex_value, context, 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)
コード例 #35
0
    def execute(self, context):
        matched = False
        for key, value in self._switch.iteritems():
            res = helpers.evaluate(key, context)
            if not isinstance(res, types.BooleanType):
                raise exceptions.DslInvalidOperationError(
                    'Switch case must be evaluated to boolean type')
            if res:
                matched = True
                CodeBlock(value).execute(context)

        if self._default is not None and not matched:
            self._default.execute(context)
コード例 #36
0
ファイル: type_scheme.py プロジェクト: lexplua/murano
    def transform(self, data, context, this, owner, default, calling_type):
        # TODO(ativelkov, slagun): temporary fix, need a better way of handling
        # composite defaults
        # A bug (#1313694) has been filed

        if data is dsl.NO_VALUE:
            data = helpers.evaluate(default, context)

        if is_passkey(data):
            return data

        context = self.prepare_transform_context(context, this, owner, default,
                                                 calling_type)
        return self._map(data, self._spec, context, '')
コード例 #37
0
ファイル: macros.py プロジェクト: nastya-kuz/murano
    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)
コード例 #38
0
    def _execute(self, base_context_func, data, context, default, **kwargs):
        # TODO(ativelkov, slagun): temporary fix, need a better way of handling
        # composite defaults
        # A bug (#1313694) has been filed

        if data is dsl.NO_VALUE:
            data = helpers.evaluate(default, context)

        if helpers.is_passkey(data):
            return data

        contract_context = base_context_func(
            self._runtime_version).create_child_context()
        contract_context['root_context'] = context
        for key, value in six.iteritems(kwargs):
            contract_context[key] = value
        contract_context[constants.CTX_NAMES_SCOPE] = \
            context[constants.CTX_NAMES_SCOPE]
        return self._map(data, self._spec, contract_context, '')
コード例 #39
0
    def set_property(self, name, value, context=None):
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_property(name)
        if context is None:
            context = self.object_store.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_property(name)
            values_to_assign = []
            for mc in declared_properties:
                spec = mc.get_property(name)
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and (spec.usage not in typespec.PropertyUsages.Writable
                             or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                default = self.__config.get(name, spec.default)
                default = self.__defaults.get(name, default)
                default = helpers.evaluate(default, context)

                obj = self.cast(mc)
                values_to_assign.append((obj,
                                         spec.validate(value,
                                                       self.real_this,
                                                       self.real_this,
                                                       default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
コード例 #40
0
 def payload(__context, __sender, *args, **kwargs):
     assert __sender is None
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         return helpers.evaluate(cls(*args, **kwargs), __context)
コード例 #41
0
def _finalize(obj, context):
    return helpers.evaluate(obj, context)
コード例 #42
0
 def execute(self, context):
     raise exceptions.ReturnException(
         helpers.evaluate(self._value, context))
コード例 #43
0
 def static_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(
         murano_method.invoke(__receiver, args, kwargs, __context, True),
         __context)
コード例 #44
0
 def payload(__context, __sender, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         executor, __sender, args, kwargs, __context, True), __context)
コード例 #45
0
 def static_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         __receiver, args, kwargs, __context, True), __context)
コード例 #46
0
ファイル: macros.py プロジェクト: bopopescu/OpenStack-Stein
 def execute(self, context):
     if helpers.evaluate(self._condition, context):
         self._code1.execute(context)
     elif self._code2 is not None:
         self._code2.execute(context)
コード例 #47
0
 def payload(__context, __sender, *args, **kwargs):
     assert __sender is None
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         return helpers.evaluate(cls(*args, **kwargs), __context)
コード例 #48
0
def _finalize(obj, context):
    return helpers.evaluate(obj, context)
コード例 #49
0
ファイル: dsl.py プロジェクト: Magic-Mirror/murano
 def __setitem__(self, key, value):
     context = helpers.get_context()
     value = helpers.evaluate(value, context)
     self.__object.set_property(key, value, context)
コード例 #50
0
 def __setitem__(self, key, value):
     context = helpers.get_context()
     value = helpers.evaluate(value, context)
     self.object.set_property(key, value, context)
コード例 #51
0
ファイル: macros.py プロジェクト: AleptNamrata/murano
 def execute(self, context):
     if helpers.evaluate(self._condition, context):
         self._code1.execute(context)
     elif self._code2 is not None:
         self._code2.execute(context)
コード例 #52
0
ファイル: yaql_integration.py プロジェクト: toby82/murano
 def payload(__context, __receiver, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         executor, __receiver, args, kwargs, __context, True), __context)