webob.response
– Response¶
Response¶
-
class
webob.response.
Response
(body=None, status=None, headerlist=None, app_iter=None, content_type=None, conditional_response=None, **kw)¶ Represents a WSGI response
-
accept_ranges
¶ Gets and sets the
Accept-Ranges
header (HTTP spec section 14.5).
-
age
¶ Gets and sets the
Age
header (HTTP spec section 14.6). Converts it using int.
-
allow
¶ Gets and sets the
Allow
header (HTTP spec section 14.7). Converts it using list.
-
app_iter
¶ Returns the app_iter of the response.
If body was set, this will create an app_iter from that body (a single-item list)
-
app_iter_range
(start, stop)¶ Return a new app_iter built from the response app_iter, that serves up only the given
start:stop
range.
-
body
¶ The body of the response, as a
str
. This will read in the entire app_iter if necessary.
-
body_file
¶ A file-like object that can be used to write to the body. If you passed in a list app_iter, that app_iter will be modified by writes.
-
cache_control
¶ Get/set/modify the Cache-Control header (HTTP spec section 14.9)
-
charset
¶ Get/set the charset (in the Content-Type)
-
conditional_response_app
(environ, start_response)¶ Like the normal __call__ interface, but checks conditional headers:
- If-Modified-Since (304 Not Modified; only on GET, HEAD)
- If-None-Match (304 Not Modified; only on GET, HEAD)
- Range (406 Partial Content; only on GET, HEAD)
-
content_disposition
¶ Gets and sets the
Content-Disposition
header (HTTP spec section 19.5.1).
-
content_encoding
¶ Gets and sets the
Content-Encoding
header (HTTP spec section 14.11).
-
content_language
¶ Gets and sets the
Content-Language
header (HTTP spec section 14.12). Converts it using list.
-
content_length
¶ Gets and sets the
Content-Length
header (HTTP spec section 14.17). Converts it using int.
-
content_location
¶ Gets and sets the
Content-Location
header (HTTP spec section 14.14).
-
content_md5
¶ Gets and sets the
Content-MD5
header (HTTP spec section 14.14).
-
content_range
¶ Gets and sets the
Content-Range
header (HTTP spec section 14.16). Converts it using ContentRange object.
-
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.
-
content_type_params
¶ A dictionary of all the parameters in the content type.
(This is not a view, set to change, modifications of the dict would not be applied otherwise)
-
copy
()¶ Makes a copy of the response
-
date
¶ Gets and sets the
Date
header (HTTP spec section 14.18). Converts it using HTTP date.
Delete a cookie from the client. Note that path and domain must match how the cookie was originally set.
This sets the cookie to the empty string, and max_age=0 so that it should expire immediately.
-
encode_content
(encoding='gzip', lazy=False)¶ Encode the content with the given encoding (only gzip and identity are supported).
-
etag
¶ Gets and sets the
ETag
header (HTTP spec section 14.19). Converts it using Entity tag.
-
expires
¶ Gets and sets the
Expires
header (HTTP spec section 14.21). Converts it using HTTP date.
-
classmethod
from_file
(fp)¶ Reads a response from a file-like object (it must implement
.read(size)
and.readline()
).It will read up to the end of the response, not the end of the file.
This reads the response as represented by
str(resp)
; it may not read every valid HTTP response properly. Responses must have aContent-Length
-
headerlist
¶ The list of response headers
-
headers
¶ The headers in a dictionary-like object
-
json
¶ Access the body of the response as JSON
-
json_body
¶ Access the body of the response as JSON
-
last_modified
¶ Gets and sets the
Last-Modified
header (HTTP spec section 14.29). Converts it using HTTP date.
-
location
¶ Gets and sets the
Location
header (HTTP spec section 14.30).
-
md5_etag
(body=None, set_content_md5=False)¶ Generate an etag for the response object using an MD5 hash of the body (the body parameter, or
self.body
if not given)Sets
self.etag
Ifset_content_md5
is True setsself.content_md5
as well
Merge the cookies that were set on this response with the given resp object (which can be any WSGI application).
If the resp is a
webob.Response
object, then the other object will be modified in-place.
-
pragma
¶ Gets and sets the
Pragma
header (HTTP spec section 14.32).
-
retry_after
¶ Gets and sets the
Retry-After
header (HTTP spec section 14.37). Converts it using HTTP date or delta seconds.
-
server
¶ Gets and sets the
Server
header (HTTP spec section 14.38).
Set (add) a cookie for the response.
Arguments are:
name
The cookie name.value
The cookie value, which should be a string orNone
. Ifvalue
isNone
, it’s equivalent to calling thewebob.response.Response.unset_cookie()
method for this cookie key (it effectively deletes the cookie on the client).max_age
An integer representing a number of seconds,datetime.timedelta
, orNone
. This value is used as theMax-Age
of the generated cookie. Ifexpires
is not passed and this value is notNone
, themax_age
value will also influence theExpires
value of the cookie (Expires
will be set to now + max_age). If this value isNone
, the cookie will not have aMax-Age
value (unlessexpires
is set). If bothmax_age
andexpires
are set, this value takes precedence.path
A string representing the cookiePath
value. It defaults to/
.domain
A string representing the cookieDomain
, orNone
. If domain isNone
, noDomain
value will be sent in the cookie.secure
A boolean. If it’sTrue
, thesecure
flag will be sent in the cookie, if it’sFalse
, thesecure
flag will not be sent in the cookie.httponly
A boolean. If it’sTrue
, theHttpOnly
flag will be sent in the cookie, if it’sFalse
, theHttpOnly
flag will not be sent in the cookie.comment
A string representing the cookieComment
value, orNone
. Ifcomment
isNone
, noComment
value will be sent in the cookie.expires
Adatetime.timedelta
object representing an amount of time,datetime.datetime
orNone
. A non-None
value is used to generate theExpires
value of the generated cookie. Ifmax_age
is not passed, but this value is notNone
, it will influence theMax-Age
header. If this value isNone
, theExpires
cookie value will be unset (unlessmax_age
is set). Ifmax_age
is set, it will be used to generate theexpires
and this value is ignored.overwrite
If this key isTrue
, before setting the cookie, unset any existing cookie.
-
status
¶ The status string
-
status_code
¶ The status as an integer
-
status_int
¶ The status as an integer
-
text
¶ Get/set the text value of the body (using the charset of the Content-Type)
-
ubody
¶ Deprecated alias for .text
-
unicode_body
¶ Deprecated alias for .text
Unset a cookie with the given name (remove it from the response).
-
vary
¶ Gets and sets the
Vary
header (HTTP spec section 14.44). Converts it using list.
-
www_authenticate
¶ Gets and sets the
WWW-Authenticate
header (HTTP spec section 14.47). Converts it usingparse_auth
andserialize_auth
.
-
-
class
webob.response.
AppIterRange
(app_iter, start, stop)¶ Wraps an app_iter, returning just a range of bytes