当前位置: 首页>>代码示例>>Python>>正文


Python FileResponse.headers["Content-Disposition"]方法代码示例

本文整理汇总了Python中pyramid.response.FileResponse.headers["Content-Disposition"]方法的典型用法代码示例。如果您正苦于以下问题:Python FileResponse.headers["Content-Disposition"]方法的具体用法?Python FileResponse.headers["Content-Disposition"]怎么用?Python FileResponse.headers["Content-Disposition"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.FileResponse的用法示例。


在下文中一共展示了FileResponse.headers["Content-Disposition"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: library

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers["Content-Disposition"] [as 别名]
def library(request):
    music_dir = request.registry.settings["music_dir"]
    library_dir = os.path.join(DATA_DIR, "library")

    # {"dir1/dir2" : "0123456789abcdef0123456789abcdef (content of dir1/dir2/index.json.checksum)"}
    client_library_revision = os.path.join(DATA_DIR, "library_revisions", "%s.json" % request.GET["revision"])
    if os.path.exists(client_library_revision):
        client_directories = json.load(open(client_library_revision))
    else:
        client_directories = {}

    new_files = []
    delete_directories = copy.deepcopy(client_directories)
    for root, dirs, files in os.walk(library_dir, topdown=False):
        rel_root = os.path.relpath(root, library_dir)
        if rel_root == ".":
            rel_root = ""

        index_file = os.path.join(rel_root, "index.json")
        checksum_file = os.path.join(rel_root, "index.json.checksum")

        if rel_root not in client_directories or client_directories[rel_root] != open(os.path.join(library_dir, checksum_file)).read():
            new_files.append(index_file)
            new_files.append(checksum_file)

        if rel_root in delete_directories:
            del delete_directories[rel_root]

    with NamedTemporaryFile() as f:
        with ZipFile(f, "w", ZIP_DEFLATED) as zip_file:
            for new_file in new_files:
                zip_file.write(os.path.join(library_dir, new_file), new_file)
            zip_file.writestr("delete_directories.txt", "\n".join(delete_directories.keys()))
            zip_file.writestr("revision.txt", open(os.path.join(library_dir, "revision.txt")).read())

        response = FileResponse(os.path.abspath(f.name))
        response.headers["Content-Disposition"] = ("attachment; filename=library.zip")
        return response
开发者ID:Gordon01,项目名称:player.thelogin.ru,代码行数:40,代码来源:views.py


注:本文中的pyramid.response.FileResponse.headers["Content-Disposition"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。