當前位置: 首頁>>代碼示例>>Python>>正文


Python FileResponse.set_cookie方法代碼示例

本文整理匯總了Python中pyramid.response.FileResponse.set_cookie方法的典型用法代碼示例。如果您正苦於以下問題:Python FileResponse.set_cookie方法的具體用法?Python FileResponse.set_cookie怎麽用?Python FileResponse.set_cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyramid.response.FileResponse的用法示例。


在下文中一共展示了FileResponse.set_cookie方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: artifact_download

# 需要導入模塊: from pyramid.response import FileResponse [as 別名]
# 或者: from pyramid.response.FileResponse import set_cookie [as 別名]
def artifact_download(request, inline):
    af = get_artifact(request)

    if af.is_bundle:
        if inline:
            raise HTTPBadRequest("Inline view not supported for bundles")
        # We have a bundle. So we need to prepare a zip (unless we already have one)
        disk_name = af.file
        # Locking on a separate file since zipfile did not want to write to the
        # same file we are locking on. It just means that we need to clean up
        # that file at the same time as the main cache file.
        with portalocker.Lock(disk_name + ".lock", timeout=300, check_interval=1):
            if not os.path.exists(disk_name):
                with zipfile.ZipFile(disk_name, 'w', compression=zipfile.ZIP_BZIP2) as _zip:
                    for cf in af.artifacts:
                        _zip.write(cf.file, arcname=cf.bundle_filename(af))
        file_name = af.name + ".zip"
    else:
        disk_name = af.file
        file_name = af.filename

    mime, encoding = mimetypes.guess_type(file_name)
    if mime is None:
        mime = ('text/plain' if inline else 'application/octet-stream')
    # If the current simple approach proves to be a problem the discussion
    # at http://stackoverflow.com/q/93551/11722 can be considered.
    response = FileResponse(disk_name, request=request, content_type=mime)
    response.content_disposition = '{}; filename="{}"'.format('inline' if inline else 'attachment', file_name)
    # Specifically needed for jquery.fileDownload
    response.set_cookie('fileDownload', 'true')
    return response
開發者ID:Zitrax,項目名稱:Artifakt,代碼行數:33,代碼來源:artifacts.py


注:本文中的pyramid.response.FileResponse.set_cookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。