(cls, range_: str, file_size: int)
| 494 | |
| 495 | @classmethod |
| 496 | def _parse_ranges(cls, range_: str, file_size: int) -> list[tuple[int, int]]: |
| 497 | ranges: list[tuple[int, int]] = [] |
| 498 | |
| 499 | for part in range_.split(","): |
| 500 | part = part.strip() |
| 501 | |
| 502 | # If the range is empty or a single dash, we ignore it. |
| 503 | if not part or part == "-": |
| 504 | continue |
| 505 | |
| 506 | # If the range is not in the format "start-end", we ignore it. |
| 507 | if "-" not in part: |
| 508 | continue |
| 509 | |
| 510 | start_str, end_str = part.split("-", 1) |
| 511 | start_str = start_str.strip() |
| 512 | end_str = end_str.strip() |
| 513 | |
| 514 | try: |
| 515 | start = int(start_str) if start_str else max(file_size - int(end_str), 0) |
| 516 | end = int(end_str) + 1 if start_str and end_str and int(end_str) < file_size else file_size |
| 517 | ranges.append((start, end)) |
| 518 | except ValueError: |
| 519 | # If the range is not numeric, we ignore it. |
| 520 | continue |
| 521 | |
| 522 | return ranges |
| 523 | |
| 524 | def generate_multipart( |
| 525 | self, |
no test coverage detected