APIHelper.py 文件源码

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

项目:kairos-emotion-sdk-python 作者: kairosinc 项目源码 文件源码
def form_encode(obj,
                    instanceName):
        """Encodes a model in a form-encoded manner such as person[Name]

        Args:
            obj (object): The given Object to form encode.
            instanceName (string): The base name to appear before each entry
                for this object.

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

        """
        # Resolve the names first
        value = APIHelper.resolve_name(obj)
        retval = dict()

        if value is None:
            return None

        # Loop through every item we need to send
        for item in value:
            if isinstance(value[item], list):
                # Loop through each item in the list and add it by number
                i = 0
                for entry in value[item]:
                    retval.update(APIHelper.form_encode(entry, instanceName + "[" + item + "][" + str(i) + "]"))
                    i += 1
            elif isinstance(value[item], dict):
                # Loop through each item in the dictionary and add it
                retval.update(APIHelper.form_encode(value[item], instanceName + "[" + item + "]"))
            else:
                # Add the current item
                retval[instanceName + "[" + item + "]"] = value[item]

        return retval
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号