• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.get_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中murano.dsl.helpers.get_type函数的典型用法代码示例。如果您正苦于以下问题:Python get_type函数的具体用法?Python get_type怎么用?Python get_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: transform

 def transform(self, value, this, owner, context, default=None):
     if default is None:
         default = self.default
     executor = helpers.get_executor(context)
     if isinstance(this, dsl_types.MuranoType):
         return self._contract.transform(
             value, executor.create_object_context(this),
             None, None, default, helpers.get_type(context))
     else:
         return self._contract.transform(
             value, executor.create_object_context(
                 this.cast(self._container_type())),
             this, owner, default, helpers.get_type(context))
开发者ID:satish-avninetworks,项目名称:murano,代码行数:13,代码来源:typespec.py


示例2: class_

 def class_(value, name, default_name=None, version_spec=None):
     object_store = None if this is None else this.object_store
     if not default_name:
         default_name = name
     murano_class = name.type
     if value is None:
         return None
     if isinstance(value, dsl_types.MuranoObject):
         obj = value
     elif isinstance(value, dsl_types.MuranoObjectInterface):
         obj = value.object
     elif isinstance(value, utils.MappingType):
         obj = helpers.instantiate(
             value, owner, object_store, root_context,
             calling_type, default_name)
     elif isinstance(value, six.string_types) and object_store:
         obj = object_store.get(value)
         if obj is None:
             if not object_store.initializing:
                 raise exceptions.NoObjectFoundError(value)
             else:
                 return TypeScheme.ObjRef(value)
     else:
         raise exceptions.ContractViolationException(
             'Value {0} cannot be represented as class {1}'.format(
                 format_scalar(value), name))
     if not helpers.is_instance_of(
             obj, murano_class.name,
             version_spec or helpers.get_type(root_context)):
         raise exceptions.ContractViolationException(
             'Object of type {0} is not compatible with '
             'requested type {1}'.format(obj.type.name, name))
     return obj
开发者ID:Aqsamm,项目名称:murano,代码行数:33,代码来源:type_scheme.py


示例3: 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)
开发者ID:tianshangjun,项目名称:murano,代码行数:34,代码来源:murano_object.py


示例4: setAttr

    def setAttr(self, _context, name, value, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(_context))
        if not isinstance(owner, murano_class.MuranoClass):
            raise TypeError()

        attribute_store = helpers.get_attribute_store(_context)
        attribute_store.set(self, owner, name, value)
开发者ID:OndrejVojta,项目名称:murano,代码行数:8,代码来源:sys_object.py


示例5: get_attr

    def get_attr(self, this, context, name, default=None, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(context))

        attribute_store = helpers.get_attribute_store(context)

        result = attribute_store.get(this.object, owner, name)
        return default if result is None else result
开发者ID:Aqsamm,项目名称:murano,代码行数:8,代码来源:sys_object.py


示例6: _get_package

 def _get_package(owner, receiver):
     if owner is None:
         if isinstance(receiver, dsl_types.MuranoObjectInterface):
             return receiver.extension._package
         murano_class = helpers.get_type(helpers.get_caller_context())
     else:
         murano_class = owner.type
     return murano_class.package
开发者ID:AleptNamrata,项目名称:murano,代码行数:8,代码来源:resource_manager.py


示例7: invoke

 def invoke(context, this, *args):
     try:
         executor = helpers.get_executor(context)
         murano_class = helpers.get_type(context)
         return executor.invoke_method(name, this, context, murano_class, *args)
     except exceptions.NoMethodFound:
         raise yaql.exceptions.YaqlExecutionException()
     except exceptions.AmbiguousMethodName:
         raise yaql.exceptions.YaqlExecutionException()
开发者ID:nastya-kuz,项目名称:murano,代码行数:9,代码来源:yaql_functions.py


示例8: getAttr

    def getAttr(self, _context, name, default=None, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(_context))
        if not isinstance(owner, murano_class.MuranoClass):
            raise TypeError()

        attribute_store = helpers.get_attribute_store(_context)

        result = attribute_store.get(self, owner, name)
        return default if result is None else result
开发者ID:OndrejVojta,项目名称:murano,代码行数:10,代码来源:sys_object.py


示例9: _get_container

def _get_container(context, obj, class_name):
    namespace_resolver = helpers.get_type(context).namespace_resolver
    class_loader = helpers.get_class_loader(context)
    class_name = namespace_resolver.resolve_name(class_name)
    murano_class = class_loader.get_class(class_name)
    p = obj.owner
    while p is not None:
        if murano_class.is_compatible(p):
            return p
        p = p.owner
    return None
开发者ID:OndrejVojta,项目名称:murano,代码行数:11,代码来源:yaql_functions.py


示例10: compose_stack_frame

def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    return {
        'instruction': None if instruction is None
        else str(instruction),

        'location': None if instruction is None
        else instruction.source_file_position,

        'method': helpers.get_current_method(context),
        'class': helpers.get_type(context)
    }
开发者ID:OndrejVojta,项目名称:murano,代码行数:12,代码来源:stack_trace.py


示例11: convert

 def convert(self, value, sender, context, function_spec, engine,
             *args, **kwargs):
     context = self._context or context
     if isinstance(value, yaql_expressions.Expression):
         value = value(utils.NO_VALUE, context, engine)
     value = super(MuranoTypeName, self).convert(
         value, sender, context, function_spec, engine)
     if isinstance(value, types.StringTypes):
         murano_type = helpers.get_type(context)
         value = dsl_types.MuranoClassReference(
             helpers.get_class(
                 murano_type.namespace_resolver.resolve_name(
                     value), context))
     return value
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:14,代码来源:dsl.py


示例12: get_property

 def get_property(self, name, 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
     if name in start_type.properties:
         return self.cast(start_type)._get_property_value(name)
     else:
         declared_properties = start_type.find_single_property(name)
         if declared_properties:
             return self.cast(declared_properties).__properties[name]
         elif derived:
             return self.cast(caller_class)._get_property_value(name)
         else:
             raise exceptions.PropertyReadError(name, start_type)
开发者ID:tianshangjun,项目名称:murano,代码行数:15,代码来源:murano_object.py


示例13: convert

 def convert(self, value, sender, context, function_spec, engine,
             *args, **kwargs):
     context = self._context or context
     if isinstance(value, yaql_expressions.Expression):
         value = value(utils.NO_VALUE, context, engine)
     value = super(MuranoTypeName, self).convert(
         value, sender, context, function_spec, engine)
     if isinstance(value, six.string_types):
         if function_spec.meta.get(constants.META_MURANO_METHOD):
             context = helpers.get_caller_context(context)
         murano_type = helpers.get_type(context)
         value = helpers.get_class(
             murano_type.namespace_resolver.resolve_name(value),
             context).get_reference()
     return value
开发者ID:olivierlemasle,项目名称:murano,代码行数:15,代码来源:dsl.py


示例14: check

 def check(self, value, context, *args, **kwargs):
     if not super(MuranoType, self).check(
             value, context, *args, **kwargs):
         return False
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     murano_class = self.murano_class
     if isinstance(murano_class, six.string_types):
         murano_class_name = murano_class
     else:
         murano_class_name = murano_class.name
     return helpers.is_instance_of(
         value, murano_class_name,
         self.version_spec or helpers.get_type(context))
开发者ID:Magic-Mirror,项目名称:murano,代码行数:16,代码来源:dsl.py


示例15: initialize

    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            instruction = helpers.get_current_instruction(context)
            frames.append({
                'instruction': None if instruction is None
                else str(instruction),

                'location': None if instruction is None
                else instruction.source_file_position,

                'method': helpers.get_current_method(context),
                'class': helpers.get_type(context)
            })
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            class InstructionStub(object):
                def __init__(self, title, position):
                    self._title = title
                    self.source_file_position = position

                def __str__(self):
                    return self._title

            native_frames = []
            for frame in inspect.trace()[1:]:
                info = inspect.getframeinfo(frame[0])
                position = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(info.filename), info.lineno,
                    -1, -1, -1, -1, -1)
                instruction = InstructionStub(
                    info.code_context[0].strip(), position)
                method = info.function
                native_frames.append({
                    'instruction': instruction,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
开发者ID:nastya-kuz,项目名称:murano,代码行数:47,代码来源:stack_trace.py


示例16: _new

def _new(context, name, *args):
    murano_class = helpers.get_type(context)
    name = murano_class.namespace_resolver.resolve_name(name)
    parameters = {}
    arg_values = [t() for t in args]
    if len(arg_values) == 1 and isinstance(arg_values[0], types.DictionaryType):
        parameters = arg_values[0]
    elif len(arg_values) > 0:
        for p in arg_values:
            if not isinstance(p, types.TupleType) or not isinstance(p[0], types.StringType):
                raise SyntaxError()
            parameters[p[0]] = p[1]

    object_store = helpers.get_object_store(context)
    class_loader = helpers.get_class_loader(context)
    new_context = yaql.context.Context(parent_context=context)
    for key, value in parameters.iteritems():
        new_context.set_data(value, key)
    return class_loader.get_class(name).new(None, object_store, new_context, parameters=parameters)
开发者ID:nastya-kuz,项目名称:murano,代码行数:19,代码来源:yaql_functions.py


示例17: inject_method_with_str

def inject_method_with_str(context, target, target_method,
                           mock_object, mock_name):
    ctx_manager = helpers.get_executor().context_manager

    current_class = helpers.get_type(context)
    mock_func = current_class.find_single_method(mock_name)
    original_class = target.type

    original_function = original_class.find_single_method(target_method)
    result_fd = original_function.instance_stub.clone()

    def payload_adapter(__context, __sender, *args, **kwargs):
        return mock_func.invoke(
            mock_object, args, kwargs, __context, True)

    result_fd.payload = payload_adapter
    existing_mocks = ctx_manager.class_mock_ctx.setdefault(
        original_class.name, [])
    existing_mocks.append(result_fd)
开发者ID:AleptNamrata,项目名称:murano,代码行数:19,代码来源:mock_context_manager.py


示例18: check

 def check(self, value, context, *args, **kwargs):
     if not super(MuranoObjectParameter, self).check(
             value, context, *args, **kwargs):
         return False
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if not isinstance(value, dsl_types.MuranoObject):
         return False
     if self.murano_class:
         murano_class = self.murano_class
         if isinstance(murano_class, six.string_types):
             return helpers.is_instance_of(
                 value, murano_class,
                 self.version_spec or helpers.get_type(context))
         else:
             return murano_class.is_compatible(value)
     else:
         return True
开发者ID:Aqsamm,项目名称:murano,代码行数:20,代码来源:dsl.py


示例19: class_

        def class_(value, name, default_name=None, version_spec=None):
            object_store = this.object_store
            if not default_name:
                default_name = name
            murano_class = name.murano_class
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                if '?' not in value:
                    new_value = {'?': {
                        'id': uuid.uuid4().hex,
                        'type': default_name.murano_class.name,
                        'classVersion': str(default_name.murano_class.version)
                    }}
                    new_value.update(value)
                    value = new_value

                obj = object_store.load(
                    value, owner, root_context, defaults=default)
            elif isinstance(value, types.StringTypes):
                obj = object_store.get(value)
                if obj is None:
                    if not object_store.initializing:
                        raise exceptions.NoObjectFoundError(value)
                    else:
                        return TypeScheme.ObjRef(value)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        value, name))
            if not helpers.is_instance_of(
                    obj, murano_class.name,
                    version_spec or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, name))
            return obj
开发者ID:tianshangjun,项目名称:murano,代码行数:41,代码来源:type_scheme.py


示例20: 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_properties(
            lambda p: p.name == name)
        if context is None:
            context = self.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_properties(
                lambda p: p.name == name)
            values_to_assign = []
            classes_for_static_properties = []
            for spec in declared_properties:
                if (caller_class is not None and not
                        helpers.are_property_modifications_allowed(context) and
                        (spec.usage not in dsl_types.PropertyUsages.Writable or
                            not derived)):
                    raise exceptions.NoWriteAccessError(name)

                if spec.usage == dsl_types.PropertyUsages.Static:
                    classes_for_static_properties.append(spec.declaring_type)
                else:
                    default = self.__config.get(name, spec.default)
                    # default = helpers.evaluate(default, context)

                    obj = self.cast(spec.declaring_type)
                    values_to_assign.append((obj, spec.transform(
                        value, self.real_this,
                        self.real_this, context, default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
            for cls in classes_for_static_properties:
                cls.set_property(name, value, context)
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
开发者ID:Aqsamm,项目名称:murano,代码行数:40,代码来源:murano_object.py



注:本文中的murano.dsl.helpers.get_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.get_executor函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap