api_helper.py 文件源码

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

项目:apimatic-cli 作者: apimatic 项目源码 文件源码
def form_encode(obj,
                    instance_name,
                    array_serialization="indexed"):
        """Encodes a model in a form-encoded manner such as person[Name]

        Args:
            obj (object): The given Object to form encode.
            instance_name (string): The base name to appear before each entry
                for this object.
            array_serialization (string): The format of array parameter serialization.

        Returns:
            dict: A dictionary of form encoded properties of the model.

        """
        retval = []

        # If we received an object, resolve it's field names.
        if hasattr(obj, "_names"):
            obj = APIHelper.to_dictionary(obj)

        if obj is None:
            return []
        elif isinstance(obj, list):
            for element in APIHelper.serialize_array(instance_name, obj, array_serialization):
                retval += APIHelper.form_encode(element[1], element[0], array_serialization)
        elif isinstance(obj, dict):
            for item in obj:
                retval += APIHelper.form_encode(obj[item], instance_name + "[" + item + "]", array_serialization)
        else:
            retval.append((instance_name, obj))

        return retval
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号