utils.py 文件源码

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

项目:tintri-python-sdk 作者: Tintri 项目源码 文件源码
def map_to_object(m, cls):
    def __getobjecttype(cls, varname):
        from .__init__ import TintriObject
        if '_property_map' in dir(cls):
            if varname in cls._property_map.keys():
                return cls._property_map[varname]
        return TintriObject

    if type(m) == types.DictionaryType:
        o = cls()

        ignoresetattr = None
        if hasattr(o, '_ignoresetattr'):
            ignoresetattr = o._ignoresetattr
            o._ignoresetattr = True

        for k in m.keys():
            cls2 = __getobjecttype(cls, k)
            setattr(o, k, map_to_object(m[k], cls2))

        if ignoresetattr:
            o._ignoresetattr = ignoresetattr

        return o
    elif type(m) == types.ListType:
        objects = []
        for obj in m:
            objects.append(map_to_object(obj, cls))
        return objects
    else:
        return m
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号