本文整理汇总了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