/usr/share/doc/python3-docs/html/_sources/library
NameSizeModeActions
2to3.rst.txt158980644editdlrm
abc.rst.txt118050644editdlrm
aifc.rst.txt75030644editdlrm
allos.rst.txt6780644editdlrm
archiving.rst.txt4400644editdlrm
argparse.rst.txt774800644editdlrm
array.rst.txt108120644editdlrm
ast.rst.txt101590644editdlrm
asynchat.rst.txt85280644editdlrm
asyncio-dev.rst.txt133980644editdlrm
asyncio-eventloop.rst.txt337010644editdlrm
asyncio-eventloops.rst.txt76600644editdlrm
asyncio-protocol.rst.txt251700644editdlrm
asyncio-queue.rst.txt43280644editdlrm
asyncio-stream.rst.txt143630644editdlrm
asyncio-subprocess.rst.txt155440644editdlrm
asyncio-sync.rst.txt90780644editdlrm
asyncio-task.rst.txt254060644editdlrm
asyncio.rst.txt22720644editdlrm
asyncore.rst.txt136240644editdlrm
atexit.rst.txt36690644editdlrm
audioop.rst.txt107120644editdlrm
base64.rst.txt103710644editdlrm
bdb.rst.txt129850644editdlrm
binary.rst.txt6540644editdlrm
binascii.rst.txt65390644editdlrm
binhex.rst.txt17090644editdlrm
bisect.rst.txt53980644editdlrm
builtins.rst.txt14650644editdlrm
bz2.rst.txt88250644editdlrm
calendar.rst.txt109880644editdlrm
cgi.rst.txt226500644editdlrm
cgitb.rst.txt29180644editdlrm
chunk.rst.txt50940644editdlrm
cmath.rst.txt93260644editdlrm
cmd.rst.txt137950644editdlrm
code.rst.txt78170644editdlrm
codecs.rst.txt755640644editdlrm
codeop.rst.txt30210644editdlrm
collections.abc.rst.txt128610644editdlrm
collections.rst.txt460630644editdlrm
colorsys.rst.txt18200644editdlrm
compileall.rst.txt89750644editdlrm
concurrency.rst.txt6730644editdlrm
concurrent.futures.rst.txt169100644editdlrm
concurrent.rst.txt1710644editdlrm
configparser.rst.txt487560644editdlrm
constants.rst.txt33310644editdlrm
contextlib.rst.txt281750644editdlrm
copy.rst.txt33780644editdlrm
copyreg.rst.txt21820644editdlrm
crypt.rst.txt51220644editdlrm
crypto.rst.txt4110644editdlrm
csv.rst.txt199020644editdlrm
ctypes.rst.txt886130644editdlrm
curses.ascii.rst.txt89200644editdlrm
curses.panel.rst.txt27640644editdlrm
curses.rst.txt763970644editdlrm
custominterp.rst.txt5690644editdlrm
datatypes.rst.txt7510644editdlrm
datetime.rst.txt905240644editdlrm
dbm.rst.txt142930644editdlrm
debug.rst.txt4710644editdlrm
decimal.rst.txt748690644editdlrm
development.rst.txt7040644editdlrm
difflib.rst.txt298610644editdlrm
dis.rst.txt325670644editdlrm
distribution.rst.txt4520644editdlrm
distutils.rst.txt19740644editdlrm
doctest.rst.txt717430644editdlrm
dummy_threading.rst.txt7840644editdlrm
email.charset.rst.txt92930644editdlrm
email.compat32-message.rst.txt334930644editdlrm
email.contentmanager.rst.txt91120644editdlrm
email.encoders.rst.txt27150644editdlrm
email.errors.rst.txt47920644editdlrm
email.examples.rst.txt19150644editdlrm
email.generator.rst.txt136370644editdlrm
email.header.rst.txt91880644editdlrm
email.headerregistry.rst.txt179570644editdlrm
email.iterators.rst.txt27950644editdlrm
email.message.rst.txt330080644editdlrm
email.mime.rst.txt117210644editdlrm
email.parser.rst.txt140920644editdlrm
email.policy.rst.txt270220644editdlrm
email.rst.txt67850644editdlrm
email.util.rst.txt92140644editdlrm
ensurepip.rst.txt49870644editdlrm
enum.rst.txt327510644editdlrm
errno.rst.txt68110644editdlrm
exceptions.rst.txt255700644editdlrm
faulthandler.rst.txt61360644editdlrm
fcntl.rst.txt71520644editdlrm
filecmp.rst.txt56230644editdlrm
fileformats.rst.txt2870644editdlrm
fileinput.rst.txt80510644editdlrm
filesys.rst.txt9610644editdlrm
fnmatch.rst.txt31030644editdlrm
formatter.rst.txt132420644editdlrm
fpectl.rst.txt41800644editdlrm
fractions.rst.txt63640644editdlrm
frameworks.rst.txt3910644editdlrm
ftplib.rst.txt175520644editdlrm
functional.rst.txt3650644editdlrm
functions.rst.txt716210644editdlrm
functools.rst.txt185030644editdlrm
gc.rst.txt96940644editdlrm
getopt.rst.txt65570644editdlrm
getpass.rst.txt18820644editdlrm
gettext.rst.txt255880644editdlrm
glob.rst.txt35080644editdlrm
grp.rst.txt24170644editdlrm
gzip.rst.txt83010644editdlrm
hashlib.rst.txt265230644editdlrm
heapq.rst.txt134020644editdlrm
hmac.rst.txt40200644editdlrm
html.entities.rst.txt13190644editdlrm
html.parser.rst.txt112750644editdlrm
html.rst.txt13040644editdlrm
http.client.rst.txt188700644editdlrm
http.cookiejar.rst.txt278320644editdlrm
http.cookies.rst.txt86450644editdlrm
http.rst.txt70960644editdlrm
http.server.rst.txt176390644editdlrm
i18n.rst.txt4080644editdlrm
idle.rst.txt258340644editdlrm
imaplib.rst.txt203670644editdlrm
imghdr.rst.txt29380644editdlrm
imp.rst.txt155480644editdlrm
importlib.rst.txt535630644editdlrm
index.rst.txt22580644editdlrm
inspect.rst.txt539280644editdlrm
internet.rst.txt9920644editdlrm
intro.rst.txt26450644editdlrm
io.rst.txt403280644editdlrm
ipaddress.rst.txt323400644editdlrm
ipc.rst.txt6490644editdlrm
itertools.rst.txt384590644editdlrm
json.rst.txt278760644editdlrm
keyword.rst.txt6170644editdlrm
language.rst.txt5220644editdlrm
linecache.rst.txt24080644editdlrm
locale.rst.txt254700644editdlrm
logging.config.rst.txt338860644editdlrm
logging.handlers.rst.txt424970644editdlrm
logging.rst.txt604790644editdlrm
lzma.rst.txt173610644editdlrm
macpath.rst.txt7070644editdlrm
mailbox.rst.txt630550644editdlrm
mailcap.rst.txt36910644editdlrm
markup.rst.txt6790644editdlrm
marshal.rst.txt48550644editdlrm
math.rst.txt143750644editdlrm
mimetypes.rst.txt98390644editdlrm
misc.rst.txt2470644editdlrm
mm.rst.txt4310644editdlrm
mmap.rst.txt112320644editdlrm
modulefinder.rst.txt32400644editdlrm
modules.rst.txt3550644editdlrm
msilib.rst.txt186120644editdlrm
msvcrt.rst.txt43920644editdlrm
multiprocessing.rst.txt1044940644editdlrm
netdata.rst.txt3390644editdlrm
netrc.rst.txt30070644editdlrm
nis.rst.txt19930644editdlrm
nntplib.rst.txt218210644editdlrm
numbers.rst.txt80890644editdlrm
numeric.rst.txt6960644editdlrm
operator.rst.txt189890644editdlrm
optparse.rst.txt769960644editdlrm
os.path.rst.txt164190644editdlrm
os.rst.txt1375340644editdlrm
ossaudiodev.rst.txt178450644editdlrm
othergui.rst.txt28220644editdlrm
parser.rst.txt151480644editdlrm
pathlib.rst.txt300450644editdlrm
pdb.rst.txt194540644editdlrm
persistence.rst.txt5910644editdlrm
pickle.rst.txt374400644editdlrm
pickletools.rst.txt37290644editdlrm
pipes.rst.txt25570644editdlrm
pkgutil.rst.txt87300644editdlrm
platform.rst.txt96240644editdlrm
plistlib.rst.txt73980644editdlrm
poplib.rst.txt81970644editdlrm
posix.rst.txt36940644editdlrm
pprint.rst.txt142740644editdlrm
profile.rst.txt279690644editdlrm
pty.rst.txt31230644editdlrm
pwd.rst.txt27390644editdlrm
pyclbr.rst.txt32970644editdlrm
pydoc.rst.txt46880644editdlrm
pyexpat.rst.txt286200644editdlrm
python.rst.txt4750644editdlrm
py_compile.rst.txt38510644editdlrm
queue.rst.txt72680644editdlrm
quopri.rst.txt25710644editdlrm
random.rst.txt185030644editdlrm
re.rst.txt649360644editdlrm
readline.rst.txt119430644editdlrm
reprlib.rst.txt51620644editdlrm
resource.rst.txt122910644editdlrm
rlcompleter.rst.txt22940644editdlrm
runpy.rst.txt82850644editdlrm
sched.rst.txt48420644editdlrm
secrets.rst.txt59300644editdlrm
select.rst.txt281750644editdlrm
selectors.rst.txt89250644editdlrm
shelve.rst.txt83900644editdlrm
shlex.rst.txt164410644editdlrm
shutil.rst.txt260140644editdlrm
signal.rst.txt172180644editdlrm
site.rst.txt96280644editdlrm
smtpd.rst.txt108060644editdlrm
smtplib.rst.txt234390644editdlrm
sndhdr.rst.txt19940644editdlrm
socket.rst.txt682020644editdlrm
socketserver.rst.txt237120644editdlrm
spwd.rst.txt29580644editdlrm
sqlite3.rst.txt392150644editdlrm
ssl.rst.txt960210644editdlrm
stat.rst.txt98050644editdlrm
statistics.rst.txt153010644editdlrm
stdtypes.rst.txt1792400644editdlrm
string.rst.txt353740644editdlrm
stringprep.rst.txt42790644editdlrm
struct.rst.txt195810644editdlrm
subprocess.rst.txt457930644editdlrm
sunau.rst.txt73900644editdlrm
superseded.rst.txt2580644editdlrm
symbol.rst.txt9750644editdlrm
symtable.rst.txt49640644editdlrm
sys.rst.txt582730644editdlrm
sysconfig.rst.txt87490644editdlrm
syslog.rst.txt43020644editdlrm
tabnanny.rst.txt20070644editdlrm
tarfile.rst.txt317490644editdlrm
telnetlib.rst.txt78990644editdlrm
tempfile.rst.txt138570644editdlrm
termios.rst.txt37510644editdlrm
test.rst.txt257640644editdlrm
text.rst.txt5840644editdlrm
textwrap.rst.txt105190644editdlrm
threading.rst.txt392570644editdlrm
time.rst.txt329670644editdlrm
timeit.rst.txt130000644editdlrm
tk.rst.txt16390644editdlrm
tkinter.rst.txt330270644editdlrm
tkinter.scrolledtext.rst.txt12550644editdlrm
tkinter.tix.rst.txt226530644editdlrm
tkinter.ttk.rst.txt584890644editdlrm
token.rst.txt26070644editdlrm
tokenize.rst.txt100020644editdlrm
trace.rst.txt69140644editdlrm
traceback.rst.txt178540644editdlrm
tracemalloc.rst.txt220890644editdlrm
tty.rst.txt10970644editdlrm
turtle.rst.txt712210644editdlrm
types.rst.txt99990644editdlrm
typing.rst.txt343320644editdlrm
undoc.rst.txt7800644editdlrm
unicodedata.rst.txt57620644editdlrm
unittest.mock-examples.rst.txt462060644editdlrm
unittest.mock.rst.txt859910644editdlrm
unittest.rst.txt933040644editdlrm
unix.rst.txt4460644editdlrm
urllib.error.rst.txt21990644editdlrm
urllib.parse.rst.txt273320644editdlrm
urllib.request.rst.txt593600644editdlrm
urllib.robotparser.rst.txt29690644editdlrm
urllib.rst.txt4660644editdlrm
uu.rst.txt23870644editdlrm
uuid.rst.txt87600644editdlrm
venv.rst.txt206210644editdlrm
warnings.rst.txt201520644editdlrm
wave.rst.txt68700644editdlrm
weakref.rst.txt213280644editdlrm
webbrowser.rst.txt97830644editdlrm
windows.rst.txt2720644editdlrm
winreg.rst.txt240730644editdlrm
winsound.rst.txt51340644editdlrm
wsgiref.rst.txt330470644editdlrm
xdrlib.rst.txt80780644editdlrm
xml.dom.minidom.rst.txt101980644editdlrm
xml.dom.pulldom.rst.txt51860644editdlrm
xml.dom.rst.txt395070644editdlrm
xml.etree.elementtree.rst.txt438710644editdlrm
xml.rst.txt60710644editdlrm
xml.sax.handler.rst.txt153990644editdlrm
xml.sax.reader.rst.txt121330644editdlrm
xml.sax.rst.txt71590644editdlrm
xml.sax.utils.rst.txt39010644editdlrm
xmlrpc.client.rst.txt230710644editdlrm
xmlrpc.rst.txt4750644editdlrm
xmlrpc.server.rst.txt149900644editdlrm
zipapp.rst.txt173920644editdlrm
zipfile.rst.txt240050644editdlrm
zipimport.rst.txt58050644editdlrm
zlib.rst.txt139120644editdlrm
_dummy_thread.rst.txt7620644editdlrm
_thread.rst.txt68860644editdlrm
__future__.rst.txt52450644editdlrm
__main__.rst.txt9040644editdlrm
Edit: /usr/share/doc/python3-docs/html/_sources/library/email.headerregistry.rst.txt (17957B)
:mod:`email.headerregistry`: Custom Header Objects -------------------------------------------------- .. module:: email.headerregistry :synopsis: Automatic Parsing of headers based on the field name .. moduleauthor:: R. David Murray .. sectionauthor:: R. David Murray **Source code:** :source:`Lib/email/headerregistry.py` -------------- .. versionadded:: 3.6 [1]_ Headers are represented by customized subclasses of :class:`str`. The particular class used to represent a given header is determined by the :attr:`~email.policy.EmailPolicy.header_factory` of the :mod:`~email.policy` in effect when the headers are created. This section documents the particular ``header_factory`` implemented by the email package for handling :RFC:`5322` compliant email messages, which not only provides customized header objects for various header types, but also provides an extension mechanism for applications to add their own custom header types. When using any of the policy objects derived from :data:`~email.policy.EmailPolicy`, all headers are produced by :class:`.HeaderRegistry` and have :class:`.BaseHeader` as their last base class. Each header class has an additional base class that is determined by the type of the header. For example, many headers have the class :class:`.UnstructuredHeader` as their other base class. The specialized second class for a header is determined by the name of the header, using a lookup table stored in the :class:`.HeaderRegistry`. All of this is managed transparently for the typical application program, but interfaces are provided for modifying the default behavior for use by more complex applications. The sections below first document the header base classes and their attributes, followed by the API for modifying the behavior of :class:`.HeaderRegistry`, and finally the support classes used to represent the data parsed from structured headers. .. class:: BaseHeader(name, value) *name* and *value* are passed to ``BaseHeader`` from the :attr:`~email.policy.EmailPolicy.header_factory` call. The string value of any header object is the *value* fully decoded to unicode. This base class defines the following read-only properties: .. attribute:: name The name of the header (the portion of the field before the ':'). This is exactly the value passed in the :attr:`~email.policy.EmailPolicy.header_factory` call for *name*; that is, case is preserved. .. attribute:: defects A tuple of :exc:`~email.errors.HeaderDefect` instances reporting any RFC compliance problems found during parsing. The email package tries to be complete about detecting compliance issues. See the :mod:`~email.errors` module for a discussion of the types of defects that may be reported. .. attribute:: max_count The maximum number of headers of this type that can have the same ``name``. A value of ``None`` means unlimited. The ``BaseHeader`` value for this attribute is ``None``; it is expected that specialized header classes will override this value as needed. ``BaseHeader`` also provides the following method, which is called by the email library code and should not in general be called by application programs: .. method:: fold(*, policy) Return a string containing :attr:`~email.policy.Policy.linesep` characters as required to correctly fold the header according to *policy*. A :attr:`~email.policy.Policy.cte_type` of ``8bit`` will be treated as if it were ``7bit``, since headers may not contain arbitrary binary data. If :attr:`~email.policy.EmailPolicy.utf8` is ``False``, non-ASCII data will be :rfc:`2047` encoded. ``BaseHeader`` by itself cannot be used to create a header object. It defines a protocol that each specialized header cooperates with in order to produce the header object. Specifically, ``BaseHeader`` requires that the specialized class provide a :func:`classmethod` named ``parse``. This method is called as follows:: parse(string, kwds) ``kwds`` is a dictionary containing one pre-initialized key, ``defects``. ``defects`` is an empty list. The parse method should append any detected defects to this list. On return, the ``kwds`` dictionary *must* contain values for at least the keys ``decoded`` and ``defects``. ``decoded`` should be the string value for the header (that is, the header value fully decoded to unicode). The parse method should assume that *string* may contain content-transfer-encoded parts, but should correctly handle all valid unicode characters as well so that it can parse un-encoded header values. ``BaseHeader``'s ``__new__`` then creates the header instance, and calls its ``init`` method. The specialized class only needs to provide an ``init`` method if it wishes to set additional attributes beyond those provided by ``BaseHeader`` itself. Such an ``init`` method should look like this:: def init(self, *args, **kw): self._myattr = kw.pop('myattr') super().init(*args, **kw) That is, anything extra that the specialized class puts in to the ``kwds`` dictionary should be removed and handled, and the remaining contents of ``kw`` (and ``args``) passed to the ``BaseHeader`` ``init`` method. .. class:: UnstructuredHeader An "unstructured" header is the default type of header in :rfc:`5322`. Any header that does not have a specified syntax is treated as unstructured. The classic example of an unstructured header is the :mailheader:`Subject` header. In :rfc:`5322`, an unstructured header is a run of arbitrary text in the ASCII character set. :rfc:`2047`, however, has an :rfc:`5322` compatible mechanism for encoding non-ASCII text as ASCII characters within a header value. When a *value* containing encoded words is passed to the constructor, the ``UnstructuredHeader`` parser converts such encoded words into unicode, following the :rfc:`2047` rules for unstructured text. The parser uses heuristics to attempt to decode certain non-compliant encoded words. Defects are registered in such cases, as well as defects for issues such as invalid characters within the encoded words or the non-encoded text. This header type provides no additional attributes. .. class:: DateHeader :rfc:`5322` specifies a very specific format for dates within email headers. The ``DateHeader`` parser recognizes that date format, as well as recognizing a number of variant forms that are sometimes found "in the wild". This header type provides the following additional attributes: .. attribute:: datetime If the header value can be recognized as a valid date of one form or another, this attribute will contain a :class:`~datetime.datetime` instance representing that date. If the timezone of the input date is specified as ``-0000`` (indicating it is in UTC but contains no information about the source timezone), then :attr:`.datetime` will be a naive :class:`~datetime.datetime`. If a specific timezone offset is found (including `+0000`), then :attr:`.datetime` will contain an aware ``datetime`` that uses :class:`datetime.timezone` to record the timezone offset. The ``decoded`` value of the header is determined by formatting the ``datetime`` according to the :rfc:`5322` rules; that is, it is set to:: email.utils.format_datetime(self.datetime) When creating a ``DateHeader``, *value* may be :class:`~datetime.datetime` instance. This means, for example, that the following code is valid and does what one would expect:: msg['Date'] = datetime(2011, 7, 15, 21) Because this is a naive ``datetime`` it will be interpreted as a UTC timestamp, and the resulting value will have a timezone of ``-0000``. Much more useful is to use the :func:`~email.utils.localtime` function from the :mod:`~email.utils` module:: msg['Date'] = utils.localtime() This example sets the date header to the current time and date using the current timezone offset. .. class:: AddressHeader Address headers are one of the most complex structured header types. The ``AddressHeader`` class provides a generic interface to any address header. This header type provides the following additional attributes: .. attribute:: groups A tuple of :class:`.Group` objects encoding the addresses and groups found in the header value. Addresses that are not part of a group are represented in this list as single-address ``Groups`` whose :attr:`~.Group.display_name` is ``None``. .. attribute:: addresses A tuple of :class:`.Address` objects encoding all of the individual addresses from the header value. If the header value contains any groups, the individual addresses from the group are included in the list at the point where the group occurs in the value (that is, the list of addresses is "flattened" into a one dimensional list). The ``decoded`` value of the header will have all encoded words decoded to unicode. :class:`~encodings.idna` encoded domain names are also decoded to unicode. The ``decoded`` value is set by :attr:`~str.join`\ ing the :class:`str` value of the elements of the ``groups`` attribute with ``', '``. A list of :class:`.Address` and :class:`.Group` objects in any combination may be used to set the value of an address header. ``Group`` objects whose ``display_name`` is ``None`` will be interpreted as single addresses, which allows an address list to be copied with groups intact by using the list obtained from the ``groups`` attribute of the source header. .. class:: SingleAddressHeader A subclass of :class:`.AddressHeader` that adds one additional attribute: .. attribute:: address The single address encoded by the header value. If the header value actually contains more than one address (which would be a violation of the RFC under the default :mod:`~email.policy`), accessing this attribute will result in a :exc:`ValueError`. Many of the above classes also have a ``Unique`` variant (for example, ``UniqueUnstructuredHeader``). The only difference is that in the ``Unique`` variant, :attr:`~.BaseHeader.max_count` is set to 1. .. class:: MIMEVersionHeader There is really only one valid value for the :mailheader:`MIME-Version` header, and that is ``1.0``. For future proofing, this header class supports other valid version numbers. If a version number has a valid value per :rfc:`2045`, then the header object will have non-``None`` values for the following attributes: .. attribute:: version The version number as a string, with any whitespace and/or comments removed. .. attribute:: major The major version number as an integer .. attribute:: minor The minor version number as an integer .. class:: ParameterizedMIMEHeader MIME headers all start with the prefix 'Content-'. Each specific header has a certain value, described under the class for that header. Some can also take a list of supplemental parameters, which have a common format. This class serves as a base for all the MIME headers that take parameters. .. attribute:: params A dictionary mapping parameter names to parameter values. .. class:: ContentTypeHeader A :class:`ParameterizedMIMEHeader` class that handles the :mailheader:`Content-Type` header. .. attribute:: content_type The content type string, in the form ``maintype/subtype``. .. attribute:: maintype .. attribute:: subtype .. class:: ContentDispositionHeader A :class:`ParameterizedMIMEHeader` class that handles the :mailheader:`Content-Disposition` header. .. attribute:: content-disposition ``inline`` and ``attachment`` are the only valid values in common use. .. class:: ContentTransferEncoding Handles the :mailheader:`Content-Transfer-Encoding` header. .. attribute:: cte Valid values are ``7bit``, ``8bit``, ``base64``, and ``quoted-printable``. See :rfc:`2045` for more information. .. class:: HeaderRegistry(base_class=BaseHeader, \ default_class=UnstructuredHeader, \ use_default_map=True) This is the factory used by :class:`~email.policy.EmailPolicy` by default. ``HeaderRegistry`` builds the class used to create a header instance dynamically, using *base_class* and a specialized class retrieved from a registry that it holds. When a given header name does not appear in the registry, the class specified by *default_class* is used as the specialized class. When *use_default_map* is ``True`` (the default), the standard mapping of header names to classes is copied in to the registry during initialization. *base_class* is always the last class in the generated class's ``__bases__`` list. The default mappings are: :subject: UniqueUnstructuredHeader :date: UniqueDateHeader :resent-date: DateHeader :orig-date: UniqueDateHeader :sender: UniqueSingleAddressHeader :resent-sender: SingleAddressHeader :to: UniqueAddressHeader :resent-to: AddressHeader :cc: UniqueAddressHeader :resent-cc: AddressHeader :from: UniqueAddressHeader :resent-from: AddressHeader :reply-to: UniqueAddressHeader ``HeaderRegistry`` has the following methods: .. method:: map_to_type(self, name, cls) *name* is the name of the header to be mapped. It will be converted to lower case in the registry. *cls* is the specialized class to be used, along with *base_class*, to create the class used to instantiate headers that match *name*. .. method:: __getitem__(name) Construct and return a class to handle creating a *name* header. .. method:: __call__(name, value) Retrieves the specialized header associated with *name* from the registry (using *default_class* if *name* does not appear in the registry) and composes it with *base_class* to produce a class, calls the constructed class's constructor, passing it the same argument list, and finally returns the class instance created thereby. The following classes are the classes used to represent data parsed from structured headers and can, in general, be used by an application program to construct structured values to assign to specific headers. .. class:: Address(display_name='', username='', domain='', addr_spec=None) The class used to represent an email address. The general form of an address is:: [display_name] or:: username@domain where each part must conform to specific syntax rules spelled out in :rfc:`5322`. As a convenience *addr_spec* can be specified instead of *username* and *domain*, in which case *username* and *domain* will be parsed from the *addr_spec*. An *addr_spec* must be a properly RFC quoted string; if it is not ``Address`` will raise an error. Unicode characters are allowed and will be property encoded when serialized. However, per the RFCs, unicode is *not* allowed in the username portion of the address. .. attribute:: display_name The display name portion of the address, if any, with all quoting removed. If the address does not have a display name, this attribute will be an empty string. .. attribute:: username The ``username`` portion of the address, with all quoting removed. .. attribute:: domain The ``domain`` portion of the address. .. attribute:: addr_spec The ``username@domain`` portion of the address, correctly quoted for use as a bare address (the second form shown above). This attribute is not mutable. .. method:: __str__() The ``str`` value of the object is the address quoted according to :rfc:`5322` rules, but with no Content Transfer Encoding of any non-ASCII characters. To support SMTP (:rfc:`5321`), ``Address`` handles one special case: if ``username`` and ``domain`` are both the empty string (or ``None``), then the string value of the ``Address`` is ``<>``. .. class:: Group(display_name=None, addresses=None) The class used to represent an address group. The general form of an address group is:: display_name: [address-list]; As a convenience for processing lists of addresses that consist of a mixture of groups and single addresses, a ``Group`` may also be used to represent single addresses that are not part of a group by setting *display_name* to ``None`` and providing a list of the single address as *addresses*. .. attribute:: display_name The ``display_name`` of the group. If it is ``None`` and there is exactly one ``Address`` in ``addresses``, then the ``Group`` represents a single address that is not in a group. .. attribute:: addresses A possibly empty tuple of :class:`.Address` objects representing the addresses in the group. .. method:: __str__() The ``str`` value of a ``Group`` is formatted according to :rfc:`5322`, but with no Content Transfer Encoding of any non-ASCII characters. If ``display_name`` is none and there is a single ``Address`` in the ``addresses`` list, the ``str`` value will be the same as the ``str`` of that single ``Address``. .. rubric:: Footnotes .. [1] Originally added in 3.3 as a :term:`provisional module `