webob — Request/Response objects

Headers

Accept-*

Parses a variety of Accept-* headers.

These headers generally take the form of:

  1. 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

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

class webob.byterange.Range(start, end)

Represents the Range header.

  • content_range(length)

    Works like range_for_length; returns None or a ContentRange object

    You can use it like:

    1. response.content_range = req.range.content_range(response.content_length)

    Though it’s still up to you to actually serve that content range!

  • classmethod parse(header)

    Parse the header; may return None if header is invalid

  • range_for_length(length)

    If there is only one range, and if it is satisfiable by the given length, then return a (start, end) non-inclusive range of bytes to serve. Otherwise return None

class webob.byterange.ContentRange(start, stop, length)

Represents the Content-Range header

This header is start-stop/length, where start-stop and length can be * (represented as None in the attributes).

  • classmethod parse(value)

    Parse the header. May return None if it cannot parse.

class webob.etag.IfRange(etag)

  • classmethod parse(value)

    Parse this from a header value.

ETag

class webob.etag.ETagMatcher(etags)

  • classmethod parse(value, strong=True)

    Parse this from a header value

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.

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).

class webob.cachecontrol.UpdateDict

Dict that has a callback on all updates