MCPcopy Index your code
hub / github.com/RustPython/RustPython / _handle_multipart

Method _handle_multipart

Lib/email/generator.py:268–324  ·  view source on GitHub ↗
(self, msg)

Source from the content-addressed store, hash-verified

266 _writeBody = _handle_text
267
268 def _handle_multipart(self, msg):
269 # The trick here is to write out each part separately, merge them all
270 # together, and then make sure that the boundary we've chosen isn't
271 # present in the payload.
272 msgtexts = []
273 subparts = msg.get_payload()
274 if subparts is None:
275 subparts = []
276 elif isinstance(subparts, str):
277 # e.g. a non-strict parse of a message with no starting boundary.
278 self.write(subparts)
279 return
280 elif not isinstance(subparts, list):
281 # Scalar payload
282 subparts = [subparts]
283 for part in subparts:
284 s = self._new_buffer()
285 g = self.clone(s)
286 g.flatten(part, unixfrom=False, linesep=self._NL)
287 msgtexts.append(s.getvalue())
288 # BAW: What about boundaries that are wrapped in double-quotes?
289 boundary = msg.get_boundary()
290 if not boundary:
291 # Create a boundary that doesn't appear in any of the
292 # message texts.
293 alltext = self._encoded_NL.join(msgtexts)
294 boundary = self._make_boundary(alltext)
295 msg.set_boundary(boundary)
296 # If there's a preamble, write it out, with a trailing CRLF
297 if msg.preamble is not None:
298 if self._mangle_from_:
299 preamble = fcre.sub('>From ', msg.preamble)
300 else:
301 preamble = msg.preamble
302 self._write_lines(preamble)
303 self.write(self._NL)
304 # dash-boundary transport-padding CRLF
305 self.write('--' + boundary + self._NL)
306 # body-part
307 if msgtexts:
308 self._fp.write(msgtexts.pop(0))
309 # *encapsulation
310 # --> delimiter transport-padding
311 # --> CRLF body-part
312 for body_part in msgtexts:
313 # delimiter transport-padding CRLF
314 self.write(self._NL + '--' + boundary + self._NL)
315 # body-part
316 self._fp.write(body_part)
317 # close-delimiter transport-padding
318 self.write(self._NL + '--' + boundary + '--' + self._NL)
319 if msg.epilogue is not None:
320 if self._mangle_from_:
321 epilogue = fcre.sub('>From ', msg.epilogue)
322 else:
323 epilogue = msg.epilogue
324 self._write_lines(epilogue)
325

Callers 1

Calls 15

writeMethod · 0.95
_new_bufferMethod · 0.95
cloneMethod · 0.95
_make_boundaryMethod · 0.95
_write_linesMethod · 0.95
isinstanceFunction · 0.85
get_payloadMethod · 0.80
get_boundaryMethod · 0.80
set_boundaryMethod · 0.80
flattenMethod · 0.45
appendMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected