wrapper.py 文件源码

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

项目:ovirtcmd 作者: fbacchella 项目源码 文件源码
def _transform_arg_type(name_type_mapping, k, v):
        name_type = name_type_mapping.get(k, None)
        name_type_wrapper = type_wrappers.get(name_type)
        if v is None:
            t = None
        elif isinstance(v, ObjectWrapper):
            t = v.type
        elif isinstance(v, str) and isinstance(name_type, EnumMeta):
            try:
                t = name_type(v)
            except ValueError:
                try:
                    t = name_type[v]
                except KeyError:
                    raise OVLibError("invalid name %s for %s" % (v, name_type.__name__))
        elif isinstance(v, str) and hasattr(name_type, 'name'):
            t = name_type(name=v)
        elif isinstance(v, dict) and name_type_wrapper is not None:
            try:
                mapped_kwargs = ObjectWrapper._map_dict(name_type_wrapper.name_type_mapping, v)
                t = name_type_mapping[k](**mapped_kwargs)
            except TypeError as e:
                raise OVLibError("Incomplete type mapping for %s(%s): %s" % (name_type_mapping[k], mapped_kwargs, e), exception=e)
        elif isinstance(v, collections.Iterable) and not isinstance(v, str) and not isinstance(v, dict):
            t = list(map(lambda x: ObjectWrapper._transform_arg_type(name_type_mapping, k, x), v))
        else:
            t = v
        return t
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号