Python pyramid.response 模块,FileResponse() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用pyramid.response.FileResponse()

项目:geo-pyprint    作者:ioda-net    | 项目源码 | 文件源码
def mapprint(request):
    payload = request.json_body

    output_file_name = MapPrint(payload).print_pdf()

    response = FileResponse(
        output_file_name,
        request=request
    )
    response.headers['Content-Disposition'] = ('attachement; filename="{}"'
                                               .format(output_file_name + '.pdf'))
    response.headers['Content-Type'] = 'application/pdf'

    if os.path.exists(output_file_name):
        os.remove(output_file_name)

    return response
项目:Tktr    作者:Intuity    | 项目源码 | 文件源码
def photo_view(self):
        # Check agreements
        if not self.user.purchase_agreement:
            return HTTPFound(location=self.request.route_path("purchase_agreement_act"))
        elif not self.user.privacy_agreement:
            return HTTPFound(location=self.request.route_path("privacy_policy_act"))
        base_path = self.request.registry._settings["base_dir"]
        if "tick_id" in self.request.matchdict:
            tick_id = self.request.matchdict["tick_id"]
            ticket = None
            # Find ticket
            for tick in self.user.tickets:
                if tick.__name__ == tick_id:
                    ticket = tick
                    break
            # Safety
            if ticket == None:
                return FileResponse(os.path.join(base_path, "data/profile_images", "blank.png"), request=self.request)
            else:
                file_name = ticket.guest_info.photo_file
                if os.path.isfile(os.path.join(base_path, "data/profile_images", file_name)):
                    return FileResponse(os.path.join(base_path, "data/profile_images", file_name), request=self.request)
                else:
                    return FileResponse(os.path.join(base_path, "data/profile_images", "blank.png"), request=self.request)
        else:
            file_name = self.user.profile.photo_file
            if os.path.isfile(os.path.join(base_path, "data/profile_images", file_name)):
                return FileResponse(os.path.join(base_path, "data/profile_images", file_name), request=self.request)
            else:
                return FileResponse(os.path.join(base_path, "data/profile_images", "blank.png"), request=self.request)
项目:unsonic    作者:redshodan    | 项目源码 | 文件源码
def index(request):
    here = os.path.dirname(__file__)
    index = os.path.join(here, 'index.html')
    return FileResponse(index, request=request)
项目:unsonic    作者:redshodan    | 项目源码 | 文件源码
def handleReq(self, session):
        row = session.query(Track).filter(Track.id == self.params["id"]).all()[0]
        return FileResponse(row.path)
项目:devpi    作者:devpi    | 项目源码 | 文件源码
def doc_serve(context, request):
    """ Serves the raw documentation files. """
    context = ContextWrapper(context)
    doc_info = get_doc_info(context, request)
    return FileResponse(str(doc_info['doc_path']))
项目:kotori    作者:daq-tools    | 项目源码 | 文件源码
def favicon_view(request):
    """
    http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/assets.html#registering-a-view-callable-to-serve-a-static-asset
    """
    icon = resource_filename('kotori.frontend', 'static/favicon.ico')
    if os.path.isfile(icon):
        return FileResponse(icon, request=request)
    else:
        return HTTPNotFound()