Package circuits :: Package web :: Module headers :: Class Headers

Class Headers

object --+    
         |    
      dict --+
             |
            Headers

Manage a collection of HTTP response headers

Instance Methods
new empty dictionary

__init__(self, headers=[])
x.__init__(...) initializes x; see help(type(x)) for signature
 
__len__(self)
Return the total number of headers, including duplicates.
 
__setitem__(self, name, val)
Set the value of a header.
 
__delitem__(self, name)
Delete all occurrences of a header, if present.
 
__getitem__(self, name)
Get the first header value for 'name'
v, remove specified key and return the corresponding value
pop(self, name, default=None)
If key is not found, d is returned if given, otherwise KeyError is raised
True if D has a key k, else False
has_key(self, name)
Return true if the message contains the header.
True if D has a key k, else False
__contains__(self, name)
Return true if the message contains the header.
 
get_all(self, name)
Return a list of all the values for the named field.
D[k] if k in D, else d
get(self, name, default=None)
Get the first header value for 'name', or return 'default'
list of D's keys
keys(self)
Return a list of all the header field names.
list of D's values
values(self)
Return a list of all header values.
list of D's (key, value) pairs, as 2-tuples
items(self)
Get all the header fields and values.
 
__repr__(self)
repr(x)
 
__str__(self)
str() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.
D.get(k,d), also set D[k]=d if k not in D
setdefault(self, name, value)
Return first matching header value for 'name', or 'value'
 
add_header(self, _name, _value, **_params)
Extended header setting.
 
elements(self, key)
Return a list of HeaderElements for the given header (or None).

Inherited from dict: __cmp__, __eq__, __ge__, __getattribute__, __gt__, __iter__, __le__, __lt__, __ne__, __new__, __sizeof__, clear, copy, fromkeys, iteritems, iterkeys, itervalues, popitem, update, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables

Inherited from dict: __hash__

Properties

Inherited from object: __class__

Method Details

__init__(self, headers=[])
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Returns:
new empty dictionary

Overrides: object.__init__
(inherited documentation)

__len__(self)
(Length operator)

 

Return the total number of headers, including duplicates.

Overrides: dict.__len__

__setitem__(self, name, val)
(Index assignment operator)

 

Set the value of a header.

Overrides: dict.__setitem__

__delitem__(self, name)
(Index deletion operator)

 

Delete all occurrences of a header, if present.

Does *not* raise an exception if the header is missing.

Overrides: dict.__delitem__

__getitem__(self, name)
(Indexing operator)

 

Get the first header value for 'name'

Return None if the header is missing instead of raising an exception.

Note that if the header appeared multiple times, the first exactly which occurrance gets returned is undefined. Use getall() to get all the values matching a header field name.

Overrides: dict.__getitem__

pop(self, name, default=None)

 

If key is not found, d is returned if given, otherwise KeyError is raised

Returns: v, remove specified key and return the corresponding value
Overrides: dict.pop
(inherited documentation)

has_key(self, name)

 

Return true if the message contains the header.

Returns: True if D has a key k, else False
Overrides: dict.has_key

__contains__(self, name)
(In operator)

 

Return true if the message contains the header.

Returns: True if D has a key k, else False
Overrides: dict.__contains__

get_all(self, name)

 

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

These will be sorted in the order they appeared in the original header list or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. If no fields exist with the given name, returns an empty list.

get(self, name, default=None)

 

Get the first header value for 'name', or return 'default'

Returns: D[k] if k in D, else d
Overrides: dict.get

keys(self)

 

Return a list of all the header field names.

These will be sorted in the order they appeared in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list.

Returns: list of D's keys
Overrides: dict.keys

values(self)

 

Return a list of all header values.

These will be sorted in the order they appeared in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list.

Returns: list of D's values
Overrides: dict.values

items(self)

 

Get all the header fields and values.

These will be sorted in the order they were in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list.

Returns: list of D's (key, value) pairs, as 2-tuples
Overrides: dict.items

__repr__(self)
(Representation operator)

 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

 

str() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.

Overrides: object.__str__

setdefault(self, name, value)

 

Return first matching header value for 'name', or 'value'

If there is no header named 'name', add a new header with name 'name' and value 'value'.

Returns: D.get(k,d), also set D[k]=d if k not in D
Overrides: dict.setdefault

add_header(self, _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.

Example:

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.