Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sendgrid/helpers/mail/attachment.py: 28%
75 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from .file_content import FileContent
2from .file_type import FileType
3from .file_name import FileName
4from .disposition import Disposition
5from .content_id import ContentId
8class Attachment(object):
9 """An attachment to be included with an email."""
11 def __init__(
12 self,
13 file_content=None,
14 file_name=None,
15 file_type=None,
16 disposition=None,
17 content_id=None):
18 """Create an Attachment
20 :param file_content: The Base64 encoded content of the attachment
21 :type file_content: FileContent, string
22 :param file_name: The filename of the attachment
23 :type file_name: FileName, string
24 :param file_type: The MIME type of the content you are attaching
25 :type file_type FileType, string, optional
26 :param disposition: The content-disposition of the attachment,
27 specifying display style. Specifies how you
28 would like the attachment to be displayed.
29 - "inline" results in the attached file being
30 displayed automatically within the message.
31 - "attachment" results in the attached file
32 requiring some action to display (e.g. opening
33 or downloading the file).
34 If unspecified, "attachment" is used. Must be one
35 of the two choices.
36 :type disposition: Disposition, string, optional
37 :param content_id: The content id for the attachment.
38 This is used when the Disposition is set to
39 "inline" and the attachment is an image, allowing
40 the file to be displayed within the email body.
41 :type content_id: ContentId, string, optional
42 """
43 self._file_content = None
44 self._file_type = None
45 self._file_name = None
46 self._disposition = None
47 self._content_id = None
49 if file_content is not None:
50 self.file_content = file_content
52 if file_type is not None:
53 self.file_type = file_type
55 if file_name is not None:
56 self.file_name = file_name
58 if disposition is not None:
59 self.disposition = disposition
61 if content_id is not None:
62 self.content_id = content_id
64 @property
65 def file_content(self):
66 """The Base64 encoded content of the attachment.
68 :rtype: FileContent
69 """
70 return self._file_content
72 @file_content.setter
73 def file_content(self, value):
74 """The Base64 encoded content of the attachment
76 :param value: The Base64 encoded content of the attachment
77 :type value: FileContent, string
78 """
79 if isinstance(value, FileContent):
80 self._file_content = value
81 else:
82 self._file_content = FileContent(value)
84 @property
85 def file_name(self):
86 """The file name of the attachment.
88 :rtype: FileName
89 """
90 return self._file_name
92 @file_name.setter
93 def file_name(self, value):
94 """The filename of the attachment
96 :param file_name: The filename of the attachment
97 :type file_name: FileName, string
98 """
99 if isinstance(value, FileName):
100 self._file_name = value
101 else:
102 self._file_name = FileName(value)
104 @property
105 def file_type(self):
106 """The MIME type of the content you are attaching.
108 :rtype: FileType
109 """
110 return self._file_type
112 @file_type.setter
113 def file_type(self, value):
114 """The MIME type of the content you are attaching
116 :param file_type: The MIME type of the content you are attaching
117 :type file_type FileType, string, optional
118 """
119 if isinstance(value, FileType):
120 self._file_type = value
121 else:
122 self._file_type = FileType(value)
124 @property
125 def disposition(self):
126 """The content-disposition of the attachment, specifying display style.
128 Specifies how you would like the attachment to be displayed.
129 - "inline" results in the attached file being displayed automatically
130 within the message.
131 - "attachment" results in the attached file requiring some action to
132 display (e.g. opening or downloading the file).
133 If unspecified, "attachment" is used. Must be one of the two choices.
135 :rtype: Disposition
136 """
137 return self._disposition
139 @disposition.setter
140 def disposition(self, value):
141 """The content-disposition of the attachment, specifying display style.
143 Specifies how you would like the attachment to be displayed.
144 - "inline" results in the attached file being displayed automatically
145 within the message.
146 - "attachment" results in the attached file requiring some action to
147 display (e.g. opening or downloading the file).
148 If unspecified, "attachment" is used. Must be one of the two choices.
150 :param disposition: The content-disposition of the attachment,
151 specifying display style. Specifies how you would
152 like the attachment to be displayed.
153 - "inline" results in the attached file being
154 displayed automatically within the message.
155 - "attachment" results in the attached file
156 requiring some action to display (e.g. opening
157 or downloading the file).
158 If unspecified, "attachment" is used. Must be one
159 of the two choices.
160 :type disposition: Disposition, string, optional
161 """
162 if isinstance(value, Disposition):
163 self._disposition = value
164 else:
165 self._disposition = Disposition(value)
167 @property
168 def content_id(self):
169 """The content id for the attachment.
171 This is used when the disposition is set to "inline" and the attachment
172 is an image, allowing the file to be displayed within the email body.
174 :rtype: string
175 """
176 return self._content_id
178 @content_id.setter
179 def content_id(self, value):
180 """The content id for the attachment.
182 This is used when the disposition is set to "inline" and the attachment
183 is an image, allowing the file to be displayed within the email body.
185 :param content_id: The content id for the attachment.
186 This is used when the Disposition is set to "inline"
187 and the attachment is an image, allowing the file to
188 be displayed within the email body.
189 :type content_id: ContentId, string, optional
190 """
191 if isinstance(value, ContentId):
192 self._content_id = value
193 else:
194 self._content_id = ContentId(value)
196 def get(self):
197 """
198 Get a JSON-ready representation of this Attachment.
200 :returns: This Attachment, ready for use in a request body.
201 :rtype: dict
202 """
203 attachment = {}
204 if self.file_content is not None:
205 attachment["content"] = self.file_content.get()
207 if self.file_type is not None:
208 attachment["type"] = self.file_type.get()
210 if self.file_name is not None:
211 attachment["filename"] = self.file_name.get()
213 if self.disposition is not None:
214 attachment["disposition"] = self.disposition.get()
216 if self.content_id is not None:
217 attachment["content_id"] = self.content_id.get()
218 return attachment