base.py 文件源码

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

项目:zun 作者: openstack 项目源码 文件源码
def obj_to_primitive(obj):
    """Recursively turn an object into a python primitive.

    A ZunObject becomes a dict, and anything that implements ObjectListBase
    becomes a list.
    """
    if isinstance(obj, ObjectListBase):
        return [obj_to_primitive(x) for x in obj]
    elif isinstance(obj, ZunObject):
        result = {}
        for key in obj.obj_fields:
            if obj.obj_attr_is_set(key) or key in obj.obj_extra_fields:
                result[key] = obj_to_primitive(getattr(obj, key))
        return result
    elif isinstance(obj, netaddr.IPAddress):
        return str(obj)
    elif isinstance(obj, netaddr.IPNetwork):
        return str(obj)
    else:
        return obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号