utils.py 文件源码

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

项目:habilitacion 作者: GabrielBD 项目源码 文件源码
def http_quote(string):
    """
    Given a unicode string, will do its dandiest to give you back a
    valid ascii charset string you can use in, say, http headers and the
    like.
    """
    if isinstance(string, six.text_type):
        try:
            import unidecode
        except ImportError:
            pass
        else:
            string = unidecode.unidecode(string)
        string = string.encode('ascii', 'replace')
    # Wrap in double-quotes for ; , and the like
    string = string.replace(b'\\', b'\\\\').replace(b'"', b'\\"')
    return '"{0!s}"'.format(string.decode())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号