data_formats.py 文件源码

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

项目:pycoalaip 作者: bigchaindb 项目源码 文件源码
def _make_context_immutable(context):
    """Best effort attempt at turning a properly formatted context
    (either a string, dict, or array of strings and dicts) into an
    immutable data structure.

    If we get an array, make it immutable by creating a tuple; if we get
    a dict, copy it into a MappingProxyType. Otherwise, return as-is.
    """
    def make_immutable(val):
        if isinstance(val, Mapping):
            return MappingProxyType(val)
        else:
            return val

    if not isinstance(context, (str, Mapping)):
        try:
            return tuple([make_immutable(val) for val in context])
        except TypeError:
            pass
    return make_immutable(context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号