A dictionary-like object for storing MIME-like message headers.
Headers are stored in the object via regular dictionary interfaces.
They are retrieved via str(), repr() or self.terse(), which returns
a standard dict with duplicate headers merged into a comma-separated
list of values (even when it is not OK to do so).
The reason this class is needed is because the dictionary interface of
the Message class of the rfc822 and mimetools modules allows each new
header to overwrite a previously-stored header with the same key. Our
HeaderDict class stores its header values as lists, so no data is lost.
Its keys are accessed case-insensitively and are always written out
in a normalized format where usually only the first letter of each
hyphen-separated word is capitalized. (Content-MD5, ETag, TE, and
WWW-Authenticate are exceptions to this rule). The str(obj)
representation prints the headers in a convenient format suitable for
printing in a MIME-like message.
Methods
# case-insensitive 'key in dict' lookup
# case-insensitive deletion: removes entire list
# case-insensitive lookup
# case-insensitive 'for key in dict' iteration
# case-insensitive storage; appends to a list
get(
self,
key,
default=None)
# retrieve a value or default if no such key
# case-insensitive key lookup
# case-insensitive 'for key in dict' iteration
# return a terse dictionary (duplicate headers in one comma-separated string)
# this is for compatibility with functions want to read the header values as
# a single string rather than as a python list of strings
# append another dict or HeaderDict
Methods inherited from class __builtin__.dict
__cmp__, __eq__, __ge__, __getattribute__, __gt__, __hash__, __le__, __len__, __lt__, __ne__, __new__, clear, copy, items, itervalues, pop, popitem, setdefault, values
Methods inherited from class __builtin__.object
__delattr__, __reduce__, __reduce_ex__, __setattr__
Fields
__dict__ = <attribute '__dict__' of 'HeaderDict' objects>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'HeaderDict' objects>
list of weak references to the object (if defined)
forceCaps = {'content-md5': 'Content-MD5', 'etag': 'ETag', 'te': 'TE', 'www-authenticate': 'WWW-Authenticate'}
Fields
Fields