moler.io package¶
Subpackages¶
Submodules¶
moler.io.io_connection module¶
External-IO connections.
The only 3 requirements for these connections is: (1) store Moler’s connection inside self.moler_connection attribute (2) forward IO received data into self.moler_connection.data_received(data) (3) provide Moler connection with method to send outgoing data:
self.moler_connection.how2send = self.send
We want all connections of this subpackage to have open()/close() API even that for memory connection that may have no sense but for majority (tcp, udp, ssh, process …) it applies, so lets have common API. Moreover, we will map it to context manager API.
send()/receive() is required but we cant force naming here since it’s better to keep native/well-known naming of external-IO (send/recv for socket, transport.write/data_received for asyncio, …) Specific external-IO implementation must do data-forwarding and send-plugin as stated above. NOTE: send/receive works on bytes since encoding/decoding is responsibility of moler_connection
So, below class is not needed to work as base class. It may, but rather it is generic template how to glue external-IO with Moler’s connection.
-
class
moler.io.io_connection.
IOConnection
(moler_connection)¶ Bases:
object
External-IO connection.
-
close
()¶ Close established connection.
-
data_received
(data, recv_time)¶ Having been given data bytes from external-IO:
just forward it to Moler’s connection:
-
disable_logging
()¶ Disable logging incoming data. :return: None
-
enable_logging
()¶ Enable logging incoming data. :return: None
-
name
¶
-
notify
(callback, when)¶ Adds subscriber to list of functions to call :param callback: reference to function to call when connection is open/established :param when: connection state change :return: None
-
open
()¶ Take ‘how to establish connection’ info from constructor and open that connection.
Return context manager to allow for: with connection.open() as conn:
-
receive
()¶ Pull data bytes from external-IO:
data = io_connection.receive()and then forward it to Moler’s connection:
self.moler_connection.data_received(data)
-
send
(data)¶ Send data bytes over external-IO.
Because of plugin done in constructor it will be called by moler_connection when it needs.
-
subscribe_on_connection_lost
(subscriber)¶ Adds subscriber to list of functions to call when connection is closed/disconnected :param subscriber: reference to function to call when connection is closed/disconnected :return: None
-
subscribe_on_connection_made
(subscriber)¶ Adds subscriber to list of functions to call when connection is open/established (also reopen after close) :param subscriber: reference to function to call when connection is open/established :return: None
-
unsubscribe_on_connection_lost
(subscriber)¶ Remove subscriber from list of functions to call when connection is closed/disconnected :param subscriber: reference to function registered by method subscribe_on_connection_lost :return: None
-
unsubscribe_on_connection_made
(subscriber)¶ Remove subscriber from list of functions to call when connection is open/established (also reopen after close) :param subscriber: reference to function registered by method subscribe_on_connection_made :return: None
-
moler.io.io_exceptions module¶
External-IO exceptions.
-
exception
moler.io.io_exceptions.
ConnectionBaseError
¶ Bases:
Exception
-
exception
moler.io.io_exceptions.
ConnectionTimeout
¶
-
exception
moler.io.io_exceptions.
RemoteEndpointDisconnected
(err_code=None)¶
-
exception
moler.io.io_exceptions.
RemoteEndpointNotConnected
¶
Module contents¶
External-IO connections.
The only 3 requirements for these connections is: (1) store Moler’s connection inside self.moler_connection attribute (2) plugin into Moler’s connection the way IO outputs data to external world:
self.moler_connection.how2send = self.send
- forward IO received data into self.moler_connection.data_received(data)