HeaderMapping¶
collections.abc.MutableMapping
which supports duplicate, case-insentive keys.
New in version 0.4.0.
Classes:
Provides a |
-
class
HeaderMapping
[source]¶ Bases:
MutableMapping
[str
,~VT
]Provides a
MutableMapping
interface to a list of headers, such as those used in an email message.See also
MutableMapping
interface, which assumes there is exactly one occurrence of the header per mapping. Some headers do in fact appear multiple times, and for those headers you must use theget_all()
method to obtain all values for that key.Methods:
__contains__
(name)Returns whether
name
is in theHeaderMapping
.__delitem__
(name)Delete all occurrences of a header, if present.
__getitem__
(name)Get a header value.
__iter__
()Returns an iterator over the keys in the
HeaderMapping
.__len__
()Return the total number of keys, including duplicates.
__repr__
()Return a string representation of the
HeaderMapping
.__setitem__
(name, val)Set the value of a header.
get
(k[, default])Get a header value.
get_all
(k[, default])Return a list of all the values for the named field.
items
()Get all the message’s header fields and values.
keys
()Return a list of all the message’s header field names.
values
()Return a list of all the message’s header values.
-
__contains__
(name)[source]¶ Returns whether
name
is in theHeaderMapping
.
-
__delitem__
(name)[source]¶ Delete all occurrences of a header, if present.
Does not raise an exception if the header is missing.
- Parameters
name (
str
)
-
__getitem__
(name)[source]¶ Get a header value.
Note
If the header appears multiple times, exactly which occurrence gets returned is undefined. Use the
get_all()
method to get all values matching a header field name.
-
__iter__
()[source]¶ Returns an iterator over the keys in the
HeaderMapping
.
-
__repr__
()[source]¶ Return a string representation of the
HeaderMapping
.New in version 0.4.1.
- Return type
-
get
(k, default=None)[source]¶ Get a header value.
Like
__getitem__()
, but returnsdefault
instead ofNone
when the field is missing.
-
get_all
(k, default=None)[source]¶ Return a list of all the values for the named field.
These will be sorted in the order they appeared in the original message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list.
If no such fields exist,
default
is returned.
-
items
()[source]¶ Get all the message’s header fields and values.
These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list.
-