MCPcopy
hub / github.com/encode/starlette / _parse_ranges

Method _parse_ranges

starlette/responses.py:496–522  ·  view source on GitHub ↗
(cls, range_: str, file_size: int)

Source from the content-addressed store, hash-verified

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,

Callers 1

_parse_range_headerMethod · 0.80

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected