Like .str_GET, but decodes values and keys
Like .str_POST, but decodes values and keys
alias of Response
Gets and sets the Accept header (HTTP spec section 14.1).
Gets and sets the Accept-Charset header (HTTP spec section 14.2).
Gets and sets the Accept-Encoding header (HTTP spec section 14.3).
Gets and sets the Accept-Language header (HTTP spec section 14.4).
The URL including SCRIPT_NAME (no PATH_INFO or query string)
Return HTTP string representing this request. If skip_body is True, exclude the body. If skip_body is an integer larger than one, skip body only if its length is bigger than that number.
Gets and sets the Authorization header (HTTP spec section 14.8). Converts it using parse_auth and serialize_auth.
Create a blank request environ (and Request wrapper) with the given path (path should be urlencoded), and any keys from environ.
The path will become path_info, with any query string split off and used.
All necessary keys will be added to the environ, but the values you pass in will take precedence. If you pass in base_url then wsgi.url_scheme, HTTP_HOST, and SCRIPT_NAME will be filled in from that value.
Any extra keyword will be passed to __init__ (e.g., decode_param_names).
Return the content of the request body.
Input stream of the request (wsgi.input). Setting this property resets the content_length and seekable flag (unlike setting req.body_file_raw).
Gets and sets the wsgi.input key in the environment.
Get the body of the request (wsgi.input) as a seekable file-like object. Middleware and routing applications should use this attribute over .body_file.
If you access this value, CONTENT_LENGTH will also be updated.
Get/set/modify the Cache-Control header (HTTP spec section 14.9)
Call the given WSGI application, returning (status_string, headerlist, app_iter)
Be sure to call app_iter.close() if it’s there.
If catch_exc_info is true, then returns (status_string, headerlist, app_iter, exc_info), where the fourth item may be None, but won’t be if there was an exception. If you don’t do this and there was an exception, the exception will be raised directly.
Get the charset of the request.
If the request was sent with a charset parameter on the Content-Type, that will be used. Otherwise if there is a default charset (set during construction, or as a class attribute) that will be returned. Otherwise None.
Setting this property after request instantiation will always update Content-Type. Deleting the property updates the Content-Type to remove any charset parameter (if none exists, then deleting the property will do nothing, and there will be no error).
Gets and sets the Content-Length header (HTTP spec section 14.13). Converts it using int.
Return the content type, but leaving off any parameters (like charset, but also things like the type in application/atom+xml; type=entry)
If you set this property, you can include parameters, or if you don’t include any parameters in the value then existing parameters will be preserved.
Like .str_cookies, but decodes values and keys
Copy the request and environment object.
This only does a shallow copy, except of wsgi.input
Copies the body, in cases where it might be shared with another request object and that is not desired.
This copies the body in-place, either into a StringIO object or a temporary file.
Copies the request and environment object, but turning this request into a GET along the way. If this was a POST request (or any other verb) then it becomes GET, and the request body is thrown away.
Gets and sets the Date header (HTTP spec section 14.8). Converts it using HTTP date.
Read a request from a file-like object (it must implement .read(size) and .readline()).
It will read up to the end of the request, not the end of the file (unless the request is a POST or PUT and has no Content-Length, in that case, the entire file is read).
This reads the request as represented by str(req); it may not read every valid HTTP request properly.
Create a request from HTTP string. If the string contains extra data after the request, raise a ValueError.
Like .call_application(application), except returns a response object with .status, .headers, and .body attributes.
This will use self.ResponseClass to figure out the class of the response object to return.
All the request headers as a case-insensitive dictionary-like object.
Host name provided in HTTP_HOST, with fall-back to SERVER_NAME
The URL through the host (no path)
Gets and sets the SERVER_PROTOCOL key in the environment.
Gets and sets the If-Match header (HTTP spec section 14.24). Converts it as a Etag.
Gets and sets the If-Modified-Since header (HTTP spec section 14.25). Converts it using HTTP date.
Gets and sets the If-None-Match header (HTTP spec section 14.26). Converts it as a Etag.
Gets and sets the If-Range header (HTTP spec section 14.27). Converts it using IfRange object.
Gets and sets the If-Unmodified-Since header (HTTP spec section 14.28). Converts it using HTTP date.
webob.is_body_readable is a flag that tells us that we can read the input stream even though CONTENT_LENGTH is missing. This allows FakeCGIBody to work and can be used by servers to support chunked encoding in requests. For background see https://bitbucket.org/ianb/webob/issue/6
Gets and sets the webob.is_body_seekable key in the environment.
Is X-Requested-With header present and equal to XMLHttpRequest?
Note: this isn’t set by every XMLHttpRequest request, it is only set if you are using a Javascript library that sets it (or you set the header yourself manually). Currently Prototype and jQuery are known to set this header.
This forces environ['wsgi.input'] to be seekable. That means that, the content is copied into a StringIO or temporary file and flagged as seekable, so that it will not be unnecessarily copied again.
After calling this method the .body_file is always seeked to the start of file and .content_length is not None.
The choice to copy to StringIO is made from self.request_body_tempfile_limit
Create a tempfile to store big request body. This API is not stable yet. A ‘size’ argument might be added.
Gets and sets the Max-Forwards header (HTTP spec section 14.31). Converts it using int.
Gets and sets the REQUEST_METHOD key in the environment.
Like .str_params, but decodes values and keys
The path of the request, without host or query string
Gets and sets the PATH_INFO key in the environment.
Returns the next segment on PATH_INFO, or None if there is no next segment. Doesn’t modify the environment.
‘Pops’ off the next segment of PATH_INFO, pushing it onto SCRIPT_NAME, and returning the popped segment. Returns None if there is nothing left on PATH_INFO.
Does not return '' when there’s an empty segment (like /path//path); these segments are just ignored.
Optional pattern argument is a regexp to match the return value before returning. If there is no match, no changes are made to the request and None is returned.
The path of the request, without host but with query string
The URL including SCRIPT_NAME and PATH_INFO, but not QUERY_STRING
Gets and sets the Pragma header (HTTP spec section 14.32).
Gets and sets the QUERY_STRING key in the environment.
Gets and sets the Range header (HTTP spec section 14.35). Converts it using Range object.
Gets and sets the Referer header (HTTP spec section 14.36).
Gets and sets the Referer header (HTTP spec section 14.36).
Resolve other_url relative to the request URL.
If to_application is True, then resolve it relative to the URL with only SCRIPT_NAME
Gets and sets the REMOTE_ADDR key in the environment.
Gets and sets the REMOTE_USER key in the environment.
Remove headers that make the request conditional.
These headers can cause the response to be 304 Not Modified, which in some cases you may not want to be possible.
This does not remove headers like If-Match, which are used for conflict detection.
Gets and sets the wsgi.url_scheme key in the environment.
Gets and sets the SCRIPT_NAME key in the environment.
Gets and sets the SERVER_NAME key in the environment.
Gets and sets the SERVER_PORT key in the environment. Converts it using int.
Return a MultiDict containing all the variables from the QUERY_STRING.
Return a MultiDict containing all the variables from a form request. Returns an empty dict-like object for non-form requests.
Form requests are typically POST requests, however PUT requests with an appropriate Content-Type are also supported.
Return a plain dictionary of cookies as found in the request.
A dictionary-like object containing both the parameters from the query string and request body.
upath_property(‘PATH_INFO’)
The full request URL, including QUERY_STRING
Return any positional variables matched in the URL.
Takes values from environ['wsgiorg.routing_args']. Systems like routes set this value.
Return any named variables matched in the URL.
Takes values from environ['wsgiorg.routing_args']. Systems like routes set this value.
upath_property(‘SCRIPT_NAME’)
Gets and sets the User-Agent header (HTTP spec section 14.43).
Represents a WSGI response
alias of Request
Gets and sets the Accept-Ranges header (HTTP spec section 14.5).
Gets and sets the Age header (HTTP spec section 14.6). Converts it using int.
Gets and sets the Allow header (HTTP spec section 14.7). Converts it using list.
Returns the app_iter of the response.
If body was set, this will create an app_iter from that body (a single-item list)
Return a new app_iter built from the response app_iter, that serves up only the given start:stop range.
The body of the response, as a str. This will read in the entire app_iter if necessary.
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.
Get/set/modify the Cache-Control header (HTTP spec section 14.9)
Get/set the charset (in the Content-Type)
Like the normal __call__ interface, but checks conditional headers:
Gets and sets the Content-Disposition header (HTTP spec section 19.5.1).
Gets and sets the Content-Encoding header (HTTP spec section 14.11).
Gets and sets the Content-Language header (HTTP spec section 14.12). Converts it using list.
Gets and sets the Content-Length header (HTTP spec section 14.17). Converts it using int.
Gets and sets the Content-Location header (HTTP spec section 14.14).
Gets and sets the Content-MD5 header (HTTP spec section 14.14).
Gets and sets the Content-Range header (HTTP spec section 14.16). Converts it using ContentRange object.
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 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)
Makes a copy of the response
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 the content with the given encoding (only gzip and identity are supported).
Get/set the request environ associated with this response, if any.
Gets and sets the ETag header (HTTP spec section 14.19). Converts it using Entity tag.
Gets and sets the Expires header (HTTP spec section 14.21). Converts it using HTTP date.
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 a Content-Length
The list of response headers
The headers in a dictionary-like object
Gets and sets the Last-Modified header (HTTP spec section 14.29). Converts it using HTTP date.
Gets and sets the Location header (HTTP spec section 14.30).
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 If set_content_md5 is True sets self.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.
Gets and sets the Pragma header (HTTP spec section 14.32).
Return the request associated with this response if any.
Gets and sets the Retry-After header (HTTP spec section 14.37). Converts it using HTTP date or delta seconds.
Gets and sets the Server header (HTTP spec section 14.38).
Set (add) a cookie for the response
The status string
The status as an integer
Get/set the unicode value of the body (using the charset of the Content-Type)
Deprecated alias for .text
Deprecated alias for .text
Unset a cookie with the given name (remove it from the response).
Gets and sets the Vary header (HTTP spec section 14.44). Converts it using list.
Gets and sets the WWW-Authenticate header (HTTP spec section 14.47). Converts it using parse_auth and serialize_auth.
Wraps an app_iter, returning just a range of bytes
Parses a variety of Accept-* headers.
These headers generally take the form of:
value1; q=0.5, value2; q=0
Where the q parameter is optional. In theory other parameters exists, but this ignores them.
Represents a generic Accept-* style header.
This object should not be modified. To add items you can use accept_obj + 'accept_thing' to get a new object
Returns the best match in the sequence of offered types.
The sequence can be a simple sequence, or you can have (match, server_quality) items in the sequence. If you have these tuples then the client quality is multiplied by the server_quality to get a total. If two matches have equal weight, then the one that shows up first in the offers list will be returned.
But among matches with the same quality the match to a more specific requested type will be chosen. For example a match to text/* trumps /.
default_match (default None) is returned if there is no intersection.
Return all the matches in order of quality, with fallback (if given) at the end.
DEPRECATED Returns the first allowed offered type. Ignores quality. Returns the first offered type if nothing else matches; or if you include None at the end of the match list then that will be returned.
Parse Accept-* style header.
Return iterator of (value, quality) pairs. quality defaults to 1.
Return the quality of the given offer. Returns None if there is no match (not 0).
Represents the Accept header, which is a list of mimetypes.
This class knows about mime wildcards, like image/*
Returns true if any HTML-like type is accepted
Returns true if any HTML-like type is accepted
Represents the Cache-Control header.
By giving a type of 'request' or 'response' you can control what attributes are allowed (some Cache-Control values only apply to requests or responses).
Returns a copy of this object.
Parse the header, returning a CacheControl object.
The object is bound to the request or response object updates_to, if that is given.
alias of UpdateDict
Represents an ETag request. Supports containment to see if an ETag matches. You can also use etag_matcher.weak_contains(etag) to allow weak ETags to match (allowable for conditional GET requests, but not ranges or other methods).
Parse this from a header value
HTML-escape a string or object
This converts any non-string objects passed into it to strings (actually, using unicode()). All values returned are non-unicode strings (using &#num; entities for all non-ASCII characters).
None is treated specially, and returns the empty string.
Dictionary view on the response headerlist. Keys are normalized for case and whitespace.
An object that represents the headers as present in a WSGI environment.
This object is a wrapper (with no internal state) for a WSGI request object, representing the CGI-style HTTP_* keys as a dictionary. Because a CGI environment can only hold one value for each key, this dictionary is single-valued (unlike outgoing headers).
Gives a multi-value dictionary object (MultiDict) plus several wrappers
An ordered dictionary that can have multiple values for each key. Adds the methods getall, getone, mixed and extend and add to the normal dictionary interface.
Add the key and value, not overwriting any previous value.
Returns a dictionary where each key is associated with a list of values.
Create a dict from a cgi.FieldStorage instance
Return a list of all values matching the key (may be an empty list)
Get one value matching the key, raising a KeyError if multiple values were found.
Returns a dictionary where the values are either single values, or a list of values when a key/value appears more than once in this dictionary. This is similar to the kind of dictionary often used to represent the variables in a web request.
Create a dict that is a view on the given list
A MultiDict wrapper that decodes returned values to unicode on the fly. Decoding is not applied to assigned values.
The key/value contents are assumed to be str/strs or str/FieldStorages (as is returned by the paste.request.parse_ functions).
Can optionally also decode keys when the decode_keys argument is True.
FieldStorage instances are cloned, and the clone’s filename variable is decoded. Its name variable is decoded when decode_keys is enabled.
Add the key and value, not overwriting any previous value.
Returns a dictionary where each key is associated with a list of values.
Return a list of all values matching the key (may be an empty list)
Get one value matching the key, raising a KeyError if multiple values were found.
Returns a dictionary where the values are either single values, or a list of values when a key/value appears more than once in this dictionary. This is similar to the kind of dictionary often used to represent the variables in a web request.
Wraps several MultiDict objects, treating it as one large MultiDict
Represents no variables; used when no variables are applicable.
This is read-only
Dict that has a callback on all updates