本文整理汇总了Python中murano.dsl.helpers.evaluate函数的典型用法代码示例。如果您正苦于以下问题:Python evaluate函数的具体用法?Python evaluate怎么用?Python evaluate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了evaluate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _evaluate_parameters
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
示例2: execute
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()
示例3: stub
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)
示例4: __call__
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)
示例5: execute
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)
示例6: execute
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)
示例7: test_evaluate
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)
示例8: payload
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)
示例9: extension_payload
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)
示例10: set_property
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)
示例11: execute
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
示例12: execute
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)
示例13: execute
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)
示例14: execute
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)
示例15: validate
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