b.t.h.r.RangeFile(object) : class documentation

Part of bzrlib.transport.http.response View In Hierarchy

File-like object that allow access to partial available data.

All accesses should happen sequentially since the acquisition occurs during an http response reception (as sockets can't be seeked, we simulate the seek by just reading and discarding the data).

The access pattern is defined by a set of ranges discovered as reading progress. Only one range is available at a given time, so all accesses should happen with monotonically increasing offsets.

Method __init__ Constructor.
Method set_range Change the range mapping
Method set_boundary Define the boundary used in a multi parts message.
Method read_boundary Read the boundary headers defining a new range
Method read_range_definition Read a new range definition in a multi parts message.
Method set_range_from_header Helper to set the new range from its description in the headers
Method read Read size bytes from the current position in the file.
Method seek Undocumented
Method tell Undocumented
Method _unquote_boundary Undocumented
Method _checked_read Read the file checking for short reads.
Method _seek_to_next_range Undocumented
def __init__(self, path, infile):
Constructor.
ParameterspathFile url, for error reports.
infileFile-like socket set at body start.
def set_range(self, start, size):
Change the range mapping
def set_boundary(self, boundary):
Define the boundary used in a multi parts message.

The file should be at the beginning of the body, the first range definition is read and taken into account.

def read_boundary(self):
Read the boundary headers defining a new range
def _unquote_boundary(self, b):
Undocumented
def read_range_definition(self):
Read a new range definition in a multi parts message.

Parse the headers including the empty line following them so that we are ready to read the data itself.

def set_range_from_header(self, content_range):
Helper to set the new range from its description in the headers
def _checked_read(self, size):
Read the file checking for short reads.

The data read is discarded along the way.

def _seek_to_next_range(self):
Undocumented
def read(self, size=-1):
Read size bytes from the current position in the file.

Reading across ranges is not supported. We rely on the underlying http client to clean the socket if we leave bytes unread. This may occur for the final boundary line of a multipart response or for any range request not entirely consumed by the client (due to offset coalescing)

ParameterssizeThe number of bytes to read. Leave unspecified or pass -1 to read to EOF.
def seek(self, offset, whence=0):
Undocumented
def tell(self):
Undocumented
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.