Package wtf :: Package app :: Module response :: Class Response
[hide private]
[frames] | no frames]

Class Response

source code

object --+
         |
        Response

Main response object
Instance Methods [hide private]
 
__init__(self, request, start_response)
Initialization
source code
any
__getattr__(self, name)
Resolve unknown attributes
source code
tuple
status(self, status=None, reason=None)
Set/get response status
source code
 
cookie(self, name, value, path='/', expires=None, max_age=None, domain=None, secure=None, comment=None, version=None, codec=None)
Set response cookie
source code
str
content_type(self, ctype=None, charset=None)
Set/get response content type
source code
 
content_length(self, length)
Add content length information
source code
 
last_modified(self, last_modified)
Add last-modified information
source code
 
cache(self, expiry, audience=None)
Add cache information
source code
 
raise_error(self, status, **param)
Raise an HTTP error
source code
 
raise_redirect(self, location, status=302)
Raise HTTP redirect
source code
 
raise_basic_auth(self, realm, message=None)
Raise a 401 error for HTTP Basic authentication
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
tuple _status = None
Tuple of status and reason phrase ((int, 'reason'))
HeaderCollection headers
Response header collection.
callable write
Response body writer.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, request, start_response)
(Constructor)

source code 
Initialization
Parameters:
Overrides: object.__init__

__getattr__(self, name)
(Qualification operator)

source code 

Resolve unknown attributes

We're looking for special env variables inserted by the middleware stack: wtf.response.<name>. These are expected to be factories, which are lazily initialized with the response object and return the actual attribute, which is cached in the response object for further use.

Parameters:
  • name (str) - The name to look up
Returns: any
The attribute in question
Raises:
  • AttributeError - Attribute could not be resolved

status(self, status=None, reason=None)

source code 
Set/get response status
Parameters:
  • status (int) - Response status code
  • reason (str) - Reason phrase
Returns: tuple
Tuple of previous status and reason phrase ((int, 'reason'))

cookie(self, name, value, path='/', expires=None, max_age=None, domain=None, secure=None, comment=None, version=None, codec=None)

source code 

Set response cookie

Parameters:
  • name (str) - Cookie name
  • value (str) - Cookie value (if a codec is given, the type should be applicable for the codec encoder).
  • path (str) - Valid URL base path for the cookie. It should always be set to a reasonable path (at least /), otherwise the cookie will only be valid for the current URL and below.
  • expires (datetime.datetime) - Expire time of the cookie. If unset or None the cookie is dropped when the browser is closed. See also the max_age parameter.
  • max_age (int) - Max age of the cookie in seconds. If set, make sure it matches the expiry time. The difference is that expires will be transformed to a HTTP date, while max-age will stay an integer. The expires parameter is the older one and better understood by the clients out there. For that reason if you set max_age only, expires will be set automatically to now + max_age. If unset or None the cookie will be dropped when the browser is closed.
  • domain (str) - Valid domain
  • secure (bool) - Whether this is an SSL-only cookie or not
  • comment (str) - Cookie comment
  • version (int) - Cookie spec version. See RFC 2965
  • codec (CookieCodecInterface) - Cookie codec to apply. If unset or None, the codec specified in the application configuration is applied.

content_type(self, ctype=None, charset=None)

source code 
Set/get response content type
Parameters:
  • ctype (str) - Content-Type
  • charset (str) - Charset
Returns: str
Full previous content type header (maybe None)

content_length(self, length)

source code 
Add content length information
Parameters:
  • length (int) - The expected length in octets

last_modified(self, last_modified)

source code 
Add last-modified information
Parameters:
  • last_modified (datetime.datetime) - Last modification date (UTC)

cache(self, expiry, audience=None)

source code 
Add cache information
Parameters:
  • expiry (int) - Expiry time in seconds from now
  • audience (str) - Caching audience; private or public

raise_error(self, status, **param)

source code 
Raise an HTTP error
Parameters:
  • status (int) - Status code
  • param (dict) - Additional parameters for the accompanying class in http_response. The request object is passed automagically.
Raises:
  • KeyError - The status code is not available
  • HTTPResponse - The requested HTTP exception

raise_redirect(self, location, status=302)

source code 
Raise HTTP redirect
Parameters:
  • location (str) - URL to redirect to
  • status (int) - Response code
Raises:

raise_basic_auth(self, realm, message=None)

source code 
Raise a 401 error for HTTP Basic authentication
Parameters:
  • realm (str) - The realm to authenticate
  • message (str) - Optional default overriding message
Raises:

Instance Variable Details [hide private]

headers

Response header collection. The headers are flushed autmatically before the fist write call or the returned iterable is passed to the WSGI layer below. The headers can't be changed anymore after that (the collection object will emit a warning in case you attempt to do that)
Type:
HeaderCollection

write

Response body writer. You are not forced to use it. In fact, it's recommended to not use it but return an iterator over the response body instead (as WSGI takes it)
Type:
callable