Helper function to format and quote a single header. Useful for single headers that are composed of multiple items. E.g., 'Content-Disposition' fields. :param header_parts: A sequence of (k, v) tuples or a :class:`dict` of (k, v) to format a
(
self,
header_parts: (
dict[str, _TYPE_FIELD_VALUE | None]
| typing.Sequence[tuple[str, _TYPE_FIELD_VALUE | None]]
),
)
| 258 | return self.header_formatter(name, value) |
| 259 | |
| 260 | def _render_parts( |
| 261 | self, |
| 262 | header_parts: ( |
| 263 | dict[str, _TYPE_FIELD_VALUE | None] |
| 264 | | typing.Sequence[tuple[str, _TYPE_FIELD_VALUE | None]] |
| 265 | ), |
| 266 | ) -> str: |
| 267 | """ |
| 268 | Helper function to format and quote a single header. |
| 269 | |
| 270 | Useful for single headers that are composed of multiple items. E.g., |
| 271 | 'Content-Disposition' fields. |
| 272 | |
| 273 | :param header_parts: |
| 274 | A sequence of (k, v) tuples or a :class:`dict` of (k, v) to format |
| 275 | as `k1="v1"; k2="v2"; ...`. |
| 276 | """ |
| 277 | iterable: typing.Iterable[tuple[str, _TYPE_FIELD_VALUE | None]] |
| 278 | |
| 279 | parts = [] |
| 280 | if isinstance(header_parts, dict): |
| 281 | iterable = header_parts.items() |
| 282 | else: |
| 283 | iterable = header_parts |
| 284 | |
| 285 | for name, value in iterable: |
| 286 | if value is not None: |
| 287 | parts.append(self._render_part(name, value)) |
| 288 | |
| 289 | return "; ".join(parts) |
| 290 | |
| 291 | def render_headers(self) -> str: |
| 292 | """ |