webtools.response

HTTP response objects. Ported from webapp2, refactored to support Python versions > 2.7, 3.0

class webtools.response.ResponseHeaders(*args, **kw)

Implements methods from wsgiref.headers.Headers, used by webtools.

add_header(_name, _value, **_params)

Extended header setting.

_name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key=”value” unless value is None, in which case only the key will be added.

Example:

h.add_header('content-disposition', 'attachment', filename='bud.gif')

Note that unlike the corresponding ‘email.message’ method, this does not handle ‘(charset, language, value)’ tuples: all values must be strings or None.

class webtools.response.Response(body=None, status=None, headerlist=None, app_iter=None, content_type=None, conditional_response=None, **kw)

Abstraction for an HTTP response.

status

The status string, including code and message.

set_status(code, message=None)

Sets the HTTP status code of this response.

Parameters:
  • code – The HTTP status string to use
  • message – A status string. If none is given, uses the default from the HTTP/1.1 specification.
status_message

The response status message, as a string.

headers

The headers as a dictionary-like object.

clear()

Clears all data written to the output stream so that it is empty.

static http_status_message(code)

Returns the default HTTP status message for the given code.

Parameters:code – The HTTP code for which we want a message.
RequestClass

alias of Request

Previous topic

webtools.request

This Page