2005-03-06 03:53:55

MIME message header storage for HTTP

Copyright 2005 Fourthought, Inc. (USA). Detailed license and copyright information: http://4suite.org/COPYRIGHT Project home, documentation, distributions: http://4suite.org/

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.

# case-insensitive 'key in dict' lookup

# case-insensitive deletion: removes entire list

# case-insensitive lookup

# case-insensitive 'for key in dict' iteration

# string representations

# case-insensitive storage; appends to a list

# retrieve a value or default if no such key

# case-insensitive key lookup

# case-insensitive 'for key in dict' iteration

# normalize key names

# 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

dictionary for instance variables (if defined)

<attribute '__dict__' of 'HeaderDict' objects>

list of weak references to the object (if defined)

<attribute '__weakref__' of 'HeaderDict' objects>
{'content-md5': 'Content-MD5', 'etag': 'ETag', 'te': 'TE', 'www-authenticate': 'WWW-Authenticate'}
_Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 4096)