class documentation

class LazyStream:

View In Hierarchy

The LazyStream wrapper allows one to get and "unget" bytes from a stream.

Given a producer object (an iterator that yields bytestrings), the LazyStream object will support iteration, reading, and keeping a "look-back" variable in case you need to "unget" some bytes.

Method __init__ Every LazyStream must have a producer when instantiated.
Method __iter__ Undocumented
Method __next__ Used when the exact number of bytes to read is unimportant.
Method ​_update​_unget​_history No summary
Method close Used to invalidate/disable this lazy stream.
Method read Undocumented
Method tell Undocumented
Method unget Place bytes back onto the front of the lazy stream.
Instance Variable ​_empty Undocumented
Instance Variable ​_leftover Undocumented
Instance Variable ​_producer Undocumented
Instance Variable ​_remaining Undocumented
Instance Variable ​_unget​_history Undocumented
Instance Variable length Undocumented
Instance Variable position Undocumented
def __init__(self, producer, length=None):

Every LazyStream must have a producer when instantiated.

A producer is an iterable that returns a string each time it is called.

def __iter__(self):

Undocumented

def __next__(self):

Used when the exact number of bytes to read is unimportant.

Return whatever chunk is conveniently returned from the iterator. Useful to avoid unnecessary bookkeeping if performance is an issue.

def _update_unget_history(self, num_bytes):
Update the unget history as a sanity check to see if we've pushed back the same number of bytes in one chunk. If we keep ungetting the same number of bytes many times (here, 50), we're mostly likely in an infinite loop of some sort. This is usually caused by a maliciously-malformed MIME request.
def close(self):

Used to invalidate/disable this lazy stream.

Replace the producer with an empty list. Any leftover bytes that have already been read will still be reported upon read() and/or next().

def read(self, size=None):

Undocumented

def tell(self):

Undocumented

def unget(self, bytes):

Place bytes back onto the front of the lazy stream.

Future calls to read() will return those bytes first. The stream position and thus tell() will be rewound.

_empty: bool =

Undocumented

_leftover =

Undocumented

_producer: list =

Undocumented

_remaining =

Undocumented

_unget_history =

Undocumented

length =

Undocumented

position: int =

Undocumented