sqla.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:idealoom 作者: conversence 项目源码 文件源码
def _create_subobject_from_json(
            self, json, target_cls, parse_def,
            context, accessor_name, object_importer=None):
        instance = None
        target_type = json.get('@type', None)
        if target_type:
            new_target_cls = get_named_class(target_type)
            if new_target_cls:
                if target_cls is not None and \
                        not issubclass(new_target_cls, target_cls):
                    raise HTTPBadRequest(
                        "Type %s was assigned to %s.%s" % (
                            target_type, self.__class__.__name__,
                            accessor_name))
                target_cls = new_target_cls
        if not target_cls:
            # Not an instance
            return None
        target_id = json.get('@id', None)
        if target_id is not None:
            if isinstance(target_id, string_types):
                instance = self._json_is_known_instance(target_id, object_importer)
                if instance is not None and object_importer:
                    object_importer.associate(target_id, instance)
        if instance is not None:
            # Interesting that it works here and not upstream
            sub_context = instance.get_instance_context(context)
            log.info("Chaining context from %s -> %s" % (context, sub_context))
            # NOTE: Here we could tombstone the instance if tombstonable.
            instance = instance._do_update_from_json(
                json, parse_def, sub_context,
                DuplicateHandling.USE_ORIGINAL, object_importer)
            instance = instance.handle_duplication(
                json, parse_def, sub_context,
                DuplicateHandling.USE_ORIGINAL, object_importer)
        else:
            instance_ctx = target_cls._do_create_from_json(
                json, parse_def, context,
                DuplicateHandling.USE_ORIGINAL, object_importer)
            if instance_ctx is None:
                raise HTTPBadRequest(
                    "Could not find or create object %s" % (
                        dumps(json),))
            if instance_ctx._instance:
                context.on_new_instance(instance_ctx._instance)
        if (target_id is not None and object_importer and
                instance_ctx._instance is not None):
            object_importer.associate(target_id, instance_ctx._instance)
        return instance_ctx

    # If a duplicate is created, do we use the original? (Error otherwise)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号