ยปCore Development>Code coverage>Lib/email/mime/image.py

Python code coverage for Lib/email/mime/image.py

#countcontent
1n/a# Copyright (C) 2001-2006 Python Software Foundation
2n/a# Author: Barry Warsaw
3n/a# Contact: email-sig@python.org
4n/a
5n/a"""Class representing image/* type MIME documents."""
6n/a
7n/a__all__ = ['MIMEImage']
8n/a
9n/aimport imghdr
10n/a
11n/afrom email import encoders
12n/afrom email.mime.nonmultipart import MIMENonMultipart
13n/a
14n/a
15n/a
16n/aclass MIMEImage(MIMENonMultipart):
17n/a """Class for generating image/* type MIME documents."""
18n/a
19n/a def __init__(self, _imagedata, _subtype=None,
20n/a _encoder=encoders.encode_base64, *, policy=None, **_params):
21n/a """Create an image/* type MIME document.
22n/a
23n/a _imagedata is a string containing the raw image data. If this data
24n/a can be decoded by the standard Python `imghdr' module, then the
25n/a subtype will be automatically included in the Content-Type header.
26n/a Otherwise, you can specify the specific image subtype via the _subtype
27n/a parameter.
28n/a
29n/a _encoder is a function which will perform the actual encoding for
30n/a transport of the image data. It takes one argument, which is this
31n/a Image instance. It should use get_payload() and set_payload() to
32n/a change the payload to the encoded form. It should also add any
33n/a Content-Transfer-Encoding or other headers to the message as
34n/a necessary. The default encoding is Base64.
35n/a
36n/a Any additional keyword arguments are passed to the base class
37n/a constructor, which turns them into parameters on the Content-Type
38n/a header.
39n/a """
40n/a if _subtype is None:
41n/a _subtype = imghdr.what(None, _imagedata)
42n/a if _subtype is None:
43n/a raise TypeError('Could not guess image MIME subtype')
44n/a MIMENonMultipart.__init__(self, 'image', _subtype, policy=policy,
45n/a **_params)
46n/a self.set_payload(_imagedata)
47n/a _encoder(self)