cardinal_pythonlib.pyramid.responses


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Specialized response types for Pyramid (which implement MIME types and suggested download methods, etc.).

class cardinal_pythonlib.pyramid.responses.BinaryResponse(body: bytes, filename: str, content_type: str, as_inline: bool = False, **kwargs)[source]

Base class for creating binary HTTP responses.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.

class cardinal_pythonlib.pyramid.responses.JsonAttachmentResponse(body: str, filename: str, **kwargs)[source]

Response class for returning a JSON file to the user as an attachment.

class cardinal_pythonlib.pyramid.responses.JsonResponse(body: str, **kwargs)[source]

Response class for showing JSON in the browser.

class cardinal_pythonlib.pyramid.responses.OdsResponse(body: bytes, filename: str, **kwargs)[source]

Response class for returning an ODS (OpenOffice Spreadsheet) file to the user.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.

class cardinal_pythonlib.pyramid.responses.PdfResponse(body: bytes, filename: str, as_inline: bool = True, **kwargs)[source]

Response class for returning a PDF to the user.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.

class cardinal_pythonlib.pyramid.responses.SqliteBinaryResponse(body: bytes, filename: str, **kwargs)[source]

Response class for returning a SQLite binary database to the user.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.

class cardinal_pythonlib.pyramid.responses.TextAttachmentResponse(body: str, filename: str, **kwargs)[source]

Response class for returning text to the user as an attachment.

class cardinal_pythonlib.pyramid.responses.TextResponse(body: str, **kwargs)[source]

Response class for returning text to the user, viewed in the browser.

class cardinal_pythonlib.pyramid.responses.TsvResponse(body: str, filename: str, **kwargs)[source]

Response class for returning a TSV file to the user.

class cardinal_pythonlib.pyramid.responses.XlsxResponse(body: bytes, filename: str, **kwargs)[source]

Response class for returning an XLSX (Excel) file to the user.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.

class cardinal_pythonlib.pyramid.responses.XmlResponse(body: str, **kwargs)[source]

Response class for returning XML to the user.

class cardinal_pythonlib.pyramid.responses.ZipResponse(body: bytes, filename: str, **kwargs)[source]

Response class for returning a ZIP file to the user.

Parameters:
  • body – binary data

  • filename – filename to associate with the download

  • content_type – MIME content type

  • as_inline – inline, rather than as an attachment? Inline: display within browser, if possible. Attachment: download.