当前位置: 首页>>代码示例>>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;未经允许,请勿转载。