MCPcopy Index your code
hub / github.com/python/cpython / _make_multipart

Method _make_multipart

Lib/email/message.py:1147–1172  ·  view source on GitHub ↗
(self, subtype, disallowed_subtypes, boundary)

Source from the content-addressed store, hash-verified

1145 content_manager.set_content(self, *args, **kw)
1146
1147 def _make_multipart(self, subtype, disallowed_subtypes, boundary):
1148 if self.get_content_maintype() == 'multipart':
1149 existing_subtype = self.get_content_subtype()
1150 disallowed_subtypes = disallowed_subtypes + (subtype,)
1151 if existing_subtype in disallowed_subtypes:
1152 raise ValueError("Cannot convert {} to {}".format(
1153 existing_subtype, subtype))
1154 keep_headers = []
1155 part_headers = []
1156 for name, value in self._headers:
1157 if name.lower().startswith('content-'):
1158 part_headers.append((name, value))
1159 else:
1160 keep_headers.append((name, value))
1161 if part_headers:
1162 # There is existing content, move it to the first subpart.
1163 part = type(self)(policy=self.policy)
1164 part._headers = part_headers
1165 part._payload = self._payload
1166 self._payload = [part]
1167 else:
1168 self._payload = []
1169 self._headers = keep_headers
1170 self['Content-Type'] = 'multipart/' + subtype
1171 if boundary is not None:
1172 self.set_param('boundary', boundary)
1173
1174 def make_related(self, boundary=None):
1175 self._make_multipart('related', ('alternative', 'mixed'), boundary)

Callers 3

make_relatedMethod · 0.95
make_alternativeMethod · 0.95
make_mixedMethod · 0.95

Calls 7

get_content_maintypeMethod · 0.80
get_content_subtypeMethod · 0.80
set_paramMethod · 0.80
formatMethod · 0.45
startswithMethod · 0.45
lowerMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected