circuits.web.headers module

Headers Support

This module implements support for parsing and handling headers.

circuits.web.headers.header_elements(fieldname, fieldvalue)

Return a sorted HeaderElement list.

Returns a sorted HeaderElement list from a comma-separated header string.

class circuits.web.headers.HeaderElement(value, params=None)

Bases: object

An element (with parameters) from an HTTP header’s element list.

static parse(elementstr)

Transform ‘token;key=val’ to (‘token’, {‘key’: ‘val’}).

classmethod from_str(elementstr)

Construct an instance from a string of the form ‘token;key=val’.

class circuits.web.headers.AcceptElement(value, params=None)

Bases: circuits.web.headers.HeaderElement

An element (with parameters) from an Accept* header’s element list.

AcceptElement objects are comparable; the more-preferred object will be “less than” the less-preferred object. They are also therefore sortable; if you sort a list of AcceptElement objects, they will be listed in priority order; the most preferred value will be first. Yes, it should have been the other way around, but it’s too late to fix now.

classmethod from_str(elementstr)

The qvalue, or priority, of this value.

class circuits.web.headers.CaseInsensitiveDict(*args, **kwargs)

Bases: dict

A case-insensitive dict subclass.

Each key is changed on entry to str(key).title().

get(key, default=None)
classmethod fromkeys(seq, value=None)
setdefault(key, x=None)
pop(key, default=None)
class circuits.web.headers.Headers(*args, **kwargs)

Bases: circuits.web.headers.CaseInsensitiveDict


Return a sorted list of HeaderElements for the given header.


Return a list of all the values for the named field.

append(key, value)
add_header(_name, _value, **_params)

Extended header setting.

_name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key=”value” unless value is None, in which case only the key will be added.


h.add_header(‘content-disposition’, ‘attachment’, filename=’bud.gif’)

Note that unlike the corresponding ‘email.Message’ method, this does not handle ‘(charset, language, value)’ tuples: all values must be strings or None.

Previous topic

circuits.web.exceptions module

Next topic

circuits.web.http module

This Page