_helpers.py 文件源码

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

项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码
def _from_bytes(value):
    """Converts bytes to a string value, if necessary.

    Args:
        value: The string/bytes value to be converted.

    Returns:
        The original value converted to unicode (if bytes) or as passed in
        if it started out as unicode.

    Raises:
        ValueError if the value could not be converted to unicode.
    """
    result = (value.decode('utf-8')
              if isinstance(value, six.binary_type) else value)
    if isinstance(result, six.text_type):
        return result
    else:
        raise ValueError(
            '{0!r} could not be converted to unicode'.format(value))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号