comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/email/mime/image.py @ 68:5028fdace37b

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