1 # Copyright (C) 2001-2004 Python Software Foundation
3 # Contact: email-sig@python.org
5 """Class representing image/* type MIME documents."""
9 from email
import Errors
10 from email
import Encoders
11 from email
.MIMENonMultipart
import MIMENonMultipart
15 class MIMEImage(MIMENonMultipart
):
16 """Class for generating image/* type MIME documents."""
18 def __init__(self
, _imagedata
, _subtype
=None,
19 _encoder
=Encoders
.encode_base64
, **_params
):
20 """Create an image/* type MIME document.
22 _imagedata is a string containing the raw image data. If this data
23 can be decoded by the standard Python `imghdr' module, then the
24 subtype will be automatically included in the Content-Type header.
25 Otherwise, you can specify the specific image subtype via the _subtype
28 _encoder is a function which will perform the actual encoding for
29 transport of the image data. It takes one argument, which is this
30 Image instance. It should use get_payload() and set_payload() to
31 change the payload to the encoded form. It should also add any
32 Content-Transfer-Encoding or other headers to the message as
33 necessary. The default encoding is Base64.
35 Any additional keyword arguments are passed to the base class
36 constructor, which turns them into parameters on the Content-Type
40 _subtype
= imghdr
.what(None, _imagedata
)
42 raise TypeError('Could not guess image MIME subtype')
43 MIMENonMultipart
.__init
__(self
, 'image', _subtype
, **_params
)
44 self
.set_payload(_imagedata
)