r""" Multipart response headers generator. ``` --{boundary}\r\n Content-Type: {content_type}\r\n Content-Range: bytes {start}-{end-1}/{max_size}\r\n \r\n ..........content...........\r\n --{boundary}\r\n Content-Type: {content_
(
self,
ranges: Sequence[tuple[int, int]],
boundary: str,
max_size: int,
content_type: str,
)
| 522 | return ranges |
| 523 | |
| 524 | def generate_multipart( |
| 525 | self, |
| 526 | ranges: Sequence[tuple[int, int]], |
| 527 | boundary: str, |
| 528 | max_size: int, |
| 529 | content_type: str, |
| 530 | ) -> tuple[int, Callable[[int, int], bytes]]: |
| 531 | r""" |
| 532 | Multipart response headers generator. |
| 533 | |
| 534 | ``` |
| 535 | --{boundary}\r\n |
| 536 | Content-Type: {content_type}\r\n |
| 537 | Content-Range: bytes {start}-{end-1}/{max_size}\r\n |
| 538 | \r\n |
| 539 | ..........content...........\r\n |
| 540 | --{boundary}\r\n |
| 541 | Content-Type: {content_type}\r\n |
| 542 | Content-Range: bytes {start}-{end-1}/{max_size}\r\n |
| 543 | \r\n |
| 544 | ..........content...........\r\n |
| 545 | --{boundary}-- |
| 546 | ``` |
| 547 | """ |
| 548 | boundary_len = len(boundary) |
| 549 | static_header_part_len = 49 + boundary_len + len(content_type) + len(str(max_size)) |
| 550 | content_length = sum( |
| 551 | (len(str(start)) + len(str(end - 1)) + static_header_part_len) # Headers |
| 552 | + (end - start) # Content |
| 553 | for start, end in ranges |
| 554 | ) + ( |
| 555 | 4 + boundary_len # --boundary-- |
| 556 | ) |
| 557 | return ( |
| 558 | content_length, |
| 559 | lambda start, end: ( |
| 560 | f"""\ |
| 561 | --{boundary}\r |
| 562 | Content-Type: {content_type}\r |
| 563 | Content-Range: bytes {start}-{end - 1}/{max_size}\r |
| 564 | \r |
| 565 | """ |
| 566 | ).encode("latin-1"), |
| 567 | ) |
no outgoing calls
no test coverage detected