Exscript.util.buffer module

A buffer object.

class Exscript.util.buffer.MonitoredBuffer(io=None)[source]

Bases: future.types.newobject.newobject

A specialized string buffer that allows for monitoring the content using regular expression-triggered callbacks.

__init__(io=None)[source]

Constructor. The data is stored in the given file-like object. If no object is given, or the io argument is None, a new StringIO is used.

Parameters:io (file-like object) – A file-like object that is used for storing the data.
add_monitor(pattern, callback, limit=80)[source]

Calls the given function whenever the given pattern matches the buffer.

Arguments passed to the callback are the index of the match, and the match object of the regular expression.

Parameters:
  • pattern (str|re.RegexObject|list(str|re.RegexObject)) – One or more regular expressions.
  • callback (callable) – The function that is called.
  • limit (int) – The maximum size of the tail of the buffer that is searched, in number of bytes.
append(data)[source]

Appends the given data to the buffer, and triggers all connected monitors, if any of them match the buffer content.

Parameters:data (str) – The data that is appended.
clear()[source]

Removes all data from the buffer.

head(bytes)[source]

Returns the number of given bytes from the head of the buffer. The buffer remains unchanged.

Parameters:bytes (int) – The number of bytes to return.
pop(bytes)[source]

Like head(), but also removes the head from the buffer.

Parameters:bytes (int) – The number of bytes to return and remove.
size()[source]

Returns the size of the buffer.

Return type:int
Returns:The size of the buffer in bytes.
tail(bytes)[source]

Returns the number of given bytes from the tail of the buffer. The buffer remains unchanged.

Parameters:bytes (int) – The number of bytes to return.