client.py 文件源码

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

项目:h1-python 作者: uber-common 项目源码 文件源码
def encode_params(obj, keys=()):
    if isinstance(obj, dict):
        # key[bar]=1&key[baz]=2
        return "&".join(encode_params(val, keys + (key,)) for key, val in obj.items())
    # key[foo][]=1&key[foo][]=2
    elif isinstance(obj, (list, tuple)):
        return "&".join(encode_params(val, keys + ("",)) for val in obj)
    # `obj` is just a value, key=1
    else:
        encoded_keys = ""
        for depth, key in enumerate(keys):
            # All keys but top-level keys should be in brackets, i.e.
            # `key[foo]=1`, not `[key][foo]=1`
            encoded_keys += key if depth == 0 else "[" + key + "]"
        return quote(encoded_keys) + "=" + quote(obj)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号