(self, subtype, disallowed_subtypes, boundary)
| 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) |
no test coverage detected