webob
– Request/Response objects¶
Headers¶
Accept-*¶
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.
-
class
webob.acceptparse.
Accept
(header_value)¶ 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-
best_match
(offers, default_match=None)¶ 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.
-
static
parse
(value)¶ Parse
Accept-*
style header.Return iterator of
(value, quality)
pairs.quality
defaults to 1.
-
quality
(offer, modifier=1)¶ Return the quality of the given offer. Returns None if there is no match (not 0).
-
-
class
webob.acceptparse.
MIMEAccept
(header_value)¶ Represents the
Accept
header, which is a list of mimetypes.This class knows about mime wildcards, like
image/*
-
accept_html
()¶ Returns true if any HTML-like type is accepted
-
accepts_html
¶ Returns true if any HTML-like type is accepted
-
static
parse
(value)¶ Parse
Accept-*
style header.Return iterator of
(value, quality)
pairs.quality
defaults to 1.
-
Cache-Control¶
-
class
webob.cachecontrol.
CacheControl
(properties, type)¶ 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).-
copy
()¶ Returns a copy of this object.
-
classmethod
parse
(header, updates_to=None, type=None)¶ Parse the header, returning a CacheControl object.
The object is bound to the request or response object
updates_to
, if that is given.
-
update_dict
¶ alias of
UpdateDict
-
Misc Functions and Internals¶
-
webob.
html_escape
(s)¶ 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.
-
class
webob.headers.
ResponseHeaders
(*args, **kw)¶ Dictionary view on the response headerlist. Keys are normalized for case and whitespace.
-
dict_of_lists
()¶ Returns a dictionary where each key is associated with a list of values.
-
getall
(key)¶ Return a list of all values matching the key (may be an empty list)
-
mixed
()¶ 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.
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
-
class
webob.headers.
EnvironHeaders
(environ)¶ 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).
-
keys
() → a set-like object providing a view on D's keys¶
-
-
class
webob.cachecontrol.
UpdateDict
¶ Dict that has a callback on all updates
-
clear
() → None. Remove all items from D.¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-