downloads.py 文件源码

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

项目:python-flask-security 作者: weinbergdavid 项目源码 文件源码
def filename_from_url(url, content_type):
    fn = urlsplit(url).path.rstrip('/')
    fn = os.path.basename(fn) if fn else 'index'
    if '.' not in fn and content_type:
        content_type = content_type.split(';')[0]
        if content_type == 'text/plain':
            # mimetypes returns '.ksh'
            ext = '.txt'
        else:
            ext = mimetypes.guess_extension(content_type)

        if ext == '.htm':  # Python 3
            ext = '.html'

        if ext:
            fn += ext

    return fn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号