multihash.py 文件源码

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

项目:oldchain-client 作者: mediachain 项目源码 文件源码
def _hashfn(hashfn):
    """Return an initialised hash object, by function, name or integer id

    >>> _hashfn(SHA1) # doctest: +ELLIPSIS
    <sha1 HASH object @ 0x...>

    >>> _hashfn('sha2-256') # doctest: +ELLIPSIS
    <sha256 HASH object @ 0x...>
    >>> _hashfn('18') # doctest: +ELLIPSIS
    <sha256 HASH object @ 0x...>

    >>> _hashfn('md5')
    Traceback (most recent call last):
      ...
    ValueError: Unknown hash function "md5"
    """
    if six.callable(hashfn):
        return hashfn()

    elif isinstance(hashfn, six.integer_types):
        return FUNCS[hashfn]()

    elif isinstance(hashfn, six.string_types):
        if hashfn in NAMES:
            return FUNCS[NAMES[hashfn]]()

        elif hashfn.isdigit():
            return _hashfn(int(hashfn))

    raise ValueError('Unknown hash function "{0}"'.format(hashfn))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号