Package qbuf :: Module socket_support :: Class StatefulProtocol

Class StatefulProtocol

source code

    object --+    
             |    
_SocketWrapper --+
                 |
                StatefulProtocol

A socket wrapper similar to Twisted's StatefulProtocol.

Instance Methods
 
__init__(self, sock, buffer_size=4096)
Wrap a socket for stateful reads.
source code
 
get_initial_state(self)
Get the initial state for the StatefulProtocol.
source code
 
update(self)
Pump the buffer and try to make as many callbacks as possible.
source code

Inherited from _SocketWrapper: close, fileno, pump_buffer, send, sendall

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, sock, buffer_size=4096)
(Constructor)

source code 

Wrap a socket for stateful reads.

The buffer_size parameter indicates how much should be read from the socket at a time.

Overrides: object.__init__

get_initial_state(self)

source code 

Get the initial state for the StatefulProtocol.

This function must return a tuple of (some_callable, bytes_to_read), where the callable will be called when that number of bytes has been read, with those same bytes as the only argument. That callable can return None to keep the same (callable, n_bytes) state, or return a new (callable, n_bytes) tuple.

update(self)

source code 

Pump the buffer and try to make as many callbacks as possible.

If the socket is closed, a SocketClosedError is raised.