MCPcopy
hub / github.com/pallets/werkzeug / range_for_length

Method range_for_length

src/werkzeug/datastructures/range.py:69–83  ·  view source on GitHub ↗

If the range is for bytes, the length is not None and there is exactly one range and it is satisfiable it returns a ``(start, stop)`` tuple, otherwise `None`.

(self, length: int | None)

Source from the content-addressed store, hash-verified

67 raise ValueError(f"{(start, end)} is not a valid range.")
68
69 def range_for_length(self, length: int | None) -> tuple[int, int] | None:
70 """If the range is for bytes, the length is not None and there is
71 exactly one range and it is satisfiable it returns a ``(start, stop)``
72 tuple, otherwise `None`.
73 """
74 if self.units != "bytes" or length is None or len(self.ranges) != 1:
75 return None
76 start, end = self.ranges[0]
77 if end is None:
78 end = length
79 if start < 0:
80 start += length
81 if http.is_byte_range_valid(start, end, length):
82 return start, min(end, length)
83 return None
84
85 def make_content_range(self, length: int | None) -> ContentRange | None:
86 """Creates a :class:`~werkzeug.datastructures.ContentRange` object

Callers 3

make_content_rangeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected