waterbutler.server package

waterbutler.server.app module

waterbutler.server.settings module

waterbutler.server.utils module

waterbutler.server.utils.parse_request_range(range_header)[source]

WB uses tornado’s httputil._parse_request_range function to parse the Range HTTP header and return a tuple representing the range. Tornado’s version returns a tuple suitable for slicing arrays, meaning that a range of 0-1 will be returned as (0, 2). WB had been assuming that the tuple would represent the first and last byte positions and was consistently returning one more byte than requested. Since WB doesn’t ever use ranges to do list slicing of byte streams, this function wraps tornado’s version and returns the actual byte indices.

Ex. Range: bytes=0-1 will be returned as (0, 1).

If the end byte is omitted, the second element of the tuple will be None. This will be sent to the provider as an open ended range, e.g. (Range: bytes=5-). Most providers interpret this to mean “send from the start byte to the end of the file”.

If this function receives an unsupported or unfamiliar Range header, it will return None, indicating that the full file should be sent. Some formats supported by other providers but unsupported by WB include:

  • Range: bytes=-5 – some providers interpret this as “send the last five bytes”
  • Range: bytes=0-5,10-12 – indicates a multi-range, “send the first six bytes, then the next three bytes starting from the eleventh”.

Unfamiliar byte ranges are anything not matching ^bytes=[0-9]+\-[0-9]*$, or ranges where the end byte position is less than the start byte.

Parameters:range_header (str) – a string containing the value of the Range header
Return type:tuple or None
Returns:a tuple representing the inclusive range of byte positions or None.
class waterbutler.server.utils.CORsMixin[source]

Bases: object

set_default_headers()[source]
options(*args, **kwargs)[source]
class waterbutler.server.utils.UtilMixin[source]

Bases: object

bytes_downloaded = 0
bytes_uploaded = 0
set_status(code, reason=None)[source]
write_stream(stream)[source]

Module contents