client_manager.py 文件源码

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

项目:uniq 作者: CiscoDevNet 项目源码 文件源码
def sanitize_for_serialization(obj):
        """
        Sanitize an object for Request.

        If obj is None, return None.
        If obj is str, int, float, bool, return directly.
        If obj is datetime.datetime, datetime.date convert to string in iso8601 format.
        If obj is list, santize each element in the list.
        If obj is dict, return the dict.
        If obj is swagger model, return the properties dict.
        """
        if isinstance(obj, type(None)):
            return None
        elif isinstance(obj, (str, int, float, bool, io.IOBase, tuple)):
            return obj
        elif isinstance(obj, list):
            return [NbClientManager.sanitize_for_serialization(sub_obj) for sub_obj in obj]
        elif isinstance(obj, (datetime.datetime, datetime.date)):
            return obj.isoformat()
        else:
            if isinstance(obj, dict):
                obj_dict = obj
            else:
                # Convert model obj to dict except attributes `swaggerTypes`, `attributeMap`
                # and attributes which value is not None.
                # Convert attribute name to json key in model definition for
                # request.
                obj_dict = {obj.attributeMap[key]: val
                            for key, val in obj.__dict__.items()
                            if key != 'swaggerTypes' and key != 'attributeMap' and val is not None}
            return {key: NbClientManager.sanitize_for_serialization(val)
                    for (key, val) in obj_dict.items()}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号