response.py 文件源码

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

项目:pynetbox 作者: digitalocean 项目源码 文件源码
def serialize(self, nested=False):
        """Serializes an object

        Pulls all the attributes in an object and creates a dict that
        can be turned into the json that netbox is expecting.

        If an attribute's value is a ``Record`` or ``IPRecord`` type
        it's replaced with the ``id`` field of that object.

        :returns: dict of values the NetBox API is expecting.
        """
        if nested:
            return _get_return(self)

        ret = {}
        for i in dict(self):
            current_val = getattr(self, i)
            if isinstance(current_val, Record):
                current_val = getattr(current_val, 'serialize')(nested=True)

            if isinstance(current_val, netaddr.ip.IPNetwork):
                current_val = str(current_val)

            ret.update({i: current_val})
        return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号