Latest Version: 0.9.6.2

WSGIResponse

A basic HTTP response with content, headers, and out-bound cookies

The class variable defaults specifies default values for content_type, charset and errors. These can be overridden for the current request via the registry.


Attributes

a charset

Get/set the charset (in the Content-Type)

a content

Get/set the specified content, where content can be: a string, a list of strings, a generator function that yields strings, or an iterable object that produces strings.

a content_type

Get/set the Content-Type header (or None), without the charset or any parameters.

If you include parameters (or ; at all) when setting the content_type, any existing parameters will be deleted; otherwise they will be preserved.

a defaults

{'headers': {'Cache-Control': 'no-cache'}, 'errors': 'strict', 'charset': 'utf-8', 'content_type': 'text/html'}

Methods

f __call__(self, environ, start_response) ...

Convenience call to return output and set status information

Conforms to the WSGI interface for calling purposes only.

Example usage:

1
2
3
4
5
def wsgi_app(environ, start_response):
    response = WSGIResponse()
    response.write("Hello world")
    response.headers['Content-Type'] = 'latin1'
    return response(environ, start_response)

f __init__(self, content='', mimetype=None, code=200) ...

f charset__del(self) ...

f charset__get(self) ...

Get/set the charset (in the Content-Type)

f charset__set(self, charset) ...

f content_type__get(self) ...

Get/set the Content-Type header (or None), without the charset or any parameters.

If you include parameters (or ; at all) when setting the content_type, any existing parameters will be deleted; otherwise they will be preserved.

f content_type__set(self, value) ...

f delete_cookie(self, key, path='/', domain=None) ...

Notify the browser the specified cookie has expired and should be deleted (via the outgoing HTTP headers)

f determine_charset(self) ...

Determine the encoding as specified by the Content-Type's charset parameter, if one is set

f flush(self) ...

f get_content(self) ...

Returns the content as an iterable of strings, encoding each element of the iterator from a Unicode object if necessary.

f has_header(self, header) ...

Case-insensitive check for a header

f set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None) ...

Define a cookie to be sent via the outgoing HTTP headers

f tell(self) ...

f write(self, content) ...

f wsgi_response(self) ...

Return this WSGIResponse as a tuple of WSGI formatted data, including: (status, headers, iterable)

See the source for more information.

Top