本文整理匯總了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