common.py 文件源码

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

项目:tintri-python-sdk 作者: Tintri 项目源码 文件源码
def _json_object_to_object(self, json_object, entity_class, context={}):
        if type(json_object) == types.DictionaryType:
            if hasattr(entity_class, '_is_paginated') and entity_class._is_paginated:
                try:
                    if hasattr(self, '_process_page'):
                        return self._process_page(json_object, entity_class, context)
                    else:
                        raise AttributeError('Class %s does not have _process_page() method' % entity_class.__name__)
                except ValueError:
                    return map_to_object(json_object, entity_class)
            else:
                return map_to_object(json_object, entity_class)
        elif type(json_object) == types.ListType:
            objects = []
            for obj in json_object:
                objects.append(map_to_object(obj, entity_class))

            # if auto_page is set, return a page with the items
            if 'typeId' in json_object and json_object['typeId'] == 'com.tintri.api.rest.v310.dto.Page' and self.__auto_page:
                return TintriPage(paginated=entity_class._is_paginated, items=objects, context=context)
            else:
                return objects
        else:
            return json_object # Return any other type as is, such as None, string, number, boolean
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号